|
|
1.1 root 1: # include "stdio.h"
2: # include "ctype.h"
3: # include "assert.h"
4: main(argc,argv)
5: char *argv[];
6: {
7: char line[100], *s, *p, *r;
8: int ck;
9: assert(argc>1);
10: rdict(argv[1]);
11: while (gets(line))
12: {
13: s=line;
14: while (*s)
15: {
16: while (*s && !isalpha(*s))
17: putc(*s++, stdout);
18: p=s;
19: while (isalpha(*s))
20: s++;
21: ck = *s;
22: *s = 0;
23: r = lkup(p);
24: printf("%s", r ? r: p);
25: if (ck)
26: {
27: printf("%c", ck);
28: s++;
29: }
30: }
31: printf("\n");
32: }
33: }
34: static char * wold[500], * wnew[500];
35: static char wspace[5000], *wp=wspace;
36: int k=0;
37: rdict (fname)
38: char *fname;
39: {
40: FILE *f;
41: char line[100],*s;
42: f = fopen(fname, "r");
43: assert(f!=NULL);
44: while (fgets(line, 100, f))
45: {
46: trimnl(line);
47: s = index(line, ' ');
48: *s++ = 0;
49: wold[k] = wp;
50: strcpy(wp, line);
51: wp += strlen(line)+1;
52: wnew[k]= wp;
53: strcpy(wp, s);
54: wp += strlen(s)+1;
55: k++;
56: assert(k<=500);
57: assert(wp<=wspace+5000);
58: }
59: }
60: trimnl(s)
61: char *s;
62: {
63: while (*s) s++;
64: if (*--s=='\n') *s=0;
65: }
66: lkup(s)
67: char *s;
68: {
69: int i;
70: for (i=0; i<k; i++)
71: if (strcmp(wold[i], s) ==0)
72: return(wnew[i]);
73: return(NULL);
74: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.