Subversion Repositories wimsdev

Rev

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
    char *pp, *p2;
88
  char *pp, *p2;
89
    for(pp=p;*pp;pp++) {
89
  for(pp=p;*pp;pp++) {
90
      if(!isspace(*pp)) continue;
90
    if(!isspace(*pp)) continue;
91
      if(leaveline) {
91
    if(leaveline) {
92
          if(*pp==13) ovlstrcpy(pp,pp+1);
92
        if(*pp==13) ovlstrcpy(pp,pp+1);
93
          if(*pp=='\n') {
93
        if(*pp=='\n') {
94
            pp++;
94
          pp++;
95
            gopt: for(p2=pp; isspace(*p2) && *p2!='\n'; p2++);
95
          gopt: for(p2=pp; isspace(*p2) && *p2!='\n'; p2++);
96
            if(p2>pp) ovlstrcpy(pp,p2);
96
          if(p2>pp) ovlstrcpy(pp,p2);
97
            pp--;
97
          pp--;
98
          }
98
        }
99
          else {
99
        else {
100
            pp++; if(!isspace(*pp) || *pp=='\n') continue;
100
          pp++; if(!isspace(*pp) || *pp=='\n') continue;
101
            goto gopt;
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
    int i,l;
116
  int i,l;
117
    FILE *dicf;
117
  FILE *dicf;
118
    char *p1, *p2, *pp;
118
  char *p1, *p2, *pp;
119
    long int flen;
119
  long int flen;
120
 
120
 
121
    entrycount=0;
121
  entrycount=0;
122
    dicf=fopen(fname,"r"); if(dicf==NULL) return;
122
  dicf=fopen(fname,"r"); if(dicf==NULL) return;
123
    fseek(dicf,0,SEEK_END);flen=ftell(dicf); fseek(dicf,0,SEEK_SET);
123
  fseek(dicf,0,SEEK_END);flen=ftell(dicf); fseek(dicf,0,SEEK_SET);
124
    if(flen>diclim) return;
124
  if(flen>diclim) return;
125
    dicbuf=xmalloc(flen+16);flen=fread(dicbuf,1,flen,dicf);
125
  dicbuf=xmalloc(flen+16);flen=fread(dicbuf,1,flen,dicf);
126
    fclose(dicf);
126
  fclose(dicf);
127
    if(flen>0 && flen<diclim) dicbuf[flen]=0;
127
  if(flen>0 && flen<diclim) dicbuf[flen]=0;
128
    else return;
128
  else return;
129
    for(i=0,p1=dicbuf;p1!=NULL && *p1!=0 && i<entrylim;p1=p2) {
129
  for(i=0,p1=dicbuf;p1!=NULL && *p1!=0 && i<entrylim;p1=p2) {
130
      p2=strchr(p1+1,'\n'); if(p2>p1) *p2++=0;
130
    p2=strchr(p1+1,'\n'); if(p2>p1) *p2++=0;
131
      pp=strchr(p1,':'); if(pp==NULL) continue;
131
    pp=strchr(p1,':'); if(pp==NULL) continue;
132
      *pp++=0;
132
    *pp++=0;
133
      strip_trailing_spaces2(p1); strip_trailing_spaces2(pp);
133
    strip_trailing_spaces2(p1); strip_trailing_spaces2(pp);
134
      singlespace2(p1);
134
    singlespace2(p1);
135
      p1=find_word_start(p1); pp=find_word_start(pp);
135
    p1=find_word_start(p1); pp=find_word_start(pp);
136
      if(*p1==0) continue;
136
    if(*p1==0) continue;
137
      if(has_digits==0) {
137
    if(has_digits==0) {
138
          char *p;
138
        char *p;
139
          for(p=p1;*p!=0 && p<pp && !isdigit(*p);p++);
139
        for(p=p1;*p!=0 && p<pp && !isdigit(*p);p++);
140
          if(isdigit(*p)) has_digits=1;
140
        if(isdigit(*p)) has_digits=1;
141
      }
141
    }
142
      entry[i].original=(unsigned char*)p1;
142
    entry[i].original=(unsigned char*)p1;
143
      entry[i].replace=(unsigned char*)pp;
143
    entry[i].replace=(unsigned char*)pp;
144
      entry[i].olen=l=strlen(p1); entry[i].earlier=-1;
144
    entry[i].olen=l=strlen(p1); entry[i].earlier=-1;
145
      if(i>0) {
145
    if(i>0) {
146
          int l1,l2;
146
        int l1,l2;
147
          l1=entry[i-1].earlier; if(l1>=0) l2=entry[l1].olen;
147
        l1=entry[i-1].earlier; if(l1>=0) l2=entry[l1].olen;
148
          else {l2=entry[i-1].olen;l1=i-1;}
148
        else {l2=entry[i-1].olen;l1=i-1;}
149
          if(l>l2 && isspace(p1[l2])
149
        if(l>l2 && isspace(p1[l2])
150
             && strncmp((char*)entry[l1].original,p1,l2)==0)
150
           && strncmp((char*)entry[l1].original,p1,l2)==0)
151
            entry[i].earlier=entry[i-1].earlier=l1;
151
          entry[i].earlier=entry[i-1].earlier=l1;
152
      }
-
 
153
      i++;
-
 
154
    }
152
    }
-
 
153
    i++;
-
 
154
  }
155
    entrycount=i;
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
{