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