mirror of
https://github.com/blendogames/thirtyflightsofloving.git
synced 2024-11-14 08:31:04 +00:00
Cleaned up string handling in extractfuncs.
This commit is contained in:
parent
6e81e12456
commit
4afc95c317
7 changed files with 385 additions and 207 deletions
|
@ -66,6 +66,8 @@ typedef struct tokenList_s
|
|||
extern int Q_stricmp (const char *s1, const char *s2);
|
||||
replacefunc_t *FindFunctionName (char *funcname);
|
||||
void Error (char *error, ...);
|
||||
void Com_sprintf (char *dest, int size, const char *fmt, ...);
|
||||
void Com_sprintf (char *dest, size_t size, const char *fmt, ...);
|
||||
void Q_strncpyz (char *dest, size_t destSize, const char *src);
|
||||
void Q_strncatz (char *dest, size_t destSize, const char *src);
|
||||
|
||||
extern int verbose;
|
||||
|
|
|
@ -170,9 +170,12 @@ void DumpReplaceFunctions (char *typeName)
|
|||
updated = 0;
|
||||
|
||||
// dump the function header
|
||||
strcpy( path, "." );
|
||||
strcat( path, PATHSEPERATOR_STR );
|
||||
strcat( path, TEMP_LIST_NAME );
|
||||
// strncpy (path, ".");
|
||||
// strncat (path, PATHSEPERATOR_STR);
|
||||
// strncat (path, TEMP_LIST_NAME);
|
||||
Q_strncpyz (path, sizeof(path), ".");
|
||||
Q_strncatz (path, sizeof(path), PATHSEPERATOR_STR);
|
||||
Q_strncatz (path, sizeof(path), TEMP_LIST_NAME);
|
||||
Log_Open( path );
|
||||
for ( rf = replacefuncs; rf; rf = rf->next )
|
||||
{
|
||||
|
@ -185,7 +188,8 @@ void DumpReplaceFunctions (char *typeName)
|
|||
Log_Close();
|
||||
|
||||
// if it's different, rename the file over the real header
|
||||
strcpy( path, TEMP_LIST_NAME );
|
||||
// strncpy (path, TEMP_LIST_NAME);
|
||||
Q_strncpyz (path, sizeof(path), TEMP_LIST_NAME);
|
||||
f = fopen( path, "rb" );
|
||||
fseek( f, 0, SEEK_END );
|
||||
len = ftell( f );
|
||||
|
@ -195,7 +199,8 @@ void DumpReplaceFunctions (char *typeName)
|
|||
buf[len] = 0;
|
||||
fclose( f );
|
||||
|
||||
strcpy( path, func_listfile );
|
||||
// strncpy (path, func_listfile);
|
||||
Q_strncpyz (path, sizeof(path), func_listfile);
|
||||
if ( f = fopen( path, "rb" ) )
|
||||
{
|
||||
fseek( f, 0, SEEK_END );
|
||||
|
@ -211,10 +216,12 @@ void DumpReplaceFunctions (char *typeName)
|
|||
char newpath[_MAX_PATH];
|
||||
|
||||
// delete the old file, rename the new one
|
||||
strcpy( path, func_listfile );
|
||||
// strncpy (path, func_listfile);
|
||||
Q_strncpyz (path, sizeof(path), func_listfile);
|
||||
remove( path );
|
||||
|
||||
strcpy( newpath, TEMP_LIST_NAME );
|
||||
// strncpy (newpath, TEMP_LIST_NAME);
|
||||
Q_strncpyz (newpath, sizeof(newpath), TEMP_LIST_NAME);
|
||||
rename( newpath, path );
|
||||
|
||||
#ifdef _WIN32
|
||||
|
@ -229,7 +236,8 @@ void DumpReplaceFunctions (char *typeName)
|
|||
}
|
||||
else {
|
||||
// delete the old file
|
||||
strcpy( path, TEMP_LIST_NAME );
|
||||
// strncpy (path, TEMP_LIST_NAME);
|
||||
Q_strncpyz (path, sizeof(path), TEMP_LIST_NAME);
|
||||
remove( path );
|
||||
}
|
||||
}
|
||||
|
@ -241,7 +249,8 @@ void DumpReplaceFunctions (char *typeName)
|
|||
free( newbuf );
|
||||
|
||||
// dump the function declarations
|
||||
strcpy( path, TEMP_DECS_NAME );
|
||||
// strncpy (path, TEMP_DECS_NAME);
|
||||
Q_strncpyz (path, sizeof(path), TEMP_DECS_NAME);
|
||||
Log_Open( path );
|
||||
for ( rf = replacefuncs; rf; rf = rf->next )
|
||||
{
|
||||
|
@ -253,7 +262,8 @@ void DumpReplaceFunctions (char *typeName)
|
|||
Log_Close();
|
||||
|
||||
// if it's different, rename the file over the real header
|
||||
strcpy( path, TEMP_DECS_NAME );
|
||||
// strncpy (path, TEMP_DECS_NAME);
|
||||
Q_strncpyz (path, sizeof(path), TEMP_DECS_NAME);
|
||||
f = fopen( path, "rb" );
|
||||
fseek( f, 0, SEEK_END );
|
||||
len = ftell( f );
|
||||
|
@ -263,7 +273,8 @@ void DumpReplaceFunctions (char *typeName)
|
|||
buf[len] = 0;
|
||||
fclose( f );
|
||||
|
||||
strcpy( path, func_decsfile );
|
||||
// strncpy (path, func_decsfile);
|
||||
Q_strncpyz (path, sizeof(path), func_decsfile);
|
||||
if ( f = fopen( path, "rb" ) )
|
||||
{
|
||||
fseek( f, 0, SEEK_END );
|
||||
|
@ -279,10 +290,12 @@ void DumpReplaceFunctions (char *typeName)
|
|||
char newpath[_MAX_PATH];
|
||||
|
||||
// delete the old file, rename the new one
|
||||
strcpy( path, func_decsfile );
|
||||
// strncpy (path, func_decsfile);
|
||||
Q_strncpyz (path, sizeof(path), func_decsfile);
|
||||
remove( path );
|
||||
|
||||
strcpy( newpath, TEMP_DECS_NAME );
|
||||
// strncpy (newpath, TEMP_DECS_NAME);
|
||||
Q_strncpyz (newpath, sizeof(newpath), TEMP_DECS_NAME);
|
||||
rename( newpath, path );
|
||||
|
||||
#ifdef _WIN32
|
||||
|
@ -298,7 +311,8 @@ void DumpReplaceFunctions (char *typeName)
|
|||
}
|
||||
else {
|
||||
// delete the old file
|
||||
strcpy( path, TEMP_DECS_NAME );
|
||||
// strncpy (path, TEMP_DECS_NAME);
|
||||
Q_strncpyz (path, sizeof(path), TEMP_DECS_NAME);
|
||||
remove( path );
|
||||
}
|
||||
}
|
||||
|
@ -362,22 +376,26 @@ int MayScrewUp (char *funcname)
|
|||
ConcatDec
|
||||
=================
|
||||
*/
|
||||
void ConcatDec (tokenList_t *list, char *str, int inc)
|
||||
void ConcatDec (tokenList_t *list, char *str, size_t strSize, int inc)
|
||||
{
|
||||
/* if (!((list->token.type == TT_NAME) || (list->token.string[0] == '*'))) {
|
||||
/* if (!((list->token.type == TT_NAME) || (list->token.string[0] == '*')))
|
||||
{
|
||||
if (list->token.string[0] == ')' || list->token.string[0] == '(') {
|
||||
if (inc++ >= 2)
|
||||
return;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
}*/
|
||||
if (list->next)
|
||||
{
|
||||
ConcatDec (list->next, str, inc);
|
||||
ConcatDec (list->next, str, strSize, inc);
|
||||
}
|
||||
strcat(str, list->token.string);
|
||||
strcat(str, " " );
|
||||
// strncat (str, list->token.string);
|
||||
// strncat (str, " " );
|
||||
Q_strncatz (str, strSize, list->token.string);
|
||||
Q_strncatz (str, strSize, " " );
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -387,7 +405,7 @@ AddFunctionName
|
|||
*/
|
||||
void AddFunctionName (char *funcname, char *filename, tokenList_t *head)
|
||||
{
|
||||
replacefunc_t *f;
|
||||
replacefunc_t *f;
|
||||
tokenList_t *list;
|
||||
|
||||
if ( FindFunctionName(funcname) )
|
||||
|
@ -415,20 +433,23 @@ void AddFunctionName (char *funcname, char *filename, tokenList_t *head)
|
|||
#endif
|
||||
// -NERVE - SMF
|
||||
|
||||
f = (replacefunc_t *) GetMemory( sizeof( replacefunc_t ) + (int)strlen( funcname ) + 1 + 6 + (int)strlen( filename ) + 1 );
|
||||
f->name = (char *) f + sizeof( replacefunc_t );
|
||||
strcpy( f->name, funcname );
|
||||
f->newname = (char *) f + sizeof( replacefunc_t ) + strlen( funcname ) + 1;
|
||||
sprintf( f->newname, "F%d", numfuncs++ );
|
||||
f->filename = (char *) f + sizeof( replacefunc_t ) + strlen( funcname ) + 1 + strlen( f->newname ) + 1;
|
||||
strcpy( f->filename, filename );
|
||||
f = (replacefunc_t *) GetMemory(sizeof(replacefunc_t) + (int)strlen(funcname) + 1 + 6 + (int)strlen(filename) + 1);
|
||||
f->name = (char *)f + sizeof(replacefunc_t);
|
||||
// strncpy (f->name, funcname);
|
||||
Q_strncpyz (f->name, strlen(funcname) + 1, funcname);
|
||||
f->newname = (char *)f + sizeof(replacefunc_t) + strlen(funcname) + 1;
|
||||
// sprintf (f->newname, "F%d", numfuncs++);
|
||||
Com_sprintf (f->newname, 6, "F%d", numfuncs++);
|
||||
f->filename = (char *)f + sizeof(replacefunc_t) + strlen(funcname) + 1 + strlen(f->newname) + 1;
|
||||
// strncpy (f->filename, filename);
|
||||
Q_strncpyz (f->filename, strlen(filename) + 1, filename);
|
||||
f->next = replacefuncs;
|
||||
replacefuncs = f;
|
||||
|
||||
// construct the declaration
|
||||
list = head;
|
||||
f->dec[0] = '\0';
|
||||
ConcatDec( list, f->dec, 0 );
|
||||
ConcatDec (list, f->dec, sizeof(f->dec), 0);
|
||||
|
||||
} //end of the function AddFunctionName
|
||||
|
||||
|
|
|
@ -72,6 +72,9 @@ Safe strncpy that ensures a trailing zero
|
|||
*/
|
||||
void Q_strncpyz (char *dest, size_t destSize, const char *src)
|
||||
{
|
||||
if (!dest) {
|
||||
Error ("Q_strncatz: NULL dest");
|
||||
}
|
||||
if ( !src ) {
|
||||
Error( "Q_strncpyz: NULL src" );
|
||||
}
|
||||
|
@ -83,16 +86,51 @@ void Q_strncpyz (char *dest, size_t destSize, const char *src)
|
|||
dest[destSize - 1] = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
=================
|
||||
Q_strncatz
|
||||
|
||||
Safe strncat that ensures a trailing zero
|
||||
=================
|
||||
*/
|
||||
void Q_strncatz (char *dest, size_t destSize, const char *src)
|
||||
{
|
||||
char *d = dest;
|
||||
const char *s = src;
|
||||
size_t decSize = destSize;
|
||||
|
||||
if (!dest) {
|
||||
Error ("Q_strncatz: NULL dest");
|
||||
}
|
||||
if (!src) {
|
||||
Error ("Q_strncatz: NULL src");
|
||||
}
|
||||
if (destSize < 1) {
|
||||
Error ("Q_strncatz: dstSize < 1");
|
||||
}
|
||||
|
||||
while (--decSize && *d)
|
||||
d++;
|
||||
|
||||
if (decSize > 0){
|
||||
while (--decSize && *s)
|
||||
*d++ = *s++;
|
||||
|
||||
*d = 0;
|
||||
}
|
||||
dest[destSize - 1] = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
=================
|
||||
Com_sprintf
|
||||
=================
|
||||
*/
|
||||
void Com_sprintf (char *dest, int size, const char *fmt, ...)
|
||||
void Com_sprintf (char *dest, size_t size, const char *fmt, ...)
|
||||
{
|
||||
int len;
|
||||
va_list argptr;
|
||||
char bigbuffer[32000]; // big, but small enough to fit in PPC stack
|
||||
size_t len;
|
||||
va_list argptr;
|
||||
char bigbuffer[32000]; // big, but small enough to fit in PPC stack
|
||||
|
||||
va_start( argptr,fmt );
|
||||
// len = vsprintf( bigbuffer, fmt, argptr );
|
||||
|
@ -109,7 +147,7 @@ void Com_sprintf (char *dest, int size, const char *fmt, ...)
|
|||
Q_strncpyz (dest, size, bigbuffer);
|
||||
}
|
||||
|
||||
int Q_stricmpn( const char *s1, const char *s2, int n )
|
||||
int Q_stricmpn (const char *s1, const char *s2, int n)
|
||||
{
|
||||
int c1, c2;
|
||||
|
||||
|
@ -140,7 +178,7 @@ int Q_stricmpn( const char *s1, const char *s2, int n )
|
|||
return 0; // strings are equal
|
||||
}
|
||||
|
||||
int Q_strncmp( const char *s1, const char *s2, int n )
|
||||
int Q_strncmp (const char *s1, const char *s2, int n)
|
||||
{
|
||||
int c1, c2;
|
||||
|
||||
|
@ -621,7 +659,8 @@ int PC_StringizeTokens( token_t *tokens, token_t *token )
|
|||
token->whitespace_p = NULL;
|
||||
token->endwhitespace_p = NULL;
|
||||
token->string[0] = '\0';
|
||||
strcat( token->string, "\"" );
|
||||
// strncat (token->string, "\"");
|
||||
Q_strncatz (token->string, sizeof(token->string), "\"");
|
||||
for ( t = tokens; t; t = t->next )
|
||||
{
|
||||
strncat( token->string, t->string, MAX_TOKEN - strlen( token->string ) );
|
||||
|
@ -640,7 +679,8 @@ int PC_MergeTokens( token_t *t1, 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 ) )
|
||||
{
|
||||
strcat( t1->string, t2->string );
|
||||
// strncat (t1->string, t2->string);
|
||||
Q_strncatz (t1->string, sizeof(t1->string), t2->string);
|
||||
return qtrue;
|
||||
} //end if
|
||||
//merging of two strings
|
||||
|
@ -648,7 +688,8 @@ int PC_MergeTokens( token_t *t1, token_t *t2 )
|
|||
//remove trailing double quote
|
||||
t1->string[strlen( t1->string ) - 1] = '\0';
|
||||
//concat without leading double quote
|
||||
strcat( t1->string, &t2->string[1] );
|
||||
// strncat (t1->string, &t2->string[1]);
|
||||
Q_strncatz (t1->string, sizeof(t1->string), &t2->string[1]);
|
||||
return qtrue;
|
||||
} //end if
|
||||
//FIXME: merging of two number of the same sub type
|
||||
|
@ -840,10 +881,11 @@ void PC_AddBuiltinDefines( source_t *source )
|
|||
|
||||
for ( i = 0; builtin[i].string; i++ )
|
||||
{
|
||||
define = (define_t *) GetMemory( sizeof( define_t ) + (int)strlen( builtin[i].string ) + 1 );
|
||||
memset( define, 0, sizeof( define_t ) );
|
||||
define->name = (char *) define + sizeof( define_t );
|
||||
strcpy( define->name, builtin[i].string );
|
||||
define = (define_t *) GetMemory(sizeof(define_t) + (int)strlen(builtin[i].string) + 1);
|
||||
memset( define, 0, sizeof(define_t) );
|
||||
define->name = (char *)define + sizeof(define_t);
|
||||
// strncpy (define->name, builtin[i].string);
|
||||
Q_strncpyz (define->name, strlen(builtin[i].string) + 1, builtin[i].string);
|
||||
define->flags |= DEFINE_FIXED;
|
||||
define->builtin = builtin[i].builtin;
|
||||
//add the define to the source
|
||||
|
@ -873,7 +915,7 @@ int PC_ExpandBuiltinDefine( source_t *source, define_t *define,
|
|||
{
|
||||
case BUILTIN_LINE:
|
||||
{
|
||||
sprintf( token.string, "%d", source->token.line );
|
||||
Com_sprintf (token.string, sizeof(token.string), "%d", source->token.line);
|
||||
#ifdef NUMBERVALUE
|
||||
token.intvalue = source->token.line;
|
||||
token.floatvalue = source->token.line;
|
||||
|
@ -886,7 +928,8 @@ int PC_ExpandBuiltinDefine( source_t *source, define_t *define,
|
|||
} //end case
|
||||
case BUILTIN_FILE:
|
||||
{
|
||||
strcpy( token.string, source->scriptstack->filename );
|
||||
// strncpy (token.string, source->scriptstack->filename);
|
||||
Q_strncpyz (token.string, sizeof(token.string), source->scriptstack->filename);
|
||||
token.type = TT_NAME;
|
||||
token.subtype = (int)strlen( token.string );
|
||||
*firsttoken = &token;
|
||||
|
@ -897,10 +940,12 @@ int PC_ExpandBuiltinDefine( source_t *source, 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, "\"" );
|
||||
// strncpy (token.string, "\"");
|
||||
Q_strncpyz (token.string, sizeof(token.string), "\"");
|
||||
strncat (token.string, curtime + 4, 7);
|
||||
strncat (token.string + 7, curtime + 20, 4);
|
||||
// strncat (token.string, sizeof(token.string), "\"");
|
||||
Q_strncatz (token.string, sizeof(token.string), "\"");
|
||||
free( curtime );
|
||||
token.type = TT_NAME;
|
||||
token.subtype = (int)strlen( token.string );
|
||||
|
@ -912,9 +957,11 @@ int PC_ExpandBuiltinDefine( source_t *source, define_t *define,
|
|||
{
|
||||
t = time( NULL );
|
||||
curtime = ctime( &t );
|
||||
strcpy( token.string, "\"" );
|
||||
strncat( token.string, curtime + 11, 8 );
|
||||
strcat( token.string, "\"" );
|
||||
// strncpy (token.string, "\"");
|
||||
Q_strncpyz (token.string, sizeof(token.string), "\"");
|
||||
strncat (token.string, curtime + 11, 8);
|
||||
// strncat (token.string, "\"");
|
||||
Q_strncatz (token.string, sizeof(token.string), "\"");
|
||||
free( curtime );
|
||||
token.type = TT_NAME;
|
||||
token.subtype = (int)strlen( token.string );
|
||||
|
@ -1084,40 +1131,41 @@ int PC_ExpandDefineIntoSource( source_t *source, define_t *define )
|
|||
lasttoken->next = source->tokens;
|
||||
source->tokens = firsttoken;
|
||||
return qtrue;
|
||||
} //end if
|
||||
} // end if
|
||||
return qfalse;
|
||||
} //end of the function PC_ExpandDefineIntoSource
|
||||
} // end of the function PC_ExpandDefineIntoSource
|
||||
//============================================================================
|
||||
//
|
||||
// Parameter: -
|
||||
// Returns: -
|
||||
// Changes Globals: -
|
||||
//============================================================================
|
||||
void PC_ConvertPath( char *path )
|
||||
void PC_ConvertPath (char *path, size_t pathSize)
|
||||
{
|
||||
char *ptr;
|
||||
|
||||
//remove double path seperators
|
||||
// remove double path seperators
|
||||
for ( ptr = path; *ptr; )
|
||||
{
|
||||
if ( ( *ptr == '\\' || *ptr == '/' ) &&
|
||||
( *( ptr + 1 ) == '\\' || *( ptr + 1 ) == '/' ) ) {
|
||||
strcpy( ptr, ptr + 1 );
|
||||
} //end if
|
||||
// strncpy (ptr, ptr + 1);
|
||||
Q_strncpyz (ptr, pathSize - (ptr - path), ptr + 1);
|
||||
} // end if
|
||||
else
|
||||
{
|
||||
ptr++;
|
||||
} //end else
|
||||
} //end while
|
||||
//set OS dependent path seperators
|
||||
} // end else
|
||||
} // end while
|
||||
// set OS dependent path seperators
|
||||
for ( ptr = path; *ptr; )
|
||||
{
|
||||
if ( *ptr == '/' || *ptr == '\\' ) {
|
||||
*ptr = PATHSEPERATOR_CHAR;
|
||||
}
|
||||
ptr++;
|
||||
} //end while
|
||||
} //end of the function PC_ConvertPath
|
||||
} // end while
|
||||
} // end of the function PC_ConvertPath
|
||||
//============================================================================
|
||||
//
|
||||
// Parameter: -
|
||||
|
@ -1146,18 +1194,23 @@ int PC_Directive_include( source_t *source )
|
|||
return qfalse;
|
||||
} //end if
|
||||
|
||||
if ( token.type == TT_STRING ) {
|
||||
StripDoubleQuotes( token.string );
|
||||
PC_ConvertPath( token.string );
|
||||
if ( token.type == TT_STRING )
|
||||
{
|
||||
StripDoubleQuotes (token.string, sizeof(token.string));
|
||||
PC_ConvertPath (token.string, sizeof(token.string));
|
||||
script = LoadScriptFile( token.string );
|
||||
if ( !script ) {
|
||||
strcpy( path, source->includepath );
|
||||
strcat( path, token.string );
|
||||
// strncpy (path, source->includepath);
|
||||
// strncat (path, token.string);
|
||||
Q_strncpyz (path, sizeof(path), source->includepath);
|
||||
Q_strncatz (path, sizeof(path), token.string);
|
||||
script = LoadScriptFile( path );
|
||||
} //end if
|
||||
} //end if
|
||||
else if ( token.type == TT_PUNCTUATION && *token.string == '<' ) {
|
||||
strcpy( path, source->includepath );
|
||||
else if ( token.type == TT_PUNCTUATION && *token.string == '<' )
|
||||
{
|
||||
// strncpy (path, source->includepath);
|
||||
Q_strncpyz (path, sizeof(path), source->includepath);
|
||||
while ( PC_ReadSourceToken( source, &token ) )
|
||||
{
|
||||
if ( token.linescrossed > 0 ) {
|
||||
|
@ -1176,7 +1229,7 @@ int PC_Directive_include( source_t *source )
|
|||
SourceError( source, "#include without file name between < >" );
|
||||
return qfalse;
|
||||
} //end if
|
||||
PC_ConvertPath( path );
|
||||
PC_ConvertPath (path, sizeof(path));
|
||||
script = LoadScriptFile( path );
|
||||
} //end if
|
||||
else
|
||||
|
@ -1368,10 +1421,11 @@ int PC_Directive_define( source_t *source )
|
|||
#endif //DEFINEHASHING
|
||||
} //end if
|
||||
//allocate define
|
||||
define = (define_t *) GetMemory( sizeof( define_t ) + (int)strlen( token.string ) + 1 );
|
||||
memset( define, 0, sizeof( define_t ) );
|
||||
define->name = (char *) define + sizeof( define_t );
|
||||
strcpy( define->name, token.string );
|
||||
define = (define_t *)GetMemory(sizeof(define_t) + (int)strlen(token.string) + 1);
|
||||
memset( define, 0, sizeof(define_t) );
|
||||
define->name = (char *)define + sizeof(define_t);
|
||||
// strncpy (define->name, token.string);
|
||||
Q_strncpyz (define->name, strlen(token.string) + 1, token.string);
|
||||
//add the define to the source
|
||||
#if DEFINEHASHING
|
||||
PC_AddDefineToHash( define, source->definehash );
|
||||
|
@ -1608,17 +1662,18 @@ define_t *PC_CopyDefine( source_t *source, define_t *define )
|
|||
define_t *newdefine;
|
||||
token_t *token, *newtoken, *lasttoken;
|
||||
|
||||
newdefine = (define_t *) GetMemory( sizeof( define_t ) + (int)strlen( define->name ) + 1 );
|
||||
//copy the define name
|
||||
newdefine->name = (char *) newdefine + sizeof( define_t );
|
||||
strcpy( newdefine->name, define->name );
|
||||
newdefine = (define_t *)GetMemory( sizeof(define_t) + (int)strlen(define->name) + 1);
|
||||
// copy the define name
|
||||
newdefine->name = (char *)newdefine + sizeof(define_t);
|
||||
// strncpy (newdefine->name, define->name);
|
||||
Q_strncpyz (newdefine->name, strlen(define->name) + 1, define->name);
|
||||
newdefine->flags = define->flags;
|
||||
newdefine->builtin = define->builtin;
|
||||
newdefine->numparms = define->numparms;
|
||||
//the define is not linked
|
||||
// the define is not linked
|
||||
newdefine->next = NULL;
|
||||
newdefine->hashnext = NULL;
|
||||
//copy the define tokens
|
||||
// copy the define tokens
|
||||
newdefine->tokens = NULL;
|
||||
for ( lasttoken = NULL, token = define->tokens; token; token = token->next )
|
||||
{
|
||||
|
@ -1626,10 +1681,13 @@ define_t *PC_CopyDefine( source_t *source, define_t *define )
|
|||
newtoken->next = NULL;
|
||||
if ( lasttoken ) {
|
||||
lasttoken->next = newtoken;
|
||||
} else { newdefine->tokens = newtoken;}
|
||||
}
|
||||
else {
|
||||
newdefine->tokens = newtoken;
|
||||
}
|
||||
lasttoken = newtoken;
|
||||
} //end for
|
||||
//copy the define parameters
|
||||
} // end for
|
||||
// copy the define parameters
|
||||
newdefine->parms = NULL;
|
||||
for ( lasttoken = NULL, token = define->parms; token; token = token->next )
|
||||
{
|
||||
|
@ -2579,7 +2637,8 @@ int PC_Directive_error( source_t *source )
|
|||
{
|
||||
token_t token;
|
||||
|
||||
strcpy( token.string, "" );
|
||||
// strncpy (token.string, "");
|
||||
Q_strncpyz (token.string, sizeof(token.string), "");
|
||||
PC_ReadSourceToken( source, &token );
|
||||
SourceError( source, "#error directive: %s", token.string );
|
||||
return qfalse;
|
||||
|
@ -2611,7 +2670,8 @@ void UnreadSignToken( source_t *source )
|
|||
token.whitespace_p = source->scriptstack->script_p;
|
||||
token.endwhitespace_p = source->scriptstack->script_p;
|
||||
token.linescrossed = 0;
|
||||
strcpy( token.string, "-" );
|
||||
// strncpy (token.string, "-");
|
||||
Q_strncpyz (token.string, sizeof(token.string), "-");
|
||||
token.type = TT_PUNCTUATION;
|
||||
token.subtype = P_SUB;
|
||||
PC_UnreadSourceToken( source, &token );
|
||||
|
@ -2624,8 +2684,8 @@ void UnreadSignToken( source_t *source )
|
|||
//============================================================================
|
||||
int PC_Directive_eval( source_t *source )
|
||||
{
|
||||
signed long int value;
|
||||
token_t token;
|
||||
signed long int value;
|
||||
token_t token;
|
||||
|
||||
if ( !PC_Evaluate( source, &value, NULL, qtrue ) ) {
|
||||
return qfalse;
|
||||
|
@ -2635,7 +2695,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, "%d", abs( value ) );
|
||||
Com_sprintf (token.string, sizeof(token.string), "%d", abs(value));
|
||||
token.type = TT_NUMBER;
|
||||
token.subtype = TT_INTEGER | TT_LONG | TT_DECIMAL;
|
||||
PC_UnreadSourceToken( source, &token );
|
||||
|
@ -2652,8 +2712,8 @@ int PC_Directive_eval( source_t *source )
|
|||
//============================================================================
|
||||
int PC_Directive_evalfloat( source_t *source )
|
||||
{
|
||||
double value;
|
||||
token_t token;
|
||||
double value;
|
||||
token_t token;
|
||||
|
||||
if ( !PC_Evaluate( source, NULL, &value, qfalse ) ) {
|
||||
return qfalse;
|
||||
|
@ -2662,7 +2722,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 ) );
|
||||
Com_sprintf (token.string, sizeof(token.string), "%1.2f", fabs(value));
|
||||
token.type = TT_NUMBER;
|
||||
token.subtype = TT_FLOAT | TT_LONG | TT_DECIMAL;
|
||||
PC_UnreadSourceToken( source, &token );
|
||||
|
@ -2733,8 +2793,8 @@ int PC_ReadDirective( source_t *source )
|
|||
//============================================================================
|
||||
int PC_DollarDirective_evalint( source_t *source )
|
||||
{
|
||||
signed long int value;
|
||||
token_t token;
|
||||
signed long int value;
|
||||
token_t token;
|
||||
|
||||
if ( !PC_DollarEvaluate( source, &value, NULL, qtrue ) ) {
|
||||
return qfalse;
|
||||
|
@ -2744,7 +2804,7 @@ 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, "%d", abs( value ) );
|
||||
Com_sprintf (token.string, sizeof(token.string), "%d", abs(value));
|
||||
token.type = TT_NUMBER;
|
||||
token.subtype = TT_INTEGER | TT_LONG | TT_DECIMAL;
|
||||
#ifdef NUMBERVALUE
|
||||
|
@ -2765,8 +2825,8 @@ int PC_DollarDirective_evalint( source_t *source )
|
|||
//============================================================================
|
||||
int PC_DollarDirective_evalfloat( source_t *source )
|
||||
{
|
||||
double value;
|
||||
token_t token;
|
||||
double value;
|
||||
token_t token;
|
||||
|
||||
if ( !PC_DollarEvaluate( source, NULL, &value, qfalse ) ) {
|
||||
return qfalse;
|
||||
|
@ -2775,7 +2835,7 @@ 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 ) );
|
||||
Com_sprintf (token.string, sizeof(token.string), "%1.2f", fabs(value));
|
||||
token.type = TT_NUMBER;
|
||||
token.subtype = TT_FLOAT | TT_LONG | TT_DECIMAL;
|
||||
#ifdef NUMBERVALUE
|
||||
|
@ -3012,51 +3072,68 @@ int PC_ExpectTokenType( source_t *source, int type, int subtype, token_t *token
|
|||
return qfalse;
|
||||
} //end if
|
||||
|
||||
if ( token->type != type ) {
|
||||
strcpy( str, "" );
|
||||
if ( token->type != type )
|
||||
{
|
||||
// strncpy (str, "");
|
||||
Q_strncpyz (str, sizeof(str), "");
|
||||
if ( type == TT_STRING ) {
|
||||
strcpy( str, "string" );
|
||||
// strncpy (str, "string");
|
||||
Q_strncpyz (str, sizeof(str), "string");
|
||||
}
|
||||
if ( type == TT_LITERAL ) {
|
||||
strcpy( str, "literal" );
|
||||
// strncpy (str, "literal");
|
||||
Q_strncpyz (str, sizeof(str), "literal");
|
||||
}
|
||||
if ( type == TT_NUMBER ) {
|
||||
strcpy( str, "number" );
|
||||
// strncpy (str, "number");
|
||||
Q_strncpyz (str, sizeof(str), "number");
|
||||
}
|
||||
if ( type == TT_NAME ) {
|
||||
strcpy( str, "name" );
|
||||
// strncpy (str, "name");
|
||||
Q_strncpyz (str, sizeof(str), "name");
|
||||
}
|
||||
if ( type == TT_PUNCTUATION ) {
|
||||
strcpy( str, "punctuation" );
|
||||
// strncpy (str, "punctuation");
|
||||
Q_strncpyz (str, sizeof(str), "punctuation");
|
||||
}
|
||||
SourceError( source, "expected a %s, found %s", str, token->string );
|
||||
return qfalse;
|
||||
} //end if
|
||||
if ( token->type == TT_NUMBER ) {
|
||||
if ( ( token->subtype & subtype ) != subtype ) {
|
||||
if ( token->type == TT_NUMBER )
|
||||
{
|
||||
if ( ( token->subtype & subtype ) != subtype )
|
||||
{
|
||||
if ( subtype & TT_DECIMAL ) {
|
||||
strcpy( str, "decimal" );
|
||||
// strncpy ( str, "decimal");
|
||||
Q_strncpyz ( str, sizeof(str), "decimal");
|
||||
}
|
||||
if ( subtype & TT_HEX ) {
|
||||
strcpy( str, "hex" );
|
||||
// strncpy (str, "hex");
|
||||
Q_strncpyz (str, sizeof(str), "hex");
|
||||
}
|
||||
if ( subtype & TT_OCTAL ) {
|
||||
strcpy( str, "octal" );
|
||||
// strncpy (str, "octal");
|
||||
Q_strncpyz (str, sizeof(str), "octal");
|
||||
}
|
||||
if ( subtype & TT_BINARY ) {
|
||||
strcpy( str, "binary" );
|
||||
// strncpy (str, "binary");
|
||||
Q_strncpyz (str, sizeof(str), "binary");
|
||||
}
|
||||
if ( subtype & TT_LONG ) {
|
||||
strcat( str, " long" );
|
||||
// strncat (str, " long");
|
||||
Q_strncatz (str, sizeof(str), " long");
|
||||
}
|
||||
if ( subtype & TT_UNSIGNED ) {
|
||||
strcat( str, " unsigned" );
|
||||
// strncat (str, " unsigned");
|
||||
Q_strncatz (str, sizeof(str), " unsigned");
|
||||
}
|
||||
if ( subtype & TT_FLOAT ) {
|
||||
strcat( str, " float" );
|
||||
// strncat (str, " float");
|
||||
Q_strncatz (str, sizeof(str), " float");
|
||||
}
|
||||
if ( subtype & TT_INTEGER ) {
|
||||
strcat( str, " integer" );
|
||||
// strncat (str, " integer");
|
||||
Q_strncatz (str, sizeof(str), " integer");
|
||||
}
|
||||
SourceError( source, "expected %s, found %s", str, token->string );
|
||||
return qfalse;
|
||||
|
@ -3181,7 +3258,8 @@ void PC_SetIncludePath( source_t *source, char *path )
|
|||
//add trailing path seperator
|
||||
if ( source->includepath[strlen( source->includepath ) - 1] != '\\' &&
|
||||
source->includepath[strlen( source->includepath ) - 1] != '/' ) {
|
||||
strcat( source->includepath, PATHSEPERATOR_STR );
|
||||
// strncat (source->includepath, PATHSEPERATOR_STR);
|
||||
Q_strncatz (source->includepath, sizeof(source->includepath), PATHSEPERATOR_STR);
|
||||
} //end if
|
||||
} //end of the function PC_SetIncludePath
|
||||
//============================================================================
|
||||
|
|
|
@ -176,7 +176,8 @@ punctuation_t default_punctuations[] =
|
|||
// Returns: -
|
||||
// Changes Globals: -
|
||||
//===========================================================================
|
||||
void PS_CreatePunctuationTable( script_t *script, punctuation_t *punctuations ) {
|
||||
void PS_CreatePunctuationTable( script_t *script, punctuation_t *punctuations )
|
||||
{
|
||||
int i;
|
||||
punctuation_t *p, *lastp, *newp;
|
||||
|
||||
|
@ -217,7 +218,8 @@ void PS_CreatePunctuationTable( script_t *script, punctuation_t *punctuations )
|
|||
// Returns: -
|
||||
// Changes Globals: -
|
||||
//===========================================================================
|
||||
char *PunctuationFromNum( script_t *script, int num ) {
|
||||
char *PunctuationFromNum( script_t *script, int num )
|
||||
{
|
||||
int i;
|
||||
|
||||
for ( i = 0; script->punctuations[i].p; i++ )
|
||||
|
@ -234,7 +236,8 @@ char *PunctuationFromNum( script_t *script, int num ) {
|
|||
// Returns: -
|
||||
// Changes Globals: -
|
||||
//===========================================================================
|
||||
void QDECL ScriptError( script_t *script, char *str, ... ) {
|
||||
void QDECL ScriptError( script_t *script, char *str, ... )
|
||||
{
|
||||
char text[1024];
|
||||
va_list ap;
|
||||
|
||||
|
@ -262,7 +265,8 @@ 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, char *str, ... )
|
||||
{
|
||||
char text[1024];
|
||||
va_list ap;
|
||||
|
||||
|
@ -290,15 +294,18 @@ void QDECL ScriptWarning( script_t *script, char *str, ... ) {
|
|||
// Returns: -
|
||||
// Changes Globals: -
|
||||
//===========================================================================
|
||||
void SetScriptPunctuations( script_t *script, punctuation_t *p ) {
|
||||
void SetScriptPunctuations( script_t *script, punctuation_t *p )
|
||||
{
|
||||
#ifdef PUNCTABLE
|
||||
if ( p ) {
|
||||
PS_CreatePunctuationTable( script, p );
|
||||
} else { PS_CreatePunctuationTable( script, default_punctuations );}
|
||||
}
|
||||
else { PS_CreatePunctuationTable( script, default_punctuations );}
|
||||
#endif //PUNCTABLE
|
||||
if ( p ) {
|
||||
script->punctuations = p;
|
||||
} else { script->punctuations = default_punctuations;}
|
||||
}
|
||||
else { script->punctuations = default_punctuations;}
|
||||
} //end of the function SetScriptPunctuations
|
||||
//============================================================================
|
||||
// Reads spaces, tabs, C-like comments etc.
|
||||
|
@ -308,7 +315,8 @@ void SetScriptPunctuations( script_t *script, punctuation_t *p ) {
|
|||
// Returns: -
|
||||
// Changes Globals: -
|
||||
//============================================================================
|
||||
int PS_ReadWhiteSpace( script_t *script ) {
|
||||
int PS_ReadWhiteSpace( script_t *script )
|
||||
{
|
||||
while ( 1 )
|
||||
{
|
||||
//skip white space
|
||||
|
@ -323,7 +331,8 @@ int PS_ReadWhiteSpace( script_t *script ) {
|
|||
script->script_p++;
|
||||
} //end while
|
||||
//skip comments
|
||||
if ( *script->script_p == '/' ) {
|
||||
if ( *script->script_p == '/' )
|
||||
{
|
||||
//comments //
|
||||
if ( *( script->script_p + 1 ) == '/' ) {
|
||||
script->script_p++;
|
||||
|
@ -343,7 +352,8 @@ int PS_ReadWhiteSpace( script_t *script ) {
|
|||
continue;
|
||||
} //end if
|
||||
//comments /* */
|
||||
else if ( *( script->script_p + 1 ) == '*' ) {
|
||||
else if ( *( script->script_p + 1 ) == '*' )
|
||||
{
|
||||
script->script_p++;
|
||||
do
|
||||
{
|
||||
|
@ -379,7 +389,8 @@ int PS_ReadWhiteSpace( script_t *script ) {
|
|||
// Returns: -
|
||||
// Changes Globals: -
|
||||
//============================================================================
|
||||
int PS_ReadEscapeCharacter( script_t *script, char *ch ) {
|
||||
int PS_ReadEscapeCharacter( script_t *script, char *ch )
|
||||
{
|
||||
int c, val, i;
|
||||
|
||||
//step over the leading '\\'
|
||||
|
@ -406,11 +417,16 @@ int PS_ReadEscapeCharacter( script_t *script, char *ch ) {
|
|||
c = *script->script_p;
|
||||
if ( c >= '0' && c <= '9' ) {
|
||||
c = c - '0';
|
||||
} else if ( c >= 'A' && c <= 'Z' ) {
|
||||
}
|
||||
else if ( c >= 'A' && c <= 'Z' ) {
|
||||
c = c - 'A' + 10;
|
||||
} else if ( c >= 'a' && c <= 'z' ) {
|
||||
}
|
||||
else if ( c >= 'a' && c <= 'z' ) {
|
||||
c = c - 'a' + 10;
|
||||
} else { break;}
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
val = ( val << 4 ) + c;
|
||||
} //end for
|
||||
script->script_p--;
|
||||
|
@ -431,7 +447,10 @@ int PS_ReadEscapeCharacter( script_t *script, char *ch ) {
|
|||
c = *script->script_p;
|
||||
if ( c >= '0' && c <= '9' ) {
|
||||
c = c - '0';
|
||||
} else { break;}
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
val = val * 10 + c;
|
||||
} //end for
|
||||
script->script_p--;
|
||||
|
@ -460,7 +479,8 @@ 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 ) {
|
||||
int PS_ReadString( script_t *script, token_t *token, int quote )
|
||||
{
|
||||
int len, tmpline;
|
||||
char *tmpscript_p;
|
||||
|
||||
|
@ -543,7 +563,8 @@ int PS_ReadString( script_t *script, token_t *token, int quote ) {
|
|||
// Returns: -
|
||||
// Changes Globals: -
|
||||
//============================================================================
|
||||
int PS_ReadName( script_t *script, token_t *token ) {
|
||||
int PS_ReadName( script_t *script, token_t *token )
|
||||
{
|
||||
int len = 0;
|
||||
char c;
|
||||
|
||||
|
@ -572,13 +593,15 @@ int PS_ReadName( script_t *script, token_t *token ) {
|
|||
// Changes Globals: -
|
||||
//============================================================================
|
||||
void NumberValue( char *string, int subtype, unsigned long int *intvalue,
|
||||
long double *floatvalue ) {
|
||||
long double *floatvalue )
|
||||
{
|
||||
unsigned long int dotfound = 0;
|
||||
|
||||
*intvalue = 0;
|
||||
*floatvalue = 0;
|
||||
//floating point number
|
||||
if ( subtype & TT_FLOAT ) {
|
||||
if ( subtype & TT_FLOAT )
|
||||
{
|
||||
while ( *string )
|
||||
{
|
||||
if ( *string == '.' ) {
|
||||
|
@ -605,7 +628,8 @@ void NumberValue( char *string, int subtype, unsigned long int *intvalue,
|
|||
while ( *string ) *intvalue = *intvalue * 10 + ( *string++ - '0' );
|
||||
*floatvalue = *intvalue;
|
||||
} //end else if
|
||||
else if ( subtype & TT_HEX ) {
|
||||
else if ( subtype & TT_HEX )
|
||||
{
|
||||
//step over the leading 0x or 0X
|
||||
string += 2;
|
||||
while ( *string )
|
||||
|
@ -639,7 +663,8 @@ void NumberValue( char *string, int subtype, unsigned long int *intvalue,
|
|||
// Returns: -
|
||||
// Changes Globals: -
|
||||
//============================================================================
|
||||
int PS_ReadNumber( script_t *script, token_t *token ) {
|
||||
int PS_ReadNumber( script_t *script, token_t *token )
|
||||
{
|
||||
int len = 0, i;
|
||||
int octal, dot;
|
||||
char c;
|
||||
|
@ -650,7 +675,8 @@ int PS_ReadNumber( script_t *script, token_t *token ) {
|
|||
//check for a hexadecimal number
|
||||
if ( *script->script_p == '0' &&
|
||||
( *( script->script_p + 1 ) == 'x' ||
|
||||
*( script->script_p + 1 ) == 'X' ) ) {
|
||||
*( script->script_p + 1 ) == 'X' ) )
|
||||
{
|
||||
token->string[len++] = *script->script_p++;
|
||||
token->string[len++] = *script->script_p++;
|
||||
c = *script->script_p;
|
||||
|
@ -672,7 +698,8 @@ int PS_ReadNumber( script_t *script, token_t *token ) {
|
|||
//check for a binary number
|
||||
else if ( *script->script_p == '0' &&
|
||||
( *( script->script_p + 1 ) == 'b' ||
|
||||
*( script->script_p + 1 ) == 'B' ) ) {
|
||||
*( script->script_p + 1 ) == 'B' ) )
|
||||
{
|
||||
token->string[len++] = *script->script_p++;
|
||||
token->string[len++] = *script->script_p++;
|
||||
c = *script->script_p;
|
||||
|
@ -750,7 +777,8 @@ int PS_ReadNumber( script_t *script, token_t *token ) {
|
|||
// Returns: -
|
||||
// Changes Globals: -
|
||||
//============================================================================
|
||||
int PS_ReadLiteral( script_t *script, token_t *token ) {
|
||||
int PS_ReadLiteral( script_t *script, token_t *token )
|
||||
{
|
||||
token->type = TT_LITERAL;
|
||||
//first quote
|
||||
token->string[0] = *script->script_p++;
|
||||
|
@ -797,7 +825,8 @@ int PS_ReadLiteral( script_t *script, token_t *token ) {
|
|||
// Returns: -
|
||||
// Changes Globals: -
|
||||
//============================================================================
|
||||
int PS_ReadPunctuation( script_t *script, token_t *token ) {
|
||||
int PS_ReadPunctuation( script_t *script, token_t *token )
|
||||
{
|
||||
int len;
|
||||
char *p;
|
||||
punctuation_t *punc;
|
||||
|
@ -815,7 +844,8 @@ int PS_ReadPunctuation( script_t *script, token_t *token ) {
|
|||
p = punc->p;
|
||||
len = (int)strlen( p );
|
||||
//if the script contains at least as much characters as the punctuation
|
||||
if ( script->script_p + len <= script->end_p ) {
|
||||
if ( script->script_p + len <= script->end_p )
|
||||
{
|
||||
//if the script contains the punctuation
|
||||
if ( !strncmp( script->script_p, p, len ) ) {
|
||||
strncpy( token->string, p, MAX_TOKEN );
|
||||
|
@ -835,7 +865,8 @@ int PS_ReadPunctuation( script_t *script, token_t *token ) {
|
|||
// Returns: -
|
||||
// Changes Globals: -
|
||||
//============================================================================
|
||||
int PS_ReadPrimitive( script_t *script, token_t *token ) {
|
||||
int PS_ReadPrimitive( script_t *script, token_t *token )
|
||||
{
|
||||
int len;
|
||||
|
||||
len = 0;
|
||||
|
@ -859,7 +890,8 @@ int PS_ReadPrimitive( script_t *script, token_t *token ) {
|
|||
// Returns: -
|
||||
// Changes Globals: -
|
||||
//============================================================================
|
||||
int PS_ReadToken( script_t *script, token_t *token ) {
|
||||
int PS_ReadToken( script_t *script, token_t *token )
|
||||
{
|
||||
//if there is a token available (from UnreadToken)
|
||||
if ( script->tokenavailable ) {
|
||||
script->tokenavailable = 0;
|
||||
|
@ -935,7 +967,8 @@ 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, char *string )
|
||||
{
|
||||
token_t token;
|
||||
|
||||
if ( !PS_ReadToken( script, &token ) ) {
|
||||
|
@ -955,64 +988,82 @@ int PS_ExpectTokenString( script_t *script, char *string ) {
|
|||
// Returns: -
|
||||
// Changes Globals: -
|
||||
//============================================================================
|
||||
int PS_ExpectTokenType( script_t *script, int type, int subtype, token_t *token ) {
|
||||
int PS_ExpectTokenType( script_t *script, int type, int subtype, token_t *token )
|
||||
{
|
||||
char str[MAX_TOKEN];
|
||||
|
||||
if ( !PS_ReadToken( script, token ) ) {
|
||||
ScriptError( script, "couldn't read expected token" );
|
||||
return 0;
|
||||
} //end if
|
||||
} // end if
|
||||
|
||||
if ( token->type != type ) {
|
||||
if ( token->type != type )
|
||||
{
|
||||
if ( type == TT_STRING ) {
|
||||
strcpy( str, "string" );
|
||||
// strncpy (str, "string");
|
||||
Q_strncpyz (str, sizeof(str), "string");
|
||||
}
|
||||
if ( type == TT_LITERAL ) {
|
||||
strcpy( str, "literal" );
|
||||
// strncpy (str, "literal");
|
||||
Q_strncpyz (str, sizeof(str), "literal");
|
||||
}
|
||||
if ( type == TT_NUMBER ) {
|
||||
strcpy( str, "number" );
|
||||
// strncpy (str, "number");
|
||||
Q_strncpyz (str, sizeof(str), "number");
|
||||
}
|
||||
if ( type == TT_NAME ) {
|
||||
strcpy( str, "name" );
|
||||
// strncpy (str, "name");
|
||||
Q_strncpyz (str, sizeof(str), "name");
|
||||
}
|
||||
if ( type == TT_PUNCTUATION ) {
|
||||
strcpy( str, "punctuation" );
|
||||
// strncpy (str, "punctuation");
|
||||
Q_strncpyz (str, sizeof(str), "punctuation");
|
||||
}
|
||||
ScriptError( script, "expected a %s, found %s", str, token->string );
|
||||
return 0;
|
||||
} //end if
|
||||
if ( token->type == TT_NUMBER ) {
|
||||
if ( ( token->subtype & subtype ) != subtype ) {
|
||||
if ( token->type == TT_NUMBER )
|
||||
{
|
||||
if ( ( token->subtype & subtype ) != subtype )
|
||||
{
|
||||
if ( subtype & TT_DECIMAL ) {
|
||||
strcpy( str, "decimal" );
|
||||
// strncpy (str, "decimal" );
|
||||
Q_strncpyz (str, sizeof(str), "decimal" );
|
||||
}
|
||||
if ( subtype & TT_HEX ) {
|
||||
strcpy( str, "hex" );
|
||||
// strncpy (str, "hex");
|
||||
Q_strncpyz (str, sizeof(str), "hex");
|
||||
}
|
||||
if ( subtype & TT_OCTAL ) {
|
||||
strcpy( str, "octal" );
|
||||
// strncpy (str, "octal");
|
||||
Q_strncpyz (str, sizeof(str), "octal");
|
||||
}
|
||||
if ( subtype & TT_BINARY ) {
|
||||
strcpy( str, "binary" );
|
||||
// strncpy (str, "binary");
|
||||
Q_strncpyz (str, sizeof(str), "binary");
|
||||
}
|
||||
if ( subtype & TT_LONG ) {
|
||||
strcat( str, " long" );
|
||||
// strncat (str, " long");
|
||||
Q_strncatz (str, sizeof(str), " long");
|
||||
}
|
||||
if ( subtype & TT_UNSIGNED ) {
|
||||
strcat( str, " unsigned" );
|
||||
// strncat (str, " unsigned");
|
||||
Q_strncatz (str, sizeof(str), " unsigned");
|
||||
}
|
||||
if ( subtype & TT_FLOAT ) {
|
||||
strcat( str, " float" );
|
||||
// strncat (str, " float" );
|
||||
Q_strncatz (str, sizeof(str), " float" );
|
||||
}
|
||||
if ( subtype & TT_INTEGER ) {
|
||||
strcat( str, " integer" );
|
||||
// strncat (str, " integer");
|
||||
Q_strncatz (str, sizeof(str), " integer");
|
||||
}
|
||||
ScriptError( script, "expected %s, found %s", str, token->string );
|
||||
return 0;
|
||||
} //end if
|
||||
} //end if
|
||||
else if ( token->type == TT_PUNCTUATION ) {
|
||||
else if ( token->type == TT_PUNCTUATION )
|
||||
{
|
||||
if ( subtype < 0 ) {
|
||||
ScriptError( script, "BUG: wrong punctuation subtype" );
|
||||
return 0;
|
||||
|
@ -1031,7 +1082,8 @@ 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 ) ) {
|
||||
ScriptError( script, "couldn't read expected token" );
|
||||
return 0;
|
||||
|
@ -1047,7 +1099,8 @@ int PS_ExpectAnyToken( script_t *script, token_t *token ) {
|
|||
// Returns: -
|
||||
// Changes Globals: -
|
||||
//============================================================================
|
||||
int PS_CheckTokenString( script_t *script, char *string ) {
|
||||
int PS_CheckTokenString( script_t *script, char *string )
|
||||
{
|
||||
token_t tok;
|
||||
|
||||
if ( !PS_ReadToken( script, &tok ) ) {
|
||||
|
@ -1067,7 +1120,8 @@ int PS_CheckTokenString( script_t *script, char *string ) {
|
|||
// 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;
|
||||
|
||||
if ( !PS_ReadToken( script, &tok ) ) {
|
||||
|
@ -1089,7 +1143,8 @@ int PS_CheckTokenType( script_t *script, int type, int subtype, token_t *token )
|
|||
// Returns: -
|
||||
// Changes Globals: -
|
||||
//============================================================================
|
||||
int PS_SkipUntilString( script_t *script, char *string ) {
|
||||
int PS_SkipUntilString( script_t *script, char *string )
|
||||
{
|
||||
token_t token;
|
||||
|
||||
while ( PS_ReadToken( script, &token ) )
|
||||
|
@ -1106,7 +1161,8 @@ int PS_SkipUntilString( script_t *script, char *string ) {
|
|||
// Returns: -
|
||||
// Changes Globals: -
|
||||
//============================================================================
|
||||
void PS_UnreadLastToken( script_t *script ) {
|
||||
void PS_UnreadLastToken( script_t *script )
|
||||
{
|
||||
script->tokenavailable = 1;
|
||||
} //end of the function UnreadLastToken
|
||||
//============================================================================
|
||||
|
@ -1115,7 +1171,8 @@ void PS_UnreadLastToken( script_t *script ) {
|
|||
// Returns: -
|
||||
// Changes Globals: -
|
||||
//============================================================================
|
||||
void PS_UnreadToken( script_t *script, token_t *token ) {
|
||||
void PS_UnreadToken( script_t *script, token_t *token )
|
||||
{
|
||||
memcpy( &script->token, token, sizeof( token_t ) );
|
||||
script->tokenavailable = 1;
|
||||
} //end of the function UnreadToken
|
||||
|
@ -1126,12 +1183,12 @@ void PS_UnreadToken( script_t *script, token_t *token ) {
|
|||
// Returns: -
|
||||
// Changes Globals: -
|
||||
//============================================================================
|
||||
char PS_NextWhiteSpaceChar( script_t *script ) {
|
||||
if ( script->whitespace_p != script->endwhitespace_p ) {
|
||||
char PS_NextWhiteSpaceChar( script_t *script )
|
||||
{
|
||||
if ( script->whitespace_p != script->endwhitespace_p ){
|
||||
return *script->whitespace_p++;
|
||||
} //end if
|
||||
else
|
||||
{
|
||||
else {
|
||||
return 0;
|
||||
} //end else
|
||||
} //end of the function PS_NextWhiteSpaceChar
|
||||
|
@ -1141,35 +1198,40 @@ char PS_NextWhiteSpaceChar( script_t *script ) {
|
|||
// Returns: -
|
||||
// Changes Globals: -
|
||||
//============================================================================
|
||||
void StripDoubleQuotes( char *string ) {
|
||||
void StripDoubleQuotes (char *string, size_t strSize)
|
||||
{
|
||||
if ( *string == '\"' ) {
|
||||
strcpy( string, string + 1 );
|
||||
} //end if
|
||||
// strncpy (string, string + 1);
|
||||
Q_strncpyz (string, strSize, string + 1);
|
||||
} // end if
|
||||
if ( string[strlen( string ) - 1] == '\"' ) {
|
||||
string[strlen( string ) - 1] = '\0';
|
||||
} //end if
|
||||
} //end of the function StripDoubleQuotes
|
||||
} // end if
|
||||
} // end of the function StripDoubleQuotes
|
||||
//============================================================================
|
||||
//
|
||||
// Parameter: -
|
||||
// Returns: -
|
||||
// Changes Globals: -
|
||||
//============================================================================
|
||||
void StripSingleQuotes( char *string ) {
|
||||
void StripSingleQuotes (char *string, size_t strSize)
|
||||
{
|
||||
if ( *string == '\'' ) {
|
||||
strcpy( string, string + 1 );
|
||||
} //end if
|
||||
// strncpy (string, string + 1);
|
||||
Q_strncpyz (string, strSize, string + 1);
|
||||
} // end if
|
||||
if ( string[strlen( string ) - 1] == '\'' ) {
|
||||
string[strlen( string ) - 1] = '\0';
|
||||
} //end if
|
||||
} //end of the function StripSingleQuotes
|
||||
} // end if
|
||||
} // end of the function StripSingleQuotes
|
||||
//============================================================================
|
||||
//
|
||||
// Parameter: -
|
||||
// Returns: -
|
||||
// Changes Globals: -
|
||||
//============================================================================
|
||||
long double ReadSignedFloat( script_t *script ) {
|
||||
long double ReadSignedFloat( script_t *script )
|
||||
{
|
||||
token_t token;
|
||||
long double sign = 1;
|
||||
|
||||
|
@ -1189,7 +1251,8 @@ long double ReadSignedFloat( script_t *script ) {
|
|||
// 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;
|
||||
|
||||
|
@ -1209,7 +1272,8 @@ signed long int ReadSignedInt( script_t *script ) {
|
|||
// Returns: -
|
||||
// Changes Globals: -
|
||||
//============================================================================
|
||||
void SetScriptFlags( script_t *script, int flags ) {
|
||||
void SetScriptFlags( script_t *script, int flags )
|
||||
{
|
||||
script->flags = flags;
|
||||
} //end of the function SetScriptFlags
|
||||
//============================================================================
|
||||
|
@ -1218,7 +1282,8 @@ 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
|
||||
//============================================================================
|
||||
|
@ -1227,7 +1292,8 @@ int GetScriptFlags( script_t *script ) {
|
|||
// Returns: -
|
||||
// Changes Globals: -
|
||||
//============================================================================
|
||||
void ResetScript( script_t *script ) {
|
||||
void ResetScript( script_t *script )
|
||||
{
|
||||
//pointer in script buffer
|
||||
script->script_p = script->buffer;
|
||||
//pointer in script buffer before reading token
|
||||
|
@ -1251,7 +1317,8 @@ void ResetScript( script_t *script ) {
|
|||
// Returns: -
|
||||
// Changes Globals: -
|
||||
//============================================================================
|
||||
int EndOfScript( script_t *script ) {
|
||||
int EndOfScript( script_t *script )
|
||||
{
|
||||
return script->script_p >= script->end_p;
|
||||
} //end of the function EndOfScript
|
||||
//============================================================================
|
||||
|
@ -1260,7 +1327,8 @@ 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
|
||||
//============================================================================
|
||||
|
@ -1269,7 +1337,8 @@ int NumLinesCrossed( script_t *script ) {
|
|||
// Returns: -
|
||||
// Changes Globals: -
|
||||
//============================================================================
|
||||
int ScriptSkipTo( script_t *script, char *value ) {
|
||||
int ScriptSkipTo( script_t *script, char *value )
|
||||
{
|
||||
int len;
|
||||
char firstchar;
|
||||
|
||||
|
@ -1295,7 +1364,8 @@ int ScriptSkipTo( script_t *script, char *value ) {
|
|||
// Returns: -
|
||||
// Changes Globals: -
|
||||
//============================================================================
|
||||
int FileLength( FILE *fp ) {
|
||||
int FileLength( FILE *fp )
|
||||
{
|
||||
int pos;
|
||||
int end;
|
||||
|
||||
|
@ -1313,7 +1383,8 @@ int FileLength( FILE *fp ) {
|
|||
// Returns: -
|
||||
// Changes Globals: -
|
||||
//============================================================================
|
||||
script_t *LoadScriptFile( char *filename ) {
|
||||
script_t *LoadScriptFile( char *filename )
|
||||
{
|
||||
#ifdef BOTLIB
|
||||
fileHandle_t fp;
|
||||
char pathname[MAX_QPATH];
|
||||
|
@ -1339,10 +1410,11 @@ script_t *LoadScriptFile( char *filename ) {
|
|||
length = FileLength( fp );
|
||||
#endif
|
||||
|
||||
buffer = GetClearedMemory( sizeof( script_t ) + length + 1 );
|
||||
buffer = GetClearedMemory(sizeof(script_t) + length + 1);
|
||||
script = (script_t *) buffer;
|
||||
memset( script, 0, sizeof( script_t ) );
|
||||
strcpy( script->filename, filename );
|
||||
memset( script, 0, sizeof(script_t) );
|
||||
// strncpy (script->filename, filename);
|
||||
Q_strncpyz (script->filename, sizeof(script->filename), filename);
|
||||
script->buffer = (char *) buffer + sizeof( script_t );
|
||||
script->buffer[length] = 0;
|
||||
script->length = length;
|
||||
|
@ -1380,14 +1452,16 @@ script_t *LoadScriptFile( char *filename ) {
|
|||
// Returns: -
|
||||
// Changes Globals: -
|
||||
//============================================================================
|
||||
script_t *LoadScriptMemory( char *ptr, int length, char *name ) {
|
||||
script_t *LoadScriptMemory( char *ptr, int length, char *name )
|
||||
{
|
||||
void *buffer;
|
||||
script_t *script;
|
||||
|
||||
buffer = GetClearedMemory( sizeof( script_t ) + length + 1 );
|
||||
script = (script_t *) buffer;
|
||||
memset( script, 0, sizeof( script_t ) );
|
||||
strcpy( script->filename, name );
|
||||
buffer = GetClearedMemory (sizeof(script_t) + length + 1);
|
||||
script = (script_t *)buffer;
|
||||
memset( script, 0, sizeof(script_t) );
|
||||
// strncpy (script->filename, name);
|
||||
Q_strncpyz (script->filename, sizeof(script->filename), name);
|
||||
script->buffer = (char *) buffer + sizeof( script_t );
|
||||
script->buffer[length] = 0;
|
||||
script->length = length;
|
||||
|
@ -1415,7 +1489,8 @@ script_t *LoadScriptMemory( char *ptr, int length, char *name ) {
|
|||
// Returns: -
|
||||
// Changes Globals: -
|
||||
//============================================================================
|
||||
void FreeScript( script_t *script ) {
|
||||
void FreeScript( script_t *script )
|
||||
{
|
||||
#ifdef PUNCTABLE
|
||||
if ( script->punctuationtable ) {
|
||||
FreeMemory( script->punctuationtable );
|
||||
|
|
|
@ -250,9 +250,9 @@ 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 );
|
||||
//remove any leading and trailing double quotes from the token
|
||||
void StripDoubleQuotes( char *string );
|
||||
void StripDoubleQuotes (char *string, size_t strSize);
|
||||
//remove any leading and trailing single quotes from the token
|
||||
void StripSingleQuotes( char *string );
|
||||
void StripSingleQuotes (char *string, size_t strSize);
|
||||
//read a possible signed integer
|
||||
signed long int ReadSignedInt( script_t *script );
|
||||
//read a possible signed floating point number
|
||||
|
@ -280,4 +280,6 @@ void QDECL ScriptError( script_t *script, char *str, ... );
|
|||
//print a script warning with filename and line number
|
||||
void QDECL ScriptWarning( script_t *script, char *str, ... );
|
||||
|
||||
|
||||
// Knightmare added
|
||||
void Q_strncpyz (char *dest, size_t destSize, const char *src);
|
||||
void Q_strncatz (char *dest, size_t destSize, const char *src);
|
||||
|
|
|
@ -2028,7 +2028,7 @@ size_t Q_strncpyz (char *dst, size_t dstSize, const char *src)
|
|||
*d = 0;
|
||||
dst[dstSize-1] = 0;
|
||||
|
||||
if (decSize == 0) // Unsufficent room in dst, return count + length of remaining src
|
||||
if (decSize == 0) // Insufficent room in dst, return count + length of remaining src
|
||||
return (s - src - 1 + strlen(s));
|
||||
else
|
||||
return (s - src - 1); // returned count excludes NULL terminator
|
||||
|
|
Binary file not shown.
Loading…
Reference in a new issue