113109Srrh #ifndef lint 2*24014Srrh static char sccsid[] = "@(#)bib.c 2.9 07/23/85"; 313109Srrh #endif not lint 415066Sgarrison /* 515066Sgarrison Bib - bibliographic formatter 613109Srrh 715066Sgarrison Authored by: Tim Budd, University of Arizona, 1983. 815066Sgarrison lookup routines written by gary levin 2/82 915066Sgarrison 1015066Sgarrison version 7/4/83 1115066Sgarrison 1215066Sgarrison Various modifications suggested by: 1315066Sgarrison David Cherveny - Duke University Medical Center 1415066Sgarrison Phil Garrison - UC Berkeley 1515066Sgarrison M. J. Hawley - Yale University 1615066Sgarrison 1715066Sgarrison 1815066Sgarrison 1915066Sgarrison 2015066Sgarrison */ 2112909Sgarrison # include <stdio.h> 2212909Sgarrison # include <ctype.h> 2312909Sgarrison # include "bib.h" 2412909Sgarrison 2512909Sgarrison # define HUNTSIZE 512 /* maximum size of hunt string */ 2612909Sgarrison # define MAXREFS 300 /* maximum number of references */ 2712909Sgarrison # define MAXATONCE 35 /* maximum references at one location */ 2812909Sgarrison 2912909Sgarrison # define getch(c,fd) (c = getc(fd)) 3012909Sgarrison # define echoc(c,ifd,ofd) (getch(c,ifd) == EOF ? c : putc(c,ofd)) 3112909Sgarrison # define testc(c,d,ifd,ofd) (getch(c, ifd) == d ? putc(c, ofd) : 0) 3212909Sgarrison 3312909Sgarrison /* global variables */ 3412909Sgarrison FILE *rfd; /* reference temporary file */ 3516245Srrh #ifndef INCORE 3612909Sgarrison char reffile[] = TMPREFFILE ;/* temporary file (see bib.h) */ 3716245Srrh #endif not INCORE 3815902Srrh struct refinfo refinfo[MAXREFS]; /* reference information */ 3915902Srrh struct refinfo *refssearch(); 4015902Srrh struct refinfo *refshash[HASHSIZE]; 4112909Sgarrison long int rend = 1; /* last position in rfd (first char unused)*/ 4215902Srrh int numrefs = 0; /* number of references generated so far */ 4312909Sgarrison FILE *tfd; /* output of pass 1 of file(s) */ 4412909Sgarrison char tmpfile[] = TMPTEXTFILE ; /* output of pass 1 */ 4517247Srrh char *common = COMFILE; /* common word file */ 4612909Sgarrison int findex = false; /* can we read the file INDEX ? */ 4712909Sgarrison 4812909Sgarrison /* global variables in bibargs */ 4923484Sgarrison extern int foot, doacite, sort, max_klen, personal; 5015066Sgarrison extern int hyphen, ordcite, biblineno; 5115066Sgarrison extern char sortstr[], pfile[], citetemplate[], bibfname[]; 5212909Sgarrison 5315902Srrh #include <signal.h> 5412909Sgarrison 5512909Sgarrison main(argc, argv) 5612909Sgarrison int argc; 5712909Sgarrison char **argv; 5812909Sgarrison { int rcomp(); 5915902Srrh int intr(); 6012909Sgarrison 6112909Sgarrison /* the file INDEX in the current directory is the default index, 6212909Sgarrison if it is present */ 6312909Sgarrison 6417247Srrh strcpy(BMACLIB, N_BMACLIB); 6517247Srrh strcpy(COMFILE, N_COMFILE); 6617247Srrh strcpy(DEFSTYLE, N_DEFSTYLE); 6717247Srrh 6815902Srrh signal(SIGINT, intr); 6912909Sgarrison rfd = fopen( INDXFILE , "r"); 7012909Sgarrison if (rfd != NULL) { 7112909Sgarrison findex = true; 7212909Sgarrison fclose(rfd); 7312909Sgarrison } 7412909Sgarrison 7515902Srrh #ifndef INCORE 7612909Sgarrison /* open temporaries, reffile will contain references collected in 7712909Sgarrison pass 1, and tmpfile will contain text. 7812909Sgarrison */ 7912909Sgarrison mktemp(reffile); 8012909Sgarrison rfd = fopen(reffile,"w+"); 8112909Sgarrison if (rfd == NULL) 8215902Srrh error("can't open temporary reference file, %s", reffile); 8315066Sgarrison putc('x', rfd); /* put garbage in first position (not used) */ 8415902Srrh #endif not INCORE 8512909Sgarrison mktemp(tmpfile); 8612909Sgarrison tfd = fopen(tmpfile,"w"); 8712909Sgarrison if (tfd == NULL) 8815902Srrh error("can't open temporary output file, %s", tmpfile); 8912909Sgarrison 9012909Sgarrison /* 9112909Sgarrison pass1 - read files, looking for citations 9212909Sgarrison arguments are read by doargs (bibargs.c) 9312909Sgarrison */ 9412909Sgarrison 9515066Sgarrison if (doargs(argc, argv, DEFSTYLE ) == 0) { 9615066Sgarrison strcpy(bibfname, "<stdin>"); 9712909Sgarrison rdtext(stdin); 9815066Sgarrison } 9912909Sgarrison 10012909Sgarrison /* 10112909Sgarrison sort references, make citations, add disambiguating characters 10212909Sgarrison */ 10312909Sgarrison 10412909Sgarrison if (sort) 10515902Srrh qsort(refinfo, numrefs, sizeof(struct refinfo), rcomp); 10615902Srrh makecites(); 10712909Sgarrison disambiguate(); 10812909Sgarrison 10912909Sgarrison /* 11012909Sgarrison reopen temporaries 11112909Sgarrison */ 11212909Sgarrison 11312909Sgarrison fclose(tfd); 11412909Sgarrison tfd = fopen(tmpfile,"r"); 11512909Sgarrison if (tfd == NULL) 11615902Srrh error("can't open temporary output file %s for reading", tmpfile); 11712909Sgarrison /* 11812909Sgarrison pass 2 - reread files, replacing references 11912909Sgarrison */ 12012909Sgarrison pass2(tfd, stdout); 12115902Srrh cleanup(0); 12215902Srrh } 12315902Srrh /* interrupt processing */ 12415902Srrh intr() 12515902Srrh { 12615902Srrh cleanup(1); 12715902Srrh } 12815902Srrh /* clean up and exit */ 12915902Srrh cleanup(val) 13015902Srrh { 13112909Sgarrison fclose(tfd); 13215902Srrh #ifndef INCORE 13312909Sgarrison fclose(rfd); 13415902Srrh unlink(reffile); 13515902Srrh #endif INCORE 13615902Srrh #ifndef DEBUG 13712909Sgarrison unlink(tmpfile); 13815902Srrh #endif DEBUG 13915902Srrh exit(val); 14012909Sgarrison } 14112909Sgarrison 14212909Sgarrison /* rdtext - read and process a text file, looking for [. commands */ 14312909Sgarrison rdtext(fd) 14412909Sgarrison FILE *fd; 14512909Sgarrison { char lastc, c, d; 14612909Sgarrison 14715066Sgarrison lastc = '\0'; 14815066Sgarrison biblineno = 1; 14912909Sgarrison while (getch(c, fd) != EOF) 15012909Sgarrison if (c == '[' || c == '{') 15112909Sgarrison if (getch(d, fd) == '.') { /* found a reference */ 15212909Sgarrison if (c == '{') { if (lastc) putc(lastc, tfd);} 15312909Sgarrison else 15415066Sgarrison switch (lastc) { 15515066Sgarrison case '\0': break; 15615066Sgarrison case ' ': fputs("\\*([<", tfd); break; 15715066Sgarrison case '.': case ',': case '?': case ':': 15815066Sgarrison case ';': case '!': case '"': case '\'': 15915066Sgarrison fputs("\\*([", tfd); /* fall through */ 16015066Sgarrison default: putc(lastc, tfd); break; 16115066Sgarrison } 16212909Sgarrison rdcite(fd, c); 16312909Sgarrison if (c == '[') 16415066Sgarrison switch (lastc) { 16515066Sgarrison case '\0': break; 16615066Sgarrison case ' ': fputs("\\*(>]", tfd); break; 16715066Sgarrison case '.': case ',': case '?': case ':': 16815066Sgarrison case ';': case '!': case '"': case '\'': 16915066Sgarrison fprintf(tfd,"\\*(%c]", lastc); break; 17015066Sgarrison } 17115066Sgarrison lastc = '\0'; 17212909Sgarrison } 17312909Sgarrison else { 17415066Sgarrison if (lastc != '\0') putc(lastc, tfd); 17512909Sgarrison ungetc(d, fd); 17612909Sgarrison lastc = c; 17712909Sgarrison } 17812909Sgarrison else { 17915066Sgarrison if (lastc != '\0') putc(lastc, tfd); 18012909Sgarrison lastc = c; 18115066Sgarrison if (c == '\n') biblineno++; 18212909Sgarrison } 18315066Sgarrison if (lastc != '\0') putc(lastc, tfd); 18412909Sgarrison } 18512909Sgarrison 18612909Sgarrison /* rdcite - read citation information inside a [. command */ 18712909Sgarrison rdcite(fd, ch) 18812909Sgarrison FILE *fd; 18912909Sgarrison char ch; 19016245Srrh { int getref(); 19112909Sgarrison char huntstr[HUNTSIZE], c, info[HUNTSIZE]; 19212909Sgarrison 19312909Sgarrison if (ch == '[') 19417245Srrh if (doacite) fputs("\\*([[", tfd); 19512909Sgarrison else 19617245Srrh if (doacite) fputs("\\*([{", tfd); 19712909Sgarrison huntstr[0] = info[0] = 0; 19812909Sgarrison while (getch(c, fd) != EOF) 19912909Sgarrison switch (c) { 20012909Sgarrison case ',': 20115902Srrh citemark(info, huntstr, (char *)0); 20212909Sgarrison huntstr[0] = info[0] = 0; 20312909Sgarrison break; 20412909Sgarrison case '.': 20512909Sgarrison while (getch(c, fd) == '.') ; 20612909Sgarrison if (c == ']') { 20715902Srrh citemark(info, huntstr, "\\*(]]"); 20812909Sgarrison return; 20912909Sgarrison } 21012909Sgarrison else if (c == '}') { 21115902Srrh citemark(info, huntstr, "\\*(}]"); 21212909Sgarrison return; 21312909Sgarrison } 21412909Sgarrison else 21512909Sgarrison addc(huntstr, c); 21612909Sgarrison break; 21712909Sgarrison 21812909Sgarrison case '{': 21912909Sgarrison while (getch(c, fd) != '}') 22012909Sgarrison if (c == EOF) { 22115902Srrh error("ill formed reference"); 22212909Sgarrison } 22312909Sgarrison else 22412909Sgarrison addc(info, c); 22512909Sgarrison break; 22612909Sgarrison 22712909Sgarrison case '\n': 22815066Sgarrison biblineno++; 22912909Sgarrison case '\t': 23012909Sgarrison c = ' '; /* fall through */ 23112909Sgarrison 23212909Sgarrison default: 23312909Sgarrison addc(huntstr,c); 23412909Sgarrison } 23512909Sgarrison error("end of file reading citation"); 23612909Sgarrison } 23716245Srrh char ncitetemplate[64]; 23816245Srrh int changecite; 23915902Srrh citemark(info, huntstr, tail) 24015902Srrh char *info, *huntstr, *tail; 24115902Srrh { 24215902Srrh char c = CITEMARK; 24315902Srrh long int n; 24416245Srrh /* 24516245Srrh * getref sets ncitetemplate as a side effect 24616245Srrh */ 24715902Srrh n = getref(huntstr); 24816245Srrh if (ncitetemplate[0]){ 24916245Srrh fprintf(tfd, "%c%s%c", FMTSTART, ncitetemplate, FMTEND); 25016245Srrh ncitetemplate[0] = 0; 25116245Srrh } 252*24014Srrh if (doacite && (tail != (char *)0)) 253*24014Srrh fprintf(tfd, "%c%d%c%s%c%s", c ,n, c, info, CITEEND, tail); 254*24014Srrh else 255*24014Srrh fprintf(tfd, "%c%d%c%s%c", c ,n, c, info, CITEEND); 256*24014Srrh 25715902Srrh } 25812909Sgarrison 25912909Sgarrison /* addc - add a character to hunt string */ 26012909Sgarrison addc(huntstr, c) 26112909Sgarrison char huntstr[HUNTSIZE], c; 26212909Sgarrison { int i; 26312909Sgarrison 26412909Sgarrison i = strlen(huntstr); 26512909Sgarrison if (i > HUNTSIZE) 26615902Srrh error("citation too long, max of %d", HUNTSIZE); 26712909Sgarrison huntstr[i] = c; 26812909Sgarrison huntstr[i+1] = 0; 26912909Sgarrison } 27015902Srrh /* getref - if an item was already referenced, return its reference index 27115902Srrh otherwise create a new entry */ 27215902Srrh int getref(huntstr) 27312909Sgarrison char huntstr[HUNTSIZE]; 27415902Srrh { char rf[REFSIZE], *r, *hunt(); 27515902Srrh int match(), getwrd(); 27615891Srrh char *realhstr; 27715902Srrh int hash; 27815902Srrh struct refinfo *rp; 27915902Srrh int lg; 28012909Sgarrison 28115891Srrh realhstr = huntstr; 28215891Srrh if (strncmp(huntstr, "$C$", 3) == 0){ 28315891Srrh char *from, *to; 28416245Srrh changecite++; 28516245Srrh for(from = huntstr + 3, to = ncitetemplate; *from; from++, to++){ 28615891Srrh switch(*from){ 28715891Srrh case '\0': 28815891Srrh case ' ': 28915891Srrh case '\n': 29015891Srrh case '\t': goto outcopy; 29115891Srrh default: *to = *from; 29215891Srrh } 29315891Srrh } 29415891Srrh outcopy: ; 29515891Srrh *to = 0; 29615891Srrh *from = 0; 29715891Srrh realhstr = from + 1; 29815891Srrh } 29915891Srrh r = hunt(realhstr); 30012909Sgarrison if (r != NULL) { 30115902Srrh /* expand defined string */ 30212909Sgarrison strcpy(rf, r); 30312909Sgarrison free(r); 30412909Sgarrison expand(rf); 30512909Sgarrison /* see if reference has already been cited */ 30615902Srrh if (foot == false && (rp = refssearch(rf))){ 30715902Srrh return(rp - refinfo); 30815902Srrh } 30912909Sgarrison /* didn't match any existing reference, create new one */ 31015902Srrh if (numrefs >= MAXREFS) 31115902Srrh error("too many references, max of %d", MAXREFS); 31215902Srrh hash = strhash(rf); 31315902Srrh lg = strlen(rf) + 1; 31415902Srrh refinfo[numrefs].ri_pos = rend; 31515902Srrh refinfo[numrefs].ri_length = lg; 31615902Srrh refinfo[numrefs].ri_hp = refshash[hash]; 31715902Srrh refinfo[numrefs].ri_n = numrefs; 31815902Srrh refshash[hash] = &refinfo[numrefs]; 31915902Srrh wrref(&refinfo[numrefs], rf); 32015902Srrh return(numrefs++); 32112909Sgarrison } 32212909Sgarrison else { 32315891Srrh bibwarning("no reference matching %s\n", realhstr); 32415902Srrh return(-1); 32512909Sgarrison } 32612909Sgarrison } 32715902Srrh struct refinfo *refssearch(rf) 32815902Srrh char *rf; 32915902Srrh { 33015902Srrh char ref[REFSIZE]; 33115902Srrh reg int i; 33215902Srrh int lg; 33315902Srrh reg struct refinfo *rp; 33415902Srrh lg = strlen(rf) + 1; 33515902Srrh for (rp = refshash[strhash(rf)]; rp; rp = rp->ri_hp){ 33615902Srrh if (rp->ri_length == lg){ 33715902Srrh rdref(rp, ref); 33815902Srrh if (strcmp(ref, rf) == 0) 33915902Srrh return(rp); 34015902Srrh } 34115902Srrh } 34215902Srrh return(0); 34315902Srrh } 34412909Sgarrison /* hunt - hunt for reference from either personal or system index */ 34512909Sgarrison char *hunt(huntstr) 34612909Sgarrison char huntstr[]; 34712909Sgarrison { char *fhunt(), *r, *p, *q, fname[120]; 34812909Sgarrison 34912909Sgarrison if (personal) { 35012909Sgarrison for (p = fname, q = pfile; ; q++) 35112909Sgarrison if (*q == ',' || *q == 0) { 35212909Sgarrison *p = 0; 35312909Sgarrison if ((r = fhunt(fname, huntstr)) != NULL) 35412909Sgarrison return(r); 35512909Sgarrison else if (*q == 0) 35612909Sgarrison break; 35712909Sgarrison p = fname; 35812909Sgarrison } 35912909Sgarrison else *p++ = *q; 36012909Sgarrison } 36112909Sgarrison else if (findex) { 36212909Sgarrison if ((r = fhunt( INDXFILE , huntstr)) != NULL) 36312909Sgarrison return(r); 36412909Sgarrison } 36512909Sgarrison if ((r = fhunt(SYSINDEX , huntstr)) != NULL) 36612909Sgarrison return(r); 36712909Sgarrison return(NULL); 36812909Sgarrison } 36912909Sgarrison 37012909Sgarrison /* fhunt - hunt from a specific file */ 37112909Sgarrison char *fhunt(file, huntstr) 37212909Sgarrison char file[], huntstr[]; 37312909Sgarrison { char *p, *r, *locate(); 37412909Sgarrison 37523484Sgarrison r = locate(huntstr, file, max_klen, common); 37612909Sgarrison 37712909Sgarrison if (r == NULL) 37812909Sgarrison return(NULL); /* error */ 37912909Sgarrison if (*r == 0) 38012909Sgarrison return(NULL); /* no match */ 38112909Sgarrison 38212909Sgarrison for (p = r; *p; p++) 38312909Sgarrison if (*p == '\n') 38412909Sgarrison if (*(p+1) == '\n') { /* end */ 38512909Sgarrison if (*(p+2) != 0) 38615066Sgarrison bibwarning("multiple references match %s\n",huntstr); 38712909Sgarrison *(p+1) = 0; 38812909Sgarrison break; 38912909Sgarrison } 39012909Sgarrison else if (*(p+1) != '%' && *(p+1) != '.') /* unnecessary newline */ 39112909Sgarrison *p = ' '; 39212909Sgarrison return(r); 39312909Sgarrison } 39415902Srrh struct cite{ 39515902Srrh int num; 39615902Srrh char *info; 39715902Srrh }; 39815902Srrh citesort(p1, p2) 39915902Srrh struct cite *p1, *p2; 40015902Srrh { 40115902Srrh return(p1->num - p2->num); 40215902Srrh } 40312909Sgarrison 40412909Sgarrison /* putrefs - gather contiguous references together, sort them if called 40512909Sgarrison for, hyphenate if necessary, and dump them out */ 40612909Sgarrison int putrefs(ifd, ofd, footrefs, fn) 40712909Sgarrison FILE *ifd, *ofd; 40812909Sgarrison int fn, footrefs[]; 40915902Srrh { 41015902Srrh struct cite cites[MAXATONCE]; 41115902Srrh char infoword[HUNTSIZE]; /* information line */ 41215902Srrh reg int i; 41315902Srrh reg char *p; 41415902Srrh reg int ncites, n, j; /* number of citations being dumped */ 41515902Srrh char c, *walloc(); 41615902Srrh int neg; 41715902Srrh /* 41815902Srrh * first gather contiguous references together, 41915902Srrh * and order them if required 42015902Srrh */ 42112909Sgarrison 42215902Srrh ncites = 0; 42315902Srrh do { 42423484Sgarrison neg = 1; 42515902Srrh n = 0; 42615902Srrh do{ 42715902Srrh getch(c, ifd); 42815902Srrh if (isdigit(c)) 42915902Srrh n = 10 * n + (c - '0'); 43015902Srrh else if (c == '-') 43115902Srrh neg *= -1; 43215902Srrh else if (c == CITEMARK) 43315902Srrh break; 43415902Srrh else 43515902Srrh error("bad cite char 0%03o in pass two",c); 43615902Srrh } while(1); 43715902Srrh if (neg < 0) { /* reference not found */ 43815902Srrh cites[ncites].num = -1; 43915902Srrh cites[ncites].info = 0; 44015902Srrh ncites++; 44115902Srrh } else { 44215902Srrh /* 44315902Srrh * Find reference n in the references 44415902Srrh */ 44515902Srrh int i; 44615902Srrh for (i = 0; i < numrefs; i++){ 44715902Srrh if (refinfo[i].ri_n == n){ 44815902Srrh cites[ncites].num = i; 44915902Srrh cites[ncites].info = 0; 45015902Srrh ncites++; 45115902Srrh break; 45215902Srrh } 45315902Srrh } 45415902Srrh if (i == numrefs) 45515902Srrh error("citation %d not found in pass 2", n); 45615902Srrh } 45715902Srrh if (getch(c, ifd) != CITEEND) { 45815902Srrh for (p = infoword; c != CITEEND ; ) { 45915902Srrh *p++ = c; 46015902Srrh getch(c, ifd); 46115902Srrh } 46215902Srrh *p = 0; 46315902Srrh cites[ncites-1].info = walloc(infoword); 46415902Srrh } 46515902Srrh getch(c, ifd); 46615902Srrh } while (c == CITEMARK); 46715902Srrh ungetc(c, ifd); 46815902Srrh if (ordcite) 46915902Srrh qsort(cites, ncites, sizeof(struct cite), citesort); 47012909Sgarrison 47115902Srrh /* now dump out values */ 47215902Srrh for (i = 0; i < ncites; i++) { 47316245Srrh if (cites[i].num >= 0) { 47416245Srrh if (changecite){ 47516245Srrh char tempcite[128]; 47616245Srrh char ref[REFSIZE]; 47716245Srrh struct refinfo *p; 47816245Srrh /* 47916245Srrh * rebuild the citation string, 48016245Srrh * using the current template in effect 48116245Srrh */ 48216245Srrh p = &refinfo[cites[i].num]; 48316245Srrh rdref(p, ref); 48416245Srrh bldcite(tempcite, cites[i].num, ref); 48516245Srrh strcat(tempcite, p->ri_disambig); 48617245Srrh if (doacite) fputs(tempcite, ofd); 48716245Srrh } else { 48817245Srrh if (doacite) fputs(refinfo[cites[i].num].ri_cite, ofd); 48916245Srrh } 49017245Srrh if (!doacite) fputs("\\&", ofd); 49116245Srrh } 49215902Srrh if (cites[i].info) { 49317245Srrh if (doacite) fputs(cites[i].info, ofd); 49417245Srrh if (!doacite) fputs("\\&", ofd); 49515902Srrh free(cites[i].info); 49615902Srrh } 49715902Srrh if (hyphen) { 49815902Srrh for (j = 1; 49915902Srrh j + i <= ncites && cites[i+j].num == cites[i].num + j; 50015902Srrh j++)/*VOID*/; 50115902Srrh if (j + i > ncites) 50215902Srrh j = ncites; 50315902Srrh else 50415902Srrh j = j + i - 1; 50515902Srrh } else { 50615902Srrh j = i; 50715902Srrh } 50815902Srrh if (j > i + 1) { 50915902Srrh fputs("\\*(]-", ofd); 51015902Srrh i = j - 1; 51115902Srrh } else if (i != ncites - 1) { 51215902Srrh fputs("\\*(],", ofd); 51315902Srrh } 51415902Srrh if (foot) { 51515902Srrh fn++; 51615902Srrh footrefs[fn] = cites[i].num; 51715902Srrh } 51815902Srrh } 51915902Srrh return(fn); 52012909Sgarrison } 52112909Sgarrison 52212909Sgarrison /* pass2 - read pass 1 files entering citation */ 52312909Sgarrison pass2(ifd, ofd) 52412909Sgarrison FILE *ifd, *ofd; 52512909Sgarrison { 52612909Sgarrison char c; 52712909Sgarrison int i, fn, footrefs[25], dumped; 52812909Sgarrison 52912909Sgarrison fn = -1; 53012909Sgarrison dumped = foot; 53112909Sgarrison while (getch(c, ifd) != EOF) { 53212909Sgarrison while (c == '\n') { 53312909Sgarrison putc(c, ofd); 53412909Sgarrison if (foot && fn >= 0) { 53512909Sgarrison for (i = 0; i <= fn; i++) 53612909Sgarrison dumpref(footrefs[i], ofd); 53712909Sgarrison fn = -1; 53812909Sgarrison } 53912909Sgarrison if (testc(c, '.', ifd, ofd)) 54012909Sgarrison if (testc(c, '[', ifd, ofd)) 54112909Sgarrison if (testc(c, ']', ifd, ofd)) { 54212909Sgarrison while (echoc(c, ifd, ofd) != '\n') 54312909Sgarrison ; 54412909Sgarrison dumped = true; 54515902Srrh for (i = 0; i < numrefs; i++){ 54612909Sgarrison dumpref(i, ofd); 54715902Srrh } 54812909Sgarrison getch(c, ifd); 54912909Sgarrison } 55012909Sgarrison } 55116245Srrh if (c == FMTSTART) 55216245Srrh changefmt(ifd); 55316245Srrh else if (c == CITEMARK) 55412909Sgarrison fn = putrefs(ifd, ofd, footrefs, fn); 55512909Sgarrison else if (c != EOF) 55612909Sgarrison putc(c, ofd); 55712909Sgarrison } 55812909Sgarrison if (dumped == false) 55915066Sgarrison bibwarning("Warning: references never dumped\n",""); 56012909Sgarrison } 56116245Srrh /* 56216245Srrh * change citation format 56316245Srrh */ 56416245Srrh changefmt(ifd) 56516245Srrh FILE *ifd; 56616245Srrh { 56716245Srrh char c; 56816245Srrh char *to; 56916245Srrh to = ncitetemplate; 57016245Srrh while (getch(c, ifd) != FMTEND) 57116245Srrh *to++ = c; 57216245Srrh *to = 0; 57316245Srrh strcpy(citetemplate, ncitetemplate); 57416245Srrh } 575