• R/O
  • SSH
  • HTTPS

svardos: Commit


Commit MetaInfo

Revision623 (tree)
Time2022-02-05 05:58:17
Authormateuszviste

Log Message

support for very long messages (longer than 256 bytes)

Change Summary

Incremental Difference

--- svarlang.lib/svarlang.c (revision 622)
+++ svarlang.lib/svarlang.c (revision 623)
@@ -38,12 +38,9 @@
3838 const char *ptr = svarlang_mem;
3939 /* find the string id in langblock memory */
4040 for (;;) {
41- if (((unsigned short *)ptr)[0] == id) {
42- ptr += 3;
43- return(ptr);
44- }
45- if (ptr[2] == 0) return(NULL);
46- ptr += ptr[2] + 3;
41+ if (((unsigned short *)ptr)[0] == id) return(ptr + 4);
42+ if (((unsigned short *)ptr)[1] == 0) return(ptr + 2); /* end of strings - return an empty string */
43+ ptr += ((unsigned short *)ptr)[1] + 4;
4744 }
4845 }
4946
--- svarlang.lib/svarlang.h (revision 622)
+++ svarlang.lib/svarlang.h (revision 623)
@@ -35,7 +35,8 @@
3535 /* Returns a pointer to the string "id". Does not require svalang_load() to be
3636 * executed, but then it will only return the reference language strings.
3737 * a string id is the concatenation of the CATS-style identifiers, for example
38- * string 1,0 becomes 0x0100, string 2.10 is 0x020A, etc. */
38+ * string 1,0 becomes 0x0100, string 2.10 is 0x020A, etc.
39+ * It NEVER returns NULL, if id not found then an empty string is returned */
3940 const char *svarlang_strid(unsigned short id);
4041
4142 /* a convenience definition to fetch strings by their CATS-style pairs instead
--- svarlang.lib/tlumacz.c (revision 622)
+++ svarlang.lib/tlumacz.c (revision 623)
@@ -16,9 +16,9 @@
1616 *
1717 * Inside a LANG BLOCK is a set of strings:
1818 *
19- * II L S where II is the string's 16-bit identifier, L is its length (1-255)
20- * and S is the actual string. All strings are ASCIIZ-formatted (ie.
21- * end with a NULL terminator).
19+ * II LL S where II is the string's 16-bit identifier, LL is its length
20+ * (1-65535) and S is the actual string. All strings are ASCIIZ (ie.
21+ * they end with a NULL terminator).
2222 *
2323 * The list of strings ends with a single 0-long string.
2424 */
@@ -35,15 +35,15 @@
3535 };
3636
3737 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);
3939 }
4040
4141 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)));
4343 }
4444
4545 static void bitmap_init(struct bitmap *b) {
46- memset(b, 0, sizeof(struct bitmap));
46+ bzero(b, sizeof(struct bitmap));
4747 }
4848
4949
@@ -105,7 +105,7 @@
105105 unsigned short len = 0, linelen;
106106 FILE *fd;
107107 char fname[] = "XX.TXT";
108- char linebuf[512];
108+ static char linebuf[8192];
109109 char *ptr;
110110 unsigned short id, linecount;
111111
@@ -128,17 +128,22 @@
128128 /* read id and get ptr to actual string ("1.15:string") */
129129 ptr = parseline(&id, linebuf);
130130 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);
132133 len = 0;
133134 break;
134135 }
135136
136- /* write string into block (II L S) */
137+ /* write string into block (II LL S) */
137138 memcpy(buff + len, &id, 2);
138139 len += 2;
139- buff[len++] = strlen(ptr) + 1;
140- memcpy(buff + len, ptr, strlen(ptr) + 1);
141- len += strlen(ptr) + 1;
140+ {
141+ unsigned short slen = strlen(ptr) + 1;
142+ memcpy(buff + len, &slen, 2);
143+ len += 2;
144+ memcpy(buff + len, ptr, slen);
145+ len += slen;
146+ }
142147
143148 /* if reference bitmap provided: check that the id is valid */
144149 if ((refb != NULL) && (bitmap_get(refb, id) == 0)) {
@@ -159,15 +164,17 @@
159164 /* if refblock provided, pull missing strings from it */
160165 if (refblock != NULL) {
161166 for (;;) {
162- id = *((unsigned short *)refblock);
163- if ((id == 0) && (refblock[2] == 0)) break;
167+ unsigned short slen;
168+ id = ((unsigned short *)refblock)[0];
169+ slen = ((unsigned short *)refblock)[1];
170+ if ((id == 0) && (slen == 0)) break;
164171 if (bitmap_get(b, id) == 0) {
165172 printf("WARNING: %s is missing string %u.%u (pulled from ref lang)\r\n", fname, id >> 8, id & 0xff);
166173 /* copy missing string from refblock */
167- memcpy(buff + len, refblock, refblock[2] + 3);
168- len += refblock[2] + 3;
174+ memcpy(buff + len, refblock, slen + 4);
175+ len += slen + 4;
169176 }
170- refblock += refblock[2] + 3;
177+ refblock += slen + 4;
171178 }
172179 }
173180
@@ -175,6 +182,8 @@
175182 buff[len++] = 0; /* id */
176183 buff[len++] = 0; /* id */
177184 buff[len++] = 0; /* len */
185+ buff[len++] = 0; /* len */
186+ buff[len++] = 0; /* empty string */
178187
179188 return(len);
180189 }
Show on old repository browser