|
|
1.1 root 1: #ifndef lint
2: static char *sccsid = "@(#)refer5.c 4.2 (Berkeley) 7/18/83";
3: #endif
4:
5: #include "refer..c"
6: #define SAME 0
7: #define NFLAB 2000
8: #define NLABC 100
9:
10: static char sig[NLABC];
11: static char bflab[NFLAB];
12: static char *labtab[NLABC];
13: static char *lbp = bflab;
14: static char labc[NLABC];
15: static char stbuff[50];
16: static int prevsig;
17:
18: putsig (nf, flds, nref, nstline, endline) /* choose signal style */
19: char *flds[], *nstline, *endline;
20: {
21: char t[100], t1[100], t2[100], format[10], *sd, *stline;
22: int addon, another = 0;
23: static FILE *fhide = 0;
24: int i;
25: char tag;
26:
27: if (labels) {
28: if (nf == 0) /* old */
29: sprintf(t, "%s%c", labtab[nref], labc[nref]);
30: else {
31: *t = 0;
32: if (keywant)
33: sprintf(t, "%s", fpar(nf,flds,t1,keywant,1,0));
34: if (science && t[0] == 0) {
35: sd = fpar(nf, flds, t2, 'D', 1, 0);
36: sprintf(t, "%s, %s", fpar(nf,flds,t1,'A',1,0),
37: sd);
38: }
39: else if (t[0] == 0) {
40: sprintf(format,
41: nmlen>0 ? "%%.%ds%%s" : "%%s%%s",
42: nmlen);
43: /* format is %s%s for default labels */
44: /* or %.3s%s eg if wanted */
45: sd = fpar(nf, flds, t2, 'D', 1, 0);
46: if (dtlen > 0) {
47: char *sdb;
48: for (sdb = sd; *sd; sd++)
49: ;
50: sd = sd - dtlen;
51: if (sd < sdb)
52: sd = sdb;
53: }
54: sprintf(t, format, fpar(nf,flds,t1,'A',1,0),
55: sd);
56: }
57: if (keywant) {
58: addon = 0;
59: for (sd = t; *sd; sd++)
60: ;
61: if (*--sd == '-') {
62: addon = 1;
63: *sd = 0;
64: }
65: }
66: if ((!keywant || addon) && !science) {
67: addch(t, keylet(t, nref));
68: }
69: else {
70: tokeytab (t,nref);
71: }
72: }
73: }
74: else {
75: if (sort)
76: sprintf(t, "%c%d%c", FLAG, nref, FLAG);
77: else
78: sprintf(t, "%d", nref);
79: }
80: another = prefix (".[", sd=lookat());
81: if (another && (strcmp(".[\n", sd) != SAME))
82: fprintf(stderr, "File %s line %d: punctuation ignored from: %s",
83: Ifile, Iline, sd);
84: strcat(sig, t);
85: #if EBUG
86: fprintf(stderr, "sig is now %s leng %d\n",sig,strlen(sig));
87: #endif
88: trimnl(nstline);
89: trimnl(endline);
90: stline = stbuff;
91: if (prevsig == 0) {
92: strcpy (stline, nstline);
93: prevsig=1;
94: }
95: if (stline[2] || endline[2]) {
96: stline += 2;
97: endline += 2;
98: }
99: else {
100: stline = "\\*([.";
101: endline = "\\*(.]";
102: }
103: if (science) {
104: stline = " (";
105: endline = ")";
106: }
107: if (bare == 0) {
108: if (!another) {
109: sprintf(t1, "%s%s\%s\n", stline, sig, endline);
110: append(t1);
111: flout();
112: sig[0] = 0;
113: prevsig = 0;
114: if (fo == fhide) {
115: int ch;
116: fclose(fhide);
117: fhide = fopen(hidenam, "r");
118: fo = ftemp;
119: while ((ch = getc(fhide)) != EOF)
120: putc(ch, fo);
121: fclose(fhide);
122: unlink(hidenam);
123: }
124: }
125: else {
126: strcat(sig, ",\\|");
127: if (fo == ftemp) { /* hide if need be */
128: sprintf(hidenam, "/tmp/rj%dc", getpid());
129: #if EBUG
130: fprintf(stderr, "hiding in %s\n", hidenam);
131: #endif
132: fhide = fopen(hidenam, "w");
133: if (fhide == NULL)
134: err("Can't get scratch file %s",
135: (void) hidenam);
136: fo = fhide;
137: }
138: }
139: }
140: if (bare < 2)
141: if (nf > 0)
142: fprintf(fo,".ds [F %s%c",t,sep);
143: if (bare > 0)
144: flout();
145: #if EBUG
146: fprintf(stderr, "sig is now %s\n",sig);
147: #endif
148: }
149:
150: char *
151: fpar (nf, flds, out, c, seq, prepend)
152: char *flds[], *out;
153: {
154: char *p, *s;
155: int i, fnd = 0;
156:
157: for(i = 0; i < nf; i++)
158: if (flds[i][1] == c && ++fnd >= seq) {
159: /* for titles use first word otherwise last */
160: if (c == 'T' || c == 'J') {
161: p = flds[i]+3;
162: if (prefix("A ", p))
163: p += 2;
164: if (prefix("An ", p))
165: p += 3;
166: if (prefix("The ", p))
167: p += 4;
168: mycpy2(out, p, 20);
169: return(out);
170: }
171: /* if its not 'L' then use just the last word */
172: s = p = flds[i]+2;
173: if (c != 'L') {
174: for(; *p; p++);
175: while (p > s && *p != ' ')
176: p--;
177: }
178: /* special wart for authors */
179: if (c == 'A' && (p[-1] == ',' || p[1] =='(')) {
180: p--;
181: while (p > s && *p != ' ')
182: p--;
183: mycpy(out, p+1);
184: }
185: else
186: strcpy(out, p+1);
187: if (c == 'A' && prepend)
188: initadd(out, flds[i]+2, p);
189: return(out);
190: }
191: return(0);
192: }
193:
194: putkey(nf, flds, nref, keystr)
195: char *flds[], *keystr;
196: {
197: char t1[50], *sf;
198: int ctype, i, count;
199:
200: fprintf(fo, ".\\\"");
201: if (nf <= 0)
202: fprintf(fo, "%s%c%c", labtab[nref], labc[nref], sep);
203: else {
204: while (ctype = *keystr++) {
205: count = atoi(keystr);
206: if (*keystr=='+')
207: count=999;
208: if (count <= 0)
209: count = 1;
210: for(i = 1; i <= count; i++) {
211: sf = fpar(nf, flds, t1, ctype, i, 1);
212: if (sf == 0)
213: break;
214: sf = artskp(sf);
215: fprintf(fo, "%s%c", sf, '-');
216: }
217: }
218: fprintf(fo, "%c%d%c%c", FLAG, nref, FLAG, sep);
219: }
220: }
221:
222:
223: tokeytab (t, nref)
224: char *t;
225: {
226: strcpy(labtab[nref]=lbp, t);
227: while (*lbp++)
228: ;
229: }
230:
231: keylet(t, nref)
232: char *t;
233: {
234: int i;
235: int x = -1;
236:
237: for(i = 1; i < nref; i++) {
238: if (strcmp(labtab[i], t) == 0)
239: x = labc[i];
240: }
241: tokeytab (t, nref);
242: if (lbp-bflab > NFLAB)
243: err("bflab overflow (%d)", NFLAB);
244: if (nref > NLABC)
245: err("nref in labc overflow (%d)", NLABC);
246: #if EBUG
247: fprintf(stderr, "lbp up to %d of 2000\n", lbp-bflab);
248: #endif
249: return(labc[nref] = x+1);
250: }
251:
252: mycpy(s, t)
253: char *s, *t;
254: {
255: while (*t && *t != ',' && *t != ' ')
256: *s++ = *t++;
257: *s = 0;
258: }
259:
260: mycpy2(s, t, n)
261: char *s, *t;
262: {
263: int c;
264:
265: while (n-- && (c= *t++) > 0) {
266: if (c == ' ')
267: c = '-';
268: *s++ = c;
269: }
270: *s = 0;
271: }
272:
273: initadd(to, from, stop)
274: char *to, *from, *stop;
275: {
276: int c, nalph = 1;
277:
278: while (*to)
279: to++;
280: while (from < stop) {
281: c = *from++;
282: if (!isalpha(c)) {
283: if (nalph)
284: *to++ = '.';
285: nalph = 0;
286: continue;
287: }
288: if (nalph++ == 0)
289: *to++ = c;
290: }
291: *to = 0;
292: }
293:
294: static char *articles[] = {
295: "the ", "an ", "a ", 0
296: };
297:
298: char *
299: artskp(s) /* skips over initial "a ", "an ", "the " in s */
300: char *s;
301: {
302:
303: char **p, *r1, *r2;
304:
305: for (p = articles; *p; p++) {
306: r2 = s;
307: for (r1 = *p; ((*r1 ^ *r2) & ~040 ) == 0; r1++)
308: r2++;
309: if (*r1 == 0 && *r2 != 0)
310: return(r2);
311: }
312: return(s);
313: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.