From 69c1e47c332a6f01f3e30f3d792afdc3c73fdf83 Mon Sep 17 00:00:00 2001 From: TimePath Date: Thu, 27 Aug 2015 09:33:56 +1000 Subject: [PATCH] Add translation helpers to /lib --- qcsrc/client/hud.qc | 1 - qcsrc/client/scoreboard.qc | 1 - qcsrc/common/notifications.qc | 1 - qcsrc/common/util.qc | 24 -------------- qcsrc/common/util.qh | 6 ---- qcsrc/{common/counting.qh => lib/Counting.qh} | 2 +- qcsrc/lib/I18N.qh | 32 +++++++++++++++++++ qcsrc/lib/_all.inc | 2 ++ qcsrc/menu/xonotic/statslist.qc | 1 - qcsrc/server/command/common.qc | 1 - qcsrc/server/command/getreplies.qc | 1 - qcsrc/server/mutators/mutators_include.qc | 1 - 12 files changed, 35 insertions(+), 38 deletions(-) rename qcsrc/{common/counting.qh => lib/Counting.qh} (99%) create mode 100644 qcsrc/lib/I18N.qh diff --git a/qcsrc/client/hud.qc b/qcsrc/client/hud.qc index 7125739cf..f623e2706 100644 --- a/qcsrc/client/hud.qc +++ b/qcsrc/client/hud.qc @@ -12,7 +12,6 @@ #include "../common/buffs.qh" #include "../common/constants.qh" -#include "../common/counting.qh" #include "../common/deathtypes.qh" #include "../common/items/all.qc" #include "../common/mapinfo.qh" diff --git a/qcsrc/client/scoreboard.qc b/qcsrc/client/scoreboard.qc index a24b94379..1e2ef0baa 100644 --- a/qcsrc/client/scoreboard.qc +++ b/qcsrc/client/scoreboard.qc @@ -5,7 +5,6 @@ #include "sortlist.qh" #include "../common/constants.qh" -#include "../common/counting.qh" #include "../common/mapinfo.qh" #include "../common/minigames/cl_minigames.qh" #include "../common/stats.qh" diff --git a/qcsrc/common/notifications.qc b/qcsrc/common/notifications.qc index 31f7e864c..2d4691021 100644 --- a/qcsrc/common/notifications.qc +++ b/qcsrc/common/notifications.qc @@ -5,7 +5,6 @@ #include "../dpdefs/dpextensions.qh" #include "constants.qh" #include "teams.qh" - #include "counting.qh" #include "../server/autocvars.qh" #include "../server/constants.qh" #include "../server/defs.qh" diff --git a/qcsrc/common/util.qc b/qcsrc/common/util.qc index c1ae4ad1a..56d64f561 100644 --- a/qcsrc/common/util.qc +++ b/qcsrc/common/util.qc @@ -2245,30 +2245,6 @@ float u8_strsize(string s) return l; } -// translation helpers -string language_filename(string s) -{ - string fn; - float fh; - fn = prvm_language; - if(fn == "" || fn == "dump") - return s; - fn = strcat(s, ".", fn); - if((fh = fopen(fn, FILE_READ)) >= 0) - { - fclose(fh); - return fn; - } - return s; -} -string CTX(string s) -{ - float p = strstrofs(s, "^", 0); - if(p < 0) - return s; - return substring(s, p+1, -1); -} - // x-encoding (encoding as zero length invisible string) const string XENCODE_2 = "xX"; const string XENCODE_22 = "0123456789abcdefABCDEF"; diff --git a/qcsrc/common/util.qh b/qcsrc/common/util.qh index 995d882f6..87aa3351c 100644 --- a/qcsrc/common/util.qh +++ b/qcsrc/common/util.qh @@ -223,12 +223,6 @@ float vercmp(string v1, string v2); float u8_strsize(string s); -// translation helpers -string prvm_language; -string language_filename(string s); -string CTX(string s); -#define ZCTX(s) strzone(CTX(s)) - // x-encoding (encoding as zero length invisible string) // encodes approx. 14 bits into 5 bytes of color code string const float XENCODE_MAX = 21295; // 2*22*22*22-1 diff --git a/qcsrc/common/counting.qh b/qcsrc/lib/Counting.qh similarity index 99% rename from qcsrc/common/counting.qh rename to qcsrc/lib/Counting.qh index f464cdc32..cd0604bf5 100644 --- a/qcsrc/common/counting.qh +++ b/qcsrc/lib/Counting.qh @@ -1,7 +1,7 @@ #ifndef COUNTING_H #define COUNTING_H -#include "util.qh" +#include "I18N.qh" // =============================================== // Time processing and counting functions/macros diff --git a/qcsrc/lib/I18N.qh b/qcsrc/lib/I18N.qh new file mode 100644 index 000000000..ab9aa7d20 --- /dev/null +++ b/qcsrc/lib/I18N.qh @@ -0,0 +1,32 @@ +#ifndef I18N_H +#define I18N_H + +// translation helpers +string prvm_language; + +string language_filename(string s) +{ + string fn = prvm_language; + if (fn == "" || fn == "dump") + return s; + fn = strcat(s, ".", fn); + int fh = fopen(fn, FILE_READ); + if (fh >= 0) + { + fclose(fh); + return fn; + } + return s; +} + +string CTX(string s) +{ + int p = strstrofs(s, "^", 0); + if (p < 0) + return s; + return substring(s, p + 1, -1); +} + +#define ZCTX(s) strzone(CTX(s)) + +#endif diff --git a/qcsrc/lib/_all.inc b/qcsrc/lib/_all.inc index 931bc50b4..410eac721 100644 --- a/qcsrc/lib/_all.inc +++ b/qcsrc/lib/_all.inc @@ -1,5 +1,7 @@ #include "Accumulate.qh" +#include "Counting.qh" #include "Cvar.qh" +#include "I18N.qh" #include "Lazy.qh" #include "Nil.qh" #include "OO.qh" diff --git a/qcsrc/menu/xonotic/statslist.qc b/qcsrc/menu/xonotic/statslist.qc index db42177fb..3c4b09e14 100644 --- a/qcsrc/menu/xonotic/statslist.qc +++ b/qcsrc/menu/xonotic/statslist.qc @@ -1,4 +1,3 @@ -#include "../../common/counting.qh" #include "../../common/playerstats.qh" #ifndef STATSLIST_H diff --git a/qcsrc/server/command/common.qc b/qcsrc/server/command/common.qc index 0bdc6672f..b303f4b33 100644 --- a/qcsrc/server/command/common.qc +++ b/qcsrc/server/command/common.qc @@ -5,7 +5,6 @@ #include "../scores.qh" #include "../../common/notifications.qh" -#include "../../common/counting.qh" // ==================================================== diff --git a/qcsrc/server/command/getreplies.qc b/qcsrc/server/command/getreplies.qc index 543f1db15..1371e8010 100644 --- a/qcsrc/server/command/getreplies.qc +++ b/qcsrc/server/command/getreplies.qc @@ -5,7 +5,6 @@ #include "../race.qh" #include "../../common/constants.qh" -#include "../../common/counting.qh" #include "../../common/mapinfo.qh" #include "../../common/util.qh" diff --git a/qcsrc/server/mutators/mutators_include.qc b/qcsrc/server/mutators/mutators_include.qc index 3129af92f..1286317eb 100644 --- a/qcsrc/server/mutators/mutators_include.qc +++ b/qcsrc/server/mutators/mutators_include.qc @@ -15,7 +15,6 @@ #include "../../common/nades.qh" #include "../../common/buffs.qh" #include "../../common/test.qh" - #include "../../common/counting.qh" #include "../../common/urllib.qh" #include "../../common/command/markup.qh" #include "../../common/command/rpn.qh" -- 2.39.2