Subversion Repositories SvarDOS

Rev

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

Rev 1291 Rev 1293
Line 14... Line 14...
14
#include <ctype.h>
14
#include <ctype.h>
15
 
15
 
16
#include "svarlang.h"
16
#include "svarlang.h"
17
 
17
 
18
#define STRINGS_CAP 65000   /* string storage size in characters */
18
#define STRINGS_CAP 65000   /* string storage size in characters */
19
#define DICT_CAP    10000   /* dictionary size in elements */ 
19
#define DICT_CAP    10000   /* dictionary size in elements */
20
 
20
 
21
/* read a single line from fd and fills it into dst, returns line length
21
/* read a single line from fd and fills it into dst, returns line length
22
 * ending CR/LF is trimmed, as well as any trailing spaces */
22
 * ending CR/LF is trimmed, as well as any trailing spaces */
23
static unsigned short readl(char *dst, size_t dstsz, FILE *fd) {
23
static unsigned short readl(char *dst, size_t dstsz, FILE *fd) {
24
  unsigned short l, lastnonspace = 0;
24
  unsigned short l, lastnonspace = 0;
Line 196... Line 196...
196
 
196
 
197
  if (l->strings_cap < svl_strings_bytes(l) + len ||
197
  if (l->strings_cap < svl_strings_bytes(l) + len ||
198
      l->dict_cap < (l->num_strings + 1) * sizeof(dict_entry_t)) {
198
      l->dict_cap < (l->num_strings + 1) * sizeof(dict_entry_t)) {
199
    return 0;
199
    return 0;
200
  }
200
  }
201
  
201
 
202
  /* find dictionary insert position, search backwards in assumption
202
  /* find dictionary insert position, search backwards in assumption
203
     that in translation files, strings are generally ordered ascending */
203
     that in translation files, strings are generally ordered ascending */
204
  for (cursor = l->num_strings; cursor > 0 && l->dict[cursor-1].id > id; cursor--);
204
  for (cursor = l->num_strings; cursor > 0 && l->dict[cursor-1].id > id; cursor--);
205
 
205
 
206
  memmove(&(l->dict[cursor+1]), &(l->dict[cursor]), sizeof(dict_entry_t)*(l->num_strings - cursor));
206
  memmove(&(l->dict[cursor+1]), &(l->dict[cursor]), sizeof(dict_entry_t)*(l->num_strings - cursor));
Line 292... Line 292...
292
        if (id >= maxid) {
292
        if (id >= maxid) {
293
          maxid = id;
293
          maxid = id;
294
          maxid_line = linecount;
294
          maxid_line = linecount;
295
        }
295
        }
296
        else {
296
        else {
297
          printf("WARNING:%s[#%u] file unsorted - line %u has higher id %u.%u\r\n", fname, linecount, maxid_line, maxid >> 8, maxid & 0xff);          
297
          printf("WARNING:%s[#%u] file unsorted - line %u has higher id %u.%u\r\n", fname, linecount, maxid_line, maxid >> 8, maxid & 0xff);
298
        }
298
        }
299
      }
299
      }
300
      else {
300
      else {
301
        printf("WARNING: %s[#%u] has an invalid id (%u.%u not present in ref lang)\r\n", fname, linecount, id >> 8, id & 0xff);
301
        printf("WARNING: %s[#%u] has an invalid id (%u.%u not present in ref lang)\r\n", fname, linecount, id >> 8, id & 0xff);
302
      }
302
      }
303
    }
303
    }
304
    else {
304
    else {
305
      printf("WARNING: %s[#%u] has a duplicated id (%u.%u)\r\n", fname, linecount, id >> 8, id & 0xff);      
305
      printf("WARNING: %s[#%u] has a duplicated id (%u.%u)\r\n", fname, linecount, id >> 8, id & 0xff);
306
    }
306
    }
307
  }
307
  }
308
 
308
 
309
  fclose(fd);
309
  fclose(fd);
310
 
310
 
Line 326... Line 326...
326
}
326
}
327
 
327
 
328
 
328
 
329
static int svl_write_header(unsigned short num_strings, FILE *fd)
329
static int svl_write_header(unsigned short num_strings, FILE *fd)
330
{
330
{
331
  return (fwrite("SvL1\x1a", 1, 5, fd) == 5) &&
331
  return (fwrite("SvL\x1a", 1, 4, fd) == 4) &&
332
          (fwrite(&num_strings, 1, 2, fd) == 2);
332
          (fwrite(&num_strings, 1, 2, fd) == 2);
333
}
333
}
334
 
334
 
335
 
335
 
336
static int svl_write_lang(svl_lang_t *l, FILE *fd)
336
static int svl_write_lang(svl_lang_t *l, FILE *fd)
Line 455... Line 455...
455
        printf("ERROR WRITING TO OUTPUT FILE\r\n");
455
        printf("ERROR WRITING TO OUTPUT FILE\r\n");
456
        ecode = 1;
456
        ecode = 1;
457
        break;
457
        break;
458
      }
458
      }
459
    }
459
    }
460
    
460
 
461
    /* write lang ID to file, followed string table size, and then
461
    /* write lang ID to file, followed string table size, and then
462
       the dictionary and string table for current language */
462
       the dictionary and string table for current language */
463
    if (!svl_write_lang(lang, fd)) {
463
    if (!svl_write_lang(lang, fd)) {
464
      printf("ERROR WRITING TO OUTPUT FILE\r\n");
464
      printf("ERROR WRITING TO OUTPUT FILE\r\n");
465
      ecode = 1;
465
      ecode = 1;