1 /* Interface to describing fields.
2    Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3    Contributed by Bob Manson (manson@juniper.net).
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 FIELD_H
22 #define FIELD_H
23 
24 typedef const struct field_def *FieldIndex;
25 #define InvalidFieldIndex NULL
26 
27 typedef struct field_def * FieldDef;
28 typedef struct complex_field_index *ComplexFieldIndex;
29 typedef struct field_list *FieldList;
30 typedef struct field_edit FieldEdit;
31 typedef struct input_template_fields InputTemplate;
32 typedef struct change_actions *ChangeActions;
33 typedef struct databaseFieldInfo *DatabaseFieldInfo;
34 typedef enum
35 {
36   InvalidFieldType = -1, Text = 0, MultiText, Enum, MultiEnum, Integer, Date,
37   TextWithRegex, PRListType
38 } FieldType;
39 
40 typedef enum
41 {
42   InvalidSearchType = -1,
43   NilSearch = 0, RegCmp, RegFind, LessThan, GreaterThan, StringMatch,
44   Equals, NotEquals, DefaultSearchType
45 } SearchType;
46 
47 #include "pr.h"
48 #include "adm.h"
49 #include "query.h"
50 #include "database.h"
51 
52 struct change_actions
53 {
54   QueryExpr expr;
55   FieldList requiredFields;
56   FieldEdit *edits;
57   int addAuditTrail;
58   QueryFormat *auditTrailFormat;
59   int requireChangeReason;
60   struct change_actions *next;
61 };
62 
63 struct field_edit
64 {
65   QueryExpr expr;
66   char *fieldToEditName;
67   FieldIndex fieldToEdit;
68   int append;
69   char *textFormat;
70   FieldList fieldsForFormat;
71   struct field_edit *next;
72 };
73 
74 struct input_template_fields
75 {
76   FieldIndex index;
77   struct input_template_fields *next;
78 };
79 
80 struct field_def
81 {
82   /* The database that this entry is associated with.  */
83   DatabaseInfo database;
84 
85   /* This field's index number. */
86   int number;
87 
88   /* The name of this field. */
89   char *name;
90 
91   /* One-line description of this field in human-readable form. */
92   char *description;
93 
94   /* Default value for the field, if no value is supplied. */
95   char *default_value;
96 
97   /* The suggested value when a PR is initially input.  */
98   char *input_default_value;
99 
100   /* If variant is enum, this is the set of possible values. */
101   StringList *enumValues;
102 
103   /* Type of data that will be accepted in this field. */
104   FieldType datatype;
105 
106   /* List of characters that can be separators between enums in a
107      MultiEnum field.  */
108   char *multiEnumSeparator;
109 
110   /* The default type of search to do on this field. */
111   SearchType defaultSearchType;
112 
113   /* If non-zero, this field should be searched when doing text searches. */
114   int textsearch;
115 
116   /* A non-zero value if this is a restricted field. */
117   int restricted;
118 
119   /* Spaces are not permitted to appear in the index file for this field. */
120   int nospaces;
121 
122   /* This field has an administrative database associated with it; this is
123      the pathanme to it. */
124   char *adm_db_name;
125 
126   /* The descriptor for the administrative database, if the field has one. */
127   AdmFieldDesc *adm_field_des;
128 
129   /* Chain of contents of the administrative database.  */
130   AdmEntry *adm_contents;
131 
132   /* Number of fields in each record of the ADM database. */
133   int adm_db_fields;
134 
135   /* Which adm field is the key.  */
136   int key_field;
137 
138   /* If the field value is required to match a regexp, this is it. */
139   StringList *regex;
140 
141   /* If this is an enum field and if allow_any_value is non-zero, we don't
142      require the value to match one of the listed enum values.  (This is
143      mainly used for the Responsible field.)  */
144   int allow_any_value;
145 
146   /* Set to a non-zero value if this field may not be edited. */
147   int readonly;
148 
149   /* The actions to perform when this field is edited. */
150   ChangeActions changeActions;
151 
152   /* Auxiliary undefined flags.  */
153   StringList *auxFlags;
154 
155   /* Maximum number of PRs permitted per field entry.  0 means "any
156      number".  Usually 0 or 1.. */
157   unsigned int maxPrsPerLine;
158 
159   /* Set to 1 if the field should not be displayed.  */
160   int editonly;
161 
162   QueryFormat *virtualFormat;
163 };
164 
165 struct field_list
166 {
167   ComplexFieldIndex ent;
168   struct field_list *next;
169 };
170 
171 extern void freeFieldList (FieldList list);
172 extern void freeStringList (StringList *list);
173 extern void freeAdmFieldDesc (AdmFieldDesc *desc);
174 extern void freeFieldEdit (FieldEdit *edit);
175 extern void clearFieldList (DatabaseInfo database);
176 
177 extern FieldList newFieldListEnt (const DatabaseInfo database,
178 				  const char *name, FieldList next);
179 
180 extern FieldIndex getNthField (const DatabaseInfo database, int n);
181 
182 extern ComplexFieldIndex newComplexFieldIndex (const DatabaseInfo database,
183 					       const char *name);
184 extern ComplexFieldIndex simpleComplexFieldIndex (FieldIndex index);
185 extern ComplexFieldIndex newComplexFieldLiteralString (const char *string);
186 extern void freeComplexFieldIndex (ComplexFieldIndex ent);
187 extern int parseComplexFieldIndex (ComplexFieldIndex ent);
188 extern FieldIndex simpleFieldIndexValue (ComplexFieldIndex field);
189 extern const char * get_field_value (PR *pr, PR *oldPR, ComplexFieldIndex ent,
190 				     FormatNamedParameter *params,
191 				     int *mustBeFreed);
192 int isConstantFieldValue (ComplexFieldIndex field);
193 extern char *complexFieldIndexToString (ComplexFieldIndex field);
194 extern char *getFieldFlags (const FieldIndex field);
195 
196 /* A bit cheezy, but it makes sense now.  */
197 #define fieldDefForIndex(FIELD) ((FieldDef)FIELD)
198 
199 #define fieldNumber(FIELD) (fieldDefForIndex ((FIELD))->number)
200 
201 extern FieldDef newFieldDef (DatabaseInfo database, char *name);
202 extern FieldIndex find_field_index (const DatabaseInfo database,
203 				    const char *name);
204 extern FieldIndex find_field_index_with_len (DatabaseInfo database,
205 					     const char *name, size_t len);
206 
207 /* If the ComplexFieldIndex represents a field type, return it; otherwise,
208    InvalidFieldType is returned. */
209 extern FieldType complexFieldType (ComplexFieldIndex field);
210 
211 extern const char *fieldTypeAsString (FieldType field);
212 
213 extern FieldType stringToFieldType (const char *string);
214 
215 extern ChangeActions newChangeAction (const DatabaseInfo database,
216 				      const char *optExpr);
217 
218 extern void freeChangeActions (ChangeActions actions);
219 
220 extern int requiresChangeReason (FieldDef field);
221 
222 #endif
223