Subversion Repositories SvarDOS

Rev

Rev 2007 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2007 Rev 2083
Line 164... Line 164...
164
      exitcode = -3;
164
      exitcode = -3;
165
      goto FCLOSE_AND_EXIT;
165
      goto FCLOSE_AND_EXIT;
166
    }
166
    }
167
 
167
 
168
    /* is it the lang I am looking for? */
168
    /* is it the lang I am looking for? */
169
    if (buff16[0] == langid) break;
169
    if ((buff16[0] & 0x7FFF) == langid) break; /* compare without highest bit - it is a flag for compression */
170
 
170
 
171
    /* skip to next lang (in two steps to avoid a potential uint16 overflow) */
171
    /* skip to next lang (in two steps to avoid a potential uint16 overflow) */
172
    FSEEK(fd, svarlang_string_count * 4);
172
    FSEEK(fd, svarlang_string_count * 4);
173
    FSEEK(fd, buff16[1]);
173
    FSEEK(fd, buff16[1]);
174
  }
174
  }
175
 
175
 
176
  /* load dictionary & strings, but only if I have enough memory space */
-
 
177
  if ((buff16[1] >= svarlang_memsz)
176
  /* load the index (dict) */
178
   || (FREAD(fd, svarlang_dict, svarlang_string_count * 4) != svarlang_string_count * 4)
177
  if (FREAD(fd, svarlang_dict, svarlang_string_count * 4) != svarlang_string_count * 4) {
179
   || (FREAD(fd, svarlang_mem, buff16[1]) != buff16[1])) {
-
 
180
    exitcode = -4;
178
    exitcode = -4;
-
 
179
    goto FCLOSE_AND_EXIT;
-
 
180
  }
-
 
181
 
-
 
182
  /* is the lang block compressed? then uncompress it */
-
 
183
  if (buff16[0] & 0x8000) {
-
 
184
    unsigned short compressedsize = buff16[1] / 2;
-
 
185
    unsigned short i;
-
 
186
    char *dst = svarlang_mem;
-
 
187
    for (i = 0; i < compressedsize; i++) {
-
 
188
      /* read a word token */
-
 
189
      if (FREAD(fd, buff16, 2) != 2) {
-
 
190
        exitcode = -5;
-
 
191
        goto FCLOSE_AND_EXIT;
-
 
192
      }
-
 
193
 
-
 
194
      /* token format is LLLL OOOO OOOO OOOO, where:
-
 
195
       * OOOO OOOO OOOO is the back reference offset (number of bytes to rewind)
-
 
196
       * LLLL is the number of bytes that have to be copied from the offset
-
 
197
       * if the token is > 256 then it represents a literal (single) byte
-
 
198
       */
-
 
199
 
-
 
200
      /* literal byte? */
-
 
201
      if ((buff16[0] & 0xFF00) == 0) {
-
 
202
        *dst = buff16[0];
-
 
203
        dst++;
-
 
204
      } else { /* backreference */
-
 
205
        char *src = dst - (buff16[0] & 0x0FFF);
-
 
206
        buff16[0] >>= 12;
-
 
207
        while (buff16[0]) {
-
 
208
          *dst = *src;
-
 
209
          dst++;
-
 
210
          src++;
-
 
211
          buff16[0]--;
-
 
212
        }
-
 
213
      }
-
 
214
    }
-
 
215
    goto FCLOSE_AND_EXIT;
-
 
216
  }
-
 
217
 
-
 
218
  /* lang block not compressed - load as is */
-
 
219
  if (FREAD(fd, svarlang_mem, buff16[1]) != buff16[1]) {
-
 
220
    exitcode = -6;
181
  }
221
  }
182
 
222
 
183
  FCLOSE_AND_EXIT:
223
  FCLOSE_AND_EXIT:
184
 
224
 
185
  FCLOSE(fd);
225
  FCLOSE(fd);