w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

mkind.h
Go to the documentation of this file.
1 /*
2  *
3  * This file is part of
4  * MakeIndex - A formatter and format independent index processor
5  *
6  * Copyright (C) 1998-2019 by the TeX Live project.
7  * Copyright (C) 1989 by Chen & Harrison International Systems, Inc.
8  * Copyright (C) 1988 by Olivetti Research Center
9  * Copyright (C) 1987 by Regents of the University of California
10  *
11  * Author:
12  * Pehong Chen
13  * Chen & Harrison International Systems, Inc.
14  * Palo Alto, California
15  * USA
16  *
17  * Contributors:
18  * Please refer to the CONTRIB file that comes with this release
19  * for a list of people who have contributed to this and/or previous
20  * release(s) of MakeIndex.
21  *
22  * All rights reserved by the copyright holders. See the copyright
23  * notice distributed with this software for a complete description of
24  * the conditions under which it is made available.
25  *
26  */
27 
28 #include <c-auto.h>
29 
30 /***********************************************************************
31 
32  INSTALLATION NOTES
33  <11-Nov-1989>
34 
35  At compile-time (or here, if compile-time definition is not
36  available), set non-zero ONE OS_xxxx operating system flag, and if
37  more than one compiler is available, ONE compiler flag:
38 
39  Operating Systems Compiler(s)
40  ================= ===========
41  OS_ATARI
42  OS_BS2000 CCD_2000
43  OS_BSD
44  OS_MVSXA IBM_C370
45  OS_VMCMS IBM_C370
46  OS_PCDOS IBM_PC_MICROSOFT
47  OS_SYSV
48  OS_TOPS20 KCC_20 or PCC_20
49  OS_VAXVMS
50  OS_XENIX
51  ================= ===========
52 
53  If no OS_xxxx symbol is defined, OS_BSD is assumed.
54 
55  Standard C prototypes are now required.
56 
57  All function declarations in MakeIndex are contained at the end of
58  this file.
59 
60  If the host system restricts external names to 6 characters, set
61  SHORTNAMES non-zero in the appropriate OS_xxxx section below.
62 
63  Installing MakeIndex under BS2000 requires at least Version 8.5
64  supporting Multiple Public Volume Sets (MPVS). Define WORK in this
65  file to your CATID (default :w:) for temporary files (.ilg, .ind),
66  in case of no MPVS support define WORK to NIL.
67 
68 */
69 
70 /**********************************************************************/
71 
72 /*
73  * Establish needed operating symbols (defaulting to OS_BSD if none
74  * specified at compile time). If you add one, add it to the check
75  * list at the end of this section, too.
76  */
77 
78 #define SHORTNAMES 0
79 
80 /**********************************************************************/
81 
82 #ifndef USE_KPATHSEA
83 #define USE_KPATHSEA 1
84 #endif
85 
86 #if USE_KPATHSEA
87 #ifndef DEBUG /* strange logic: makeindex uses DEBUG to force debugging */
88 #define NO_DEBUG 1 /* kpathsea uses NO_DEBUG to suppress it. */
89 #endif
90 #include <kpathsea/config.h>
91 #include <kpathsea/c-limits.h>
92 #include <kpathsea/c-memstr.h>
93 #include <kpathsea/magstep.h>
94 #include <kpathsea/proginit.h>
95 #include <kpathsea/progname.h>
96 #include <kpathsea/tex-glyph.h>
97 #include <kpathsea/expand.h>
98 #endif
99 
100 #include <stdio.h>
101 
102 #ifdef HAVE_CTYPE_H
103 #include <ctype.h>
104 #endif
105 
106 #ifndef HAVE_STRCHR
107 #define strchr index /* convert STDC form to old K&R form */
108 #endif
109 
110 #ifndef HAVE_STRRCHR
111 #define strrchr rindex /* convert STDC form to old K&R form */
112 #endif
113 
114 #ifdef HAVE_STRING_H
115 #include <string.h>
116 #else
117 #ifdef HAVE_STRINGS_H
118 #include <string.h>
119 #endif
120 #endif
121 
122 #ifdef HAVE_TYPES_H
123 #include <types.h>
124 #endif
125 
126 #if SHORTNAMES
127 /*
128  * Provide alternate external names which are unique in the first SIX
129  * characters as required for portability (and Standard C)
130  */
131 #define check_all chk_all
132 #define check_idx chk_idx
133 #define check_mixsym chk_mix
134 #define compare_one cmp_one
135 #define compare_page cmp_page
136 #define compare_string cmp_string
137 #define delim_n dlm_n
138 #define delim_p dlm_p
139 #define delim_r dlm_r
140 #define delim_t dlm_t
141 #define encap_i ecp_i
142 #define encap_p ecp_p
143 #define encap_range ecp_range
144 #define encap_s ecp_s
145 #define group_skip grp_skip
146 #define group_type grp_type
147 #define idx_aclose idxaclose
148 #define idx_actual idxactual
149 #define idx_keyword idx_kwd
150 #define indent_length ind_length
151 #define indent_space ind_space
152 #define headings_flag hd_flag
153 #define heading_pre hd_pre
154 #define heading_suf hd_suf
155 #define symhead_pos sym_pos
156 #define symhead_neg sym_neg
157 #define numhead_pos num_pos
158 #define numhead_neg num_neg
159 #define process_idx prc_idx
160 #define process_precedence prc_pre
161 #define range_ptr rng_ptr
162 #define scan_alpha_lower scnalw
163 #define scan_alpha_upper scnaup
164 #define scan_arabic scnarabic
165 #define scan_arg1 scna1
166 #define scan_arg2 scna2
167 #define scan_char scnchr
168 #define scan_field scnfld
169 #define scan_idx scnidx
170 #define scan_key scnkey
171 #define scan_no scnno
172 #define scan_roman_lower scnrlw
173 #define scan_roman_upper scnrup
174 #define scan_spec scnspc
175 #define scan_string scnstr
176 #define scan_style scnsty
177 #define setpagelen spg_len
178 #define setpage_close spg_close
179 #define setpage_open spg_open
180 #define suffix_2p suf_2p
181 #define suffix_3p suf_3p
182 #define suffix_mp suf_mp
183 #endif /* SHORTNAMES */
184 
185 #define EXIT exit
186 
187 #undef TRUE
188 #define TRUE 1
189 
190 #undef FALSE
191 #define FALSE 0
192 
193 #undef NUL
194 #define NUL '\0'
195 
196 #undef NIL
197 #define NIL ""
198 
199 #define TAB '\t'
200 #define LFD '\n'
201 #define SPC ' '
202 #define LSQ '['
203 #define RSQ ']'
204 #define BSH '\\'
205 
206 #ifdef DOSISH
207 #define ENV_SEPAR ';'
208 #define DIR_DELIM '/'
209 #define ALT_DIR_DELIM '\\'
210 #define IS_DIR_DELIM(c) ((c) == DIR_DELIM || (c) == ALT_DIR_DELIM)
211 #else /* not DOSISH */
212 #define ENV_SEPAR ':'
213 #define DIR_DELIM '/'
214 #define IS_DIR_DELIM(c) ((c) == DIR_DELIM)
215 #endif /* not DOSISH */
216 
217 #ifndef SW_PREFIX /* can override at compile time */
218 #define SW_PREFIX '-'
219 #endif
220 
221 #define EXT_DELIM '.'
222 #define ROMAN_SIGN '*'
223 #define EVEN "even"
224 #define ODD "odd"
225 #define ANY "any"
226 
227 extern int mk_getc (FILE *str); /* line endings patch */
228 #define GET_CHAR mk_getc
229 
230 #define TOASCII(i) (char)((i) + 48)
231 
232 /* NB: The typecasts here are CRITICAL for correct sorting of entries
233  that use characters in the range 128..255! */
234 #define TOLOWER(C) (isupper((unsigned char)(C)) ? \
235  (unsigned char)tolower((unsigned char)(C)) : (unsigned char)(C))
236 #define TOUPPER(C) (isupper((unsigned char)(C)) ? \
237  (unsigned char)(C) : (unsigned char)toupper((unsigned char)(C)))
238 
239 #if USE_KPATHSEA /* kpathsea defines STREQ */
240 #undef STREQ
241 #undef STRNEQ
242 #endif
243 
244 #define STREQ(A, B) (strcmp(A, B) == 0)
245 #define STRNEQ(A, B) (strcmp(A, B) != 0)
246 
247 #define MESSAGE(F) { \
248  if (verbose) \
249  fprintf(stderr, F); \
250  fprintf(ilg_fp, F); \
251 }
252 
253 #define MESSAGE1(F, S) { \
254  if (verbose) \
255  fprintf(stderr, F, S); \
256  fprintf(ilg_fp, F, S); \
257 }
258 
259 #if USE_KPATHSEA /* kpathsea defines a different FATAL */
260 #undef FATAL
261 #endif
262 
263 #define FATAL(F) { \
264  fprintf(stderr, F); \
265  fprintf(stderr, USAGE, pgm_fn); \
266  EXIT(1); \
267 }
268 
269 #if USE_KPATHSEA /* kpathsea defines a different FATAL1 */
270 #undef FATAL1
271 #endif
272 
273 #define FATAL1(F, S) { \
274  fprintf(stderr, F, S); \
275  fprintf(stderr, USAGE, pgm_fn); \
276  EXIT(1); \
277 }
278 
279 #if USE_KPATHSEA /* kpathsea defines a different FATAL2 */
280 #undef FATAL2
281 #endif
282 
283 #define FATAL2(F, D1, D2) { \
284  fprintf(stderr, F, D1, D2); \
285  fprintf(stderr, USAGE, pgm_fn); \
286  EXIT(1); \
287 }
288 
289 #define OPEN_IN(FP) fopen(FP, "rb")
290 #define OPEN_OUT(FP) fopen(FP, "wb")
291 #define CLOSE(FP) fclose(FP)
292 
293 #define ISDIGIT(C) ('0' <= C && C <= '9')
294 #define ISSYMBOL(C) (('!' <= C && C <= '@') || \
295  ('[' <= C && C <= '`') || \
296  ('{' <= C && C <= '~'))
297 
298 /*====================================================================
299 Many arrays in MakeIndex are dimensioned [xxx_MAX], where the xxx_MAX
300 values are defined below. The use of each of these is described in
301 comments. However, no run-time check is made to ensure that these are
302 consistent, or reasonable! Therefore, change them only with great
303 care.
304 
305 If any array overflows, please report to tex-k@tug.org.
306 ======================================================================*/
307 
308 #define ARABIC_MAX 99 /* maximum digits in an Arabic page */
309  /* number field */
310 
311 #define ARGUMENT_MAX 10240 /* maximum length of sort or actual key */
312  /* in index entry */
313 
314 #define ARRAY_MAX 1024 /* maximum length of constant values in */
315  /* style file */
316 
317 #define FIELD_MAX 3 /* maximum levels of index entries (item, */
318  /* subitem, subsubitem); cannot be */
319  /* increased beyond 3 without */
320  /* significant design changes (no field */
321  /* names are known beyond 3 levels) */
322 
323 #ifdef LINE_MAX /* IBM RS/6000 AIX has this in <sys/limits.h> */
324 #undef LINE_MAX
325 #endif
326 #define LINE_MAX 72 /* maximum output line length (longer */
327  /* ones wrap if possible) */
328 
329 #define NUMBER_MAX 99 /* maximum digits in a Roman or Arabic */
330  /* page number */
331  /* (MAX(ARABIC_MAX,ROMAN_MAX)) */
332 
333 #define PAGEFIELD_MAX 10 /* maximum fields in a composite page */
334  /* number */
335 
336 #define PAGETYPE_MAX 5 /* fixed at 5; see use in scanst.c */
337 
338 #define ROMAN_MAX 99 /* maximum length of Roman page number */
339  /* field */
340 
341 #define STRING_MAX 999 /* maximum length of host filename */
342 
343 /*====================================================================*/
344 
345 #if USE_KPATHSEA
346 #define VERSION "version 2.15 [TeX Live " TEX_LIVE_VERSION "] (kpathsea + Thai support)"
347 #else
348 #define VERSION "version 2.15 [20-Nov-2007] (with Thai support)"
349 #endif
350 
351 #define PUT_VERSION { \
352  MESSAGE1("This is %s, ", pgm_fn); \
353  MESSAGE1("%s.\n", VERSION); \
354  need_version = FALSE; \
355 }
356 
357 #ifdef HAVE_SETLOCALE
358 #define USAGE \
359  "Usage: %s [-ilqrcgLT] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n"
360 #else
361 #define USAGE \
362  "Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n"
363 #endif
364 
365 #define STYLE_PATH "INDEXSTYLE" /* environment variable defining search */
366  /* path for style files */
367 #define INDEX_IDX ".idx"
368 #define INDEX_ILG ".ilg"
369 #define INDEX_IND ".ind"
370 #define INDEX_STY ".mst"
371 
372 #define INDEX_LOG ".log"
373 
374 #define EMPTY -9999
375 #define ROML 0
376 #define ROMU 1
377 #define ARAB 2
378 #define ALPL 3
379 #define ALPU 4
380 #undef DUPLICATE /* may already be defined for WIN32 */
381 #define DUPLICATE 9999
382 
383 #define SYMBOL -1
384 #define ALPHA -2
385 
386 #define GERMAN 0
387 
388 typedef struct KFIELD
389 {
390  char *sf[FIELD_MAX]; /* sort key */
391  char *af[FIELD_MAX]; /* actual key */
392  int group; /* key group */
393  char lpg[NUMBER_MAX]; /* literal page */
394  int npg[PAGEFIELD_MAX]; /* page field array */
395  short count; /* page field count */
396  short type; /* page number type */
397  char *encap; /* encapsulator */
398  const char *fn; /* input filename */
399  int lc; /* line number */
401 
402 typedef struct KNODE
403 {
405  struct KNODE *next;
407 
408 extern int letter_ordering;
409 extern int compress_blanks;
410 extern int init_page;
411 extern int merge_page;
412 extern int even_odd;
413 extern int verbose;
414 extern int german_sort;
415 extern int thai_sort;
416 extern int locale_sort;
417 
418 extern char idx_keyword[ARRAY_MAX];
419 extern char idx_aopen;
420 extern char idx_aclose;
421 extern char idx_level;
422 extern char idx_ropen;
423 extern char idx_rclose;
424 extern char idx_quote;
425 extern char idx_actual;
426 extern char idx_encap;
427 extern char idx_escape;
428 
429 extern char page_comp[ARRAY_MAX];
430 extern int page_offset[PAGETYPE_MAX];
431 
432 extern char preamble[ARRAY_MAX];
433 extern char postamble[ARRAY_MAX];
434 extern char setpage_open[ARRAY_MAX];
435 extern char setpage_close[ARRAY_MAX];
436 extern char group_skip[ARRAY_MAX];
437 extern int headings_flag;
438 extern char heading_pre[ARRAY_MAX];
439 extern char heading_suf[ARRAY_MAX];
440 extern char symhead_pos[ARRAY_MAX];
441 extern char symhead_neg[ARRAY_MAX];
442 extern char numhead_pos[ARRAY_MAX];
443 extern char numhead_neg[ARRAY_MAX];
444 extern int prelen;
445 extern int postlen;
446 extern int skiplen;
447 extern int headprelen;
448 extern int headsuflen;
449 extern int setpagelen;
450 
451 extern char item_r[FIELD_MAX][ARRAY_MAX];
452 extern char item_u[FIELD_MAX][ARRAY_MAX];
453 extern char item_x[FIELD_MAX][ARRAY_MAX];
454 extern int ilen_r[FIELD_MAX];
455 extern int ilen_u[FIELD_MAX];
456 extern int ilen_x[FIELD_MAX];
457 
458 extern char delim_p[FIELD_MAX][ARRAY_MAX];
459 extern char delim_n[ARRAY_MAX];
460 extern char delim_r[ARRAY_MAX];
461 extern char delim_t[ARRAY_MAX];
462 
463 extern char suffix_2p[ARRAY_MAX];
464 extern char suffix_3p[ARRAY_MAX];
465 extern char suffix_mp[ARRAY_MAX];
466 
467 extern char encap_p[ARRAY_MAX];
468 extern char encap_i[ARRAY_MAX];
469 extern char encap_s[ARRAY_MAX];
470 
471 extern int linemax;
472 extern char indent_space[ARRAY_MAX];
473 extern int indent_length;
474 
475 extern FILE *idx_fp;
476 extern FILE *sty_fp;
477 extern FILE *ind_fp;
478 extern FILE *ilg_fp;
479 
480 extern const char *idx_fn;
481 extern const char *pgm_fn;
482 extern const char *ind_fn;
483 extern const char *ilg_fn;
484 
485 #ifndef MKIND_C
486 extern char sty_fn[];
487 extern char ind[];
488 extern char ilg[];
489 extern char pageno[];
490 
491 #ifdef DEBUG
492 extern long totmem;
493 #endif /* DEBUG */
494 
495 #endif
496 
497 extern FIELD_PTR *idx_key;
498 extern NODE_PTR head;
499 extern NODE_PTR tail;
500 
501 extern int idx_dot;
502 extern int idx_tt;
503 extern int idx_gt;
504 extern int idx_et;
505 extern int idx_dc;
506 
507 #define DOT "."
508 #define DOT_MAX 1000
509 #define CMP_MAX 1500
510 
511 #define IDX_DOT(MAX) { \
512  idx_dot = TRUE; \
513  if (idx_dc++ == 0) { \
514  if (verbose) \
515  fprintf(stderr, DOT); \
516  fprintf(ilg_fp, DOT); \
517  } \
518  if (idx_dc == MAX) \
519  idx_dc = 0; \
520 }
521 
522 #define ALL_DONE { \
523  if (fn_no > 0) { \
524  if (verbose) \
525 fprintf(stderr, \
526  "Overall %d files read (%d entries accepted, %d rejected).\n", \
527  fn_no+1, idx_gt, idx_et); \
528 fprintf(ilg_fp, \
529  "Overall %d files read (%d entries accepted, %d rejected).\n", \
530  fn_no+1, idx_gt, idx_et); \
531  } \
532 }
533 
534 #define DONE(A, B, C, D) { \
535  if (verbose) \
536  fprintf(stderr, "done (%d %s, %d %s).\n", (A), B, C, D); \
537  fprintf(ilg_fp, "done (%d %s, %d %s).\n", (A), B, C, D); \
538 }
539 
540 extern void gen_ind (void);
541 extern int group_type (const char *str);
542 extern void scan_idx (void);
543 extern void scan_sty (void);
544 extern void sort_idx (void);
545 extern int strtoint (char *str);
546 
547 #ifdef HAVE_STDLIB_H
548 #include <stdlib.h>
549 #endif
550 #if __NeXT__
551 int access (const char *, int);
552 #else
553 #ifdef HAVE_UNISTD_H
554 #include <unistd.h>
555 #endif
556 #endif
557 
558 #ifndef R_OK
559 #define R_OK 4 /* only symbol from sys/file.h */
560 #endif
#define access
Definition: win32lib.h:59
int idx_dot
Definition: mkind.c:42
char preamble[1024]
Definition: scanst.c:46
char item_r[3][1024]
Definition: scanst.c:70
int verbose
Definition: pnmhistmap.c:30
char symhead_pos[1024]
Definition: scanst.c:64
int indent_length
Definition: scanst.c:93
char idx_quote
Definition: scanst.c:41
int idx_tt
Definition: mkind.c:44
char idx_ropen
Definition: scanst.c:39
void scan_sty(void)
Definition: scanst.c:116
char symhead_neg[1024]
Definition: scanst.c:65
const char * pgm_fn
Definition: mkind.c:55
NODE_PTR head
Definition: scanid.c:43
int german_sort
Definition: mkind.c:38
int ilen_u[3]
Definition: scanst.c:75
#define PAGEFIELD_MAX
Definition: mkind.h:333
struct KNODE * NODE_PTR
char item_x[3][1024]
Definition: scanst.c:72
struct KFIELD FIELD
char pageno[]
Definition: mkind.c:62
FIELD_PTR * idx_key
Definition: mkind.c:48
char indent_space[1024]
Definition: scanst.c:94
char delim_t[1024]
Definition: scanst.c:81
char group_skip[1024]
Definition: scanst.c:55
FILE * sty_fp
Definition: mkind.c:50
const char * ind_fn
Definition: mkind.c:59
int mk_getc(FILE *str)
Definition: mkind.c:86
int idx_gt
Definition: mkind.c:46
char delim_n[1024]
Definition: scanst.c:79
const char * ilg_fn
Definition: mkind.c:61
FILE * ilg_fp
Definition: mkind.c:53
struct KNODE NODE
char ind[]
Definition: mkind.c:58
char suffix_2p[1024]
Definition: scanst.c:83
char idx_aopen
Definition: scanst.c:36
int linemax
Definition: scanst.c:91
int idx_dc
Definition: scanid.c:36
int thai_sort
Definition: mkind.c:39
int headsuflen
Definition: scanst.c:62
char setpage_close[1024]
Definition: scanst.c:52
char heading_pre[1024]
Definition: scanst.c:59
char idx_escape
Definition: scanst.c:44
FILE * idx_fp
Definition: mkind.c:51
#define NUMBER_MAX
Definition: mkind.h:329
char idx_level
Definition: scanst.c:38
char idx_aclose
Definition: scanst.c:37
char numhead_neg[1024]
Definition: scanst.c:68
int init_page
Definition: mkind.c:35
#define FIELD_MAX
Definition: mkind.h:317
char encap_s[1024]
Definition: scanst.c:89
int letter_ordering
Definition: mkind.c:32
char encap_p[1024]
Definition: scanst.c:87
char idx_encap
Definition: scanst.c:43
FILE * ind_fp
Definition: mkind.c:52
#define PAGETYPE_MAX
Definition: mkind.h:336
int setpagelen
Definition: scanst.c:53
int ilen_r[3]
Definition: scanst.c:74
char page_comp[1024]
Definition: scanst.c:96
int headings_flag
Definition: scanst.c:58
struct KFIELD * FIELD_PTR
int skiplen
Definition: scanst.c:56
char setpage_open[1024]
Definition: scanst.c:51
int merge_page
Definition: mkind.c:34
int idx_et
Definition: mkind.c:45
char ilg[]
Definition: mkind.c:60
int page_offset[5]
Definition: scanst.c:97
int strtoint(char *str)
Definition: mkind.c:563
int compress_blanks
Definition: mkind.c:33
void scan_idx(void)
Definition: scanid.c:63
int headprelen
Definition: scanst.c:61
void gen_ind(void)
Definition: genind.c:64
char delim_r[1024]
Definition: scanst.c:80
char delim_p[3][1024]
Definition: scanst.c:78
int ilen_x[3]
Definition: scanst.c:76
void sort_idx(void)
Definition: sortid.c:46
char encap_i[1024]
Definition: scanst.c:88
char suffix_mp[1024]
Definition: scanst.c:85
int postlen
Definition: scanst.c:49
char idx_keyword[1024]
Definition: scanst.c:35
int locale_sort
Definition: mkind.c:40
char idx_rclose
Definition: scanst.c:40
char postamble[1024]
Definition: disdvi.c:379
int even_odd
Definition: mkind.c:36
const char * idx_fn
Definition: mkind.c:57
char idx_actual
Definition: scanst.c:42
int prelen
Definition: scanst.c:48
#define ARRAY_MAX
Definition: mkind.h:314
char heading_suf[1024]
Definition: scanst.c:60
char numhead_pos[1024]
Definition: scanst.c:67
char item_u[3][1024]
Definition: scanst.c:71
NODE_PTR tail
Definition: scanid.c:44
char suffix_3p[1024]
Definition: scanst.c:84
int group_type(const char *str)
Definition: scanid.c:401
char sty_fn[]
Definition: mkind.c:56
#define str(s)
Definition: sh6.c:399
Definition: mkind.h:389
short type
Definition: mkind.h:396
int lc
Definition: mkind.h:399
int npg[10]
Definition: mkind.h:394
char * encap
Definition: mkind.h:397
char * af[3]
Definition: mkind.h:391
short count
Definition: mkind.h:395
char lpg[99]
Definition: mkind.h:393
const char * fn
Definition: mkind.h:398
int group
Definition: mkind.h:392
Definition: mkind.h:403
struct KNODE * next
Definition: mkind.h:405
FIELD data
Definition: mkind.h:404
Definition: tfmaux.c:31
#define FILE
Definition: t1stdio.h:34