1 /*-
2 ******************************************************************************
3 ******************************************************************************
4 **
5 **  MODULE
6 **
7 **      $RCSfile: bibtex.h,v $
8 **      $Revision: 3.71 $
9 **      $Date: 1996/08/18 20:47:30 $
10 **
11 **  DESCRIPTION
12 **
13 **      A 32-bit implementation of BibTeX v0.99c for MS-DOS, OS/2 2.x,
14 **      Unix and VMS.  This C language implementation is based on the
15 **      original WEB source but it has been enhanced to support 8-bit input
16 **      characters and a very large processing capacity.
17 **
18 **      For documentation describing how to use and build this program,
19 **      see the 00README.TXT file that accompanies this distribution.
20 **
21 **  MODULE CONTENTS
22 **
23 **      This module defines the macros used in the BibTeX WEB source.
24 **      This file also contains the definitions that determine BibTeX's
25 **      processing capacity.
26 **
27 **  AUTHORS
28 **
29 **      Original WEB translation to C, conversion to "big" (32-bit) capacity,
30 **      addition of run-time selectable capacity and 8-bit support extensions
31 **      by:
32 **
33 **          Niel Kempson
34 **          Snowy Owl Systems Limited, Cheltenham, England
35 **          E-mail: kempson@snowyowl.co.uk
36 **
37 **      8-bit support extensions also by:
38 **
39 **          Alejandro Aguilar-Sierra
40 **          Centro de Ciencias de la Atm\'osfera,
41 **          Universidad Nacional Aut\'onoma de M\'exico, M\'exico
42 **          E-mail: asierra@servidor.unam.mx
43 **
44 **  COPYRIGHT
45 **
46 **      This implementation copyright (c) 1991-1995 by Niel Kempson
47 **           and copyright (c) 1995 by Alejandro Aguilar-Sierra.
48 **
49 **      This program is free software; you can redistribute it and/or
50 **      modify it under the terms of the GNU General Public License as
51 **      published by the Free Software Foundation; either version 1, or
52 **      (at your option) any later version.
53 **
54 **      This program is distributed in the hope that it will be useful,
55 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
56 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
57 **      General Public License for more details.
58 **
59 **      You should have received a copy of the GNU General Public License
60 **      along with this program; if not, write to the Free Software
61 **      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
62 **
63 **      In other words, you are welcome to use, share and improve this
64 **      program.  You are forbidden to forbid anyone else to use, share
65 **      and improve what you give them.  Help stamp out software-hoarding!
66 **
67 **  ACKNOWLEDGEMENT
68 **
69 **      The original BibTeX was written by Oren Patashnik using Donald
70 **      Knuth's WEB system.  This format produces a PASCAL program for
71 **      execution and a TeX documented version of the source code. This
72 **      program started as a (manual) translation of the WEB source into C.
73 **
74 **  CHANGE LOG
75 **
76 **      $Log: bibtex.h,v $
77 **      Revision 3.71  1996/08/18  20:47:30  kempson
78 **      Official release 3.71 (see HISTORY file for details).
79 **
80 **      Revision 3.70  1996/04/08  10:08:40  kempson
81 **      Final documentation & cosmetic changes for official release 3.70.
82 **
83 **      Revision 3.5  1995/09/24  20:44:37  kempson
84 **      Many changes for final beta test version.
85 **
86 **      Revision 3.4  1995/04/09  22:15:43  kempson
87 **      Placed under RCS control
88 **
89 ******************************************************************************
90 ******************************************************************************
91 */
92 #ifndef __BIBTEX_H__
93 #define __BIBTEX_H__                1
94 
95 
96 /***************************************************************************
97  * WEB section number:   1
98  * ~~~~~~~~~~~~~~~~~~~
99  * The BANNER string is defined here and should be changed whenever BibTeX
100  * is modified.
101  ***************************************************************************/
102 #ifdef UTF_8
103 # define BANNER     "This is BibTeXu: a UTF-8 Big BibTeX version 0.99d"
104 # define PROGNAME "bibtexu"
105 # define SUPPORT_8BIT
106 #else
107 # ifdef SUPPORT_8BIT
108 #  define BANNER     "This is 8-bit Big BibTeX version 0.99d"
109 # else
110 #  define BANNER     "This is Big BibTeX version 0.99d"
111 # endif
112 # define PROGNAME "bibtex8"
113 #endif
114 
115 
116 /***************************************************************************
117  * WEB section number:   2
118  * ~~~~~~~~~~~~~~~~~~~
119  * Terminal output goes to the file |TERM_OUT|, while terminal input comes
120  * from |TERM_IN|.  On our system, these (system-dependent) files are
121  * already opened at the beginning of the program.
122  ***************************************************************************/
123 #define TERM_OUT                    stdout
124 #define TERM_IN                     stdin
125 
126 /***************************************************************************
127  * WEB section number:   3
128  * ~~~~~~~~~~~~~~~~~~~
129  * This program uses the term |print| instead of |write| when writing on
130  * both the |log_file| and (system-dependent) |term_out| file, and it
131  * uses |trace_pr| when in |trace| mode, for which it writes on just the
132  * |log_file|.  If you want to change where either set of macros writes
133  * to, you should also change the other macros in this program for that
134  * set; each such macro begins with |print_| or |trace_pr_|.
135  ***************************************************************************/
136 #define PRINT_NEWLINE               print_a_newline ()
137 
138 #define PRINT(X) \
139             {\
140                 if (log_file != NULL)\
141                     FPRINTF (log_file, X);\
142                 FPRINTF (TERM_OUT, X);\
143             }
144 
145 #define PRINT2(X, Y) \
146             {\
147                 if (log_file != NULL)\
148                     FPRINTF (log_file, X, Y);\
149                 FPRINTF (TERM_OUT, X, Y);\
150             }
151 
152 #define PRINT3(X, Y, Z) \
153             {\
154                 if (log_file != NULL)\
155                     FPRINTF (log_file, X, Y, Z);\
156                 FPRINTF (TERM_OUT, X, Y, Z);\
157             }
158 
159 #define PRINT4(W, X, Y, Z) \
160             {\
161                 if (log_file != NULL)\
162                     FPRINTF (log_file, W, X, Y, Z);\
163                 FPRINTF (TERM_OUT, W, X, Y, Z);\
164             }
165 
166 #define PRINT_LN(X) \
167             {\
168                 if (log_file != NULL) {\
169                     FPRINTF (log_file, X); FPUTC ('\n', log_file);\
170                 }\
171                 FPRINTF (TERM_OUT, X); FPUTC('\n', TERM_OUT);\
172             }
173 
174 #define PRINT_LN2(X, Y) \
175             {\
176                 if (log_file != NULL) {\
177                     FPRINTF (log_file, X, Y); FPUTC ('\n', log_file);\
178                 }\
179                 FPRINTF (TERM_OUT, X, Y); FPUTC('\n', TERM_OUT);\
180             }
181 
182 #define PRINT_LN3(X, Y, Z) \
183             {\
184                 if (log_file != NULL) {\
185                     FPRINTF (log_file, X, Y, Z); FPUTC ('\n', log_file);\
186                 }\
187                 FPRINTF (TERM_OUT, X, Y, Z); FPUTC('\n', TERM_OUT);\
188             }
189 
190 #define PRINT_LN4(W, X, Y, Z) \
191             {\
192                 if (log_file != NULL) {\
193                     FPRINTF (log_file, W, X, Y, Z); FPUTC ('\n', log_file);\
194                 }\
195                 FPRINTF (TERM_OUT, W, X, Y, Z); FPUTC('\n', TERM_OUT);\
196             }
197 
198 #define TRACE_PR(X) \
199             if (log_file != NULL) FPRINTF (log_file, X);
200 
201 #define TRACE_PR2(X, Y) \
202             if (log_file != NULL) FPRINTF (log_file, X, Y);
203 
204 #define TRACE_PR3(X, Y, Z) \
205             if (log_file != NULL) FPRINTF (log_file, X, Y, Z);
206 
207 #define TRACE_PR_LN(X) \
208             {\
209                 if (log_file != NULL) {\
210                     FPRINTF (log_file, X);  FPUTC ('\n', log_file);\
211                 }\
212             }
213 
214 #define TRACE_PR_LN2(X, Y) \
215             {\
216                 if (log_file != NULL) {\
217                     FPRINTF (log_file, X, Y); FPUTC ('\n', log_file);\
218                 }\
219             }
220 
221 #define TRACE_PR_LN3(X, Y, Z) \
222             {\
223                 if (log_file != NULL) {\
224                     FPRINTF (log_file, X, Y, Z); FPUTC ('\n', log_file);\
225                 }\
226             }
227 
228 #define TRACE_PR_NEWLINE \
229             {\
230                 if (log_file != NULL)\
231                     FPUTC ('\n', log_file);\
232             }
233 
234 
235 /***************************************************************************
236  * WEB section number:   4
237  * ~~~~~~~~~~~~~~~~~~~
238  * Some of the code is intended to be used only when diagnosing the strange
239  * behaviour that sometimes occurs when BibTeX is being installed or when
240  * system wizards are fooling around with BibTeX without quite knowing what
241  * they are doing. Such code will not normally be compiled; it is delimited
242  * by the preprocessor conditionals `#ifdef DEBUG ... #endif'. Similarly,
243  * there is some conditional code delimited by `#ifdef STAT ... #endif'
244  * that is intended only for use when statistics are to be kept about
245  * BibTeX's memory/CPU usage, and there is conditional code delimited by
246  * `#ifdef TRACE ... #endif' that is intended to be a trace facility for
247  * use mainly when debugging .BST files.
248  ***************************************************************************/
249 #define DEBUG                       1
250 #define STAT                        1
251 #define TRACE                       1
252 
253 /***************************************************************************
254  * WEB section number:   9
255  * ~~~~~~~~~~~~~~~~~~~
256  * Here are some macros for common programming idioms.
257  ***************************************************************************/
258 #define INCR(X)                     ++(X)
259 #define DECR(X)                     --(X)
260 #define LOOP                        while (TRUE)
261 #define DO_NOTHING                  ;
262 #define EMPTY                       0
263 #define ANY_VALUE                   0
264 
265 /***************************************************************************
266  * WEB section number:   14
267  * ~~~~~~~~~~~~~~~~~~~
268  * These parameters may be changed at compile time to extend or reduce
269  * BiBTeX's capacity. They are set to accommodate a maximum of about 750
270  * cites when used with the standard styles.
271  ***************************************************************************/
272 #define MIN_PRINT_LINE              3
273 #define MAX_PRINT_LINE              79
274 #define AUX_STACK_SIZE              20
275 #define MAX_BIB_FILES               20
276 
277 #define BUF_SIZE                   20000
278 #define MAX_CITES                  750
279 #define MAX_FIELDS                 5000
280 #define MAX_STRINGS                4000
281 #define POOL_SIZE                  65000L
282 
283 #define MIN_CROSSREFS               2
284 #define WIZ_FN_SPACE                3000
285 #define SINGLE_FN_SPACE             50
286 #define ENT_STR_SIZE                100
287 #define GLOB_STR_SIZE               1000
288 #define LIT_STK_SIZE                50
289 
290 
291 /***************************************************************************
292  * WEB section number:   15
293  * ~~~~~~~~~~~~~~~~~~~
294  * These parameters can also be changed at compile time, but they're
295  * needed to define some WEB numeric macros so they must be defined
296  * themselves.
297  ***************************************************************************/
298 #define HASH_SIZE                  5000
299 
300 #ifdef MSDOS
301 # define FILE_NAME_SIZE             64
302 #else                           /* NOT MSDOS */
303 # define FILE_NAME_SIZE             255
304 #endif                          /* MSDOS */
305 
306 #define MAX_GLOB_STRS               10
307 
308 /***************************************************************************
309  * WEB section number:   18
310  * ~~~~~~~~~~~~~~~~~~~
311  * A global variable called |history| will contain one of four values at
312  * the end of every run: |spotless| means that no unusual messages were
313  * printed; |warning_message| means that a message of possible interest
314  * was printed but no serious errors were detected; |error_message| means
315  * that at least one error was found; |fatal_message| means that the
316  * program terminated abnormally. The value of |history| does not
317  * influence the behavior of the program; it is simply computed for the
318  * convenience of systems that might want to use such information.
319  ***************************************************************************/
320 #define SPOTLESS                    0
321 #define WARNING_MESSAGE             1
322 #define ERROR_MESSAGE               2
323 #define FATAL_MESSAGE               3
324 
325 /***************************************************************************
326  * WEB section number:   23
327  * ~~~~~~~~~~~~~~~~~~~
328  * We shall use the |text_char| to stand for the data type of the
329  * characters that are converted to and from |ASCIICode_T| when they are
330  * input and output. We shall also assume that |text_char| consists of the
331  * elements |chr[FIRST_TEXT_CHAR]| through |chr[LAST_TEXT_CHAR]| inclusive.
332  * The following definitions should be adjusted if necessary.
333  ***************************************************************************/
334 #define FIRST_TEXT_CHAR             0
335 #define LAST_TEXT_CHAR              255
336 
337 #ifdef SUPPORT_8BIT
338 #define LAST_ASCII_CHAR             255
339 #else
340 #define LAST_ASCII_CHAR             127
341 #endif                          /* SUPPORT_8BIT */
342 
343 
344 /***************************************************************************
345  * WEB section number:   26
346  * ~~~~~~~~~~~~~~~~~~~
347  * Some of the ASCII codes without visible characters have been given
348  * symbolic names in this program because they are used with a special
349  * meaning.  The |tab| character may be system dependent.
350  ***************************************************************************/
351 #define NULL_CODE                   0
352 #define TAB                         9
353 #define SPACE                       32
354 #define INVALID_CODE                127
355 
356 /***************************************************************************
357  * WEB section number:   29
358  * ~~~~~~~~~~~~~~~~~~~
359  * Also, various characters are given symbolic names; all the ones this
360  * program uses are collected here.  We use the sharp sign as the
361  * |concat_char|, rather than something more natural (like an ampersand),
362  * for uniformity of database syntax (ampersand is a valid character in
363  * identifiers).
364  ***************************************************************************/
365 #define DOUBLE_QUOTE                '"'
366 #define NUMBER_SIGN                 '#'
367 #define COMMENT                     '%'
368 #define SINGLE_QUOTE                '\''
369 #define LEFT_PAREN                  '('
370 #define RIGHT_PAREN                 ')'
371 #define COMMA                       ','
372 #define MINUS_SIGN                  '-'
373 #define EQUALS_SIGN                 '='
374 #define AT_SIGN                     '@'
375 #define LEFT_BRACE                  '{'
376 #define RIGHT_BRACE                 '}'
377 #define PERIOD                      '.'
378 #define QUESTION_MARK               '?'
379 #define EXCLAMATION_MARK            '!'
380 #define TIE                         '~'
381 #define HYPHEN                      '-'
382 #define STAR                        '*'
383 #define CONCAT_CHAR                 '#'
384 #define COLON                       ':'
385 #define BACKSLASH                   '\\'
386 
387 /***************************************************************************
388  * WEB section number:   31
389  * ~~~~~~~~~~~~~~~~~~~~
390  * Every character has two types of the lexical classifications.  The
391  * first type is general, and the second type tells whether the character
392  * is legal in identifiers.
393  ***************************************************************************/
394 #define ILLEGAL                     0
395 #define WHITE_SPACE                 1
396 #define ALPHA                       2
397 #define NUMERIC                     3
398 #define SEP_CHAR                    4
399 #define OTHER_LEX                   5
400 #define LAST_LEX                    5
401 #define ILLEGAL_ID_CHAR             0
402 #define LEGAL_ID_CHAR               1
403 
404 /***************************************************************************
405  * WEB section number:   35
406  * ~~~~~~~~~~~~~~~~~~~~
407  * Now we initialize the system-dependent |char_width| array, for which
408  * |space| is the only |white_space| character given a nonzero printing
409  * width.  The widths here are taken from Stanford's June '87 cmr10 font
410  * and represent hundredths of a point (rounded), but since they're used
411  * only for relative comparisons, the units have no meaning.
412  ***************************************************************************/
413 #define SS_WIDTH                    500
414 #define AE_WIDTH                    722
415 #define OE_WIDTH                    778
416 #define UPPER_AE_WIDTH              903
417 #define UPPER_OE_WIDTH              1014
418 
419 /***************************************************************************
420  * WEB section number:   44
421  * ~~~~~~~~~~~~~~~~~~~~
422  * When something in the program wants to be bigger or something out
423  * there wants to be smaller, it's time to call it a run.  Here's the
424  * first of several macros that have associated procedures so that they
425  * produce less inline code.
426  ***************************************************************************/
427 #define BIBTEX_OVERFLOW(X, Y)              {\
428     print_overflow ();\
429     PRINT_LN3 ("%s%ld\n", (X), (long) (Y));\
430     longjmp (Close_Up_Shop_Flag, 1);}
431 
432 /***************************************************************************
433  * WEB section number:   45
434  * ~~~~~~~~~~~~~~~~~~~~
435  * When something happens that the program thinks is impossible, call the
436  * maintainer.
437  ***************************************************************************/
438 #define CONFUSION(X)                {\
439             PRINT (X); print_confusion();\
440             longjmp (Close_Up_Shop_Flag, 1);}
441 #define CONFUSION2(X, Y)            {\
442             PRINT2 (X, Y); print_confusion();\
443             longjmp (Close_Up_Shop_Flag, 1);}
444 
445 /***************************************************************************
446  * WEB section number:   50
447  * ~~~~~~~~~~~~~~~~~~~~
448  * These macros send a string in |str_pool| to an output file.
449  ***************************************************************************/
450 #define MAX_POP                     3
451 #define PRINT_POOL_STR(X)           print_a_pool_str(X)
452 #define TRACE_PR_POOL_STR(X)        { out_pool_str(log_file, X);}
453 
454 /***************************************************************************
455  * WEB section number:  52
456  * ~~~~~~~~~~~~~~~~~~~
457  * Several of the elementary string operations are performed using WEB
458  * macros instead of using PASCAL procedures, because many of the operations
459  * are done quite frequently and we want to avoid the overhead of procedure
460  * calls. For example, here's a simple macro that computes the length of a
461  * string.
462  ***************************************************************************/
463 #define LENGTH(s)                   (str_start[(s)+1] - str_start[s])
464 
465 /***************************************************************************
466  * WEB section number:   53
467  * ~~~~~~~~~~~~~~~~~~~
468  * Strings are created by appending character codes to |str_pool|. The macro
469  * called |append_char|, defined here, does not check to see if the value
470  * of |pool_ptr| is too high; this test is supposed to be made before
471  * |append_char| is used.
472  ***************************************************************************/
473 #define APPEND_CHAR(X)              {str_pool[pool_ptr] = (X);\
474                                      INCR(pool_ptr);}
475 #define STR_ROOM(X)                 {while((pool_ptr+(X))>Pool_Size)\
476                                         pool_overflow();}
477 
478 /***************************************************************************
479  * WEB section number:   55
480  * ~~~~~~~~~~~~~~~~~~~
481  * These macros destroy an recreate the string at the end of the pool.
482  ***************************************************************************/
483 #define FLUSH_STRING                {DECR(str_ptr);\
484                                      pool_ptr=str_start[str_ptr];}
485 #define UNFLUSH_STRING              {INCR(str_ptr);\
486                                      pool_ptr=str_start[str_ptr];}
487 
488 /***************************************************************************
489  * WEB section number:  62
490  * ~~~~~~~~~~~~~~~~~~~
491  * This system-independent procedure converts upper-case characters to
492  * lower case for the specified part of |buf|.  It is system independent
493  * because it uses only the internal representation for characters.
494  ***************************************************************************/
495 #define CASE_DIFFERENCE             ('a' - 'A')
496 
497 /***************************************************************************
498  * WEB section number:   64
499  * ~~~~~~~~~~~~~~~~~~~
500  * All static strings that BibTeX might have to search for, generally
501  * identifiers, are stored and retrieved by means of a fairly standard
502  * hash-table algorithm (but slightly altered here) called the method of
503  * ``coalescing lists'' (cf.\ Algorithm 6.4C in The Art of Computer
504  * Programming).  Once a string enters the table, it is never removed.
505  * The actual sequence of characters forming a string is stored in the
506  * |str_pool| array.
507  ***************************************************************************/
508 #define HASH_BASE                   (EMPTY + 1)
509 #define HASH_MAX                    (HASH_BASE + Hash_Size - 1)
510 #define HASH_IS_FULL                ((hash_used) == (HASH_BASE))
511 #define TEXT_ILK                    0
512 #define INTEGER_ILK                 1
513 #define AUX_COMMAND_ILK             2
514 #define AUX_FILE_ILK                3
515 #define BST_COMMAND_ILK             4
516 #define BST_FILE_ILK                5
517 #define BIB_FILE_ILK                6
518 #define FILE_EXT_ILK                7
519 #define FILE_AREA_ILK               8
520 #define CITE_ILK                    9
521 #define LC_CITE_ILK                 10
522 #define BST_FN_ILK                  11
523 #define BIB_COMMAND_ILK             12
524 #define MACRO_ILK                   13
525 #define CONTROL_SEQ_ILK             14
526 #define LAST_ILK                    14
527 
528 /***************************************************************************
529  * WEB section number:   68
530  * ~~~~~~~~~~~~~~~~~~~
531  * Here is the subroutine that searches the the hash table for a (string,
532  * str_ilk) pair, where the string is of length l >= 0 and appears in
533  * |buffer[j..(j+l-1)]|. If it finds the pair, it returns the corresponding
534  * hash table location and sets the global variable |hash_found| to |TRUE|.
535  * Otherwise is sets |hash_found| to |FALSE|, and if the parameter
536  * |insert_it| is |TRUE|, it inserts the pair into the hash table, inserts
537  * the string into |str_pool| if not previously encountered, and returns its
538  * location. Note that two different pairs can have the same string but
539  * different |str_ilks|, in which case the second pair encountered, if
540  * |insert_it| were |TRUE|, would be inserted into the hash table though its
541  * string wouldn't be inserted into |str_pool| because it would already be
542  * there.
543  ***************************************************************************/
544 #define MAX_HASH_VALUE              (Hash_Prime + Hash_Prime - 2 + 127)
545 #define DO_INSERT                   TRUE
546 #define DONT_INSERT                 FALSE
547 
548 /***************************************************************************
549  * WEB section number:   73
550  * ~~~~~~~~~~~~~~~~~~~
551  * The longest pre-defined string determines type definitions used to
552  * insert the pre-defined strings into |str_pool|.
553  * Set to accommodate the longest translations of the environment variables.
554  ***************************************************************************/
555 #define LONGEST_PDS                 MAX_FILE_NAME
556 
557 /***************************************************************************
558  * WEB section number:   78
559  * ~~~~~~~~~~~~~~~~~~~
560  * These constants all begin with |n_| and are used for the |case|
561  * statement that determines which command to execute.  The variable
562  * |command_num| is set to one of these and is used to do the branching,
563  * but it must have the full |integer| range because at times it can
564  * assume an arbitrary |ilk_info| value (though it will be one of the
565  * values here when we actually use it).
566  ***************************************************************************/
567 #define N_AUX_BIBDATA               0
568 #define N_AUX_BIBSTYLE              1
569 #define N_AUX_CITATION              2
570 #define N_AUX_INPUT                 3
571 
572 #define N_BST_ENTRY                 0
573 #define N_BST_EXECUTE               1
574 #define N_BST_FUNCTION              2
575 #define N_BST_INTEGERS              3
576 #define N_BST_ITERATE               4
577 #define N_BST_MACRO                 5
578 #define N_BST_READ                  6
579 #define N_BST_REVERSE               7
580 #define N_BST_SORT                  8
581 #define N_BST_STRINGS               9
582 
583 #define N_BIB_COMMENT               0
584 #define N_BIB_PREAMBLE              1
585 #define N_BIB_STRING                2
586 
587 /***************************************************************************
588  * WEB section number:   80
589  * ~~~~~~~~~~~~~~~~~~~
590  * This section describes the various |buffer| scanning routines.  The
591  * two global variables |buf_ptr1| and |buf_ptr2| are used in scanning an
592  * input line.  Between scans, |buf_ptr1| points to the first character
593  * of the current token and |buf_ptr2| points to that of the next.  The
594  * global variable |last|, set by the function |input_ln|, marks the end
595  * of the current line; it equals 0 at the end of the current file.  All
596  * the procedures and functions in this section will indicate an
597  * end-of-line when it's the end of the file.
598  ***************************************************************************/
599 #define TOKEN_LEN                   (buf_ptr2 - buf_ptr1)
600 #define SCAN_CHAR                   buffer[buf_ptr2]
601 
602 /***************************************************************************
603  * WEB section number:  81
604  * ~~~~~~~~~~~~~~~~~~~
605  * These macros send the current token, in |buffer[buf_ptr1]| to
606  * |buffer[buf_ptr2-1]|, to an output file.
607  ***************************************************************************/
608 #define PRINT_TOKEN                 print_a_token ();
609 #define TRACE_PR_TOKEN              out_token (log_file);
610 
611 /***************************************************************************
612  * WEB section number:   89
613  * ~~~~~~~~~~~~~~~~~~~
614  * These are the possible values for |scan_result|; they're set by the
615  * |scan_identifier| procedure and are described in the next section.
616  ***************************************************************************/
617 #define ID_NULL                     0
618 #define SPECIFIED_CHAR_ADJACENT     1
619 #define OTHER_CHAR_ADJACENT         2
620 #define WHITE_ADJACENT              3
621 
622 /***************************************************************************
623  * WEB section number:  91
624  * ~~~~~~~~~~~~~~~~~~~
625  * The next two procedures scan for an integer, setting the global
626  * variable |token_value| to the corresponding integer.
627  ***************************************************************************/
628 #define CHAR_VALUE                  (SCAN_CHAR - '0')
629 
630 /***************************************************************************
631  * WEB section number:  93
632  * ~~~~~~~~~~~~~~~~~~~
633  * This procedure scans for an integer, stopping at the first nondigit;
634  * it sets the value of |token_value| accordingly.  It returns |true| if
635  * the token was a legal integer (i.e., consisted of an optional
636  * |minus_sign| followed by one or more digits).
637  ***************************************************************************/
638 #define NEGATIVE                    (sign_length == 1)
639 
640 /***************************************************************************
641  * WEB section number:  98
642  * ~~~~~~~~~~~~~~~~~~~
643  * I mean, this is truly disgraceful ...
644  *
645  * Note: The |term_out| file is system dependent.
646  ***************************************************************************/
647 #define SAM_YOU_MADE_THE_FILE_NAME_TOO {\
648             sam_too_long_file_name_print ();\
649             goto Aux_Not_Found_Label;}
650 
651 /***************************************************************************
652  * WEB section number:  99
653  * ~~~~~~~~~~~~~~~~~~~
654  * We've abused the user enough for one section; suffice it to
655  * say here that most of what we said last module still applies.
656  * Note: The |term_out| file is system dependent.
657  ***************************************************************************/
658 #define SAM_YOU_MADE_THE_FILE_NAME_WRON {\
659             sam_wrong_file_name_print ();\
660             goto Aux_Not_Found_Label;}
661 
662 /***************************************************************************
663  * WEB section number:  104
664  * ~~~~~~~~~~~~~~~~~~~
665  * Here we set up definitions and declarations for files opened in this
666  * section.  Each element in |aux_list| (except for
667  * |aux_list[aux_stack_size]|, which is always unused) is a pointer to
668  * the appropriate |str_pool| string representing the \.{.aux} file name.
669  * The array |aux_file| contains the corresponding \PASCAL\ |file|
670  * variables.
671  ***************************************************************************/
672 #define CUR_AUX_STR                 aux_list[aux_ptr]
673 #define CUR_AUX_FILE                aux_file[aux_ptr]
674 #define CUR_AUX_LINE                aux_ln_stack[aux_ptr]
675 
676 /***************************************************************************
677  * WEB section number:  111
678  * ~~~~~~~~~~~~~~~~~~~
679  * When we find a bug, we print a message and flush the rest of the line.
680  * This macro must be called from within a procedure that has an |exit|
681  * label.
682  ***************************************************************************/
683 #define AUX_ERR_RETURN              {aux_err_print(); goto Exit_Label;}
684 
685 /***************************************************************************
686  * WEB section number:  112
687  * ~~~~~~~~~~~~~~~~~~~
688  * Here are a bunch of macros whose print statements are used at least
689  * twice.  Thus we save space by making the statements procedures.  This
690  * macro complains when there's a repeated command that's to be used just
691  * once.
692  ***************************************************************************/
693 #define AUX_ERR_ILLEGAL_ANOTHER(X)  {aux_err_illegal_another_print (X);\
694                                      AUX_ERR_RETURN;}
695 
696 /***************************************************************************
697  * WEB section number:  113
698  * ~~~~~~~~~~~~~~~~~~~
699  * This one complains when a command is missing its |right_brace|.
700  ***************************************************************************/
701 #define AUX_ERR_NO_RIGHT_BRACE      {\
702             PRINT2 ("No \"%c\"", xchr[RIGHT_BRACE]);\
703             AUX_ERR_RETURN;}
704 
705 /***************************************************************************
706  * WEB section number:  114
707  * ~~~~~~~~~~~~~~~~~~~
708  * This one complains when a command has stuff after its |right_brace|.
709  ***************************************************************************/
710 #define AUX_ERR_STUFF_AFTER_RIGHT_BRACE {\
711             PRINT2 ("Stuff after \"%c\"", xchr[RIGHT_BRACE]);\
712             AUX_ERR_RETURN;}
713 
714 /***************************************************************************
715  * WEB section number:  115
716  * ~~~~~~~~~~~~~~~~~~~
717  * And this one complains when a command has white space in its argument.
718  ***************************************************************************/
719 #define AUX_ERR_WHITE_SPACE_IN_ARGUMENT {\
720             PRINT ("White space in argument");\
721             AUX_ERR_RETURN;}
722 
723 /***************************************************************************
724  * WEB section number:  117
725  * ~~~~~~~~~~~~~~~~~~~
726  * Here we introduce some variables for processing a \.{\\bibdata}
727  * command.  Each element in |bib_list| (except for
728  * |bib_list[max_bib_files]|, which is always unused) is a pointer to the
729  * appropriate |str_pool| string representing the \.{.bib} file name.
730  * The array |bib_file| contains the corresponding \PASCAL\ |file|
731  * variables.
732  ***************************************************************************/
733 #define CUR_BIB_STR                 bib_list[bib_ptr]
734 #define CUR_BIB_FILE                bib_file[bib_ptr]
735 
736 /***************************************************************************
737  * WEB section number:  122
738  * ~~~~~~~~~~~~~~~~~~~
739  * This macro is very similar to aux_err but it complains specifically about
740  * opening a file for a \bibdata command.
741  ***************************************************************************/
742 #define OPEN_BIBDATA_AUX_ERR(X)     {\
743             PRINT (X);\
744             print_bib_name();\
745             AUX_ERR_RETURN;}
746 
747 /***************************************************************************
748  * WEB section number:  129
749  * ~~~~~~~~~~~~~~~~~~~
750  * Here we introduce some variables for processing a \.{\\citation}
751  * command.  Each element in |cite_list| (except for
752  * |cite_list[Max_Cites]|, which is always unused) is a pointer to the
753  * appropriate |str_pool| string.  The cite-key list is kept in order of
754  * occurrence with duplicates removed.
755  ***************************************************************************/
756 #define CUR_CITE_STR                cite_list[cite_ptr]
757 
758 /***************************************************************************
759  * WEB section number:  133
760  * ~~~~~~~~~~~~~~~~~~~
761  * We must check if (the lower-case version of) this cite key has been
762  * previously encountered, and proceed accordingly.  The alias kludge
763  * helps make the stack space not overflow on some machines.
764  ***************************************************************************/
765 #define EX_BUF1                     ex_buf
766 
767 /***************************************************************************
768  * WEB section number:  144
769  * ~~~~~~~~~~~~~~~~~~~
770  * We must complain if anything's amiss.
771  ***************************************************************************/
772 #define AUX_END_ERR(X)              {\
773             aux_end1_err_print();\
774             PRINT (X);\
775             aux_end2_err_print();}
776 
777 /***************************************************************************
778  * WEB section number:   149
779  * ~~~~~~~~~~~~~~~~~~~
780  * When there's a serious error parsing the .bst file, we flush the rest of
781  * the current command; a blank line is assumed to mark the end of a command
782  * (but for the purposes of error recovery only). Thus, error recovery will
783  * be better if style designers leave blank lines between .bst commands.
784  * This macro must be called from within a procedure that has an 'exit'
785  * label.
786  ***************************************************************************/
787 #define BST_ERR_PRINT_AND_LOOK_FOR_BLAN {\
788             bst_err_print_and_look_for_blan();\
789             goto Exit_Label;}
790 
791 #define BST_ERR(X)                  {\
792             PRINT (X);\
793             bst_err_print_and_look_for_blan ();\
794             goto Exit_Label;}
795 
796 #define BST_ERR2(X, Y)              {\
797             PRINT2 (X, Y);\
798             bst_err_print_and_look_for_blan ();\
799             goto Exit_Label;}
800 
801 /***************************************************************************
802  * WEB section number:   150
803  * ~~~~~~~~~~~~~~~~~~~
804  * When there's a harmless error parsing the .bst file (harmless
805  * syntactically, at least) we give just a warning message.
806  ***************************************************************************/
807 #define BST_WARN(X)                 {\
808             PRINT (X); bst_warn_print();}
809 
810 /***************************************************************************
811  * WEB section number:   153
812  * ~~~~~~~~~~~~~~~~~~~
813  * It's often illegal to end a .bst command in certain places, and this is
814  * where we come to check.
815  ***************************************************************************/
816 #define EAT_BST_WHITE_AND_EOF_CHECK(X)  {\
817             if (! eat_bst_white_space()) {\
818                 PRINT (X); BST_ERR(X);}}
819 
820 /***************************************************************************
821  * WEB section number:   156
822  * ~~~~~~~~~~~~~~~~~~~
823  * We need data structures for the function definitions, the entry
824  * variables, the global variables, and the actual entries corresponding
825  * to the cite-key list.  First we define the classes of `function's used.
826  * Functions in all classes are of |bst_fn_ilk| except for |int_literal|s,
827  * which are of |integer_ilk|; and |str_literal|s, which are of
828  * |text_ilk|.
829  ***************************************************************************/
830 #define BUILT_IN                    0
831 #define WIZ_DEFINED                 1
832 #define INT_LITERAL                 2
833 #define STR_LITERAL                 3
834 #define FIELD                       4
835 #define INT_ENTRY_VAR               5
836 #define STR_ENTRY_VAR               6
837 #define INT_GLOBAL_VAR              7
838 #define STR_GLOBAL_VAR              8
839 #define LAST_FN_CLASS               8
840 
841 /***************************************************************************
842  * WEB section number:  160
843  * ~~~~~~~~~~~~~~~~~~~
844  * Besides the function classes, we have types based on \BibTeX's
845  * capacity limitations and one based on what can go into the array
846  * |wiz_functions| explained below.
847  ***************************************************************************/
848 #define QUOTE_NEXT_FN               (HASH_BASE - 1)
849 #define END_OF_DEF                  (HASH_MAX + 1)
850 
851 /***************************************************************************
852  * WEB section number:  161
853  * ~~~~~~~~~~~~~~~~~~~
854  * We store information about the \.{.bst} functions in arrays the same
855  * size as the hash-table arrays and in locations corresponding to their
856  * hash-table locations.  The two arrays |fn_info| (an alias of
857  * |ilk_info| described earlier) and |fn_type| accomplish this: |fn_type|
858  * specifies one of the above classes, and |fn_info| gives information
859  * dependent on the class.
860  ***************************************************************************/
861 #define FN_INFO                     ilk_info
862 #define MISSING                     EMPTY
863 
864 /***************************************************************************
865  * WEB section number:  166
866  * ~~~~~~~~~~~~~~~~~~~
867  * This macro is used to scan all .bst identifiers. The argument supplies
868  * .bst command name. The associated procedure simply prints an error
869  * message.
870  ***************************************************************************/
871 #define BST_IDENTIFIER_SCAN(X)      {\
872         scan_identifier (RIGHT_BRACE, COMMENT, COMMENT);\
873         if ((scan_result == WHITE_ADJACENT) \
874             || (scan_result == SPECIFIED_CHAR_ADJACENT)) {DO_NOTHING;}\
875         else {bst_id_print(); BST_ERR(X)}}
876 
877 /***************************************************************************
878  * WEB section number:  167
879  * ~~~~~~~~~~~~~~~~~~~
880  * This macro just makes sure we're at a |left_brace|.
881  ***************************************************************************/
882 #define BST_GET_AND_CHECK_LEFT_BRACE(X) {\
883         if (SCAN_CHAR != LEFT_BRACE) \
884                 {bst_left_brace_print(); BST_ERR(X);}\
885         INCR (buf_ptr2);}
886 
887 /***************************************************************************
888  * WEB section number:  168
889  * ~~~~~~~~~~~~~~~~~~~
890  * This macro just makes sure we're at a |right_brace|.
891  ***************************************************************************/
892 #define BST_GET_AND_CHECK_RIGHT_BRACE(X)        {\
893         if (SCAN_CHAR != RIGHT_BRACE) \
894                 {bst_right_brace_print(); BST_ERR(X);}\
895         INCR (buf_ptr2);}
896 
897 /***************************************************************************
898  * WEB section number:  169
899  * ~~~~~~~~~~~~~~~~~~~
900  * This macro complains if we've already encountered a function to be
901  * inserted into the hash table.
902  ***************************************************************************/
903 #define CHECK_FOR_ALREADY_SEEN_FUNCTION(X)      {\
904         if (hash_found) {\
905             already_seen_function_print(X);\
906             goto Exit_Label;}}
907 
908 /***************************************************************************
909  * WEB section number:  183
910  * ~~~~~~~~~~~~~~~~~~~
911  * We're about to start scanning tokens in a function definition.  When a
912  * function token is illegal, we skip until it ends; a |white_space|
913  * character, an end-of-line, a |right_brace|, or a |comment| marks the
914  * end of the current token.
915  ***************************************************************************/
916 #define SKIP_TOKEN(X)               {\
917             PRINT (X);\
918             skip_token_print ();\
919             goto Next_Token_Label;}
920 #define SKIP_TOKEN2(X, Y)           {\
921             PRINT2 (X, Y);\
922             skip_token_print ();\
923             goto Next_Token_Label;}
924 
925 /***************************************************************************
926  * WEB section number:  184
927  * ~~~~~~~~~~~~~~~~~~~
928  * This macro is similar to the last one but is specifically for
929  * recursion in a |wiz_defined| function, which is illegal; it helps save
930  * space.
931  ***************************************************************************/
932 #define SKIP_RECURSIVE_TOKEN        { print_recursion_illegal (); \
933                                       goto Next_Token_Label;}
934 
935 /***************************************************************************
936  * WEB section number:  185
937  * ~~~~~~~~~~~~~~~~~~~
938  * Here's another macro for saving some space when there's a problem with
939  * a token.
940  ***************************************************************************/
941 #define SKIP_TOKEN_UNKNOWN_FUNCTION {skp_token_unknown_function_prin ();\
942                                      goto Next_Token_Label;}
943 
944 /***************************************************************************
945  * WEB section number:  186
946  * ~~~~~~~~~~~~~~~~~~~
947  * And another.
948  ***************************************************************************/
949 #define SKIP_TOKEN_ILLEGAL_STUFF_AFTER {\
950             skip_illegal_stuff_after_token ();\
951             goto Next_Token_Label;}
952 
953 /***************************************************************************
954  * WEB section number:  194
955  * ~~~~~~~~~~~~~~~~~~~
956  * This module marks the implicit function as being quoted, generates a
957  * name, and stores it in the hash table.  This name is strictly internal
958  * to this program, starts with a |single_quote| (since that will make
959  * this function name unique), and ends with the variable |impl_fn_num|
960  * converted to ASCII.  The alias kludge helps make the stack space not
961  * overflow on some machines.
962  ***************************************************************************/
963 #define EX_BUF2                     ex_buf
964 
965 /***************************************************************************
966  * WEB section number:  197
967  * ~~~~~~~~~~~~~~~~~~~
968  * This module appends a character to |int_buf| after checking to make
969  * sure it will fit; for use in |int_to_ASCII|.
970  ***************************************************************************/
971 #define APPEND_INT_CHAR(X)          {\
972             if (int_ptr == Buf_Size)\
973                 { buffer_overflow ();}\
974             int_buf[int_ptr] = (X);\
975             INCR (int_ptr); }
976 
977 /***************************************************************************
978  * WEB section number:  216
979  * ~~~~~~~~~~~~~~~~~~~
980  * Here we insert the just found |int_global_var| name into the hash
981  * table and record it as an |int_global_var|.  Also, we initialize it by
982  * setting |fn_info[fn_loc]| to 0.
983  ***************************************************************************/
984 #define END_OF_STRING               INVALID_CODE
985 
986 /***************************************************************************
987  * WEB section number:  219
988  * ~~~~~~~~~~~~~~~~~~~
989  * These global variables are used ...
990  ***************************************************************************/
991 #define UNDEFINED                   (HASH_MAX + 1)
992 
993 /***************************************************************************
994  * WEB section number:  221
995  * ~~~~~~~~~~~~~~~~~~~
996  * When there's a serious error parsing a \.{.bib} file, we flush
997  * everything up to the beginning of the next entry.
998  ***************************************************************************/
999 #define BIB_ERR(X)                  {\
1000             PRINT (X);\
1001             bib_err_print ();\
1002             goto Exit_Label;}
1003 #define BIB_ERR2(X, Y)              {\
1004             PRINT2 (X, Y);\
1005             bib_err_print ();\
1006             goto Exit_Label;}
1007 #define BIB_ERR3(X, Y, Z)                   {\
1008             PRINT3 (X, Y, Z);\
1009             bib_err_print ();\
1010             goto Exit_Label;}
1011 
1012 /***************************************************************************
1013  * WEB section number:  222
1014  * ~~~~~~~~~~~~~~~~~~~
1015  * When there's a harmless error parsing a \.{.bib} file, we just give a
1016  * warning message.  This is always called after other stuff has been
1017  * printed out.
1018  ***************************************************************************/
1019 #define BIB_WARN(X)                 {\
1020             PRINT (X);\
1021             bib_warn_print ();}
1022 #define BIB_WARN_NEWLINE(X)         {\
1023             PRINT_LN (X);\
1024             bib_warn_print ();}
1025 
1026 /***************************************************************************
1027  * WEB section number:  229
1028  * ~~~~~~~~~~~~~~~~~~~
1029  * It's often illegal to end a \.{.bib} command in certain places, and
1030  * this is where we come to check.
1031  ***************************************************************************/
1032 #define EAT_BIB_WHITE_AND_EOF_CHECK {\
1033             if (! eat_bib_white_space())\
1034                 {eat_bib_print();\
1035                 goto Exit_Label;}}
1036 
1037 /***************************************************************************
1038  * WEB section number:  230
1039  * ~~~~~~~~~~~~~~~~~~~
1040  * And here are a bunch of error-message macros, each called more than
1041  * once, that thus save space as implemented.  This one is for when one
1042  * of two possible characters is expected while scanning.
1043  ***************************************************************************/
1044 #define BIB_ONE_OF_TWO_EXPECTED_ERR(X, Y)       {\
1045             bib_one_of_two_print (X, Y);\
1046             goto Exit_Label;}
1047 
1048 /***************************************************************************
1049  * WEB section number:  231
1050  * ~~~~~~~~~~~~~~~~~~~
1051  * This one's for an unexpected equals sign.
1052  ***************************************************************************/
1053 #define BIB_EQUALS_SIGN_EXPECTED_ERR    {\
1054             bib_equals_sign_print ();\
1055             goto Exit_Label;}
1056 
1057 /***************************************************************************
1058  * WEB section number:  232
1059  * ~~~~~~~~~~~~~~~~~~~
1060  * This complains about unbalanced braces.
1061  ***************************************************************************/
1062 #define BIB_UNBALANCED_BRACES_ERR       {\
1063             bib_unbalanced_braces_print ();\
1064             goto Exit_Label;}
1065 
1066 /***************************************************************************
1067  * WEB section number:  233
1068  * ~~~~~~~~~~~~~~~~~~~
1069  * And this one about an overly exuberant field.
1070  ***************************************************************************/
1071 #define BIB_FIELD_TOO_LONG_ERR      {\
1072             bib_field_too_long_print ();\
1073             goto Exit_Label;}
1074 
1075 /***************************************************************************
1076  * WEB section number:  234
1077  * ~~~~~~~~~~~~~~~~~~~
1078  * This one is just a warning, not an error.  It's for when something
1079  * isn't (or might not be) quite right with a macro name.
1080  ***************************************************************************/
1081 #define MACRO_NAME_WARNING(X)       {\
1082             macro_warn_print ();\
1083             BIB_WARN_NEWLINE (X);}
1084 
1085 /***************************************************************************
1086  * WEB section number:  235
1087  * ~~~~~~~~~~~~~~~~~~~
1088  * This macro is used to scan all \.{.bib} identifiers.  The argument
1089  * tells what was happening at the time.  The associated procedure simply
1090  * prints an error message.
1091  ***************************************************************************/
1092 #define BIB_IDENTIFIER_SCAN_CHECK(X)    {\
1093             if ((scan_result == WHITE_ADJACENT) \
1094                 || (scan_result == SPECIFIED_CHAR_ADJACENT)) {DO_NOTHING;}\
1095             else {bib_id_print(); BIB_ERR (X);}}
1096 
1097 /***************************************************************************
1098  * WEB section number:  247
1099  * ~~~~~~~~~~~~~~~~~~~
1100  * The variables for the function
1101  * |scan_and_store_the_field_value_and_eat_white| must be global since
1102  * the functions it calls use them too.  The alias kludge helps make the
1103  * stack space not overflow on some machines.
1104  ***************************************************************************/
1105 #define FIELD_VL_STR                ex_buf
1106 #define FIELD_END                   ex_buf_ptr
1107 #define FIELD_START                 ex_buf_xptr
1108 
1109 /***************************************************************************
1110  * WEB section number:  251
1111  * ~~~~~~~~~~~~~~~~~~~
1112  * Now we come to the stuff that actually accumulates the field value to
1113  * be stored.  This module copies a character into |field_vl_str| if it
1114  * will fit; since it's so low level, it's implemented as a macro.
1115  ***************************************************************************/
1116 #define COPY_CHAR(X)                {\
1117             if (FIELD_END == Buf_Size)\
1118                 { BIB_FIELD_TOO_LONG_ERR; }\
1119             else\
1120                 { FIELD_VL_STR[FIELD_END] = (X);\
1121                 INCR (FIELD_END);}}
1122 
1123 /***************************************************************************
1124  * WEB section number:  252
1125  * ~~~~~~~~~~~~~~~~~~~
1126  * The \.{.bib}-specific scanning function |compress_bib_white| skips
1127  * over |white_space| characters within a string until hitting a nonwhite
1128  * character; in fact, it does everything |eat_bib_white_space| does, but
1129  * it also adds a |space| to |field_vl_str|.  This function is never
1130  * called if there are no |white_space| characters (or ends-of-line) to
1131  * be scanned (though the associated macro might be).  The function
1132  * returns |false| if there is a serious syntax error.
1133  ***************************************************************************/
1134 #define CHECK_FOR_AND_COMPRESS_BIB_WHIT {\
1135             if ((lex_class[SCAN_CHAR] == WHITE_SPACE) || (buf_ptr2 == last)){\
1136                 if (! compress_bib_white ()) { goto Exit_Label;}}}
1137 
1138 /***************************************************************************
1139  * WEB section number:  264
1140  * ~~~~~~~~~~~~~~~~~~~
1141  * If the cross-referenced entry isn't already on |cite_list| we add it
1142  * (at least temporarily); if it is already on |cite_list| we update the
1143  * cross-reference count, if necessary.  Note that |all_entries| is
1144  * |false| here.  The alias kludge helps make the stack space not
1145  * overflow on some machines.
1146  ***************************************************************************/
1147 #define EXTRA_BUF                   out_buf
1148 
1149 /***************************************************************************
1150  * WEB section number:  267
1151  * ~~~~~~~~~~~~~~~~~~~
1152  * The lower-case version of this database key must correspond to one in
1153  * |cite_list|, or else |all_entries| must be |true|, if this entry is to
1154  * be included in the reference list.  Accordingly, this module sets
1155  * |store_entry|, which determines whether the relevant information for
1156  * this entry is stored.  The alias kludge helps make the stack space not
1157  * overflow on some machines.
1158  ***************************************************************************/
1159 #define EX_BUF3                     ex_buf
1160 
1161 /***************************************************************************
1162  * WEB section number:  270
1163  * ~~~~~~~~~~~~~~~~~~~
1164  * This module, a simpler version of the
1165  * |find_cite_locs_for_this_cite_key| function, exists primarily to
1166  * compute |lc_xcite_loc|.  When this code is executed we have
1167  * |(all_entries) and (entry_cite_ptr >= all_marker) and (not
1168  * entry_exists[entry_cite_ptr])|.  The alias kludge helps make the stack
1169  * space not overflow on some machines.
1170  ***************************************************************************/
1171 #define EX_BUF4                     ex_buf
1172 #define EX_BUF4_PTR                 ex_buf_ptr
1173 
1174 /***************************************************************************
1175  * WEB section number:  277
1176  * ~~~~~~~~~~~~~~~~~~~
1177  * Occasionally we need to figure out the hash-table location of a given
1178  * cite-key string and its lower-case equivalent.  This function does
1179  * that.  To perform the task it needs to borrow a buffer, a need that
1180  * gives rise to the alias kludge---it helps make the stack space not
1181  * overflow on some machines (and while it's at it, it'll borrow a
1182  * pointer, too).  Finally, the function returns |true| if the cite key
1183  * exists on |cite_list|, and its sets |cite_hash_found| according to
1184  * whether or not it found the actual version (before |lower_case|ing) of
1185  * the cite key; however, its {\sl raison d'\^$\mkern-8mu$etre\/}
1186  * (literally, ``to eat a raisin'') is to compute |cite_loc| and
1187  * |lc_cite_loc|.
1188  ***************************************************************************/
1189 #define EX_BUF5                     ex_buf
1190 #define EX_BUF5_PTR                 ex_buf_ptr
1191 
1192 /***************************************************************************
1193  * WEB section number:  289
1194  * ~~~~~~~~~~~~~~~~~~~
1195  * The array |sorted_cites| initially specifies that the entries are to
1196  * be processed in order of cite-key occurrence.  The \.{sort} command
1197  * may change this to whatever it likes (which, we hope, is whatever the
1198  * style-designer instructs it to like).  We make |sorted_cites| an alias
1199  * to save space; this works fine because we're done with |cite_info|.
1200  ***************************************************************************/
1201 #define SORTED_CITES                cite_info
1202 
1203 /***************************************************************************
1204  * WEB section number:  291
1205  * ~~~~~~~~~~~~~~~~~~~
1206  * Where |lit_stk_loc| is a stack location, and where |stk_type| gives
1207  * one of the three types of literals (an integer, a string, or a
1208  * function) or a special marker.  If a |lit_stk_type| element is a
1209  * |stk_int| then the corresponding |lit_stack| element is an integer; if
1210  * a |stk_str|, then a pointer to a |str_pool| string; and if a |stk_fn|,
1211  * then a pointer to the function's hash-table location.  However, if the
1212  * literal should have been a |stk_str| that was the value of a field
1213  * that happened to be |missing|, then the special value
1214  * |stk_field_missing| goes on the stack instead; its corresponding
1215  * |lit_stack| element is a pointer to the field-name's string.  Finally,
1216  * |stk_empty| is the type of a literal popped from an empty stack.
1217  ***************************************************************************/
1218 #define STK_INT                     0
1219 #define STK_STR                     1
1220 #define STK_FN                      2
1221 #define STK_FIELD_MISSING           3
1222 #define STK_EMPTY                   4
1223 #define LAST_LIT_TYPE               4
1224 
1225 /***************************************************************************
1226  * WEB section number:  293
1227  * ~~~~~~~~~~~~~~~~~~~
1228  * When there's an error while executing \.{.bst} functions, what we do
1229  * depends on whether the function is messing with the entries.
1230  * Furthermore this error is serious enough to classify as an
1231  * |error_message| instead of a |warning_message|.  These messages (that
1232  * is, from |bst_ex_warn|) are meant both for the user and for the style
1233  * designer while debugging.
1234  ***************************************************************************/
1235 #define BST_EX_WARN(X)              {\
1236             PRINT (X); bst_ex_warn_print ();}
1237 #define BST_EX_WARN2(X, Y)          {\
1238             PRINT2 (X, Y); bst_ex_warn_print ();}
1239 
1240 /***************************************************************************
1241  * WEB section number:  294
1242  * ~~~~~~~~~~~~~~~~~~~
1243  * When an error is so harmless, we print a warning message instead of an
1244  * error message.
1245  ***************************************************************************/
1246 #define BST_MILD_EX_WARN(X)                 {\
1247             PRINT (X); bst_mild_ex_warn_print ();}
1248 
1249 /***************************************************************************
1250  * WEB section number:  301
1251  * ~~~~~~~~~~~~~~~~~~~
1252  * The function |less_than| compares the two \.{sort.key\$}s indirectly
1253  * pointed to by its arguments and returns |true| if the first argument's
1254  * \.{sort.key\$} is lexicographically less than the second's (that is,
1255  * alphabetically earlier).  In case of ties the function compares the
1256  * indices |arg1| and |arg2|, which are assumed to be different, and
1257  * returns |true| if the first is smaller.  This function uses
1258  * |ASCII_code|s to compare, so it might give ``interesting'' results
1259  * when handling nonletters.
1260  ***************************************************************************/
1261 #define COMPARE_RETURN(X)           {\
1262             less_than = (X);\
1263             goto Exit_Label;}
1264 
1265 /***************************************************************************
1266  * WEB section number:  302
1267  * ~~~~~~~~~~~~~~~~~~~
1268  * The recursive procedure |quick_sort| sorts ...
1269  ***************************************************************************/
1270 #define SHORT_LIST                  10
1271 #define END_OFFSET                  4
1272 
1273 /***************************************************************************
1274  * WEB section number:  308
1275  * ~~~~~~~~~~~~~~~~~~~
1276  * This macro pushes the last thing, necessarily a string, that was
1277  * popped.  And this module, along with others that push the literal
1278  * stack without explicitly calling |push_lit_stack|, have an index entry
1279  * under ``push the literal stack''; these implicit pushes collectively
1280  * speed up the program by about ten percent.
1281  ***************************************************************************/
1282 #define REPUSH_STRING               {\
1283             if (lit_stack[lit_stk_ptr] >= cmd_str_ptr)\
1284                 { UNFLUSH_STRING; }\
1285             INCR (lit_stk_ptr);}
1286 
1287 /***************************************************************************
1288  * WEB section number:  319
1289  * ~~~~~~~~~~~~~~~~~~~
1290  * These macros append a character to |ex_buf|.  Which is called depends
1291  * on whether the character is known to fit.
1292  ***************************************************************************/
1293 #define APPEND_EX_BUF_CHAR(X)       {\
1294             ex_buf[ex_buf_ptr] = (X);\
1295             INCR(ex_buf_ptr);}
1296 #define APPEND_EX_BUF_CHAR_AND_CHECK(X)    {\
1297             if (ex_buf_ptr == Buf_Size) {buffer_overflow ();}; \
1298             APPEND_EX_BUF_CHAR(X)}
1299 
1300 /***************************************************************************
1301  * WEB section number:   333
1302  * ~~~~~~~~~~~~~~~~~~~
1303  * These constants all begin with |n_| and are used for the |case|
1304  * statement that determines which |built_in| function to execute.
1305  ***************************************************************************/
1306 #define N_EQUALS                    0
1307 #define N_GREATER_THAN              1
1308 #define N_LESS_THAN                 2
1309 #define N_PLUS                      3
1310 #define N_MINUS                     4
1311 #define N_CONCATENATE               5
1312 #define N_GETS                      6
1313 #define N_ADD_PERIOD                7
1314 #define N_CALL_TYPE                 8
1315 #define N_CHANGE_CASE               9
1316 #define N_CHR_TO_INT                10
1317 #define N_CITE                      11
1318 #define N_DUPLICATE                 12
1319 #define N_EMPTY                     13
1320 #define N_FORMAT_NAME               14
1321 #define N_IF                        15
1322 #define N_INT_TO_CHR                16
1323 #define N_INT_TO_STR                17
1324 #define N_MISSING                   18
1325 #define N_NEWLINE                   19
1326 #define N_NUM_NAMES                 20
1327 #define N_POP                       21
1328 #define N_PREAMBLE                  22
1329 #define N_PURIFY                    23
1330 #define N_QUOTE                     24
1331 #define N_SKIP                      25
1332 #define N_STACK                     26
1333 #define N_SUBSTRING                 27
1334 #define N_SWAP                      28
1335 #define N_TEXT_LENGTH               29
1336 #define N_TEXT_PREFIX               30
1337 #define N_TOP_STACK                 31
1338 #define N_TYPE                      32
1339 #define N_WARNING                   33
1340 #define N_WHILE                     34
1341 #define N_WIDTH                     35
1342 #define N_WRITE                     36
1343 #define NUM_BLT_IN_FNS              37
1344 
1345 /***************************************************************************
1346  * WEB section number:  338
1347  * ~~~~~~~~~~~~~~~~~~~
1348  * These constants all begin with |n_| and are used for the |case|
1349  * statement that determines which, if any, control sequence we're
1350  * dealing with; a control sequence of interest will be either one of the
1351  * undotted characters `\.{\\i}' or `\.{\\j}' or one of the foreign
1352  * characters in Table~3.2 of the \LaTeX\ manual.
1353  ***************************************************************************/
1354 #define N_I                         0
1355 #define N_J                         1
1356 #define N_OE                        2
1357 #define N_OE_UPPER                  3
1358 #define N_AE                        4
1359 #define N_AE_UPPER                  5
1360 #define N_AA                        6
1361 #define N_AA_UPPER                  7
1362 #define N_O                         8
1363 #define N_O_UPPER                   9
1364 #define N_L                         10
1365 #define N_L_UPPER                   11
1366 #define N_SS                        12
1367 
1368 /***************************************************************************
1369  * WEB section number:  344
1370  * ~~~~~~~~~~~~~~~~~~~
1371  * These are nonrecursive variables that |execute_fn| uses.  Declaring
1372  * them here (instead of in the previous module) saves execution time and
1373  * stack space on most machines.
1374  ***************************************************************************/
1375 #define NAME_BUF                    sv_buffer
1376 
1377 /***************************************************************************
1378  * WEB section number:  356
1379  * ~~~~~~~~~~~~~~~~~~~
1380  * It's time for a complaint if either of the two (entry or global) string
1381  * lengths is exceeded.
1382  ***************************************************************************/
1383 #define BST_STRING_SIZE_EXCEEDED(X, Y)  {\
1384             bst_1print_string_size_exceeded ();\
1385             PRINT3 ("%ld%s", (long) (X), Y);\
1386             bst_2print_string_size_exceeded ();}
1387 
1388 /***************************************************************************
1389  * WEB section number:  365
1390  * ~~~~~~~~~~~~~~~~~~~
1391  * First we define a few variables for case conversion.  The constant
1392  * definitions, to be used in |case| statements, are in order of probable
1393  * frequency.
1394  ***************************************************************************/
1395 #define TITLE_LOWERS                0
1396 #define ALL_LOWERS                  1
1397 #define ALL_UPPERS                  2
1398 #define BAD_CONVERSION              3
1399 
1400 /***************************************************************************
1401  * WEB section number:  397
1402  * ~~~~~~~~~~~~~~~~~~~
1403  * It's a von token if there exists a first brace-level-0 letter (or
1404  * brace-level-1 special character), and it's in lower case; in this case
1405  * we return |true|.  The token is in |name_buf|, starting at
1406  * |name_bf_ptr| and ending just before |name_bf_xptr|.
1407  ***************************************************************************/
1408 #define RETURN_VON_FOUND            {\
1409             von_token_found = TRUE;\
1410             goto Exit_Label;}
1411 
1412 /***************************************************************************
1413  * WEB section number:  417
1414  * ~~~~~~~~~~~~~~~~~~~
1415  * Here we output either the \.{.bst} given string if it exists, or else
1416  * the \.{.bib} |sep_char| if it exists, or else the default string.  A
1417  * |tie| is the default space character between the last two tokens of
1418  * the name part, and between the first two tokens if the first token is
1419  * short enough; otherwise, a |space| is the default.
1420  ***************************************************************************/
1421 #define LONG_TOKEN                  3
1422 
1423 /***************************************************************************
1424  * WEB section number:  419
1425  * ~~~~~~~~~~~~~~~~~~~
1426  * If the last character output for this name part is a |tie| but the
1427  * previous character it isn't, we're dealing with a discretionary |tie|;
1428  * thus we replace it by a |space| if there are enough characters in the
1429  * rest of the name part.
1430  ***************************************************************************/
1431 #define LONG_NAME                   3
1432 
1433 /***************************************************************************
1434  * WEB section number:  465
1435  * ~~~~~~~~~~~~~~~~~~~
1436  * These statistics can help determine how large some of the constants
1437  * should be and can tell how useful certain |built_in| functions are.
1438  * They are written to the same files as tracing information.
1439  ***************************************************************************/
1440 #define STAT_PR                     TRACE_PR
1441 #define STAT_PR2                    TRACE_PR2
1442 #define STAT_PR3                    TRACE_PR3
1443 
1444 #define STAT_PR_LN                  TRACE_PR_LN
1445 #define STAT_PR_LN2                 TRACE_PR_LN2
1446 #define STAT_PR_LN3                 TRACE_PR_LN3
1447 
1448 #define STAT_PR_POOL_STR            TRACE_PR_POOL_STR
1449 
1450 
1451 /***************************************************************************
1452  * WEB section number:  N/A
1453  * ~~~~~~~~~~~~~~~~~~~
1454  * C isn't very good at declaring two dimensional arrays whose sizes are
1455  * determined at run time.  Here we create a useful macro to simulate
1456  * accessing a 2D array by converting the row/col into an offset from the
1457  * beginning of a 1D array.
1458  ***************************************************************************/
1459 #define ENTRY_STRS(_r,_c)       entry_strs[(_r * (Ent_Str_Size+1)) + _c]
1460 #define GLOBAL_STRS(_r,_c)      global_strs[(_r * (Glob_Str_Size+1)) + _c]
1461 
1462 
1463 /***************************************************************************
1464  * WEB section number:  N/A
1465  * ~~~~~~~~~~~~~~~~~~~
1466  * Define a macro to handle 1-, 2-, 3-, and 4-byte UTF-8 codes.
1467  ***************************************************************************/
1468 #define DO_UTF8(ch, do_1, do_2, do_3, do_4) \
1469   if (ch <= 0x7F) { do_1; } \
1470   else if ((ch >= 0xC2) && (ch <= 0xDF)) { do_2; } \
1471   else if ((ch >= 0xE0) && (ch <= 0xEF)) { do_3; } \
1472   else if ((ch >= 0xF0) && (ch <= 0xF4)) { do_4; } \
1473   else printf("this isn't a right UTF-8 char!\n")
1474 
1475 
1476 /***************************************************************************
1477  * WEB section number:  N/A
1478  * ~~~~~~~~~~~~~~~~~~~
1479  * Macros adapted from Kpathsea (lib.h) and Web2C (cpascal.h) to dynamically
1480  * resize arrays.
1481  ***************************************************************************/
1482 /* Reallocate N items of type T for ARRAY using myrealloc.  */
1483 #define MYRETALLOC(array, addr, n, t) ((addr) = (t *) myrealloc(addr, (n) * sizeof(t), array))
1484 /* BibTeX needs this to dynamically reallocate arrays.  Too bad we can't
1485    rely on stringification, or we could avoid the ARRAY_NAME arg.
1486    Actually allocate one more than requests, so we can index the last
1487    entry, as Pascal wants to do.  */
1488 #define BIB_XRETALLOC_NOSET(array_name, array_var, type, size_var, new_size) \
1489   if (log_file != NULL)\
1490     fprintf (log_file, "Reallocated %s (elt_size=%d) to %ld items from %ld.\n", \
1491              array_name, (int) sizeof (type), new_size, size_var); \
1492   MYRETALLOC (array_name, array_var, new_size + 1, type)
1493 /* Same as above, but also increase SIZE_VAR for the last (or only) array.  */
1494 #define BIB_XRETALLOC(array_name, array_var, type, size_var, new_size) do { \
1495   BIB_XRETALLOC_NOSET(array_name, array_var, type, size_var, new_size); \
1496   size_var = new_size; \
1497 } while (0)
1498 /* Same as above, but for the pseudo-TYPE ASCIICode_T[LENGTH+1].  */
1499 #define BIB_XRETALLOC_STRING(array_name, array_var, length, size_var, new_size) \
1500   if (log_file != NULL)\
1501     fprintf (log_file, "Reallocated %s (elt_size=%d) to %ld items from %ld.\n", \
1502              array_name, (int) (length + 1), new_size, size_var); \
1503   MYRETALLOC (array_name, array_var, (new_size) * (length + 1), ASCIICode_T)
1504 
1505 #endif                          /* __BIBTEX_H__ */
1506 
1507