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