|
|
1.1 ! root 1: # include "refer..c" ! 2: char *class(); ! 3: char seenstr[60]; ! 4: putref (n, tvec) ! 5: char *tvec[]; ! 6: { ! 7: char *s, *tx, *sq; ! 8: char *caps(), *revauth(); ! 9: char buf1[LLINE], buf2[50]; ! 10: char *strchr(); ! 11: int nauth = 0, i, lastype = 0, cch, macro = 0, la; ! 12: int lauth =0, ltitle =0, lother =0; ! 13: ! 14: # if D1 ! 15: fprintf(stderr, "in putref, fo is %o\n",fo); ! 16: # endif ! 17: if (!preserve) ! 18: fprintf(fo, ".]-%c", sep); ! 19: else ! 20: fprintf(fo, ".[%c", sep); ! 21: # define dsde (macro? "de" : "ds") ! 22: # define ifnl (macro? sep : ' ') ! 23: seenstr[0]=0; ! 24: for (i=0; i<n; i++) ! 25: { ! 26: s = tvec[i]; ! 27: if (*s==0) continue; ! 28: if (control(s[0]) ) ! 29: { ! 30: if (lastype && macro) ! 31: fprintf(fo, "..%c", sep); ! 32: if (control(s[1])) ! 33: { ! 34: cch = s[2]; ! 35: tx = s+3; ! 36: macro=1; ! 37: } ! 38: else ! 39: { ! 40: cch = s[1]; ! 41: tx = s+2; ! 42: macro=0; ! 43: } ! 44: } ! 45: else ! 46: { ! 47: cch = lastype; ! 48: tx=s; ! 49: } ! 50: # if D1 ! 51: fprintf(stderr, "smallcaps %s cch %c\n",smallcaps, cch); ! 52: # endif ! 53: if (preserve) ! 54: { ! 55: fprintf(fo, "%s%c", s, sep); ! 56: continue; ! 57: } ! 58: if (mindex (smallcaps, cch)) ! 59: tx = caps(tx, buf1); ! 60: # if D1 ! 61: fprintf(stderr, " s %o tx %o %s\n",s,tx,tx); ! 62: # endif ! 63: if (!control(s[0]) || (strchr(appfld, s[1]) && seen(s[1]))) /* append to previous item */ ! 64: { ! 65: if (control(s[0])) ! 66: lastype = s[1]; ! 67: if (lastype!=0) ! 68: { ! 69: if (macro) ! 70: fprintf(fo, "%s%c", tx, sep); ! 71: else ! 72: fprintf(fo, ".as [%c \" %s%c",lastype,tx,sep); ! 73: if (lastype == 'T') ! 74: ltitle = (mindex(".;,?", last(tx))!=0); ! 75: if (lastype == 'A') ! 76: lauth = last(tx) == '.'; ! 77: if (lastype == 'O') ! 78: lother = (mindex(".;,?", last(tx)) != 0); ! 79: } ! 80: continue; ! 81: } ! 82: if (mindex(ignfld, cch)) /* skip XYZ[] */ ! 83: { ! 84: lastype=0; ! 85: continue; ! 86: } ! 87: else ! 88: if (cch == 'A') ! 89: { ! 90: if (nauth < authrev) ! 91: tx = revauth(tx, buf2); ! 92: if (nauth++ ==0) ! 93: if (macro) ! 94: fprintf(fo, ".de [%c%c%s%c",cch,sep,tx,sep); ! 95: else ! 96: fprintf(fo, ".ds [%c%s%c", cch,tx,sep); ! 97: else ! 98: { ! 99: la = (tvec[i+1][1]!='A'); ! 100: fprintf(fo, ".as [A \""); ! 101: if (la == 0 || nauth != 2) ! 102: fprintf(fo, (nauth < authrev) ? ";" : ","); ! 103: if (la) ! 104: fprintf(fo,"%s", ! 105: mindex(smallcaps, 'A')? " \\s-2AND\\s+2" : " and"); ! 106: fprintf(fo, "%s%c", tx, sep); ! 107: } ! 108: lauth = last(tx)=='.'; ! 109: } ! 110: else ! 111: { ! 112: if (cch == 'D' && yearonly) ! 113: { ! 114: sq = tx+strlen(tx); ! 115: while (*--sq!=' ' && sq>tx) ! 116: ; ! 117: if (sq>tx) tx=sq; ! 118: } ! 119: if (macro) ! 120: fprintf(fo, ".de [%c%c%s%c",cch,sep, tx, sep); ! 121: else ! 122: fprintf(fo, ".ds [%c%s%c",cch,tx, sep); ! 123: } ! 124: if (cch=='P') ! 125: fprintf(fo, ".nr [P %d%c", mindex(s, '-')!=0, sep); ! 126: lastype = cch; ! 127: if (cch == 'T') ! 128: ltitle = (mindex(".;,?", last(tx)) != 0); ! 129: if (cch == 'O') ! 130: lother = (mindex(".;,?", last(tx)) != 0); ! 131: } ! 132: if (lastype && macro) ! 133: fprintf(fo, "..%c", sep); ! 134: if (pagecit) ! 135: fprintf(fo, ".ds [%% \\*(%c%c%c", prnA[refnum/62], prnB[refnum%62], sep); ! 136: if (!preserve) ! 137: { ! 138: fprintf(fo, ".nr [T %d%c", ltitle, sep); ! 139: fprintf(fo, ".nr [A %d%c", lauth, sep); ! 140: fprintf(fo, ".nr [O %d%c", lother, sep); ! 141: fprintf (fo, ".][ %s%c", class(n, tvec), '\n'); ! 142: } ! 143: else ! 144: fprintf(fo, ".]\n"); ! 145: } ! 146: tabs (sv, line) ! 147: char *sv[], *line; ! 148: { ! 149: char *p; ! 150: int n = 0; ! 151: sv[n++] = line; ! 152: for( p= line; *p; p++) ! 153: { ! 154: if (*p == '\n') ! 155: { ! 156: *p=0; ! 157: sv[n++] = p+1; ! 158: } ! 159: } ! 160: return(n-1); ! 161: } ! 162: char * ! 163: class (nt, tv) ! 164: char *tv[]; ! 165: { ! 166: if (hastype (nt, tv, 'J')) ! 167: return("1 journal-article"); ! 168: if (hastype (nt, tv, 'B')) ! 169: return("3 article-in-book"); ! 170: if (hastype (nt, tv, 'R')) ! 171: return ("4 tech-report"); ! 172: if (hastype (nt, tv, 'G')) ! 173: return ("4 tech-report"); ! 174: if (hastype (nt, tv, 'I')) ! 175: return("2 book"); ! 176: if (hastype (nt, tv,'M')) ! 177: return ("5 bell-tm"); ! 178: return("0 other"); ! 179: } ! 180: hastype (nt, tv, c) ! 181: char *tv[]; ! 182: { ! 183: int i; ! 184: for(i=0; i<nt; i++) ! 185: if ( control(tv[i][0]) && tv[i][1]==c ) ! 186: return(1); ! 187: return(0); ! 188: } ! 189: char * ! 190: caps(a, b) ! 191: char *a, *b; ! 192: { ! 193: char *p; ! 194: int c, alph, this; ! 195: p=b; ! 196: alph = 0; ! 197: while (c = *a++) ! 198: { ! 199: this = isalpha(c); ! 200: if (this && alph==1) ! 201: { ! 202: *b++ = '\\'; ! 203: *b++ = 's'; ! 204: *b++ = '-'; ! 205: *b++ = '2'; ! 206: } ! 207: if (!this && alph>1) ! 208: { ! 209: *b++ = '\\'; ! 210: *b++ = 's'; ! 211: *b++ = '+'; ! 212: *b++ = '2'; ! 213: } ! 214: if (this) ! 215: c &= (~040); ! 216: *b++ = c; ! 217: alph = this ? alph+1 : 0; ! 218: } ! 219: if (alph>1) ! 220: { ! 221: *b++ = '\\'; ! 222: *b++ = 's'; ! 223: *b++ = '+'; ! 224: *b++ = '2'; ! 225: } ! 226: *b=0; ! 227: return (p); ! 228: } ! 229: char * ! 230: revauth(s, b) ! 231: char *s, *b; ! 232: { ! 233: char *init, *name, *jr, *p, *bcop; ! 234: bcop = b; ! 235: init=name=s; ! 236: while (*name)name++; ! 237: jr=name; ! 238: while (name>init && *name!= ' ') ! 239: name--; ! 240: if (name[-1] == ',' || name[-1]== '(' ) ! 241: { ! 242: jr = --name; ! 243: while (name>init && *name != ' ') ! 244: name--; ! 245: } ! 246: p=name; ! 247: while (p<jr) ! 248: *b++ = *p++; ! 249: if (init<name && nocomma==0) ! 250: *b++ = ','; ! 251: while (init<name) ! 252: *b++ = *init++; ! 253: if (*jr)jr++; ! 254: while(*jr) ! 255: *b++ = *jr++; ! 256: *b++ = 0; ! 257: return(bcop); ! 258: } ! 259: last(s) ! 260: char *s; ! 261: { ! 262: while (*s) s++; ! 263: return(*--s); ! 264: } ! 265: seen(c) ! 266: { ! 267: char *s, *strchr(); ! 268: s = strchr(seenstr,c); ! 269: if (s!=NULL) return(1); ! 270: for(s=seenstr; *s; s++) ! 271: ; ! 272: *s++ = c; ! 273: *s=0; ! 274: return(0); ! 275: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.