2 * Copyright 1993 Open Software Foundation, Inc., Cambridge, Massachusetts.
7 * Open Software Foundation, Inc.
9 * Permission is hereby granted to use, copy, modify and freely distribute
10 * the software in this file and its documentation for any purpose without
11 * fee, provided that the above copyright notice appears in all copies and
12 * that both the copyright notice and this permission notice appear in
13 * supporting documentation. Further, provided that the name of Open
14 * Software Foundation, Inc. ("OSF") not be used in advertising or
15 * publicity pertaining to distribution of the software without prior
16 * written permission from OSF. OSF makes no representations about the
17 * suitability of this software for any purpose. It is provided "as is"
18 * without express or implied warranty.
20 /* ________________________________________________________________________
22 * Common definitions for "instant" program.
23 * ________________________________________________________________________
28 static char *gen_h_RCSid =
29 "$XConsortium: general.h /main/11 1996/08/08 14:41:50 cde-hp $";
33 /* get Tcl header so the variables make sense */
36 /* instant variable delimiter (can't use '$', collides with Tcl) */
39 /* string/numeric/character definitions */
47 /* bigmask/flags for the Split() function */
51 /* Command codes (1st char of esis lines) from sgmls. See its manpage. */
57 #define CMD_NOTATION 'N'
58 #define CMD_EXT_ENT 'E'
59 #define CMD_INT_ENT 'I'
62 #define CMD_FILENAME 'f'
65 #define CMD_SUBDOC 'S'
66 #define CMD_SUBDOC_S '{'
67 #define CMD_SUBDOC_E '}'
68 #define CMD_EXT_REF '&'
69 #define CMD_APPINFO '#'
70 #define CMD_CONFORM 'C'
74 #define LINESIZE 60000
76 /* Name of library env variable, and default value. */
78 #define TPT_LIB "TPT_LIB"
81 #define DEF_TPT_LIB "/project/tools/libdata/tpt"
84 /* for buffered output (buffer gets passed to interpreter) */
85 typedef struct _OutputBuffer {
86 char *base; /* pointer to start of buffer */
87 char *current; /* pointer to current location in buffer */
88 int size; /* total size of buffer */
91 #define OBUF_INCR 4096 /* enlarge buffer by this when full */
93 #define MIN(i,j) (((i) < (j)) ? (i) : (j))
96 /* Relationships - for querying */
98 REL_None, REL_Parent, REL_Child, REL_Ancestor, REL_Descendant,
99 REL_Sibling, REL_Preceding, REL_ImmPreceding, REL_Following,
100 REL_ImmFollowing, REL_Cousin, REL_Is1stContent, REL_HasOnlyContent,
104 /* Initial map sizes (IMS) */
105 #define IMS_relations 3
109 #define IMS_sdatacache 30
110 #define IMS_variables 20
111 #define IMS_attnames 50
112 #define IMS_elemnames 50
114 /* ----- structure definitions ----- */
116 /* We use this for variables, attributes, etc., so the caller only needs an
117 * opaque handle to the thing below, not worrying about array management. */
119 char *name; /* name of the thing */
120 char *sval; /* string value */
124 int n_alloc; /* number of elements allocated */
125 int n_used; /* number of elements used */
126 int slot_incr; /* increment for allocating slots */
127 int flags; /* info about this set of mappings */
128 Mapping_t *maps; /* array of mappings */
131 /* ______________________________________________________________________ */
133 /* Information about an entity reference. Not all fields will be used
135 typedef struct _ent {
136 char *type; /* entity type */
137 char *ename; /* entity name */
138 char *nname; /* notation name */
139 char *sysid; /* sys id */
140 char *pubid; /* pub id */
141 char *fname; /* filename */
142 struct _ent *next; /* next in linked list */
145 /* Content (child nodes) of an element (node in the tree) -- both data
146 * and other elements. */
148 char type; /* element, data, or pi? */
150 struct _elem *elem; /* direct children of this elem */
151 char *data; /* character data of this elem */
155 /* An element (node in the tree) */
156 typedef struct _elem {
157 char *gi; /* element GI */
158 Content_t *cont; /* content - element & data children */
159 int ncont; /* # of content/children */
160 struct _elem **econt; /* element children */
161 int necont; /* # of element children */
162 char **dcont; /* character data children */
163 int ndcont; /* # of data children */
164 Mapping_t *atts; /* array of attributes */
165 int natts; /* # of attributes */
166 Entity_t *entity; /* ext entity & notation info */
167 char *id; /* for linking */
168 int index; /* an internal bookkeeping mechanism */
169 int depth; /* how deep in tree */
170 int lineno; /* line number */
171 char *infile; /* input filename */
172 int my_eorder; /* order of this elem of its parent */
173 struct _elem *parent; /* this elem's direct parent */
174 struct _elem *next; /* kept in linked list */
175 void *trans; /* pointer to translation spec */
176 /* I'm not crazy about this, but it works */
177 int gen_trans[2]; /* refs to generated trans specs */
178 int processed; /* was this node processed? */
181 /* For mapping of element IDs to elements themselves. */
182 typedef struct id_s {
183 char *id; /* ID of the element */
184 Element_t *elem; /* pointer to it */
188 /* ----- global variable declarations ----- */
196 def Element_t *DocTree; /* root of document tree */
197 def char **UsedElem; /* a unique list of used elem names */
198 def int nUsedElem; /* number of used elem names */
199 def char **UsedAtt; /* a unique list of used attrib names */
200 def int nUsedAtt; /* number of used attrib names */
201 def ID_t *IDList; /* list of IDs used in the doc */
202 def Map_t *Variables; /* general, global variables */
203 def Map_t *SDATAmap; /* SDATA mappings */
204 def Map_t *PImap; /* Processing Instruction mappings */
205 def Entity_t *Entities; /* list of entities */
207 def FILE *outfp; /* where output is written */
208 def char *tpt_lib; /* TPT library directory */
209 def int verbose; /* flag - verbose output? */
210 def int warnings; /* flag - show warnings? */
211 def int interactive; /* flag - interactive browsing? */
212 def int slave; /* are we slave to another process? */
213 def int fold_case; /* flag - fold case of GIs? */
214 def Tcl_Interp *interpreter; /* interp for start_ and end_code */
215 def Element_t *tclE; /* active element in Tcl call */
218 /* ----- some macros for convenience and ease of code reading ----- */
220 /* #define stripNL(s) { char *_cp; if ((_cp=strchr(s, NL))) *_cp = EOS; } */
221 #define stripNL(s) { char *_cp = s; while (*_cp) _cp++; \
222 if ((_cp > s) && (*--_cp == NL)) *_cp = EOS; }
224 #define I18N_TRIGGER 0xFF
226 /* Similar to calloc(), malloc(), and realloc(), but check for success.
228 * (1) number of 'elements' to allocate
229 * (2) variable to point at allocated space
230 * (3) type of 'element'
231 * Eg: Calloc(5, e, Element_t) replaces
232 * if (!(e = (Element_t *)calloc(5, sizeof(Element_t))) {
233 * ... handle error ... ;
236 #define Calloc(N,V,T) \
237 { if (!((V) = (T *)calloc((size_t)N, sizeof(T)))) { \
238 perror("Calloc failed -- out of memory. Bailing out."); exit(1); \
240 #define Malloc(N,V,T) \
241 { if (!((V) = (T *)malloc((size_t)N*sizeof(T)))) { \
242 perror("Malloc failed -- out of memory. Bailing out."); exit(1); \
244 #define Realloc(N,V,T) \
245 { if (!((V) = (T *)realloc(V,(size_t)N*sizeof(T)))) { \
246 perror("Realloc failed -- out of memory. Bailing out."); exit(1); \
249 /* similar to strcmp(), but check first chars first, for efficiency */
250 #define StrEq(s1,s2) (s1[0] == s2[0] && !strcmp(s1,s2))
252 /* similar to isspace(), but check for blank or tab - without overhead
253 * of procedure call */
254 #define IsWhite(c) (c == ' ' || c == TAB)
256 #define ContType(e,i) (e->cont[i].type)
257 #define ContData(e,i) (e->cont[i].ch.data)
258 #define ContElem(e,i) (e->cont[i].ch.elem)
259 #define IsContData(e,i) (e->cont[i].type == CMD_DATA)
260 #define IsContElem(e,i) (e->cont[i].type == CMD_OPEN)
261 #define IsContPI(e,i) (e->cont[i].type == CMD_PI)
263 /* ----- function prototypes ----- */
265 /* things defined in util.c */
266 Element_t *QRelation(Element_t *, char *, Relation_t);
267 Relation_t FindRelByName(char *);
268 char *FindAttValByName(Element_t *, char *);
269 char *FindContext(Element_t *, int, char *);
270 char *AddElemName(char *);
271 char *AddAttName(char *);
272 void OutputString(char *, FILE *, int);
273 int Putc(int, FILE *);
274 int FPuts(const char *, FILE *);
276 FILE *OpenFile(char *);
277 char *FindElementPath(Element_t *, char *);
278 char *NearestOlderElem(Element_t *, char *);
279 void PrintLocation(Element_t *, FILE *);
280 char **Split(char *, int *, int);
281 void DescendTree(Element_t *, void(*)(), void(*)(), void(*)(), void *);
283 Mapping_t *FindMapping(Map_t *, char *);
284 char *FindMappingVal(Map_t *, char *);
285 void SetMapping(Map_t *, char *);
286 void SetMappingNV(Map_t *, char *, char *);
287 void AddID(Element_t *, char *);
288 Element_t *FindElemByID(char *);
290 /* things defined in translate.c */
291 void DoTranslate(Element_t*, char *, FILE *);
293 /* things defined in traninit.c */
294 void ReadTransSpec(char *);
295 void ReadSDATA(char *);
296 void ReadCharMap(char *);
298 /* things defined in info.c */
299 void PrintContext(Element_t *e);
300 void PrintElemSummary(Element_t *);
301 void PrintElemTree(Element_t *);
302 void PrintStats(Element_t *);
305 /* ----- other declarations ----- */
308 #define strdup(s) strcpy((char *)malloc(strlen(s)+1), s)