1 /* All things that the query tools have in common.
2    Copyright (C) 1994, 95, 96, 1997 Free Software Foundation, Inc.
3    Contributed by Brendan Kehoe (brendan@cygnus.com).
4 
5 This file is part of GNU GNATS.
6 
7 GNU GNATS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11 
12 GNU GNATS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with GNU GNATS; see the file COPYING.  If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA.  */
20 
21 #ifndef _QUERY_H_
22 #define _QUERY_H_
23 
24 typedef struct queryFormat QueryFormat;
25 typedef struct queryExpr *QueryExpr;
26 struct re_pattern_buffer;
27 
28 typedef enum e_lists {
29   InvalidListType = -1,
30   ListCategories = 0, ListSubmitters, ListResponsible, ListStates,
31   ListFieldNames,  ListInitialInputFields, ListInitialRequiredFields,
32   ListDatabases
33 } ListTypes;
34 
35 /* The four operations to perform. */
36 typedef enum queryOp {
37   InvalidQueryOp = -1, QueryMatch = 0, QueryAnd, QueryOr, QueryNot
38 } QueryOp;
39 
40 #include "index.h"
41 #include "builtin-fields.h"
42 #include "field.h"
43 #include "mail.h"
44 
45 struct queryFormat
46 {
47   /* The name of this query format. */
48   char *name;
49 
50   /* A printf-style format.  If this is null, we just write the fields out
51      as-is. */
52   char *printf;
53 
54   /* The separator to place between each field.  If this is NULL, we print
55      out the field header followed by the contents, and an EOL between each
56      field. */
57   char *separator;
58 
59   /* The list of fields. */
60   FieldList fields;
61 
62   /* If 1, the query is "raw", and should not process virtual fields.  */
63   int rawQuery;
64 
65   /* The next format in the list.  */
66   struct queryFormat *next;
67 };
68 
69 /* The function that is invoked from iterate_prs () is of this type.
70    First argument is the result # (1 for the first PR matched, 2 for
71    the second, etc). The second argument is the PR entry for the
72    PR, and the final argument is the QueryFormat supplied to
73    iterate_prs.
74 
75    The function is invoked with a NULL PR entry when we run out of PRs
76    to match; the result # is the total # of PRs that were matched. */
77 typedef void (*QueryFunc)(int, PR *, QueryFormat *);
78 
79 /* Return the numeric equivalent of enum entry TEXT for field FIELD; entries
80    are numbered starting from 1.  0 is returned if TEXT is not a valid
81    entry for FIELD.  */
82 extern int enum_numeric (const char *text, FieldIndex field);
83 
84 extern int gnats_regcmp (const char *regexp, const char *string,
85 			 struct re_pattern_buffer *compRegexp);
86 extern int regfind (const char *regexp, const char *string,
87 		    struct re_pattern_buffer *compRegexp);
88 
89 extern QueryExpr booleanQuery (QueryOp op, QueryExpr left,
90 			       QueryExpr right);
91 
92 extern QueryExpr queryFieldType (FieldType fieldType,
93 				 SearchType stype,
94 				 ComplexFieldIndex rhs);
95 
96 extern QueryExpr queryBuiltinField (PR_BuiltinField builtinField,
97 				     SearchType stype,
98 				     const char *regex);
99 
100 extern QueryExpr *insertBooleanQuery (QueryExpr *lhs, QueryOp op);
101 
102 extern void freeQueryExpr (QueryExpr);
103 
104 extern int print_pr (FILE *, PR *pr, QueryFormat *query_format,
105 		     const char *eolTerminator);
106 
107 extern int print_named_format_pr (FILE *, PR *pr, const char *format_name,
108 				  const char *eolTerminator, ErrorDesc *err);
109 
110 extern int process_format (FILE *fp, char **res, PR *pr, PR *oldPR,
111 			   QueryFormat *fmt,
112 			   const char *eolTerminator,
113 			   FormatNamedParameter *parameters);
114 
115 extern int pr_matches_expr (PR *pr, PR *oldPR, QueryExpr expr,
116 			    FormatNamedParameter *params);
117 extern int set_query_opt (QueryExpr *, int, const char *, int);
118 
119 extern int iterate_prs (const DatabaseInfo database,
120 			int ac, char **av, QueryExpr exp, QueryFormat *format,
121 			QueryFunc func, ErrorDesc *err);
122 
123 extern void addQueryFormat (DatabaseInfo database, QueryFormat *format);
124 extern QueryFormat *findQueryFormat (const DatabaseInfo database,
125 				     const char *name, ErrorDesc *err);
126 
127 extern void insert_not_closed (QueryExpr *);
128 extern void insert_closed (QueryExpr *);
129 
130 extern SearchType getSearchTypeForName (const char *);
131 extern const char *getSearchOperatorForType (SearchType type);
132 extern QueryExpr parseQueryExpression (const DatabaseInfo database,
133 				       const char *expr, const char *exprend);
134 extern char *queryExprToString (char *string, QueryExpr expr);
135 extern time_t get_any_date (const char *dateString);
136 
137 extern void append_string (char **res, const char *string);
138 
139 extern void freeQueryFormat (QueryFormat *format);
140 extern void freeQueryFormatList (QueryFormat *q);
141 #endif
142