mirror of https://github.com/OpenTTD/OpenTTD
(svn r1820) Style cleanup:
- indentation - 0 -> '\0' in string handling - whitespaces - space after for, switch, etc. - don't treat non-boolean values as boolean - space before and after binary operators - bracing stylerelease/0.4.5
parent
ccf3c71903
commit
498ccae27a
127
strings.c
127
strings.c
|
@ -59,15 +59,70 @@ const uint16 _currency_string_list[] = {
|
|||
};
|
||||
|
||||
static const uint16 _cargo_string_list[NUM_LANDSCAPE][NUM_CARGO] = {
|
||||
/* LT_NORMAL */ {STR_PASSENGERS, STR_TONS, STR_BAGS, STR_LITERS, STR_ITEMS, STR_CRATES, STR_TONS, STR_TONS, STR_TONS, STR_TONS, STR_BAGS, STR_RES_OTHER},
|
||||
/* LT_HILLY */ {STR_PASSENGERS, STR_TONS, STR_BAGS, STR_LITERS, STR_ITEMS, STR_CRATES, STR_TONS, STR_TONS, STR_RES_OTHER, STR_TONS, STR_BAGS, STR_TONS},
|
||||
/* LT_DESERT */ {STR_PASSENGERS, STR_LITERS, STR_BAGS, STR_LITERS, STR_TONS, STR_CRATES, STR_TONS, STR_TONS, STR_TONS, STR_LITERS, STR_BAGS, STR_TONS},
|
||||
/* LT_CANDY */ {STR_PASSENGERS, STR_TONS, STR_BAGS, STR_NOTHING, STR_NOTHING, STR_TONS, STR_TONS, STR_LITERS, STR_TONS, STR_NOTHING, STR_LITERS, STR_NOTHING}
|
||||
{ /* LT_NORMAL */
|
||||
STR_PASSENGERS,
|
||||
STR_TONS,
|
||||
STR_BAGS,
|
||||
STR_LITERS,
|
||||
STR_ITEMS,
|
||||
STR_CRATES,
|
||||
STR_TONS,
|
||||
STR_TONS,
|
||||
STR_TONS,
|
||||
STR_TONS,
|
||||
STR_BAGS,
|
||||
STR_RES_OTHER
|
||||
},
|
||||
|
||||
{ /* LT_HILLY */
|
||||
STR_PASSENGERS,
|
||||
STR_TONS,
|
||||
STR_BAGS,
|
||||
STR_LITERS,
|
||||
STR_ITEMS,
|
||||
STR_CRATES,
|
||||
STR_TONS,
|
||||
STR_TONS,
|
||||
STR_RES_OTHER,
|
||||
STR_TONS,
|
||||
STR_BAGS,
|
||||
STR_TONS
|
||||
},
|
||||
|
||||
{ /* LT_DESERT */
|
||||
STR_PASSENGERS,
|
||||
STR_LITERS,
|
||||
STR_BAGS,
|
||||
STR_LITERS,
|
||||
STR_TONS,
|
||||
STR_CRATES,
|
||||
STR_TONS,
|
||||
STR_TONS,
|
||||
STR_TONS,
|
||||
STR_LITERS,
|
||||
STR_BAGS,
|
||||
STR_TONS
|
||||
},
|
||||
|
||||
{ /* LT_CANDY */
|
||||
STR_PASSENGERS,
|
||||
STR_TONS,
|
||||
STR_BAGS,
|
||||
STR_NOTHING,
|
||||
STR_NOTHING,
|
||||
STR_TONS,
|
||||
STR_TONS,
|
||||
STR_LITERS,
|
||||
STR_TONS,
|
||||
STR_NOTHING,
|
||||
STR_LITERS,
|
||||
STR_NOTHING
|
||||
}
|
||||
};
|
||||
|
||||
static char *str_cat(char *dst, const char *src)
|
||||
{
|
||||
while ( (*dst++ = *src++) != 0) {}
|
||||
while ((*dst++ = *src++) != '\0') {}
|
||||
return dst - 1;
|
||||
}
|
||||
|
||||
|
@ -190,7 +245,7 @@ static char *FormatCommaNumber(char *buff, int32 number)
|
|||
}
|
||||
}
|
||||
|
||||
*buff = 0;
|
||||
*buff = '\0';
|
||||
|
||||
return buff;
|
||||
}
|
||||
|
@ -222,7 +277,7 @@ static char *FormatNoCommaNumber(char *buff, int32 number)
|
|||
}
|
||||
}
|
||||
|
||||
*buff = 0;
|
||||
*buff = '\0';
|
||||
|
||||
return buff;
|
||||
}
|
||||
|
@ -235,7 +290,7 @@ static char *FormatYmdString(char *buff, uint16 number)
|
|||
|
||||
ConvertDayToYMD(&ymd, number);
|
||||
|
||||
for(src = GetStringPtr(ymd.day+STR_01AC_1ST-1); (*buff++=*src++) != 0;) {}
|
||||
for (src = GetStringPtr(ymd.day + STR_01AC_1ST - 1); (*buff++ = *src++) != '\0';) {}
|
||||
|
||||
buff[-1] = ' ';
|
||||
memcpy(buff, GetStringPtr(STR_0162_JAN + ymd.month), 4);
|
||||
|
@ -251,7 +306,7 @@ static char *FormatMonthAndYear(char *buff, uint16 number)
|
|||
|
||||
ConvertDayToYMD(&ymd, number);
|
||||
|
||||
for(src = GetStringPtr(STR_MONTH_JAN + ymd.month); (*buff++=*src++) != 0;) {}
|
||||
for (src = GetStringPtr(STR_MONTH_JAN + ymd.month); (*buff++ = *src++) != '\0';) {}
|
||||
buff[-1] = ' ';
|
||||
|
||||
return FormatNoCommaNumber(buff, ymd.year + MAX_YEAR_BEGIN_REAL);
|
||||
|
@ -269,7 +324,7 @@ static char *FormatTinyDate(char *buff, uint16 number)
|
|||
|
||||
uint GetCurrentCurrencyRate(void)
|
||||
{
|
||||
return (&_currency_specs[_opt.currency])->rate;
|
||||
return _currency_specs[_opt.currency].rate;
|
||||
}
|
||||
|
||||
static char *FormatGenericCurrency(char *buff, const CurrencySpec *spec, int64 number, bool compact)
|
||||
|
@ -283,11 +338,14 @@ static char *FormatGenericCurrency(char *buff, const CurrencySpec *spec, int64 n
|
|||
number *= spec->rate;
|
||||
|
||||
// convert from negative
|
||||
if (number < 0) { *buff++ = '-'; number = -number; }
|
||||
if (number < 0) {
|
||||
*buff++ = '-';
|
||||
number = -number;
|
||||
}
|
||||
|
||||
// add prefix part
|
||||
s = spec->prefix;
|
||||
while (s != spec->prefix + lengthof(spec->prefix) && (c=*s++)) *buff++ = c;
|
||||
while (s != spec->prefix + lengthof(spec->prefix) && (c = *s++) != '\0') *buff++ = c;
|
||||
|
||||
// for huge numbers, compact the number into k or M
|
||||
if (compact) {
|
||||
|
@ -305,7 +363,10 @@ static char *FormatGenericCurrency(char *buff, const CurrencySpec *spec, int64 n
|
|||
p = buf;
|
||||
j = 4;
|
||||
do {
|
||||
if (--j == 0) { *p++ = spec->separator; j = 3; }
|
||||
if (--j == 0) {
|
||||
*p++ = spec->separator;
|
||||
j = 3;
|
||||
}
|
||||
*p++ = '0' + number % 10;
|
||||
} while (number /= 10);
|
||||
do *buff++ = *--p; while (p != buf);
|
||||
|
@ -314,7 +375,7 @@ static char *FormatGenericCurrency(char *buff, const CurrencySpec *spec, int64 n
|
|||
|
||||
// add suffix part
|
||||
s = spec->suffix;
|
||||
while (s != spec->suffix + lengthof(spec->suffix) && (c=*s++)) *buff++ = c;
|
||||
while (s != spec->suffix + lengthof(spec->suffix) && (c = *s++) != '\0') *buff++ = c;
|
||||
|
||||
return buff;
|
||||
}
|
||||
|
@ -323,7 +384,7 @@ static char *DecodeString(char *buff, const char *str)
|
|||
{
|
||||
byte b;
|
||||
|
||||
while((b = *str++) != 0) {
|
||||
while ((b = *str++) != '\0') {
|
||||
switch (b) {
|
||||
case 0x1: // {SETX}
|
||||
*buff++ = b;
|
||||
|
@ -442,7 +503,7 @@ static char *DecodeString(char *buff, const char *str)
|
|||
Station *st;
|
||||
InjectDParam(1);
|
||||
st = GetStation(GetDParam(1));
|
||||
if (!st->xy) { // station doesn't exist anymore
|
||||
if (st->xy == 0) { // station doesn't exist anymore
|
||||
buff = GetString(buff, STR_UNKNOWN_DESTINATION);
|
||||
break;
|
||||
}
|
||||
|
@ -500,7 +561,7 @@ static char *DecodeString(char *buff, const char *str)
|
|||
*buff++ = b;
|
||||
}
|
||||
}
|
||||
buff[0] = 0;
|
||||
*buff = '\0';
|
||||
return buff;
|
||||
}
|
||||
|
||||
|
@ -508,21 +569,22 @@ static char *DecodeString(char *buff, const char *str)
|
|||
static char *StationGetSpecialString(char *buff)
|
||||
{
|
||||
int x = GetParamInt8();
|
||||
if (x & 1) *buff++ = 0xB4;
|
||||
if (x & 2) *buff++ = 0xB5;
|
||||
if (x & 4) *buff++ = 0xB6;
|
||||
if (x & 8) *buff++ = 0xB7;
|
||||
if (x & 16) *buff++ = 0xB8;
|
||||
*buff = 0;
|
||||
if (x & 0x01) *buff++ = '\xB4';
|
||||
if (x & 0x02) *buff++ = '\xB5';
|
||||
if (x & 0x04) *buff++ = '\xB6';
|
||||
if (x & 0x08) *buff++ = '\xB7';
|
||||
if (x & 0x10) *buff++ = '\xB8';
|
||||
*buff = '\0';
|
||||
return buff;
|
||||
}
|
||||
|
||||
static char *GetSpecialTownNameString(char *buff, int ind) {
|
||||
static char *GetSpecialTownNameString(char *buff, int ind)
|
||||
{
|
||||
uint32 x = GetParamInt32();
|
||||
|
||||
_town_name_generators[ind](buff, x);
|
||||
|
||||
while (*buff != 0) buff++;
|
||||
while (*buff != '\0') buff++;
|
||||
return buff;
|
||||
}
|
||||
|
||||
|
@ -666,7 +728,6 @@ static const char * const _song_names[] = {
|
|||
static char *GetSpecialPlayerNameString(char *buff, int ind)
|
||||
{
|
||||
switch (ind) {
|
||||
|
||||
// not used
|
||||
case 1: {
|
||||
int i = GetParamInt32() & 0xFFFF;
|
||||
|
@ -710,7 +771,6 @@ static char *GetSpecialPlayerNameString(char *buff, int ind)
|
|||
return str_cat(buff, GetScreenshotFormatDesc(i));
|
||||
}
|
||||
|
||||
|
||||
assert(0);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -729,7 +789,8 @@ StringID RemapOldStringID(StringID s)
|
|||
return s;
|
||||
}
|
||||
|
||||
bool ReadLanguagePack(int lang_index) {
|
||||
bool ReadLanguagePack(int lang_index)
|
||||
{
|
||||
int tot_count, i;
|
||||
char *lang_pack;
|
||||
size_t len;
|
||||
|
@ -772,8 +833,8 @@ bool ReadLanguagePack(int lang_index) {
|
|||
s = lang_pack + sizeof(LanguagePackHeader);
|
||||
for (i = 0; i != tot_count; i++) {
|
||||
len = (byte)*s;
|
||||
*s++ = 0; // zero terminate the string before.
|
||||
if (len >= 0xC0) { len = ((len & 0x3F) << 8) + (byte)*s++; }
|
||||
*s++ = '\0'; // zero terminate the string before.
|
||||
if (len >= 0xC0) len = ((len & 0x3F) << 8) + (byte)*s++;
|
||||
langpack_offs[i] = s;
|
||||
s += len;
|
||||
}
|
||||
|
@ -809,7 +870,7 @@ void InitializeLanguagePacks(void)
|
|||
char *s = str_fmt("%s%s", _path.lang_dir, files[i]);
|
||||
in = fopen(s, "rb");
|
||||
free(s);
|
||||
if (!in ||
|
||||
if (in == NULL ||
|
||||
(j = fread(&hdr, sizeof(hdr), 1, in), fclose(in), j) != 1 ||
|
||||
hdr.ident != TO_LE32(LANGUAGE_PACK_IDENT) ||
|
||||
hdr.version != TO_LE32(LANGUAGE_PACK_VERSION)) {
|
||||
|
@ -820,7 +881,7 @@ void InitializeLanguagePacks(void)
|
|||
dl->ent[m].file = files[i];
|
||||
dl->ent[m].name = strdup(hdr.name);
|
||||
|
||||
if (!strcmp(hdr.name, "English")) def = m;
|
||||
if (strcmp(hdr.name, "English") == 0) def = m;
|
||||
|
||||
m++;
|
||||
}
|
||||
|
@ -834,7 +895,7 @@ void InitializeLanguagePacks(void)
|
|||
dl->dropdown[i] = INVALID_STRING_ID;
|
||||
|
||||
for (i = 0; i != dl->num; i++)
|
||||
if (!strcmp(dl->ent[i].file, dl->curr_file)) {
|
||||
if (strcmp(dl->ent[i].file, dl->curr_file) == 0) {
|
||||
def = i;
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue