Subversion Repositories SvarDOS

Rev

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

Rev 601 Rev 623
Line 14... Line 14...
14
 * II LL    - II is the LANG identifier ("EN", "PL", etc) and LL is the size
14
 * II LL    - II is the LANG identifier ("EN", "PL", etc) and LL is the size
15
 *            of the block (65535 bytes max).
15
 *            of the block (65535 bytes max).
16
 *
16
 *
17
 * Inside a LANG BLOCK is a set of strings:
17
 * Inside a LANG BLOCK is a set of strings:
18
 *
18
 *
19
 * II L S  where II is the string's 16-bit identifier, L is its length (1-255)
19
 * II LL S  where II is the string's 16-bit identifier, LL is its length
20
 *         and S is the actual string. All strings are ASCIIZ-formatted (ie.
20
 *          (1-65535) and S is the actual string. All strings are ASCIIZ (ie.
21
 *         end with a NULL terminator).
21
 *          they end with a NULL terminator).
22
 *
22
 *
23
 * The list of strings ends with a single 0-long string.
23
 * The list of strings ends with a single 0-long string.
24
 */
24
 */
25
 
25
 
26
 
26
 
Line 33... Line 33...
33
struct bitmap {
33
struct bitmap {
34
  unsigned char bits[8192];
34
  unsigned char bits[8192];
35
};
35
};
36
 
36
 
37
static void bitmap_set(struct bitmap *b, unsigned short id) {
37
static void bitmap_set(struct bitmap *b, unsigned short id) {
38
  b->bits[id / 8] |= 1 << (id & 7);
38
  b->bits[id >> 3] |= 1 << (id & 7);
39
}
39
}
40
 
40
 
41
static int bitmap_get(const struct bitmap *b, unsigned short id) {
41
static int bitmap_get(const struct bitmap *b, unsigned short id) {
42
  return(b->bits[id / 8] & (1 << (id & 7)));
42
  return(b->bits[id >> 3] & (1 << (id & 7)));
43
}
43
}
44
 
44
 
45
static void bitmap_init(struct bitmap *b) {
45
static void bitmap_init(struct bitmap *b) {
46
  memset(b, 0, sizeof(struct bitmap));
46
  bzero(b, sizeof(struct bitmap));
47
}
47
}
48
 
48
 
49
 
49
 
50
 
50
 
51
/* read a single line from fd and fills it into dst, returns line length
51
/* read a single line from fd and fills it into dst, returns line length
Line 103... Line 103...
103
/* opens a CATS-style file and compiles it into a ressources lang block */
103
/* opens a CATS-style file and compiles it into a ressources lang block */
104
static unsigned short gen_langstrings(unsigned char *buff, const char *langid, struct bitmap *b, const struct bitmap *refb, const unsigned char *refblock) {
104
static unsigned short gen_langstrings(unsigned char *buff, const char *langid, struct bitmap *b, const struct bitmap *refb, const unsigned char *refblock) {
105
  unsigned short len = 0, linelen;
105
  unsigned short len = 0, linelen;
106
  FILE *fd;
106
  FILE *fd;
107
  char fname[] = "XX.TXT";
107
  char fname[] = "XX.TXT";
108
  char linebuf[512];
108
  static char linebuf[8192];
109
  char *ptr;
109
  char *ptr;
110
  unsigned short id, linecount;
110
  unsigned short id, linecount;
111
 
111
 
112
  bitmap_init(b);
112
  bitmap_init(b);
113
 
113
 
Line 126... Line 126...
126
    if ((linelen == 0) || (linebuf[0] == '#')) continue;
126
    if ((linelen == 0) || (linebuf[0] == '#')) continue;
127
 
127
 
128
    /* read id and get ptr to actual string ("1.15:string") */
128
    /* read id and get ptr to actual string ("1.15:string") */
129
    ptr = parseline(&id, linebuf);
129
    ptr = parseline(&id, linebuf);
130
    if (ptr == NULL) {
130
    if (ptr == NULL) {
131
      printf("ERROR: line #%u of %s is malformed\r\n", linecount, fname);
131
      printf("ERROR: line #%u of %s is malformed (linelen = %u):\r\n", linecount, fname, linelen);
-
 
132
      puts(linebuf);
132
      len = 0;
133
      len = 0;
133
      break;
134
      break;
134
    }
135
    }
135
 
136
 
136
    /* write string into block (II L S) */
137
    /* write string into block (II LL S) */
137
    memcpy(buff + len, &id, 2);
138
    memcpy(buff + len, &id, 2);
138
    len += 2;
139
    len += 2;
-
 
140
    {
139
    buff[len++] = strlen(ptr) + 1;
141
      unsigned short slen = strlen(ptr) + 1;
-
 
142
      memcpy(buff + len, &slen, 2);
-
 
143
      len += 2;
140
    memcpy(buff + len, ptr, strlen(ptr) + 1);
144
      memcpy(buff + len, ptr, slen);
141
    len += strlen(ptr) + 1;
145
      len += slen;
-
 
146
    }
142
 
147
 
143
    /* if reference bitmap provided: check that the id is valid */
148
    /* if reference bitmap provided: check that the id is valid */
144
    if ((refb != NULL) && (bitmap_get(refb, id) == 0)) {
149
    if ((refb != NULL) && (bitmap_get(refb, id) == 0)) {
145
      printf("WARNING: %s[#%u] has an invalid id (%u.%u not present in ref lang)\r\n", fname, linecount, id >> 8, id & 0xff);
150
      printf("WARNING: %s[#%u] has an invalid id (%u.%u not present in ref lang)\r\n", fname, linecount, id >> 8, id & 0xff);
146
    }
151
    }
Line 157... Line 162...
157
  fclose(fd);
162
  fclose(fd);
158
 
163
 
159
  /* if refblock provided, pull missing strings from it */
164
  /* if refblock provided, pull missing strings from it */
160
  if (refblock != NULL) {
165
  if (refblock != NULL) {
161
    for (;;) {
166
    for (;;) {
-
 
167
      unsigned short slen;
162
      id = *((unsigned short *)refblock);
168
      id = ((unsigned short *)refblock)[0];
-
 
169
      slen = ((unsigned short *)refblock)[1];
163
      if ((id == 0) && (refblock[2] == 0)) break;
170
      if ((id == 0) && (slen == 0)) break;
164
      if (bitmap_get(b, id) == 0) {
171
      if (bitmap_get(b, id) == 0) {
165
        printf("WARNING: %s is missing string %u.%u (pulled from ref lang)\r\n", fname, id >> 8, id & 0xff);
172
        printf("WARNING: %s is missing string %u.%u (pulled from ref lang)\r\n", fname, id >> 8, id & 0xff);
166
        /* copy missing string from refblock */
173
        /* copy missing string from refblock */
167
        memcpy(buff + len, refblock, refblock[2] + 3);
174
        memcpy(buff + len, refblock, slen + 4);
168
        len += refblock[2] + 3;
175
        len += slen + 4;
169
      }
176
      }
170
      refblock += refblock[2] + 3;
177
      refblock += slen + 4;
171
    }
178
    }
172
  }
179
  }
173
 
180
 
174
  /* write the block terminator (0-long string) */
181
  /* write the block terminator (0-long string) */
175
  buff[len++] = 0; /* id */
182
  buff[len++] = 0; /* id */
176
  buff[len++] = 0; /* id */
183
  buff[len++] = 0; /* id */
177
  buff[len++] = 0; /* len */
184
  buff[len++] = 0; /* len */
-
 
185
  buff[len++] = 0; /* len */
-
 
186
  buff[len++] = 0; /* empty string */
178
 
187
 
179
  return(len);
188
  return(len);
180
}
189
}
181
 
190
 
182
 
191