Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
cvar.qh File Reference
#include "nil.qh"
#include "progname.qh"
#include "static.qh"
Include dependency graph for cvar.qh:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define __AUTOCVAR(file, archive, var, type, desc, default)
#define _AUTOCVAR(...)
#define AUTOCVAR(...)
#define AUTOCVAR_5(file, archive, var, type, desc)
#define AUTOCVAR_6(file, archive, var, type, default, desc)
#define AUTOCVAR_SAVE(...)
#define BINOP(op, len, expr)
#define EVAL__AUTOCVAR(...)
#define repr_cvar_bool(x)
#define repr_cvar_float(x)
#define repr_cvar_int(x)
#define repr_cvar_string(x)
#define repr_cvar_vector(x)
#define X(expr)

Functions

ERASEABLE bool cvar_value_issafe (string s)
ERASEABLE bool expr_evaluate (string s)
 Evaluate an expression of the form: [+ | -]?
ERASEABLE string MakeConsoleSafe (string input)
 Escape the string to make it safe for consoles.
ERASEABLE void RegisterCvars (void(string name, string def, string desc, bool archive, string file) f)
ERASEABLE void RegisterCvars_Save (string name, string def, string desc, bool archive, string file)
ERASEABLE void RegisterCvars_Set (string name, string def, string desc, bool archive, string file)
 STATIC_INIT_LATE (Cvars)

Variables

const noref bool default_bool = false
const noref float default_float = 0
const noref int default_int = 0
const noref string default_string = ""
const noref vector default_vector = '0 0 0'
int RegisterCvars_Save_fd

Macro Definition Documentation

◆ __AUTOCVAR

#define __AUTOCVAR ( file,
archive,
var,
type,
desc,
default )
Value:
ACCUMULATE void RegisterCvars(void(string, string, string, bool, string) f) \
{ \
f( #var, repr_cvar_##type(default), desc, archive, file); \
} \
type autocvar_##var = default
ERASEABLE void RegisterCvars(void(string name, string def, string desc, bool archive, string file) f)
Definition cvar.qh:8
#define ACCUMULATE
Definition _all.inc:31

Definition at line 151 of file cvar.qh.

151#define __AUTOCVAR(file, archive, var, type, desc, default) \
152 ACCUMULATE void RegisterCvars(void(string, string, string, bool, string) f) \
153 { \
154 f( #var, repr_cvar_##type(default), desc, archive, file); \
155 } \
156 type autocvar_##var = default

◆ _AUTOCVAR

#define _AUTOCVAR ( ...)
Value:
EVAL__AUTOCVAR(OVERLOAD(AUTOCVAR, __FILE__, __VA_ARGS__))
#define AUTOCVAR(...)
Definition cvar.qh:164
#define EVAL__AUTOCVAR(...)
Definition cvar.qh:162
#define OVERLOAD(F,...)
Definition misc.qh:12

Definition at line 161 of file cvar.qh.

◆ AUTOCVAR

#define AUTOCVAR ( ...)
Value:
_AUTOCVAR(false, __VA_ARGS__)
#define _AUTOCVAR(...)
Definition cvar.qh:161

Definition at line 164 of file cvar.qh.

◆ AUTOCVAR_5

#define AUTOCVAR_5 ( file,
archive,
var,
type,
desc )
Value:
__AUTOCVAR(file, archive, var, type, desc, default_##type)
#define __AUTOCVAR(file, archive, var, type, desc, default)
Definition cvar.qh:151

Definition at line 157 of file cvar.qh.

157#define AUTOCVAR_5(file, archive, var, type, desc) \
158 __AUTOCVAR(file, archive, var, type, desc, default_##type)

◆ AUTOCVAR_6

#define AUTOCVAR_6 ( file,
archive,
var,
type,
default,
desc )
Value:
__AUTOCVAR(file, archive, var, type, desc, default)

Definition at line 159 of file cvar.qh.

159#define AUTOCVAR_6(file, archive, var, type, default, desc) \
160 __AUTOCVAR(file, archive, var, type, desc, default)

◆ AUTOCVAR_SAVE

#define AUTOCVAR_SAVE ( ...)
Value:
_AUTOCVAR(true, __VA_ARGS__)

Definition at line 163 of file cvar.qh.

◆ BINOP

#define BINOP ( op,
len,
expr )
Value:
if ((o = strstrofs(s, op, 0)) >= 0) \
{ \
k = substring(s, 0, o); \
v = substring(s, o + len, -1); \
X(expr); \
}
#define strstrofs
string substring(string s, float start, float length)

Referenced by expr_evaluate().

◆ EVAL__AUTOCVAR

#define EVAL__AUTOCVAR ( ...)
Value:
__VA_ARGS__

Definition at line 162 of file cvar.qh.

◆ repr_cvar_bool

#define repr_cvar_bool ( x)
Value:
((x) ? "1" : "0")
v x
Definition ent_cs.qc:146

Definition at line 139 of file cvar.qh.

◆ repr_cvar_float

#define repr_cvar_float ( x)
Value:
(ftos(x))
string ftos(float f)

Definition at line 141 of file cvar.qh.

◆ repr_cvar_int

#define repr_cvar_int ( x)
Value:
(itos(x))
#define itos(i)
Definition int.qh:6

Definition at line 140 of file cvar.qh.

◆ repr_cvar_string

#define repr_cvar_string ( x)
Value:
(x)

Definition at line 142 of file cvar.qh.

◆ repr_cvar_vector

#define repr_cvar_vector ( x)
Value:
(sprintf("%v", x))

Definition at line 143 of file cvar.qh.

◆ X

#define X ( expr)
Value:
if (expr) \
continue; \
expr_fail = true; \
break

Referenced by expr_evaluate().

Function Documentation

◆ cvar_value_issafe()

ERASEABLE bool cvar_value_issafe ( string s)

Definition at line 11 of file cvar.qh.

12{
13 if (strstrofs(s, "\"", 0) >= 0) return false;
14 if (strstrofs(s, "\\", 0) >= 0) return false;
15 if (strstrofs(s, ";", 0) >= 0) return false;
16 if (strstrofs(s, "$", 0) >= 0) return false;
17 if (strstrofs(s, "\r", 0) >= 0) return false;
18 if (strstrofs(s, "\n", 0) >= 0) return false;
19 return true;
20}

References strstrofs.

Referenced by _MapInfo_Parse_Settemp(), InitGameplayMode(), MapInfo_Get_ByName_NoFallbacks(), and spawnfunc().

◆ expr_evaluate()

ERASEABLE bool expr_evaluate ( string s)

Evaluate an expression of the form: [+ | -]?

[var[op]val | [op]var | val | var] ... +: all must match. this is the default -: one must NOT match

var>x var<x var>=x var<=x var==x var!=x var===x var!==x

Definition at line 48 of file cvar.qh.

49{
50 bool ret = false;
51 if (str2chr(s, 0) == '+')
52 s = substring(s, 1, -1);
53 else if (str2chr(s, 0) == '-')
54 {
55 ret = true;
56 s = substring(s, 1, -1);
57 }
58 bool expr_fail = false;
59 for (int i = 0, n = tokenize_console(s); i < n; ++i)
60 {
61 int o;
62 string k, v;
63 s = argv(i);
64 #define X(expr) \
65 if (expr) \
66 continue; \
67 expr_fail = true; \
68 break
69
70 #define BINOP(op, len, expr) \
71 if ((o = strstrofs(s, op, 0)) >= 0) \
72 { \
73 k = substring(s, 0, o); \
74 v = substring(s, o + len, -1); \
75 X(expr); \
76 }
77 BINOP(">=", 2, cvar(k) >= stof(v))
78 BINOP("<=", 2, cvar(k) <= stof(v))
79 BINOP(">", 1, cvar(k) > stof(v))
80 BINOP("<", 1, cvar(k) < stof(v))
81 BINOP("==", 2, cvar(k) == stof(v))
82 BINOP("!=", 2, cvar(k) != stof(v))
83 BINOP("===", 3, cvar_string(k) == v)
84 BINOP("!==", 3, cvar_string(k) != v)
85 {
86 k = s;
87 bool b = true;
88 if (str2chr(k, 0) == '!')
89 {
90 k = substring(s, 1, -1);
91 b = false;
92 }
93 float f = stof(k);
94 X(boolean((ftos(f) == k) ? f : cvar(k)) == b);
95 }
96 #undef BINOP
97 #undef X
98 }
99 if (!expr_fail)
100 ret = !ret;
101 // now ret is true if we want to keep the item, and false if we want to get rid of it
102 return ret;
103}
#define BINOP(op, len, expr)
#define X(expr)
#define str2chr
#define tokenize_console
float stof(string val,...)
float cvar(string name)
const string cvar_string(string name)
string argv(float n)

References argv(), BINOP, cvar(), cvar_string(), ftos(), stof(), str2chr, substring(), tokenize_console, and X.

Referenced by SV_OnEntityPreSpawnFunction().

◆ MakeConsoleSafe()

ERASEABLE string MakeConsoleSafe ( string input)

Escape the string to make it safe for consoles.

Definition at line 24 of file cvar.qh.

25{
26 input = strreplace("\n", "", input);
27 input = strreplace("\\", "\\\\", input);
28 input = strreplace("$", "$$", input);
29 input = strreplace("\"", "\\\"", input);
30 return input;
31}

Referenced by GameCommand_adminmsg(), Local_Notification(), Local_Notification_centerprint_Add(), Local_Notification_HUD_Notify_Push(), Local_Notification_sprintf(), net_handle_ServerWelcome(), RegisterCvars_Set(), Send_Notification(), Send_Notification_Core(), and Welcome_Message_Show_Try().

◆ RegisterCvars()

ERASEABLE void RegisterCvars ( void(string name, string def, string desc, bool archive, string file) f)

Definition at line 8 of file cvar.qh.

8{}

References name.

Referenced by STATIC_INIT_LATE().

◆ RegisterCvars_Save()

ERASEABLE void RegisterCvars_Save ( string name,
string def,
string desc,
bool archive,
string file )

Definition at line 115 of file cvar.qh.

116{
117 if (!archive)
118 return;
119 fputs(RegisterCvars_Save_fd, sprintf("seta %s \"%s\"\n", name, def));
120}
int RegisterCvars_Save_fd
Definition cvar.qh:113
string name
Definition menu.qh:30
void fputs(float fhandle, string s)

References fputs(), name, and RegisterCvars_Save_fd.

Referenced by STATIC_INIT_LATE().

◆ RegisterCvars_Set()

ERASEABLE void RegisterCvars_Set ( string name,
string def,
string desc,
bool archive,
string file )

Definition at line 106 of file cvar.qh.

107{
108 localcmd(sprintf("\nset %1$s \"$%1$s\" \"%2$s\"\n", name, MakeConsoleSafe(desc)));
109 if (archive)
110 localcmd(sprintf("\nseta %1$s \"$%1$s\"\n", name));
111}
ERASEABLE string MakeConsoleSafe(string input)
Escape the string to make it safe for consoles.
Definition cvar.qh:24
void localcmd(string command,...)

References localcmd(), MakeConsoleSafe(), and name.

Referenced by STATIC_INIT_LATE().

◆ STATIC_INIT_LATE()

STATIC_INIT_LATE ( Cvars )

Definition at line 122 of file cvar.qh.

123{
125 RegisterCvars_Save_fd = fopen(sprintf("default%s.cfg", PROGNAME), FILE_WRITE);
126 if (RegisterCvars_Save_fd >= 0)
127 {
130 }
131}
const float FILE_WRITE
ERASEABLE void RegisterCvars_Save(string name, string def, string desc, bool archive, string file)
Definition cvar.qh:115
ERASEABLE void RegisterCvars_Set(string name, string def, string desc, bool archive, string file)
Definition cvar.qh:106
void fclose(float fhandle)
float fopen(string filename, float mode)
#define PROGNAME
Definition progname.qh:4

References fclose(), FILE_WRITE, fopen(), PROGNAME, RegisterCvars(), RegisterCvars_Save(), RegisterCvars_Save_fd, and RegisterCvars_Set().

Variable Documentation

◆ default_bool

const noref bool default_bool = false

Definition at line 133 of file cvar.qh.

◆ default_float

const noref float default_float = 0

Definition at line 135 of file cvar.qh.

◆ default_int

const noref int default_int = 0

Definition at line 134 of file cvar.qh.

◆ default_string

const noref string default_string = ""

Definition at line 136 of file cvar.qh.

◆ default_vector

const noref vector default_vector = '0 0 0'

Definition at line 137 of file cvar.qh.

◆ RegisterCvars_Save_fd

int RegisterCvars_Save_fd

Definition at line 113 of file cvar.qh.

Referenced by RegisterCvars_Save(), and STATIC_INIT_LATE().