From 53b160e0116b0236aec1c1086d72354eb8343420 Mon Sep 17 00:00:00 2001 From: rubidium Date: Wed, 17 Oct 2012 18:53:35 +0000 Subject: [PATCH] (svn r24603) [1.2] -Backport from trunk: - Fix: [OSX] Some compile problems in mac-only code [FS#5296] (r24524) - Fix: The gender of an industry name is defined by the industry-type part of the name, not by the town-name part, even if it comes first (r24523, r24522) - Fix: GStexts were compiled incompletely when containing certain string codes (r24516, r24515) - Fix: The mousewheel did not work in the build waypoint window [FS#5285] (r24507) --- src/game/game_text.cpp | 10 ++++------ src/os/macosx/G5_detector.cpp | 2 +- src/rail_gui.cpp | 2 +- src/strgen/strgen.cpp | 7 +------ src/strgen/strgen.h | 2 +- src/strgen/strgen_base.cpp | 11 +++++++++++ src/strings.cpp | 25 ++++++++++++++++--------- src/video/cocoa/cocoa_v.mm | 4 ++-- src/video/cocoa/fullscreen.mm | 2 +- 9 files changed, 38 insertions(+), 27 deletions(-) diff --git a/src/game/game_text.cpp b/src/game/game_text.cpp index 4ffaa9e549..07388c842b 100644 --- a/src/game/game_text.cpp +++ b/src/game/game_text.cpp @@ -147,11 +147,6 @@ struct StringListReader : StringReader { return buffer; } - - /* virtual */ void HandlePragma(char *str) - { - strgen_fatal("unknown pragma '%s'", str); - } }; /** Class for writing an encoded language. */ @@ -183,7 +178,10 @@ struct TranslationWriter : LanguageWriter { void Write(const byte *buffer, size_t length) { - *this->strings->Append() = strndup((const char*)buffer, length); + char *dest = MallocT(length + 1); + memcpy(dest, buffer, length); + dest[length] = '\0'; + *this->strings->Append() = dest; } }; diff --git a/src/os/macosx/G5_detector.cpp b/src/os/macosx/G5_detector.cpp index ad69a2e430..53d21c4d4f 100644 --- a/src/os/macosx/G5_detector.cpp +++ b/src/os/macosx/G5_detector.cpp @@ -21,7 +21,7 @@ #endif /* this function is a lightly modified version of some code from Apple's developer homepage to detect G5 CPUs at runtime */ -main() +int main() { host_basic_info_data_t hostInfo; mach_msg_type_number_t infoCount; diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp index 990812ad82..9f28c2b611 100644 --- a/src/rail_gui.cpp +++ b/src/rail_gui.cpp @@ -1766,7 +1766,7 @@ static const NWidgetPart _nested_build_waypoint_widgets[] = { EndContainer(), NWidget(NWID_HORIZONTAL), NWidget(NWID_MATRIX, COLOUR_DARK_GREEN, WID_BRW_WAYPOINT_MATRIX), SetPIP(3, 2, 3), SetScrollbar(WID_BRW_SCROLL), - NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BRW_WAYPOINT), SetMinimalSize(66, 60), SetDataTip(0x0, STR_WAYPOINT_GRAPHICS_TOOLTIP), EndContainer(), + NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BRW_WAYPOINT), SetMinimalSize(66, 60), SetDataTip(0x0, STR_WAYPOINT_GRAPHICS_TOOLTIP), SetScrollbar(WID_BRW_SCROLL), EndContainer(), EndContainer(), NWidget(NWID_VERTICAL), NWidget(NWID_VSCROLLBAR, COLOUR_DARK_GREEN, WID_BRW_SCROLL), diff --git a/src/strgen/strgen.cpp b/src/strgen/strgen.cpp index a905a599b5..b18d5e02f0 100644 --- a/src/strgen/strgen.cpp +++ b/src/strgen/strgen.cpp @@ -147,11 +147,6 @@ void FileStringReader::HandlePragma(char *str) strecpy(_lang.own_name, str + 8, lastof(_lang.own_name)); } else if (!memcmp(str, "isocode ", 8)) { strecpy(_lang.isocode, str + 8, lastof(_lang.isocode)); - } else if (!memcmp(str, "plural ", 7)) { - _lang.plural_form = atoi(str + 7); - if (_lang.plural_form >= lengthof(_plural_forms)) { - error("Invalid pluralform %d", _lang.plural_form); - } } else if (!memcmp(str, "textdir ", 8)) { if (!memcmp(str + 8, "ltr", 3)) { _lang.text_dir = TD_LTR; @@ -208,7 +203,7 @@ void FileStringReader::HandlePragma(char *str) _lang.num_cases++; } } else { - error("unknown pragma '%s'", str); + StringReader::HandlePragma(str); } } diff --git a/src/strgen/strgen.h b/src/strgen/strgen.h index badfb06f7e..18ea269979 100644 --- a/src/strgen/strgen.h +++ b/src/strgen/strgen.h @@ -81,7 +81,7 @@ struct StringReader { * Handle the pragma of the file. * @param str The pragma string to parse. */ - virtual void HandlePragma(char *str) = 0; + virtual void HandlePragma(char *str); /** * Start parsing the file. diff --git a/src/strgen/strgen_base.cpp b/src/strgen/strgen_base.cpp index 3d0c91d30e..7e4516f612 100644 --- a/src/strgen/strgen_base.cpp +++ b/src/strgen/strgen_base.cpp @@ -783,6 +783,17 @@ void StringReader::HandleString(char *str) } } +void StringReader::HandlePragma(char *str) +{ + if (!memcmp(str, "plural ", 7)) { + _lang.plural_form = atoi(str + 7); + if (_lang.plural_form >= lengthof(_plural_forms)) { + strgen_fatal("Invalid pluralform %d", _lang.plural_form); + } + } else { + strgen_fatal("unknown pragma '%s'", str); + } +} static void rstrip(char *buf) { diff --git a/src/strings.cpp b/src/strings.cpp index 954996d680..181ac83108 100644 --- a/src/strings.cpp +++ b/src/strings.cpp @@ -132,7 +132,7 @@ static char **_langpack_offs; static LanguagePack *_langpack; static uint _langtab_num[TAB_COUNT]; ///< Offset into langpack offs static uint _langtab_start[TAB_COUNT]; ///< Offset into langpack offs -static bool _keep_gender_data = false; ///< Should we retain the gender data in the current string? +static bool _scan_for_gender_data = false; ///< Are we scanning for the gender of the current string? (instead of formatting it) const char *GetStringPtr(StringID string) @@ -880,11 +880,11 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg /* Now do the string formatting. */ char buf[256]; - bool old_kgd = _keep_gender_data; - _keep_gender_data = true; + bool old_sgd = _scan_for_gender_data; + _scan_for_gender_data = true; StringParameters tmp_params(args->GetPointerToOffset(offset), args->num_param - offset, NULL); p = FormatString(buf, input, &tmp_params, lastof(buf)); - _keep_gender_data = old_kgd; + _scan_for_gender_data = old_sgd; *p = '\0'; /* And determine the string. */ @@ -900,7 +900,7 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg /* This sets up the gender for the string. * We just ignore this one. It's used in {G 0 Der Die Das} to determine the case. */ case SCC_GENDER_INDEX: // {GENDER 0} - if (_keep_gender_data) { + if (_scan_for_gender_data) { buff += Utf8Encode(buff, SCC_GENDER_INDEX); *buff++ = *str++; } else { @@ -1314,11 +1314,18 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg const Industry *i = Industry::GetIfValid(args->GetInt32(SCC_INDUSTRY_NAME)); if (i == NULL) break; - /* First print the town name and the industry type name. */ - int64 args_array[2] = {i->town->index, GetIndustrySpec(i->type)->name}; - StringParameters tmp_params(args_array); + if (_scan_for_gender_data) { + /* Gender is defined by the industry type. + * STR_FORMAT_INDUSTRY_NAME may have the town first, so it would result in the gender of the town name */ + StringParameters tmp_params(NULL, 0, NULL); + buff = FormatString(buff, GetStringPtr(GetIndustrySpec(i->type)->name), &tmp_params, last, next_substr_case_index); + } else { + /* First print the town name and the industry type name. */ + int64 args_array[2] = {i->town->index, GetIndustrySpec(i->type)->name}; + StringParameters tmp_params(args_array); - buff = FormatString(buff, GetStringPtr(STR_FORMAT_INDUSTRY_NAME), &tmp_params, last, next_substr_case_index); + buff = FormatString(buff, GetStringPtr(STR_FORMAT_INDUSTRY_NAME), &tmp_params, last, next_substr_case_index); + } next_substr_case_index = 0; break; } diff --git a/src/video/cocoa/cocoa_v.mm b/src/video/cocoa/cocoa_v.mm index 3b85f9e8b7..9045f32624 100644 --- a/src/video/cocoa/cocoa_v.mm +++ b/src/video/cocoa/cocoa_v.mm @@ -241,7 +241,7 @@ static CocoaSubdriver *QZ_CreateWindowSubdriver(int width, int height, int bpp) CocoaSubdriver *ret; #endif -#ifdef ENABLE_COCOA_QUARTZ && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4) +#if defined(ENABLE_COCOA_QUARTZ) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4) /* The reason for the version mismatch is due to the fact that the 10.4 binary needs to work on 10.5 as well. */ if (MacOSVersionIsAtLeast(10, 5, 0)) { ret = QZ_CreateWindowQuartzSubdriver(width, height, bpp); @@ -254,7 +254,7 @@ static CocoaSubdriver *QZ_CreateWindowSubdriver(int width, int height, int bpp) if (ret != NULL) return ret; #endif -#ifdef ENABLE_COCOA_QUARTZ && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4) +#if defined(ENABLE_COCOA_QUARTZ) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4) /* * If we get here we are running 10.4 or earlier and either openttd was compiled without the QuickDraw driver * or it failed to load for some reason. Fall back to Quartz if possible even though that driver is slower. diff --git a/src/video/cocoa/fullscreen.mm b/src/video/cocoa/fullscreen.mm index bd55852c36..c8148edfc9 100644 --- a/src/video/cocoa/fullscreen.mm +++ b/src/video/cocoa/fullscreen.mm @@ -65,7 +65,7 @@ struct OTTD_QuartzGammaTable { @end @implementation NSScreen (NSScreenAccess) -- (void) setFrame:(NSRect)frame; +- (void) setFrame:(NSRect)frame { /* The 64 bits libraries don't seem to know about _frame, so this hack won't work. */ #if !__LP64__