Subversion Repositories SvarDOS

Rev

Rev 969 | Rev 1064 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 969 Rev 1061
Line 122... Line 122...
122
  }
122
  }
123
  return(i);
123
  return(i);
124
}
124
}
125
 
125
 
126
 
126
 
127
/* opens a CATS-style file and compiles it into a ressources lang block */
127
/* opens a CATS-style file and compiles it into a ressources lang block
-
 
128
 * returns 0 on error, or the size of the generated data block otherwise */
128
static unsigned short gen_langstrings(unsigned char *buff, const char *langid, struct bitmap *b, const struct bitmap *refb, const unsigned char *refblock) {
129
static unsigned short gen_langstrings(unsigned char *buff, const char *langid, struct bitmap *b, const struct bitmap *refb, const unsigned char *refblock) {
129
  unsigned short len = 0, linelen;
130
  unsigned short len = 0, linelen;
130
  FILE *fd;
131
  FILE *fd;
131
  char fname[] = "XX.TXT";
132
  char fname[] = "XX.TXT";
132
  static char linebuf[8192];
133
  static char linebuf[8192];
Line 220... Line 221...
220
 
221
 
221
int main(int argc, char **argv) {
222
int main(int argc, char **argv) {
222
  FILE *fd;
223
  FILE *fd;
223
  int ecode = 0;
224
  int ecode = 0;
224
  char *buff, *refblock;
225
  char *buff, *refblock;
-
 
226
  unsigned short refblocksz = 0;
225
  static struct bitmap bufbitmap;
227
  static struct bitmap bufbitmap;
226
  static struct bitmap refbitmap;
228
  static struct bitmap refbitmap;
227
  unsigned short i;
229
  unsigned short i;
-
 
230
  unsigned short biggest_langsz = 0;
228
 
231
 
229
  if (argc < 2) {
232
  if (argc < 2) {
230
    puts("usage: tlumacz en fr pl etc");
233
    puts("usage: tlumacz en fr pl etc");
231
    return(1);
234
    return(1);
232
  }
235
  }
Line 269... Line 272...
269
      printf("ERROR COMPUTING LANG '%s'\r\n", id);
272
      printf("ERROR COMPUTING LANG '%s'\r\n", id);
270
      ecode = 1;
273
      ecode = 1;
271
      break;
274
      break;
272
    } else {
275
    } else {
273
      printf("computed %s lang block of %u bytes\r\n", id, sz);
276
      printf("computed %s lang block of %u bytes\r\n", id, sz);
-
 
277
      if (sz > biggest_langsz) biggest_langsz = sz;
274
    }
278
    }
275
    /* write lang ID to file, followed by block size and then the actual block */
279
    /* write lang ID to file, followed by block size and then the actual block */
276
    if ((fwrite(id, 1, 2, fd) != 2) ||
280
    if ((fwrite(id, 1, 2, fd) != 2) ||
277
        (fwrite(&sz, 1, 2, fd) != 2) ||
281
        (fwrite(&sz, 1, 2, fd) != 2) ||
278
        (fwrite(buff, 1, sz, fd) != sz)) {
282
        (fwrite(buff, 1, sz, fd) != sz)) {
279
      printf("ERROR WRITING TO OUTPUT FILE\r\n");
283
      printf("ERROR WRITING TO OUTPUT FILE\r\n");
280
      ecode = 1;
284
      ecode = 1;
281
      break;
285
      break;
282
    }
286
    }
283
    /* compute the default block for reference language */
287
    /* remember reference data for other languages */
284
    if (i == 1) {
288
    if (i == 1) {
285
      unsigned short x;
-
 
286
      FILE *fd2;
-
 
287
      fd2 = fopen("DEFLANG.C", "wb");
-
 
288
      if (fd2 == NULL) {
-
 
289
        puts("ERROR: FAILED TO OPEN OR CREATE DEFLANG.C");
-
 
290
        break;
-
 
291
      }
-
 
292
      fprintf(fd2, "/* THIS FILE HAS BEEN AUTOGENERATE BY TLUMACZ (PART OF THE SVARLANG LIBRARY) */\r\n");
-
 
293
      fprintf(fd2, "const unsigned short svarlang_memsz = %uu;\r\n", sz * 2);
-
 
294
      fprintf(fd2, "char svarlang_mem[%u] = {\r\n", sz * 2);
-
 
295
      for (x = 0; x < sz; x++) {
-
 
296
        fprintf(fd2, "%u", buff[x]);
-
 
297
        if (x + 1 < sz) fprintf(fd2, ",");
-
 
298
        if ((x & 15) == 15) fprintf(fd2, "\r\n");
-
 
299
      }
-
 
300
      fprintf(fd2, "};\r\n");
-
 
301
      fclose(fd2);
289
      refblocksz = sz;
302
      /* remember reference data for other languages */
-
 
303
      memcpy(refblock, buff, MEMBLOCKSZ);
290
      memcpy(refblock, buff, MEMBLOCKSZ);
304
      memcpy(&refbitmap, &bufbitmap, sizeof(struct bitmap));
291
      memcpy(&refbitmap, &bufbitmap, sizeof(struct bitmap));
305
    }
292
    }
306
  }
293
  }
307
 
294
 
308
  fclose(fd);
295
  fclose(fd);
309
 
296
 
-
 
297
  /* compute the deflang.c file containing a dump of the reference block */
-
 
298
  fd = fopen("DEFLANG.C", "wb");
-
 
299
  if (fd == NULL) {
-
 
300
    puts("ERROR: FAILED TO OPEN OR CREATE DEFLANG.C");
-
 
301
    ecode = 1;
-
 
302
  } else {
-
 
303
    unsigned short allocsz = biggest_langsz + (biggest_langsz / 20);
-
 
304
    printf("biggest lang block is %u bytes -> allocating a %u bytes buffer\n", biggest_langsz, allocsz);
-
 
305
    fprintf(fd, "/* THIS FILE HAS BEEN GENERATED BY TLUMACZ (PART OF THE SVARLANG LIBRARY) */\r\n");
-
 
306
    fprintf(fd, "const unsigned short svarlang_memsz = %uu;\r\n", allocsz);
-
 
307
    fprintf(fd, "char svarlang_mem[%u] = {\r\n", allocsz);
-
 
308
    for (i = 0; i < refblocksz; i++) {
-
 
309
      fprintf(fd, "%u", buff[i]);
-
 
310
      if (i + 1 < refblocksz) fprintf(fd, ",");
-
 
311
      if ((i & 15) == 15) fprintf(fd, "\r\n");
-
 
312
    }
-
 
313
    fprintf(fd, "};\r\n");
-
 
314
    fclose(fd);
-
 
315
  }
-
 
316
 
310
  return(ecode);
317
  return(ecode);
311
}
318
}