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

📄 bibargs.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 3 页
字号:
                   for (p = &line[1]; *p == ' '; p++) ;                   strcpy(sortstr, p);                   break;         case 'T': for (p = &line[1]; *p == ' '; p++) ;                   strcpy(trailstr, p);                   break;         case 'X': capsmcap = true;     /* this is now replace by AX */                   break;         default:  fprintf(tfd,"%s\n",line);                   while (fgets(line, LINELENGTH, fd) != NULL)                      fputs(line, tfd);                   return;         }   }   /* close up */   fclose(fd);}/* error - report unrecoverable error message */  /*VARARGS1*/  error(str, a1, a2)  char *str;{  bibwarning(str, a1, a2);  /*   *	clean up temp files and exit   */  cleanup(1);}#ifndef INCORE#ifdef READWRITE/*** fixrfd( mode ) -- re-opens the rfd file to be read or write,**      depending on the mode.  Uses a static int to save the current mode**      and avoid unnecessary re-openings.*/fixrfd( mode )register int mode;{	static int cur_mode = WRITE;    /* rfd open for writing initially */	if (mode != cur_mode)	{		rfd = freopen(reffile, ((mode == READ)? "r" : "a"), rfd);		cur_mode = mode;		if (rfd == NULL)		      error("Hell!  Couldn't re-open reference file %s",			reffile);	}}#endif#endif not INCORE/* tfgets - fgets which trims off newline */   char *tfgets(line, n, ptr)   char line[];   int  n;   FILE *ptr;{  reg char *p;   p = fgets(line, n, ptr);   if (p == NULL)      return(NULL);   else      for (p = line; *p; p++)         if (*p == '\n')            *p = 0;   return(line);}/* getwrd - place next word from in[i] into out */int getwrd(in, i, out)   reg char in[], out[];   reg int i;{  int j;   j = 0;   while (isspace(in[i]))      i++;   if (in[i] != '\0')      while (in[i]  != '\0' && !isspace(in[i]))         out[j++] = in[i++];   else      i = 0;    /* signals end of in[i..]   */   out[j] = 0;   return (i);}/* walloc - allocate enough space for a word */char *walloc(word)   char *word;{  char *i, *malloc();   i = malloc(1 + strlen(word));   if (i == NULL)      error("out of storage");   strcpy(i, word);   return(i);}/* isword - see if character is legit word char */#define iswordc(c) (isalnum(c) || c == '&' || c == '_')   expand(line)   char *line;{  char line2[REFSIZE], word[REFSIZE];   reg	struct wordinfo *wp;   reg	char *p, *q, *w;   q = line2;   if (TibOption) {      /* expand only macro names in |name| vertical bars; name must exist */      for (p = line; *p != '\0'; /* VOID */ ) {	 if (*p == '|') {	    p++;	    w = word;	    while (*p != '|' && *p != '\0' && !isspace(*p)) { *w++ = *p++; }	    *w = '\0';	    /* skip second '|', if present */	    if (*p++ != '|') {	       --p;	       bibwarning("Unbalanced |macro| bars\n");	       }	    else if ((wp = wordsearch(word)) != 0) {	       strcpy(word, wp->wi_def);	       if (wp->wi_expanding) {		  bibwarning("Recursive definition for |%s|\n", word);		  }	       else {		  wp->wi_expanding = true;		  expand(word);		  wp->wi_expanding = false;		  }	       }	    else {	       char errword[REFSIZE];	       bibwarning("word |%s| not defined\n", word);	       strcpy(errword, "?");	       strcat(errword, word);	       strcat(errword, "?");	       wordstuff(word, errword);	       strcpy(word, errword);	       }	    for (w = word; *w != '\0'; *q++ = *w++);	    }	 else {	    *q++ = *p++;	    }	 }          }   else {      for (p = line; *p != '\0'; /*VOID*/){	 if (isalnum(*p)) {	    for (w = word; *p && iswordc(*p); ) *w++ = *p++;	    *w = 0;	    if (wp = wordsearch(word)){	       if (wp->wi_expanding) 		  bibwarning("Recursive definition for %s\n", word);	       else {		  strcpy(word, wp->wi_def);		  wp->wi_expanding = true;		  expand(word);		  wp->wi_expanding = false;		  }	       }	    for (w = word; *w != '\0'; *q++ = *w++);	    }	 else if (*p == '\\' && *(p+1) != '\0') {	    *q++ = *p++;	    *q++ = *p++;	    }	 else {	    *q++ = *p++;	    }	 }      }   *q = 0;   strcpy(line, line2);}/* wordstuff- save a word and its definition, building a hash table */   wordstuff(word, def)   char *word, *def;{   int i;   if (wordtop >= MAXDEFS)	error("too many definitions, max of %d", MAXDEFS);   words[wordtop].wi_length = strlen(word);   words[wordtop].wi_word = word ? walloc(word) : NULL;   words[wordtop].wi_def = def ? walloc(def) : NULL;   i = strhash(word);   words[wordtop].wi_expanding = false;   words[wordtop].wi_hp = wordhash[i];   wordhash[i] = &words[wordtop];   wordtop++;}   struct wordinfo *wordsearch(word)   char *word;{   reg int lg;   reg struct wordinfo *wp;   lg = strlen(word);   for (wp = wordhash[strhash(word)]; wp; wp = wp->wi_hp){	if (wp->wi_length == lg && (strcmp(wp->wi_word, word) == 0)){		return(wp);	}   }   return(0);}/* wordrestuff - save a word and its definition, but replace any existing * definition; this could be more efficient, but it is only used to * redefine BMACLIB at the present.  -ads 8/88 */   wordrestuff(word, def)   char *word, *def;{   struct wordinfo *wp = wordsearch(word);   if (wp == NULL) wordstuff(word, def);   else {      if (wp->wi_word != NULL) free(wp->wi_word);      if (wp->wi_def != NULL) free(wp->wi_def);      wp->wi_length = strlen(word);      wp->wi_word = word ? walloc(word) : NULL;      wp->wi_def = def ? walloc(def) : NULL;      wp->wi_expanding = false;      }}   int strhash(str)   reg char *str;{   reg int value = 0;   for (value = 0; *str; value <<= 2, value += *str++)/*VOID*/;   value %= HASHSIZE;   if (value < 0)	value += HASHSIZE;   return(value);}/* rdref - read text for an already cited reference */   rdref(p, ref)   struct refinfo *p;   char ref[REFSIZE];{   ref[0] = 0;#ifndef INCORE#ifdef READWRITE   fixrfd( READ );                      /* fix access mode of rfd, if nec. */#endif   fseek(rfd, p->ri_pos, 0);   fread(ref, p->ri_length, 1, rfd);#else INCORE   strcpy(ref, p->ri_ref);#endif INCORE}/* wrref - write text for a new reference */   wrref(p, ref)   struct refinfo *p;   char ref[REFSIZE];{#ifndef INCORE#ifdef READWRITE    fixrfd( WRITE );                 /* fix access mode of rfd, if nec. */#else    fseek(rfd, p->ri_pos, 0);        /* go to end of rfd */#endif    fwrite(ref, p->ri_length, 1, rfd);#else INCORE   p->ri_ref = walloc(ref);#endif INCORE}/* breakname - break a name into first and last name */   breakname(line, first, last)   char line[], first[], last[];{  reg char *t, *f, *q, *r, *p;   for (t = line; *t != '\n'; t++);   for (t--; isspace(*t); t--);   /* now strip off last name */   for (q = t; isspace(*q) == 0 || ((*q == ' ') & (*(q-1) == '\\')); q--)      if (q == line)         break;   f = q;   if (q != line) {      q++;      for (; isspace(*f); f--);      f++;      }   /* first name is start to f, last name is q to t */   for (r = first, p = line; p != f; )      *r++ = *p++;   *r = 0;   for (r = last, p = q, t++; q != t; )      *r++ = *q++;   *r = 0;}/* match - see if string1 is a substring of string2 (case independent)*/   int match(str1, str2)   reg char str1[], str2[];{  reg int  j, i;   char a, b;   for (i = 0; str2[i]; i++) {      for (j = 0; str1[j]; j++) {         if (isupper(a = str2[i+j]))            a = (a - 'A') + 'a';         if (isupper(b = str1[j]))            b = (b - 'A') + 'a';         if (a != b)            break;         }      if (str1[j] == 0)         return(true);      }   return(false);}/* scopy - append a copy of one string to another */   char *scopy(p, q)   reg char *p, *q;{   while (*p++ = *q++)      ;   return(--p);}/* rcomp - reference comparison routine for qsort utility */   int rcomp(ap, bp)   struct refinfo *ap, *bp;{  char ref1[REFSIZE], ref2[REFSIZE], field1[MAXFIELD], field2[MAXFIELD];   reg	char *p, *q;   char *getfield();   int  neg, res;   int  fields_found;   rdref(ap, ref1);   rdref(bp, ref2);   for (p = sortstr; *p; p = q) {      if (*p == '-') {         p++;         neg = true;         }      else         neg = false;      q = getfield(p, field1, ref1);      fields_found = true;      if (q == 0) {	 res = 1;	 fields_found = false;      } else if (strcmp (field1, "") == 0) {	/* field not found */         if (*p == 'A') {            getfield("F", field1, ref1);	    if (strcmp (field1, "") == 0) {               getfield("I", field1, ref1);	       if (strcmp (field1, "") == 0) {	          res = 1;		  fields_found = false;	       }	    }	 } else {	    res = 1;	    fields_found = false;	 }      }      if (getfield(p, field2, ref2) == 0) {	 res = -1;	 fields_found = false;      } else if (strcmp (field2, "") == 0) {	/* field not found */         if (*p == 'A') {            getfield("F", field2, ref2);	    if (strcmp (field2, "") == 0) {               getfield("I", field2, ref2);	       if (strcmp (field2, "") == 0) {	          res = -1;		  fields_found = false;	       }	    }	 } else {	    res = -1;	    fields_found = false;	 }      }      if (fields_found) {         if (*p == 'A') {            if (isupper(field1[0]))               field1[0] -= 'A' - 'a';            if (isupper(field2[0]))               field2[0] -= 'A' - 'a';            }         res = strcmp(field1, field2);         }      if (neg)         res = - res;      if (res != 0)         break;      }   if (res == 0)      if (ap < bp)         res = -1;      else         res = 1;   return(res);}/* makecites - make standard citation strings, using citetemplate currently in effect */   makecites(){  char ref[REFSIZE], tempcite[100], *malloc();   reg int  i;   for (i = 0; i < numrefs; i++) {      rdref(&refinfo[i], ref);      bldcite(tempcite, i, ref);      refinfo[i].ri_cite = malloc(2 + strlen(tempcite));      if (refinfo[i].ri_cite == NULL)         error("out of storage");      strcpy(refinfo[i].ri_cite, tempcite);      }}/* bldcite - build a single citation string */   bldcite(cp, i, ref)   char *cp, ref[];   int  i;{  reg char *p, *q, *fp;   char c;   char field[REFSIZE];   char *getfield(), *aabet(), *aabetlast(),        *fullaabet(), *multfull();   getfield("F", field, ref);   if (field[0] != 0)      for (p = field; *p; p++)         *cp++ = *p;   else {      p = citetemplate;      field[0] = 0;      while (c = *p++) {         if (isalpha(c)) {                      /* field name   */            q = getfield(p-1, field, ref);            if (q != 0) {               p = q;               for (fp = field; *fp; )                  *cp++ = *fp++;               }            }         else if (c == '1') {                   /* numeric  order */            sprintf(field,"%d",1 + i);            for (fp = field; *fp; )               *cp++ = *fp++;            }         else if (c == '2')                     /* alternate alphabetic */            cp = aabet(cp, ref);         else if (c == '3')                     /* Astrophysical Journal style*/            cp = multfull(cp, ref, 3);         else if (c == '4')                     /* Computing Surveys style*/            cp = multfull(cp, ref, 2);	 else if (c == '8')			/* Full alphabetic */	    cp = fullaabet(cp, ref);         else if (c == '9')                     /* Last name of Senior Author*/            cp = aabetlast(cp, ref);	 else if (c == '0') {			/* print nothing */

⌨️ 快捷键说明

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