📄 bib.c
字号:
#ifndef lintstatic char sccsid[] = "@(#)bib.c 2.12 1/3/94";#endif not lint/* Bib - bibliographic formatter Authored by: Tim Budd, University of Arizona, 1983. lookup routines written by gary levin 2/82 version 7/4/83 Various modifications suggested by: David Cherveny - Duke University Medical Center Phil Garrison - UC Berkeley M. J. Hawley - Yale University version 8/23/1988 Adapted to use TiB style macro calls (i.e. |macro|) A. Dain Samples */# include <stdio.h># include <ctype.h># include "bib.h"# define HUNTSIZE 512 /* maximum size of hunt string */# define MAXREFS 300 /* maximum number of references */# define MAXATONCE 35 /* maximum references at one location */# define getch(c,fd) (c = getc(fd))# define echoc(c,ifd,ofd) (getch(c,ifd) == EOF ? c : putc(c,ofd))# define testc(c,d,ifd,ofd) (getch(c, ifd) == d ? putc(c, ofd) : 0)/* global variables */ FILE *rfd; /* reference temporary file */#ifndef INCORE char reffile[] = TMPREFFILE ;/* temporary file (see bib.h) */#endif not INCORE struct refinfo refinfo[MAXREFS]; /* reference information */ struct refinfo *refssearch(); struct refinfo *refshash[HASHSIZE]; long int rend = 1; /* last position in rfd (first char unused)*/ int numrefs = 0; /* number of references generated so far */ FILE *tfd; /* output of pass 1 of file(s) */ char bibtmpfile[] = TMPTEXTFILE ; /* output of pass 1 */ char *common = COMFILE; /* common word file */ int findex = false; /* can we read the file INDEX ? */char *programName;/* global variables in bibargs */ extern int foot, doacite, sort, max_klen, personal; extern int hyphen, ordcite, biblineno; extern char sortstr[], pfile[], citetemplate[], bibfname[]; extern int TibOption;#include <signal.h>main(argc, argv) int argc; char **argv;{ int rcomp(); void intr(); /* the file INDEX in the current directory is the default index, if it is present */ InitDirectory(BMACLIB,N_BMACLIB); InitDirectory(COMFILE,N_COMFILE); InitDirectory(DEFSTYLE,N_DEFSTYLE); signal(SIGINT, intr); rfd = fopen( INDXFILE , "r"); if (rfd != NULL) { findex = true; fclose(rfd); }#ifndef INCORE /* open temporaries, reffile will contain references collected in pass 1, and bibtmpfile will contain text. */ mktemp(reffile); rfd = fopen(reffile,"w+"); if (rfd == NULL) error("can't open temporary reference file, %s", reffile); putc('x', rfd); /* put garbage in first position (not used) */#endif not INCORE mktemp(bibtmpfile); tfd = fopen(bibtmpfile,"w"); if (tfd == NULL) error("can't open temporary output file, %s", bibtmpfile); /* pass1 - read files, looking for citations arguments are read by doargs (bibargs.c) */ if (doargs(argc, argv, DEFSTYLE ) == 0) { /* may not return */ strcpy(bibfname, "<stdin>"); rdtext(stdin); } /* sort references, make citations, add disambiguating characters */ if (sort) qsort(refinfo, numrefs, sizeof(struct refinfo), rcomp); makecites(); disambiguate(); /* reopen temporaries */ fclose(tfd); tfd = fopen(bibtmpfile,"r"); if (tfd == NULL) error("can't open temporary output file %s for reading", bibtmpfile); /* pass 2 - reread files, replacing references */ pass2(tfd, stdout); cleanup(0);}/* interrupt processing */voidintr(){ cleanup(1);}/* clean up and exit */cleanup(val){ fclose(tfd);#ifndef INCORE fclose(rfd); unlink(reffile);#endif INCORE#ifndef DEBUG unlink(bibtmpfile);#endif DEBUG exit(val);}/* rdtext - read and process a text file, looking for [. commands */ rdtext(fd) FILE *fd;{ char lastc, c, d; lastc = '\0'; biblineno = 1; while (getch(c, fd) != EOF) if (c == '[' || c == '{') if (getch(d, fd) == '.') { /* found a reference */ if (c == '{') { if (lastc) putc(lastc, tfd);} else switch (lastc) { case '\0': break; case ' ': fputs("\\*([<", tfd); break; case '.': case ',': case '?': case ':': case ';': case '!': case '"': case '\'': fputs("\\*([", tfd); /* fall through */ default: putc(lastc, tfd); break; } rdcite(fd, c); if (c == '[') switch (lastc) { case '\0': break; case ' ': fputs("\\*(>]", tfd); break; case '.': case ',': case '?': case ':': case ';': case '!': case '"': case '\'': fprintf(tfd,"\\*(%c]", lastc); break; } lastc = '\0'; } else { if (lastc != '\0') putc(lastc, tfd); ungetc(d, fd); lastc = c; } else { if (lastc != '\0') putc(lastc, tfd); lastc = c; if (c == '\n') biblineno++; } if (lastc != '\0') putc(lastc, tfd);}/* rdcite - read citation information inside a [. command */ rdcite(fd, ch) FILE *fd; char ch;{ int getref(); char huntstr[HUNTSIZE], c, info[HUNTSIZE]; if (ch == '[') if (doacite) fputs("\\*([[", tfd); else if (doacite) fputs("\\*([{", tfd); huntstr[0] = info[0] = 0; while (getch(c, fd) != EOF) switch (c) { case ',': citemark(info, huntstr, ""); huntstr[0] = info[0] = 0; break; case '.': while (getch(c, fd) == '.') ; if (c == ']') { citemark(info, huntstr, "\\*(]]"); return; } else if (c == '}') { citemark(info, huntstr, "\\*(}]"); return; } else addc(huntstr, c); break; case '{': while (getch(c, fd) != '}') if (c == EOF) { error("ill formed reference"); } else addc(info, c); break; case '\n': biblineno++; case '\t': c = ' '; /* fall through */ default: addc(huntstr,c); } error("end of file reading citation");}char ncitetemplate[64];int changecite;citemark(info, huntstr, tail) char *info, *huntstr, *tail;{ char c = CITEMARK; long int n; /* * getref sets ncitetemplate as a side effect */ n = getref(huntstr); if (ncitetemplate[0]){ fprintf(tfd, "%c%s%c", FMTSTART, ncitetemplate, FMTEND); ncitetemplate[0] = 0; } fprintf(tfd, "%c%d%c%s%c%s", c ,n, c, info, CITEEND, doacite?tail:"");}/* addc - add a character to hunt string */addc(huntstr, c) char huntstr[HUNTSIZE], c;{ int i; i = strlen(huntstr); if (i > HUNTSIZE) error("citation too long, max of %d", HUNTSIZE); huntstr[i] = c; huntstr[i+1] = 0;}/* getref - if an item was already referenced, return its reference index otherwise create a new entry */int getref(huntstr) char huntstr[HUNTSIZE];{ char rf[REFSIZE], *r, *hunt(); int match(), getwrd(); char *realhstr; int hash; struct refinfo *rp; int lg; realhstr = huntstr; if (strncmp(huntstr, "$C$", 3) == 0){ char *from, *to; changecite++; for(from = huntstr + 3, to = ncitetemplate; *from; from++, to++){ switch(*from){ case '\0': case ' ': case '\n': case '\t': goto outcopy; default: *to = *from; } } outcopy: ; *to = 0; *from = 0; realhstr = from + 1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -