Skip to content

Instantly share code, notes, and snippets.

@ensiform
Created March 8, 2024 03:36
Show Gist options
  • Save ensiform/8c9a6ea23aebe7e2bdfe5929db36e637 to your computer and use it in GitHub Desktop.
Save ensiform/8c9a6ea23aebe7e2bdfe5929db36e637 to your computer and use it in GitHub Desktop.
diff --git a/codemp/botlib/be_ai_chat.cpp b/codemp/botlib/be_ai_chat.cpp
index fb29c536..7b5bd9ff 100644
--- a/codemp/botlib/be_ai_chat.cpp
+++ b/codemp/botlib/be_ai_chat.cpp
@@ -909,7 +909,7 @@ int BotLoadChatMessage(source_t *source, char *chatmessagestring)
SourceError(source, "chat message too long");
return qfalse;
} //end if
- sprintf(&ptr[strlen(ptr)], "%cv%ld%c", ESCAPE_CHAR, token.intvalue, ESCAPE_CHAR);
+ sprintf(&ptr[strlen(ptr)], "%cv%d%c", ESCAPE_CHAR, token.intvalue, ESCAPE_CHAR);
} //end if
//random string
else if (token.type == TT_NAME)
diff --git a/codemp/botlib/be_interface.cpp b/codemp/botlib/be_interface.cpp
index 6d61da92..a243de07 100644
--- a/codemp/botlib/be_interface.cpp
+++ b/codemp/botlib/be_interface.cpp
@@ -910,5 +910,7 @@ botlib_export_t *GetBotLibAPI(int apiVersion, botlib_import_t *import) {
be_botlib_export.BotLibUpdateEntity = Export_BotLibUpdateEntity;
be_botlib_export.Test = BotExportTest;
+ PC_Init();
+
return &be_botlib_export;
}
diff --git a/codemp/botlib/botlib.h b/codemp/botlib/botlib.h
index 0345e758..a3ecd5f1 100644
--- a/codemp/botlib/botlib.h
+++ b/codemp/botlib/botlib.h
@@ -426,7 +426,7 @@ typedef struct botlib_export_s
int (*BotLibVarGet)(char *var_name, char *value, int size);
//sets a C-like define returns BLERR_
- int (*PC_AddGlobalDefine)(char *string);
+ int (*PC_AddGlobalDefine)(const char *string);
int (*PC_LoadSourceHandle)(const char *filename);
int (*PC_FreeSourceHandle)(int handle);
int (*PC_ReadTokenHandle)(int handle, pc_token_t *pc_token);
diff --git a/codemp/botlib/l_precomp.cpp b/codemp/botlib/l_precomp.cpp
index 8089a56c..b56a902e 100644
--- a/codemp/botlib/l_precomp.cpp
+++ b/codemp/botlib/l_precomp.cpp
@@ -105,14 +105,12 @@ typedef enum {qfalse, qtrue} qboolean;
//directive name with parse function
typedef struct directive_s
{
- char *name;
+ const char *name;
int (*func)(source_t *source);
} directive_t;
#define DEFINEHASHSIZE 1024
-#define TOKEN_HEAP_SIZE 4096
-
int numtokens;
/*
int tokenheapinitialized; //true when the token heap is initialized
@@ -134,7 +132,7 @@ qboolean addGlobalDefine = qfalse;
// Returns: -
// Changes Globals: -
//============================================================================
-void QDECL SourceError(source_t *source, char *str, ...)
+void QDECL SourceError(source_t *source, const char *str, ...)
{
char text[1024];
va_list ap;
@@ -158,7 +156,7 @@ void QDECL SourceError(source_t *source, char *str, ...)
// Returns: -
// Changes Globals: -
//===========================================================================
-void QDECL SourceWarning(source_t *source, char *str, ...)
+void QDECL SourceWarning(source_t *source, const char *str, ...)
{
char text[1024];
va_list ap;
@@ -175,14 +173,28 @@ void QDECL SourceWarning(source_t *source, char *str, ...)
#ifdef BSPC
Log_Print("warning: file %s, line %d: %s\n", source->scriptstack->filename, source->scriptstack->line, text);
#endif //BSPC
-} //end of the function ScriptWarning
+} //end of the function SourceWarning
//============================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//============================================================================
-void PC_PushIndent(source_t *source, int type, int skip)
+void PC_Init(void)
+{
+#if DEFINEHASHING
+ if (!globaldefines) {
+ globaldefines = (struct define_s **)GetClearedMemory(DEFINEHASHSIZE * sizeof(define_t *));
+ }
+#endif
+} //end of the function PC_Init
+//============================================================================
+//
+// Parameter: -
+// Returns: -
+// Changes Globals: -
+//============================================================================
+static void PC_PushIndent(source_t *source, int type, int skip)
{
indent_t *indent;
@@ -200,7 +212,7 @@ void PC_PushIndent(source_t *source, int type, int skip)
// Returns: -
// Changes Globals: -
//============================================================================
-void PC_PopIndent(source_t *source, int *type, int *skip)
+static void PC_PopIndent(source_t *source, int *type, int *skip)
{
indent_t *indent;
@@ -225,7 +237,7 @@ void PC_PopIndent(source_t *source, int *type, int *skip)
// Returns: -
// Changes Globals: -
//============================================================================
-void PC_PushScript(source_t *source, script_t *script)
+static void PC_PushScript(source_t *source, script_t *script)
{
script_t *s;
@@ -247,34 +259,11 @@ void PC_PushScript(source_t *source, script_t *script)
// Returns: -
// Changes Globals: -
//============================================================================
-void PC_InitTokenHeap(void)
-{
- /*
- int i;
-
- if (tokenheapinitialized) return;
- freetokens = NULL;
- for (i = 0; i < TOKEN_HEAP_SIZE; i++)
- {
- token_heap[i].next = freetokens;
- freetokens = &token_heap[i];
- } //end for
- tokenheapinitialized = qtrue;
- */
-} //end of the function PC_InitTokenHeap
-//============================================================================
-//
-// Parameter: -
-// Returns: -
-// Changes Globals: -
-//============================================================================
-token_t *PC_CopyToken(token_t *token)
+static token_t *PC_CopyToken(token_t *token)
{
token_t *t;
-// t = (token_t *) malloc(sizeof(token_t));
t = (token_t *) GetMemory(sizeof(token_t));
-// t = freetokens;
if (!t)
{
#ifdef BSPC
@@ -284,7 +273,6 @@ token_t *PC_CopyToken(token_t *token)
#endif
return NULL;
} //end if
-// freetokens = freetokens->next;
Com_Memcpy(t, token, sizeof(token_t));
t->next = NULL;
numtokens++;
@@ -296,12 +284,9 @@ token_t *PC_CopyToken(token_t *token)
// Returns: -
// Changes Globals: -
//============================================================================
-void PC_FreeToken(token_t *token)
+static void PC_FreeToken(token_t *token)
{
- //free(token);
FreeMemory(token);
-// token->next = freetokens;
-// freetokens = token;
numtokens--;
} //end of the function PC_FreeToken
//============================================================================
@@ -310,7 +295,7 @@ void PC_FreeToken(token_t *token)
// Returns: -
// Changes Globals: -
//============================================================================
-int PC_ReadSourceToken(source_t *source, token_t *token)
+static int PC_ReadSourceToken(source_t *source, token_t *token)
{
token_t *t;
script_t *script;
@@ -353,7 +338,7 @@ int PC_ReadSourceToken(source_t *source, token_t *token)
// Returns: -
// Changes Globals: -
//============================================================================
-int PC_UnreadSourceToken(source_t *source, token_t *token)
+static int PC_UnreadSourceToken(source_t *source, token_t *token)
{
token_t *t;
@@ -368,10 +353,13 @@ int PC_UnreadSourceToken(source_t *source, token_t *token)
// Returns: -
// Changes Globals: -
//============================================================================
+define_t *PC_FindHashedDefine( define_t **definehash, const char *name );
+int PC_ExpandDefineIntoSource( source_t *source, token_t *deftoken, define_t *define );
int PC_ReadDefineParms(source_t *source, define_t *define, token_t **parms, int maxparms)
{
token_t token, *t, *last;
int i, done, lastcomma, numparms, indent;
+ define_t *newdefine;
if (!PC_ReadSourceToken(source, &token))
{
@@ -420,7 +408,7 @@ int PC_ReadDefineParms(source_t *source, define_t *define, token_t **parms, int
//
if (!strcmp(token.string, ","))
{
- if (indent <= 0)
+ if (indent <= 1)
{
if (lastcomma) SourceWarning(source, "too many comma's");
lastcomma = 1;
@@ -432,7 +420,6 @@ int PC_ReadDefineParms(source_t *source, define_t *define, token_t **parms, int
if (!strcmp(token.string, "("))
{
indent++;
- continue;
} //end if
else if (!strcmp(token.string, ")"))
{
@@ -446,6 +433,15 @@ int PC_ReadDefineParms(source_t *source, define_t *define, token_t **parms, int
break;
} //end if
} //end if
+ else if ( token.type == TT_NAME ) {
+ newdefine = PC_FindHashedDefine( source->definehash, token.string );
+ if ( newdefine ) {
+ if ( !PC_ExpandDefineIntoSource( source, &token, newdefine ) ) {
+ return qfalse;
+ }
+ continue;
+ }
+ } // end if
//
if (numparms < define->numparms)
{
@@ -467,20 +463,26 @@ int PC_ReadDefineParms(source_t *source, define_t *define, token_t **parms, int
// Returns: -
// Changes Globals: -
//============================================================================
-int PC_StringizeTokens(token_t *tokens, token_t *token)
+static int PC_StringizeTokens(const token_t *tokens, token_t *token)
{
- token_t *t;
+ const token_t *t;
+ int len, total;
token->type = TT_STRING;
token->whitespace_p = NULL;
token->endwhitespace_p = NULL;
- token->string[0] = '\0';
- strcat(token->string, "\"");
+ token->string[0] = '"';
+ total = 1;
for (t = tokens; t; t = t->next)
{
- strncat(token->string, t->string, MAX_TOKEN - strlen(token->string) - 1);
- } //end for
- strncat(token->string, "\"", MAX_TOKEN - strlen(token->string) - 1);
+ len = (int)strlen( t->string );
+ if ( len + total >= sizeof( token->string ) - 1 ) // reserve space for '"' and '\0'
+ return qfalse;
+ strcpy( token->string + total, t->string );
+ total += len;
+ }
+ strcpy( token->string + total, "\"" );
+
return qtrue;
} //end of the function PC_StringizeTokens
//============================================================================
@@ -489,19 +491,24 @@ int PC_StringizeTokens(token_t *tokens, token_t *token)
// Returns: -
// Changes Globals: -
//============================================================================
-int PC_MergeTokens(token_t *t1, token_t *t2)
+static int PC_MergeTokens(token_t *t1, const token_t *t2)
{
//merging of a name with a name or number
if (t1->type == TT_NAME && (t2->type == TT_NAME || t2->type == TT_NUMBER))
{
+ if ( strlen( t1->string ) + strlen( t2->string ) >= sizeof( t1->string ) )
+ return qfalse;
strcat(t1->string, t2->string);
return qtrue;
} //end if
//merging of two strings
if (t1->type == TT_STRING && t2->type == TT_STRING)
{
+ int len1 = (int)strlen( t1->string );
+ if ( strlen( t1->string ) + strlen( t2->string ) - 2 >= sizeof( t1->string ) )
+ return qfalse;
//remove trailing double quote
- t1->string[strlen(t1->string)-1] = '\0';
+ t1->string[len1-1] = '\0';
//concat without leading double quote
strcat(t1->string, &t2->string[1]);
return qtrue;
@@ -533,7 +540,7 @@ void PC_PrintDefine(define_t *define)
// Returns: -
// Changes Globals: -
//============================================================================
-void PC_PrintDefineHashTable(define_t **definehash)
+/*void PC_PrintDefineHashTable(define_t **definehash)
{
int i;
define_t *d;
@@ -547,7 +554,7 @@ void PC_PrintDefineHashTable(define_t **definehash)
} //end for
Log_Write("\n");
} //end for
-} //end of the function PC_PrintDefineHashTable
+}*/ //end of the function PC_PrintDefineHashTable
//============================================================================
//
// Parameter: -
@@ -556,7 +563,7 @@ void PC_PrintDefineHashTable(define_t **definehash)
//============================================================================
//char primes[16] = {1, 3, 5, 7, 11, 13, 17, 19, 23, 27, 29, 31, 37, 41, 43, 47};
-int PC_NameHash(char *name)
+int PC_NameHash(const char *name)
{
int hash, i;
@@ -580,7 +587,6 @@ void PC_AddDefineToHash(define_t *define, define_t **definehash)
{
int hash;
-
if ( addGlobalDefine )
{
definehash = globaldefines;
@@ -602,7 +608,7 @@ void PC_AddDefineToHash(define_t *define, define_t **definehash)
// Returns: -
// Changes Globals: -
//============================================================================
-define_t *PC_FindHashedDefine(define_t **definehash, char *name)
+define_t *PC_FindHashedDefine(define_t **definehash, const char *name)
{
define_t *d;
int hash;
@@ -621,7 +627,7 @@ define_t *PC_FindHashedDefine(define_t **definehash, char *name)
// Returns: -
// Changes Globals: -
//============================================================================
-define_t *PC_FindDefine(define_t *defines, char *name)
+define_t *PC_FindDefine(define_t *defines, const char *name)
{
define_t *d;
@@ -638,7 +644,7 @@ define_t *PC_FindDefine(define_t *defines, char *name)
// if no parm found with the given name -1 is returned
// Changes Globals: -
//============================================================================
-int PC_FindDefineParm(define_t *define, char *name)
+int PC_FindDefineParm(define_t *define, const char *name)
{
token_t *p;
int i;
@@ -683,7 +689,7 @@ void PC_FreeDefine(define_t *define)
// Returns: -
// Changes Globals: -
//============================================================================
-void PC_AddBuiltinDefines(source_t *source)
+/*void PC_AddBuiltinDefines(source_t *source)
{
int i;
define_t *define;
@@ -716,7 +722,7 @@ void PC_AddBuiltinDefines(source_t *source)
source->defines = define;
#endif //DEFINEHASHING
} //end for
-} //end of the function PC_AddBuiltinDefines
+}*/ //end of the function PC_AddBuiltinDefines
//============================================================================
//
// Parameter: -
@@ -750,7 +756,7 @@ int PC_ExpandBuiltinDefine(source_t *source, token_t *deftoken, define_t *define
{
strcpy(token->string, source->scriptstack->filename);
token->type = TT_NAME;
- token->subtype = strlen(token->string);
+ token->subtype = (int)strlen(token->string);
*firsttoken = token;
*lasttoken = token;
break;
@@ -759,13 +765,20 @@ int PC_ExpandBuiltinDefine(source_t *source, token_t *deftoken, define_t *define
{
t = time(NULL);
curtime = ctime(&t);
- strcpy(token->string, "\"");
- strncat(token->string, curtime+4, 7);
- strncat(token->string+7, curtime+20, 4);
- strcat(token->string, "\"");
- free(curtime);
+ if ( strlen( curtime ) < 24 )
+ {
+ strcpy( token->string, "*** BAD CURTIME ***" );
+ }
+ else
+ {
+ strcpy(token->string, "\"");
+ strncat(token->string, curtime+4, 7);
+ strncat(token->string+7, curtime+20, 4);
+ strcat(token->string, "\"");
+ }
+ //free(curtime);
token->type = TT_NAME;
- token->subtype = strlen(token->string);
+ token->subtype = (int)strlen(token->string);
*firsttoken = token;
*lasttoken = token;
break;
@@ -774,17 +787,30 @@ int PC_ExpandBuiltinDefine(source_t *source, token_t *deftoken, define_t *define
{
t = time(NULL);
curtime = ctime(&t);
- strcpy(token->string, "\"");
- strncat(token->string, curtime+11, 8);
- strcat(token->string, "\"");
- free(curtime);
+ if ( strlen( curtime ) < 24 )
+ {
+ strcpy( token->string, "*** BAD CURTIME ***" );
+ }
+ else
+ {
+ strcpy(token->string, "\"");
+ strncat(token->string, curtime+11, 8);
+ strcat(token->string, "\"");
+ }
+ //free(curtime);
token->type = TT_NAME;
- token->subtype = strlen(token->string);
+ token->subtype = (int)strlen(token->string);
*firsttoken = token;
*lasttoken = token;
break;
} //end case
case BUILTIN_STDC:
+ {
+ SourceWarning( source, "__STDC__ not supported" );
+ *firsttoken = NULL;
+ *lasttoken = NULL;
+ break;
+ } //end case
default:
{
*firsttoken = NULL;
@@ -803,7 +829,7 @@ int PC_ExpandBuiltinDefine(source_t *source, token_t *deftoken, define_t *define
int PC_ExpandDefine(source_t *source, token_t *deftoken, define_t *define,
token_t **firsttoken, token_t **lasttoken)
{
- token_t *parms[MAX_DEFINEPARMS], *dt, *pt, *t;
+ token_t *parms[MAX_DEFINEPARMS] = { NULL }, *dt, *pt, *t;
token_t *t1, *t2, *first, *last, *nextpt, token;
int parmnum, i;
@@ -958,7 +984,7 @@ int PC_ExpandDefineIntoSource(source_t *source, token_t *deftoken, define_t *def
// Returns: -
// Changes Globals: -
//============================================================================
-void PC_ConvertPath(char *path)
+static void PC_ConvertPath(char *path)
{
char *ptr;
@@ -992,7 +1018,7 @@ int PC_Directive_include(source_t *source)
{
script_t *script;
token_t token;
- char path[MAX_PATH];
+ char path[MAX_QPATH];
#ifdef QUAKE
foundfile_t file;
#endif //QUAKE
@@ -1341,7 +1367,7 @@ int PC_Directive_define(source_t *source)
// Returns: -
// Changes Globals: -
//============================================================================
-define_t *PC_DefineFromString(char *string)
+define_t *PC_DefineFromString(const char *string)
{
script_t *script;
source_t src;
@@ -1349,12 +1375,10 @@ define_t *PC_DefineFromString(char *string)
int res, i;
define_t *def;
- PC_InitTokenHeap();
-
- script = LoadScriptMemory(string, strlen(string), "*extern");
+ script = LoadScriptMemory(string, (int)strlen(string), "*extern");
//create a new source
Com_Memset(&src, 0, sizeof(source_t));
- strncpy(src.filename, "*extern", MAX_PATH);
+ Q_strncpyz(src.filename, "*extern", sizeof(src.filename));
src.scriptstack = script;
#if DEFINEHASHING
src.definehash = (struct define_s **)GetClearedMemory(DEFINEHASHSIZE * sizeof(define_t *));
@@ -1388,7 +1412,7 @@ define_t *PC_DefineFromString(char *string)
FreeScript(script);
//if the define was created successfully
if (res > 0) return def;
- //free the define is created
+ //free the define if created
if (src.defines) PC_FreeDefine(def);
//
return NULL;
@@ -1399,7 +1423,7 @@ define_t *PC_DefineFromString(char *string)
// Returns: -
// Changes Globals: -
//============================================================================
-int PC_AddDefine(source_t *source, char *string)
+/*int PC_AddDefine(source_t *source, char *string)
{
define_t *define;
@@ -1417,7 +1441,7 @@ int PC_AddDefine(source_t *source, char *string)
source->defines = define;
#endif //DEFINEHASHING
return qtrue;
-} //end of the function PC_AddDefine
+}*/ //end of the function PC_AddDefine
//============================================================================
// add a globals define that will be added to all opened sources
//
@@ -1425,13 +1449,16 @@ int PC_AddDefine(source_t *source, char *string)
// Returns: -
// Changes Globals: -
//============================================================================
-int PC_AddGlobalDefine(char *string)
+int PC_AddGlobalDefine(const char *string)
{
-#if !DEFINEHASHING
- define_t *define;
-
- define = PC_DefineFromString(string);
+ define_t *define = PC_DefineFromString(string);
if (!define) return qfalse;
+#if DEFINEHASHING
+ qboolean savedAGD = addGlobalDefine;
+ addGlobalDefine = qtrue;
+ PC_AddDefineToHash(define, NULL);
+ addGlobalDefine = savedAGD;
+#else
define->next = globaldefines;
globaldefines = define;
#endif
@@ -1444,7 +1471,7 @@ int PC_AddGlobalDefine(char *string)
// Returns: -
// Changes Globals: -
//============================================================================
-int PC_RemoveGlobalDefine(char *name)
+/*int PC_RemoveGlobalDefine(char *name)
{
#if !DEFINEHASHING
define_t *define;
@@ -1457,7 +1484,7 @@ int PC_RemoveGlobalDefine(char *name)
} //end if
#endif
return qfalse;
-} //end of the function PC_RemoveGlobalDefine
+}*/ //end of the function PC_RemoveGlobalDefine
//============================================================================
// remove all globals defines
//
@@ -1497,7 +1524,7 @@ void PC_RemoveAllGlobalDefines(void)
// Returns: -
// Changes Globals: -
//============================================================================
-define_t *PC_CopyDefine(source_t *source, define_t *define)
+define_t *PC_CopyDefine(define_t *define)
{
define_t *newdefine;
token_t *token, *newtoken, *lasttoken;
@@ -1561,7 +1588,7 @@ void PC_AddGlobalDefinesToSource(source_t *source)
define_t* newdefine;
for (define = globaldefines; define; define = define->next)
{
- newdefine = PC_CopyDefine(source, define);
+ newdefine = PC_CopyDefine(define);
@@ -1576,7 +1603,7 @@ void PC_AddGlobalDefinesToSource(source_t *source)
// Returns: -
// Changes Globals: -
//============================================================================
-int PC_Directive_if_def(source_t *source, int type)
+static int PC_Directive_if_def(source_t *source, int type)
{
token_t token;
define_t *d;
@@ -1628,6 +1655,65 @@ int PC_Directive_ifndef(source_t *source)
// Returns: -
// Changes Globals: -
//============================================================================
+static int PC_Directive_elif_def( source_t *source, int type )
+{
+ token_t token;
+ define_t *d;
+ int skip, checktype;
+
+ PC_PopIndent(source, &checktype, &skip);
+ if (!checktype || checktype == INDENT_ELSE)
+ {
+ SourceError(source, "misplaced #elifdef");
+ return qfalse;
+ } //end if
+
+ if (!PC_ReadLine(source, &token))
+ {
+ SourceError(source, "#elifdef without name");
+ return qfalse;
+ } //end if
+ if (token.type != TT_NAME)
+ {
+ PC_UnreadSourceToken(source, &token);
+ SourceError(source, "expected name after #elifdef, found %s", token.string);
+ return qfalse;
+ } //end if
+#if DEFINEHASHING
+ d = PC_FindHashedDefine(source->definehash, token.string);
+#else
+ d = PC_FindDefine(source->defines, token.string);
+#endif //DEFINEHASHING
+ skip = (type == INDENT_ELIFDEF) == (d == NULL);
+ PC_PushIndent(source, type, skip);
+ return qtrue;
+} //end of the function PC_Directive_elif_def
+//============================================================================
+//
+// Parameter: -
+// Returns: -
+// Changes Globals: -
+//============================================================================
+int PC_Directive_elifdef(source_t *source)
+{
+ return PC_Directive_elif_def(source, INDENT_ELIFDEF);
+} //end of the function PC_Directive_elifdef
+//============================================================================
+//
+// Parameter: -
+// Returns: -
+// Changes Globals: -
+//============================================================================
+int PC_Directive_elifndef(source_t *source)
+{
+ return PC_Directive_elif_def(source, INDENT_ELIFNDEF);
+} //end of the function PC_Directive_elifndef
+//============================================================================
+//
+// Parameter: -
+// Returns: -
+// Changes Globals: -
+//============================================================================
int PC_Directive_else(source_t *source)
{
int type, skip;
@@ -1680,8 +1766,8 @@ typedef struct operator_s
typedef struct value_s
{
- signed long int intvalue;
- double floatvalue;
+ signed int intvalue;
+ float floatvalue;
int parentheses;
struct value_s *prev, *next;
} value_t;
@@ -1743,8 +1829,8 @@ int PC_OperatorPriority(int op)
op = &operator_heap[numoperators++];
#define FreeOperator(op)
-int PC_EvaluateTokens(source_t *source, token_t *tokens, signed long int *intvalue,
- double *floatvalue, int integer)
+int PC_EvaluateTokens(source_t *source, token_t *tokens, signed int *intvalue,
+ float *floatvalue, int integer)
{
operator_t *o, *firstoperator, *lastoperator;
value_t *v, *firstvalue, *lastvalue, *v1, *v2;
@@ -1755,7 +1841,7 @@ int PC_EvaluateTokens(source_t *source, token_t *tokens, signed long int *intval
int lastwasvalue = 0;
int negativevalue = 0;
int questmarkintvalue = 0;
- double questmarkfloatvalue = 0;
+ float questmarkfloatvalue = 0;
int gotquestmarkvalue = qfalse;
//
operator_t operator_heap[MAX_OPERATORS];
@@ -1846,7 +1932,7 @@ int PC_EvaluateTokens(source_t *source, token_t *tokens, signed long int *intval
AllocValue(v);
if (negativevalue)
{
- v->intvalue = - (signed int) t->intvalue;
+ v->intvalue = -(signed int)(t->intvalue);
v->floatvalue = - t->floatvalue;
} //end if
else
@@ -2090,9 +2176,9 @@ int PC_EvaluateTokens(source_t *source, token_t *tokens, signed long int *intval
case P_LOGIC_LEQ: v1->intvalue = v1->intvalue <= v2->intvalue;
v1->floatvalue = v1->floatvalue <= v2->floatvalue; break;
case P_LOGIC_EQ: v1->intvalue = v1->intvalue == v2->intvalue;
- v1->floatvalue = v1->floatvalue == v2->floatvalue; break;
+ v1->floatvalue = fabsf(v1->floatvalue - v2->floatvalue) < 0.0001f; break;
case P_LOGIC_UNEQ: v1->intvalue = v1->intvalue != v2->intvalue;
- v1->floatvalue = v1->floatvalue != v2->floatvalue; break;
+ v1->floatvalue = fabsf(v1->floatvalue - v2->floatvalue) > 0.0001f; break;
case P_LOGIC_GREATER: v1->intvalue = v1->intvalue > v2->intvalue;
v1->floatvalue = v1->floatvalue > v2->floatvalue; break;
case P_LOGIC_LESS: v1->intvalue = v1->intvalue < v2->intvalue;
@@ -2195,8 +2281,8 @@ int PC_EvaluateTokens(source_t *source, token_t *tokens, signed long int *intval
// Returns: -
// Changes Globals: -
//============================================================================
-int PC_Evaluate(source_t *source, signed long int *intvalue,
- double *floatvalue, int integer)
+int PC_Evaluate(source_t *source, signed int *intvalue,
+ float *floatvalue, int integer)
{
token_t token, *firsttoken, *lasttoken;
token_t *t, *nexttoken;
@@ -2294,8 +2380,8 @@ int PC_Evaluate(source_t *source, signed long int *intvalue,
// Returns: -
// Changes Globals: -
//============================================================================
-int PC_DollarEvaluate(source_t *source, signed long int *intvalue,
- double *floatvalue, int integer)
+int PC_DollarEvaluate(source_t *source, signed int *intvalue,
+ float *floatvalue, int integer)
{
int indent, defined = qfalse;
token_t token, *firsttoken, *lasttoken;
@@ -2404,7 +2490,7 @@ int PC_DollarEvaluate(source_t *source, signed long int *intvalue,
//============================================================================
int PC_Directive_elif(source_t *source)
{
- signed long int value;
+ int value;
int type, skip;
PC_PopIndent(source, &type, &skip);
@@ -2426,7 +2512,7 @@ int PC_Directive_elif(source_t *source)
//============================================================================
int PC_Directive_if(source_t *source)
{
- signed long int value;
+ int value;
int skip;
if (!PC_Evaluate(source, &value, NULL, qtrue)) return qfalse;
@@ -2455,7 +2541,7 @@ int PC_Directive_error(source_t *source)
{
token_t token;
- strcpy(token.string, "");
+ token.string[0] = '\0';
PC_ReadSourceToken(source, &token);
SourceError(source, "#error directive: %s", token.string);
return qfalse;
@@ -2466,6 +2552,21 @@ int PC_Directive_error(source_t *source)
// Returns: -
// Changes Globals: -
//============================================================================
+int PC_Directive_warning(source_t *source)
+{
+ token_t token;
+
+ token.string[0] = '\0';
+ PC_ReadSourceToken(source, &token);
+ SourceWarning(source, "#warning directive: %s", token.string);
+ return qtrue;
+} //end of the function PC_Directive_warning
+//============================================================================
+//
+// Parameter: -
+// Returns: -
+// Changes Globals: -
+//============================================================================
int PC_Directive_pragma(source_t *source)
{
token_t token;
@@ -2480,6 +2581,20 @@ int PC_Directive_pragma(source_t *source)
// Returns: -
// Changes Globals: -
//============================================================================
+int PC_Directive_embed(source_t *source)
+{
+ token_t token;
+
+ SourceWarning(source, "#embed directive not supported");
+ while(PC_ReadLine(source, &token)) ;
+ return qtrue;
+} //end of the function PC_Directive_embed
+//============================================================================
+//
+// Parameter: -
+// Returns: -
+// Changes Globals: -
+//============================================================================
void UnreadSignToken(source_t *source)
{
token_t token;
@@ -2501,7 +2616,7 @@ void UnreadSignToken(source_t *source)
//============================================================================
int PC_Directive_eval(source_t *source)
{
- signed long int value;
+ signed int value;
token_t token;
if (!PC_Evaluate(source, &value, NULL, qtrue)) return qfalse;
@@ -2510,7 +2625,7 @@ int PC_Directive_eval(source_t *source)
token.whitespace_p = source->scriptstack->script_p;
token.endwhitespace_p = source->scriptstack->script_p;
token.linescrossed = 0;
- sprintf(token.string, "%ld", labs(value));
+ sprintf(token.string, "%d", abs(value));
token.type = TT_NUMBER;
token.subtype = TT_INTEGER|TT_LONG|TT_DECIMAL;
PC_UnreadSourceToken(source, &token);
@@ -2525,7 +2640,7 @@ int PC_Directive_eval(source_t *source)
//============================================================================
int PC_Directive_evalfloat(source_t *source)
{
- double value;
+ float value;
token_t token;
if (!PC_Evaluate(source, NULL, &value, qfalse)) return qfalse;
@@ -2533,7 +2648,7 @@ int PC_Directive_evalfloat(source_t *source)
token.whitespace_p = source->scriptstack->script_p;
token.endwhitespace_p = source->scriptstack->script_p;
token.linescrossed = 0;
- sprintf(token.string, "%1.2f", fabs(value));
+ sprintf(token.string, "%1.2f", Q_fabs(value));
token.type = TT_NUMBER;
token.subtype = TT_FLOAT|TT_LONG|TT_DECIMAL;
PC_UnreadSourceToken(source, &token);
@@ -2546,12 +2661,14 @@ int PC_Directive_evalfloat(source_t *source)
// Returns: -
// Changes Globals: -
//============================================================================
-directive_t directives[20] =
+static const directive_t directives[] =
{
{"if", PC_Directive_if},
{"ifdef", PC_Directive_ifdef},
{"ifndef", PC_Directive_ifndef},
{"elif", PC_Directive_elif},
+ {"elifdef", PC_Directive_elifdef},
+ {"elifndef", PC_Directive_elifndef},
{"else", PC_Directive_else},
{"endif", PC_Directive_endif},
{"include", PC_Directive_include},
@@ -2559,7 +2676,9 @@ directive_t directives[20] =
{"undef", PC_Directive_undef},
{"line", PC_Directive_line},
{"error", PC_Directive_error},
+ {"warning", PC_Directive_warning},
{"pragma", PC_Directive_pragma},
+ {"embed", PC_Directive_embed},
{"eval", PC_Directive_eval},
{"evalfloat", PC_Directive_evalfloat},
{NULL, NULL}
@@ -2606,7 +2725,7 @@ int PC_ReadDirective(source_t *source)
//============================================================================
int PC_DollarDirective_evalint(source_t *source)
{
- signed long int value;
+ signed int value;
token_t token;
if (!PC_DollarEvaluate(source, &value, NULL, qtrue)) return qfalse;
@@ -2615,13 +2734,13 @@ int PC_DollarDirective_evalint(source_t *source)
token.whitespace_p = source->scriptstack->script_p;
token.endwhitespace_p = source->scriptstack->script_p;
token.linescrossed = 0;
- sprintf(token.string, "%ld", labs(value));
+ sprintf(token.string, "%d", abs(value));
token.type = TT_NUMBER;
token.subtype = TT_INTEGER|TT_LONG|TT_DECIMAL;
#ifdef NUMBERVALUE
- token.intvalue = labs(value);
- token.floatvalue = token.intvalue;
+ token.intvalue = value;
+ token.floatvalue = value;
#endif //NUMBERVALUE
PC_UnreadSourceToken(source, &token);
@@ -2638,7 +2757,7 @@ int PC_DollarDirective_evalint(source_t *source)
//============================================================================
int PC_DollarDirective_evalfloat(source_t *source)
{
- double value;
+ float value;
token_t token;
if (!PC_DollarEvaluate(source, NULL, &value, qfalse)) return qfalse;
@@ -2646,13 +2765,13 @@ int PC_DollarDirective_evalfloat(source_t *source)
token.whitespace_p = source->scriptstack->script_p;
token.endwhitespace_p = source->scriptstack->script_p;
token.linescrossed = 0;
- sprintf(token.string, "%1.2f", fabs(value));
+ sprintf(token.string, "%1.2f", Q_fabs(value));
token.type = TT_NUMBER;
token.subtype = TT_FLOAT|TT_LONG|TT_DECIMAL;
#ifdef NUMBERVALUE
- token.floatvalue = fabs(value);
- token.intvalue = (unsigned long) token.floatvalue;
+ token.intvalue = (unsigned int) value;
+ token.floatvalue = value;
#endif //NUMBERVALUE
PC_UnreadSourceToken(source, &token);
@@ -2667,7 +2786,7 @@ int PC_DollarDirective_evalfloat(source_t *source)
// Returns: -
// Changes Globals: -
//============================================================================
-directive_t dollardirectives[20] =
+static const directive_t dollardirectives[] =
{
{"evalint", PC_DollarDirective_evalint},
{"evalfloat", PC_DollarDirective_evalfloat},
@@ -2810,6 +2929,10 @@ int PC_ReadToken(source_t *source, token_t *token)
continue;
} //end if
} //end if
+ //if skipping source because of conditional compilation
+ if ( source->skip ) {
+ continue;
+ }
// recursively concatenate strings that are behind each other still resolving defines
if (token->type == TT_STRING)
{
@@ -2832,8 +2955,6 @@ int PC_ReadToken(source_t *source, token_t *token)
}
}
} //end if
- //if skipping source because of conditional compilation
- if (source->skip) continue;
//if the token is a name
if (token->type == TT_NAME)
{
@@ -2863,7 +2984,7 @@ int PC_ReadToken(source_t *source, token_t *token)
// Returns: -
// Changes Globals: -
//============================================================================
-int PC_ExpectTokenString(source_t *source, char *string)
+int PC_ExpectTokenString(source_t *source, const char *string)
{
token_t token;
@@ -2958,7 +3079,7 @@ int PC_ExpectAnyToken(source_t *source, token_t *token)
// Returns: -
// Changes Globals: -
//============================================================================
-int PC_CheckTokenString(source_t *source, char *string)
+int PC_CheckTokenString(source_t *source, const char *string)
{
token_t tok;
@@ -2975,7 +3096,7 @@ int PC_CheckTokenString(source_t *source, char *string)
// Returns: -
// Changes Globals: -
//============================================================================
-int PC_CheckTokenType(source_t *source, int type, int subtype, token_t *token)
+/*int PC_CheckTokenType(source_t *source, int type, int subtype, token_t *token)
{
token_t tok;
@@ -2990,14 +3111,14 @@ int PC_CheckTokenType(source_t *source, int type, int subtype, token_t *token)
//
PC_UnreadSourceToken(source, &tok);
return qfalse;
-} //end of the function PC_CheckTokenType
+}*/ //end of the function PC_CheckTokenType
//============================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//============================================================================
-int PC_SkipUntilString(source_t *source, char *string)
+/*int PC_SkipUntilString(source_t *source, char *string)
{
token_t token;
@@ -3006,7 +3127,7 @@ int PC_SkipUntilString(source_t *source, char *string)
if (!strcmp(token.string, string)) return qtrue;
} //end while
return qfalse;
-} //end of the function PC_SkipUntilString
+}*/ //end of the function PC_SkipUntilString
//============================================================================
//
// Parameter: -
@@ -3033,7 +3154,7 @@ void PC_UnreadToken(source_t *source, token_t *token)
// Returns: -
// Changes Globals: -
//============================================================================
-void PC_SetIncludePath(source_t *source, char *path)
+/*void PC_SetIncludePath(source_t *source, char *path)
{
size_t len;
@@ -3046,7 +3167,7 @@ void PC_SetIncludePath(source_t *source, char *path)
{
strcat(source->includepath, PATHSEPERATOR_STR);
} //end if
-} //end of the function PC_SetIncludePath
+}*/ //end of the function PC_SetIncludePath
//============================================================================
//
// Parameter: -
@@ -3068,8 +3189,6 @@ source_t *LoadSourceFile(const char *filename)
source_t *source;
script_t *script;
- PC_InitTokenHeap();
-
#if DEFINEHASHING
if ( !globaldefines )
{
@@ -3085,7 +3204,7 @@ source_t *LoadSourceFile(const char *filename)
source = (source_t *) GetMemory(sizeof(source_t));
Com_Memset(source, 0, sizeof(source_t));
- strncpy(source->filename, filename, MAX_PATH);
+ Q_strncpyz(source->filename, filename, sizeof(source->filename));
source->scriptstack = script;
source->tokens = NULL;
source->defines = NULL;
@@ -3104,13 +3223,11 @@ source_t *LoadSourceFile(const char *filename)
// Returns: -
// Changes Globals: -
//============================================================================
-source_t *LoadSourceMemory(char *ptr, int length, char *name)
+/*source_t *LoadSourceMemory(char *ptr, int length, char *name)
{
source_t *source;
script_t *script;
- PC_InitTokenHeap();
-
script = LoadScriptMemory(ptr, length, name);
if (!script) return NULL;
script->next = NULL;
@@ -3130,7 +3247,7 @@ source_t *LoadSourceMemory(char *ptr, int length, char *name)
#endif //DEFINEHASHING
PC_AddGlobalDefinesToSource(source);
return source;
-} //end of the function LoadSourceMemory
+}*/ //end of the function LoadSourceMemory
//============================================================================
//
// Parameter: -
@@ -3211,7 +3328,7 @@ void FreeSource(source_t *source)
#define MAX_SOURCEFILES 64
-source_t *sourceFiles[MAX_SOURCEFILES];
+static source_t *sourceFiles[MAX_SOURCEFILES];
int PC_LoadSourceHandle(const char *filename)
{
@@ -3324,7 +3441,7 @@ int PC_SourceFileAndLine(int handle, char *filename, int *line)
// Returns: -
// Changes Globals: -
//============================================================================
-void PC_SetBaseFolder(char *path)
+void PC_SetBaseFolder(const char *path)
{
PS_SetBaseFolder(path);
} //end of the function PC_SetBaseFolder
diff --git a/codemp/botlib/l_precomp.h b/codemp/botlib/l_precomp.h
index b1731c11..b4aca64f 100644
--- a/codemp/botlib/l_precomp.h
+++ b/codemp/botlib/l_precomp.h
@@ -61,7 +61,7 @@ along with this program; if not, see <http://www.gnu.org/licenses/>.
#define DEFINE_FIXED 0x0001
-#define DEFINE_GLOBAL 0x0002
+#define DEFINE_GLOBAL 0x0002
#define BUILTIN_LINE 1
#define BUILTIN_FILE 2
@@ -74,6 +74,8 @@ along with this program; if not, see <http://www.gnu.org/licenses/>.
#define INDENT_ELIF 0x0004
#define INDENT_IFDEF 0x0008
#define INDENT_IFNDEF 0x0010
+#define INDENT_ELIFDEF 0x0020
+#define INDENT_ELIFNDEF 0x0040
//macro definitions
typedef struct define_s
@@ -86,7 +88,7 @@ typedef struct define_s
token_t *tokens; //macro tokens (possibly containing parm tokens)
struct define_s *next; //next defined macro in a list
struct define_s *hashnext; //next define in the hash chain
- struct define_s *globalnext; //used to link up the globald defines
+ struct define_s *globalnext; //used to link up the global defines
} define_t;
//indents
@@ -119,17 +121,17 @@ typedef struct source_s
//read a token from the source
int PC_ReadToken(source_t *source, token_t *token);
//expect a certain token
-int PC_ExpectTokenString(source_t *source, char *string);
+int PC_ExpectTokenString(source_t *source, const char *string);
//expect a certain token type
int PC_ExpectTokenType(source_t *source, int type, int subtype, token_t *token);
//expect a token
int PC_ExpectAnyToken(source_t *source, token_t *token);
//returns true when the token is available
-int PC_CheckTokenString(source_t *source, char *string);
+int PC_CheckTokenString(source_t *source, const char *string);
//returns true and reads the token when a token with the given type is available
-int PC_CheckTokenType(source_t *source, int type, int subtype, token_t *token);
+//int PC_CheckTokenType(source_t *source, int type, int subtype, token_t *token);
//skip tokens until the given token string is read
-int PC_SkipUntilString(source_t *source, char *string);
+//int PC_SkipUntilString(source_t *source, char *string);
//unread the last token read from the script
void PC_UnreadLastToken(source_t *source);
//unread the given token
@@ -139,31 +141,33 @@ int PC_ReadLine(source_t *source, token_t *token);
//returns true if there was a white space in front of the token
int PC_WhiteSpaceBeforeToken(token_t *token);
//add a define to the source
-int PC_AddDefine(source_t *source, char *string);
+//int PC_AddDefine(source_t *source, char *string);
//add a globals define that will be added to all opened sources
-int PC_AddGlobalDefine(char *string);
+int PC_AddGlobalDefine(const char *string);
//remove the given global define
-int PC_RemoveGlobalDefine(char *name);
+//int PC_RemoveGlobalDefine(char *name);
//remove all globals defines
void PC_RemoveAllGlobalDefines(void);
//add builtin defines
-void PC_AddBuiltinDefines(source_t *source);
+//void PC_AddBuiltinDefines(source_t *source);
//set the source include path
-void PC_SetIncludePath(source_t *source, char *path);
+//void PC_SetIncludePath(source_t *source, const char *path);
//set the punction set
-void PC_SetPunctuations(source_t *source, punctuation_t *p);
+//void PC_SetPunctuations(source_t *source, punctuation_t *p);
//set the base folder to load files from
-void PC_SetBaseFolder(char *path);
+void PC_SetBaseFolder(const char *path);
//load a source file
source_t *LoadSourceFile(const char *filename);
//load a source from memory
-source_t *LoadSourceMemory(char *ptr, int length, char *name);
+//source_t *LoadSourceMemory(char *ptr, int length, char *name);
//free the given source
void FreeSource(source_t *source);
//print a source error
-void QDECL SourceError(source_t *source, char *str, ...);
+void QDECL SourceError(source_t *source, const char *str, ...);
//print a source warning
-void QDECL SourceWarning(source_t *source, char *str, ...);
+void QDECL SourceWarning(source_t *source, const char *str, ...);
+
+void PC_Init( void );
#ifdef BSPC
// some of BSPC source does include qcommon/q_shared.h and some does not
diff --git a/codemp/botlib/l_script.cpp b/codemp/botlib/l_script.cpp
index ab49c8c6..d89e5935 100644
--- a/codemp/botlib/l_script.cpp
+++ b/codemp/botlib/l_script.cpp
@@ -88,85 +88,89 @@ typedef enum {qfalse, qtrue} qboolean;
#define PUNCTABLE
//longer punctuations first
-punctuation_t default_punctuations[] =
+static punctuation_t default_punctuations[] =
{
//binary operators
- {">>=",P_RSHIFT_ASSIGN, NULL},
- {"<<=",P_LSHIFT_ASSIGN, NULL},
+ {">>=",P_RSHIFT_ASSIGN},
+ {"<<=",P_LSHIFT_ASSIGN},
//
- {"...",P_PARMS, NULL},
+ {"...",P_PARMS},
//define merge operator
- {"##",P_PRECOMPMERGE, NULL},
+ {"##",P_PRECOMPMERGE},
//logic operators
- {"&&",P_LOGIC_AND, NULL},
- {"||",P_LOGIC_OR, NULL},
- {">=",P_LOGIC_GEQ, NULL},
- {"<=",P_LOGIC_LEQ, NULL},
- {"==",P_LOGIC_EQ, NULL},
- {"!=",P_LOGIC_UNEQ, NULL},
+ {"&&",P_LOGIC_AND},
+ {"||",P_LOGIC_OR},
+ {">=",P_LOGIC_GEQ},
+ {"<=",P_LOGIC_LEQ},
+ {"==",P_LOGIC_EQ},
+ {"!=",P_LOGIC_UNEQ},
//arithmatic operators
- {"*=",P_MUL_ASSIGN, NULL},
- {"/=",P_DIV_ASSIGN, NULL},
- {"%=",P_MOD_ASSIGN, NULL},
- {"+=",P_ADD_ASSIGN, NULL},
- {"-=",P_SUB_ASSIGN, NULL},
- {"++",P_INC, NULL},
- {"--",P_DEC, NULL},
+ {"*=",P_MUL_ASSIGN},
+ {"/=",P_DIV_ASSIGN},
+ {"%=",P_MOD_ASSIGN},
+ {"+=",P_ADD_ASSIGN},
+ {"-=",P_SUB_ASSIGN},
+ {"++",P_INC},
+ {"--",P_DEC},
//binary operators
- {"&=",P_BIN_AND_ASSIGN, NULL},
- {"|=",P_BIN_OR_ASSIGN, NULL},
- {"^=",P_BIN_XOR_ASSIGN, NULL},
- {">>",P_RSHIFT, NULL},
- {"<<",P_LSHIFT, NULL},
+ {"&=",P_BIN_AND_ASSIGN},
+ {"|=",P_BIN_OR_ASSIGN},
+ {"^=",P_BIN_XOR_ASSIGN},
+ {">>",P_RSHIFT},
+ {"<<",P_LSHIFT},
//reference operators
- {"->",P_POINTERREF, NULL},
+ {"->",P_POINTERREF},
//C++
- {"::",P_CPP1, NULL},
- {".*",P_CPP2, NULL},
+ {"::",P_CPP1},
+ {".*",P_CPP2},
//arithmatic operators
- {"*",P_MUL, NULL},
- {"/",P_DIV, NULL},
- {"%",P_MOD, NULL},
- {"+",P_ADD, NULL},
- {"-",P_SUB, NULL},
- {"=",P_ASSIGN, NULL},
+ {"*",P_MUL},
+ {"/",P_DIV},
+ {"%",P_MOD},
+ {"+",P_ADD},
+ {"-",P_SUB},
+ {"=",P_ASSIGN},
//binary operators
- {"&",P_BIN_AND, NULL},
- {"|",P_BIN_OR, NULL},
- {"^",P_BIN_XOR, NULL},
- {"~",P_BIN_NOT, NULL},
+ {"&",P_BIN_AND},
+ {"|",P_BIN_OR},
+ {"^",P_BIN_XOR},
+ {"~",P_BIN_NOT},
//logic operators
- {"!",P_LOGIC_NOT, NULL},
- {">",P_LOGIC_GREATER, NULL},
- {"<",P_LOGIC_LESS, NULL},
+ {"!",P_LOGIC_NOT},
+ {">",P_LOGIC_GREATER},
+ {"<",P_LOGIC_LESS},
//reference operator
- {".",P_REF, NULL},
+ {".",P_REF},
//seperators
- {",",P_COMMA, NULL},
- {";",P_SEMICOLON, NULL},
+ {",",P_COMMA},
+ {";",P_SEMICOLON},
//label indication
- {":",P_COLON, NULL},
+ {":",P_COLON},
//if statement
- {"?",P_QUESTIONMARK, NULL},
+ {"?",P_QUESTIONMARK},
//embracements
- {"(",P_PARENTHESESOPEN, NULL},
- {")",P_PARENTHESESCLOSE, NULL},
- {"{",P_BRACEOPEN, NULL},
- {"}",P_BRACECLOSE, NULL},
- {"[",P_SQBRACKETOPEN, NULL},
- {"]",P_SQBRACKETCLOSE, NULL},
+ {"(",P_PARENTHESESOPEN},
+ {")",P_PARENTHESESCLOSE},
+ {"{",P_BRACEOPEN},
+ {"}",P_BRACECLOSE},
+ {"[",P_SQBRACKETOPEN},
+ {"]",P_SQBRACKETCLOSE},
//
- {"\\",P_BACKSLASH, NULL},
+ {"\\",P_BACKSLASH},
//precompiler operator
- {"#",P_PRECOMP, NULL},
+ {"#",P_PRECOMP},
#ifdef DOLLAR
- {"$",P_DOLLAR, NULL},
+ {"$",P_DOLLAR},
#endif //DOLLAR
// StringEd key
- {"@",P_ATSIGN, NULL},
+ {"@",P_ATSIGN},
{NULL, 0}
};
+static int default_punctuationtable[256];
+static int default_nextpunctuation[ARRAY_LEN(default_punctuations)];
+static qboolean default_setup;
+
#ifdef BSPC
char basefolder[MAX_PATH];
#else
@@ -179,39 +183,66 @@ char basefolder[MAX_QPATH];
// Returns: -
// Changes Globals: -
//===========================================================================
-void PS_CreatePunctuationTable(script_t *script, punctuation_t *punctuations)
+void PS_CreatePunctuationTable(script_t *script, const punctuation_t *punctuations)
{
- int i;
- punctuation_t *p, *lastp, *newp;
+ int i, n, lastp;
+ const punctuation_t *p, *newp;
//get memory for the table
- if (!script->punctuationtable) script->punctuationtable = (punctuation_t **)
- GetMemory(256 * sizeof(punctuation_t *));
- Com_Memset(script->punctuationtable, 0, 256 * sizeof(punctuation_t *));
+ if ( punctuations == default_punctuations ) {
+ script->punctuationtable = default_punctuationtable;
+ script->nextpunctuation = default_nextpunctuation;
+ if ( default_setup ) {
+ return;
+ }
+ default_setup = qtrue;
+ i = (int)ARRAY_LEN(default_punctuations);
+ }
+ else {
+ if ( !script->punctuationtable || script->punctuationtable == default_punctuationtable ) {
+ script->punctuationtable = (int *)GetMemory( 256 * sizeof( int ) );
+ }
+ if ( script->nextpunctuation && script->nextpunctuation != default_nextpunctuation ) {
+ FreeMemory( script->nextpunctuation );
+ }
+ for( i = 0; punctuations[i].p; i++ )
+ {
+ }
+ script->nextpunctuation = (int *) GetMemory( i * sizeof( int ) );
+ }
+ memset( script->punctuationtable, 0xFF, 256 * sizeof( int ) );
+ memset( script->nextpunctuation, 0xFF, i * sizeof( int ) );
//add the punctuations in the list to the punctuation table
- for (i = 0; punctuations[i].p; i++)
+ for ( i = 0; punctuations[i].p; i++ )
{
newp = &punctuations[i];
- lastp = NULL;
+ lastp = -1;
//sort the punctuations in this table entry on length (longer punctuations first)
- for (p = script->punctuationtable[(unsigned int) newp->p[0]]; p; p = p->next)
+ for ( n = script->punctuationtable[(unsigned int) newp->p[0]]; n >= 0; n = script->nextpunctuation[n] )
{
- if (strlen(p->p) < strlen(newp->p))
- {
- newp->next = p;
- if (lastp) lastp->next = newp;
- else script->punctuationtable[(unsigned int) newp->p[0]] = newp;
+ p = &punctuations[n];
+ if ( strlen( p->p ) < strlen( newp->p ) ) {
+ script->nextpunctuation[i] = n;
+ if ( lastp >= 0 ) {
+ script->nextpunctuation[lastp] = i;
+ }
+ else {
+ script->punctuationtable[(unsigned int) newp->p[0]] = i;
+ }
break;
- } //end if
- lastp = p;
- } //end for
- if (!p)
- {
- newp->next = NULL;
- if (lastp) lastp->next = newp;
- else script->punctuationtable[(unsigned int) newp->p[0]] = newp;
- } //end if
- } //end for
+ }
+ lastp = n;
+ }
+ if ( n < 0 ) {
+ script->nextpunctuation[i] = -1;
+ if ( lastp >= 0 ) {
+ script->nextpunctuation[lastp] = i;
+ }
+ else {
+ script->punctuationtable[(unsigned int) newp->p[0]] = i;
+ }
+ }
+ }
} //end of the function PS_CreatePunctuationTable
//===========================================================================
//
@@ -235,7 +266,7 @@ const char *PunctuationFromNum(script_t *script, int num)
// Returns: -
// Changes Globals: -
//===========================================================================
-void QDECL ScriptError(script_t *script, char *str, ...)
+void QDECL ScriptError(script_t *script, const char *str, ...)
{
char text[1024];
va_list ap;
@@ -261,7 +292,7 @@ void QDECL ScriptError(script_t *script, char *str, ...)
// Returns: -
// Changes Globals: -
//===========================================================================
-void QDECL ScriptWarning(script_t *script, char *str, ...)
+void QDECL ScriptWarning(script_t *script, const char *str, ...)
{
char text[1024];
va_list ap;
@@ -287,7 +318,7 @@ void QDECL ScriptWarning(script_t *script, char *str, ...)
// Returns: -
// Changes Globals: -
//===========================================================================
-void SetScriptPunctuations(script_t *script, punctuation_t *p)
+static void SetScriptPunctuations(script_t *script, const punctuation_t *p)
{
#ifdef PUNCTABLE
if (p) PS_CreatePunctuationTable(script, p);
@@ -304,7 +335,7 @@ void SetScriptPunctuations(script_t *script, punctuation_t *p)
// Returns: -
// Changes Globals: -
//============================================================================
-int PS_ReadWhiteSpace(script_t *script)
+static int PS_ReadWhiteSpace(script_t *script)
{
while(1)
{
@@ -363,9 +394,9 @@ int PS_ReadWhiteSpace(script_t *script)
// Returns: -
// Changes Globals: -
//============================================================================
-int PS_ReadEscapeCharacter(script_t *script, char *ch)
+static int PS_ReadEscapeCharacter(script_t *script, char *ch)
{
- int c, val, i;
+ int c, val;
//step over the leading '\\'
script->script_p++;
@@ -386,7 +417,7 @@ int PS_ReadEscapeCharacter(script_t *script, char *ch)
case 'x':
{
script->script_p++;
- for (i = 0, val = 0; ; i++, script->script_p++)
+ for (val = 0; ; script->script_p++)
{
c = *script->script_p;
if (c >= '0' && c <= '9') c = c - '0';
@@ -407,7 +438,7 @@ int PS_ReadEscapeCharacter(script_t *script, char *ch)
default: //NOTE: decimal ASCII code, NOT octal
{
if (*script->script_p < '0' || *script->script_p > '9') ScriptError(script, "unknown escape char");
- for (i = 0, val = 0; ; i++, script->script_p++)
+ for (val = 0; ; script->script_p++)
{
c = *script->script_p;
if (c >= '0' && c <= '9') c = c - '0';
@@ -427,7 +458,7 @@ int PS_ReadEscapeCharacter(script_t *script, char *ch)
//step over the escape character or the last digit of the number
script->script_p++;
//store the escape character
- *ch = c;
+ *ch = (char)c;
//successfully read escape character
return 1;
} //end of the function PS_ReadEscapeCharacter
@@ -441,10 +472,10 @@ int PS_ReadEscapeCharacter(script_t *script, char *ch)
// Returns: qtrue when a string was read succesfully
// Changes Globals: -
//============================================================================
-int PS_ReadString(script_t *script, token_t *token, int quote)
+static int PS_ReadString(script_t *script, token_t *token, int quote)
{
int len, tmpline;
- char *tmpscript_p;
+ const char *tmpscript_p;
if (quote == '\"') token->type = TT_STRING;
else token->type = TT_LITERAL;
@@ -467,7 +498,7 @@ int PS_ReadString(script_t *script, token_t *token, int quote)
{
if (!PS_ReadEscapeCharacter(script, &token->string[len]))
{
- token->string[len] = 0;
+ token->string[len] = '\0';
return 0;
} //end if
len++;
@@ -503,13 +534,13 @@ int PS_ReadString(script_t *script, token_t *token, int quote)
{
if (*script->script_p == '\0')
{
- token->string[len] = 0;
+ token->string[len] = '\0';
ScriptError(script, "missing trailing quote");
return 0;
} //end if
if (*script->script_p == '\n')
{
- token->string[len] = 0;
+ token->string[len] = '\0';
ScriptError(script, "newline inside string %s", token->string);
return 0;
} //end if
@@ -517,7 +548,7 @@ int PS_ReadString(script_t *script, token_t *token, int quote)
} //end else
} //end while
//trailing quote
- token->string[len++] = quote;
+ token->string[len++] = (char)quote;
//end string with a zero
token->string[len] = '\0';
//the sub type is the length of the string
@@ -560,8 +591,8 @@ int PS_ReadName(script_t *script, token_t *token)
// Returns: -
// Changes Globals: -
//============================================================================
-void NumberValue(char *string, int subtype, unsigned long int *intvalue,
- long double *floatvalue)
+static void NumberValue(char *string, int subtype, unsigned int *intvalue,
+ float *floatvalue)
{
unsigned long int dotfound = 0;
@@ -580,17 +611,17 @@ void NumberValue(char *string, int subtype, unsigned long int *intvalue,
} //end if
if (dotfound)
{
- *floatvalue = *floatvalue + (long double) (*string - '0') /
- (long double) dotfound;
+ *floatvalue = *floatvalue + (float) (*string - '0') /
+ (float) dotfound;
dotfound *= 10;
} //end if
else
{
- *floatvalue = *floatvalue * 10.0 + (long double) (*string - '0');
+ *floatvalue = *floatvalue * 10.0 + (float) (*string - '0');
} //end else
string++;
} //end while
- *intvalue = (unsigned long) *floatvalue;
+ *intvalue = (int) *floatvalue;
} //end if
else if (subtype & TT_DECIMAL)
{
@@ -609,21 +640,21 @@ void NumberValue(char *string, int subtype, unsigned long int *intvalue,
else *intvalue += *string - '0';
string++;
} //end while
- *floatvalue = *intvalue;
+ *floatvalue = (float)*intvalue;
} //end else if
else if (subtype & TT_OCTAL)
{
//step over the first zero
string += 1;
while(*string) *intvalue = (*intvalue << 3) + (*string++ - '0');
- *floatvalue = *intvalue;
+ *floatvalue = (float)*intvalue;
} //end else if
else if (subtype & TT_BINARY)
{
//step over the leading 0b or 0B
string += 2;
while(*string) *intvalue = (*intvalue << 1) + (*string++ - '0');
- *floatvalue = *intvalue;
+ *floatvalue = (float)*intvalue;
} //end else if
} //end of the function NumberValue
//============================================================================
@@ -632,7 +663,7 @@ void NumberValue(char *string, int subtype, unsigned long int *intvalue,
// Returns: -
// Changes Globals: -
//============================================================================
-int PS_ReadNumber(script_t *script, token_t *token)
+static int PS_ReadNumber(script_t *script, token_t *token)
{
int len = 0, i;
int octal, dot;
@@ -789,13 +820,14 @@ int PS_ReadLiteral(script_t *script, token_t *token)
//============================================================================
int PS_ReadPunctuation(script_t *script, token_t *token)
{
- int len;
+ int len, n;
const char *p;
- punctuation_t *punc;
+ const punctuation_t *punc;
#ifdef PUNCTABLE
- for (punc = script->punctuationtable[(unsigned int)*script->script_p]; punc; punc = punc->next)
+ for (n = script->punctuationtable[(unsigned int)*script->script_p]; n >= 0; n = script->nextpunctuation[n])
{
+ punc = &script->punctuations[n];
#else
int i;
@@ -811,7 +843,7 @@ int PS_ReadPunctuation(script_t *script, token_t *token)
//if the script contains the punctuation
if (!Q_strncmp(script->script_p, p, len))
{
- strncpy(token->string, p, MAX_TOKEN);
+ Q_strncpyz(token->string, p, sizeof(token->string));
script->script_p += len;
token->type = TT_PUNCTUATION;
//sub type is the number of the punctuation
@@ -835,14 +867,14 @@ int PS_ReadPrimitive(script_t *script, token_t *token)
len = 0;
while(*script->script_p > ' ' && *script->script_p != ';')
{
- if (len >= MAX_TOKEN - 1)
+ if (len >= MAX_TOKEN)
{
ScriptError(script, "primitive token longer than MAX_TOKEN = %d", MAX_TOKEN);
return 0;
} //end if
token->string[len++] = *script->script_p++;
} //end while
- token->string[len] = 0;
+ token->string[len] = '\0';
//copy the token into the script structure
Com_Memcpy(&script->token, token, sizeof(token_t));
//primitive reading successfull
@@ -928,7 +960,7 @@ int PS_ReadToken(script_t *script, token_t *token)
// Returns: -
// Changes Globals: -
//============================================================================
-int PS_ExpectTokenString(script_t *script, char *string)
+int PS_ExpectTokenString(script_t *script, const char *string)
{
token_t token;
@@ -985,7 +1017,7 @@ int PS_ExpectTokenType(script_t *script, int type, int subtype, token_t *token)
if (subtype & TT_UNSIGNED) strcat(str, " unsigned");
if (subtype & TT_FLOAT) strcat(str, " float");
if (subtype & TT_INTEGER) strcat(str, " integer");
- ScriptError(script, "expected %s, found %s", str, token->string);
+ ScriptError(script, "expected %s, found '%s'", str, token->string);
return 0;
} //end if
} //end if
@@ -998,8 +1030,8 @@ int PS_ExpectTokenType(script_t *script, int type, int subtype, token_t *token)
} //end if
if (token->subtype != subtype)
{
- ScriptError(script, "expected %s, found %s",
- script->punctuations[subtype].p, token->string);
+ ScriptError(script, "expected '%s', found '%s'",
+ PunctuationFromNum( script, subtype ), token->string);
return 0;
} //end if
} //end else if
@@ -1011,7 +1043,7 @@ int PS_ExpectTokenType(script_t *script, int type, int subtype, token_t *token)
// Returns: -
// Changes Globals: -
//============================================================================
-int PS_ExpectAnyToken(script_t *script, token_t *token)
+/*int PS_ExpectAnyToken(script_t *script, token_t *token)
{
if (!PS_ReadToken(script, token))
{
@@ -1022,14 +1054,14 @@ int PS_ExpectAnyToken(script_t *script, token_t *token)
{
return 1;
} //end else
-} //end of the function PS_ExpectAnyToken
+}*/ //end of the function PS_ExpectAnyToken
//============================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//============================================================================
-int PS_CheckTokenString(script_t *script, char *string)
+/*int PS_CheckTokenString(script_t *script, char *string)
{
token_t tok;
@@ -1039,14 +1071,14 @@ int PS_CheckTokenString(script_t *script, char *string)
//token not available
script->script_p = script->lastscript_p;
return 0;
-} //end of the function PS_CheckTokenString
+}*/ //end of the function PS_CheckTokenString
//============================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//============================================================================
-int PS_CheckTokenType(script_t *script, int type, int subtype, token_t *token)
+/*int PS_CheckTokenType(script_t *script, int type, int subtype, token_t *token)
{
token_t tok;
@@ -1061,14 +1093,14 @@ int PS_CheckTokenType(script_t *script, int type, int subtype, token_t *token)
//token is not available
script->script_p = script->lastscript_p;
return 0;
-} //end of the function PS_CheckTokenType
+}*/ //end of the function PS_CheckTokenType
//============================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//============================================================================
-int PS_SkipUntilString(script_t *script, char *string)
+/*int PS_SkipUntilString(script_t *script, const char *string)
{
token_t token;
@@ -1077,28 +1109,28 @@ int PS_SkipUntilString(script_t *script, char *string)
if (!strcmp(token.string, string)) return 1;
} //end while
return 0;
-} //end of the function PS_SkipUntilString
+}*/ //end of the function PS_SkipUntilString
//============================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//============================================================================
-void PS_UnreadLastToken(script_t *script)
+/*void PS_UnreadLastToken(script_t *script)
{
script->tokenavailable = 1;
-} //end of the function UnreadLastToken
+}*/ //end of the function UnreadLastToken
//============================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//============================================================================
-void PS_UnreadToken(script_t *script, token_t *token)
+/*void PS_UnreadToken(script_t *script, token_t *token)
{
Com_Memcpy(&script->token, token, sizeof(token_t));
script->tokenavailable = 1;
-} //end of the function UnreadToken
+}*/ //end of the function UnreadToken
//============================================================================
// returns the next character of the read white space, returns NULL if none
//
@@ -1106,7 +1138,7 @@ void PS_UnreadToken(script_t *script, token_t *token)
// Returns: -
// Changes Globals: -
//============================================================================
-char PS_NextWhiteSpaceChar(script_t *script)
+/*char PS_NextWhiteSpaceChar(script_t *script)
{
if (script->whitespace_p != script->endwhitespace_p)
{
@@ -1116,7 +1148,7 @@ char PS_NextWhiteSpaceChar(script_t *script)
{
return 0;
} //end else
-} //end of the function PS_NextWhiteSpaceChar
+}*/ //end of the function PS_NextWhiteSpaceChar
//============================================================================
//
// Parameter: -
@@ -1157,7 +1189,7 @@ void StripSingleQuotes(char *string)
// Returns: -
// Changes Globals: -
//============================================================================
-long double ReadSignedFloat(script_t *script)
+/*long double ReadSignedFloat(script_t *script)
{
token_t token;
long double sign = 1;
@@ -1181,14 +1213,14 @@ long double ReadSignedFloat(script_t *script)
}
return sign * token.floatvalue;
-} //end of the function ReadSignedFloat
+}*/ //end of the function ReadSignedFloat
//============================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//============================================================================
-signed long int ReadSignedInt(script_t *script)
+/*signed long int ReadSignedInt(script_t *script)
{
token_t token;
signed long int sign = 1;
@@ -1212,7 +1244,7 @@ signed long int ReadSignedInt(script_t *script)
}
return sign * token.intvalue;
-} //end of the function ReadSignedInt
+}*/ //end of the function ReadSignedInt
//============================================================================
//
// Parameter: -
@@ -1229,17 +1261,17 @@ void SetScriptFlags(script_t *script, int flags)
// Returns: -
// Changes Globals: -
//============================================================================
-int GetScriptFlags(script_t *script)
+/*int GetScriptFlags(script_t *script)
{
return script->flags;
-} //end of the function GetScriptFlags
+}*/ //end of the function GetScriptFlags
//============================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//============================================================================
-void ResetScript(script_t *script)
+/*void ResetScript(script_t *script)
{
//pointer in script buffer
script->script_p = script->buffer;
@@ -1256,7 +1288,7 @@ void ResetScript(script_t *script)
script->lastline = 1;
//clear the saved token
Com_Memset(&script->token, 0, sizeof(token_t));
-} //end of the function ResetScript
+}*/ //end of the function ResetScript
//============================================================================
// returns true if at the end of the script
//
@@ -1274,17 +1306,17 @@ int EndOfScript(script_t *script)
// Returns: -
// Changes Globals: -
//============================================================================
-int NumLinesCrossed(script_t *script)
+/*int NumLinesCrossed(script_t *script)
{
return script->line - script->lastline;
-} //end of the function NumLinesCrossed
+}*/ //end of the function NumLinesCrossed
//============================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//============================================================================
-int ScriptSkipTo(script_t *script, char *value)
+/*int ScriptSkipTo(script_t *script, char *value)
{
int len;
char firstchar;
@@ -1303,7 +1335,7 @@ int ScriptSkipTo(script_t *script, char *value)
} //end if
script->script_p++;
} while(1);
-} //end of the function ScriptSkipTo
+}*/ //end of the function ScriptSkipTo
#ifndef BOTLIB
//============================================================================
//
@@ -1334,13 +1366,14 @@ script_t *LoadScriptFile(const char *filename)
{
#ifdef BOTLIB
fileHandle_t fp;
- char pathname[MAX_QPATH];
+ char pathname[MAX_QPATH*2];
#else
FILE *fp;
#endif
int length;
void *buffer;
script_t *script;
+ char *buf;
#ifdef BOTLIB
if (strlen(basefolder))
@@ -1356,12 +1389,25 @@ script_t *LoadScriptFile(const char *filename)
length = FileLength(fp);
#endif
- buffer = GetClearedMemory(sizeof(script_t) + length + 1);
+ buffer = GetClearedMemory(sizeof(script_t) + (unsigned int)length + 1);
script = (script_t *) buffer;
Com_Memset(script, 0, sizeof(script_t));
Q_strncpyz(script->filename, filename, sizeof(script->filename));
- script->buffer = (char *) buffer + sizeof(script_t);
- script->buffer[length] = 0;
+ buf = (char *) buffer + sizeof(script_t);
+#ifdef BOTLIB
+ botimport.FS_Read(buf, length, fp);
+ buf[length] = '\0';
+ botimport.FS_FCloseFile(fp);
+#else
+ if (fread(script->buffer, length, 1, fp) != 1)
+ {
+ FreeMemory(buffer);
+ script = NULL;
+ } //end if
+ fclose(fp);
+#endif
+ length = COM_Compress(buf);
+ script->buffer = buf;
script->length = length;
//pointer in script buffer
script->script_p = script->buffer;
@@ -1377,20 +1423,6 @@ script_t *LoadScriptFile(const char *filename)
//
SetScriptPunctuations(script, NULL);
//
-#ifdef BOTLIB
- botimport.FS_Read(script->buffer, length, fp);
- botimport.FS_FCloseFile(fp);
-#else
- if (fread(script->buffer, length, 1, fp) != 1)
- {
- FreeMemory(buffer);
- script = NULL;
- } //end if
- fclose(fp);
-#endif
- //
- script->length = COM_Compress(script->buffer);
-
return script;
} //end of the function LoadScriptFile
//============================================================================
@@ -1399,17 +1431,20 @@ script_t *LoadScriptFile(const char *filename)
// Returns: -
// Changes Globals: -
//============================================================================
-script_t *LoadScriptMemory(char *ptr, int length, char *name)
+script_t *LoadScriptMemory(const char *ptr, int length, const char *name)
{
void *buffer;
script_t *script;
+ char *buf;
- buffer = GetClearedMemory(sizeof(script_t) + length + 1);
+ buffer = GetClearedMemory(sizeof(script_t) + (unsigned int)length + 1);
script = (script_t *) buffer;
Com_Memset(script, 0, sizeof(script_t));
Q_strncpyz(script->filename, name, sizeof(script->filename));
- script->buffer = (char *) buffer + sizeof(script_t);
- script->buffer[length] = 0;
+ buf = (char *) buffer + sizeof(script_t);
+ Com_Memcpy( buf, ptr, length );
+ buf[length] = '\0';
+ script->buffer = buf;
script->length = length;
//pointer in script buffer
script->script_p = script->buffer;
@@ -1425,7 +1460,7 @@ script_t *LoadScriptMemory(char *ptr, int length, char *name)
//
SetScriptPunctuations(script, NULL);
//
- Com_Memcpy(script->buffer, ptr, length);
+ //Com_Memcpy(script->buffer, ptr, length);
//
return script;
} //end of the function LoadScriptMemory
@@ -1438,7 +1473,14 @@ script_t *LoadScriptMemory(char *ptr, int length, char *name)
void FreeScript(script_t *script)
{
#ifdef PUNCTABLE
- if (script->punctuationtable) FreeMemory(script->punctuationtable);
+ if (script->punctuationtable && script->punctuationtable != default_punctuationtable) {
+ FreeMemory(script->punctuationtable);
+ script->punctuationtable = NULL;
+ }
+ if(script->nextpunctuation && script->nextpunctuation != default_nextpunctuation) {
+ FreeMemory(script->nextpunctuation);
+ script->nextpunctuation = NULL;
+ }
#endif //PUNCTABLE
FreeMemory(script);
} //end of the function FreeScript
@@ -1448,7 +1490,7 @@ void FreeScript(script_t *script)
// Returns: -
// Changes Globals: -
//============================================================================
-void PS_SetBaseFolder(char *path)
+void PS_SetBaseFolder(const char *path)
{
#ifdef BSPC
sprintf(basefolder, path);
diff --git a/codemp/botlib/l_script.h b/codemp/botlib/l_script.h
index 574732a7..8c18d286 100644
--- a/codemp/botlib/l_script.h
+++ b/codemp/botlib/l_script.h
@@ -158,7 +158,6 @@ typedef struct punctuation_s
{
const char *p; //punctuation character(s)
int n; //punctuation indication
- struct punctuation_s *next; //next punctuation
} punctuation_t;
//token
@@ -168,11 +167,11 @@ typedef struct token_s
int type; //last read token type
int subtype; //last read token sub type
#ifdef NUMBERVALUE
- unsigned long int intvalue; //integer value
- long double floatvalue; //floating point value
+ unsigned int intvalue; //integer value
+ float floatvalue; //floating point value
#endif //NUMBERVALUE
- char *whitespace_p; //start of white space before token
- char *endwhitespace_p; //start of white space before token
+ const char *whitespace_p; //start of white space before token
+ const char *endwhitespace_p; //start of white space before token
int line; //line the token was on
int linescrossed; //lines crossed in white space
struct token_s *next; //next token in chain
@@ -182,19 +181,20 @@ typedef struct token_s
typedef struct script_s
{
char filename[1024]; //file name of the script
- char *buffer; //buffer containing the script
- char *script_p; //current pointer in the script
- char *end_p; //pointer to the end of the script
- char *lastscript_p; //script pointer before reading token
- char *whitespace_p; //begin of the white space
- char *endwhitespace_p; //end of the white space
+ const char *buffer; //buffer containing the script
+ const char *script_p; //current pointer in the script
+ const char *end_p; //pointer to the end of the script
+ const char *lastscript_p; //script pointer before reading token
+ const char *whitespace_p; //begin of the white space
+ const char *endwhitespace_p; //end of the white space
int length; //length of the script in bytes
int line; //current line in script
int lastline; //line before reading token
int tokenavailable; //set by UnreadLastToken
int flags; //several script flags
- punctuation_t *punctuations; //the punctuations used in the script
- punctuation_t **punctuationtable;
+ const punctuation_t *punctuations; //the punctuations used in the script
+ int *punctuationtable; //ASCII table with punctuations
+ int *nextpunctuation; //next punctuation in chain
token_t token; //available token
struct script_s *next; //next script in a chain
} script_t;
@@ -202,39 +202,39 @@ typedef struct script_s
//read a token from the script
int PS_ReadToken(script_t *script, token_t *token);
//expect a certain token
-int PS_ExpectTokenString(script_t *script, char *string);
+//int PS_ExpectTokenString(script_t *script, const char *string);
//expect a certain token type
int PS_ExpectTokenType(script_t *script, int type, int subtype, token_t *token);
//expect a token
-int PS_ExpectAnyToken(script_t *script, token_t *token);
+//int PS_ExpectAnyToken(script_t *script, token_t *token);
//returns true when the token is available
-int PS_CheckTokenString(script_t *script, char *string);
+//int PS_CheckTokenString(script_t *script, const char *string);
//returns true and reads the token when a token with the given type is available
-int PS_CheckTokenType(script_t *script, int type, int subtype, token_t *token);
+//int PS_CheckTokenType(script_t *script, int type, int subtype, token_t *token);
//skip tokens until the given token string is read
-int PS_SkipUntilString(script_t *script, char *string);
+//int PS_SkipUntilString(script_t *script, const char *string);
//unread the last token read from the script
-void PS_UnreadLastToken(script_t *script);
+//void PS_UnreadLastToken(script_t *script);
//unread the given token
-void PS_UnreadToken(script_t *script, token_t *token);
+//void PS_UnreadToken(script_t *script, token_t *token);
//returns the next character of the read white space, returns NULL if none
-char PS_NextWhiteSpaceChar(script_t *script);
+//char PS_NextWhiteSpaceChar(script_t *script);
//remove any leading and trailing double quotes from the token
void StripDoubleQuotes(char *string);
//remove any leading and trailing single quotes from the token
void StripSingleQuotes(char *string);
//read a possible signed integer
-signed long int ReadSignedInt(script_t *script);
+//signed long int ReadSignedInt(script_t *script);
//read a possible signed floating point number
-long double ReadSignedFloat(script_t *script);
+//long double ReadSignedFloat(script_t *script);
//set an array with punctuations, NULL restores default C/C++ set
-void SetScriptPunctuations(script_t *script, punctuation_t *p);
+//void SetScriptPunctuations(script_t *script, const punctuation_t *p);
//set script flags
void SetScriptFlags(script_t *script, int flags);
//get script flags
-int GetScriptFlags(script_t *script);
+//int GetScriptFlags(script_t *script);
//reset a script
-void ResetScript(script_t *script);
+//void ResetScript(script_t *script);
//returns true if at the end of the script
int EndOfScript(script_t *script);
//returns a pointer to the punctuation with the given number
@@ -242,12 +242,12 @@ const char *PunctuationFromNum(script_t *script, int num);
//load a script from the given file at the given offset with the given length
script_t *LoadScriptFile(const char *filename);
//load a script from the given memory with the given length
-script_t *LoadScriptMemory(char *ptr, int length, char *name);
+script_t *LoadScriptMemory(const char *ptr, int length, const char *name);
//free a script
void FreeScript(script_t *script);
//set the base folder to load files from
-void PS_SetBaseFolder(char *path);
+void PS_SetBaseFolder(const char *path);
//print a script error with filename and line number
-void QDECL ScriptError(script_t *script, char *str, ...) __attribute__ ((format (printf, 2, 3)));
+void QDECL ScriptError(script_t *script, const char *str, ...) __attribute__ ((format (printf, 2, 3)));
//print a script warning with filename and line number
-void QDECL ScriptWarning(script_t *script, char *str, ...) __attribute__ ((format (printf, 2, 3)));
+void QDECL ScriptWarning(script_t *script, const char *str, ...) __attribute__ ((format (printf, 2, 3)));
diff --git a/codemp/cgame/cg_public.h b/codemp/cgame/cg_public.h
index 801aa1be..b044089c 100644
--- a/codemp/cgame/cg_public.h
+++ b/codemp/cgame/cg_public.h
@@ -614,7 +614,7 @@ typedef struct cgameImport_s {
void (*Key_SetCatcher) ( int catcher );
// preprocessor (botlib_export->PC_***)
- int (*PC_AddGlobalDefine) ( char *string );
+ int (*PC_AddGlobalDefine) ( const char *string );
int (*PC_FreeSource) ( int handle );
int (*PC_LoadGlobalDefines) ( const char *filename );
int (*PC_LoadSource) ( const char *filename );
diff --git a/codemp/cgame/cg_syscalls.c b/codemp/cgame/cg_syscalls.c
index 2c905d67..56e2890f 100644
--- a/codemp/cgame/cg_syscalls.c
+++ b/codemp/cgame/cg_syscalls.c
@@ -386,7 +386,7 @@ void trap_Key_SetCatcher( int catcher ) {
int trap_Key_GetKey( const char *binding ) {
return Q_syscall( CG_KEY_GETKEY, binding );
}
-int trap_PC_AddGlobalDefine( char *define ) {
+int trap_PC_AddGlobalDefine( const char *define ) {
return Q_syscall( CG_PC_ADD_GLOBAL_DEFINE, define );
}
int trap_PC_LoadSource( const char *filename ) {
diff --git a/codemp/game/g_public.h b/codemp/game/g_public.h
index d90e3509..173a4b43 100644
--- a/codemp/game/g_public.h
+++ b/codemp/game/g_public.h
@@ -971,7 +971,7 @@ typedef struct gameImport_s {
int (*BotLibShutdown) ( void );
int (*BotLibVarSet) ( char *var_name, char *value );
int (*BotLibVarGet) ( char *var_name, char *value, int size );
- int (*BotLibDefine) ( char *string );
+ int (*BotLibDefine) ( const char *string );
int (*BotLibStartFrame) ( float time );
int (*BotLibLoadMap) ( const char *mapname );
int (*BotLibUpdateEntity) ( int ent, void *bue );
diff --git a/codemp/game/g_syscalls.c b/codemp/game/g_syscalls.c
index 3e49935e..c9600c03 100644
--- a/codemp/game/g_syscalls.c
+++ b/codemp/game/g_syscalls.c
@@ -421,7 +421,7 @@ int trap_BotLibVarSet(char *var_name, char *value) {
int trap_BotLibVarGet(char *var_name, char *value, int size) {
return Q_syscall( BOTLIB_LIBVAR_GET, var_name, value, size );
}
-int trap_BotLibDefine(char *string) {
+int trap_BotLibDefine(const char *string) {
return Q_syscall( BOTLIB_PC_ADD_GLOBAL_DEFINE, string );
}
int trap_BotLibStartFrame(float time) {
diff --git a/codemp/server/sv_gameapi.cpp b/codemp/server/sv_gameapi.cpp
index d216669a..e6dcf796 100644
--- a/codemp/server/sv_gameapi.cpp
+++ b/codemp/server/sv_gameapi.cpp
@@ -1211,7 +1211,7 @@ static int SV_BotLibVarGet( char *var_name, char *value, int size ) {
return botlib_export->BotLibVarGet( var_name, value, size );
}
-static int SV_BotLibDefine( char *string ) {
+static int SV_BotLibDefine( const char *string ) {
return botlib_export->PC_AddGlobalDefine( string );
}
diff --git a/codemp/ui/ui_public.h b/codemp/ui/ui_public.h
index 9cb29cca..8bee9b32 100644
--- a/codemp/ui/ui_public.h
+++ b/codemp/ui/ui_public.h
@@ -269,7 +269,7 @@ typedef struct uiImport_s {
void (*Key_SetCatcher) ( int catcher );
void (*Key_SetOverstrikeMode) ( qboolean state );
- int (*PC_AddGlobalDefine) ( char *define );
+ int (*PC_AddGlobalDefine) ( const char *define );
int (*PC_FreeSource) ( int handle );
int (*PC_LoadGlobalDefines) ( const char* filename );
int (*PC_LoadSource) ( const char *filename );
diff --git a/codemp/ui/ui_syscalls.c b/codemp/ui/ui_syscalls.c
index a2e4d8fd..02cd5c0a 100644
--- a/codemp/ui/ui_syscalls.c
+++ b/codemp/ui/ui_syscalls.c
@@ -286,7 +286,7 @@ int trap_LAN_CompareServers( int source, int sortKey, int sortDir, int s1, int s
int trap_MemoryRemaining( void ) {
return Q_syscall( UI_MEMORY_REMAINING );
}
-int trap_PC_AddGlobalDefine( char *define ) {
+int trap_PC_AddGlobalDefine( const char *define ) {
return Q_syscall( UI_PC_ADD_GLOBAL_DEFINE, define );
}
int trap_PC_LoadSource( const char *filename ) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment