Rev 12248 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 12248 | Rev 13634 | ||
---|---|---|---|
Line 83... | Line 83... | ||
83 | } |
83 | } |
84 | 84 | ||
85 | /* change all spaces into ' ', and collapse multiple occurences */ |
85 | /* change all spaces into ' ', and collapse multiple occurences */ |
86 | void singlespace2(char *p) |
86 | void singlespace2(char *p) |
87 | { |
87 | { |
88 |
|
88 | char *pp, *p2; |
89 |
|
89 | for(pp=p;*pp;pp++) { |
90 |
|
90 | if(!isspace(*pp)) continue; |
91 |
|
91 | if(leaveline) { |
92 |
|
92 | if(*pp==13) ovlstrcpy(pp,pp+1); |
93 |
|
93 | if(*pp=='\n') { |
94 |
|
94 | pp++; |
95 |
|
95 | gopt: for(p2=pp; isspace(*p2) && *p2!='\n'; p2++); |
96 |
|
96 | if(p2>pp) ovlstrcpy(pp,p2); |
97 |
|
97 | pp--; |
98 |
|
98 | } |
99 |
|
99 | else { |
100 |
|
100 | pp++; if(!isspace(*pp) || *pp=='\n') continue; |
101 |
|
101 | goto gopt; |
102 |
|
102 | } |
103 | } |
- | |
104 | else { |
- | |
105 | if(*pp!=' ') *pp=' '; |
- | |
106 | if(!isspace(*(pp+1))) continue; |
- | |
107 | for(pp++,p2=pp;isspace(*p2);p2++); |
- | |
108 | ovlstrcpy(pp,p2); pp--; |
- | |
109 | } |
- | |
110 | } |
103 | } |
- | 104 | else { |
|
- | 105 | if(*pp!=' ') *pp=' '; |
|
- | 106 | if(!isspace(*(pp+1))) continue; |
|
- | 107 | for(pp++,p2=pp;isspace(*p2);p2++); |
|
- | 108 | ovlstrcpy(pp,p2); pp--; |
|
- | 109 | } |
|
- | 110 | } |
|
111 | } |
111 | } |
112 | 112 | ||
113 | /* Prepare dictionary */ |
113 | /* Prepare dictionary */ |
114 | void prepare_dic(char *fname) |
114 | void prepare_dic(char *fname) |
115 | { |
115 | { |
116 |
|
116 | int i,l; |
117 |
|
117 | FILE *dicf; |
118 |
|
118 | char *p1, *p2, *pp; |
119 |
|
119 | long int flen; |
120 | 120 | ||
121 |
|
121 | entrycount=0; |
122 |
|
122 | dicf=fopen(fname,"r"); if(dicf==NULL) return; |
123 |
|
123 | fseek(dicf,0,SEEK_END);flen=ftell(dicf); fseek(dicf,0,SEEK_SET); |
124 |
|
124 | if(flen>diclim) return; |
125 |
|
125 | dicbuf=xmalloc(flen+16);flen=fread(dicbuf,1,flen,dicf); |
126 |
|
126 | fclose(dicf); |
127 |
|
127 | if(flen>0 && flen<diclim) dicbuf[flen]=0; |
128 |
|
128 | else return; |
129 |
|
129 | for(i=0,p1=dicbuf;p1!=NULL && *p1!=0 && i<entrylim;p1=p2) { |
130 |
|
130 | p2=strchr(p1+1,'\n'); if(p2>p1) *p2++=0; |
131 |
|
131 | pp=strchr(p1,':'); if(pp==NULL) continue; |
132 |
|
132 | *pp++=0; |
133 |
|
133 | strip_trailing_spaces2(p1); strip_trailing_spaces2(pp); |
134 |
|
134 | singlespace2(p1); |
135 |
|
135 | p1=find_word_start(p1); pp=find_word_start(pp); |
136 |
|
136 | if(*p1==0) continue; |
137 |
|
137 | if(has_digits==0) { |
138 |
|
138 | char *p; |
139 |
|
139 | for(p=p1;*p!=0 && p<pp && !isdigit(*p);p++); |
140 |
|
140 | if(isdigit(*p)) has_digits=1; |
141 |
|
141 | } |
142 |
|
142 | entry[i].original=(unsigned char*)p1; |
143 |
|
143 | entry[i].replace=(unsigned char*)pp; |
144 |
|
144 | entry[i].olen=l=strlen(p1); entry[i].earlier=-1; |
145 |
|
145 | if(i>0) { |
146 |
|
146 | int l1,l2; |
147 |
|
147 | l1=entry[i-1].earlier; if(l1>=0) l2=entry[l1].olen; |
148 |
|
148 | else {l2=entry[i-1].olen;l1=i-1;} |
149 |
|
149 | if(l>l2 && isspace(p1[l2]) |
150 |
|
150 | && strncmp((char*)entry[l1].original,p1,l2)==0) |
151 |
|
151 | entry[i].earlier=entry[i-1].earlier=l1; |
152 | } |
- | |
153 | i++; |
- | |
154 | } |
152 | } |
- | 153 | i++; |
|
- | 154 | } |
|
155 |
|
155 | entrycount=i; |
156 | } |
156 | } |
157 | 157 | ||
158 | /* now make the translation. */ |
158 | /* now make the translation. */ |
159 | void translate(char *p) |
159 | void translate(char *p) |
160 | { |
160 | { |