From: terencehill Date: Thu, 7 Feb 2019 17:48:12 +0000 (+0100) Subject: Introduce the shared function write_String_To_File that can be used by all the dump... X-Git-Tag: xonotic-v0.8.5~1604^2~9 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=44aa8946945001e43f22bb2ca8c7b725dc8c9513;p=xonotic%2Fxonotic-data.pk3dir.git Introduce the shared function write_String_To_File that can be used by all the dump* commands --- diff --git a/qcsrc/common/effects/effectinfo.qc b/qcsrc/common/effects/effectinfo.qc index 84bc880ba..474d41d1e 100644 --- a/qcsrc/common/effects/effectinfo.qc +++ b/qcsrc/common/effects/effectinfo.qc @@ -263,10 +263,7 @@ void effectinfo_read() void effectinfo_dump(int fh, bool alsoprint) { - #define WRITE(s) MACRO_BEGIN \ - fputs(fh, s); \ - if (alsoprint) LOG_INFO(s); \ - MACRO_END + #define WRITE(str) write_String_To_File(fh, str, alsoprint) WRITE("// ********************************************** //\n"); WRITE("// ** WARNING - DO NOT MANUALLY EDIT THIS FILE ** //\n"); WRITE("// ** ** //\n"); diff --git a/qcsrc/common/notifications/all.qc b/qcsrc/common/notifications/all.qc index 438ff5d22..04fc75e8f 100644 --- a/qcsrc/common/notifications/all.qc +++ b/qcsrc/common/notifications/all.qc @@ -777,10 +777,7 @@ void Notification_GetCvars(entity this) /** used to output notifications.cfg file */ void Dump_Notifications(int fh, bool alsoprint) { - #define NOTIF_WRITE(a) MACRO_BEGIN \ - fputs(fh, a); \ - if (alsoprint) LOG_INFO(a); \ - MACRO_END + #define NOTIF_WRITE(str) write_String_To_File(fh, str, alsoprint) #define NOTIF_WRITE_ENTITY(e, description) MACRO_BEGIN \ string notif_msg = sprintf( \ diff --git a/qcsrc/common/turrets/config.qc b/qcsrc/common/turrets/config.qc index effabeac2..d1a980d76 100644 --- a/qcsrc/common/turrets/config.qc +++ b/qcsrc/common/turrets/config.qc @@ -30,6 +30,7 @@ float T_Config_Queue_Compare(float root, float child, entity pass) void Dump_Turret_Settings() { + #define TUR_CONFIG_WRITETOFILE(str) write_String_To_File(tur_config_file, str, tur_config_alsoprint) int totalsettings = 0; FOREACH(Turrets, it != TUR_Null, { // step 1: clear the queue @@ -44,15 +45,16 @@ void Dump_Turret_Settings() heapsort(TUR_CONFIG_COUNT, T_Config_Queue_Swap, T_Config_Queue_Compare, NULL); // step 4: write queue - TUR_CONFIG_WRITETOFILE(sprintf("// {{{ #%d: %s\n", i, it.turret_name)) + TUR_CONFIG_WRITETOFILE(sprintf("// {{{ #%d: %s\n", i, it.turret_name)); for(int j = 0; j <= TUR_CONFIG_COUNT; ++j) - TUR_CONFIG_WRITETOFILE(config_queue[j]) - TUR_CONFIG_WRITETOFILE("// }}}\n") + TUR_CONFIG_WRITETOFILE(config_queue[j]); + TUR_CONFIG_WRITETOFILE("// }}}\n"); // step 5: debug info LOG_INFOF("#%d: %s: %d settings...", i, it.turret_name, TUR_CONFIG_COUNT); totalsettings += TUR_CONFIG_COUNT; }); + #undef TUR_CONFIG_WRITETOFILE // clear queue now that we're finished TUR_CONFIG_COUNT = 0; diff --git a/qcsrc/common/turrets/config.qh b/qcsrc/common/turrets/config.qh index ac09e9e37..ad9c3846f 100644 --- a/qcsrc/common/turrets/config.qh +++ b/qcsrc/common/turrets/config.qh @@ -7,9 +7,6 @@ float tur_config_file; float tur_config_alsoprint; float TUR_CONFIG_COUNT; -#define TUR_CONFIG_WRITETOFILE(a) { \ - fputs(tur_config_file, a); \ - if(tur_config_alsoprint) { LOG_INFO(a); } } #endif diff --git a/qcsrc/common/util.qc b/qcsrc/common/util.qc index 66cd016c0..74e337f74 100644 --- a/qcsrc/common/util.qc +++ b/qcsrc/common/util.qc @@ -1305,6 +1305,13 @@ float matchacl(string acl, string str) return r; } +ERASEABLE +void write_String_To_File(int fh, string str, bool alsoprint) +{ + fputs(fh, str); + if (alsoprint) LOG_INFO(str); +} + string get_model_datafilename(string m, float sk, string fil) { if(m) diff --git a/qcsrc/common/util.qh b/qcsrc/common/util.qh index a1c0d6785..d0a8ab86a 100644 --- a/qcsrc/common/util.qh +++ b/qcsrc/common/util.qh @@ -135,6 +135,8 @@ string getcurrentmod(); float matchacl(string acl, string str); // matches str against ACL acl (with entries +foo*, +foo, +*foo, +*foo*, and same with - for forbidding) +void write_String_To_File(int fh, string str, bool alsoprint); + string get_model_datafilename(string mod, float skn, string fil); // skin -1 will return wildcard, mod string_null will also put wildcard there string get_model_parameters_modelname; float get_model_parameters_modelskin; diff --git a/qcsrc/common/weapons/config.qc b/qcsrc/common/weapons/config.qc index b53e25fde..bf34d5320 100644 --- a/qcsrc/common/weapons/config.qc +++ b/qcsrc/common/weapons/config.qc @@ -26,6 +26,7 @@ void Dump_Weapon_Settings() { int totalweapons = 0, totalsettings = 0; int wepcount = 1; + #define WEP_CONFIG_WRITETOFILE(str) write_String_To_File(wep_config_file, str, wep_config_alsoprint) FOREACH(Weapons, it != WEP_Null, { if((it.spawnflags & WEP_FLAG_HIDDEN) && (it.spawnflags & WEP_FLAG_MUTATORBLOCKED) && !(it.spawnflags & WEP_FLAG_NORMAL)) continue; // never include the attacks @@ -56,6 +57,7 @@ void Dump_Weapon_Settings() totalsettings += WEP_CONFIG_COUNT; wepcount += 1; }); + #undef WEP_CONFIG_WRITETOFILE // clear queue now that we're finished WEP_CONFIG_COUNT = 0; diff --git a/qcsrc/common/weapons/config.qh b/qcsrc/common/weapons/config.qh index 883082c97..b21bf0170 100644 --- a/qcsrc/common/weapons/config.qh +++ b/qcsrc/common/weapons/config.qh @@ -14,11 +14,6 @@ int WEP_CONFIG_COUNT; config_queue[WEP_CONFIG_COUNT] = a; \ ++WEP_CONFIG_COUNT; } -#define WEP_CONFIG_WRITETOFILE(a) MACRO_BEGIN \ - fputs(wep_config_file, a); \ - if(wep_config_alsoprint) { LOG_INFO(a); } \ -MACRO_END - #define WEP_CONFIG_WRITE_CVARS(wepname, name, T) WEP_CONFIG_WRITE_PROPS_##T(wepname, name)