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