home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fonts 1
/
freshfonts1.bin
/
bbs
/
programs
/
amiga
/
makeindex.lha
/
makeindex-2.12
/
src
/
mkind.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-04-02
|
18KB
|
758 lines
/*
*
* This file is part of
* MakeIndex - A formatter and format independent index processor
*
* Copyright (C) 1989 by Chen & Harrison International Systems, Inc.
* Copyright (C) 1988 by Olivetti Research Center
* Copyright (C) 1987 by Regents of the University of California
*
* Author:
* Pehong Chen
* Chen & Harrison International Systems, Inc.
* Palo Alto, California
* USA
* (phc@renoir.berkeley.edu or chen@orc.olivetti.com)
*
* Contributors:
* Please refer to the CONTRIB file that comes with this release
* for a list of people who have contributed to this and/or previous
* release(s) of MakeIndex.
*
* All rights reserved by the copyright holders. See the copyright
* notice distributed with this software for a complete description of
* the conditions under which it is made available.
*
*/
#define MKIND_C 1
#include "mkind.h"
#undef MKIND_C
int letter_ordering = FALSE;
int compress_blanks = FALSE;
int merge_page = TRUE;
int init_page = FALSE;
int even_odd = -1;
int verbose = TRUE;
int german_sort = FALSE;
int fn_no = -1; /* total number of files */
int idx_dot = TRUE; /* flag which shows dot in ilg being
* active */
int idx_tt = 0; /* total entry count (all files) */
int idx_et = 0; /* erroneous entry count (all files) */
int idx_gt = 0; /* good entry count (all files) */
FIELD_PTR *idx_key;
FILE *log_fp;
FILE *sty_fp;
FILE *idx_fp;
FILE *ind_fp;
FILE *ilg_fp;
#if OS_BS2000
FILE *widx_fp;
char widx_fn[STRING_MAX + 5];
#endif /* OS_BS2000 */
char *pgm_fn;
#if OS_AMIGA
char sty_fn[ARRAY_MAX];
#else
char sty_fn[LINE_MAX];
#endif
char *idx_fn;
char ind[STRING_MAX];
char *ind_fn;
char ilg[STRING_MAX];
char *ilg_fn;
char pageno[NUMBER_MAX];
static char log_fn[STRING_MAX];
static char base[STRING_MAX];
static int need_version = TRUE;
static void check_all ARGS((char *fn,int ind_given,int ilg_given,
int log_given));
static void check_idx ARGS((char *fn,int open_fn));
static void find_pageno ARGS((void));
static void open_sty ARGS((char *fn));
static void prepare_idx ARGS((void));
static void process_idx ARGS((char * *fn,int use_stdin,int sty_given,
int ind_given,int ilg_given,int log_given));
#if OS_PCDOS
#if IBM_PC_TURBO
unsigned _stklen = 0xf000; /* Turbo C ignores size set in
.exe file by LINK or EXEMOD,
sigh... */
#endif /* IBM_PC_TURBO */
#endif /* OS_PCDOS */
#if OS_ATARI
long _stksize = 20000L; /* make the stack larger than 2KB */
/* size must be given */
#endif /* OS_ATARI */
#ifdef DEBUG
long totmem = 0L; /* for debugging memory usage */
#endif /* DEBUG */
int
#if STDC
main(int argc, char *argv[])
#else
main(argc, argv)
int argc;
char *argv[];
#endif
{
#if OS_AMIGA
char **fns; /* better to alloc using malloc (safe stack), so MakeIndex
works with just 4000 stack size */
#else
char *fns[ARRAY_MAX];
#endif /* OS_AMIGA */
char *ap;
int use_stdin = FALSE;
int sty_given = FALSE;
int ind_given = FALSE;
int ilg_given = FALSE;
int log_given = FALSE;
/* determine program name */
#if (OS_ATARI | OS_VAXVMS | OS_BS2000 | OS_MVSXA | OS_VMCMS)
pgm_fn = "MakeIndex"; /* Use symbolic name on some systems */
#else
pgm_fn = strrchr(*argv, DIR_DELIM);
if (pgm_fn == NULL)
pgm_fn = *argv;
else
pgm_fn++;
#if OS_PCDOS
{
register char *ext = pgm_fn + strlen(pgm_fn)-4;
if ( *ext == '.' )
*ext = NUL; /* cut off ".EXE" */
}
(void)strlwr(pgm_fn); /* lower program name */
#endif /* OS_PCDOS */
#endif /* OS_VAXVMS | OS_BS2000 | OS_MVSXA */
#if OS_AMIGA
if ((fns = malloc(ARRAY_MAX*sizeof(char *))) == NULL)
FATAL("Not enough memory...abort.\n","");
#endif /* OS_AMIGA */
/* process command line options */
while (--argc > 0) {
if (**++argv == SW_PREFIX) {
if (*(*argv + 1) == NUL)
break;
for (ap = ++*argv; *ap != NUL; ap++)
#if (OS_BS2000 | OS_MVSXA | OS_VAXVMS)
switch (tolower(*ap)) {
#else
switch (*ap) {
#endif /* (OS_BS2000 | OS_MVSXA | OS_VAXVMS) */
/* use standard input */
case 'i':
use_stdin = TRUE;
break;
/* enable letter ordering */
case 'l':
letter_ordering = TRUE;
break;
/* disable range merge */
case 'r':
merge_page = FALSE;
break;
/* supress progress message -- quiet mode */
case 'q':
verbose = FALSE;
break;
/* compress blanks */
case 'c':
compress_blanks = TRUE;
break;
/* style file */
case 's':
argc--;
if (argc <= 0)
FATAL("Expected -s <stylefile>\n","");
open_sty(*++argv);
sty_given = TRUE;
break;
/* output index file name */
case 'o':
argc--;
if (argc <= 0)
FATAL("Expected -o <ind>\n","");
ind_fn = *++argv;
ind_given = TRUE;
break;
/* transcript file name */
case 't':
argc--;
if (argc <= 0)
FATAL("Expected -t <logfile>\n","");
ilg_fn = *++argv;
ilg_given = TRUE;
break;
/* initial page */
case 'p':
argc--;
if (argc <= 0)
FATAL("Expected -p <num>\n","");
strcpy(pageno, *++argv);
init_page = TRUE;
if (STREQ(pageno, EVEN)) {
log_given = TRUE;
even_odd = 2;
} else if (STREQ(pageno, ODD)) {
log_given = TRUE;
even_odd = 1;
} else if (STREQ(pageno, ANY)) {
log_given = TRUE;
even_odd = 0;
}
break;
/* enable german sort */
case 'g':
german_sort = TRUE;
break;
/* bad option */
default:
FATAL("Unknown option -%c.\n", *ap);
break;
}
} else {
if (fn_no < ARRAY_MAX) {
check_idx(*argv, FALSE);
fns[++fn_no] = *argv;
} else {
FATAL("Too many input files (max %d).\n", ARRAY_MAX);
}
}
}
/* changes for 2.12 (May 20, 1993) by Julian Reschke (jr@ms.maus.de):
if only one input file and no explicit style file was given */
#if OS_BS2000
/* not supported */
#else
if (fn_no == 0 && !sty_given)
{
char tmp[STRING_MAX + 5];
/* base set by last call to check_idx */
sprintf (tmp, "%s%s", base, INDEX_STY);
if (0 == access(tmp, R_OK)) {
open_sty (tmp);
sty_given = TRUE;
}
}
#endif
process_idx(fns, use_stdin, sty_given, ind_given, ilg_given, log_given);
idx_gt = idx_tt - idx_et;
ALL_DONE;
if (idx_gt > 0) {
prepare_idx();
sort_idx();
gen_ind();
MESSAGE("Output written in %s.\n", ind_fn);
} else
MESSAGE("Nothing written in %s.\n", ind_fn);
MESSAGE("Transcript written in %s.\n", ilg_fn);
CLOSE(ind_fp);
CLOSE(ilg_fp);
#if OS_AMIGA
free(fns); /* freeing fns vector */
#endif
EXIT(0);
return (0); /* never executed--avoids complaints */
/* about no return value */
}
static void
prepare_idx(VOID_ARG)
{
NODE_PTR ptr = head;
int i = 0;
#ifdef DEBUG
totmem += idx_gt * sizeof(FIELD_PTR);
(void)fprintf(stderr,"prepare_idx(): calloc(%d,%d)\ttotmem = %ld\n",
idx_gt,sizeof(FIELD_PTR),totmem);
#endif /* DEBUG */
if (head == (NODE_PTR)NULL)
FATAL("No valid index entries collected.\n", "");
if ((idx_key = (FIELD_PTR *) calloc(idx_gt, sizeof(FIELD_PTR))) == NULL) {
FATAL("Not enough core...abort.\n", "");
}
for (i = 0; i < idx_gt; i++) {
idx_key[i] = &(ptr->data);
ptr = ptr->next;
}
}
static void
#if STDC
process_idx(char *fn[], int use_stdin, int sty_given, int ind_given,
int ilg_given, int log_given)
#else
process_idx(fn, use_stdin, sty_given, ind_given, ilg_given, log_given)
char *fn[];
int use_stdin;
int sty_given;
int ind_given;
int ilg_given;
int log_given;
#endif
{
int i;
if (fn_no == -1)
/* use stdin if no input files specified */
use_stdin = TRUE;
else {
check_all(fn[0], ind_given, ilg_given, log_given);
PUT_VERSION;
if (sty_given)
scan_sty();
if (german_sort && (idx_quote == '"'))
FATAL("Option -g invalid, quote character must be different from '%c'.\n",
'"');
scan_idx();
ind_given = TRUE;
ilg_given = T