feat(radio): sort global/special function names (#5429)
Co-authored-by: Peter Feerick <peter.feerick@gmail.com>
This commit is contained in:
@@ -0,0 +1,151 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <locale>
|
||||
|
||||
#define CFN_ONLY
|
||||
#define SKIP
|
||||
#include "../radio/src/dataconstants.h"
|
||||
|
||||
#define LCD_W 480
|
||||
#define TR(a,b) b
|
||||
#define TR3(a, b, c) c
|
||||
|
||||
#if defined(LNG_CN)
|
||||
#include "../radio/src/translations/cn.h"
|
||||
#define LOC "zh_CN.UTF-8"
|
||||
#elif defined(LNG_CZ)
|
||||
#include "../radio/src/translations/cz.h"
|
||||
#define LOC "cs_CZ.UTF-8"
|
||||
#elif defined(LNG_DA)
|
||||
#include "../radio/src/translations/da.h"
|
||||
#define LOC "da_DK.UTF-8"
|
||||
#elif defined(LNG_DE)
|
||||
#include "../radio/src/translations/de.h"
|
||||
#define LOC "de_DE.UTF-8"
|
||||
#elif defined(LNG_EN)
|
||||
#include "../radio/src/translations/en.h"
|
||||
#define LOC "en_US.UTF-8"
|
||||
#elif defined(LNG_ES)
|
||||
#include "../radio/src/translations/es.h"
|
||||
#define LOC "es_ES.UTF-8"
|
||||
#elif defined(LNG_FI)
|
||||
#include "../radio/src/translations/fi.h"
|
||||
#define LOC "fi_FI.UTF-8"
|
||||
#elif defined(LNG_FR)
|
||||
#include "../radio/src/translations/fr.h"
|
||||
#define LOC "fr_FR.UTF-8"
|
||||
#elif defined(LNG_HE)
|
||||
#include "../radio/src/translations/he.h"
|
||||
#define LOC "he_IL.UTF-8"
|
||||
#elif defined(LNG_IT)
|
||||
#include "../radio/src/translations/it.h"
|
||||
#define LOC "it_IT.UTF-8"
|
||||
#elif defined(LNG_JP)
|
||||
#include "../radio/src/translations/jp.h"
|
||||
#define LOC "ja_JP.UTF-8"
|
||||
#elif defined(LNG_NL)
|
||||
#include "../radio/src/translations/nl.h"
|
||||
#define LOC "nl_NL.UTF-8"
|
||||
#elif defined(LNG_PL)
|
||||
#include "../radio/src/translations/pl.h"
|
||||
#define LOC "pl_PL.UTF-8"
|
||||
#elif defined(LNG_PT)
|
||||
#include "../radio/src/translations/pt.h"
|
||||
#define LOC "pt_PT.UTF-8"
|
||||
#elif defined(LNG_RU)
|
||||
#include "../radio/src/translations/ru.h"
|
||||
#define LOC "ru_RU.UTF-8"
|
||||
#elif defined(LNG_SE)
|
||||
#include "../radio/src/translations/se.h"
|
||||
#define LOC "sv_SE.UTF-8"
|
||||
#elif defined(LNG_TW)
|
||||
#include "../radio/src/translations/tw.h"
|
||||
#define LOC "zh_TW.UTF-8"
|
||||
#elif defined(LNG_UA)
|
||||
#include "../radio/src/translations/ua.h"
|
||||
#define LOC "uk_UA.UTF-8"
|
||||
#else
|
||||
#error "Unknown language"
|
||||
#endif
|
||||
|
||||
struct cfn {
|
||||
std::string str;
|
||||
std::string nam;
|
||||
Functions func;
|
||||
};
|
||||
|
||||
struct LocaleComparator {
|
||||
std::locale locale;
|
||||
|
||||
LocaleComparator(const std::locale& loc) : locale(loc) {}
|
||||
|
||||
bool operator()(const struct cfn& lhs, const struct cfn& rhs) const {
|
||||
return std::use_facet< std::collate<char> >(locale).compare(
|
||||
lhs.str.data(), lhs.str.data() + lhs.str.size(),
|
||||
rhs.str.data(), rhs.str.data() + rhs.str.size()) < 0;
|
||||
}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
#if defined(LOC)
|
||||
std::vector<struct cfn> list = {
|
||||
{ TR_SF_SAFETY, "FUNC_OVERRIDE_CHANNEL", FUNC_OVERRIDE_CHANNEL },
|
||||
{ TR_SF_TRAINER, "FUNC_TRAINER", FUNC_TRAINER },
|
||||
{ TR_SF_INST_TRIM, "FUNC_INSTANT_TRIM", FUNC_INSTANT_TRIM },
|
||||
{ TR_SF_RESET, "FUNC_RESET", FUNC_RESET },
|
||||
{ TR_SF_SET_TIMER, "FUNC_SET_TIMER", FUNC_SET_TIMER },
|
||||
{ TR_ADJUST_GVAR, "FUNC_ADJUST_GVAR", FUNC_ADJUST_GVAR },
|
||||
{ TR_SF_VOLUME, "FUNC_VOLUME", FUNC_VOLUME },
|
||||
{ TR_SF_FAILSAFE, "FUNC_SET_FAILSAFE", FUNC_SET_FAILSAFE },
|
||||
{ TR_SF_RANGE_CHECK, "FUNC_RANGECHECK", FUNC_RANGECHECK },
|
||||
{ TR_SF_MOD_BIND, "FUNC_BIND", FUNC_BIND },
|
||||
{ TR_SOUND, "FUNC_PLAY_SOUND", FUNC_PLAY_SOUND },
|
||||
{ TR_PLAY_TRACK, "FUNC_PLAY_TRACK", FUNC_PLAY_TRACK },
|
||||
{ TR_PLAY_VALUE, "FUNC_PLAY_VALUE", FUNC_PLAY_VALUE },
|
||||
{ TR_SF_PLAY_SCRIPT, "FUNC_PLAY_SCRIPT", FUNC_PLAY_SCRIPT },
|
||||
{ TR_SF_BG_MUSIC, "FUNC_BACKGND_MUSIC", FUNC_BACKGND_MUSIC },
|
||||
{ TR_SF_BG_MUSIC_PAUSE, "FUNC_BACKGND_MUSIC_PAUSE", FUNC_BACKGND_MUSIC_PAUSE },
|
||||
{ TR_SF_VARIO, "FUNC_VARIO", FUNC_VARIO },
|
||||
{ TR_SF_HAPTIC, "FUNC_HAPTIC", FUNC_HAPTIC },
|
||||
{ TR_SF_LOGS, "FUNC_LOGS", FUNC_LOGS },
|
||||
{ TR_BRIGHTNESS, "FUNC_BACKLIGHT", FUNC_BACKLIGHT },
|
||||
{ TR_SF_BACKLIGHT, "FUNC_BACKLIGHT", FUNC_BACKLIGHT },
|
||||
{ TR_SF_SCREENSHOT, "FUNC_SCREENSHOT", FUNC_SCREENSHOT },
|
||||
{ TR_SF_RACING_MODE, "FUNC_RACING_MODE", FUNC_RACING_MODE },
|
||||
{ TR_SF_DISABLE_TOUCH, "FUNC_DISABLE_TOUCH", FUNC_DISABLE_TOUCH },
|
||||
{ TR_SF_SET_SCREEN, "FUNC_SET_SCREEN", FUNC_SET_SCREEN },
|
||||
{ TR_SF_DISABLE_AUDIO_AMP, "FUNC_DISABLE_AUDIO_AMP", FUNC_DISABLE_AUDIO_AMP },
|
||||
{ TR_SF_RGBLEDS, "FUNC_RGB_LED", FUNC_RGB_LED },
|
||||
{ TR_SF_LCD_TO_VIDEO, "FUNC_LCD_TO_VIDEO", FUNC_LCD_TO_VIDEO },
|
||||
{ TR_SF_TEST, "FUNC_TEST", FUNC_TEST },
|
||||
};
|
||||
|
||||
std::locale locale(LOC);
|
||||
std::sort(list.begin(), list.end(), LocaleComparator(locale));
|
||||
|
||||
for (int i = 0; i < list.size(); i += 1) {
|
||||
if (strcmp(TR_BRIGHTNESS, TR_SF_BACKLIGHT) != 0) {
|
||||
if (list[i].str == TR_BRIGHTNESS) {
|
||||
printf("#if defined(OLED_SCREEN)\n");
|
||||
} else if (list[i].str == TR_SF_BACKLIGHT) {
|
||||
printf("#if !defined(OLED_SCREEN)\n");
|
||||
}
|
||||
}
|
||||
printf(" /* %s */ %s,\n", list[i].str.c_str(), list[i].nam.c_str());
|
||||
if (strcmp(TR_BRIGHTNESS, TR_SF_BACKLIGHT) != 0) {
|
||||
if (list[i].str == TR_BRIGHTNESS || list[i].str == TR_SF_BACKLIGHT) {
|
||||
printf("#endif\n");
|
||||
}
|
||||
} else if (list[i].str == TR_BRIGHTNESS) {
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
#else
|
||||
static_assert(false,"No valid language defined!");
|
||||
#endif
|
||||
}
|
||||
Executable
+113
@@ -0,0 +1,113 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
# set -x
|
||||
|
||||
# Required locales (check your system and install if needed):
|
||||
|
||||
# zh_CN.UTF-8 / zh_CN.utf8
|
||||
# cs_CZ.UTF-8 / cs_CZ.utf8
|
||||
# da_DK.UTF-8 / da_DK.utf8
|
||||
# de_DE.UTF-8 / de_DE.utf8
|
||||
# es_ES.UTF-8 / es_ES.utf8
|
||||
# en_US.UTF-8 / en_US.utf8
|
||||
# fi_FI.UTF-8 / fi_FI.utf8
|
||||
# fr_FR.UTF-8 / fr_FR.utf8
|
||||
# he_IL.UTF-8 / he_IL.utf8
|
||||
# it_IT.UTF-8 / it_IT.utf8
|
||||
# ja_JP.UTF-8 / ja_JP.utf8
|
||||
# nl_NL.UTF-8 / nl_NL.utf8
|
||||
# pl_PL.UTF-8 / pl_PL.utf8
|
||||
# pt_PT.UTF-8 / pt_PT.utf8
|
||||
# ru_RU.UTF-8 / ru_RU.utf8
|
||||
# sv_SE.UTF-8 / sv_SE.utf8
|
||||
# zh_TW.UTF-8 / zh_TW.utf8
|
||||
# uk_UA.UTF-8 / uk_UA.utf8
|
||||
|
||||
# Determine the compiler to use
|
||||
if command -v g++ >/dev/null 2>&1; then
|
||||
CXX=g++
|
||||
elif command -v gcc >/dev/null 2>&1; then
|
||||
CXX=gcc
|
||||
elif command -v clang++ >/dev/null 2>&1; then
|
||||
CXX=clang++
|
||||
else
|
||||
echo "Neither g++, gcc nor clang++ found. Please install a C++ compiler."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Compile specified translation macro, append to cfn_sort.cpp
|
||||
compile_and_append() {
|
||||
local lng_macro=$1
|
||||
local translation_macro=$2
|
||||
local condition=$3
|
||||
|
||||
echo "Compiling ${translation_macro} (${lng_macro}) ..."
|
||||
|
||||
$CXX -std=c++11 -lstdc++ -Wfatal-errors -D${lng_macro} tools/cfn_sorter.cpp
|
||||
{
|
||||
if [ "$condition" = "else" ]; then
|
||||
echo "#${condition}"
|
||||
else
|
||||
echo "#${condition} defined(${translation_macro})"
|
||||
fi
|
||||
./a.out
|
||||
} >> radio/src/cfn_sort.cpp
|
||||
}
|
||||
|
||||
rm radio/src/cfn_sort.cpp
|
||||
|
||||
# Copyright header
|
||||
cat tools/copyright-header.txt > radio/src/cfn_sort.cpp
|
||||
|
||||
# Start of cfn_sort.cpp
|
||||
echo "Compiling TRANSLATIONS_CN (LNG_CN) ..."
|
||||
$CXX -std=c++11 -lstdc++ -Wfatal-errors -DLNG_CN tools/cfn_sorter.cpp
|
||||
{
|
||||
cat <<EOF >> radio/src/cfn_sort.cpp
|
||||
// This file is auto-generated via cfn_sorter.sh. Do not edit.
|
||||
|
||||
#include "dataconstants.h"
|
||||
|
||||
Functions cfn_sorted[] = {
|
||||
#if defined(TRANSLATIONS_CN)
|
||||
EOF
|
||||
./a.out
|
||||
} >> radio/src/cfn_sort.cpp
|
||||
|
||||
# Languages
|
||||
compile_and_append "LNG_CZ" "TRANSLATIONS_CZ" "elif"
|
||||
compile_and_append "LNG_DA" "TRANSLATIONS_DA" "elif"
|
||||
compile_and_append "LNG_DE" "TRANSLATIONS_DE" "elif"
|
||||
compile_and_append "LNG_ES" "TRANSLATIONS_ES" "elif"
|
||||
compile_and_append "LNG_FI" "TRANSLATIONS_FI" "elif"
|
||||
compile_and_append "LNG_FR" "TRANSLATIONS_FR" "elif"
|
||||
compile_and_append "LNG_HE" "TRANSLATIONS_HE" "elif"
|
||||
compile_and_append "LNG_IT" "TRANSLATIONS_IT" "elif"
|
||||
compile_and_append "LNG_JP" "TRANSLATIONS_JP" "elif"
|
||||
compile_and_append "LNG_NL" "TRANSLATIONS_NL" "elif"
|
||||
compile_and_append "LNG_PL" "TRANSLATIONS_PL" "elif"
|
||||
compile_and_append "LNG_PT" "TRANSLATIONS_PT" "elif"
|
||||
compile_and_append "LNG_RU" "TRANSLATIONS_RU" "elif"
|
||||
compile_and_append "LNG_SE" "TRANSLATIONS_SE" "elif"
|
||||
compile_and_append "LNG_TW" "TRANSLATIONS_TW" "elif"
|
||||
compile_and_append "LNG_UA" "TRANSLATIONS_UA" "elif"
|
||||
|
||||
# Final else case
|
||||
compile_and_append "LNG_EN" "TRANSLATIONS_EN" "else"
|
||||
|
||||
# End of cfn_sort.cpp
|
||||
cat <<EOF >> radio/src/cfn_sort.cpp
|
||||
#endif
|
||||
};
|
||||
|
||||
uint8_t getFuncSortIdx(uint8_t func)
|
||||
{
|
||||
for (uint8_t i = 0; i < FUNC_MAX; i += 1)
|
||||
if (cfn_sorted[i] == func)
|
||||
return i;
|
||||
return 0;
|
||||
}
|
||||
EOF
|
||||
|
||||
[ -f ./a.out ] && rm ./a.out
|
||||
Reference in New Issue
Block a user