X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=blobdiff_plain;f=prvm_edict.c;h=22be6c176e2e876cc9eba8f90be8b09ec1df24c7;hp=2c60372bb34c832717bf299552dc33a5a224054e;hb=668fc41f79b91c7c33baef71384a7c4f88d9a919;hpb=0b4104966c3390067281b17983023676074ae734 diff --git a/prvm_edict.c b/prvm_edict.c index 2c60372b..22be6c17 100644 --- a/prvm_edict.c +++ b/prvm_edict.c @@ -29,7 +29,7 @@ int prvm_type_size[8] = {1,sizeof(string_t)/4,1,3,1,1,sizeof(func_t)/4,sizeof(v prvm_eval_t prvm_badvalue; // used only for error returns -cvar_t prvm_language = {CVAR_SAVE, "prvm_language", "", "when set, loads progs.dat.LANGUAGENAME.po for string translations; when set to dump, progs.dat.pot is written from the strings in the progs"}; +cvar_t prvm_language = {CVAR_SAVE, "prvm_language", "", "when set, loads PROGSFILE.LANGUAGENAME.po and common.LANGUAGENAME.po for string translations; when set to dump, PROGSFILE.pot is written from the strings in the progs"}; // LordHavoc: prints every opcode as it executes - warning: this is significant spew cvar_t prvm_traceqc = {0, "prvm_traceqc", "0", "prints every QuakeC statement as it is executed (only for really thorough debugging!)"}; // LordHavoc: counts usage of each QuakeC statement @@ -156,8 +156,10 @@ prvm_prog_t *PRVM_ProgFromString(const char *str) return SVVM_prog; if (!strcmp(str, "client")) return CLVM_prog; +#ifdef CONFIG_MENU if (!strcmp(str, "menu")) return MVM_prog; +#endif return NULL; } @@ -1683,7 +1685,7 @@ static void PRVM_PO_ParseString(char *out, const char *in, size_t outsize) ++in; } } -static po_t *PRVM_PO_Load(const char *filename, mempool_t *pool) +static po_t *PRVM_PO_Load(const char *filename, const char *filename2, mempool_t *pool) { po_t *po; const char *p, *q; @@ -1693,93 +1695,106 @@ static po_t *PRVM_PO_Load(const char *filename, mempool_t *pool) size_t decodedpos; int hashindex; po_string_t thisstr; - const char *buf = (const char *) FS_LoadFile(filename, pool, true, NULL); - - if(!buf) - return NULL; - - memset(&thisstr, 0, sizeof(thisstr)); // hush compiler warning - - po = (po_t *)Mem_Alloc(pool, sizeof(*po)); - memset(po, 0, sizeof(*po)); + int i; - p = buf; - while(*p) + for (i = 0; i < 2; ++i) { - if(*p == '#') - { - // skip to newline - p = strchr(p, '\n'); - if(!p) - break; - ++p; - continue; - } - if(*p == '\r' || *p == '\n') - { - ++p; + const char *buf = (const char *) + FS_LoadFile((i > 0 ? filename : filename2), pool, true, NULL); + // first read filename2, then read filename + // so that progs.dat.de.po wins over common.de.po + // and within file, last item wins + + if(!buf) continue; - } - if(!strncmp(p, "msgid \"", 7)) - { - mode = 0; - p += 6; - } - else if(!strncmp(p, "msgstr \"", 8)) + + if (!po) { - mode = 1; - p += 7; + po = (po_t *)Mem_Alloc(pool, sizeof(*po)); + memset(po, 0, sizeof(*po)); } - else + + memset(&thisstr, 0, sizeof(thisstr)); // hush compiler warning + + p = buf; + while(*p) { - p = strchr(p, '\n'); - if(!p) - break; - ++p; - continue; + if(*p == '#') + { + // skip to newline + p = strchr(p, '\n'); + if(!p) + break; + ++p; + continue; + } + if(*p == '\r' || *p == '\n') + { + ++p; + continue; + } + if(!strncmp(p, "msgid \"", 7)) + { + mode = 0; + p += 6; + } + else if(!strncmp(p, "msgstr \"", 8)) + { + mode = 1; + p += 7; + } + else + { + p = strchr(p, '\n'); + if(!p) + break; + ++p; + continue; + } + decodedpos = 0; + while(*p == '"') + { + ++p; + q = strchr(p, '\n'); + if(!q) + break; + if(*(q-1) == '\r') + --q; + if(*(q-1) != '"') + break; + if((size_t)(q - p) >= (size_t) sizeof(inbuf)) + break; + strlcpy(inbuf, p, q - p); // not - 1, because this adds a NUL + PRVM_PO_ParseString(decodedbuf + decodedpos, inbuf, sizeof(decodedbuf) - decodedpos); + decodedpos += strlen(decodedbuf + decodedpos); + if(*q == '\r') + ++q; + if(*q == '\n') + ++q; + p = q; + } + if(mode == 0) + { + if(thisstr.key) + Mem_Free(thisstr.key); + thisstr.key = (char *)Mem_Alloc(pool, decodedpos + 1); + memcpy(thisstr.key, decodedbuf, decodedpos + 1); + } + else if(decodedpos > 0 && thisstr.key) // skip empty translation results + { + thisstr.value = (char *)Mem_Alloc(pool, decodedpos + 1); + memcpy(thisstr.value, decodedbuf, decodedpos + 1); + hashindex = CRC_Block((const unsigned char *) thisstr.key, strlen(thisstr.key)) % PO_HASHSIZE; + thisstr.nextonhashchain = po->hashtable[hashindex]; + po->hashtable[hashindex] = (po_string_t *)Mem_Alloc(pool, sizeof(thisstr)); + memcpy(po->hashtable[hashindex], &thisstr, sizeof(thisstr)); + memset(&thisstr, 0, sizeof(thisstr)); + } } - decodedpos = 0; - while(*p == '"') - { - ++p; - q = strchr(p, '\n'); - if(!q) - break; - if(*(q-1) == '\r') - --q; - if(*(q-1) != '"') - break; - if((size_t)(q - p) >= (size_t) sizeof(inbuf)) - break; - strlcpy(inbuf, p, q - p); // not - 1, because this adds a NUL - PRVM_PO_ParseString(decodedbuf + decodedpos, inbuf, sizeof(decodedbuf) - decodedpos); - decodedpos += strlen(decodedbuf + decodedpos); - if(*q == '\r') - ++q; - if(*q == '\n') - ++q; - p = q; - } - if(mode == 0) - { - if(thisstr.key) - Mem_Free(thisstr.key); - thisstr.key = (char *)Mem_Alloc(pool, decodedpos + 1); - memcpy(thisstr.key, decodedbuf, decodedpos + 1); - } - else if(decodedpos > 0 && thisstr.key) // skip empty translation results - { - thisstr.value = (char *)Mem_Alloc(pool, decodedpos + 1); - memcpy(thisstr.value, decodedbuf, decodedpos + 1); - hashindex = CRC_Block((const unsigned char *) thisstr.key, strlen(thisstr.key)) % PO_HASHSIZE; - thisstr.nextonhashchain = po->hashtable[hashindex]; - po->hashtable[hashindex] = (po_string_t *)Mem_Alloc(pool, sizeof(thisstr)); - memcpy(po->hashtable[hashindex], &thisstr, sizeof(thisstr)); - memset(&thisstr, 0, sizeof(thisstr)); - } - } - - Mem_Free((char *) buf); + + Mem_Free((char *) buf); + } + return po; } static const char *PRVM_PO_Lookup(po_t *po, const char *str) @@ -2288,7 +2303,7 @@ void PRVM_Prog_Load(prvm_prog_t *prog, const char * filename, unsigned char * da } else { - po_t *po = PRVM_PO_Load(va(vabuf, sizeof(vabuf), "%s.%s.po", realfilename, prvm_language.string), prog->progs_mempool); + po_t *po = PRVM_PO_Load(va(vabuf, sizeof(vabuf), "%s.%s.po", realfilename, prvm_language.string), "common.po", prog->progs_mempool); if(po) { for (i=0 ; inumglobaldefs ; i++) @@ -2718,7 +2733,7 @@ static void PRVM_UpdateBreakpoints(prvm_prog_t *prog) { size_t sz = sizeof(prvm_vec_t) * ((global->type & ~DEF_SAVEGLOBAL) == ev_vector ? 3 : 1); prog->watch_global = global->ofs; - prog->watch_global_type = global->type; + prog->watch_global_type = (etype_t)global->type; memcpy(&prog->watch_global_value, PRVM_GLOBALFIELDVALUE(prog->watch_global), sz); } if (prog->watch_global_type != ev_void) @@ -2740,7 +2755,7 @@ static void PRVM_UpdateBreakpoints(prvm_prog_t *prog) size_t sz = sizeof(prvm_vec_t) * ((field->type & ~DEF_SAVEGLOBAL) == ev_vector ? 3 : 1); prog->watch_edict = debug->watch_edict; prog->watch_field = field->ofs; - prog->watch_field_type = field->type; + prog->watch_field_type = (etype_t)field->type; if (prog->watch_edict < prog->num_edicts) memcpy(&prog->watch_edictfield_value, PRVM_EDICTFIELDVALUE(PRVM_EDICT_NUM(prog->watch_edict), prog->watch_field), sz); else