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