2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
24 * Copyright 1993 Open Software Foundation, Inc., Cambridge, Massachusetts.
25 * All rights reserved.
29 * Open Software Foundation, Inc.
31 * Permission is hereby granted to use, copy, modify and freely distribute
32 * the software in this file and its documentation for any purpose without
33 * fee, provided that the above copyright notice appears in all copies and
34 * that both the copyright notice and this permission notice appear in
35 * supporting documentation. Further, provided that the name of Open
36 * Software Foundation, Inc. ("OSF") not be used in advertising or
37 * publicity pertaining to distribution of the software without prior
38 * written permission from OSF. OSF makes no representations about the
39 * suitability of this software for any purpose. It is provided "as is"
40 * without express or implied warranty.
42 /* ________________________________________________________________________
44 * Common definitions for "instant" program.
45 * ________________________________________________________________________
50 static char *gen_h_RCSid =
51 "$XConsortium: general.h /main/11 1996/08/08 14:41:50 cde-hp $";
55 /* get Tcl header so the variables make sense */
58 /* Compatibility with pre 8.6 versions */
59 #if (TCL_MAJOR_VERSION < 8) || (TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION < 6)
60 # define Tcl_GetErrorLine(x) ((x)->errorLine)
63 /* instant variable delimiter (can't use '$', collides with Tcl) */
66 /* string/numeric/character definitions */
74 /* bigmask/flags for the Split() function */
78 /* Command codes (1st char of esis lines) from sgmls. See its manpage. */
84 #define CMD_NOTATION 'N'
85 #define CMD_EXT_ENT 'E'
86 #define CMD_INT_ENT 'I'
89 #define CMD_FILENAME 'f'
92 #define CMD_SUBDOC 'S'
93 #define CMD_SUBDOC_S '{'
94 #define CMD_SUBDOC_E '}'
95 #define CMD_EXT_REF '&'
96 #define CMD_APPINFO '#'
97 #define CMD_CONFORM 'C'
101 #define LINESIZE 60000
103 /* Name of library env variable, and default value. */
105 #define TPT_LIB "TPT_LIB"
108 #define DEF_TPT_LIB "/project/tools/libdata/tpt"
111 /* for buffered output (buffer gets passed to interpreter) */
112 typedef struct _OutputBuffer {
113 char *base; /* pointer to start of buffer */
114 char *current; /* pointer to current location in buffer */
115 int size; /* total size of buffer */
118 #define OBUF_INCR 4096 /* enlarge buffer by this when full */
120 #define MIN(i,j) (((i) < (j)) ? (i) : (j))
123 /* Relationships - for querying */
125 REL_None, REL_Parent, REL_Child, REL_Ancestor, REL_Descendant,
126 REL_Sibling, REL_Preceding, REL_ImmPreceding, REL_Following,
127 REL_ImmFollowing, REL_Cousin, REL_Is1stContent, REL_HasOnlyContent,
131 /* Initial map sizes (IMS) */
132 #define IMS_relations 3
136 #define IMS_sdatacache 30
137 #define IMS_variables 20
138 #define IMS_attnames 50
139 #define IMS_elemnames 50
141 /* ----- structure definitions ----- */
143 /* We use this for variables, attributes, etc., so the caller only needs an
144 * opaque handle to the thing below, not worrying about array management. */
146 char *name; /* name of the thing */
147 char *sval; /* string value */
151 int n_alloc; /* number of elements allocated */
152 int n_used; /* number of elements used */
153 int slot_incr; /* increment for allocating slots */
154 int flags; /* info about this set of mappings */
155 Mapping_t *maps; /* array of mappings */
158 /* ______________________________________________________________________ */
160 /* Information about an entity reference. Not all fields will be used
162 typedef struct _ent {
163 char *type; /* entity type */
164 char *ename; /* entity name */
165 char *nname; /* notation name */
166 char *sysid; /* sys id */
167 char *pubid; /* pub id */
168 char *fname; /* filename */
169 struct _ent *next; /* next in linked list */
172 /* Content (child nodes) of an element (node in the tree) -- both data
173 * and other elements. */
175 char type; /* element, data, or pi? */
177 struct _elem *elem; /* direct children of this elem */
178 char *data; /* character data of this elem */
182 /* An element (node in the tree) */
183 typedef struct _elem {
184 char *gi; /* element GI */
185 Content_t *cont; /* content - element & data children */
186 int ncont; /* # of content/children */
187 struct _elem **econt; /* element children */
188 int necont; /* # of element children */
189 char **dcont; /* character data children */
190 int ndcont; /* # of data children */
191 Mapping_t *atts; /* array of attributes */
192 int natts; /* # of attributes */
193 Entity_t *entity; /* ext entity & notation info */
194 char *id; /* for linking */
195 int index; /* an internal bookkeeping mechanism */
196 int depth; /* how deep in tree */
197 int lineno; /* line number */
198 char *infile; /* input filename */
199 int my_eorder; /* order of this elem of its parent */
200 struct _elem *parent; /* this elem's direct parent */
201 struct _elem *next; /* kept in linked list */
202 void *trans; /* pointer to translation spec */
203 /* I'm not crazy about this, but it works */
204 int gen_trans[2]; /* refs to generated trans specs */
205 int processed; /* was this node processed? */
208 /* For mapping of element IDs to elements themselves. */
209 typedef struct id_s {
210 char *id; /* ID of the element */
211 Element_t *elem; /* pointer to it */
215 /* ----- global variable declarations ----- */
223 def Element_t *DocTree; /* root of document tree */
224 def char **UsedElem; /* a unique list of used elem names */
225 def int nUsedElem; /* number of used elem names */
226 def char **UsedAtt; /* a unique list of used attrib names */
227 def int nUsedAtt; /* number of used attrib names */
228 def ID_t *IDList; /* list of IDs used in the doc */
229 def Map_t *Variables; /* general, global variables */
230 def Map_t *SDATAmap; /* SDATA mappings */
231 def Map_t *PImap; /* Processing Instruction mappings */
232 def Entity_t *Entities; /* list of entities */
234 def FILE *outfp; /* where output is written */
235 def char *tpt_lib; /* TPT library directory */
236 def int verbose; /* flag - verbose output? */
237 def int warnings; /* flag - show warnings? */
238 def int interactive; /* flag - interactive browsing? */
239 def int slave; /* are we slave to another process? */
240 def int fold_case; /* flag - fold case of GIs? */
241 def Tcl_Interp *interpreter; /* interp for start_ and end_code */
242 def Element_t *tclE; /* active element in Tcl call */
245 /* ----- some macros for convenience and ease of code reading ----- */
247 /* #define stripNL(s) { char *_cp; if ((_cp=strchr(s, NL))) *_cp = EOS; } */
248 #define stripNL(s) { char *_cp = s; while (*_cp) _cp++; \
249 if ((_cp > s) && (*--_cp == NL)) *_cp = EOS; }
251 #define I18N_TRIGGER 0xFF
253 /* Similar to calloc(), malloc(), and realloc(), but check for success.
255 * (1) number of 'elements' to allocate
256 * (2) variable to point at allocated space
257 * (3) type of 'element'
258 * Eg: Calloc(5, e, Element_t) replaces
259 * if (!(e = (Element_t *)calloc(5, sizeof(Element_t))) {
260 * ... handle error ... ;
263 #define Calloc(N,V,T) \
264 { if (!((V) = (T *)calloc((size_t)N, sizeof(T)))) { \
265 perror("Calloc failed -- out of memory. Bailing out."); exit(1); \
267 #define Malloc(N,V,T) \
268 { if (!((V) = (T *)malloc((size_t)N*sizeof(T)))) { \
269 perror("Malloc failed -- out of memory. Bailing out."); exit(1); \
271 #define Realloc(N,V,T) \
272 { if (!((V) = (T *)realloc(V,(size_t)N*sizeof(T)))) { \
273 perror("Realloc failed -- out of memory. Bailing out."); exit(1); \
276 /* similar to strcmp(), but check first chars first, for efficiency */
277 #define StrEq(s1,s2) (s1[0] == s2[0] && !strcmp(s1,s2))
279 /* similar to isspace(), but check for blank or tab - without overhead
280 * of procedure call */
281 #define IsWhite(c) (c == ' ' || c == TAB)
283 #define ContType(e,i) (e->cont[i].type)
284 #define ContData(e,i) (e->cont[i].ch.data)
285 #define ContElem(e,i) (e->cont[i].ch.elem)
286 #define IsContData(e,i) (e->cont[i].type == CMD_DATA)
287 #define IsContElem(e,i) (e->cont[i].type == CMD_OPEN)
288 #define IsContPI(e,i) (e->cont[i].type == CMD_PI)
290 /* ----- function prototypes ----- */
292 /* things defined in util.c */
293 Element_t *QRelation(Element_t *, char *, Relation_t);
294 Relation_t FindRelByName(char *);
295 char *FindAttValByName(Element_t *, char *);
296 char *FindContext(Element_t *, int, char *);
297 char *AddElemName(char *);
298 char *AddAttName(char *);
299 void OutputString(char *, FILE *, int);
300 int Putc(int, FILE *);
301 int FPuts(const char *, FILE *);
303 FILE *OpenFile(char *);
304 char *FindElementPath(Element_t *, char *);
305 char *NearestOlderElem(Element_t *, char *);
306 void PrintLocation(Element_t *, FILE *);
307 char **Split(char *, int *, int);
308 void DescendTree(Element_t *, void(*)(), void(*)(), void(*)(), void *);
310 Mapping_t *FindMapping(Map_t *, char *);
311 char *FindMappingVal(Map_t *, char *);
312 void SetMapping(Map_t *, char *);
313 void SetMappingNV(Map_t *, char *, char *);
314 void AddID(Element_t *, char *);
315 Element_t *FindElemByID(char *);
317 /* things defined in translate.c */
318 void DoTranslate(Element_t*, char *, FILE *);
320 /* things defined in traninit.c */
321 void ReadTransSpec(char *);
322 void ReadSDATA(char *);
323 void ReadCharMap(char *);
325 /* things defined in info.c */
326 void PrintContext(Element_t *e);
327 void PrintElemSummary(Element_t *);
328 void PrintElemTree(Element_t *);
329 void PrintStats(Element_t *);