fix typo (?) in extractfuncs tool to fix segfault when run w/o any args.

fix some warnings.

Submitted by: Ozkan Sezer
This commit is contained in:
Yamagi Burmeister 2015-08-31 18:57:16 +02:00
parent 264ca3d89e
commit faa5144244
4 changed files with 178 additions and 173 deletions

View File

@ -1,3 +1,3 @@
#!/bin/sh #!/bin/sh
gcc -g -o extractfuncts -DSCREWUP extractfuncs.c l_log.c l_memory.c l_precomp.c l_script.c clang -o extractfuncs -Wall -DSCREWUP extractfuncs.c l_log.c l_memory.c l_precomp.c l_script.c

View File

@ -48,14 +48,14 @@ static char *func_decsfile = "g_func_decs.h";
#define TEMP_LIST_NAME "g_func_list.tmp" #define TEMP_LIST_NAME "g_func_list.tmp"
#define TEMP_DECS_NAME "g_func_decs.tmp" #define TEMP_DECS_NAME "g_func_decs.tmp"
//=========================================================================== //===========================================================================
#if 0 #if 0
/* /*
================= =================
WriteWhiteSpace WriteWhiteSpace
================= =================
*/ */
void WriteWhiteSpace (FILE *fp, script_t *script) void WriteWhiteSpace (FILE *fp, script_t *script)
{ {
int c; int c;
@ -71,11 +71,11 @@ void WriteWhiteSpace (FILE *fp, script_t *script)
} //end while } //end while
} //end of the function WriteWhiteSpace } //end of the function WriteWhiteSpace
/* /*
================= =================
WriteString WriteString
================= =================
*/ */
void WriteString (FILE *fp, script_t *script) void WriteString (FILE *fp, script_t *script)
{ {
char *ptr; char *ptr;
@ -88,11 +88,11 @@ void WriteString (FILE *fp, script_t *script)
} //end while } //end while
} //end of the function WriteString } //end of the function WriteString
/* /*
================= =================
ScrewUpFile ScrewUpFile
================= =================
*/ */
void ScrewUpFile (char *oldfile, char *newfile) void ScrewUpFile (char *oldfile, char *newfile)
{ {
FILE *fp; FILE *fp;
@ -137,11 +137,11 @@ void ScrewUpFile (char *oldfile, char *newfile)
} //end of the function ScrewUpFile } //end of the function ScrewUpFile
#endif #endif
/* /*
================= =================
Error Error
================= =================
*/ */
void Error (char *error, ...) void Error (char *error, ...)
{ {
va_list argptr; va_list argptr;
@ -153,11 +153,11 @@ void Error (char *error, ...)
exit( 1 ); exit( 1 );
} }
/* /*
================= =================
DumpReplaceFunctions DumpReplaceFunctions
================= =================
*/ */
void DumpReplaceFunctions (char *typeName) void DumpReplaceFunctions (char *typeName)
{ {
replacefunc_t *rf; replacefunc_t *rf;
@ -196,7 +196,7 @@ void DumpReplaceFunctions (char *typeName)
fclose( f ); fclose( f );
strcpy( path, func_listfile ); strcpy( path, func_listfile );
if ( f = fopen( path, "rb" ) ) if ((f = fopen( path, "rb" )) != NULL)
{ {
fseek( f, 0, SEEK_END ); fseek( f, 0, SEEK_END );
newlen = ftell( f ); newlen = ftell( f );
@ -264,7 +264,7 @@ void DumpReplaceFunctions (char *typeName)
fclose( f ); fclose( f );
strcpy( path, func_decsfile ); strcpy( path, func_decsfile );
if ( f = fopen( path, "rb" ) ) if ((f = fopen( path, "rb" )) != NULL)
{ {
fseek( f, 0, SEEK_END ); fseek( f, 0, SEEK_END );
newlen = ftell( f ); newlen = ftell( f );
@ -317,11 +317,11 @@ void DumpReplaceFunctions (char *typeName)
#endif #endif
} // end of the function DumpReplaceFunctions } // end of the function DumpReplaceFunctions
/* /*
================= =================
FindFunctionName FindFunctionName
================= =================
*/ */
replacefunc_t *FindFunctionName (char *funcname) replacefunc_t *FindFunctionName (char *funcname)
{ {
replacefunc_t *f; replacefunc_t *f;
@ -336,11 +336,11 @@ replacefunc_t *FindFunctionName (char *funcname)
return NULL; return NULL;
} //end of the function FindFunctionName } //end of the function FindFunctionName
/* /*
================= =================
MayScrewUp MayScrewUp
================= =================
*/ */
int MayScrewUp (char *funcname) int MayScrewUp (char *funcname)
{ {
if ( !strcmp(funcname, "GetBotAPI") ) if ( !strcmp(funcname, "GetBotAPI") )
@ -358,11 +358,11 @@ int MayScrewUp (char *funcname)
return true; return true;
} //end of the function MayScrewUp } //end of the function MayScrewUp
/* /*
================= =================
ConcatDec ConcatDec
================= =================
*/ */
void ConcatDec (tokenList_t *list, char *str, int inc) void ConcatDec (tokenList_t *list, char *str, int inc)
{ {
/* if (!((list->token.type == TT_NAME) || (list->token.string[0] == '*'))) { /* if (!((list->token.type == TT_NAME) || (list->token.string[0] == '*'))) {
@ -381,11 +381,11 @@ void ConcatDec (tokenList_t *list, char *str, int inc)
strcat(str, " " ); strcat(str, " " );
} }
/* /*
================= =================
AddFunctionName 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;
@ -433,11 +433,11 @@ void AddFunctionName (char *funcname, char *filename, tokenList_t *head)
} //end of the function AddFunctionName } //end of the function AddFunctionName
/* /*
================= =================
AddTokenToList AddTokenToList
================= =================
*/ */
void AddTokenToList (tokenList_t **head, token_t *token) void AddTokenToList (tokenList_t **head, token_t *token)
{ {
tokenList_t *newhead; tokenList_t *newhead;
@ -454,10 +454,10 @@ void AddTokenToList (tokenList_t **head, token_t *token)
} }
#if 0 #if 0
/* /*
================= =================
KillTokenList KillTokenList
================= =================
*/ */
void KillTokenList (tokenList_t *head) void KillTokenList (tokenList_t *head)
{ {
@ -469,11 +469,11 @@ void KillTokenList (tokenList_t *head)
} }
#endif #endif
/* /*
================= =================
StripTokenList StripTokenList
================= =================
*/ */
void StripTokenList (tokenList_t *head) void StripTokenList (tokenList_t *head)
{ {
tokenList_t *trav, *lastTrav; tokenList_t *trav, *lastTrav;
@ -496,13 +496,13 @@ void StripTokenList (tokenList_t *head)
lastTrav->next = NULL; lastTrav->next = NULL;
} }
/* /*
================= =================
GetTypeNamesFromFile GetTypeNamesFromFile
Knightmare- this gets structs / vars of a given type Knightmare- this gets structs / vars of a given type
================= =================
*/ */
void GetTypeNamesFromFile (char *filename, char *typeName) void GetTypeNamesFromFile (char *filename, char *typeName)
{ {
source_t *source; source_t *source;
@ -572,11 +572,11 @@ void GetTypeNamesFromFile (char *filename, char *typeName)
FreeSource( source ); FreeSource( source );
} }
/* /*
================= =================
GetFunctionNamesFromFile GetFunctionNamesFromFile
================= =================
*/ */
void GetFunctionNamesFromFile (char *filename) void GetFunctionNamesFromFile (char *filename)
{ {
source_t *source; source_t *source;
@ -669,11 +669,11 @@ void GetFunctionNamesFromFile (char *filename)
FreeSource( source ); FreeSource( source );
} //end of the function GetFunctionNamesFromFile } //end of the function GetFunctionNamesFromFile
/* /*
================= =================
Usage Usage
================= =================
*/ */
void Usage (void) void Usage (void)
{ {
// Error( "USAGE SCREWUP: extractfuncs <file filter>\n" ); // Error( "USAGE SCREWUP: extractfuncs <file filter>\n" );
@ -681,60 +681,60 @@ void Usage (void)
"no -o defaults to g_func_list.h g_func_decs.h or g_<structname>_list.h g_<structname>_decs.h\n" ); "no -o defaults to g_func_list.h g_func_decs.h or g_<structname>_list.h g_<structname>_decs.h\n" );
} }
/* /*
================= =================
main main
================= =================
*/ */
#ifdef _WIN32 #ifdef _WIN32
void main (int argc, char *argv[]) void main (int argc, char *argv[])
{ {
WIN32_FIND_DATA filedata; WIN32_FIND_DATA filedata;
HWND handle; HWND handle;
int i, firstParm, done; int i, firstParm, done;
char typeName[128]; char typeName[128];
qboolean typeExtract = false; qboolean typeExtract = false;
qboolean firstParmSet = false; qboolean firstParmSet = false;
// if ( argc < 2 ) // if ( argc < 2 )
// Usage (); // Usage ();
// Knightmare- check for command line switches // Knightmare- check for command line switches
for (i=0; i<argc; i++) for (i=0; i<argc; i++)
{ {
if (!firstParmSet && argv[i][0] == '-') if (!firstParmSet && argv[i][0] == '-')
{ {
firstParm = i; firstParm = i;
firstParmSet = true; firstParmSet = true;
} }
if ( !Q_stricmp(argv[i], "-t") && (i < argc-1) && (argv[i+1][0] != '-') ) if ( !Q_stricmp(argv[i], "-t") && (i < argc-1) && (argv[i+1][0] != '-') )
{ {
char buf[_MAX_PATH]; char buf[_MAX_PATH];
Com_sprintf (typeName, sizeof(typeName), argv[i+1]); Com_sprintf (typeName, sizeof(typeName), argv[i+1]);
printf("Data type to extract: %s\n", typeName); printf("Data type to extract: %s\n", typeName);
Com_sprintf (buf, sizeof(buf), "g_%s_list.h", typeName); Com_sprintf (buf, sizeof(buf), "g_%s_list.h", typeName);
func_listfile = strdup(buf); func_listfile = strdup(buf);
Com_sprintf (buf, sizeof(buf), "g_%s_decs.h", typeName); Com_sprintf (buf, sizeof(buf), "g_%s_decs.h", typeName);
func_decsfile = strdup(buf); func_decsfile = strdup(buf);
typeExtract = true; typeExtract = true;
} }
else if ( !Q_stricmp(argv[i], "-o") && (i < argc-1) && (argv[i+1][0] != '-') ) else if ( !Q_stricmp(argv[i], "-o") && (i < argc-1) && (argv[i+1][0] != '-') )
{ {
func_listfile = argv[i+1]; func_listfile = argv[i+1];
printf("Pointer table list file: %s\n", func_listfile); printf("Pointer table list file: %s\n", func_listfile);
if ( (i < argc-2) && (argv[i+2][0] != '-') ) if ( (i < argc-2) && (argv[i+2][0] != '-') )
{ {
func_decsfile = argv[i+2]; func_decsfile = argv[i+2];
printf("Pointer list decs file: %s\n", func_decsfile); printf("Pointer list decs file: %s\n", func_decsfile);
} }
} }
else if (!Q_stricmp(argv[i], "-d")) { else if (!Q_stricmp(argv[i], "-d")) {
printf("Define option not yet implemented.\n"); printf("Define option not yet implemented.\n");
} }
} }
if (argc < 1 || (firstParmSet && firstParm < 1)) if (argc < 2 || (firstParmSet && firstParm < 1))
Usage (); Usage ();
// end Knightmare // end Knightmare
@ -756,6 +756,8 @@ void main (int argc, char *argv[])
DumpReplaceFunctions (typeName); DumpReplaceFunctions (typeName);
else else
DumpReplaceFunctions (NULL); DumpReplaceFunctions (NULL);
return 0;
} }
#else #else
/* /*
@ -766,9 +768,9 @@ int main (int argc, char *argv[])
{ {
int i, firstParm; int i, firstParm;
int argbase = 1; int argbase = 1;
char typeName[128]; char typeName[128];
qboolean typeExtract = false; qboolean typeExtract = false;
qboolean firstParmSet = false; qboolean firstParmSet = false;
/* if ( argc < 2 ) /* if ( argc < 2 )
Usage(); Usage();
@ -783,42 +785,42 @@ int main (int argc, char *argv[])
argbase = 4; argbase = 4;
} }
*/ */
// Knightmare- check for command line switches // Knightmare- check for command line switches
for (i=0; i<argc; i++) for (i=0; i<argc; i++)
{ {
if (!firstParmSet && argv[i][0] == '-') if (!firstParmSet && argv[i][0] == '-')
{ {
firstParm = i; firstParm = i;
firstParmSet = true; firstParmSet = true;
} }
if ( !Q_stricmp(argv[i], "-t") && (i < argc-1) && (argv[i+1][0] != '-') ) if ( !Q_stricmp(argv[i], "-t") && (i < argc-1) && (argv[i+1][0] != '-') )
{ {
char buf[_MAX_PATH]; char buf[_MAX_PATH];
Com_sprintf (typeName, sizeof(typeName), argv[i+1]); Com_sprintf (typeName, sizeof(typeName), argv[i+1]);
printf("Data type to extract: %s\n", typeName); printf("Data type to extract: %s\n", typeName);
Com_sprintf (buf, sizeof(buf), "g_%s_list.h", typeName); Com_sprintf (buf, sizeof(buf), "g_%s_list.h", typeName);
func_listfile = strdup(buf); func_listfile = strdup(buf);
Com_sprintf (buf, sizeof(buf), "g_%s_decs.h", typeName); Com_sprintf (buf, sizeof(buf), "g_%s_decs.h", typeName);
func_decsfile = strdup(buf); func_decsfile = strdup(buf);
typeExtract = true; typeExtract = true;
} }
else if ( !Q_stricmp(argv[i], "-o") && (i < argc-1) && (argv[i+1][0] != '-') ) else if ( !Q_stricmp(argv[i], "-o") && (i < argc-1) && (argv[i+1][0] != '-') )
{ {
func_listfile = argv[i+1]; func_listfile = argv[i+1];
printf("Pointer table list file: %s\n", func_listfile); printf("Pointer table list file: %s\n", func_listfile);
if ( (i < argc-2) && (argv[i+2][0] != '-') ) if ( (i < argc-2) && (argv[i+2][0] != '-') )
{ {
func_decsfile = argv[i+2]; func_decsfile = argv[i+2];
printf("Pointer list decs file: %s\n", func_decsfile); printf("Pointer list decs file: %s\n", func_decsfile);
} }
} }
else if (!Q_stricmp(argv[i], "-d")) { else if (!Q_stricmp(argv[i], "-d")) {
printf("Define option not yet implemented.\n"); printf("Define option not yet implemented.\n");
} }
} }
if (argc < 1 || (firstParmSet && firstParm < 1)) if (argc < 2 || (firstParmSet && firstParm < 1))
Usage (); Usage ();
// end Knightmare // end Knightmare
@ -835,6 +837,8 @@ int main (int argc, char *argv[])
DumpReplaceFunctions (typeName); DumpReplaceFunctions (typeName);
else else
DumpReplaceFunctions (NULL); DumpReplaceFunctions (NULL);
return 0;
} }
#endif #endif

View File

@ -49,6 +49,7 @@ you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, R
#include <stdarg.h> #include <stdarg.h>
#include <time.h> #include <time.h>
#include <math.h> #include <math.h>
#include <ctype.h>
#include "l_memory.h" #include "l_memory.h"
#include "l_script.h" #include "l_script.h"
#include "l_precomp.h" #include "l_precomp.h"
@ -78,10 +79,10 @@ void Q_strncpyz( char *dest, const char *src, int destsize ) {
dest[destsize - 1] = 0; dest[destsize - 1] = 0;
} }
/* /*
================= =================
Com_sprintf Com_sprintf
================= =================
*/ */
void Com_sprintf (char *dest, int size, const char *fmt, ...) void Com_sprintf (char *dest, int size, const char *fmt, ...)
{ {
@ -789,12 +790,12 @@ void PC_AddBuiltinDefines( source_t *source ) {
char *string; char *string;
int builtin; int builtin;
} builtin[] = { } builtin[] = {
"__LINE__", BUILTIN_LINE, { "__LINE__", BUILTIN_LINE },
"__FILE__", BUILTIN_FILE, { "__FILE__", BUILTIN_FILE },
"__DATE__", BUILTIN_DATE, { "__DATE__", BUILTIN_DATE },
"__TIME__", BUILTIN_TIME, { "__TIME__", BUILTIN_TIME },
// "__STDC__", BUILTIN_STDC, // { "__STDC__", BUILTIN_STDC },
NULL, 0 { NULL, 0 }
}; };
for ( i = 0; builtin[i].string; i++ ) for ( i = 0; builtin[i].string; i++ )
@ -811,7 +812,7 @@ void PC_AddBuiltinDefines( source_t *source ) {
#else #else
define->next = source->defines; define->next = source->defines;
source->defines = define; source->defines = define;
#endif //DEFINEHASHING #endif /* DEFINEHASHING */
} //end for } //end for
} //end of the function PC_AddBuiltinDefines } //end of the function PC_AddBuiltinDefines
//============================================================================ //============================================================================
@ -823,7 +824,7 @@ void PC_AddBuiltinDefines( source_t *source ) {
int PC_ExpandBuiltinDefine( source_t *source, define_t *define, int PC_ExpandBuiltinDefine( source_t *source, define_t *define,
token_t **firsttoken, token_t **lasttoken ) { token_t **firsttoken, token_t **lasttoken ) {
token_t token; token_t token;
unsigned long t; // time_t t; //to prevent LCC warning time_t t;
char *curtime; char *curtime;
memcpy( &token, &source->token, sizeof( token_t ) ); memcpy( &token, &source->token, sizeof( token_t ) );

View File

@ -721,13 +721,13 @@ int PS_ReadNumber( script_t *script, token_t *token ) {
{ {
c = *script->script_p; c = *script->script_p;
//check for a LONG number //check for a LONG number
if ( c == 'l' || c == 'L' && if ( (c == 'l' || c == 'L') &&
!( token->subtype & TT_LONG ) ) { !( token->subtype & TT_LONG ) ) {
script->script_p++; script->script_p++;
token->subtype |= TT_LONG; token->subtype |= TT_LONG;
} //end if } //end if
//check for an UNSIGNED number //check for an UNSIGNED number
else if ( c == 'u' || c == 'U' && else if ( (c == 'u' || c == 'U') &&
!( token->subtype & ( TT_UNSIGNED | TT_FLOAT ) ) ) { !( token->subtype & ( TT_UNSIGNED | TT_FLOAT ) ) ) {
script->script_p++; script->script_p++;
token->subtype |= TT_UNSIGNED; token->subtype |= TT_UNSIGNED;
@ -736,7 +736,7 @@ int PS_ReadNumber( script_t *script, token_t *token ) {
token->string[len] = '\0'; token->string[len] = '\0';
#ifdef NUMBERVALUE #ifdef NUMBERVALUE
NumberValue( token->string, token->subtype, &token->intvalue, &token->floatvalue ); NumberValue( token->string, token->subtype, &token->intvalue, &token->floatvalue );
#endif //NUMBERVALUE #endif /* NUMBERVALUE */
if ( !( token->subtype & TT_FLOAT ) ) { if ( !( token->subtype & TT_FLOAT ) ) {
token->subtype |= TT_INTEGER; token->subtype |= TT_INTEGER;
} }