1: #ifndef lint
   2: static char sccsid[] = "@(#)listrefs.c	2.5	10/12/84";
   3: #endif not lint
   4: /*
   5:         Listrefs - list references for bib system
   6: 
   7:         Authored by: Tim Budd, University of Arizona, 1983.
   8:                 lookup routines written by gary levin 2/82
   9: 
  10:                 version 7/4/83
  11: 
  12:         Various modifications suggested by:
  13:                 David Cherveny - Duke University Medical Center
  14:                 Phil Garrison - UC Berkeley
  15:                 M. J. Hawley - Yale University
  16: 
  17: 
  18: 
  19: 
  20:                                                         */
  21: # include <stdio.h>
  22: # include <ctype.h>
  23: # include "bib.h"
  24: # include "streams.h"
  25: # define MAXLIST 2000  /* maximum number of references that can be listed */
  26: # define getch(c,fd) (c = getc(fd))
  27: 
  28: FILE *tfd;
  29: 
  30: #ifndef INCORE
  31: FILE *rfd;                      /* reference file position */
  32: char reffile[] = TMPREFFILE;    /* temporary file (see bib.h) */
  33: #endif INCORE
  34: struct refinfo refinfo[MAXLIST];      /* references temporary file, seek positions */
  35: struct refinfo *refshash[HASHSIZE];
  36: long int rend = 1;              /* last used position in reference file */
  37: int numrefs = 0;               /* number of references */
  38: extern int sort;                /* see if things are to be sorted */
  39: extern char bibfname[];
  40: extern int biblineno;
  41: 
  42: #include <signal.h>
  43: main(argc, argv)
  44:    int argc;
  45:    char **argv;
  46: {  char defult[120];
  47:    int  i, rcomp(), intr();
  48: 
  49:    strcpy(BMACLIB, N_BMACLIB);
  50:    strcpy(COMFILE, N_COMFILE);
  51:    strcpy(DEFSTYLE, N_DEFSTYLE);
  52: 
  53:    signal(SIGINT, intr);
  54:    tfd = stdout;
  55:    strcpy(defult, BMACLIB);
  56:    strcat(defult,"/bib.list");
  57: #ifndef INCORE
  58:    mktemp(reffile);
  59:    rfd = fopen(reffile,"w+");
  60:    if (rfd == NULL)
  61:       error("can't open temporary reference file");
  62:    putc('x', rfd);      /* put garbage in first position */
  63: #endif not INCORE
  64: 
  65:    doargs(argc, argv, defult);
  66: 
  67:    if (sort)
  68:       qsort(refinfo, numrefs, sizeof(struct refinfo), rcomp);
  69:    makecites();
  70:    disambiguate();
  71: 
  72:    for (i = 0; i < numrefs; i++)
  73:       dumpref(i, stdout);
  74: 
  75:    cleanup(0);
  76: }
  77: intr()
  78: {
  79:   cleanup(1);
  80: }
  81: cleanup(val)
  82: {
  83: #ifndef INCORE
  84:   fclose(rfd);
  85:   unlink(reffile);
  86: #endif not INCORE
  87:   exit(val);
  88: }
  89: 
  90: /* rdtext - process a file */
  91:    rdtext(ifile)
  92:    FILE *ifile;
  93: {  char c, *p, rec[REFSIZE];
  94:    int i;
  95:    int hash, lg;
  96: 
  97:    biblineno = 1;
  98:    for (;;) {
  99:       while (getch(c, ifile) == '\n')
 100:          biblineno++;   /* skip leading newlines */
 101:       if (c == EOF)
 102:          return;
 103: 
 104:       p = rec;          /* read a reference */
 105:       for (;;) {
 106:          for (*p++ = c; getch(c, ifile) != '\n'; )
 107:             if (c == EOF)
 108:                error("ill formed reference file");
 109:             else
 110:                *p++ = c;
 111:          if (getch(c, ifile) == '\n' || c == EOF) {
 112:             biblineno++;
 113:             *p++ = '\n';
 114:             break;
 115:             }
 116:          if (c == '.' || c == '%')
 117:             *p++ = '\n';
 118:          else
 119:             *p++ = ' ';
 120:          }
 121: 
 122:       *p = 0;
 123:       expand(rec);
 124: 
 125:       /* didn't match any existing reference, create new one */
 126:       if (numrefs >= MAXLIST)
 127:     error("too many references, max of %d", MAXLIST);
 128:       hash = strhash(rec);
 129:       lg = strlen(rec) + 1;
 130:       refinfo[numrefs].ri_pos = rend;
 131:       refinfo[numrefs].ri_length = lg;
 132:       refinfo[numrefs].ri_hp = refshash[hash];
 133:       refinfo[numrefs].ri_n = numrefs;
 134:       refshash[hash] = &refinfo[numrefs];
 135:       wrref(&refinfo[numrefs], rec);
 136:       numrefs++;
 137:       }
 138: }

Defined functions

cleanup defined in line 81; used 3 times
intr defined in line 77; used 2 times
main defined in line 43; never used
rdtext defined in line 91; used 2 times

Defined variables

numrefs defined in line 37; used 15 times
reffile defined in line 32; used 5 times
refinfo defined in line 34; used 23 times
refshash defined in line 35; used 2 times
rend defined in line 36; used 1 times
sccsid defined in line 2; never used

Defined macros

MAXLIST defined in line 25; used 3 times
getch defined in line 26; used 3 times
Last modified: 1984-10-13
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1141
Valid CSS Valid XHTML 1.0 Strict