Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dthelp / parser / pass1 / helptag / global.h
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
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)
10  * any later version.
11  *
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
16  * details.
17  *
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
22  */
23 /* $TOG: global.h /main/4 1998/04/06 13:18:34 mgreess $ */
24 /* Copyright (c) 1988, 1989 Hewlett-Packard Co. */
25 /* Global definitions for HP Tag/TeX translator */
26 /*   When changing this file, check "grphpar.h" for conflicts */
27
28 #if defined(DEFINE)
29 #define EXTERN
30 #define INIT(a) = a
31 #else
32 #define EXTERN extern
33 #define INIT(a)
34 #endif
35
36 #include <malloc.h>
37 #include <string.h>
38 #include <time.h>
39 #if defined(MSDOS)
40 #include <io.h>
41 #include <stdlib.h>
42 #include <process.h>
43 #include <direct.h>
44 #endif
45 #include <ctype.h>
46
47 #include <unistd.h>
48 #include <locale.h>
49 #include <fcntl.h>
50
51 #define MAXHEADLINES 3
52 #define FNAMELEN 513
53 #define BIGBUF 1024
54
55 /* Must be in same order as values in optkey, adjust NUMOPTIONS if changed*/
56 #define DRAFT         1
57 #define FINAL         2
58 #define MEMO          3
59 #define NOMEMO        4
60 #define SEARCHKEY     5
61 #define CLEARSEARCH   6
62 #define LONGFILES     7
63 #define LONGFILE      8
64 #define LONG          9
65 #define SHORTFILES   10
66 #define SHORTFILE    11
67 #define SHORT        12
68 #define CHARSET      13
69 #define ONERROR      14
70
71 #if defined(FUTURE_FEATURE)
72 #define GRAPHICS     15
73 #define NOGRAPHICS   16
74 #define REV          17
75 #define NOREV        18
76 #endif /* FUTURE_FEATURE */
77
78 #define NUMOPTIONS 14
79
80 EXTERN int optval INIT(M_NULLVAL) ;
81
82 EXTERN char *optkey[NUMOPTIONS]
83 #if defined(DEFINE)
84   = {
85       "draft",
86       "final",
87       "memo",
88       "nomemo",
89       "search",
90       "clearsearch",
91       "longfiles",
92       "longfile",
93       "long",
94       "shortfiles",
95       "shortfile",
96       "short",
97       "charset",
98       "onerror",
99
100 #if defined(FUTURE_FEATURE)
101       "graphics",
102       "nographics",
103       "rev",
104       "norev",
105 #endif /* FUTURE_FEATURE */
106       }
107 #endif
108   ;
109
110 /* Processing options */
111 EXTERN LOGICAL final INIT(FALSE) ;
112 EXTERN LOGICAL memo INIT(FALSE) ;
113 EXTERN int rebuild INIT(FALSE) ;
114
115 EXTERN LOGICAL stoponerror INIT(TRUE) ;
116
117 #if defined(FUTURE_FEATURE)
118 EXTERN LOGICAL prntrevs INIT(FALSE) ;
119 #endif /* FUTURE_FEATURE */
120
121 /* Flag for filelist vs. Tag to SDL translator */
122 EXTERN LOGICAL filelist INIT(FALSE) ;
123
124 EXTERN M_WCHAR *helpcharset INIT(NULL);
125 EXTERN M_WCHAR *helplang    INIT(NULL);
126 EXTERN char    *docId INIT("SDL-RESERVED0");
127 EXTERN char    sdlReservedName[] INIT("SDL-RESERVED");
128 #define SDLNAMESIZ sizeof("SDL-RESERVED")
129 EXTERN char    *pubId INIT("CDE 1.0");
130
131 /* Working directory, input directory, installation directory,
132    and search paths */
133 EXTERN LOGICAL defaultext ;
134 EXTERN M_WCHAR *inputname;    /* pointer to name of main input file */
135 EXTERN char *base ;
136 EXTERN char *baseext ;
137 EXTERN char *nodirbase ;
138 EXTERN char *work INIT("") ;
139 EXTERN char *indir INIT(NULL) ;
140 EXTERN char *install INIT(NULL) ;
141 typedef struct search SEARCH ;
142 struct search {
143   char *directory ;
144   SEARCH *next ;
145   } ;
146 EXTERN SEARCH *path INIT(NULL) ;
147 EXTERN SEARCH **endpath INIT(&path) ;
148 EXTERN char dirsep INIT('/') ;
149
150 #define CSEP '/'
151 #define SSEP "/"
152
153 /* True within a sequence of rsect's */
154 EXTERN LOGICAL rsectseq INIT(FALSE) ;
155
156 /* True if SAMEPAGE for this rsect sequence */
157 EXTERN LOGICAL rsectsame ;
158
159 /* True if this manual has a glossary */
160 EXTERN LOGICAL glossary INIT(FALSE) ;
161
162 /* True while processing a note if a head was encountered */
163 EXTERN LOGICAL notehead ;
164
165 /* File pointer for cross-reference file */
166 EXTERN FILE *xrf ;
167
168 /* global link type pointer, used in xref to match latest link type */
169 EXTERN int global_linktype INIT (0);
170
171 /* pointers to image parameters for use in imagetext */
172 EXTERN M_WCHAR *indentp;
173 EXTERN M_WCHAR *imagegentityp;
174 EXTERN M_WCHAR *imagegpositionp;
175 EXTERN M_WCHAR *imageghyperlinkp;
176 EXTERN M_WCHAR *imageglinktypep;
177 EXTERN M_WCHAR *imagegdescription;
178
179 LOGICAL inParText INIT(FALSE);
180 LOGICAL inSdlP    INIT(FALSE);
181
182 /* Save these ids and reuse them on the current virpage.
183  * We need two of each (except for the first) so we can alternate to
184  * avoid <form> thinking it is supposed to span them.  The bullet id
185  * indexes will flip back and forth between 0 and 1 to pick an id.
186 */
187 int bulletId[2], looseBulletId[2], firstBulletId, firstLooseBulletId;
188 int bulletIdIndex INIT(1);
189 int looseBulletIdIndex INIT(1);
190
191 /* save the textsize to emit it on the <p> tag; this allows us to have
192  * a single ssi= for the "ex" <block> and modify the text size individually 
193  * in the "ex" <p>
194 */
195 EXTERN int exTextSize;
196
197 /* File offset after preamble, and before \bye.  Used to determine 
198    whether content found in the document */
199 EXTERN long postpreamble INIT(0L) ;
200 EXTERN long prebye INIT(0L) ;
201 EXTERN LOGICAL filefound INIT(FALSE) ;
202
203 /* Chapter or appendix number */
204 EXTERN int part INIT(0) ;
205 EXTERN int chapter INIT(0) ;
206 EXTERN int chapinc INIT(0) ;
207 EXTERN char chapstring[15] INIT("0") ;
208
209 #define NODEID_LENGTH 204
210 /* name of current node */
211 EXTERN M_WCHAR nodeid[NODEID_LENGTH+1];  
212 /* Node level variables */
213 EXTERN int thisnodelevel INIT(0);
214 EXTERN M_WCHAR *savehelpfilename INIT(NULL);
215 /* flag for omitting first newline in topic map file */
216 EXTERN LOGICAL nohometopic INIT(TRUE);
217 EXTERN int     parTextId   INIT(0);
218 EXTERN char *helpbase INIT(NULL);
219 EXTERN char *helpext;
220
221 /* Should we use these BASENAME_LIMIT on the size of file names? */
222 LOGICAL usingshortnames INIT(FALSE);
223 /* Limit on how long the basename can be for a .ht file */
224 #define BASENAME_LIMIT 6
225 /* limit on how many additional character are allowed before the ext */
226 /* (How many chapter numbers    foo``12''.ht */
227 #define PRE_EXTENSION_LIMIT 2
228
229 EXTERN FILE *snbfp;
230 EXTERN FILE *indexfp;
231
232 /* Whether have processed anything in chapter or appendix */
233 EXTERN LOGICAL chapst INIT(FALSE) ; 
234
235 /* TRUE for chapter, FALSE for appendix */
236 EXTERN LOGICAL inchapter INIT(TRUE) ;
237
238 /* Figure number within this chapter or appendix */
239 EXTERN int figno ;
240
241 /* Options on a particular figure */
242 EXTERN int ftype, fborder, ftonumber, fvideo, fstrip, fsnap, fautoscale,
243            fmaxlistrows ;
244
245 /* Place to hold <snb> entries until after a <virpage><head>, if any,
246  * is seen.  Also, an integer value of the offset into the file to the
247  * point immediately after either <virpage> or <virpage><head> - the
248  * place to put the <snb>.
249 */
250 EXTERN char *savesnb  INIT(NULL);
251 EXTERN int   snbstart INIT(0);
252
253 /* Table number within this chapter or appendix */
254 EXTERN int tableno ;
255
256 /* footnote number */
257 EXTERN int footnoteno INIT(0);
258
259 /* True while processing abbrev head for page footer */
260 EXTERN LOGICAL fabbrev INIT(FALSE) ;
261
262 EXTERN FILE *outfile ;
263
264 /* True if a figure or table has a caption */
265 EXTERN LOGICAL figcaption ;
266 EXTERN LOGICAL tabcaption ;
267 EXTERN char   *capposition; /* left/center/right position of the caption */
268
269 EXTERN LOGICAL had_an_otherfront_head INIT(FALSE);
270
271 /* For softkeys */
272 EXTERN int sklines, skchars ;
273
274 /* contains current m_textchar, used to see if we need to issue an italic
275    correction.  Issue italic correction everywhere except after commas
276    and periods.  */
277 EXTERN M_WCHAR cur_char INIT(' ') ;
278
279 /* Special characters */
280 #define O_BR  '{'
281 #define C_BR  '}'
282 #define ESCAPE 27
283
284 /* Error _CoeMessage section */
285 EXTERN LOGICAL emsghead INIT(FALSE) ;
286 /* emsghead has three possible values:
287      DEFHEAD  : use default error message title
288      USERHEAD : user specified
289      FALSE    : do not process head (assume define is not equal to
290                                DEFHEAD or USERHEAD)
291 */
292 #define DEFHEAD  2
293 #define USERHEAD 3
294
295 /* declarations for the <form> stack */
296 typedef struct forminfo FORMINFO;
297 struct forminfo {
298   char *rowVec;
299   int   vecLen;
300   };
301 EXTERN FORMINFO *formStackBase INIT(NULL);
302 EXTERN FORMINFO *formStackTop  INIT(NULL);
303 EXTERN FORMINFO *formStackMax  INIT(NULL);
304
305 /* flag that we have output an SDL <block> for <partext> */
306 EXTERN LOGICAL inBlock INIT(FALSE);
307
308 /* flag that we need to output an <fdata> for a <form> */
309 EXTERN LOGICAL needFData INIT(FALSE);
310
311 /* Figure stuff */
312 #define FIGDEFWH "3in"
313 #define MAXNORMROWS 55
314 #define MAXSMALROWS 75
315 #define MAXTINYROWS 100
316 #define MAXPENS 8  /* when changing, check prfigpenwidths() ! */
317 #define MAXPENWIDTH 1864680    /* approx 1cm in scaled points */
318
319 EXTERN LOGICAL fignote ;
320 EXTERN int fignotePtr, in_graphic, nlines, blank_middle ;
321 EXTERN unsigned long ncolumns, max_columns, res_index, xx, ri ;
322 EXTERN LOGICAL file_ent ;
323 EXTERN M_WCHAR *f_content ;
324 EXTERN M_WCHAR f_contqual[FNAMELEN] ;
325 EXTERN M_WCHAR *f_file ;
326
327 /* callouts -- entfile and lineno */
328 EXTERN M_WCHAR *figinpath ;
329 EXTERN int figline INIT(0) ;
330
331 /* -- callouts -- */
332 #define BYTE       unsigned char
333 #define NEWPT      0
334 #define NEWGROUP   1
335 #define NEWLINE    2
336 #define NEWCALLOUT 3
337
338 typedef struct tagFPOINT {
339 float   x,y;
340 } FPOINT ;
341
342 typedef struct tagPwT {
343 FPOINT  coord;
344 char    ew[2],
345         ns[2],
346         lcr[2];
347 } PTWTXT ;
348
349 #define AN_desc         3
350 #define AN_nsew         60
351 #define AN_text         12
352 #define AN_isbros               16
353 #define AN_hasbros      32
354 #define AN_sf1                  64
355 #define AN_sf2                  128
356 #define SH_desc         0
357 #define SH_nsew         2
358 #define SH_text         2
359 #define SH_isbros               4
360 #define SH_hasbros      5
361 #define SH_sf1                  6
362 #define SH_sf2                  7
363
364 #define UNPK(c,an,sh)   ((c&an)>>sh)
365
366 EXTERN FILE *calfile ;
367 EXTERN int maxct;
368 EXTERN LOGICAL okcallout ;
369 /* -- end callout -- */
370
371 EXTERN FILE *pclfile ;
372
373 #define VERSION "Version"
374 EXTERN char *version INIT(NULL) ;
375
376 EXTERN char texdone[] INIT("TeX run completed successfully.") ;
377
378 /* Code for standard library function "access" */
379 #define READABLE 04
380
381 /* Allowable units on dimensions */
382 #define SPperPT 65536.0
383 #define PTperIN 72.27
384 #define CMperIN 2.54
385 #define MMperIN 25.4
386 #define PTperPC 12.0
387 EXTERN char *dimarray[5] 
388 #if defined(DEFINE)
389  = {  "in",
390       "cm",
391       "mm",
392       "pc",
393       "pt" }
394 #endif
395  ;
396
397 /* misc */
398 EXTERN int newhline INIT(0) ;
399 EXTERN int synelcnt INIT(0);
400
401 /* Cross-Reference Declarations */
402 /* do we have foreward references? */
403 EXTERN LOGICAL have_forward_xrefs INIT(FALSE);
404 EXTERN M_WCHAR *xrffile ;    /* Save file and line number for error messages */
405 EXTERN int xrfline INIT(0) ;  /* --used to store into structure "xref"   */
406 EXTERN M_TRIE xtree ;
407 struct xref {
408     M_WCHAR *textptr ;       /* Pointer to expansion of xref */
409     LOGICAL defined ;     /* Whether the xref has been defined */
410     LOGICAL wheredef ;    /* Whether defined in this pass or a previous one */
411     LOGICAL retrieved ;   /* Whether the value has been used */
412     LOGICAL csensitive ;  /* Whether the value is chapter sensitive */
413     LOGICAL xrefable;     /* can this be xref'd to legally? */
414     char *chapstring ;    /* Number of chapter or appendix where it occurs */
415     LOGICAL inchapter ;   /* Whether in chapter or appendix */
416     M_WCHAR *file ;      /* File and line # where first referred to or  */
417     int line ;            /*   first defined for error reports   */
418     } ;
419   /* Value of one particular cross-reference */
420 EXTERN M_WCHAR xrefstring[400] ;
421 EXTERN int xstrlen INIT(0) ;
422   /* Pointer to the id */
423 EXTERN M_WCHAR *savid ;
424 EXTERN LOGICAL  iderr ;
425 EXTERN char *imageId INIT(NULL); /* "image" id saved for "imagetext" */
426
427 /* Save head for page header in rsect and table of contents string*/
428 EXTERN M_WCHAR savehead[400] ;
429 EXTERN M_WCHAR savetabcap[400] ;
430 EXTERN int     svheadlen ;
431 EXTERN int     svtclen ;
432 EXTERN LOGICAL savhd ;
433 EXTERN LOGICAL savtc ;
434 EXTERN LOGICAL hderr ;
435 EXTERN LOGICAL echo ;
436 EXTERN LOGICAL tooutput INIT(TRUE) ;
437
438 /* Save example until we see an annotation (which will behave like a head */
439 EXTERN char    *saveex;
440 EXTERN int      svexlen;
441 EXTERN char    *saveexseg;
442 EXTERN int      svexseglen;
443 EXTERN LOGICAL  savex;
444 EXTERN LOGICAL  stackex;
445 EXTERN LOGICAL  firstAnnot;
446 EXTERN LOGICAL  tonumexlines;
447 EXTERN int      exLineNum;
448 EXTERN int      oldExLineNum;
449
450 /* Glossary Declarations */
451 EXTERN M_TRIE gtree ;
452 #define MAXTERM 200
453 EXTERN M_WCHAR term[MAXTERM + 1] ;
454 EXTERN M_WCHAR *termp ;
455 EXTERN LOGICAL wsterm ;
456 EXTERN int     lastTermId;
457
458 /* Saved document title */
459 EXTERN M_WCHAR *savedtitle;
460
461 /* tell whether .hmi should have generic info put into it */
462 EXTERN LOGICAL hadtitle INIT(FALSE);
463 EXTERN LOGICAL hadabstract INIT(FALSE);
464
465 /* emit an empty abstract title if no head specified */
466 EXTERN LOGICAL needabstracthead INIT(FALSE);
467      
468 /* Numeric codes corresponding to keyword parameter values */
469
470 #define FIXED 1
471 #define FLOAT 2
472
473 #define SIDE 1
474 #define STACK 2
475
476 #define COMPUTER 1
477 #define DISPLAY  2
478
479 /* Note that the definition of BOX was chosen so that the border
480 parameter on both figure and table could use it, even though these
481 parameters do not share all possible values */
482 #define BOX 1
483 #define TOP 2
484 #define BOTTOM 3
485 #define NOBORDER 4
486 #define SCREEN 5
487 #define NOBOX 2
488
489 #define ART 1
490 #define PCL 2
491 #define TIFF 3
492 #define LISTING 4
493 #define TEXT 5
494 #define HPGL 7
495
496 /* IMPORTANT: "FIG..." values should not be          */
497 /*             changed (eg. see proc "checkmargin")  */
498 #define FIGTOP    0
499 #define FIGRIGHT  1
500 #define FIGBOTTOM 2
501 #define FIGLEFT   3
502 #define NFIGSIDES 4
503
504 #define WRAP 1
505 #define NOWRAP 2
506
507 /* text size macros */
508 #define NORMAL 1
509 #define SMALLER 2
510 #define SMALLEST 3
511
512 #define NUMBER 1
513 #define NONUMBER 2
514
515 #define LEFT 1
516 #define INDENT 2
517 #define CENTER 3
518 #define RIGHT 4
519
520 #define TIGHT 1
521 #define LOOSE 2
522
523 #define NORULE 1
524 #define HEADRULE 2
525 #define GRID 3
526
527 #define ORDER 0
528 #define BULLET 1
529 #define PLAIN 2
530 #define MILSPEC 3
531 #define LABEL 4
532 #define CHECK 5
533
534 #define UROMAN 0
535 #define UALPHA 1
536 #define ARABIC 2
537 #define LALPHA 3
538 #define LROMAN 4
539
540 #define DOTPUNCT 0
541 #define PARENPUNCT 1
542
543 #define NEWPAGE 0
544 #define SAMEPAGE 1
545
546 #define GLOSS 1
547 #define NOGLOSS 2
548
549 #define INVERSE 1
550 #define NOINVERSE 2
551
552 #define STRIP 1
553 #define NOSTRIP 2
554
555 #define DPENWDVAL 1
556
557 #define SNAP 1
558 #define NOSNAP 2
559
560 #define AUTOSCALE 1
561 #define NOAUTOSCALE 2
562
563 /* the values for these elements are significant...they are used to set
564  * TeX register values which are later tested by  macros
565  */
566 #define COMMAND 1
567 #define KEYS2 2
568
569 /* the values for these elements are significant...they are used to set
570  * TeX register values which are later tested by  macros
571  */
572 #define TWO 2
573 #define FOUR 4
574 #define EIGHT 8
575 #define OTHER 0
576
577 /* values for ctable tracking */
578 EXTERN int ctbltype;
579 EXTERN int ctbldisplines;
580 EXTERN int ctblgraphics;
581
582 /* Declarations for lists */
583 #define MAXLISTLEV 8
584 /* FIRST  => first paragraph in list item.  The one following the label.
585    FOLLOW => immediately after a figure, note, caution, warning, ex or vex
586    INSIDE => at least one previous paragraph
587 */
588 enum ParagraphListLocation {FIRST, FOLLOW, INSIDE};
589 EXTERN LOGICAL firstPInBlock; /* give the first para a different ssi= */
590
591 EXTERN LOGICAL lablisttight[MAXLISTLEV];
592 EXTERN int labhid[MAXLISTLEV];
593 EXTERN int labhtextid[MAXLISTLEV];
594 EXTERN int labelid[MAXLISTLEV];
595 EXTERN int labeltextid[MAXLISTLEV];
596 EXTERN int list INIT(0) ;
597 typedef struct contchain CONTCHAIN ;
598 struct contchain {
599   long where ;
600   CONTCHAIN *next ;
601   } ;
602 typedef struct list LIST ;
603 struct list {
604   int type ;
605   int order ;
606   int count ;
607   int space ;
608   unsigned char punct ;
609   unsigned char started ;
610   unsigned char where ; 
611   LIST *lastlist ;
612   CONTCHAIN *chain ; 
613   } ;
614 EXTERN LIST outlist 
615 #if defined(DEFINE)
616   = {0, 0, 0, 0, DOTPUNCT, FALSE, FIRST, NULL, NULL}
617 #endif
618   ;
619 EXTERN LIST *lastlist INIT(&outlist) ;
620 EXTERN int bulcount INIT(0) ;
621
622 typedef struct rowvec ROWVEC;
623 struct rowvec {
624   unsigned char firstitem;
625   unsigned char longlabel;
626   };
627 EXTERN ROWVEC listitems[MAXLISTLEV+1];
628
629 /* save area for index processing */
630 EXTERN M_WCHAR idxsav[400] ;
631 /* Sort form of an index term */
632 EXTERN M_WCHAR sort[400] ;
633 /* Sort form of an index sub term */
634 EXTERN M_WCHAR subsort[400] ;
635 /* print form of index term */
636 EXTERN M_WCHAR print[400] ;
637 /* print form of index sub term */
638 EXTERN M_WCHAR subprint[400] ;
639 EXTERN int idxsavlen ;
640 EXTERN LOGICAL didsort ;
641 EXTERN LOGICAL didsubsort ;
642
643 /* Strings for constructing error messages */
644 EXTERN char firstused[] INIT("'%s' first used in line %d") ;
645 EXTERN char undef[] INIT("Undefined cross-reference %s (") ;
646 EXTERN char infile[] INIT("file %s, ") ;
647 EXTERN char online[] INIT("line %d)\n") ;
648 EXTERN char offile[] INIT(" of file: %s") ;
649 /* Whitemenu supported only in calculator, issue message only once */
650 EXTERN LOGICAL wmenu_err INIT(FALSE) ;
651
652 /* Pop the stack of font changes */
653 #define POPFONT 
654 /* For index entries */
655 #define IDXSTRT1 {}
656 #define IDXSTRT2 {}
657 #define IDXSTRT IDXSTRT1 IDXSTRT2
658
659 #define IDXEND1 {}
660 #define IDXEND2 {}
661 #define IDXEND3 {}
662 #define IDXEND IDXEND1 IDXEND2 IDXEND3
663
664 /* Absorb consecutive <CR>'s, because TeX gets confused by them */
665 EXTERN LOGICAL multi_cr_flag INIT(FALSE);
666
667 /* flag for leaders within <LIST PLAIN> only */
668 EXTERN LOGICAL leaderok INIT(FALSE) ;
669
670 /* Direct debugging trace output to stdout or outfile */
671 EXTERN LOGICAL tracetostd INIT(FALSE) ;
672
673 /* Function prototypes */
674 #include "fproto.h"
675
676 /* Declarations for handling special characters */
677 #include "roman8.h"
678
679 /* Declarations for handling special characters for calculators*/
680 EXTERN char ccoutbuf[128] ;
681
682 /* Character conversion tables */
683 #include "charconv.h"