From cd8035319d3d5479ec95acbc82c8109638425605 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Fri, 21 Nov 2003 21:34:53 +0000 Subject: [PATCH] PR_GetString should have been returning const char *. now does --- include/QF/progs.h | 4 ++-- include/QF/qfplist.h | 2 +- libs/gamecode/builtins/bi_gib.c | 4 ++-- libs/gamecode/builtins/pr_cmds.c | 20 ++++++++++---------- libs/gamecode/engine/pr_edict.c | 10 +++++----- libs/gamecode/engine/pr_exec.c | 4 ++-- libs/gamecode/engine/pr_parse.c | 14 +++++++------- libs/gamecode/engine/pr_strings.c | 6 +++--- libs/util/qfplist.c | 14 ++++++++++---- tools/qwaq/builtins.c | 6 +++--- 10 files changed, 45 insertions(+), 39 deletions(-) diff --git a/include/QF/progs.h b/include/QF/progs.h index 4e4b10931..c1d02aed9 100644 --- a/include/QF/progs.h +++ b/include/QF/progs.h @@ -221,7 +221,7 @@ int PR_InitRuntime (progs_t *pr); // qboolean PR_StringValid (progs_t *pr, int num); -char *PR_GetString(progs_t *pr, int num); +const char *PR_GetString(progs_t *pr, int num); int PR_SetString(progs_t *pr, const char *s); void PR_GarbageCollect (progs_t *pr); @@ -378,7 +378,7 @@ struct progs_s { struct hashtab_s *protocols; // debug info - char *debugfile; + const char *debugfile; struct pr_debug_header_s *debug; struct pr_auxfunction_s *auxfunctions; struct pr_auxfunction_s **auxfunction_map; diff --git a/include/QF/qfplist.h b/include/QF/qfplist.h index d86c5e352..3f83742d4 100644 --- a/include/QF/qfplist.h +++ b/include/QF/qfplist.h @@ -89,7 +89,7 @@ plitem_t *PL_A_InsertObjectAtIndex (plitem_t *, plitem_t *, int ind); plitem_t *PL_NewDictionary (void); plitem_t *PL_NewArray (void); plitem_t *PL_NewData (void *, int); -plitem_t *PL_NewString (char *); +plitem_t *PL_NewString (const char *); void PL_FreeItem (struct plitem_s *); diff --git a/libs/gamecode/builtins/bi_gib.c b/libs/gamecode/builtins/bi_gib.c index 4edbee459..16791602b 100644 --- a/libs/gamecode/builtins/bi_gib.c +++ b/libs/gamecode/builtins/bi_gib.c @@ -115,7 +115,7 @@ bi_GIB_Builtin_Add (progs_t *pr) { bi_gib_resources_t *res = PR_Resources_Find (pr, "GIB"); bi_gib_builtin_t *builtin; - char *name = P_GSTRING (pr, 0); + const char *name = P_GSTRING (pr, 0); func_t func = P_FUNCTION (pr, 1); if (GIB_Builtin_Exists (name)) { @@ -139,7 +139,7 @@ bi_GIB_Builtin_Add (progs_t *pr) static void bi_GIB_Return (progs_t *pr) { - char *str = P_GSTRING(pr, 0); + const char *str = P_GSTRING(pr, 0); if (str) GIB_Return (str); diff --git a/libs/gamecode/builtins/pr_cmds.c b/libs/gamecode/builtins/pr_cmds.c index dbb3413d5..6d1f8972c 100644 --- a/libs/gamecode/builtins/pr_cmds.c +++ b/libs/gamecode/builtins/pr_cmds.c @@ -602,15 +602,15 @@ PF_charcount (progs_t *pr) static void PF_sprintf (progs_t *pr) { - char *format; - char *c; // current - char *out = 0; - char new_format[INT_WIDTH * 2 + 9]; // "%0-+ #." and conversion - int fmt_alternate, fmt_leadzero, fmt_leftjust, fmt_minwidth, - fmt_precision, fmt_signed, fmt_space, fmt_type, looping, - ret; - size_t new_format_i; - int curarg = 1, out_max = 32, out_size = 0; + const char *format; + const char *c; // current + char *out = 0; + char new_format[INT_WIDTH * 2 + 9]; // "%0-+ #." and conversion + int fmt_alternate, fmt_leadzero, fmt_leftjust, fmt_minwidth; + int fmt_precision, fmt_signed, fmt_space, fmt_type, looping; + int ret; + size_t new_format_i; + int curarg = 1, out_max = 32, out_size = 0; format = P_GSTRING (pr, 0); c = format; @@ -774,7 +774,7 @@ PF_sprintf (progs_t *pr) } } } else if (*c == '%' && *(c + 1) == 's') { - char *s; + const char *s; if (curarg > MAX_ARG) goto maxargs; s = P_GSTRING (pr, 0 + curarg); diff --git a/libs/gamecode/engine/pr_edict.c b/libs/gamecode/engine/pr_edict.c index 565b197cc..c35a76046 100644 --- a/libs/gamecode/engine/pr_edict.c +++ b/libs/gamecode/engine/pr_edict.c @@ -369,12 +369,12 @@ PR_GlobalStringNoContents (progs_t *pr, int ofs, etype_t type) void ED_Print (progs_t *pr, edict_t *ed) { - int l; + int l; unsigned int i; - char *name; - int type; - ddef_t *d; - pr_type_t *v; + const char *name; + int type; + ddef_t *d; + pr_type_t *v; if (ed->free) { Sys_Printf ("FREE\n"); diff --git a/libs/gamecode/engine/pr_exec.c b/libs/gamecode/engine/pr_exec.c index bce24ec03..b06f9136c 100644 --- a/libs/gamecode/engine/pr_exec.c +++ b/libs/gamecode/engine/pr_exec.c @@ -273,8 +273,8 @@ PR_ExecuteProgram (progs_t * pr, func_t fnum) break; case OP_ADD_S: { - char *a = PR_GetString (pr, OPA.string_var); - char *b = PR_GetString (pr, OPB.string_var); + const char *a = PR_GetString (pr, OPA.string_var); + const char *b = PR_GetString (pr, OPB.string_var); int lena = strlen (a); int size = lena + strlen (b) + 1; char *c = Hunk_TempAlloc (size); diff --git a/libs/gamecode/engine/pr_parse.c b/libs/gamecode/engine/pr_parse.c index 00c8b4729..75726bc62 100644 --- a/libs/gamecode/engine/pr_parse.c +++ b/libs/gamecode/engine/pr_parse.c @@ -118,10 +118,10 @@ ED_Write (progs_t *pr, QFile *f, edict_t *ed) { unsigned int i; int j; - int type; - char *name; - ddef_t *d; - pr_type_t *v; + int type; + const char *name; + ddef_t *d; + pr_type_t *v; Qprintf (f, "{\n"); @@ -162,10 +162,10 @@ ED_Write (progs_t *pr, QFile *f, edict_t *ed) void ED_WriteGlobals (progs_t *pr, QFile *f) { - ddef_t *def; + ddef_t *def; unsigned int i; - char *name; - int type; + const char *name; + int type; Qprintf (f, "{\n"); for (i = 0; i < pr->progs->numglobaldefs; i++) { diff --git a/libs/gamecode/engine/pr_strings.c b/libs/gamecode/engine/pr_strings.c index 996699cfa..9f02d6336 100644 --- a/libs/gamecode/engine/pr_strings.c +++ b/libs/gamecode/engine/pr_strings.c @@ -154,10 +154,10 @@ PR_LoadStrings (progs_t *pr) void PR_GarbageCollect (progs_t *pr) { - char *str; + const char *str; unsigned int i; int j; - ddef_t *def; + ddef_t *def; strref_t *sr; for (i = 0; i < pr->dyn_str_size; i++) @@ -222,7 +222,7 @@ PR_StringValid (progs_t *pr, int num) return get_string (pr, num) != 0; } -char * +const char * PR_GetString (progs_t *pr, int num) { char *str; diff --git a/libs/util/qfplist.c b/libs/util/qfplist.c index b55daffd8..0809eb80f 100644 --- a/libs/util/qfplist.c +++ b/libs/util/qfplist.c @@ -98,14 +98,20 @@ PL_NewData (void *data, int size) return item; } -plitem_t * -PL_NewString (char *str) +static plitem_t * +new_string (char *str) { plitem_t *item = PL_NewItem (QFString); item->data = str; return item; } +plitem_t * +PL_NewString (const char *str) +{ + return new_string (strdup (str)); +} + void PL_FreeItem (plitem_t *item) { @@ -581,7 +587,7 @@ PL_ParsePropertyListItem (pldata_t *pl) if (!str) { return NULL; } else { - return PL_NewString (str); + return new_string (str); } } @@ -591,7 +597,7 @@ PL_ParsePropertyListItem (pldata_t *pl) if (!str) { return NULL; } else { - return PL_NewString (str); + return new_string (str); } } } // switch diff --git a/tools/qwaq/builtins.c b/tools/qwaq/builtins.c index 7653fa24a..77cebf790 100644 --- a/tools/qwaq/builtins.c +++ b/tools/qwaq/builtins.c @@ -49,7 +49,7 @@ static __attribute__ ((unused)) const char rcsid[] = static void bi_print (progs_t *pr) { - char *str; + const char *str; str = P_GSTRING (pr, 0); fprintf (stdout, "%s", str); @@ -77,7 +77,7 @@ bi_strerror (progs_t *pr) static void bi_open (progs_t *pr) { - char *path = P_GSTRING (pr, 0); + const char *path = P_GSTRING (pr, 0); int flags = P_INT (pr, 1); int mode = P_INT (pr, 2); R_INT (pr) = open (path, flags, mode); @@ -112,7 +112,7 @@ static void bi_write (progs_t *pr) { int handle = P_INT (pr, 0); - char *buffer = P_GSTRING (pr, 1); + const char *buffer = P_GSTRING (pr, 1); int count = P_INT (pr, 2); R_INT (pr) = write (handle, buffer, count);