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 librararies 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 /* instant variable delimiter (can't use '$', collides with Tcl) */
61 /* string/numeric/character definitions */
69 /* bigmask/flags for the Split() function */
73 /* Command codes (1st char of esis lines) from sgmls. See its manpage. */
79 #define CMD_NOTATION 'N'
80 #define CMD_EXT_ENT 'E'
81 #define CMD_INT_ENT 'I'
84 #define CMD_FILENAME 'f'
87 #define CMD_SUBDOC 'S'
88 #define CMD_SUBDOC_S '{'
89 #define CMD_SUBDOC_E '}'
90 #define CMD_EXT_REF '&'
91 #define CMD_APPINFO '#'
92 #define CMD_CONFORM 'C'
96 #define LINESIZE 60000
98 /* Name of library env variable, and default value. */
100 #define TPT_LIB "TPT_LIB"
103 #define DEF_TPT_LIB "/project/tools/libdata/tpt"
106 /* for buffered output (buffer gets passed to interpreter) */
107 typedef struct _OutputBuffer {
108 char *base; /* pointer to start of buffer */
109 char *current; /* pointer to current location in buffer */
110 int size; /* total size of buffer */
113 #define OBUF_INCR 4096 /* enlarge buffer by this when full */
115 #define MIN(i,j) (((i) < (j)) ? (i) : (j))
118 /* Relationships - for querying */
120 REL_None, REL_Parent, REL_Child, REL_Ancestor, REL_Descendant,
121 REL_Sibling, REL_Preceding, REL_ImmPreceding, REL_Following,
122 REL_ImmFollowing, REL_Cousin, REL_Is1stContent, REL_HasOnlyContent,
126 /* Initial map sizes (IMS) */
127 #define IMS_relations 3
131 #define IMS_sdatacache 30
132 #define IMS_variables 20
133 #define IMS_attnames 50
134 #define IMS_elemnames 50
136 /* ----- structure definitions ----- */
138 /* We use this for variables, attributes, etc., so the caller only needs an
139 * opaque handle to the thing below, not worrying about array management. */
141 char *name; /* name of the thing */
142 char *sval; /* string value */
146 int n_alloc; /* number of elements allocated */
147 int n_used; /* number of elements used */
148 int slot_incr; /* increment for allocating slots */
149 int flags; /* info about this set of mappings */
150 Mapping_t *maps; /* array of mappings */
153 /* ______________________________________________________________________ */
155 /* Information about an entity reference. Not all fields will be used
157 typedef struct _ent {
158 char *type; /* entity type */
159 char *ename; /* entity name */
160 char *nname; /* notation name */
161 char *sysid; /* sys id */
162 char *pubid; /* pub id */
163 char *fname; /* filename */
164 struct _ent *next; /* next in linked list */
167 /* Content (child nodes) of an element (node in the tree) -- both data
168 * and other elements. */
170 char type; /* element, data, or pi? */
172 struct _elem *elem; /* direct children of this elem */
173 char *data; /* character data of this elem */
177 /* An element (node in the tree) */
178 typedef struct _elem {
179 char *gi; /* element GI */
180 Content_t *cont; /* content - element & data children */
181 int ncont; /* # of content/children */
182 struct _elem **econt; /* element children */
183 int necont; /* # of element children */
184 char **dcont; /* character data children */
185 int ndcont; /* # of data children */
186 Mapping_t *atts; /* array of attributes */
187 int natts; /* # of attributes */
188 Entity_t *entity; /* ext entity & notation info */
189 char *id; /* for linking */
190 int index; /* an internal bookkeeping mechanism */
191 int depth; /* how deep in tree */
192 int lineno; /* line number */
193 char *infile; /* input filename */
194 int my_eorder; /* order of this elem of its parent */
195 struct _elem *parent; /* this elem's direct parent */
196 struct _elem *next; /* kept in linked list */
197 void *trans; /* pointer to translation spec */
198 /* I'm not crazy about this, but it works */
199 int gen_trans[2]; /* refs to generated trans specs */
200 int processed; /* was this node processed? */
203 /* For mapping of element IDs to elements themselves. */
204 typedef struct id_s {
205 char *id; /* ID of the element */
206 Element_t *elem; /* pointer to it */
210 /* ----- global variable declarations ----- */
218 def Element_t *DocTree; /* root of document tree */
219 def char **UsedElem; /* a unique list of used elem names */
220 def int nUsedElem; /* number of used elem names */
221 def char **UsedAtt; /* a unique list of used attrib names */
222 def int nUsedAtt; /* number of used attrib names */
223 def ID_t *IDList; /* list of IDs used in the doc */
224 def Map_t *Variables; /* general, global variables */
225 def Map_t *SDATAmap; /* SDATA mappings */
226 def Map_t *PImap; /* Processing Instruction mappings */
227 def Entity_t *Entities; /* list of entities */
229 def FILE *outfp; /* where output is written */
230 def char *tpt_lib; /* TPT library directory */
231 def int verbose; /* flag - verbose output? */
232 def int warnings; /* flag - show warnings? */
233 def int interactive; /* flag - interactive browsing? */
234 def int slave; /* are we slave to another process? */
235 def int fold_case; /* flag - fold case of GIs? */
236 def Tcl_Interp *interpreter; /* interp for start_ and end_code */
237 def Element_t *tclE; /* active element in Tcl call */
240 /* ----- some macros for convenience and ease of code reading ----- */
242 /* #define stripNL(s) { char *_cp; if ((_cp=strchr(s, NL))) *_cp = EOS; } */
243 #define stripNL(s) { char *_cp = s; while (*_cp) _cp++; \
244 if ((_cp > s) && (*--_cp == NL)) *_cp = EOS; }
246 #define I18N_TRIGGER 0xFF
248 /* Similar to calloc(), malloc(), and realloc(), but check for success.
250 * (1) number of 'elements' to allocate
251 * (2) variable to point at allocated space
252 * (3) type of 'element'
253 * Eg: Calloc(5, e, Element_t) replaces
254 * if (!(e = (Element_t *)calloc(5, sizeof(Element_t))) {
255 * ... handle error ... ;
258 #define Calloc(N,V,T) \
259 { if (!((V) = (T *)calloc((size_t)N, sizeof(T)))) { \
260 perror("Calloc failed -- out of memory. Bailing out."); exit(1); \
262 #define Malloc(N,V,T) \
263 { if (!((V) = (T *)malloc((size_t)N*sizeof(T)))) { \
264 perror("Malloc failed -- out of memory. Bailing out."); exit(1); \
266 #define Realloc(N,V,T) \
267 { if (!((V) = (T *)realloc(V,(size_t)N*sizeof(T)))) { \
268 perror("Realloc failed -- out of memory. Bailing out."); exit(1); \
271 /* similar to strcmp(), but check first chars first, for efficiency */
272 #define StrEq(s1,s2) (s1[0] == s2[0] && !strcmp(s1,s2))
274 /* similar to isspace(), but check for blank or tab - without overhead
275 * of procedure call */
276 #define IsWhite(c) (c == ' ' || c == TAB)
278 #define ContType(e,i) (e->cont[i].type)
279 #define ContData(e,i) (e->cont[i].ch.data)
280 #define ContElem(e,i) (e->cont[i].ch.elem)
281 #define IsContData(e,i) (e->cont[i].type == CMD_DATA)
282 #define IsContElem(e,i) (e->cont[i].type == CMD_OPEN)
283 #define IsContPI(e,i) (e->cont[i].type == CMD_PI)
285 /* ----- function prototypes ----- */
287 /* things defined in util.c */
288 Element_t *QRelation(Element_t *, char *, Relation_t);
289 Relation_t FindRelByName(char *);
290 char *FindAttValByName(Element_t *, char *);
291 char *FindContext(Element_t *, int, char *);
292 char *AddElemName(char *);
293 char *AddAttName(char *);
294 void OutputString(char *, FILE *, int);
295 int Putc(int, FILE *);
296 int FPuts(const char *, FILE *);
298 FILE *OpenFile(char *);
299 char *FindElementPath(Element_t *, char *);
300 char *NearestOlderElem(Element_t *, char *);
301 void PrintLocation(Element_t *, FILE *);
302 char **Split(char *, int *, int);
303 void DescendTree(Element_t *, void(*)(), void(*)(), void(*)(), void *);
305 Mapping_t *FindMapping(Map_t *, char *);
306 char *FindMappingVal(Map_t *, char *);
307 void SetMapping(Map_t *, char *);
308 void SetMappingNV(Map_t *, char *, char *);
309 void AddID(Element_t *, char *);
310 Element_t *FindElemByID(char *);
312 /* things defined in translate.c */
313 void DoTranslate(Element_t*, char *, FILE *);
315 /* things defined in traninit.c */
316 void ReadTransSpec(char *);
317 void ReadSDATA(char *);
318 void ReadCharMap(char *);
320 /* things defined in info.c */
321 void PrintContext(Element_t *e);
322 void PrintElemSummary(Element_t *);
323 void PrintElemTree(Element_t *);
324 void PrintStats(Element_t *);
327 /* ----- other declarations ----- */
330 #define strdup(s) strcpy((char *)malloc(strlen(s)+1), s)