1 /*
2 	cvar.h
3 
4 	Configuration variable definitions and prototypes
5 
6 	Copyright (C) 1996-1997  Id Software, Inc.
7 
8 	This program is free software; you can redistribute it and/or
9 	modify it under the terms of the GNU General Public License
10 	as published by the Free Software Foundation; either version 2
11 	of the License, or (at your option) any later version.
12 
13 	This program is distributed in the hope that it will be useful,
14 	but WITHOUT ANY WARRANTY; without even the implied warranty of
15 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 
17 	See the GNU General Public License for more details.
18 
19 	You should have received a copy of the GNU General Public License
20 	along with this program; if not, write to:
21 
22 		Free Software Foundation, Inc.
23 		59 Temple Place - Suite 330
24 		Boston, MA  02111-1307, USA
25 
26 */
27 
28 #ifndef __cvar_h
29 #define __cvar_h
30 
31 /** \defgroup cvar Configuration variables
32 	\ingroup utils
33 */
34 //@{
35 
36 #include "QF/qtypes.h"
37 #include "QF/quakeio.h"
38 
39 typedef struct cvar_s {
40 	const char *name;			///< The name of the cvar.
41 	const char *string;			///< The current cvar value as a string.
42 	const char *default_string;	///< The default value of the cvar.
43 	int	        flags;			///< Cvar flags
44 	/** Callback for when the cvar value changes.
45 
46 		This allows for more flexibility in what happens when a cvar is
47 		nodifed than can be achieved with flags alone. While a similar could
48 		be done using commands, a cvar with a callback and CVAR_ARCHIVE set
49 		allows the setting to be saved automatically.
50 
51 		\param var	This cvar.
52 	*/
53 	void      (*callback)(struct cvar_s *var);
54 	const char *description;	///< for "help" command
55 	float       value;			///< The current cvar value as a float
56 	int         int_val;		///< The current cvar value as an integer
57 	vec3_t      vec;			///< The current cvar value as a vector
58 	struct cvar_s *next;		///< \internal Linked list of cvars.
59 } cvar_t;
60 
61 typedef struct cvar_alias_s {
62 	char       *name;			///< The name of the alias.
63 	cvar_t     *cvar;			///< The cvar to which this alias refers
64 	struct cvar_alias_s	*next;	///< \internal LInked list of aliases.
65 } cvar_alias_t;
66 
67 /** \name cvar_flags
68 	Zoid| A good CVAR_ROM example is userpath.  The code should read "cvar_t
69 	*fs_userpath = CvarGet("fs_userpath", ".", CVAR_ROM);  The user can
70 	override that with +set fs_userpath \<blah\> since the command line +set
71 	gets created _before_ the C code for fs_basepath setup is called.  The
72 	code goes "look, the user made fs_basepath already", uses the users value,
73 	but sets CVAR_ROM as per the call.
74 */
75 //@{
76 #define CVAR_NONE			0		///< normal cvar
77 #define	CVAR_ARCHIVE		1		///< set to cause it to be saved to
78 									///< config.cfg
79 #define	CVAR_USERINFO		2		///< sent to server on connect or change
80 #define	CVAR_SERVERINFO		4		///< sent in response to front end requests
81 #define	CVAR_NOTIFY			32		///< Will notify players when changed.
82 									///< (not implemented)
83 #define	CVAR_ROM			64		///< display only, cannot be set
84 #define	CVAR_USER_CREATED	128		///< created by a set command
85 #define CVAR_LATCH			2048	///< will change only when C code next does
86 									///< a Cvar_Get(), so it can't be changed
87 									///< (not implemented)
88 //@}
89 
90 
91 // Returns the Cvar if found, creates it with value if not.  Description and
92 // flags are always updated.
93 cvar_t	*Cvar_Get (const char *name, const char *value, int cvarflags,
94 				   void (*callback)(cvar_t*), const char *description);
95 
96 cvar_t	*Cvar_FindAlias (const char *alias_name);
97 
98 cvar_t	*Cvar_MakeAlias (const char *name, cvar_t *cvar);
99 cvar_t	*Cvar_RemoveAlias (const char *name);
100 
101 // equivelants to "<name> <variable>" typed at the console
102 void 	Cvar_Set (cvar_t *var, const char *value);
103 void	Cvar_SetValue (cvar_t *var, float value);
104 
105 // allows you to change a Cvar's flags without a full Cvar_Get
106 void	Cvar_SetFlags (cvar_t *var, int cvarflags);
107 
108 // returns 0 if not defined or non numeric
109 float	Cvar_VariableValue (const char *var_name);
110 
111 // returns an empty string if not defined
112 const char	*Cvar_VariableString (const char *var_name);
113 
114 // called by Cmd_ExecuteString when Cmd_Argv(0) doesn't match a known
115 // command.  Returns true if the command was a variable reference that
116 // was handled. (print or change)
117 qboolean Cvar_Command (void);
118 
119 // Writes lines containing "set variable value" for all variables
120 // with the archive flag set to true.
121 void 	Cvar_WriteVariables (QFile *f);
122 
123 // attempts to match a partial variable name for command line completion
124 // returns NULL if nothing fits
125 const char 	*Cvar_CompleteVariable (const char *partial);
126 
127 // Added by EvilTypeGuy - functions for tab completion system
128 // Thanks to Fett erich@heintz.com
129 // Thanks to taniwha
130 int		Cvar_CompleteCountPossible (const char *partial);
131 const char	**Cvar_CompleteBuildList (const char *partial);
132 
133 // Returns a pointer to the Cvar, NULL if not found
134 cvar_t *Cvar_FindVar (const char *var_name);
135 
136 void Cvar_Init_Hash (void);
137 void Cvar_Init (void);
138 
139 extern cvar_t	*cvar_vars;
140 
141 //@}
142 
143 #endif // __cvar_h
144