Subversion Repositories SvarDOS

Compare Revisions

Ignore whitespace Rev 622 → Rev 623

/svarlang.lib/svarlang.c
38,12 → 38,9
const char *ptr = svarlang_mem;
/* find the string id in langblock memory */
for (;;) {
if (((unsigned short *)ptr)[0] == id) {
ptr += 3;
return(ptr);
}
if (ptr[2] == 0) return(NULL);
ptr += ptr[2] + 3;
if (((unsigned short *)ptr)[0] == id) return(ptr + 4);
if (((unsigned short *)ptr)[1] == 0) return(ptr + 2); /* end of strings - return an empty string */
ptr += ((unsigned short *)ptr)[1] + 4;
}
}
 
/svarlang.lib/svarlang.h
35,7 → 35,8
/* Returns a pointer to the string "id". Does not require svalang_load() to be
* executed, but then it will only return the reference language strings.
* a string id is the concatenation of the CATS-style identifiers, for example
* string 1,0 becomes 0x0100, string 2.10 is 0x020A, etc. */
* string 1,0 becomes 0x0100, string 2.10 is 0x020A, etc.
* It NEVER returns NULL, if id not found then an empty string is returned */
const char *svarlang_strid(unsigned short id);
 
/* a convenience definition to fetch strings by their CATS-style pairs instead
/svarlang.lib/tlumacz.c
16,9 → 16,9
*
* Inside a LANG BLOCK is a set of strings:
*
* II L S where II is the string's 16-bit identifier, L is its length (1-255)
* and S is the actual string. All strings are ASCIIZ-formatted (ie.
* end with a NULL terminator).
* II LL S where II is the string's 16-bit identifier, LL is its length
* (1-65535) and S is the actual string. All strings are ASCIIZ (ie.
* they end with a NULL terminator).
*
* The list of strings ends with a single 0-long string.
*/
35,15 → 35,15
};
 
static void bitmap_set(struct bitmap *b, unsigned short id) {
b->bits[id / 8] |= 1 << (id & 7);
b->bits[id >> 3] |= 1 << (id & 7);
}
 
static int bitmap_get(const struct bitmap *b, unsigned short id) {
return(b->bits[id / 8] & (1 << (id & 7)));
return(b->bits[id >> 3] & (1 << (id & 7)));
}
 
static void bitmap_init(struct bitmap *b) {
memset(b, 0, sizeof(struct bitmap));
bzero(b, sizeof(struct bitmap));
}
 
 
105,7 → 105,7
unsigned short len = 0, linelen;
FILE *fd;
char fname[] = "XX.TXT";
char linebuf[512];
static char linebuf[8192];
char *ptr;
unsigned short id, linecount;
 
128,17 → 128,22
/* read id and get ptr to actual string ("1.15:string") */
ptr = parseline(&id, linebuf);
if (ptr == NULL) {
printf("ERROR: line #%u of %s is malformed\r\n", linecount, fname);
printf("ERROR: line #%u of %s is malformed (linelen = %u):\r\n", linecount, fname, linelen);
puts(linebuf);
len = 0;
break;
}
 
/* write string into block (II L S) */
/* write string into block (II LL S) */
memcpy(buff + len, &id, 2);
len += 2;
buff[len++] = strlen(ptr) + 1;
memcpy(buff + len, ptr, strlen(ptr) + 1);
len += strlen(ptr) + 1;
{
unsigned short slen = strlen(ptr) + 1;
memcpy(buff + len, &slen, 2);
len += 2;
memcpy(buff + len, ptr, slen);
len += slen;
}
 
/* if reference bitmap provided: check that the id is valid */
if ((refb != NULL) && (bitmap_get(refb, id) == 0)) {
159,15 → 164,17
/* if refblock provided, pull missing strings from it */
if (refblock != NULL) {
for (;;) {
id = *((unsigned short *)refblock);
if ((id == 0) && (refblock[2] == 0)) break;
unsigned short slen;
id = ((unsigned short *)refblock)[0];
slen = ((unsigned short *)refblock)[1];
if ((id == 0) && (slen == 0)) break;
if (bitmap_get(b, id) == 0) {
printf("WARNING: %s is missing string %u.%u (pulled from ref lang)\r\n", fname, id >> 8, id & 0xff);
/* copy missing string from refblock */
memcpy(buff + len, refblock, refblock[2] + 3);
len += refblock[2] + 3;
memcpy(buff + len, refblock, slen + 4);
len += slen + 4;
}
refblock += refblock[2] + 3;
refblock += slen + 4;
}
}
 
175,6 → 182,8
buff[len++] = 0; /* id */
buff[len++] = 0; /* id */
buff[len++] = 0; /* len */
buff[len++] = 0; /* len */
buff[len++] = 0; /* empty string */
 
return(len);
}