📄 bibargs.c
字号:
#ifndef lintstatic char sccsid[] = "@(#)bibargs.c 2.13 5/27/93";#endif not lint/* Authored by: Tim Budd, University of Arizona, 1983. 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 read argument strings for bib and listrefs do name formatting, printing lines, other actions common to both */# include <stdio.h># include <ctype.h># include "bib.h"# define LINELENGTH 1024# define MAXDEFS 500 /* maximum number of defined words *//* global variables */ char bibfname[120]; /* file name currently being read */ int biblineno; /* line number currently being referenced */ int abbrev = false; /* automatically abbreviate names */ int capsmcap = false; /* print names in caps small caps (CACM form)*/ int TibOption = false; /* expect files in TiB format */ int TibxOption = false; /* to create files for bib2tib */ int numrev = 0; /* number of authors names to reverse */ int edabbrev = false; /* abbreviate editors names ? */ int edcapsmcap = false; /* print editors in cap small caps */ int ednumrev = 0; /* number of editors to reverse */ int max_klen = 6; /* max size of key */ int sort = false; /* sort references ? (default no) */ int foot = false; /* footnoted references ? (default endnotes) */ int doacite = true; /* place citations ? */ int redefWarning = false; /* warnings on attempted redefs ? */ int hyphen = false; /* hypenate contiguous references */ int ordcite = true; /* order multiple citations */ char sortstr[80] = "1"; /* sorting template */ char trailstr[80] = ""; /* trailing characters to output */ char pfile[400]; /* private file name */ int personal = false; /* personal file given ? (default no) */ char citetemplate[80] = "1"; /* citation template */ struct wordinfo words[MAXDEFS]; /* defined words */ struct wordinfo *wordhash[HASHSIZE]; struct wordinfo *wordsearch(); int wordtop = 0; /* number of defined words */ char letterSeen[128]; /* keeps track of keyletters * so we know whether to emit a .ds * or a .as /* *//* where output goes */ extern FILE *tfd;/* reference file information */ extern struct refinfo refinfo[]; extern char reffile[];#ifndef INCORE extern FILE *rfd;#endif not INCORE extern int numrefs; extern char *programName;char *usageArr[] = {"-aa abbreviate authors' first names","-arN reverse first N authors' names; no N, do all","-ax print authors' last names in Caps-Small","-cS use template S for citations","-d change the default directory","-ea abbreviate editors' first names","-ex print editors' last names in Caps-Small","-erN reverse first N editors' names; no N, do all","-f dump reference after citation for footnotes","-iFILE process FILE (e.g. a file of definitions)","-h hyphenate sequences of citations (turns on -o)","-nS turn off options; S is composed of the option letters 'afhosx'","-pFILE search these FILEs (comma separated list) instead of INDEX","-R print warnings when duplicate definitions of names are ignored","-sS sort references according to template S","-tTYPE use the style TYPE","-Tib expect files to be in TiB format (which see)","-Tibx write a file for converting bib to TiB-style |macros|","",0}; voidusageErr(argv0, opt, str) char *argv0; char *opt; char *str;{ char **p; fprintf(stderr, "Illegal invocation of %s. Acceptable options:\n", argv0); fprintf(stderr, "Argument: %s\n", opt); fprintf(stderr, "Problem: %s\n", str); for (p = usageArr; *p != 0; p++) { fprintf(stderr, " %s\n", *p); }}/* bibwarning - print out a warning message */ /*VARARGS1*/ bibwarning(msg, a1, a2) char *msg;{ fprintf(stderr,"%s: `%s', line %d: ", programName, bibfname, biblineno); fprintf(stderr, msg, a1, a2); fprintf(stderr, "\n");}/* doargs - read command argument line for both bib and listrefs set switch values call rdtext on file arguments, after dumping default style file if no alternative style is given*/ int doargs(argc, argv, defstyle) int argc; char **argv, defstyle[];{ int numfiles, i, style; char *p, *q, *walloc(); FILE *fd; numfiles = 0; style = true; TibxOption = false; newbibdir(BMACLIB); programName = argv[0]; for (i = 1; i < argc; i++) if (argv[i][0] == '-') switch(argv[i][1]) { case 'a': for (p = &argv[i][2]; *p; p++) if (*p == 'a' || *p == 0) abbrev = true; else if (*p == 'x') capsmcap = true; else if (*p == 'r') { if (*(p+1)) numrev = atoi(p+1); else numrev = 1000; break; } break; case 'c': if (argv[i][2] == 0) error("citation string expected for 'c'"); else for (p = citetemplate,q = &argv[i][2]; *p++ = *q++; ); break; case 'd': if (argv[i][2]) p = &argv[i][2]; else { /* take next arg */ i++; p = argv[i]; } newbibdir(p); break; case 'e': for (p = &argv[i][2]; *p; p++) if (*p == 'a') edabbrev = true; else if (*p == 'x') edcapsmcap = true; else if (*p == 'r') { if (*(p+1)) ednumrev = atoi(p+1); else ednumrev = 1000; break; } break; case 'f': CASE_f: foot = true; hyphen = false; break; case 'i': CASE_i: if (argv[i][2]) p = &argv[i][2]; else { /* take next arg */ i++; p = argv[i]; } incfile(p); break; case 'l': if (argv[i][2]){ max_klen = atoi(&argv[i][2]); if (max_klen > REFSIZE) error("too long key size"); } else { error("-l needs a numeric value"); } break; case 'h': hyphen = ordcite = true; break; case 'n': for (p = &argv[i][2]; *p; p++) if (*p == 'a') abbrev = false; else if (*p == 'f') foot = false; else if (*p == 'h') hyphen = false; else if (*p == 'o') ordcite = false; else if (*p == 'R') redefWarning = false; else if (*p == 'r') numrev = 0; else if (*p == 's') sort = false; else if (*p == 'x') capsmcap = false; else if (*p == 'v') doacite = true; break; case 'o': ordcite = true; break; case 'p': if (argv[i][2]) p = &argv[i][2]; else { /* take next arg */ i++; p = argv[i]; } strcpy(pfile, p); personal = true; break; case 'R': redefWarning = true; break; case 'r': if (argv[i][2] == 0) /* synonym -ar */ numrev = 1000; else numrev = atoi(&argv[i][2]); break; case 's': sort = true; if (argv[i][2]) for (p = sortstr,q = &argv[i][2]; *p++ = *q++; ); break; case 't': style = false; goto CASE_i; case 'T': if (strcmp("Tib", &(argv[i][1])) == 0) TibOption = true; else if (strcmp("Tibx",&(argv[i][1])) == 0) TibxOption = true; else { usageErr(argv[0], argv[i], "Did you want the Tib option?"); error("'%s' invalid switch", argv[i]); } break; case 'v': doacite = false; goto CASE_f; case 'x': capsmcap = true; /* synonym for -ax */ break; case 0: if (style) { /* no style command given, take default */ style = false; incfile( defstyle ); } strcpy(bibfname,"<stdin>"); rdtext(stdin); numfiles++; break; default: usageErr(argv[0], argv[i], "Invalid switch"); error("'%c' invalid switch", argv[i][1]); } else { /* file name */ numfiles++; if (style) { style = false; incfile( defstyle ); } fd = fopen(argv[i], "r"); if (fd == NULL) { error("can't open file %s", argv[i]); } else { strcpy(bibfname, argv[i]); rdtext(fd); fclose(fd); } } if (style) incfile( defstyle ); if (TibxOption) { /* Emits m4 macros that allow easy transformation of old bib-style bibliographic databases into tib-style. The primary problem (although not the only one) is the change of |macro| calls. */ reg struct wordinfo *wp; FILE *outf; outf = fopen("bib.m4.in","w"); for (i=0; i<HASHSIZE; i++) { for (wp = wordhash[i]; wp != NULL; wp = wp->wi_hp) { fprintf(outf,"define(%s,|%s__m4_|)dnl\n",wp->wi_word,wp->wi_word); } } fclose(outf); } return(numfiles);}newbibdir(name) char *name;{ strreplace(COMFILE, BMACLIB, name); strreplace(DEFSTYLE, BMACLIB, name); strcpy(BMACLIB, name); wordrestuff("BMACLIB", BMACLIB); fprintf(tfd, ".ds l] %s\n", BMACLIB);}/* incfile - read in an included file */incfile(np) char *np;{ char name[120]; FILE *fd; char *p, line[LINELENGTH], dline[LINELENGTH], word[80], *tfgets(); int i, getwrd(); strcpy(line, bibfname); /* temporary save in case of errors */ /* first try ./<yourfile> */ strcpy(bibfname, np); fd = fopen(bibfname, "r"); /* try BMACLIB/<yourfile> */ if (fd == NULL && *np != '/') { strcpy(name, BMACLIB); strcat(name, "/"); strcat(name, np); strcpy(bibfname, name); fd = fopen(bibfname, "r"); } /* try BMACLIB/tibmacs/<yourfile> */ if (TibOption && fd == NULL && *np != '/') { strcpy(name, BMACLIB); strcat(name, "/tibmacs/"); strcat(name, np); strcpy(bibfname, name); fd = fopen(bibfname, "r"); } /* try BMACLIB/bibmacs/<yourfile> */ if (!TibOption && fd == NULL && *np != '/') { strcpy(name, BMACLIB); strcat(name, "/bibmacs/"); strcat(name, np); strcpy(bibfname, name); fd = fopen(bibfname, "r"); } /* try ./bib.<yourfile> */ if (fd == NULL && *np != '/') { strcpy(name, "bib."); strcat(name, np); strcpy(bibfname, name); fd = fopen(bibfname, "r"); } /* try BMACLIB/bib.<yourfile> */ if (fd == NULL && *np != '/') { strcpy(name,BMACLIB); strcat(name, "/bib."); strcat(name, np); strcpy(bibfname, name); fd = fopen(bibfname, "r"); } if (fd == NULL) { /* unsave old name */ strcpy(bibfname, line); bibwarning("%s: can't find", np); exit(1); } /* now go off and process file */ biblineno = 1; while (tfgets(line, LINELENGTH, fd) != NULL) { biblineno++; switch(line[0]) { case '#': break; case 'A': for (p = &line[1]; *p; p++) if (*p == 'A' || *p == '\0') abbrev = true; else if (*p == 'X') capsmcap = true; else if (*p == 'R') { if (*(p+1)) numrev = atoi(p+1); else numrev = 1000; break; } break; case 'C': for (p = &line[1]; *p == ' '; p++) ; strcpy(citetemplate, p); break; case 'D': if ((i = getwrd(line, 1, word)) == 0) error("word expected in definition"); if (wordsearch(word)) { /* already there-toss rest of def.*/ if (redefWarning) bibwarning("Attempted redefine of %s ignored.",word); while(line[strlen(line)-1] == '\\' ) { if (tfgets(line, LINELENGTH, fd) == NULL) break; } break; } for (p = &line[i]; isspace(*p); p++) ; for (strcpy(dline, p); dline[strlen(dline)-1] == '\\'; ){ dline[strlen(dline)-1] = '\n'; if (tfgets(line, LINELENGTH, fd) == NULL) break; strcat(dline, line); } wordstuff(word, dline); break; case 'E': for (p = &line[1]; *p; p++) if (*p == 'A') edabbrev = true; else if (*p == 'X') edcapsmcap = true; else if (*p == 'R') { if (*(p+1)) ednumrev = atoi(p+1); else ednumrev = 1000; break; } break; case 'F': foot = true; hyphen = false; break; case 'I': for (p = &line[1]; *p == ' '; p++); expand(p); incfile(p); break; case 'H': hyphen = ordcite = true; break; case 'O': ordcite = true; break; case 'R': if (line[1] == 0) /* this is now replaced by AR */ numrev = 1000; else numrev = atoi(&line[1]); break; case 'S': sort = true;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -