| 1 | /* emxdoc.h -- Global header file
|
|---|
| 2 | Copyright (c) 1993-1999 Eberhard Mattes
|
|---|
| 3 |
|
|---|
| 4 | This file is part of emxdoc.
|
|---|
| 5 |
|
|---|
| 6 | emxdoc is free software; you can redistribute it and/or modify it
|
|---|
| 7 | under the terms of the GNU General Public License as published by
|
|---|
| 8 | the Free Software Foundation; either version 2, or (at your option)
|
|---|
| 9 | any later version.
|
|---|
| 10 |
|
|---|
| 11 | emxdoc is distributed in the hope that it will be useful,
|
|---|
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 14 | GNU General Public License for more details.
|
|---|
| 15 |
|
|---|
| 16 | You should have received a copy of the GNU General Public License
|
|---|
| 17 | along with emxdoc; see the file COPYING. If not, write to
|
|---|
| 18 | the Free Software Foundation, 59 Temple Place - Suite 330,
|
|---|
| 19 | Boston, MA 02111-1307, USA. */
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 | #if !defined (EXTERN)
|
|---|
| 23 | #define EXTERN extern
|
|---|
| 24 | #define INIT(X)
|
|---|
| 25 | #endif
|
|---|
| 26 |
|
|---|
| 27 | #define FALSE 0
|
|---|
| 28 | #define TRUE 1
|
|---|
| 29 |
|
|---|
| 30 | #define ENV_STACK_SIZE 8
|
|---|
| 31 | #define HL_STACK_SIZE 8
|
|---|
| 32 | #define STYLE_STACK_SIZE 8
|
|---|
| 33 | #define SECTION_LEVELS 3
|
|---|
| 34 |
|
|---|
| 35 | #define HL_BF 0x01
|
|---|
| 36 | #define HL_SL 0x02
|
|---|
| 37 | #define HL_TT 0x04
|
|---|
| 38 | #define HL_UL 0x08
|
|---|
| 39 | #define HL_EM 0x10
|
|---|
| 40 |
|
|---|
| 41 | #define HF_UNNUMBERED 0x01
|
|---|
| 42 | #define HF_HIDE 0x02
|
|---|
| 43 |
|
|---|
| 44 | /* Flag bits for the `flags' field of struct word. */
|
|---|
| 45 |
|
|---|
| 46 | #define WF_ABBREV 0x01
|
|---|
| 47 |
|
|---|
| 48 | #ifdef __GNUC__
|
|---|
| 49 | #define PRINTF(x,y) __attribute__ ((format (printf, x, y)))
|
|---|
| 50 | #define NORETURN2 __attribute__ ((noreturn))
|
|---|
| 51 | #else
|
|---|
| 52 | #define PRINTF(x,y)
|
|---|
| 53 | #define NORETURN2
|
|---|
| 54 | #endif
|
|---|
| 55 |
|
|---|
| 56 | typedef unsigned char uchar;
|
|---|
| 57 |
|
|---|
| 58 | enum tag
|
|---|
| 59 | {
|
|---|
| 60 | TAG_HEADING,
|
|---|
| 61 | TAG_TOC,
|
|---|
| 62 | TAG_TITLE,
|
|---|
| 63 | TAG_IPF,
|
|---|
| 64 | TAG_ENDIPF,
|
|---|
| 65 | TAG_ITEM,
|
|---|
| 66 | TAG_SAMPLECODE,
|
|---|
| 67 | TAG_ENDSAMPLECODE,
|
|---|
| 68 | TAG_VERBATIM,
|
|---|
| 69 | TAG_ENDVERBATIM,
|
|---|
| 70 | TAG_EXAMPLE,
|
|---|
| 71 | TAG_ENDEXAMPLE,
|
|---|
| 72 | TAG_HEADERS,
|
|---|
| 73 | TAG_ENDHEADERS,
|
|---|
| 74 | TAG_PROTOTYPE,
|
|---|
| 75 | TAG_ENDPROTOTYPE,
|
|---|
| 76 | TAG_DESCRIPTION,
|
|---|
| 77 | TAG_ENDDESCRIPTION,
|
|---|
| 78 | TAG_ENUMERATE,
|
|---|
| 79 | TAG_ENDENUMERATE,
|
|---|
| 80 | TAG_ITEMIZE,
|
|---|
| 81 | TAG_ENDITEMIZE,
|
|---|
| 82 | TAG_LIST,
|
|---|
| 83 | TAG_ENDLIST,
|
|---|
| 84 | TAG_INDENT,
|
|---|
| 85 | TAG_ENDINDENT,
|
|---|
| 86 | TAG_TYPEWRITER,
|
|---|
| 87 | TAG_ENDTYPEWRITER,
|
|---|
| 88 | TAG_TABLE,
|
|---|
| 89 | TAG_ENDTABLE,
|
|---|
| 90 | TAG_LABEL,
|
|---|
| 91 | TAG_TEXT,
|
|---|
| 92 | TAG_ENDTEXT,
|
|---|
| 93 | TAG_LATEX,
|
|---|
| 94 | TAG_ENDLATEX,
|
|---|
| 95 | TAG_HTML,
|
|---|
| 96 | TAG_ENDHTML,
|
|---|
| 97 | TAG_FORMAT,
|
|---|
| 98 | TAG_STYLE,
|
|---|
| 99 | TAG_REF,
|
|---|
| 100 | TAG_HPT,
|
|---|
| 101 | TAG_BREAK,
|
|---|
| 102 | TAG_INDEX,
|
|---|
| 103 | TAG_KEYWORD,
|
|---|
| 104 | TAG_FUNCTION,
|
|---|
| 105 | TAG_SEEALSO,
|
|---|
| 106 | TAG_COMPAT,
|
|---|
| 107 | TAG_SAMPLEFILE,
|
|---|
| 108 | TAG_RESTRICTIONS,
|
|---|
| 109 | TAG_IMPLEMENTATION,
|
|---|
| 110 | TAG_BUGS,
|
|---|
| 111 | TAG_RETURNVALUE,
|
|---|
| 112 | TAG_PARAM,
|
|---|
| 113 | TAG_LANGUAGE,
|
|---|
| 114 | TAG_SYNTAX,
|
|---|
| 115 | TAG_IPFMINITOC,
|
|---|
| 116 | TAG_HTMLMINITOC,
|
|---|
| 117 | TAG_MINITOC,
|
|---|
| 118 | TAG_HTMLFRAGMENT,
|
|---|
| 119 | TAG_SPECIAL,
|
|---|
| 120 | TAG_FULLSTOP,
|
|---|
| 121 | TAG_SET,
|
|---|
| 122 | TAG_REPLACE,
|
|---|
| 123 | TAG_ERRORS,
|
|---|
| 124 | TAG_HINTS
|
|---|
| 125 | };
|
|---|
| 126 |
|
|---|
| 127 | enum style
|
|---|
| 128 | {
|
|---|
| 129 | STYLE_NORMAL,
|
|---|
| 130 | STYLE_BOLD,
|
|---|
| 131 | STYLE_TTY,
|
|---|
| 132 | STYLE_UNDERLINE,
|
|---|
| 133 | STYLE_SLANTED,
|
|---|
| 134 | STYLE_SYNTAX,
|
|---|
| 135 | STYLE_PARAM,
|
|---|
| 136 | STYLE_EMPHASIZE
|
|---|
| 137 | };
|
|---|
| 138 |
|
|---|
| 139 | enum el
|
|---|
| 140 | {
|
|---|
| 141 | EL_END,
|
|---|
| 142 | EL_WORD,
|
|---|
| 143 | EL_PUNCT,
|
|---|
| 144 | EL_SPACE,
|
|---|
| 145 | EL_STYLE,
|
|---|
| 146 | EL_ENDSTYLE,
|
|---|
| 147 | EL_REF,
|
|---|
| 148 | EL_BREAK
|
|---|
| 149 | };
|
|---|
| 150 |
|
|---|
| 151 | enum env
|
|---|
| 152 | {
|
|---|
| 153 | ENV_NONE,
|
|---|
| 154 | ENV_ENUMERATE,
|
|---|
| 155 | ENV_ITEMIZE,
|
|---|
| 156 | ENV_DESCRIPTION,
|
|---|
| 157 | ENV_LIST,
|
|---|
| 158 | ENV_INDENT,
|
|---|
| 159 | ENV_TYPEWRITER
|
|---|
| 160 | };
|
|---|
| 161 |
|
|---|
| 162 | enum lang
|
|---|
| 163 | {
|
|---|
| 164 | LANG_ENGLISH,
|
|---|
| 165 | LANG_GERMAN
|
|---|
| 166 | };
|
|---|
| 167 |
|
|---|
| 168 | enum syntax
|
|---|
| 169 | {
|
|---|
| 170 | SYNTAX_EMX,
|
|---|
| 171 | SYNTAX_DVIDRV
|
|---|
| 172 | };
|
|---|
| 173 |
|
|---|
| 174 | struct special
|
|---|
| 175 | {
|
|---|
| 176 | uchar *text;
|
|---|
| 177 | uchar *ipf;
|
|---|
| 178 | uchar *latex;
|
|---|
| 179 | uchar *html;
|
|---|
| 180 | };
|
|---|
| 181 |
|
|---|
| 182 | struct word
|
|---|
| 183 | {
|
|---|
| 184 | struct word *next;
|
|---|
| 185 | struct word *database;
|
|---|
| 186 | enum style style;
|
|---|
| 187 | uchar *str;
|
|---|
| 188 | uchar *repl;
|
|---|
| 189 | struct special *special;
|
|---|
| 190 | struct word_table *subidx;
|
|---|
| 191 | int ref, idx;
|
|---|
| 192 | uchar flags;
|
|---|
| 193 | };
|
|---|
| 194 |
|
|---|
| 195 | struct word_table;
|
|---|
| 196 |
|
|---|
| 197 | struct element
|
|---|
| 198 | {
|
|---|
| 199 | enum el el;
|
|---|
| 200 | int n;
|
|---|
| 201 | struct word *wp;
|
|---|
| 202 | };
|
|---|
| 203 |
|
|---|
| 204 | struct environment
|
|---|
| 205 | {
|
|---|
| 206 | enum env env;
|
|---|
| 207 | int tmargin;
|
|---|
| 208 | int imargin;
|
|---|
| 209 | int start_line;
|
|---|
| 210 | int counter;
|
|---|
| 211 | };
|
|---|
| 212 |
|
|---|
| 213 | struct toc
|
|---|
| 214 | {
|
|---|
| 215 | struct toc *next;
|
|---|
| 216 | int level;
|
|---|
| 217 | int ref;
|
|---|
| 218 | int print;
|
|---|
| 219 | int global;
|
|---|
| 220 | unsigned flags;
|
|---|
| 221 | uchar *number;
|
|---|
| 222 | uchar *title;
|
|---|
| 223 | };
|
|---|
| 224 |
|
|---|
| 225 | enum enc { ENC_DEFAULT = -3, ENC_AMBIGUOUS = -2, ENC_UNSUPPORTED = -1,
|
|---|
| 226 | ENC_CP850 = 0, ENC_ISO8859_1, ENCODINGS };
|
|---|
| 227 |
|
|---|
| 228 | /* This is the escape character. */
|
|---|
| 229 | EXTERN uchar escape INIT (0xfe);
|
|---|
| 230 |
|
|---|
| 231 | /* The current input line number. */
|
|---|
| 232 | EXTERN int line_no INIT (0);
|
|---|
| 233 |
|
|---|
| 234 | /* The current input line. */
|
|---|
| 235 | EXTERN uchar input[256];
|
|---|
| 236 |
|
|---|
| 237 | /* The input encoding. */
|
|---|
| 238 | EXTERN enum enc input_encoding INIT (ENC_DEFAULT);
|
|---|
| 239 |
|
|---|
| 240 | /* The output encoding. */
|
|---|
| 241 | EXTERN enum enc output_encoding INIT (ENC_DEFAULT);
|
|---|
| 242 |
|
|---|
| 243 | /* This is the processing mode. */
|
|---|
| 244 | EXTERN char mode INIT (0);
|
|---|
| 245 |
|
|---|
| 246 | /* Concatenate instead of call .inf files */
|
|---|
| 247 | EXTERN int opt_a INIT (FALSE);
|
|---|
| 248 |
|
|---|
| 249 | /* Select line break algorithm for text output. */
|
|---|
| 250 | EXTERN int opt_b INIT (0);
|
|---|
| 251 |
|
|---|
| 252 | /* Use color instead of slanted type. */
|
|---|
| 253 | EXTERN int opt_c INIT (FALSE);
|
|---|
| 254 |
|
|---|
| 255 | /* French spacing. */
|
|---|
| 256 | EXTERN int opt_f INIT (FALSE);
|
|---|
| 257 |
|
|---|
| 258 | /* Gather global information. */
|
|---|
| 259 | EXTERN int opt_g INIT (FALSE);
|
|---|
| 260 |
|
|---|
| 261 | /* Display warning messages. */
|
|---|
| 262 | EXTERN int opt_w INIT (0);
|
|---|
| 263 |
|
|---|
| 264 | EXTERN const char *input_fname INIT (NULL);
|
|---|
| 265 |
|
|---|
| 266 | /* The input stream. */
|
|---|
| 267 | EXTERN FILE *input_file INIT (NULL);
|
|---|
| 268 |
|
|---|
| 269 | /* Non-zero if the end of the input file has been reached. */
|
|---|
| 270 | EXTERN int end_of_file INIT (FALSE);
|
|---|
| 271 |
|
|---|
| 272 | /* The output stream. */
|
|---|
| 273 | EXTERN FILE *output_file INIT (NULL);
|
|---|
| 274 |
|
|---|
| 275 | /* The global table of words. */
|
|---|
| 276 | EXTERN struct word_table *word_top INIT (NULL);
|
|---|
| 277 |
|
|---|
| 278 | EXTERN int hl_stack[HL_STACK_SIZE];
|
|---|
| 279 | EXTERN int hl_sp;
|
|---|
| 280 |
|
|---|
| 281 | /* Current line number of the output file. */
|
|---|
| 282 | EXTERN int output_line_no;
|
|---|
| 283 |
|
|---|
| 284 | /* Current column number of the output file. */
|
|---|
| 285 | EXTERN int output_x;
|
|---|
| 286 |
|
|---|
| 287 | /* Non-zero when writing output file (second pass). */
|
|---|
| 288 | EXTERN int out;
|
|---|
| 289 |
|
|---|
| 290 | /* Non-zero while formatting a prototype. */
|
|---|
| 291 | EXTERN int prototype_flag INIT (FALSE);
|
|---|
| 292 |
|
|---|
| 293 | /* The stack of nested environments. */
|
|---|
| 294 | EXTERN struct environment env_stack[ENV_STACK_SIZE];
|
|---|
| 295 |
|
|---|
| 296 | /* Stack pointer for stack of nested environments. */
|
|---|
| 297 | EXTERN int env_sp;
|
|---|
| 298 |
|
|---|
| 299 | /* Current list of formatting elements. */
|
|---|
| 300 | EXTERN struct element *elements INIT (NULL);
|
|---|
| 301 |
|
|---|
| 302 | /* Non-zero if a new paragraph should be started. */
|
|---|
| 303 | EXTERN int para_flag;
|
|---|
| 304 |
|
|---|
| 305 | /* Number of functions. */
|
|---|
| 306 | EXTERN int function_count;
|
|---|
| 307 |
|
|---|
| 308 | /* ... */
|
|---|
| 309 | EXTERN int ref_no INIT (1);
|
|---|
| 310 |
|
|---|
| 311 | /* ... */
|
|---|
| 312 | EXTERN int idx_no INIT (0);
|
|---|
| 313 |
|
|---|
| 314 | /* The title of the document. */
|
|---|
| 315 | EXTERN uchar *title INIT (NULL);
|
|---|
| 316 |
|
|---|
| 317 | /* The language of the document. */
|
|---|
| 318 | EXTERN enum lang language INIT (LANG_ENGLISH);
|
|---|
| 319 |
|
|---|
| 320 | /* Current tag: the tag. */
|
|---|
| 321 | EXTERN enum tag tg_tag;
|
|---|
| 322 |
|
|---|
| 323 | /* Current tag: style. */
|
|---|
| 324 | EXTERN enum style tg_style;
|
|---|
| 325 |
|
|---|
| 326 | /* Current tag: level (for h-, h=, h1 through h3, i1, i2 and index). */
|
|---|
| 327 | EXTERN int tg_level;
|
|---|
| 328 |
|
|---|
| 329 | /* Current tag: character for underlining (for h-, h= and h1 through h3). */
|
|---|
| 330 | EXTERN int tg_underline;
|
|---|
| 331 |
|
|---|
| 332 | /* Current tag: flags (such as HF_UNNUMBERED). */
|
|---|
| 333 | EXTERN unsigned tg_flags;
|
|---|
| 334 |
|
|---|
| 335 |
|
|---|
| 336 | void fatal (const char *fmt, ...) NORETURN2 PRINTF (1, 2);
|
|---|
| 337 | void nonfatal (const char *fmt, ...) PRINTF (1, 2);
|
|---|
| 338 | void warning (int level, const char *fmt, ...) PRINTF (2, 3);
|
|---|
| 339 | void *xmalloc (size_t n);
|
|---|
| 340 | uchar *xstrdup (const uchar *s);
|
|---|
| 341 |
|
|---|
| 342 | struct word_table *wt_new (unsigned hash_size);
|
|---|
| 343 | struct word *wt_find (struct word_table *wt, const uchar *str, unsigned hash);
|
|---|
| 344 | unsigned wt_hash (struct word_table *wt, const uchar *str);
|
|---|
| 345 | struct word *wt_add (struct word_table *wt, const uchar *str);
|
|---|
| 346 | int wt_walk (struct word_table *wt, int (*callback)(struct word *));
|
|---|
| 347 | int wt_count (const struct word_table *wt);
|
|---|
| 348 |
|
|---|
| 349 | struct word *word_find (const uchar *str, unsigned hash);
|
|---|
| 350 | unsigned word_hash (const uchar *str);
|
|---|
| 351 | struct word *word_add (const uchar *str);
|
|---|
| 352 | int word_walk (int (*callback)(struct word *));
|
|---|
| 353 |
|
|---|
| 354 | void write_nl (void);
|
|---|
| 355 | void write_break (void);
|
|---|
| 356 | void write_nstring (const uchar *p, size_t n);
|
|---|
| 357 | void write_string (const uchar *p);
|
|---|
| 358 | void write_line (const uchar *p);
|
|---|
| 359 | void write_fmt (const char *fmt, ...) PRINTF (1, 2);
|
|---|
| 360 | void write_space (void);
|
|---|
| 361 | void format_output (const uchar *p, int may_break);
|
|---|
| 362 | void format_string (const uchar *p, int sty, int may_break);
|
|---|
| 363 | void format_spaces (int n, enum style style, int may_break);
|
|---|
| 364 | void make_elements (const uchar *p);
|
|---|
| 365 | void start_hilite (int hilite);
|
|---|
| 366 | void end_hilite (void);
|
|---|
| 367 | struct word *use_reference (const uchar *p);
|
|---|
| 368 | void open_input (const char *name);
|
|---|
| 369 | void read_line (void);
|
|---|
| 370 | void init_file (void);
|
|---|
| 371 | int parse_tag (const uchar **ptr);
|
|---|
| 372 | void start_index (void);
|
|---|