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