Subversion Repositories SvarDOS

Rev

Rev 2115 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2115 Rev 2116
Line 179... Line 179...
179
    goto FCLOSE_AND_EXIT;
179
    goto FCLOSE_AND_EXIT;
180
  }
180
  }
181
 
181
 
182
  /* is the lang block compressed? then uncompress it */
182
  /* is the lang block compressed? then uncompress it */
183
  if (buff16[0] & 0x8000) {
183
  if (buff16[0] & 0x8000) {
184
    unsigned short compressedsize = buff16[1] / 2;
184
    unsigned short compressedwords = buff16[1] / 2;
185
    unsigned short i;
-
 
186
    char *dst = svarlang_mem;
185
    char *dst = svarlang_mem;
187
    unsigned char rawwords = 0; /* number of uncompressible words */
186
    unsigned char rawwords = 0; /* number of uncompressible words */
188
    unsigned short *mvcompptr;
187
    unsigned short *mvcompptr;
189
 
188
 
190
    /* start by loading the entire block at the end of the svarlang mem */
189
    /* start by loading the entire block at the end of the svarlang mem */
Line 193... Line 192...
193
      exitcode = -5;
192
      exitcode = -5;
194
      goto FCLOSE_AND_EXIT;
193
      goto FCLOSE_AND_EXIT;
195
    }
194
    }
196
 
195
 
197
    /* uncompress now */
196
    /* uncompress now */
198
    for (i = 0; i < compressedsize; i++) {
197
    while (compressedwords != 0) {
-
 
198
      unsigned short token;
199
      /* get next mvcomp token */
199
      /* get next mvcomp token */
200
      buff16[0] = mvcompptr[i];
200
      token = *mvcompptr;
-
 
201
      mvcompptr++;
-
 
202
      compressedwords--;
201
 
203
 
202
      /* token format is LLLL OOOO OOOO OOOO, where:
204
      /* token format is LLLL OOOO OOOO OOOO, where:
203
       * OOOO OOOO OOOO is the back reference offset (number of bytes-1 to rewind)
205
       * OOOO OOOO OOOO is the back reference offset (number of bytes-1 to rewind)
204
       * LLLL is the number of bytes (-1) that have to be copied from the offset.
206
       * LLLL is the number of bytes (-1) that have to be copied from the offset.
205
       *
207
       *
Line 212... Line 214...
212
       */
214
       */
213
 
215
 
214
      /* raw word? */
216
      /* raw word? */
215
      if (rawwords != 0) {
217
      if (rawwords != 0) {
216
        unsigned short *dst16 = (void *)dst;
218
        unsigned short *dst16 = (void *)dst;
217
        *dst16 = buff16[0];
219
        *dst16 = token;
218
        dst += 2;
220
        dst += 2;
219
        rawwords--;
221
        rawwords--;
220
 
222
 
221
      /* literal byte? */
223
      /* literal byte? */
222
      } else if ((buff16[0] & 0xF000) == 0) {
224
      } else if ((token & 0xF000) == 0) {
223
        *dst = buff16[0] & 0xff;
225
        *dst = token; /* no need for an explicit "& 0xff", dst is a char ptr so token is naturally truncated to lowest 8 bits */
224
        dst++;
226
        dst++;
225
        rawwords = buff16[0] >> 8; /* number of RAW words that are about to follow */
227
        rawwords = token >> 8; /* number of RAW words that are about to follow */
226
 
228
 
227
      /* else it's a backreference */
229
      /* else it's a backreference */
228
      } else {
230
      } else {
229
        char *src = dst - (buff16[0] & 0x0FFF) - 1;
231
        char *src = dst - (token & 0x0FFF) - 1;
230
        buff16[0] >>= 12;
232
        token >>= 12;
231
        for (;;) {
233
        for (;;) {
232
          *dst = *src;
234
          *dst = *src;
233
          dst++;
235
          dst++;
234
          src++;
236
          src++;
235
          if (buff16[0] == 0) break;
237
          if (token == 0) break;
236
          buff16[0]--;
238
          token--;
237
        }
239
        }
238
      }
240
      }
239
    }
241
    }
240
    goto FCLOSE_AND_EXIT;
242
    goto FCLOSE_AND_EXIT;
241
  }
243
  }