Back to index

tetex-bin  3.0
mkind.h
Go to the documentation of this file.
00001 /*
00002  *
00003  *  This file is part of
00004  *     MakeIndex - A formatter and format independent index processor
00005  *
00006  *  Copyright (C) 1989 by Chen & Harrison International Systems, Inc.
00007  *  Copyright (C) 1988 by Olivetti Research Center
00008  *  Copyright (C) 1987 by Regents of the University of California
00009  *
00010  *  Author:
00011  *     Pehong Chen
00012  *     Chen & Harrison International Systems, Inc.
00013  *     Palo Alto, California
00014  *     USA
00015  *     (phc@renoir.berkeley.edu or chen@orc.olivetti.com)
00016  *
00017  *  Contributors:
00018  *     Please refer to the CONTRIB file that comes with this release
00019  *     for a list of people who have contributed to this and/or previous
00020  *     release(s) of MakeIndex.
00021  *
00022  *  All rights reserved by the copyright holders.  See the copyright
00023  *  notice distributed with this software for a complete description of
00024  *  the conditions under which it is made available.
00025  *
00026  */
00027 
00028 #include "c-auto.h"
00029 
00030 /***********************************************************************
00031 
00032                         INSTALLATION NOTES
00033                            <11-Nov-1989>
00034 
00035    At compile-time (or here, if compile-time definition is not
00036    available), set non-zero ONE OS_xxxx operating system flag, and if
00037    more than one compiler is available, ONE compiler flag:
00038 
00039     Operating Systems        Compiler(s)
00040     =================        ===========
00041     OS_ATARI
00042     OS_BS2000                CCD_2000
00043     OS_BSD
00044     OS_MVSXA                 IBM_C370
00045     OS_VMCMS                 IBM_C370
00046     OS_PCDOS                 IBM_PC_MICROSOFT
00047     OS_SYSV
00048     OS_TOPS20                KCC_20 or PCC_20
00049     OS_VAXVMS
00050     OS_XENIX
00051     =================        ===========
00052 
00053    If no OS_xxxx symbol is defined, OS_BSD is assumed.
00054 
00055    If Standard C prototypes are supported, define the symbol
00056    STDC_PROTOTYPES in the appropriate OS_xxxx section below, and insert
00057    #include's for the standard system files which define library
00058    prototypes.  STDC_PROTOTYPES will be defined automatically if
00059    __STDC__ is; the latter must be defined by all Standard C conformant
00060    implementations.
00061 
00062    All function declarations in MakeIndex are contained at the end of
00063    this file.  If 185STDC_PROTOTYPES is not selected, then all the standard
00064    library functions must be declared explicitly.
00065 
00066    If the host system restricts external names to 6 characters, set
00067    SHORTNAMES non-zero in the appropriate OS_xxxx section below.
00068 
00069    Installing MakeIndex under BS2000 requires at least Version 8.5
00070    supporting Multiple Public Volume Sets (MPVS). Define WORK in this
00071    file to your CATID (default :w:) for temporary files (.ilg, .ind),
00072    in case of no MPVS support define WORK to NIL.
00073 
00074 */
00075 
00076 /**********************************************************************/
00077 
00078 #define STDC  (__STDC__ || __cplusplus)
00079 
00080 /*
00081  * Establish needed operating symbols (defaulting to OS_BSD if none
00082  * specified at compile time).  If you add one, add it to the check
00083  * list at the end of this section, too.
00084  */
00085 
00086 #define SHORTNAMES 0
00087 #define STDC_PROTOTYPES STDC
00088 
00089 /**********************************************************************/
00090 
00091 #ifndef USE_KPATHSEA
00092 #define USE_KPATHSEA 1
00093 #endif
00094 
00095 #if USE_KPATHSEA
00096 #ifndef DEBUG     /* strange logic: makeindex uses DEBUG to force debugging */
00097 #define NO_DEBUG  /* kpathsea uses NO_DEBUG to suppress it.                 */
00098 #endif
00099 #include <kpathsea/config.h>
00100 #include <kpathsea/c-limits.h>
00101 #include <kpathsea/c-memstr.h>
00102 #include <kpathsea/magstep.h>
00103 #include <kpathsea/proginit.h>
00104 #include <kpathsea/progname.h>
00105 #include <kpathsea/tex-glyph.h>
00106 #include <kpathsea/expand.h>
00107 #include <c-auto.h>
00108 #endif
00109 
00110 #include    <stdio.h>
00111 
00112 #ifdef HAVE_CTYPE_H
00113 #include    <ctype.h>
00114 #endif
00115 
00116 #ifndef HAVE_STRCHR
00117 #define strchr  index                  /* convert STDC form to old K&R form */
00118 #endif
00119 
00120 #ifndef HAVE_STRRCHR
00121 #define strrchr rindex                 /* convert STDC form to old K&R form */
00122 #endif
00123 
00124 #ifdef HAVE_STRING_H
00125 #include <string.h>
00126 #else
00127 #ifdef HAVE_STRINGS_H
00128 #include <string.h>
00129 #endif
00130 #endif
00131 
00132 #ifdef HAVE_TYPES_H
00133 #include <types.h>
00134 #endif
00135 
00136 #if    SHORTNAMES
00137 /*
00138  * Provide alternate external names which are unique in the first SIX
00139  * characters as required for portability (and Standard C)
00140  */
00141 #define check_all          chk_all
00142 #define check_idx          chk_idx
00143 #define check_mixsym       chk_mix
00144 #define compare_one        cmp_one
00145 #define compare_page       cmp_page
00146 #define compare_string     cmp_string
00147 #define delim_n            dlm_n
00148 #define delim_p            dlm_p
00149 #define delim_r            dlm_r
00150 #define delim_t            dlm_t
00151 #define encap_i            ecp_i
00152 #define encap_p            ecp_p
00153 #define encap_range        ecp_range
00154 #define encap_s            ecp_s
00155 #define group_skip         grp_skip
00156 #define group_type         grp_type
00157 #define idx_aclose         idxaclose
00158 #define idx_actual         idxactual
00159 #define idx_keyword        idx_kwd
00160 #define indent_length      ind_length
00161 #define indent_space       ind_space
00162 #define headings_flag      hd_flag
00163 #define heading_pre        hd_pre
00164 #define heading_suf        hd_suf
00165 #define symhead_pos        sym_pos
00166 #define symhead_neg        sym_neg
00167 #define numhead_pos        num_pos
00168 #define numhead_neg        num_neg
00169 #define process_idx        prc_idx
00170 #define process_precedence prc_pre
00171 #define range_ptr          rng_ptr
00172 #define scan_alpha_lower   scnalw
00173 #define scan_alpha_upper   scnaup
00174 #define scan_arabic        scnarabic
00175 #define scan_arg1          scna1
00176 #define scan_arg2          scna2
00177 #define scan_char          scnchr
00178 #define scan_field         scnfld
00179 #define scan_idx           scnidx
00180 #define scan_key           scnkey
00181 #define scan_no            scnno
00182 #define scan_roman_lower   scnrlw
00183 #define scan_roman_upper   scnrup
00184 #define scan_spec          scnspc
00185 #define scan_string        scnstr
00186 #define scan_style         scnsty
00187 #define setpagelen         spg_len
00188 #define setpage_close      spg_close
00189 #define setpage_open       spg_open
00190 #define suffix_2p          suf_2p
00191 #define suffix_3p          suf_3p
00192 #define suffix_mp          suf_mp
00193 #endif                                 /* SHORTNAMES */
00194 
00195 #define EXIT exit
00196 
00197 #undef TRUE
00198 #define TRUE 1
00199 
00200 #undef FALSE
00201 #define FALSE 0
00202 
00203 #undef NUL
00204 #define NUL '\0'
00205 
00206 #undef NIL
00207 #define NIL ""
00208 
00209 #define TAB '\t'
00210 #define LFD '\n'
00211 #define SPC ' '
00212 #define LSQ '['
00213 #define RSQ ']'
00214 #define BSH '\\'
00215 
00216 #ifdef DOSISH
00217 #define ENV_SEPAR ';'
00218 #define DIR_DELIM '/'
00219 #define ALT_DIR_DELIM '\\'
00220 #define IS_DIR_DELIM(c) ((c) == DIR_DELIM || (c) == ALT_DIR_DELIM)
00221 #else  /* not DOSISH */
00222 #define ENV_SEPAR ':'
00223 #define DIR_DELIM '/'
00224 #define IS_DIR_DELIM(c) ((c) == DIR_DELIM)
00225 #endif /* not DOSISH */
00226 
00227 #ifndef SW_PREFIX                  /* can override at compile time */
00228 #define SW_PREFIX  '-'
00229 #endif
00230 
00231 #define EXT_DELIM  '.'
00232 #define ROMAN_SIGN '*'
00233 #define EVEN       "even"
00234 #define ODD        "odd"
00235 #define ANY        "any"
00236 
00237 #define GET_CHAR getc
00238 
00239 #define TOASCII(i) (char)((i) + 48)
00240 
00241 /* NB: The typecasts here are CRITICAL for correct sorting of entries
00242    that use characters in the range 128..255! */
00243 #define TOLOWER(C) (isupper((unsigned char)(C)) ? \
00244        (unsigned char)tolower((unsigned char)(C)) : (unsigned char)(C))
00245 #define TOUPPER(C) (isupper((unsigned char)(C)) ? \
00246        (unsigned char)(C) : (unsigned char)toupper((unsigned char)(C)))
00247 
00248 #if USE_KPATHSEA /* kpathsea defines STREQ */
00249 #undef STREQ
00250 #undef STRNEQ
00251 #endif
00252 
00253 #define STREQ(A, B)  (strcmp(A, B) == 0)
00254 #define STRNEQ(A, B) (strcmp(A, B) != 0)
00255 
00256 #define MESSAGE(F, S) { \
00257     if (verbose) \
00258        fprintf(stderr, F, S); \
00259     fprintf(ilg_fp, F, S); \
00260 }
00261 
00262 #if USE_KPATHSEA /* kpathsea defines a different FATAL */
00263 #undef FATAL
00264 #endif
00265 
00266 #define FATAL(F, S) { \
00267     fprintf(stderr, F, S); \
00268     fprintf(stderr, USAGE, pgm_fn); \
00269     EXIT(1); \
00270 }
00271 
00272 #if USE_KPATHSEA /* kpathsea defines a different FATAL2 */
00273 #undef FATAL2
00274 #endif
00275 
00276 #define FATAL2(F, D1, D2) { \
00277     fprintf(stderr, F, D1, D2); \
00278     fprintf(stderr, USAGE, pgm_fn); \
00279     EXIT(1); \
00280 }
00281 
00282 #define OPEN_IN(FP)   fopen(FP, "r")
00283 #define OPEN_OUT(FP)  fopen(FP, "w")
00284 #define CLOSE(FP)     fclose(FP)
00285 
00286 #define ISDIGIT(C)  ('0' <= C && C <= '9')
00287 #define ISSYMBOL(C) (('!' <= C && C <= '@') || \
00288                    ('[' <= C && C <= '`') || \
00289                    ('{' <= C && C <= '~'))
00290 
00291 /*====================================================================
00292 Many arrays in MakeIndex are dimensioned [xxx_MAX], where the xxx_MAX
00293 values are defined below.  The use of each of these is described in
00294 comments.  However, no run-time check is made to ensure that these are
00295 consistent, or reasonable!  Therefore, change them only with great
00296 care.
00297 
00298 The array sizes should be made generously large: there are a great
00299 many uses of strings in MakeIndex with the strxxx() and sprintf()
00300 functions where no checking is done for adequate target storage sizes.
00301 Although some input checking is done to avoid this possibility, it is
00302 highly likely that there are still several places where storage
00303 violations are possible, with core dumps, or worse, incorrect output,
00304 ensuing.
00305 ======================================================================*/
00306 
00307 #define ARABIC_MAX    10    /* maximum digits in an Arabic page */
00308                             /* number field */
00309 
00310 #define ARGUMENT_MAX  1024  /* maximum length of sort or actual key */
00311                             /* in index entry */
00312 
00313 #define ARRAY_MAX     1024  /* maximum length of constant values in */
00314                             /* style file */
00315 
00316 #define FIELD_MAX    3      /* maximum levels of index entries (item, */
00317                             /* subitem, subsubitem); cannot be */
00318                             /* increased beyond 3 without */
00319                             /* significant design changes (no field */
00320                             /* names are known beyond 3 levels) */
00321 
00322 #ifdef LINE_MAX             /* IBM RS/6000 AIX has this in <sys/limits.h> */
00323 #undef LINE_MAX
00324 #endif
00325 #define LINE_MAX      72    /* maximum output line length (longer */
00326                             /* ones wrap if possible) */
00327 
00328 #define NUMBER_MAX    16    /* maximum digits in a Roman or Arabic */
00329                             /* page number */
00330                             /* (MAX(ARABIC_MAX,ROMAN_MAX)) */
00331 
00332 #define PAGEFIELD_MAX 10    /* maximum fields in a composite page */
00333                             /* number */
00334 
00335 #define PAGETYPE_MAX  5            /* fixed at 5; see use in scanst.c */
00336 
00337 #define ROMAN_MAX     16    /* maximum length of Roman page number */
00338                             /* field */
00339 
00340 #define STRING_MAX    256   /* maximum length of host filename */
00341 
00342 /*====================================================================*/
00343 
00344 #if USE_KPATHSEA
00345 #define VERSION       "version 2.14 [02-Oct-2002] (kpathsea + Thai support)"
00346 #else
00347 #define VERSION       "version 2.14 [02-Oct-2002] (with Thai support)"
00348 #endif
00349 
00350 #define PUT_VERSION { \
00351     MESSAGE("This is %s, ", pgm_fn); \
00352     MESSAGE("%s.\n", VERSION); \
00353     need_version = FALSE; \
00354 }
00355 
00356 #ifdef HAVE_SETLOCALE
00357 #define USAGE \
00358    "Usage: %s [-ilqrcgLT] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n"
00359 #else
00360 #define USAGE \
00361    "Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n"
00362 #endif
00363 
00364 #define STYLE_PATH "INDEXSTYLE"    /* environment variable defining search */
00365                             /* path for style files */
00366 #define INDEX_IDX  ".idx"
00367 #define INDEX_ILG  ".ilg"
00368 #define INDEX_IND  ".ind"
00369 #define INDEX_STY  ".mst"
00370 
00371 #define INDEX_LOG  ".log"
00372 
00373 #define EMPTY     -9999
00374 #define ROML      0
00375 #define ROMU      1
00376 #define ARAB      2
00377 #define ALPL      3
00378 #define ALPU      4
00379 #define DUPLICATE 9999
00380 
00381 #define SYMBOL -1
00382 #define ALPHA  -2
00383 
00384 #define GERMAN 0
00385 
00386 typedef struct KFIELD
00387 {
00388     char    *sf[FIELD_MAX];        /* sort key */
00389     char    *af[FIELD_MAX];        /* actual key */
00390     int     group;                 /* key group */
00391     char    lpg[NUMBER_MAX];              /* literal page */
00392     int     npg[PAGEFIELD_MAX];           /* page field array */
00393     short   count;                 /* page field count */
00394     short   type;                  /* page number type */
00395     char    *encap;                /* encapsulator */
00396     char    *fn;                   /* input filename */
00397     int     lc;                           /* line number */
00398 }      FIELD, *FIELD_PTR;
00399 
00400 typedef struct KNODE
00401 {
00402     FIELD   data;
00403     struct KNODE *next;
00404 }      NODE, *NODE_PTR;
00405 
00406 extern int letter_ordering;
00407 extern int compress_blanks;
00408 extern int init_page;
00409 extern int merge_page;
00410 extern int even_odd;
00411 extern int verbose;
00412 extern int german_sort;
00413 extern int thai_sort;
00414 extern int locale_sort;
00415 
00416 extern char idx_keyword[ARRAY_MAX];
00417 extern char idx_aopen;
00418 extern char idx_aclose;
00419 extern char idx_level;
00420 extern char idx_ropen;
00421 extern char idx_rclose;
00422 extern char idx_quote;
00423 extern char idx_actual;
00424 extern char idx_encap;
00425 extern char idx_escape;
00426 
00427 extern char page_comp[ARRAY_MAX];
00428 extern int page_offset[PAGETYPE_MAX];
00429 
00430 extern char preamble[ARRAY_MAX];
00431 extern char postamble[ARRAY_MAX];
00432 extern char setpage_open[ARRAY_MAX];
00433 extern char setpage_close[ARRAY_MAX];
00434 extern char group_skip[ARRAY_MAX];
00435 extern int headings_flag;
00436 extern char heading_pre[ARRAY_MAX];
00437 extern char heading_suf[ARRAY_MAX];
00438 extern char symhead_pos[ARRAY_MAX];
00439 extern char symhead_neg[ARRAY_MAX];
00440 extern char numhead_pos[ARRAY_MAX];
00441 extern char numhead_neg[ARRAY_MAX];
00442 extern int prelen;
00443 extern int postlen;
00444 extern int skiplen;
00445 extern int headprelen;
00446 extern int headsuflen;
00447 extern int setpagelen;
00448 
00449 extern char item_r[FIELD_MAX][ARRAY_MAX];
00450 extern char item_u[FIELD_MAX][ARRAY_MAX];
00451 extern char item_x[FIELD_MAX][ARRAY_MAX];
00452 extern int ilen_r[FIELD_MAX];
00453 extern int ilen_u[FIELD_MAX];
00454 extern int ilen_x[FIELD_MAX];
00455 
00456 extern char delim_p[FIELD_MAX][ARRAY_MAX];
00457 extern char delim_n[ARRAY_MAX];
00458 extern char delim_r[ARRAY_MAX];
00459 extern char delim_t[ARRAY_MAX];
00460 
00461 extern char suffix_2p[ARRAY_MAX];
00462 extern char suffix_3p[ARRAY_MAX];
00463 extern char suffix_mp[ARRAY_MAX];
00464 
00465 extern char encap_p[ARRAY_MAX];
00466 extern char encap_i[ARRAY_MAX];
00467 extern char encap_s[ARRAY_MAX];
00468 
00469 extern int linemax;
00470 extern char indent_space[ARRAY_MAX];
00471 extern int indent_length;
00472 
00473 extern FILE *idx_fp;
00474 extern FILE *sty_fp;
00475 extern FILE *ind_fp;
00476 extern FILE *ilg_fp;
00477 
00478 extern char *idx_fn;
00479 extern char *pgm_fn;
00480 extern char *ind_fn;
00481 extern char *ilg_fn;
00482 
00483 #ifndef MKIND_C
00484 extern char sty_fn[];
00485 extern char ind[];
00486 extern char ilg[];
00487 extern char pageno[];
00488 
00489 #ifdef DEBUG
00490 extern long totmem;
00491 #endif /* DEBUG */
00492 
00493 #endif
00494 
00495 extern FIELD_PTR *idx_key;
00496 extern NODE_PTR head;
00497 extern NODE_PTR tail;
00498 
00499 extern int idx_dot;
00500 extern int idx_tt;
00501 extern int idx_gt;
00502 extern int idx_et;
00503 extern int idx_dc;
00504 
00505 #define DOT     "."
00506 #define DOT_MAX 1000
00507 #define CMP_MAX 1500
00508 
00509 #define IDX_DOT(MAX) { \
00510     idx_dot = TRUE; \
00511     if (idx_dc++ == 0) { \
00512        if (verbose) \
00513            fprintf(stderr, DOT); \
00514        fprintf(ilg_fp, DOT); \
00515     } \
00516     if (idx_dc == MAX) \
00517        idx_dc = 0; \
00518 }
00519 
00520 #define ALL_DONE { \
00521     if (fn_no > 0) { \
00522        if (verbose) \
00523 fprintf(stderr, \
00524        "Overall %d files read (%d entries accepted, %d rejected).\n", \
00525        fn_no+1, idx_gt, idx_et); \
00526 fprintf(ilg_fp, \
00527        "Overall %d files read (%d entries accepted, %d rejected).\n", \
00528        fn_no+1, idx_gt, idx_et); \
00529     } \
00530 }
00531 
00532 #define DONE(A, B, C, D) { \
00533     if (verbose) \
00534        fprintf(stderr, "done (%d %s, %d %s).\n", (A), B, C, D); \
00535     fprintf(ilg_fp, "done (%d %s, %d %s).\n", (A), B, C, D); \
00536 }
00537 
00538 #if    STDC_PROTOTYPES
00539 #define ARGS(arg_list)      arg_list
00540 #define VOIDP        void*
00541 #define VOID_ARG     void
00542 #else
00543 #define ARGS(arg_list)      ()
00544 #define const
00545 #define VOIDP        char*
00546 #define VOID_ARG
00547 #endif
00548 
00549 extern void gen_ind ARGS((void));
00550 extern int group_type ARGS((char *str));
00551 extern int main ARGS((int argc, char **argv));
00552 extern void qqsort ARGS((char *base, int n, int size,
00553               int (*compar)ARGS((char*,char*))));
00554 extern void scan_idx ARGS((void));
00555 extern void scan_sty ARGS((void));
00556 extern void sort_idx ARGS((void));
00557 extern int strtoint ARGS((char *str));
00558 
00559 #if STDC
00560 #ifdef HAVE_STDLIB_H
00561 #include <stdlib.h>
00562 #endif
00563 #if __NeXT__
00564 int    access ARGS((const char *, int));
00565 #else
00566 #ifdef HAVE_UNISTD_H
00567 #include <unistd.h>
00568 #endif
00569 #endif
00570 #else
00571 /* Miscellaneous standard library routines */
00572 int    access ARGS((const char *, int));
00573 
00574 char   *getenv ARGS((const char *name));
00575 
00576 char   *strchr ARGS((const char *s,int c));
00577 char   *strrchr ARGS((const char *s,int c));
00578 #ifndef USE_KPATHSEA
00579 VOIDP  calloc ARGS((size_t nitems,size_t size));
00580 VOIDP  malloc ARGS((size_t size));
00581 #endif
00582 #endif /* __STDC__ */
00583 
00584 #ifndef    R_OK
00585 #define R_OK 4                         /* only symbol from sys/file.h */
00586 #endif