============ Cvar_Toggle_f Toggles a cvar for easy single key binding, optionally through a list of given values ============ */
| 853 | ============ |
| 854 | */ |
| 855 | void Cvar_Toggle_f( void ) { |
| 856 | int i, c = Cmd_Argc(); |
| 857 | char *curval; |
| 858 | |
| 859 | if(c < 2) { |
| 860 | Com_Printf("usage: toggle <variable> [value1, value2, ...]\n"); |
| 861 | return; |
| 862 | } |
| 863 | |
| 864 | if(c == 2) { |
| 865 | Cvar_Set2(Cmd_Argv(1), va("%d", |
| 866 | !Cvar_VariableValue(Cmd_Argv(1))), |
| 867 | qfalse); |
| 868 | return; |
| 869 | } |
| 870 | |
| 871 | if(c == 3) { |
| 872 | Com_Printf("toggle: nothing to toggle to\n"); |
| 873 | return; |
| 874 | } |
| 875 | |
| 876 | curval = Cvar_VariableString(Cmd_Argv(1)); |
| 877 | |
| 878 | // don't bother checking the last arg for a match since the desired |
| 879 | // behaviour is the same as no match (set to the first argument) |
| 880 | for(i = 2; i + 1 < c; i++) { |
| 881 | if(strcmp(curval, Cmd_Argv(i)) == 0) { |
| 882 | Cvar_Set2(Cmd_Argv(1), Cmd_Argv(i + 1), qfalse); |
| 883 | return; |
| 884 | } |
| 885 | } |
| 886 | |
| 887 | // fallback |
| 888 | Cvar_Set2(Cmd_Argv(1), Cmd_Argv(2), qfalse); |
| 889 | } |
| 890 | |
| 891 | /* |
| 892 | ============ |
nothing calls this directly
no test coverage detected