From 99b68e8f16647cc05bcf50a7408675e3aea37182 Mon Sep 17 00:00:00 2001 From: Magnus Larsen Date: Fri, 3 Jan 2025 22:29:31 -0800 Subject: [PATCH] Move LanguageStrings.cmake to a C Macro --- cmake-scripts/BuildLanguages.cmake | 36 ++-------- cmake-scripts/LanguageStrings.cmake | 77 --------------------- src/resources/generated_languages.h.in | 16 ----- src/resources/languages.h | 94 +++++++++++++++++++++++++- 4 files changed, 99 insertions(+), 124 deletions(-) delete mode 100644 cmake-scripts/LanguageStrings.cmake delete mode 100644 src/resources/generated_languages.h.in diff --git a/cmake-scripts/BuildLanguages.cmake b/cmake-scripts/BuildLanguages.cmake index e69ccee2e..503747c6e 100644 --- a/cmake-scripts/BuildLanguages.cmake +++ b/cmake-scripts/BuildLanguages.cmake @@ -1,39 +1,12 @@ # -# BuildLanguages.cmake has two jobs: -# - it generates src/resources/generated_languages.h from LanguageStrings.cmake, and -# - if option BUILD_LANGUAGES is on, builds the .LNG files from resources/translations/*.TXT +# BuildLanguages.cmake has one job: +# if option BUILD_LANGUAGES is on, builds the .LNG files from resources/translations/*.TXT # -macro(lang_str enum_name) - if(${ARGC} GREATER 1) - set(count "${ARGV1}") - - if(${count} LESS 1) - message(FATAL_ERROR "Cannot add less than 1 of lang_str '${enum_name}'.") - endif() - - string(APPEND LANG_ENUM "\n ${enum_name} = ${Lang_Count},") - string(APPEND LANG_ENUM "\n ${enum_name}_Last = ${Lang_Count} + (${count} - 1),\n") - math(EXPR Lang_Count "${Lang_Count} + ${count}") - else() - string(APPEND LANG_ENUM "\n ${enum_name} = ${Lang_Count},\n") - math(EXPR Lang_Count "${Lang_Count} + 1") - endif() -endmacro() -set(Lang_Count 0) -set(LANG_ENUM "") -include("cmake-scripts/LanguageStrings.cmake") -configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/resources/generated_languages.h.in" "${CMAKE_CURRENT_BINARY_DIR}/src/resources/generated_languages.h") - -message(STATUS "BuildLanguages' Lang_Count: ${Lang_Count}") - - if(NOT BUILD_LANGUAGES) - # early out, having written generated_languages.h return() endif() - if(WIN32) set(LANGUAGE_INSTALL_PATH "openomf/resources/") else() @@ -48,6 +21,9 @@ file(GLOB OPENOMF_LANGS "${LANG_SRC}/*.TXT" ) +file(READ "${LANG_SRC}/langstr_count" Lang_Count) +string(REGEX REPLACE "\n+$" "" Lang_Count "${Lang_Count}") + # generate custom target info set(BUILD_LANG_COMMANDS) set(BUILD_LANG_SOURCES) @@ -59,7 +35,7 @@ foreach(TXT ${OPENOMF_LANGS}) DEPENDS "${TXT}" BYPRODUCTS "${LNG}" COMMAND ${CMAKE_COMMAND} -E echo_append "${LANG}, " - COMMAND "$" --import "${TXT}" --output "${LNG}" --check-count ${Lang_Count} + COMMAND "$" --import "${TXT}" --output "${LNG}" --check-count "${Lang_Count}" ) install(FILES "${LNG}" DESTINATION "${LANGUAGE_INSTALL_PATH}") endforeach() diff --git a/cmake-scripts/LanguageStrings.cmake b/cmake-scripts/LanguageStrings.cmake deleted file mode 100644 index c4ac17b95..000000000 --- a/cmake-scripts/LanguageStrings.cmake +++ /dev/null @@ -1,77 +0,0 @@ -# This file is used by BuildLanguages.cmake to make resources/generated_languages.h - -# lang_str( []) -# The is what's used in the C code to refer to this language string. -# Specifying a allows for a range of lang strs to be added under one name - -# strings from OMF 2097 -lang_str(LangPilot 11) -lang_str(LangPilotDescription 11) -lang_str(LangRobot 11) -lang_str(LangRobotDescription 11) -lang_str(LangArena 5) -lang_str(LangArenaDescription 5) -lang_str(LangPronoun 6) -lang_str(LangNewsroomUnrankedChallengerDialog) -lang_str(LangNewsroomUnrankedChallenger 2) -lang_str(LangNewsroomNewChampion) -lang_str(LangNewsroomReport 48) -lang_str(LangCpuDifficulty 7) -lang_str(LangTooPatheticDialog) -lang_str(LangTooPatheticInsult) -lang_str(LangVsInsult1 121) -lang_str(LangVsInsult2 121) -lang_str(LangPlug 16) -lang_str(LangPilotStatPower) -lang_str(LangPilotStatSpeed) -lang_str(LangPilotStatEndurance) -lang_str(LangChooseYourPilot) -lang_str(LangChooseYourRobot) -lang_str(LangSceneEnd) -lang_str(LangSceneEnd1 10) -lang_str(LangSceneEnd2 10) -lang_str(LangSelectTournament) -lang_str(LangSelectPhotoForChr) -lang_str(LangSelectChrToLoad) -lang_str(LangSelectChrToDelete) -lang_str(LangSelectOpponent) -lang_str(LangTrainingTitle 3) -lang_str(LangTrainingConfirmation 3) -lang_str(LangTrainingHelp 3) -lang_str(LangTrainingDone) -lang_str(LangTradeGainCash) -lang_str(LangTradeSpendCash) -lang_str(LangTradeEquitable) -lang_str(LangButtonSelect) -lang_str(LangTournamentFight) -lang_str(LangEnterTrainingHelp) -lang_str(LangBuyUpgradesHelp) -lang_str(LangSellUpgradesHelp) -lang_str(LangChrLoadHelp) -lang_str(LangChrCreateHelp) -lang_str(LangChrDeleteHelp) -lang_str(LangTournamentSimHelp) -lang_str(LangTournamentQuitHelp) -lang_str(LangTournamentRegisterHelp) -lang_str(LangTournamentDifficulty 4) -lang_str(LangNo) -lang_str(LangYes) -lang_str(LangPromptChrName) -lang_str(LangCustomizeColor1) -lang_str(LangCustomizeColor2) -lang_str(LangCustomizeColor3) -lang_str(LangUpgradePowerSell) -lang_str(LangUpgradePowerBuy) -lang_str(LangUpgradeSpeedSell) -lang_str(LangUpgradeSpeedBuy) -lang_str(LangUpgradeArmorSell) -lang_str(LangUpgradeArmorBuy) -lang_str(LangUpgradeStunResistanceSell) -lang_str(LangUpgradeStunResistanceBuy) -lang_str(LangTradeHelp) -lang_str(LangTradeNoneAvailable) -lang_str(LangTradeAvailable) -lang_str(LangUpgradeQuitSell) -lang_str(LangUpgradeQuitBuy) -# strings new in OpenOMF -lang_str(LangLanguage) diff --git a/src/resources/generated_languages.h.in b/src/resources/generated_languages.h.in deleted file mode 100644 index 3b88fdfa0..000000000 --- a/src/resources/generated_languages.h.in +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef GENERATED_LANGUAGES_H -#define GENERATED_LANGUAGES_H - -/*! \brief OpenOMF String ID - * - * These string IDs are generated by BuildLanguages.cmake from the list in LanguageStrings.cmake, - * and match the generated .LNG files. - */ -enum { -@LANG_ENUM@ - - // Number of strings contained in a .LNG file - Lang_Count = @Lang_Count@ -}; - -#endif // GENERATED_LANGUAGES_H diff --git a/src/resources/languages.h b/src/resources/languages.h index 3747d0fd6..3e959ec54 100644 --- a/src/resources/languages.h +++ b/src/resources/languages.h @@ -1,7 +1,6 @@ #ifndef LANGUAGES_H #define LANGUAGES_H -#include "resources/generated_languages.h" #include /* @@ -31,4 +30,97 @@ const char *lang_get(int id); #define lang_get_offset(LangStr, offset) lang_get_offset_impl(LangStr, LangStr##_Last, (offset)) const char *lang_get_offset_impl(int id, int last, int offset); +#define lang_str(enum_variant) enum_variant +#define lang_str_range(enum_variant, count) enum_variant, enum_variant##_Last = enum_variant + (count - 1) + +/*! \brief OpenOMF String ID + * + * These string IDs are generated by BuildLanguages.cmake from the list in LanguageStrings.cmake, + * and match the generated .LNG files. + */ +enum +{ + // lang_str(), + // lang_str_range(, ), + // The is what's used in the C code to refer to this language string. + // Specifying a allows for a range of lang strs to be added under one name + + // strings from OMF 2097 + lang_str_range(LangPilot, 11), + lang_str_range(LangPilotDescription, 11), + lang_str_range(LangRobot, 11), + lang_str_range(LangRobotDescription, 11), + lang_str_range(LangArena, 5), + lang_str_range(LangArenaDescription, 5), + lang_str_range(LangPronoun, 6), + lang_str(LangNewsroomUnrankedChallengerDialog), + lang_str_range(LangNewsroomUnrankedChallenger, 2), + lang_str(LangNewsroomNewChampion), + lang_str_range(LangNewsroomReport, 48), + lang_str_range(LangCpuDifficulty, 7), + lang_str(LangTooPatheticDialog), + lang_str(LangTooPatheticInsult), + lang_str_range(LangVsInsult1, 121), + lang_str_range(LangVsInsult2, 121), + lang_str_range(LangPlug, 16), + lang_str(LangPilotStatPower), + lang_str(LangPilotStatSpeed), + lang_str(LangPilotStatEndurance), + lang_str(LangChooseYourPilot), + lang_str(LangChooseYourRobot), + lang_str(LangSceneEnd), + lang_str_range(LangSceneEnd1, 10), + lang_str_range(LangSceneEnd2, 10), + lang_str(LangSelectTournament), + lang_str(LangSelectPhotoForChr), + lang_str(LangSelectChrToLoad), + lang_str(LangSelectChrToDelete), + lang_str(LangSelectOpponent), + lang_str_range(LangTrainingTitle, 3), + lang_str_range(LangTrainingConfirmation, 3), + lang_str_range(LangTrainingHelp, 3), + lang_str(LangTrainingDone), + lang_str(LangTradeGainCash), + lang_str(LangTradeSpendCash), + lang_str(LangTradeEquitable), + lang_str(LangButtonSelect), + lang_str(LangTournamentFight), + lang_str(LangEnterTrainingHelp), + lang_str(LangBuyUpgradesHelp), + lang_str(LangSellUpgradesHelp), + lang_str(LangChrLoadHelp), + lang_str(LangChrCreateHelp), + lang_str(LangChrDeleteHelp), + lang_str(LangTournamentSimHelp), + lang_str(LangTournamentQuitHelp), + lang_str(LangTournamentRegisterHelp), + lang_str_range(LangTournamentDifficulty, 4), + lang_str(LangNo), + lang_str(LangYes), + lang_str(LangPromptChrName), + lang_str(LangCustomizeColor1), + lang_str(LangCustomizeColor2), + lang_str(LangCustomizeColor3), + lang_str(LangUpgradePowerSell), + lang_str(LangUpgradePowerBuy), + lang_str(LangUpgradeSpeedSell), + lang_str(LangUpgradeSpeedBuy), + lang_str(LangUpgradeArmorSell), + lang_str(LangUpgradeArmorBuy), + lang_str(LangUpgradeStunResistanceSell), + lang_str(LangUpgradeStunResistanceBuy), + lang_str(LangTradeHelp), + lang_str(LangTradeNoneAvailable), + lang_str(LangTradeAvailable), + lang_str(LangUpgradeQuitSell), + lang_str(LangUpgradeQuitBuy), + // strings new in OpenOMF + lang_str(LangLanguage), + + Lang_Count, +}; + +#undef lang_str +#undef lang_str_range + #endif // LANGUAGES_H