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