Research V7 development
[unix-history] / usr / src / cmd / refer / refer6.c
CommitLineData
1f7f4648
ML
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}
126class (nt, tv)
127 char *tv[];
128{
129if (hastype (nt, tv, 'J'))
130 return("1 journal-article");
131if (hastype (nt, tv, 'B'))
132 return("3 article-in-book");
133if (hastype (nt, tv, 'R'))
134 return ("4 tech-report");
135if (hastype (nt, tv, 'G'))
136 return ("4 tech-report");
137if (hastype (nt, tv, 'I'))
138 return("2 book");
139if (hastype (nt, tv,'M'))
140 return ("5 bell-tm");
141return("0 other");
142}
143hastype (nt, tv, c)
144 char *tv[];
145{
146int i;
147for(i=0; i<nt; i++)
148 if ( control(tv[i][0]) && tv[i][1]==c )
149 return(1);
150return(0);
151}
152caps(a, b)
153 char *a, *b;
154{
155char *p;
156int c, alph, this;
157p=b;
158alph = 0;
159while (c = *a++)
160 {
161 this = isalpha(c);
162 if (this && alph==1)
163 {
164 *b++ = '\\';
165 *b++ = 's';
166 *b++ = '-';
167 *b++ = '2';
168 }
169 if (!this && alph>1)
170 {
171 *b++ = '\\';
172 *b++ = 's';
173 *b++ = '+';
174 *b++ = '2';
175 }
176 if (this)
177 c &= (~040);
178 *b++ = c;
179 alph = this ? alph+1 : 0;
180 }
181if (alph>1)
182 {
183 *b++ = '\\';
184 *b++ = 's';
185 *b++ = '+';
186 *b++ = '2';
187 }
188*b=0;
189return (p);
190}
191revauth(s, b)
192 char *s, *b;
193{
194char *init, *name, *jr, *p, *bcop;
195bcop = b;
196init=name=s;
197while (*name)name++;
198jr=name;
199while (name>init && *name!= ' ')
200 name--;
201if (name[-1] == ',' || name[-1]== '(' )
202 {
203 jr = --name;
204 while (name>init && *name != ' ')
205 name--;
206 }
207p=name;
208while (p<jr)
209 *b++ = *p++;
210*b++ = ',';
211while (init<name)
212 *b++ = *init++;
213if (*jr)jr++;
214while(*jr)
215 *b++ = *jr++;
216*b++ = 0;
217return(bcop);
218}
219last(s)
220 char *s;
221{
222while (*s) s++;
223return(*--s);
224}