Commit | Line | Data |
---|---|---|
a7aefbdf BT |
1 | #ifndef lint |
2 | static char *sccsid = "@(#)kaiser.c 4.1 (Berkeley) %G%"; | |
3 | #endif | |
4 | ||
5 | #include <stdio.h> | |
6 | #include <ctype.h> | |
7 | ||
8 | char *months[] { | |
9 | "Jan", "Feb", "Mar", "Apr", "May", "Jun", | |
10 | "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", 0}; | |
11 | ||
12 | main() | |
13 | { | |
14 | int state 1000, i, book, volume, corp, report; | |
15 | int na; | |
16 | char *v[20], **vv, **rr; | |
17 | char ubuff[1000], *up; | |
18 | char line[100]; | |
19 | char *p, *s, *r, *q; | |
20 | while (gets(line)) | |
21 | { | |
22 | if (line[1]>'9' || line[1]<'0') continue; | |
23 | switch(line[0]) | |
24 | { | |
25 | case 'T': | |
26 | if (state > 'T') | |
27 | { | |
28 | book=0; | |
29 | report=0; | |
30 | printf("\n%%T "); | |
31 | } | |
32 | printf("%s\n", line+18); | |
33 | state='T'; | |
34 | na = getargs(line+18, v); | |
35 | for(i=0;i<na;i++) | |
36 | if (strcmp(v[i], "(Book)")==0) | |
37 | book=1; | |
38 | continue; | |
39 | case 'A': | |
40 | state = 'A'; | |
41 | na=getargs(line+18, vv=v); | |
42 | if (na<=0) continue; | |
43 | while (na>0) | |
44 | { | |
45 | printf("%%A "); | |
46 | corp=0; | |
47 | for(p=vv[1]; *p; p++) | |
48 | if (islower(*p)) | |
49 | corp=1; | |
50 | if (corp==0) | |
51 | { | |
52 | for(p=vv[1]; *p; p++) | |
53 | printf("%c. ", *p); | |
54 | if (na>2 &&strcmp(vv[2], "+")) | |
55 | { | |
56 | printf("%s", vv[0]); | |
57 | if (strcmp(vv[2], "Jr.")==0) | |
58 | printf(","); | |
59 | printf(" %s\n",vv[2]); | |
60 | vv++; | |
61 | na--; | |
62 | } | |
63 | else | |
64 | printf("%s\n", vv[0]); | |
65 | } | |
66 | else | |
67 | printf("%s %s\n",vv[0],vv[1]); | |
68 | vv+=2; | |
69 | na-=2; | |
70 | if (strcmp(vv[0], "+")==0) | |
71 | { | |
72 | vv++; | |
73 | na--; | |
74 | } | |
75 | } | |
76 | continue; | |
77 | case 'U': | |
78 | if (state!='U') | |
79 | ubuff[0]=0; | |
80 | else | |
81 | strcat(ubuff, " "); | |
82 | state = 'U'; | |
83 | strcat(ubuff, line+18); | |
84 | if (line[2]=='.') | |
85 | { /* end of item */ | |
86 | p=ubuff; /*start*/ | |
87 | volume=0; | |
88 | for(s=ubuff; *s; s++) | |
89 | if (s[-1]==' ' && prefix("Vol", s)) | |
90 | { | |
91 | for(q=s-1; q>ubuff; q--) | |
92 | { | |
93 | if (*q==' ' || *q==',') *q=0; | |
94 | else break; | |
95 | } | |
96 | volume=1; | |
97 | break; | |
98 | } | |
99 | if (*s==0) | |
100 | for(s=ubuff; *s && (*s!=',' || sprefix("Inc", s+1)); s++) | |
101 | ; | |
102 | else | |
103 | s++; | |
104 | if (*s==',')*s++=0; | |
105 | if (book) | |
106 | printf("%%I %s\n",ubuff); | |
107 | else if (volume) | |
108 | printf("%%J %s\n", ubuff); | |
109 | else if (substr(ubuff, "Report")!=0) | |
110 | { | |
111 | report=1; | |
112 | printf("%%R %s\n", ubuff); | |
113 | } | |
114 | else | |
115 | printf("%%J %s\n", ubuff); | |
116 | if (volume) | |
117 | { | |
118 | s += 3; /* Vol */ | |
119 | if (*s=='.') s++; | |
120 | while (*s==' ')s++; | |
121 | printf("%%V "); | |
122 | while (*s && *s != ' ' && *s!=',' && *s!=';' && *s!= ':') | |
123 | putchar(*s++); | |
124 | putchar('\n'); | |
125 | if (*s==':') | |
126 | { | |
127 | printf("%%N "); | |
128 | while (*s==' ')s++; | |
129 | while (isdigit(*s)) | |
130 | putchar(*s++); | |
131 | putchar('\n'); | |
132 | } | |
133 | *s++=0; | |
134 | while (*s==' ')*s++=0; | |
135 | if (s[0]=='N' && s[1]=='o' && (s[2]==' '||s[2]=='.')) | |
136 | { | |
137 | s+=2; | |
138 | while (*s==' '||*s=='.')s++; | |
139 | printf("%%N "); | |
140 | while (isdigit(*s)||*s=='-') | |
141 | putchar(*s++); | |
142 | putchar('\n'); | |
143 | } | |
144 | if (*s==',') *s++=0; | |
145 | } | |
146 | for(rr=months; *rr; rr++) | |
147 | { | |
148 | q= substr(s, *rr); | |
149 | if (q) | |
150 | { | |
151 | for(r=q; *r; r++); | |
152 | r--; | |
153 | if (*r=='.')*r=0; | |
154 | printf("%%D %s\n",q); | |
155 | *(q-1)=0; | |
156 | break; | |
157 | } | |
158 | } | |
159 | if (*rr==0) | |
160 | { | |
161 | for(q=s; *q; q++) | |
162 | { | |
163 | if (q[0]=='1' && q[1]=='9' && (q[4]==0 || (q[4]=='.' && q[5]==0))) | |
164 | { | |
165 | if (q[4]=='.') q[4]=0; | |
166 | printf("%%D %s\n",q); | |
167 | rr=months; | |
168 | q[-1]=0; | |
169 | if (q==s) q[0]=0; | |
170 | break; | |
171 | } | |
172 | } | |
173 | } | |
174 | if (*rr==0) /* no date */ | |
175 | printf("%%D 19xx\n"); | |
176 | /* if book bite off next field for city, if report for issuer */ | |
177 | if (book) | |
178 | { | |
179 | for(q=s; *q && *q != ','; q++) | |
180 | ; | |
181 | if (*q==',') | |
182 | { | |
183 | r=q; | |
184 | r++; | |
185 | while (*r==' ')r++; | |
186 | if (isupper(r[0]) && isupper(r[1])) | |
187 | { | |
188 | r+=2; | |
189 | *r++=0; | |
190 | while (*r==' ')r++; | |
191 | } | |
192 | else | |
193 | *q=0; | |
194 | printf("%%C %s\n", s); | |
195 | s=r; | |
196 | } | |
197 | } | |
198 | for(q=s; *q; q++) | |
199 | { | |
200 | if (q[0]==' ' && q[1]=='p' && (q[2]=='p'||q[2]==0)) | |
201 | { | |
202 | for(r=q; r>s; r--) | |
203 | { | |
204 | if (*r==' ' || *r==',') | |
205 | *r=0; | |
206 | } | |
207 | *q=0; | |
208 | q+=2; | |
209 | if (q[0]=='p')q++; | |
210 | while (*q==' '||*q=='.')q++; | |
211 | r=q; | |
212 | while (isdigit(*q)||*q=='.'||*q=='-'||isalpha(*q))q++; | |
213 | *q++=0; | |
214 | while (*q==' ')q++; | |
215 | printf("%%P %s\n",r); | |
216 | break; | |
217 | } | |
218 | } | |
219 | s=ispp(s); | |
220 | while (*s==' ')s++; | |
221 | while (*q==' ')q++; | |
222 | if (*s||*q) | |
223 | printf("%%O %s %s\n", *s?s:"", *q?q:""); | |
224 | } | |
225 | continue; | |
226 | } | |
227 | } | |
228 | } | |
229 | ||
230 | getargs(s, arps) | |
231 | char *s, *arps[]; | |
232 | { | |
233 | int i; | |
234 | i = 0; | |
235 | while (1) | |
236 | { | |
237 | arps[i++]=s; | |
238 | while (*s != 0 && *s!=' '&& *s != '\t')s++; | |
239 | if (*s==0) break; | |
240 | *s++ =0; | |
241 | while (*s==' ' || *s=='\t')s++; | |
242 | if (*s==0)break; | |
243 | } | |
244 | return(i); | |
245 | } | |
246 | ||
247 | prefix(small, big) | |
248 | char *small, *big; | |
249 | { | |
250 | int c; | |
251 | while ((c= *small++) == *big++) | |
252 | if (c==0) return(1); | |
253 | return(c==0); | |
254 | } | |
255 | ||
256 | substr(big, small) | |
257 | char *small, *big; | |
258 | { | |
259 | while (*big) | |
260 | if (prefix(small, big)) | |
261 | return(big); | |
262 | else | |
263 | big++; | |
264 | return(0); | |
265 | } | |
266 | ||
267 | sprefix(small, big) | |
268 | char *small, *big; | |
269 | { | |
270 | while (*big==' ') big++; | |
271 | return(prefix(small,big)); | |
272 | } | |
273 | ||
274 | ispp(s) | |
275 | char *s; | |
276 | { | |
277 | static char buff[50]; | |
278 | char *p, *t; | |
279 | p=s; | |
280 | while (*p==' ') p++; | |
281 | if (!isdigit(*p)) return(s); | |
282 | t=p; | |
283 | while (isdigit(*p))p++; | |
284 | if (p[0]!='p' || p[1]!='p') return(s); | |
285 | *p=0; | |
286 | sprintf(buff, "%spp.", t); | |
287 | return(buff); | |
288 | } |