compat.h: Add str*equal () convenience macros

cl_main.c: Clean up version string a little
cmd.c: Add setrom parsing to first init phase, clean up includes a little
cvar.c: setrom command now uses set's semantics. Cvar_Set, Cvar_Set_f,
Cvar_Setrom_f now do a Con_DPrintf to report attempts to set CVAR_ROM
cvars.
sv_main.c: Clean up version string a little
vid.c: -winsize, -width, and -height no longer use Cvar_SetROM. The code
looks a little uglier, but it's more correct.
This commit is contained in:
Jeff Teunissen 2000-11-04 07:42:43 +00:00
parent c7790511ec
commit ba11d00aba
6 changed files with 92 additions and 61 deletions

View file

@ -74,3 +74,17 @@ extern int vsnprintf(char *s, size_t maxlen, const char *format, va_list arg);
#endif #endif
#endif // _COMPAT_H #endif // _COMPAT_H
/* String utility functions */
#if !defined(strequal)
# define strequal(a,b) (strcmp (a, b) == 0)
#endif
#if !defined(strcaseequal)
# define strcaseequal(a,b) (strcasecmp (a, b) == 0)
#endif
#if !defined(strnequal)
# define strnequal(a,b,c) (strncmp (a, b, c) == 0)
#endif
#if !defined(strncaseequal)
# define strncaseequal(a,b,c) (strncasecmp (a, b, c) == 0)
#endif

View file

@ -1702,9 +1702,9 @@ void Host_Init (quakeparms_t *parms)
host_initialized = true; host_initialized = true;
Con_Printf ("\nClient Version %s (Build %04d)\n\n", VERSION, build_number()); Con_Printf ("\nClient version %s (build %04d)\n\n", VERSION, build_number ());
Con_Printf ("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> %s Initialized <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n", PROGRAM); Con_Printf ("<EFBFBD><EFBFBD> %s initialized €<EFBFBD><EFBFBD>\n", PROGRAM);
} }

View file

@ -27,10 +27,18 @@
*/ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
# include <config.h> # include "config.h"
#endif #endif
#include <string.h>
#include <ctype.h>
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif
#include "sys.h" #include "sys.h"
#include "cmd.h" #include "cmd.h"
#include "compat.h"
#include "cvar.h" #include "cvar.h"
#include "sizebuf.h" #include "sizebuf.h"
#include "console.h" #include "console.h"
@ -39,12 +47,6 @@
#include "commdef.h" #include "commdef.h"
#include "zone.h" #include "zone.h"
#include <string.h>
#include <ctype.h>
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif
void Cmd_ForwardToServer (void); void Cmd_ForwardToServer (void);
#define MAX_ALIAS_NAME 32 #define MAX_ALIAS_NAME 32
@ -258,10 +260,14 @@ Cbuf_Execute_Sets (void)
while (cmd_text.cursize) { while (cmd_text.cursize) {
extract_line (line); extract_line (line);
// execute the command line // execute the command line
if (strncmp(line,"set",3)==0 if (strnequal(line, "set", 3) && isspace((int) line[3])) {
&& isspace((int) line[3])) //Con_DPrintf ("+%s\n",line);
//Con_DPrintf("+%s\n",line),
Cmd_ExecuteString (line); Cmd_ExecuteString (line);
}
if (strnequal(line, "setrom", 6) && isspace((int) line[6])) {
//Con_DPrintf ("+%s\n",line);
Cmd_ExecuteString (line);
}
} }
} }

View file

@ -187,22 +187,25 @@ void Cvar_Info (cvar_t *var);
Cvar_Set Cvar_Set
============ ============
*/ */
void Cvar_Set (cvar_t *var, char *value) void
Cvar_Set (cvar_t *var, char *value)
{ {
if (!var) if (!var)
return; return;
if(var->flags & CVAR_ROM) if(var->flags & CVAR_ROM) {
Con_DPrintf ("Cvar \"%s\" is read-only, cannot modify\n", var->name);
return; return;
}
free (var->string); // free the old value string free (var->string); // free the old value string
var->string = malloc (strlen(value)+1); var->string = malloc (strlen (value) + 1);
strcpy (var->string, value); strcpy (var->string, value);
var->value = atof (var->string); var->value = atof (var->string);
var->int_val = atoi (var->string); var->int_val = atoi (var->string);
Cvar_Info(var); Cvar_Info (var);
} }
@ -211,7 +214,8 @@ void Cvar_Set (cvar_t *var, char *value)
doesn't check for CVAR_ROM flag doesn't check for CVAR_ROM flag
*/ */
void Cvar_SetROM (cvar_t *var, char *value) void
Cvar_SetROM (cvar_t *var, char *value)
{ {
if (!var) if (!var)
return; return;
@ -252,11 +256,12 @@ Cvar_Command
Handles variable inspection and changing from the console Handles variable inspection and changing from the console
============ ============
*/ */
qboolean Cvar_Command (void) qboolean
Cvar_Command (void)
{ {
cvar_t *v; cvar_t *v;
// check variables // check variables
v = Cvar_FindVar (Cmd_Argv(0)); v = Cvar_FindVar (Cmd_Argv(0));
if (!v) if (!v)
v = Cvar_FindAlias (Cmd_Argv(0)); v = Cvar_FindAlias (Cmd_Argv(0));
@ -264,8 +269,7 @@ qboolean Cvar_Command (void)
return false; return false;
// perform a variable print or set // perform a variable print or set
if (Cmd_Argc() == 1) if (Cmd_Argc() == 1) {
{
Con_Printf ("\"%s\" is \"%s\"\n", v->name, v->string); Con_Printf ("\"%s\" is \"%s\"\n", v->name, v->string);
return true; return true;
} }
@ -292,56 +296,63 @@ void Cvar_WriteVariables (QFile *f)
Qprintf (f, "%s \"%s\"\n", var->name, var->string); Qprintf (f, "%s \"%s\"\n", var->name, var->string);
} }
void Cvar_Set_f(void) void
Cvar_Set_f (void)
{ {
cvar_t *var; cvar_t *var;
char *value; char *value;
char *var_name; char *var_name;
if (Cmd_Argc() != 3) if (Cmd_Argc() != 3) {
{
Con_Printf ("usage: set <cvar> <value>\n"); Con_Printf ("usage: set <cvar> <value>\n");
return; return;
} }
var_name = Cmd_Argv (1); var_name = Cmd_Argv (1);
value = Cmd_Argv (2); value = Cmd_Argv (2);
var = Cvar_FindVar (var_name); var = Cvar_FindVar (var_name);
if (!var) if (!var)
var = Cvar_FindAlias (var_name); var = Cvar_FindAlias (var_name);
if (var)
{ if (var) {
Cvar_Set (var, value); if (var->flags & CVAR_ROM) {
} Con_DPrintf ("Cvar \"%s\" is read-only, cannot modify\n", var_name);
else } else {
{ Cvar_Set (var, value);
}
} else {
var = Cvar_Get (var_name, value, CVAR_USER_CREATED, var = Cvar_Get (var_name, value, CVAR_USER_CREATED,
"User created cvar"); "User-created cvar");
} }
} }
void Cvar_Setrom_f(void) void
Cvar_Setrom_f (void)
{ {
cvar_t *var; cvar_t *var;
char *value; char *value;
char *var_name; char *var_name;
if (Cmd_Argc() != 2) if (Cmd_Argc() != 3) {
{ Con_Printf ("usage: setrom <cvar> <value>\n");
Con_Printf ("usage: setrom <cvar>\n");
return; return;
} }
var_name = Cmd_Argv (1); var_name = Cmd_Argv (1);
value = Cmd_Argv (2); value = Cmd_Argv (2);
var = Cvar_FindVar (var_name); var = Cvar_FindVar (var_name);
if (!var) if (!var)
var = Cvar_FindAlias (var_name); var = Cvar_FindAlias (var_name);
if (var)
{ if (var) {
var->flags |= CVAR_ROM; if (var->flags & CVAR_ROM) {
} Con_DPrintf ("Cvar \"%s\" is read-only, cannot modify\n", var_name);
else } else {
{ Cvar_Set (var, value);
Con_Printf ("cvar %s not found\n", var_name); }
} else {
var = Cvar_Get (var_name, value, CVAR_USER_CREATED|CVAR_ROM,
"User-created READ-ONLY Cvar");
} }
} }

View file

@ -1917,11 +1917,11 @@ void SV_Init (quakeparms_t *parms)
host_initialized = true; host_initialized = true;
// Con_Printf ("Exe: "__TIME__" "__DATE__"\n"); // Con_Printf ("Exe: "__TIME__" "__DATE__"\n");
Con_Printf ("%4.1f megabyte heap\n",parms->memsize/ (1024*1024.0)); Con_Printf ("%4.1f megabyte heap\n", parms->memsize / (1024*1024.0));
Con_Printf ("\nQuakeForge Version %s (Build %04d)\n\n", VERSION, build_number()); Con_Printf ("\n%s server, Version %s (build %04d)\n\n", PROGRAM, VERSION, build_number ());
Con_Printf ("======== %s Initialized ========\n", PROGRAM); Con_Printf ("<==> %s initialized <==>\n", PROGRAM);
// process command line arguments // process command line arguments
Cmd_StuffCmds_f (); Cmd_StuffCmds_f ();

View file

@ -47,13 +47,19 @@ VID_GetWindowSize (int def_w, int def_h)
{ {
int pnum; int pnum;
vid_width = Cvar_Get ("vid_width", va("%d",def_w), CVAR_ROM, "screen width"); if ((pnum=COM_CheckParm("-winsize"))) {
vid_height = Cvar_Get ("vid_height", va("%d",def_h), CVAR_ROM, "screen height"); if (pnum >= com_argc-2)
Sys_Error("VID: -winsize <width> <height>\n");
vid_width = Cvar_Get ("vid_width", com_argv[pnum+1], CVAR_ROM, "screen width");
vid_height = Cvar_Get ("vid_height", com_argv[pnum+2], CVAR_ROM, "screen height");
if (!vid_width->int_val || !vid_height->int_val)
Sys_Error("VID: Bad window width/height\n");
}
if ((pnum=COM_CheckParm("-width"))) { if ((pnum=COM_CheckParm("-width"))) {
if (pnum >= com_argc-1) if (pnum >= com_argc-1)
Sys_Error("VID: -width <width>\n"); Sys_Error("VID: -width <width>\n");
Cvar_SetROM (vid_width, com_argv[pnum+1]); vid_width = Cvar_Get ("vid_width", com_argv[pnum+1], CVAR_ROM, "screen width");
if (!vid_width->int_val) if (!vid_width->int_val)
Sys_Error("VID: Bad window width\n"); Sys_Error("VID: Bad window width\n");
} }
@ -61,19 +67,13 @@ VID_GetWindowSize (int def_w, int def_h)
if ((pnum=COM_CheckParm("-height"))) { if ((pnum=COM_CheckParm("-height"))) {
if (pnum >= com_argc-1) if (pnum >= com_argc-1)
Sys_Error("VID: -height <height>\n"); Sys_Error("VID: -height <height>\n");
Cvar_SetROM (vid_height, com_argv[pnum+1]); vid_height = Cvar_Get ("vid_height", com_argv[pnum+1], CVAR_ROM, "screen height");
if (!vid_height->int_val) if (!vid_height->int_val)
Sys_Error("VID: Bad window height\n"); Sys_Error("VID: Bad window height\n");
} }
if ((pnum=COM_CheckParm("-winsize"))) { vid_width = Cvar_Get ("vid_width", va("%d",def_w), CVAR_ROM, "screen width");
if (pnum >= com_argc-2) vid_height = Cvar_Get ("vid_height", va("%d",def_h), CVAR_ROM, "screen height");
Sys_Error("VID: -winsize <width> <height>\n");
Cvar_SetROM (vid_width, com_argv[pnum+1]);
Cvar_SetROM (vid_height, com_argv[pnum+2]);
if (!vid_width->int_val || !vid_height->int_val)
Sys_Error("VID: Bad window width/height\n");
}
scr_width = vid.width = vid_width->int_val; scr_width = vid.width = vid_width->int_val;
scr_height = vid.height = vid_height->int_val; scr_height = vid.height = vid_height->int_val;