From e339e82c01e873191cc48a137d23dcb431c463cf Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 4 Jun 2001 04:52:14 +0000 Subject: [PATCH] hash.h is now const correct as is a lot of qfcc --- include/QF/hash.h | 4 ++-- libs/gamecode/pr_edict.c | 4 ++-- libs/gamecode/pr_strings.c | 2 +- libs/util/cmd.c | 4 ++-- libs/util/cvar.c | 4 ++-- libs/util/hash.c | 2 +- libs/util/quakefs.c | 2 +- nq/source/skin.c | 2 +- qw/source/skin.c | 2 +- tools/qfcc/include/qfcc.h | 18 +++++++++--------- tools/qfcc/source/pr_comp.c | 2 +- tools/qfcc/source/pr_def.c | 4 ++-- tools/qfcc/source/pr_imm.c | 6 +++--- tools/qfcc/source/pr_lex.c | 6 +++--- tools/qfcc/source/pr_opcode.c | 2 +- tools/qfcc/source/qfcc.c | 6 +++--- tools/qwaq/main.qc | 5 +++++ 17 files changed, 40 insertions(+), 35 deletions(-) diff --git a/include/QF/hash.h b/include/QF/hash.h index b79677b5b..d21d965f2 100644 --- a/include/QF/hash.h +++ b/include/QF/hash.h @@ -41,12 +41,12 @@ typedef struct hashlink_s { typedef struct hashtab_s { size_t tab_size; void *user_data; - char *(*get_key)(void*,void*); + const char *(*get_key)(void*,void*); void (*free_ele)(void*,void*); hashlink_t *tab[1]; // variable size } hashtab_t; -hashtab_t *Hash_NewTable (int tsize, char *(*gk)(void*,void*), +hashtab_t *Hash_NewTable (int tsize, const char *(*gk)(void*,void*), void (*f)(void*,void*), void *ud); void Hash_DelTable (hashtab_t *tab); void Hash_FlushTable (hashtab_t *tab); diff --git a/libs/gamecode/pr_edict.c b/libs/gamecode/pr_edict.c index 3fe6f1bb8..028798b14 100644 --- a/libs/gamecode/pr_edict.c +++ b/libs/gamecode/pr_edict.c @@ -990,7 +990,7 @@ ED_LoadFromFile (progs_t * pr, char *data) Con_DPrintf ("%i entities inhibited\n", inhibit); } -static char * +static const char * function_get_key (void *f, void *_pr) { progs_t *pr = (progs_t*)_pr; @@ -998,7 +998,7 @@ function_get_key (void *f, void *_pr) return PR_GetString (pr, func->s_name); } -static char * +static const char * var_get_key (void *d, void *_pr) { progs_t *pr = (progs_t*)_pr; diff --git a/libs/gamecode/pr_strings.c b/libs/gamecode/pr_strings.c index 98434a072..9a1e9ce37 100644 --- a/libs/gamecode/pr_strings.c +++ b/libs/gamecode/pr_strings.c @@ -42,7 +42,7 @@ #include "QF/hash.h" #include "QF/progs.h" -static char * +static const char * strref_get_key (void *_sr, void *notused) { strref_t *sr = (strref_t*)_sr; diff --git a/libs/util/cmd.c b/libs/util/cmd.c index be24fbb93..5bf463381 100644 --- a/libs/util/cmd.c +++ b/libs/util/cmd.c @@ -824,14 +824,14 @@ cmd_alias_free (void *_a, void *unused) free (a); } -static char * +static const char * cmd_alias_get_key (void *_a, void *unused) { cmdalias_t *a = (cmdalias_t*)_a; return a->name; } -static char * +static const char * cmd_get_key (void *c, void *unused) { cmd_function_t *cmd = (cmd_function_t*)c; diff --git a/libs/util/cvar.c b/libs/util/cvar.c index 7b43f63ad..d7c37ec9c 100644 --- a/libs/util/cvar.c +++ b/libs/util/cvar.c @@ -431,7 +431,7 @@ cvar_free (void *c, void *unused) free (cvar); } -static char * +static const char * cvar_get_key (void *c, void *unused) { cvar_t *cvar = (cvar_t*)c; @@ -446,7 +446,7 @@ calias_free (void *c, void *unused) free (calias); } -static char * +static const char * calias_get_key (void *c, void *unused) { cvar_alias_t *calias = (cvar_alias_t*)c; diff --git a/libs/util/hash.c b/libs/util/hash.c index 3c232ae89..34dc2c53e 100644 --- a/libs/util/hash.c +++ b/libs/util/hash.c @@ -69,7 +69,7 @@ hash (const char *str) } hashtab_t * -Hash_NewTable (int tsize, char *(*gk)(void*,void*), void (*f)(void*,void*), +Hash_NewTable (int tsize, const char *(*gk)(void*,void*), void (*f)(void*,void*), void *ud) { hashtab_t *tab = calloc (1, (size_t)&((hashtab_t*)0)->tab[tsize]); diff --git a/libs/util/quakefs.c b/libs/util/quakefs.c index 6f70eb3ad..a7582501f 100644 --- a/libs/util/quakefs.c +++ b/libs/util/quakefs.c @@ -716,7 +716,7 @@ COM_LoadStackFile (char *path, void *buffer, int bufsize) return buf; } -static char * +static const char * pack_get_key (void *_p, void *unused) { packfile_t *p = (packfile_t *) _p; diff --git a/nq/source/skin.c b/nq/source/skin.c index b276f4783..8aefb5ca7 100644 --- a/nq/source/skin.c +++ b/nq/source/skin.c @@ -69,7 +69,7 @@ int num_temp_skins; int skin_textures; int skin_fb_textures; -static char * +static const char * skin_get_key (void *_skin, void *unused) { skin_t *skin = (skin_t*)_skin; diff --git a/qw/source/skin.c b/qw/source/skin.c index a8c761d61..73068bc8c 100644 --- a/qw/source/skin.c +++ b/qw/source/skin.c @@ -69,7 +69,7 @@ int num_temp_skins; int skin_textures; int skin_fb_textures; -static char * +static const char * skin_get_key (void *_skin, void *unused) { skin_t *skin = (skin_t*)_skin; diff --git a/tools/qfcc/include/qfcc.h b/tools/qfcc/include/qfcc.h index eed000a85..732610d94 100644 --- a/tools/qfcc/include/qfcc.h +++ b/tools/qfcc/include/qfcc.h @@ -252,7 +252,7 @@ typedef struct type_s typedef struct def_s { type_t *type; - char *name; + const char *name; struct def_s *next; struct def_s *scope_next; // to facilitate hash table removal gofs_t ofs; @@ -293,7 +293,7 @@ struct function_s { int builtin; // if non 0, call an internal function int code; // first statement - char *file; // source file with definition + const char *file; // source file with definition int file_line; struct def_s *def; int parm_ofs[MAX_PARMS]; // allways contiguous, right? @@ -369,9 +369,9 @@ type_t *PR_ParseType (void); char *PR_ParseName (void); def_t *PR_ParseImmediate (def_t *def); -qboolean PR_Check (token_type_t type, char *string); -void PR_Expect (token_type_t type, char *string); -void PR_ParseError (char *error, ...); +qboolean PR_Check (token_type_t type, const char *string); +void PR_Expect (token_type_t type, const char *string); +void PR_ParseError (const char *error, ...); extern jmp_buf pr_parse_abort; // longjump with this on parse error @@ -395,7 +395,7 @@ extern def_t *pr_scope; extern int pr_error_count; void PR_NewLine (void); -def_t *PR_GetDef (type_t *type, char *name, def_t *scope, qboolean allocate); +def_t *PR_GetDef (type_t *type, const char *name, def_t *scope, qboolean allocate); def_t *PR_NewDef (type_t *type, const char *name, def_t *scope); void PR_FlushScope (def_t *scope); @@ -416,7 +416,7 @@ char *PR_ValueString (etype_t type, void *val); void PR_ClearGrabMacros (void); -qboolean PR_CompileFile (char *string, char *filename); +qboolean PR_CompileFile (char *string, const char *filename); extern qboolean pr_dumpasm; @@ -464,7 +464,7 @@ extern char precache_files[MAX_FILES][MAX_DATA_PATH]; extern int precache_files_block[MAX_SOUNDS]; extern int numfiles; -int CopyString (char *str); -int ReuseString (char *str); +int CopyString (const char *str); +int ReuseString (const char *str); diff --git a/tools/qfcc/source/pr_comp.c b/tools/qfcc/source/pr_comp.c index 7577036b4..79ee63035 100644 --- a/tools/qfcc/source/pr_comp.c +++ b/tools/qfcc/source/pr_comp.c @@ -593,7 +593,7 @@ PR_ParseDefs (void) Compile the null-terminated text, adding definitions to the pr structure */ qboolean -PR_CompileFile (char *string, char *filename) +PR_CompileFile (char *string, const char *filename) { if (!pr.memory) Error ("PR_CompileFile: Didn't clear"); diff --git a/tools/qfcc/source/pr_def.c b/tools/qfcc/source/pr_def.c index 4e76edaed..9f871a58e 100644 --- a/tools/qfcc/source/pr_def.c +++ b/tools/qfcc/source/pr_def.c @@ -30,7 +30,7 @@ int pr_edict_size; static hashtab_t *defs_by_name; -static char * +static const char * defs_get_key (void *_def, void *_tab) { def_t *def = (def_t*)_def; @@ -49,7 +49,7 @@ defs_get_key (void *_def, void *_tab) If allocate is true, a new def will be allocated if it can't be found */ def_t * -PR_GetDef (type_t *type, char *name, def_t *scope, qboolean allocate) +PR_GetDef (type_t *type, const char *name, def_t *scope, qboolean allocate) { def_t *def; char element[MAX_NAME]; diff --git a/tools/qfcc/source/pr_imm.c b/tools/qfcc/source/pr_imm.c index a05e4f01f..2c1129300 100644 --- a/tools/qfcc/source/pr_imm.c +++ b/tools/qfcc/source/pr_imm.c @@ -28,14 +28,14 @@ static hashtab_t *string_imm_defs; static hashtab_t *float_imm_defs; static hashtab_t *vector_imm_defs; -static char * +static const char * string_imm_get_key (void *_def, void *unused) { def_t *def = (def_t*)_def; return G_STRING (def->ofs); } -static char * +static const char * float_imm_get_key (void *_def, void *unused) { def_t *def = (def_t*)_def; @@ -44,7 +44,7 @@ float_imm_get_key (void *_def, void *unused) return rep; } -static char * +static const char * vector_imm_get_key (void *_def, void *unused) { def_t *def = (def_t*)_def; diff --git a/tools/qfcc/source/pr_lex.c b/tools/qfcc/source/pr_lex.c index 03f11f34c..c41999098 100644 --- a/tools/qfcc/source/pr_lex.c +++ b/tools/qfcc/source/pr_lex.c @@ -568,7 +568,7 @@ PR_Lex (void) Aborts the current file load */ void -PR_ParseError (char *error, ...) +PR_ParseError (const char *error, ...) { va_list argptr; char string[1024]; @@ -590,7 +590,7 @@ PR_ParseError (char *error, ...) to string */ void -PR_Expect (token_type_t type, char *string) +PR_Expect (token_type_t type, const char *string) { if (type != pr_token_type || strcmp (string, pr_token)) PR_ParseError ("expected %s, found %s", string, pr_token); @@ -605,7 +605,7 @@ PR_Expect (token_type_t type, char *string) Otherwise, return false and do nothing else. */ qboolean -PR_Check (token_type_t type, char *string) +PR_Check (token_type_t type, const char *string) { if (type != pr_token_type || strcmp (string, pr_token)) return false; diff --git a/tools/qfcc/source/pr_opcode.c b/tools/qfcc/source/pr_opcode.c index 48807727e..0751a4b01 100644 --- a/tools/qfcc/source/pr_opcode.c +++ b/tools/qfcc/source/pr_opcode.c @@ -169,7 +169,7 @@ PR_Statement (opcode_t * op, def_t * var_a, def_t * var_b) return var_c; } -static char * +static const char * get_key (void *_op, void *_tab) { opcode_t *op = (opcode_t *)_op; diff --git a/tools/qfcc/source/qfcc.c b/tools/qfcc/source/qfcc.c index d5ffcd91b..11f32d839 100644 --- a/tools/qfcc/source/qfcc.c +++ b/tools/qfcc/source/qfcc.c @@ -112,14 +112,14 @@ WriteFiles (void) */ static hashtab_t *strings_tab; -static char * +static const char * stings_get_key (void *_str, void *unsued) { return (char*)_str; } int -CopyString (char *str) +CopyString (const char *str) { int old; @@ -134,7 +134,7 @@ CopyString (char *str) } int -ReuseString (char *str) +ReuseString (const char *str) { char *s; diff --git a/tools/qwaq/main.qc b/tools/qwaq/main.qc index fcfd30d7f..69cf3aed5 100644 --- a/tools/qwaq/main.qc +++ b/tools/qwaq/main.qc @@ -2,10 +2,15 @@ string hello = "hello"; string world = "world"; float () main = { + local string s; + print (hello + " " + world + "\n"); if (hello < world) print (hello); if (world > hello) print (world); print ("\n"); + s = hello + world; + s = s + "\n"; + print (s); };