1: # include "refer.h" 2: extern int refnum; 3: 4: putref (n, tvec) 5: char *tvec[]; 6: { 7: char *s, *tx; 8: char buf1[LLINE], buf2[50]; 9: int nauth 0, i, lastype 0, cch, macro 0, la; 10: int lauth =0, ltitle =0, lother =0; 11: 12: fprintf(fo, ".]-%c", sep); 13: for (i=0; i<n; i++) 14: { 15: s = tvec[i]; 16: if (*s==0) continue; 17: if (control(s[0]) ) 18: { 19: if (lastype && macro) 20: fprintf(fo, "..%c", sep); 21: if (control(s[1])) 22: { 23: cch = s[2]; 24: tx = s+3; 25: macro=1; 26: } 27: else 28: { 29: cch = s[1]; 30: tx = s+2; 31: macro=0; 32: } 33: } 34: else 35: { 36: cch = lastype; 37: tx=s; 38: } 39: if (mindex (smallcaps, cch)) 40: tx = caps(tx, buf1); 41: if (!control(s[0])) /* append to previous item */ 42: { 43: if (lastype!=0) 44: { 45: if (macro) 46: fprintf(fo, "%s%c", tx, sep); 47: else 48: fprintf(fo, ".as [%c \" %s%c",lastype,tx,sep); 49: if (lastype == 'T') 50: ltitle = (mindex(".;,?", last(tx))!=0); 51: if (lastype == 'A') 52: lauth = last(tx) == '.'; 53: } 54: continue; 55: } 56: if (mindex("XYZ[]", cch)) /* skip these */ 57: { 58: lastype=0; 59: continue; 60: } 61: else if (cch == 'A') 62: { 63: if (nauth < authrev) 64: tx = revauth(tx, buf2); 65: if (nauth++ ==0) 66: if (macro) 67: fprintf(fo, ".de [%c%c%s%c",cch,sep,tx,sep); 68: else 69: fprintf(fo, ".ds [%c%s%c", cch,tx,sep); 70: else 71: { 72: la = (tvec[i+1][1]!='A'); 73: fprintf(fo, ".as [A \""); 74: if (la == 0 || nauth != 2) 75: fprintf(fo, ","); 76: if (la) 77: #ifdef MFLAG 78: fprintf(fo," \\*(&2"); 79: #else 80: fprintf(fo,"%s", 81: mindex(smallcaps, 'A')? " \\s-2AND\\s+2" : " and"); 82: #endif 83: fprintf(fo, "%s%c", tx, sep); 84: } 85: lauth = last(tx)=='.'; 86: } 87: #ifdef MFLAG 88: else if (cch=='D' && mflag) { 89: if (macro) 90: fprintf(fo,".de [D%c%s",sep,tx); 91: else 92: fprintf(fo,".ds [D%s",tx); 93: if (labc[refnum]==1) 94: fprintf(fo,"%c%d%c%c",KEYLET,refnum,KEYLET,sep); 95: else 96: fprintf(fo,"%c%c",labc[refnum],sep); 97: } 98: #endif 99: else 100: if (macro) 101: fprintf(fo, ".de [%c%c%s%c",cch,sep, tx, sep); 102: else 103: fprintf(fo, ".ds [%c%s%c",cch,tx, sep); 104: if (cch=='P') 105: fprintf(fo, ".nr [P %d%c", mindex(s, '-')!=0, sep); 106: lastype = cch; 107: if (cch == 'T') 108: ltitle = (mindex(".;,?", last(tx)) != 0); 109: if (cch == 'O') 110: lother = (mindex(".;,?", last(tx)) != 0); 111: } 112: if (lastype && macro) 113: fprintf(fo, "..%c", sep); 114: fprintf(fo, ".nr [T %d%c", ltitle, sep); 115: fprintf(fo, ".nr [A %d%c", lauth, sep); 116: fprintf(fo, ".nr [O %d%c", lother, sep); 117: fprintf (fo, ".][ %s%c", class(n, tvec), '\n'); 118: } 119: tabs (sv, line,lim) 120: char *sv[], *line; 121: { 122: char *p; 123: int n 0; 124: sv[n++] = line; 125: for( p= line; *p && n<lim; p++) 126: { 127: if (*p == '\n') 128: { 129: *p=0; 130: sv[n++] = p+1; 131: } 132: } 133: if (*p) 134: fprintf(stderr,"%s: %s: Too many %% fields in reference\n", 135: Ifile, sinput); 136: return(n-1); 137: } 138: class (nt, tv) 139: char *tv[]; 140: { 141: if (hastype (nt, tv, 'J')) 142: return("1 journal-article"); 143: if (hastype (nt, tv, 'B')) 144: return("3 article-in-book"); 145: if (hastype (nt, tv, 'R')) 146: return ("4 tech-report"); 147: if (hastype (nt, tv, 'G')) 148: return ("4 tech-report"); 149: if (hastype (nt, tv, 'I')) 150: return("2 book"); 151: if (hastype (nt, tv,'M')) 152: return ("5 bell-tm"); 153: return("0 other"); 154: } 155: hastype (nt, tv, c) 156: char *tv[]; 157: { 158: int i; 159: for(i=0; i<nt; i++) 160: if ( control(tv[i][0]) && tv[i][1]==c ) 161: return(1); 162: return(0); 163: } 164: caps(a, b) 165: char *a, *b; 166: { 167: char *p; 168: int c, alph, this; 169: p=b; 170: alph = 0; 171: while (c = *a++) 172: { 173: this = isalpha(c); 174: if (this && alph==1) 175: { 176: *b++ = '\\'; 177: *b++ = 's'; 178: *b++ = '-'; 179: *b++ = '2'; 180: } 181: if (!this && alph>1) 182: { 183: *b++ = '\\'; 184: *b++ = 's'; 185: *b++ = '+'; 186: *b++ = '2'; 187: } 188: if (this) 189: c &= (~040); 190: *b++ = c; 191: alph = this ? alph+1 : 0; 192: } 193: if (alph>1) 194: { 195: *b++ = '\\'; 196: *b++ = 's'; 197: *b++ = '+'; 198: *b++ = '2'; 199: } 200: *b=0; 201: return (p); 202: } 203: revauth(s, b) 204: char *s, *b; 205: { 206: char *init, *name, *jr, *p, *bcop; 207: bcop = b; 208: init=name=s; 209: while (*name)name++; 210: while (*--name == ' ') ; 211: *++name = 0; 212: jr=name; 213: while (name>init && *name!= ' ') 214: name--; 215: if (name[-1] == ',' || name[-1]== '(' ) 216: { 217: jr = --name; 218: while (name>init && *name != ' ') 219: name--; 220: } 221: p=name; 222: while (p<jr) 223: *b++ = *p++; 224: *b++ = ','; 225: while (init<name) 226: *b++ = *init++; 227: if (*jr)jr++; 228: while(*jr) 229: *b++ = *jr++; 230: *b++ = 0; 231: return(bcop); 232: } 233: last(s) 234: char *s; 235: { 236: while (*s) s++; 237: return(*--s); 238: }