From: Mario Date: Thu, 13 Jul 2017 02:49:06 +0000 (+1000) Subject: Make use of modern lib to clean up the addtolist and removefromlist commands, also... X-Git-Tag: xonotic-v0.8.5~2556^2 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=03fc8036fe84543daae626985b548bdef4613563;p=xonotic%2Fxonotic-data.pk3dir.git Make use of modern lib to clean up the addtolist and removefromlist commands, also add the new item to the end of the list rather than the start (sanity) --- diff --git a/qcsrc/common/command/generic.qc b/qcsrc/common/command/generic.qc index 49a9d1309..a9abd9886 100644 --- a/qcsrc/common/command/generic.qc +++ b/qcsrc/common/command/generic.qc @@ -74,13 +74,12 @@ void GenericCommand_addtolist(float request, float argc) } else // add it to the end of the list if the list doesn't already have it { - argc = tokenizebyseparator(cvar_string(original_cvar), " "); - int i; - for(i = 0; i < argc; ++i) - if(argv(i) == tmp_string) - return; // already in list + FOREACH_WORD(cvar_string(original_cvar), it == tmp_string, + { + return; // already in the list + }); - cvar_set(original_cvar, strcat(tmp_string, " ", cvar_string(original_cvar))); + cvar_set(original_cvar, cons(cvar_string(original_cvar), tmp_string)); } return; } @@ -336,19 +335,15 @@ void GenericCommand_removefromlist(float request, float argc) { if(argc == 3) { - float i; string original_cvar = argv(1); string removal = argv(2); - string tmp_string; - argc = tokenizebyseparator(cvar_string(original_cvar), " "); - - tmp_string = ""; - for(i = 0; i < argc; ++i) - if(argv(i) != removal) - tmp_string = strcat(tmp_string, " ", argv(i)); + string tmp_string = ""; + FOREACH_WORD(cvar_string(original_cvar), it != removal, + { + tmp_string = cons(tmp_string, it); + }); - tmp_string = substring(tmp_string, 1, strlen(tmp_string) - 1); cvar_set(original_cvar, tmp_string); return;