(svn r2359) Use strecpy instead of str_cat (which was rather a cpy than a cat, btw), remove the latter and simplify some constructs

replace/41b28d7194a279bdc17475d4fbe2ea6ec885a466
tron 19 years ago
parent 870127fd30
commit aa1c202577

@ -124,11 +124,6 @@ static const StringID _cargo_string_list[NUM_LANDSCAPE][NUM_CARGO] = {
} }
}; };
static char *str_cat(char *dst, const char *src)
{
while ((*dst++ = *src++) != '\0') {}
return dst - 1;
}
static const char *GetStringPtr(StringID string) static const char *GetStringPtr(StringID string)
{ {
@ -464,21 +459,18 @@ static char *DecodeString(char *buff, const char *str)
buff = FormatNoCommaNumber(buff, GetParamInt32()); buff = FormatNoCommaNumber(buff, GetParamInt32());
break; break;
case 2: /* {REV} */ case 2: /* {REV} */
buff = str_cat(buff, _openttd_revision); buff = strecpy(buff, _openttd_revision, NULL);
break; break;
case 3: { /* {SHORTCARGO} */ case 3: { /* {SHORTCARGO} */
// Short description of cargotypes. Layout: // Short description of cargotypes. Layout:
// 8-bit = cargo type // 8-bit = cargo type
// 16-bit = cargo count // 16-bit = cargo count
const char *s;
StringID cargo_str = _cargo_string_list[_opt_ptr->landscape][(byte)GetParamInt8()]; StringID cargo_str = _cargo_string_list[_opt_ptr->landscape][(byte)GetParamInt8()];
uint16 multiplier = (cargo_str == STR_LITERS) ? 1000 : 1; uint16 multiplier = (cargo_str == STR_LITERS) ? 1000 : 1;
// liquid type of cargo is multiplied by 100 to get correct amount // liquid type of cargo is multiplied by 100 to get correct amount
buff = FormatCommaNumber(buff, GetParamInt16() * multiplier); buff = FormatCommaNumber(buff, GetParamInt16() * multiplier);
s = GetStringPtr(cargo_str); buff = strecpy(buff, " ", NULL);
buff = strecpy(buff, GetStringPtr(cargo_str), NULL);
memcpy(buff++, " ", 1);
while (*s) *buff++ = *s++;
} break; } break;
case 4: /* {CURRCOMPACT64} */ case 4: /* {CURRCOMPACT64} */
// 64 bit compact currency-unit // 64 bit compact currency-unit
@ -494,14 +486,11 @@ static char *DecodeString(char *buff, const char *str)
GetParamInt16(); GetParamInt16();
//assert(0); //assert(0);
break; break;
case 0x87: { // {VOLUME} case 0x87: // {VOLUME}
const char *s;
buff = FormatCommaNumber(buff, GetParamInt16() * 1000); buff = FormatCommaNumber(buff, GetParamInt16() * 1000);
memcpy(buff++, " ", 1); buff = strecpy(buff, " ", NULL);
s = GetStringPtr(STR_LITERS); buff = strecpy(buff, GetStringPtr(STR_LITERS), NULL);
while (*s) *buff++ = *s++;
break; break;
}
case 0x88: // {STRING} case 0x88: // {STRING}
buff = GetString(buff, (uint16)GetParamUint16()); buff = GetString(buff, (uint16)GetParamUint16());
@ -684,8 +673,8 @@ static char *GenAndCoName(char *buff)
num = 12; num = 12;
} }
buff = str_cat(buff, _surname_list[base + ((num * (byte)(x >> 16)) >> 8)]); buff = strecpy(buff, _surname_list[base + (num * GB(x, 16, 8) >> 8)], NULL);
buff = str_cat(buff, " & Co."); buff = strecpy(buff, " & Co.", NULL);
return buff; return buff;
} }
@ -715,7 +704,7 @@ static char *GenPlayerName_4(char *buff)
num = 12; num = 12;
} }
buff = str_cat(buff, _surname_list[base + ((num * (byte)(x >> 16)) >> 8)]); buff = strecpy(buff, _surname_list[base + (num * GB(x, 16, 8) >> 8)], NULL);
return buff; return buff;
} }
@ -749,7 +738,7 @@ static char *GetSpecialPlayerNameString(char *buff, int ind)
{ {
switch (ind) { switch (ind) {
case 1: // not used case 1: // not used
return str_cat(buff, _silly_company_names[GetParamInt32() & 0xFFFF]); return strecpy(buff, _silly_company_names[GetParamInt32() & 0xFFFF], NULL);
case 2: // used for Foobar & Co company names case 2: // used for Foobar & Co company names
return GenAndCoName(buff); return GenAndCoName(buff);
@ -758,19 +747,20 @@ static char *GetSpecialPlayerNameString(char *buff, int ind)
return GenPlayerName_4(buff); return GenPlayerName_4(buff);
case 4: // song names case 4: // song names
return str_cat(buff, _song_names[GetParamUint16() - 1]); return strecpy(buff, _song_names[GetParamUint16() - 1], NULL);
} }
// town name? // town name?
if (IS_INT_INSIDE(ind - 6, 0, SPECSTR_TOWNNAME_LAST-SPECSTR_TOWNNAME_START + 1)) { if (IS_INT_INSIDE(ind - 6, 0, SPECSTR_TOWNNAME_LAST-SPECSTR_TOWNNAME_START + 1)) {
buff = GetSpecialTownNameString(buff, ind - 6); buff = GetSpecialTownNameString(buff, ind - 6);
return str_cat(buff, " Transport"); return strecpy(buff, " Transport", NULL);
} }
// language name? // language name?
if (IS_INT_INSIDE(ind, (SPECSTR_LANGUAGE_START - 0x70E4), (SPECSTR_LANGUAGE_END - 0x70E4) + 1)) { if (IS_INT_INSIDE(ind, (SPECSTR_LANGUAGE_START - 0x70E4), (SPECSTR_LANGUAGE_END - 0x70E4) + 1)) {
int i = ind - (SPECSTR_LANGUAGE_START - 0x70E4); int i = ind - (SPECSTR_LANGUAGE_START - 0x70E4);
return str_cat(buff, i == _dynlang.curr ? _langpack->own_name : _dynlang.ent[i].name); return strecpy(buff,
i == _dynlang.curr ? _langpack->own_name : _dynlang.ent[i].name, NULL);
} }
// resolution size? // resolution size?
@ -782,7 +772,7 @@ static char *GetSpecialPlayerNameString(char *buff, int ind)
// screenshot format name? // screenshot format name?
if (IS_INT_INSIDE(ind, (SPECSTR_SCREENSHOT_START - 0x70E4), (SPECSTR_SCREENSHOT_END - 0x70E4) + 1)) { if (IS_INT_INSIDE(ind, (SPECSTR_SCREENSHOT_START - 0x70E4), (SPECSTR_SCREENSHOT_END - 0x70E4) + 1)) {
int i = ind - (SPECSTR_SCREENSHOT_START - 0x70E4); int i = ind - (SPECSTR_SCREENSHOT_START - 0x70E4);
return str_cat(buff, GetScreenshotFormatDesc(i)); return strecpy(buff, GetScreenshotFormatDesc(i), NULL);
} }
assert(0); assert(0);

Loading…
Cancel
Save