⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bib.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 2 页
字号:
   }   r = hunt(realhstr);   if (r != NULL) {      /* expand defined string */      strcpy(rf, r);      free(r);      expand(rf);      /* see if reference has already been cited */      if (foot == false && (rp = refssearch(rf))){		return(rp - refinfo);      }      /* didn't match any existing reference, create new one */      if (numrefs >= MAXREFS)	error("too many references, max of %d", MAXREFS);      hash = strhash(rf);      lg = strlen(rf) + 1;      refinfo[numrefs].ri_pos = rend;      refinfo[numrefs].ri_length = lg;      refinfo[numrefs].ri_hp = refshash[hash];      refinfo[numrefs].ri_n = numrefs;      refshash[hash] = &refinfo[numrefs];      wrref(&refinfo[numrefs], rf);      return(numrefs++);      }   else {      bibwarning("no reference matching %s\n", realhstr);      return(-1);      }}struct refinfo *refssearch(rf)   char *rf;{   char ref[REFSIZE];   reg	int i;   int	lg;   reg	struct refinfo *rp;   lg = strlen(rf) + 1;   for (rp = refshash[strhash(rf)]; rp; rp = rp->ri_hp){	     if (rp->ri_length == lg){		     rdref(rp, ref);		     if (strcmp(ref, rf) == 0)			return(rp);	     }   }   return(0);}/* hunt - hunt for reference from either personal or system index *//* the old versions would stop at the first index file where a citation * matched.  This is NOT what is desired.  I have changed it so that it still * returns the first citation found, but also reports the existence of * duplicate entries in an INDEX file as well as across INDEX files. * Also, we do NOT assume that the SYSINDEX has been Tib'd.  Therefore, * if tib style expansion is in effect, the SYSINDEX is not searched. * (Besides which, on Sun systems at least, the SYSINDEX files are * created by refer, not bib, so we can't use them very effectively * anyway.  Besides which again, everything in SYSINDEX is in our * local files anyway.) *                   - ads 8/88 */char *hunt(huntstr)   char huntstr[];{  char *found, *fhunt(), *r, *tp, *sp, fname[120];   found = NULL;   if (personal) {      for (tp = fname, sp = pfile; ; sp++)         if (*sp == ',' || *sp == '\0') {            *tp = '\0';            if ((r = fhunt(fname, huntstr)) != NULL) {		if (found != NULL) {		    /* we need an option to suppress this message -ads 5/89 */		    bibwarning("multiple INDEX files match citation %s\n",							huntstr);		    return (found);		    }		found = r;		}            if (*sp == '\0')               break;            tp = fname;            }         else *tp++ = *sp;      if (found != NULL) return (found);      }   else if (findex) {      if ((r = fhunt(INDXFILE , huntstr)) != NULL)         return(r);      }   if (!TibOption) {      if ((r = fhunt(SYSINDEX , huntstr)) != NULL)	 return(r);      }   return(NULL);}/* fhunt - hunt from a specific file */   char *fhunt(file, huntstr)   char file[], huntstr[];{  char *p, *r, *locate();   r = locate(huntstr, file, max_klen, common);   if (r == NULL)      return(NULL);  /* error */   if (*r == 0)      return(NULL);  /* no match */   for (p = r; *p; p++)      if (*p == '\n')         if (*(p+1) == '\n') { /* end */            if (*(p+2) != 0)               bibwarning("multiple references match %s\n",huntstr);            *(p+1) = 0;            break;            }         else if (*(p+1) != '%' && *(p+1) != '.') /* unnecessary newline */            *p = ' ';   return(r);}struct cite{	int	num;	char	*info;};citesort(p1, p2)	struct cite *p1, *p2;{	return(p1->num - p2->num);}/* putrefs - gather contiguous references together, sort them if called   for, hyphenate if necessary, and dump them out */int putrefs(ifd, ofd, footrefs, fn)FILE *ifd, *ofd;int  fn, footrefs[];{	struct cite cites[MAXATONCE];	char	infoword[HUNTSIZE];    /* information line */	reg	int i;	reg	char *p;	reg	int  ncites, n, j;         /* number of citations being dumped */	char	c, *walloc();	int neg;	/*	 * first gather contiguous references together,	 * and order them if required     	 */	ncites = 0;	do {		neg = 1;		n = 0;		do{			getch(c, ifd);			if (isdigit(c))				n = 10 * n + (c - '0');			else if (c == '-')				neg *= -1;			else if (c == CITEMARK)				break;			else				error("bad cite char 0%03o in pass two",c);		} while(1);		if (neg < 0) {     /* reference not found */			cites[ncites].num = -1;			cites[ncites].info = 0;			ncites++;		} else {			/*			 * Find reference n in the references			 */			int i;			for (i = 0; i < numrefs; i++){				if (refinfo[i].ri_n == n){					cites[ncites].num = i;					cites[ncites].info = 0;					ncites++;					break;				}			}			if (i == numrefs)				error("citation	%d not found in pass 2", n);		}		if (getch(c, ifd) != CITEEND) {			for (p = infoword; c != CITEEND ; ) {				*p++ = c;				getch(c, ifd);			}			*p = 0;			cites[ncites-1].info = walloc(infoword);		}		getch(c, ifd);	} while (c == CITEMARK);	ungetc(c, ifd);	if (ordcite)		qsort(cites, ncites, sizeof(struct cite), citesort);	/* now dump out values */	for (i = 0; i < ncites; i++) {		if (cites[i].num >= 0) {			if (changecite){				char tempcite[128];				char ref[REFSIZE];				struct refinfo *p;				/*				 * rebuild the citation string,				 * using the current template in effect				 */				p = &refinfo[cites[i].num];				rdref(p, ref);				bldcite(tempcite, cites[i].num, ref);				strcat(tempcite, p->ri_disambig);				if (doacite) fputs(tempcite, ofd);			} else {				if (doacite) fputs(refinfo[cites[i].num].ri_cite, ofd);			}			if (!doacite) fputs("\\&", ofd);		}		if (cites[i].info) {			if (doacite) fputs(cites[i].info, ofd);			if (!doacite) fputs("\\&", ofd);			free(cites[i].info);		}		if (hyphen) {			for (j = 1;			     j + i <= ncites && cites[i+j].num == cites[i].num + j;			     j++)/*VOID*/;			if (j + i > ncites)				j = ncites;			else				j = j + i - 1;		} else {			j = i;		}		if (j > i + 1) {			fputs("\\*(]-", ofd);			i = j - 1;		} else if (i != ncites - 1) {			fputs("\\*(],", ofd);		}		if (foot) {			fn++;			footrefs[fn] = cites[i].num;		}	}	return(fn);}/* pass2 - read pass 1 files entering citation */   pass2(ifd, ofd)   FILE *ifd, *ofd;{   char c;   int  i, fn, footrefs[25], dumped;   fn = -1;   dumped = foot;   while (getch(c, ifd) != EOF) {      while (c == '\n') {         putc(c, ofd);         if (foot && fn >= 0) {            for (i = 0; i <= fn; i++)                dumpref(footrefs[i], ofd);            fn = -1;            }         if (testc(c, '.', ifd, ofd))            if (testc(c, '[', ifd, ofd))               if (testc(c, ']', ifd, ofd)) {                  while (echoc(c, ifd, ofd) != '\n')                     ;                  dumped = true;                  for (i = 0; i < numrefs; i++){                     dumpref(i, ofd);		  }                  getch(c, ifd);                  }         }      if (c == FMTSTART)	 changefmt(ifd);      else if (c == CITEMARK)         fn = putrefs(ifd, ofd, footrefs, fn);      else if (c != EOF)         putc(c, ofd);      }   if (dumped == false)      bibwarning("Warning: references never dumped\n","");}/* *	change citation format */changefmt(ifd)	FILE	*ifd;{	char	c;	char	*to;	to = ncitetemplate;	while (getch(c, ifd) != FMTEND)		*to++ = c;	*to = 0;	strcpy(citetemplate, ncitetemplate);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -