Rev 7676 | Rev 8123 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 7676 | Rev 8100 | ||
---|---|---|---|
Line 27... | Line 27... | ||
27 | char sepchar=':', grpchar=0; |
27 | char sepchar=':', grpchar=0; |
28 | 28 | ||
29 | /***************** Nothing should need change hereafter *****************/ |
29 | /***************** Nothing should need change hereafter *****************/ |
30 | 30 | ||
31 | #include "../wims.h" |
31 | #include "../wims.h" |
32 | #include "../Lib/ |
32 | #include "../Lib/libwims.h" |
- | 33 | ||
33 | 34 | ||
34 | char inpbuf[MAX_LINELEN+1], outbuf[2*MAX_LINELEN+2]; |
35 | char inpbuf[MAX_LINELEN+1], outbuf[2*MAX_LINELEN+2]; |
35 | char *dicbuf; |
36 | char *dicbuf; |
36 | char dicname[1024], suffixname[1024]; |
37 | char dicname[1024], suffixname[1024]; |
37 | 38 | ||
38 | struct entry { |
39 | struct entry { |
39 | char *original; |
40 | char *original; |
40 | char *replace; |
41 | char *replace; |
41 | } entry[entrylim]; |
42 | } entry[entrylim]; |
42 | int entrycount; |
43 | int entrycount; |
43 | 44 | ||
44 | int nocase=0, hassuffix=0, leaveline=0; |
45 | int nocase=0, hassuffix=0, leaveline=0; |
45 | int entrycount, ocount; |
46 | int entrycount, ocount; |
46 | 47 | ||
- | 48 | /* |
|
47 | void *xmalloc(size_t n) |
49 | void *xmalloc(size_t n) |
48 | { |
50 | { |
49 | void *p; |
51 | void *p; |
50 | p=malloc(n); |
52 | p=malloc(n); |
51 | if(p==NULL) exit(1); |
53 | if(p==NULL) exit(1); |
52 |
|
54 | return p; |
53 |
|
55 | } |
54 | 56 | */ |
|
55 | /* Points to the end of the word */ |
57 | /* Points to the end of the word */ |
56 |
|
58 | /*char *find_word_end(char *p) |
57 | { |
59 | { |
58 | int i; |
60 | int i; |
59 | for(i=0;!isspace(*p) && *p!=0 && i<MAX_LINELEN; p++,i++); |
61 | for(i=0;!isspace(*p) && *p!=0 && i<MAX_LINELEN; p++,i++); |
60 | return p; |
62 | return p; |
61 | } |
63 | } |
62 | 64 | */ |
|
63 | /* Strips leading spaces */ |
65 | /* Strips leading spaces */ |
64 |
|
66 | /*char *find_word_start(char *p) |
65 | { |
67 | { |
66 | int i; |
68 | int i; |
67 | for(i=0; isspace(*p) && i<MAX_LINELEN; p++,i++); |
69 | for(i=0; isspace(*p) && i<MAX_LINELEN; p++,i++); |
68 | return p; |
70 | return p; |
69 | } |
71 | } |
70 | 72 | */ |
|
71 | /* strip trailing spaces; return string end. */ |
73 | /* strip trailing spaces; return string end. */ |
72 | char * |
74 | char *strip_trailing_spaces2(char *p) |
73 | { |
75 | { |
74 | char *pp; |
76 | char *pp; |
75 | if(*p==0) return p; |
77 | if(*p==0) return p; |
76 | for(pp=p+strlen(p)-1; pp>=p && isspace(*pp); *(pp--)=0); |
78 | for(pp=p+strlen(p)-1; pp>=p && isspace(*pp); *(pp--)=0); |
77 | return pp; |
79 | return pp; |
Line 88... | Line 90... | ||
88 | void sortdic(void) |
90 | void sortdic(void) |
89 | { |
91 | { |
90 | qsort(entry,entrycount,sizeof(entry[0]),compare); |
92 | qsort(entry,entrycount,sizeof(entry[0]),compare); |
91 | } |
93 | } |
92 | 94 | ||
93 | /* modify a string. Bufferlen must be |
95 | /* modify a string. Bufferlen must be at least MAX_LINELEN */ |
94 | void |
96 | void string_modify3(char *start, char *bad_beg, char *bad_end, char *good,...) |
95 | { |
97 | { |
96 | char buf[MAX_LINELEN+1]; |
98 | char buf[MAX_LINELEN+1]; |
97 | va_list vp; |
99 | va_list vp; |
98 | 100 | ||
99 | va_start(vp,good); |
101 | va_start(vp,good); |
Line 103... | Line 105... | ||
103 | strcat(buf,bad_end); |
105 | strcat(buf,bad_end); |
104 | ovlstrcpy(bad_beg,buf); |
106 | ovlstrcpy(bad_beg,buf); |
105 | } |
107 | } |
106 | 108 | ||
107 | /* change all spaces into ' ', and collapse multiple occurences */ |
109 | /* change all spaces into ' ', and collapse multiple occurences */ |
108 | void |
110 | void singlespace2(char *p) |
109 | { |
111 | { |
110 | char *pp, *p2; |
112 | char *pp, *p2; |
111 | for(pp=p;*pp;pp++) { |
113 | for(pp=p;*pp;pp++) { |
112 | if(!isspace(*pp)) continue; |
114 | if(!isspace(*pp)) continue; |
113 | if(leaveline) { |
115 | if(leaveline) { |
Line 149... | Line 151... | ||
149 | else return; |
151 | else return; |
150 | for(i=0,p1=dicbuf;p1!=NULL && *p1!=0 && i<entrylim;p1=p2) { |
152 | for(i=0,p1=dicbuf;p1!=NULL && *p1!=0 && i<entrylim;p1=p2) { |
151 | p2=strchr(p1+1,'\n'); if(p2>p1) *p2++=0; |
153 | p2=strchr(p1+1,'\n'); if(p2>p1) *p2++=0; |
152 | pp=strchr(p1,sepchar); if(pp==NULL) continue; |
154 | pp=strchr(p1,sepchar); if(pp==NULL) continue; |
153 | *pp++=0; |
155 | *pp++=0; |
154 |
|
156 | strip_trailing_spaces2(p1); strip_trailing_spaces2(pp); |
155 |
|
157 | singlespace2(p1); |
156 | p1=find_word_start(p1); pp=find_word_start(pp); |
158 | p1=find_word_start(p1); pp=find_word_start(pp); |
157 | if(*p1==0) continue; |
159 | if(*p1==0) continue; |
158 | entry[i].original=p1; entry[i].replace=pp; i++; |
160 | entry[i].original=p1; entry[i].replace=pp; i++; |
159 | } |
161 | } |
160 | entrycount=i; |
162 | entrycount=i; |