Bell 32V development
[unix-history] / usr / src / cmd / refer / refer6.c
CommitLineData
2b1a705e
TL
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;
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 }
101if (lastype && macro)
102 fprintf(fo, "..%c", sep);
103fprintf(fo, ".nr [T %d%c", ltitle, sep);
104fprintf(fo, ".nr [A %d%c", lauth, sep);
105fprintf (fo, ".][ %s%c", class(n, tvec), '\n');
106}
107tabs (sv, line)
108 char *sv[], *line;
109{
110char *p;
111int n = 0;
112sv[n++] = line;
113for( p= line; *p; p++)
114 {
115 if (*p == '\n')
116 {
117 *p=0;
118 sv[n++] = p+1;
119 }
120 }
121return(n-1);
122}
123char *
124class (nt, tv)
125 char *tv[];
126{
127if (hastype (nt, tv, 'J'))
128 return("1 journal-article");
129if (hastype (nt, tv, 'B'))
130 return("3 article-in-book");
131if (hastype (nt, tv, 'R'))
132 return ("4 tech-report");
133if (hastype (nt, tv, 'G'))
134 return ("4 tech-report");
135if (hastype (nt, tv, 'I'))
136 return("2 book");
137if (hastype (nt, tv,'M'))
138 return ("5 bell-tm");
139return("0 other");
140}
141hastype (nt, tv, c)
142 char *tv[];
143{
144int i;
145for(i=0; i<nt; i++)
146 if ( control(tv[i][0]) && tv[i][1]==c )
147 return(1);
148return(0);
149}
150char *
151caps(a, b)
152 char *a, *b;
153{
154char *p;
155int c, alph, this;
156p=b;
157alph = 0;
158while (c = *a++)
159 {
160 this = isalpha(c);
161 if (this && alph==1)
162 {
163 *b++ = '\\';
164 *b++ = 's';
165 *b++ = '-';
166 *b++ = '2';
167 }
168 if (!this && alph>1)
169 {
170 *b++ = '\\';
171 *b++ = 's';
172 *b++ = '+';
173 *b++ = '2';
174 }
175 if (this)
176 c &= (~040);
177 *b++ = c;
178 alph = this ? alph+1 : 0;
179 }
180if (alph>1)
181 {
182 *b++ = '\\';
183 *b++ = 's';
184 *b++ = '+';
185 *b++ = '2';
186 }
187*b=0;
188return (p);
189}
190char *
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}