1 /* $MirOS: src/usr.bin/oldroff/refer/refer2.c,v 1.2 2008/11/08 23:04:46 tg Exp $ */
2
3 /*-
4 * Copyright (c) 1979, 1980, 1981, 1986, 1988, 1990, 1991, 1992
5 * The Regents of the University of California.
6 * Copyright (C) Caldera International Inc. 2001-2002.
7 * Copyright (c) 2003, 2004
8 * Thorsten "mirabilos" Glaser <tg@mirbsd.org>
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms,
12 * with or without modification, are permitted provided
13 * that the following conditions are met:
14 *
15 * Redistributions of source code and documentation must retain
16 * the above copyright notice, this list of conditions and the
17 * following disclaimer. Redistributions in binary form must
18 * reproduce the above copyright notice, this list of conditions
19 * and the following disclaimer in the documentation and/or other
20 * materials provided with the distribution.
21 *
22 * All advertising materials mentioning features or use of this
23 * software must display the following acknowledgement:
24 * This product includes software developed or owned by
25 * Caldera International, Inc.
26 *
27 * Neither the name of Caldera International, Inc. nor the names
28 * of other contributors may be used to endorse or promote products
29 * derived from this software without specific prior written permission.
30 *
31 * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
32 * INTERNATIONAL, INC. AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
33 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
34 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35 * ARE DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE
36 * LIABLE FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR
37 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
38 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
39 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
40 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
41 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
42 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43 */
44
45 #ifndef lint
46 static char sccsid[] = "@(#)refer2.c 4.4 (Berkeley) 4/18/91";
47 #endif /* not lint */
48
49 #include "refer..c"
50 #define NFLD 30
51 #define TLEN 512
52
53 extern FILE *in;
54 char one[ANSLEN];
55 int onelen = ANSLEN;
56 extern char usedir[];
57
doref(line1)58 doref(line1)
59 char *line1;
60 {
61 char buff[QLEN], dbuff[3*QLEN];
62 char answer[ANSLEN], temp[TLEN], line[BUFSIZ];
63 char *p, **sr, *flds[NFLD], *r;
64 int stat, nf, nr, query = 0, alph, digs;
65
66 again:
67 buff[0] = dbuff[0] = 0;
68 if (biblio && Iline == 1 && line1[0] == '%')
69 strcat(dbuff, line1);
70 while (input(line)) { /* get query */
71 Iline++;
72 if (prefix(".]", line))
73 break;
74 if (biblio && line[0] == '\n')
75 break;
76 if (biblio && line[0] == '%' && line[1] == *convert)
77 break;
78 if (control(line[0]))
79 query = 1;
80 strcat(query ? dbuff : buff, line);
81 if (strlen(buff) > QLEN)
82 err("query too long (%d)", strlen(buff));
83 if (strlen(dbuff) > 3 * QLEN)
84 err("record at line %d too long", Iline-1);
85 }
86 if (biblio && line[0] == '\n' && feof(in))
87 return;
88 if (strcmp(buff, "$LIST$\n")==0) {
89 assert (dbuff[0] == 0);
90 dumpold();
91 return;
92 }
93 answer[0] = 0;
94 for (p = buff; *p; p++) {
95 if (isupper(*p))
96 *p |= 040;
97 }
98 alph = digs = 0;
99 for (p = buff; *p; p++) {
100 if (isalpha(*p))
101 alph++;
102 else
103 if (isdigit(*p))
104 digs++;
105 else {
106 *p = 0;
107 if ((alph+digs < 3) || common(p-alph)) {
108 r = p-alph;
109 while (r < p)
110 *r++ = ' ';
111 }
112 if (alph == 0 && digs > 0) {
113 r = p-digs;
114 if (digs != 4 || atoi(r)/100 != 19) {
115 while (r < p)
116 *r++ = ' ';
117 }
118 }
119 *p = ' ';
120 alph = digs = 0;
121 }
122 }
123 one[0] = 0;
124 if (buff[0]) { /* do not search if no query */
125 for (sr = rdata; sr < search; sr++) {
126 temp[0] = 0;
127 corout(buff, temp, "hunt", *sr, TLEN);
128 assert(strlen(temp) < TLEN);
129 if (strlen(temp)+strlen(answer) > BUFSIZ)
130 err("Accumulated answers too large",0);
131 strcat(answer, temp);
132 if (strlen(answer)>BUFSIZ)
133 err("answer too long (%d)", strlen(answer));
134 if (newline(answer) > 0)
135 break;
136 }
137 }
138 assert(strlen(one) < ANSLEN);
139 assert(strlen(answer) < ANSLEN);
140 if (buff[0])
141 switch (newline(answer)) {
142 case 0:
143 fprintf(stderr, "No such paper: %s\n", buff);
144 return;
145 default:
146 fprintf(stderr, "Too many hits: %s\n", trimnl(buff));
147 choices(answer);
148 p = buff;
149 while (*p != '\n')
150 p++;
151 *++p = 0;
152 case 1:
153 if (endpush)
154 if (nr = chkdup(answer)) {
155 if (bare < 2) {
156 nf = tabs(flds, one);
157 nf += tabs(flds+nf, dbuff);
158 assert(nf < NFLD);
159 putsig(nf,flds,nr,line1,line,0);
160 }
161 return;
162 }
163 if (one[0] == 0)
164 corout(answer, one, "deliv", usedir, QLEN);
165 break;
166 }
167 assert(strlen(buff) < QLEN);
168 assert(strlen(one) < ANSLEN);
169 nf = tabs(flds, one);
170 nf += tabs(flds+nf, dbuff);
171 assert(nf < NFLD);
172 refnum++;
173 if (sort)
174 putkey(nf, flds, refnum, keystr);
175 if (bare < 2)
176 putsig(nf, flds, refnum, line1, line, 1);
177 else
178 flout();
179 putref(nf, flds);
180 if (biblio && line[0] == '\n')
181 goto again;
182 if (biblio && line[0] == '%' && line[1] == *convert)
183 fprintf(fo, "%s%c%s", convert+1, sep, line+3);
184 }
185
newline(s)186 newline(s)
187 char *s;
188 {
189 int k = 0, c;
190
191 while (c = *s++)
192 if (c == '\n')
193 k++;
194 return(k);
195 }
196
choices(buff)197 choices(buff)
198 char *buff;
199 {
200 char ob[BUFSIZ], *p, *r, *q, *t;
201 int nl;
202
203 for (r = p = buff; *p; p++) {
204 if (*p == '\n') {
205 *p++ = 0;
206 corout(r, ob, "deliv", usedir, BUFSIZ);
207 nl = 1;
208 for (q = ob; *q; q++) {
209 if (nl && (q[0]=='.'||q[0]=='%') && q[1]=='T') {
210 q += 3;
211 for (t = q; *t && *t != '\n'; t++)
212 ;
213 *t = 0;
214 fprintf(stderr, "%.70s\n", q);
215 q = 0;
216 break;
217 }
218 nl = *q == '\n';
219 }
220 if (q)
221 fprintf(stderr, "??? at %s\n",r);
222 r=p;
223 }
224 }
225 }
226
control(c)227 control(c)
228 {
229 if (c == '.')
230 return(1);
231 if (c == '%')
232 return(1);
233 return(0);
234 }
235