mirror of
https://github.com/yquake2/extractfunctions.git
synced 2025-02-21 11:20:50 +00:00
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:
parent
264ca3d89e
commit
faa5144244
4 changed files with 178 additions and 173 deletions
2
build.sh
2
build.sh
|
@ -1,3 +1,3 @@
|
|||
#!/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
|
||||
|
|
316
extractfuncs.c
316
extractfuncs.c
|
@ -48,14 +48,14 @@ static char *func_decsfile = "g_func_decs.h";
|
|||
#define TEMP_LIST_NAME "g_func_list.tmp"
|
||||
#define TEMP_DECS_NAME "g_func_decs.tmp"
|
||||
|
||||
//===========================================================================
|
||||
//===========================================================================
|
||||
|
||||
#if 0
|
||||
/*
|
||||
=================
|
||||
WriteWhiteSpace
|
||||
=================
|
||||
*/
|
||||
/*
|
||||
=================
|
||||
WriteWhiteSpace
|
||||
=================
|
||||
*/
|
||||
void WriteWhiteSpace (FILE *fp, script_t *script)
|
||||
{
|
||||
int c;
|
||||
|
@ -71,11 +71,11 @@ void WriteWhiteSpace (FILE *fp, script_t *script)
|
|||
} //end while
|
||||
} //end of the function WriteWhiteSpace
|
||||
|
||||
/*
|
||||
=================
|
||||
WriteString
|
||||
=================
|
||||
*/
|
||||
/*
|
||||
=================
|
||||
WriteString
|
||||
=================
|
||||
*/
|
||||
void WriteString (FILE *fp, script_t *script)
|
||||
{
|
||||
char *ptr;
|
||||
|
@ -88,11 +88,11 @@ void WriteString (FILE *fp, script_t *script)
|
|||
} //end while
|
||||
} //end of the function WriteString
|
||||
|
||||
/*
|
||||
=================
|
||||
ScrewUpFile
|
||||
=================
|
||||
*/
|
||||
/*
|
||||
=================
|
||||
ScrewUpFile
|
||||
=================
|
||||
*/
|
||||
void ScrewUpFile (char *oldfile, char *newfile)
|
||||
{
|
||||
FILE *fp;
|
||||
|
@ -137,11 +137,11 @@ void ScrewUpFile (char *oldfile, char *newfile)
|
|||
} //end of the function ScrewUpFile
|
||||
#endif
|
||||
|
||||
/*
|
||||
=================
|
||||
Error
|
||||
=================
|
||||
*/
|
||||
/*
|
||||
=================
|
||||
Error
|
||||
=================
|
||||
*/
|
||||
void Error (char *error, ...)
|
||||
{
|
||||
va_list argptr;
|
||||
|
@ -153,11 +153,11 @@ void Error (char *error, ...)
|
|||
exit( 1 );
|
||||
}
|
||||
|
||||
/*
|
||||
=================
|
||||
DumpReplaceFunctions
|
||||
=================
|
||||
*/
|
||||
/*
|
||||
=================
|
||||
DumpReplaceFunctions
|
||||
=================
|
||||
*/
|
||||
void DumpReplaceFunctions (char *typeName)
|
||||
{
|
||||
replacefunc_t *rf;
|
||||
|
@ -196,7 +196,7 @@ void DumpReplaceFunctions (char *typeName)
|
|||
fclose( f );
|
||||
|
||||
strcpy( path, func_listfile );
|
||||
if ( f = fopen( path, "rb" ) )
|
||||
if ((f = fopen( path, "rb" )) != NULL)
|
||||
{
|
||||
fseek( f, 0, SEEK_END );
|
||||
newlen = ftell( f );
|
||||
|
@ -264,7 +264,7 @@ void DumpReplaceFunctions (char *typeName)
|
|||
fclose( f );
|
||||
|
||||
strcpy( path, func_decsfile );
|
||||
if ( f = fopen( path, "rb" ) )
|
||||
if ((f = fopen( path, "rb" )) != NULL)
|
||||
{
|
||||
fseek( f, 0, SEEK_END );
|
||||
newlen = ftell( f );
|
||||
|
@ -317,11 +317,11 @@ void DumpReplaceFunctions (char *typeName)
|
|||
#endif
|
||||
} // end of the function DumpReplaceFunctions
|
||||
|
||||
/*
|
||||
=================
|
||||
FindFunctionName
|
||||
=================
|
||||
*/
|
||||
/*
|
||||
=================
|
||||
FindFunctionName
|
||||
=================
|
||||
*/
|
||||
replacefunc_t *FindFunctionName (char *funcname)
|
||||
{
|
||||
replacefunc_t *f;
|
||||
|
@ -336,11 +336,11 @@ replacefunc_t *FindFunctionName (char *funcname)
|
|||
return NULL;
|
||||
} //end of the function FindFunctionName
|
||||
|
||||
/*
|
||||
=================
|
||||
MayScrewUp
|
||||
=================
|
||||
*/
|
||||
/*
|
||||
=================
|
||||
MayScrewUp
|
||||
=================
|
||||
*/
|
||||
int MayScrewUp (char *funcname)
|
||||
{
|
||||
if ( !strcmp(funcname, "GetBotAPI") )
|
||||
|
@ -358,11 +358,11 @@ int MayScrewUp (char *funcname)
|
|||
return true;
|
||||
} //end of the function MayScrewUp
|
||||
|
||||
/*
|
||||
=================
|
||||
ConcatDec
|
||||
=================
|
||||
*/
|
||||
/*
|
||||
=================
|
||||
ConcatDec
|
||||
=================
|
||||
*/
|
||||
void ConcatDec (tokenList_t *list, char *str, int inc)
|
||||
{
|
||||
/* 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, " " );
|
||||
}
|
||||
|
||||
/*
|
||||
=================
|
||||
AddFunctionName
|
||||
=================
|
||||
*/
|
||||
/*
|
||||
=================
|
||||
AddFunctionName
|
||||
=================
|
||||
*/
|
||||
void AddFunctionName (char *funcname, char *filename, tokenList_t *head)
|
||||
{
|
||||
replacefunc_t *f;
|
||||
|
@ -433,11 +433,11 @@ void AddFunctionName (char *funcname, char *filename, tokenList_t *head)
|
|||
|
||||
} //end of the function AddFunctionName
|
||||
|
||||
/*
|
||||
=================
|
||||
AddTokenToList
|
||||
=================
|
||||
*/
|
||||
/*
|
||||
=================
|
||||
AddTokenToList
|
||||
=================
|
||||
*/
|
||||
void AddTokenToList (tokenList_t **head, token_t *token)
|
||||
{
|
||||
tokenList_t *newhead;
|
||||
|
@ -454,10 +454,10 @@ void AddTokenToList (tokenList_t **head, token_t *token)
|
|||
}
|
||||
|
||||
#if 0
|
||||
/*
|
||||
=================
|
||||
KillTokenList
|
||||
=================
|
||||
/*
|
||||
=================
|
||||
KillTokenList
|
||||
=================
|
||||
*/
|
||||
void KillTokenList (tokenList_t *head)
|
||||
{
|
||||
|
@ -469,11 +469,11 @@ void KillTokenList (tokenList_t *head)
|
|||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
=================
|
||||
StripTokenList
|
||||
=================
|
||||
*/
|
||||
/*
|
||||
=================
|
||||
StripTokenList
|
||||
=================
|
||||
*/
|
||||
void StripTokenList (tokenList_t *head)
|
||||
{
|
||||
tokenList_t *trav, *lastTrav;
|
||||
|
@ -496,13 +496,13 @@ void StripTokenList (tokenList_t *head)
|
|||
lastTrav->next = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
=================
|
||||
GetTypeNamesFromFile
|
||||
|
||||
Knightmare- this gets structs / vars of a given type
|
||||
=================
|
||||
*/
|
||||
/*
|
||||
=================
|
||||
GetTypeNamesFromFile
|
||||
|
||||
Knightmare- this gets structs / vars of a given type
|
||||
=================
|
||||
*/
|
||||
void GetTypeNamesFromFile (char *filename, char *typeName)
|
||||
{
|
||||
source_t *source;
|
||||
|
@ -572,11 +572,11 @@ void GetTypeNamesFromFile (char *filename, char *typeName)
|
|||
FreeSource( source );
|
||||
}
|
||||
|
||||
/*
|
||||
=================
|
||||
GetFunctionNamesFromFile
|
||||
=================
|
||||
*/
|
||||
/*
|
||||
=================
|
||||
GetFunctionNamesFromFile
|
||||
=================
|
||||
*/
|
||||
void GetFunctionNamesFromFile (char *filename)
|
||||
{
|
||||
source_t *source;
|
||||
|
@ -669,11 +669,11 @@ void GetFunctionNamesFromFile (char *filename)
|
|||
FreeSource( source );
|
||||
} //end of the function GetFunctionNamesFromFile
|
||||
|
||||
/*
|
||||
=================
|
||||
Usage
|
||||
=================
|
||||
*/
|
||||
/*
|
||||
=================
|
||||
Usage
|
||||
=================
|
||||
*/
|
||||
void Usage (void)
|
||||
{
|
||||
// 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" );
|
||||
}
|
||||
|
||||
/*
|
||||
=================
|
||||
main
|
||||
=================
|
||||
*/
|
||||
/*
|
||||
=================
|
||||
main
|
||||
=================
|
||||
*/
|
||||
#ifdef _WIN32
|
||||
void main (int argc, char *argv[])
|
||||
{
|
||||
WIN32_FIND_DATA filedata;
|
||||
HWND handle;
|
||||
int i, firstParm, done;
|
||||
char typeName[128];
|
||||
qboolean typeExtract = false;
|
||||
qboolean firstParmSet = false;
|
||||
char typeName[128];
|
||||
qboolean typeExtract = false;
|
||||
qboolean firstParmSet = false;
|
||||
|
||||
// if ( argc < 2 )
|
||||
// Usage ();
|
||||
|
||||
// Knightmare- check for command line switches
|
||||
for (i=0; i<argc; i++)
|
||||
{
|
||||
if (!firstParmSet && argv[i][0] == '-')
|
||||
{
|
||||
firstParm = i;
|
||||
firstParmSet = true;
|
||||
}
|
||||
|
||||
if ( !Q_stricmp(argv[i], "-t") && (i < argc-1) && (argv[i+1][0] != '-') )
|
||||
{
|
||||
char buf[_MAX_PATH];
|
||||
Com_sprintf (typeName, sizeof(typeName), argv[i+1]);
|
||||
printf("Data type to extract: %s\n", typeName);
|
||||
Com_sprintf (buf, sizeof(buf), "g_%s_list.h", typeName);
|
||||
func_listfile = strdup(buf);
|
||||
Com_sprintf (buf, sizeof(buf), "g_%s_decs.h", typeName);
|
||||
func_decsfile = strdup(buf);
|
||||
typeExtract = true;
|
||||
}
|
||||
else if ( !Q_stricmp(argv[i], "-o") && (i < argc-1) && (argv[i+1][0] != '-') )
|
||||
{
|
||||
func_listfile = argv[i+1];
|
||||
printf("Pointer table list file: %s\n", func_listfile);
|
||||
if ( (i < argc-2) && (argv[i+2][0] != '-') )
|
||||
{
|
||||
// Knightmare- check for command line switches
|
||||
for (i=0; i<argc; i++)
|
||||
{
|
||||
if (!firstParmSet && argv[i][0] == '-')
|
||||
{
|
||||
firstParm = i;
|
||||
firstParmSet = true;
|
||||
}
|
||||
|
||||
if ( !Q_stricmp(argv[i], "-t") && (i < argc-1) && (argv[i+1][0] != '-') )
|
||||
{
|
||||
char buf[_MAX_PATH];
|
||||
Com_sprintf (typeName, sizeof(typeName), argv[i+1]);
|
||||
printf("Data type to extract: %s\n", typeName);
|
||||
Com_sprintf (buf, sizeof(buf), "g_%s_list.h", typeName);
|
||||
func_listfile = strdup(buf);
|
||||
Com_sprintf (buf, sizeof(buf), "g_%s_decs.h", typeName);
|
||||
func_decsfile = strdup(buf);
|
||||
typeExtract = true;
|
||||
}
|
||||
else if ( !Q_stricmp(argv[i], "-o") && (i < argc-1) && (argv[i+1][0] != '-') )
|
||||
{
|
||||
func_listfile = argv[i+1];
|
||||
printf("Pointer table list file: %s\n", func_listfile);
|
||||
if ( (i < argc-2) && (argv[i+2][0] != '-') )
|
||||
{
|
||||
func_decsfile = argv[i+2];
|
||||
printf("Pointer list decs file: %s\n", func_decsfile);
|
||||
}
|
||||
}
|
||||
else if (!Q_stricmp(argv[i], "-d")) {
|
||||
printf("Define option not yet implemented.\n");
|
||||
}
|
||||
printf("Pointer list decs file: %s\n", func_decsfile);
|
||||
}
|
||||
}
|
||||
else if (!Q_stricmp(argv[i], "-d")) {
|
||||
printf("Define option not yet implemented.\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (argc < 1 || (firstParmSet && firstParm < 1))
|
||||
if (argc < 2 || (firstParmSet && firstParm < 1))
|
||||
Usage ();
|
||||
// end Knightmare
|
||||
|
||||
|
@ -756,6 +756,8 @@ void main (int argc, char *argv[])
|
|||
DumpReplaceFunctions (typeName);
|
||||
else
|
||||
DumpReplaceFunctions (NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
/*
|
||||
|
@ -766,9 +768,9 @@ int main (int argc, char *argv[])
|
|||
{
|
||||
int i, firstParm;
|
||||
int argbase = 1;
|
||||
char typeName[128];
|
||||
qboolean typeExtract = false;
|
||||
qboolean firstParmSet = false;
|
||||
char typeName[128];
|
||||
qboolean typeExtract = false;
|
||||
qboolean firstParmSet = false;
|
||||
|
||||
/* if ( argc < 2 )
|
||||
Usage();
|
||||
|
@ -783,42 +785,42 @@ int main (int argc, char *argv[])
|
|||
argbase = 4;
|
||||
}
|
||||
*/
|
||||
// Knightmare- check for command line switches
|
||||
for (i=0; i<argc; i++)
|
||||
{
|
||||
if (!firstParmSet && argv[i][0] == '-')
|
||||
{
|
||||
firstParm = i;
|
||||
firstParmSet = true;
|
||||
}
|
||||
|
||||
if ( !Q_stricmp(argv[i], "-t") && (i < argc-1) && (argv[i+1][0] != '-') )
|
||||
{
|
||||
char buf[_MAX_PATH];
|
||||
Com_sprintf (typeName, sizeof(typeName), argv[i+1]);
|
||||
printf("Data type to extract: %s\n", typeName);
|
||||
Com_sprintf (buf, sizeof(buf), "g_%s_list.h", typeName);
|
||||
func_listfile = strdup(buf);
|
||||
Com_sprintf (buf, sizeof(buf), "g_%s_decs.h", typeName);
|
||||
func_decsfile = strdup(buf);
|
||||
typeExtract = true;
|
||||
}
|
||||
else if ( !Q_stricmp(argv[i], "-o") && (i < argc-1) && (argv[i+1][0] != '-') )
|
||||
{
|
||||
func_listfile = argv[i+1];
|
||||
printf("Pointer table list file: %s\n", func_listfile);
|
||||
if ( (i < argc-2) && (argv[i+2][0] != '-') )
|
||||
{
|
||||
// Knightmare- check for command line switches
|
||||
for (i=0; i<argc; i++)
|
||||
{
|
||||
if (!firstParmSet && argv[i][0] == '-')
|
||||
{
|
||||
firstParm = i;
|
||||
firstParmSet = true;
|
||||
}
|
||||
|
||||
if ( !Q_stricmp(argv[i], "-t") && (i < argc-1) && (argv[i+1][0] != '-') )
|
||||
{
|
||||
char buf[_MAX_PATH];
|
||||
Com_sprintf (typeName, sizeof(typeName), argv[i+1]);
|
||||
printf("Data type to extract: %s\n", typeName);
|
||||
Com_sprintf (buf, sizeof(buf), "g_%s_list.h", typeName);
|
||||
func_listfile = strdup(buf);
|
||||
Com_sprintf (buf, sizeof(buf), "g_%s_decs.h", typeName);
|
||||
func_decsfile = strdup(buf);
|
||||
typeExtract = true;
|
||||
}
|
||||
else if ( !Q_stricmp(argv[i], "-o") && (i < argc-1) && (argv[i+1][0] != '-') )
|
||||
{
|
||||
func_listfile = argv[i+1];
|
||||
printf("Pointer table list file: %s\n", func_listfile);
|
||||
if ( (i < argc-2) && (argv[i+2][0] != '-') )
|
||||
{
|
||||
func_decsfile = argv[i+2];
|
||||
printf("Pointer list decs file: %s\n", func_decsfile);
|
||||
}
|
||||
}
|
||||
else if (!Q_stricmp(argv[i], "-d")) {
|
||||
printf("Define option not yet implemented.\n");
|
||||
}
|
||||
printf("Pointer list decs file: %s\n", func_decsfile);
|
||||
}
|
||||
}
|
||||
else if (!Q_stricmp(argv[i], "-d")) {
|
||||
printf("Define option not yet implemented.\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (argc < 1 || (firstParmSet && firstParm < 1))
|
||||
if (argc < 2 || (firstParmSet && firstParm < 1))
|
||||
Usage ();
|
||||
// end Knightmare
|
||||
|
||||
|
@ -835,6 +837,8 @@ int main (int argc, char *argv[])
|
|||
DumpReplaceFunctions (typeName);
|
||||
else
|
||||
DumpReplaceFunctions (NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
25
l_precomp.c
25
l_precomp.c
|
@ -49,6 +49,7 @@ you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, R
|
|||
#include <stdarg.h>
|
||||
#include <time.h>
|
||||
#include <math.h>
|
||||
#include <ctype.h>
|
||||
#include "l_memory.h"
|
||||
#include "l_script.h"
|
||||
#include "l_precomp.h"
|
||||
|
@ -78,10 +79,10 @@ void Q_strncpyz( char *dest, const char *src, int destsize ) {
|
|||
dest[destsize - 1] = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
=================
|
||||
Com_sprintf
|
||||
=================
|
||||
/*
|
||||
=================
|
||||
Com_sprintf
|
||||
=================
|
||||
*/
|
||||
void Com_sprintf (char *dest, int size, const char *fmt, ...)
|
||||
{
|
||||
|
@ -789,12 +790,12 @@ void PC_AddBuiltinDefines( source_t *source ) {
|
|||
char *string;
|
||||
int builtin;
|
||||
} builtin[] = {
|
||||
"__LINE__", BUILTIN_LINE,
|
||||
"__FILE__", BUILTIN_FILE,
|
||||
"__DATE__", BUILTIN_DATE,
|
||||
"__TIME__", BUILTIN_TIME,
|
||||
// "__STDC__", BUILTIN_STDC,
|
||||
NULL, 0
|
||||
{ "__LINE__", BUILTIN_LINE },
|
||||
{ "__FILE__", BUILTIN_FILE },
|
||||
{ "__DATE__", BUILTIN_DATE },
|
||||
{ "__TIME__", BUILTIN_TIME },
|
||||
// { "__STDC__", BUILTIN_STDC },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
for ( i = 0; builtin[i].string; i++ )
|
||||
|
@ -811,7 +812,7 @@ void PC_AddBuiltinDefines( source_t *source ) {
|
|||
#else
|
||||
define->next = source->defines;
|
||||
source->defines = define;
|
||||
#endif //DEFINEHASHING
|
||||
#endif /* DEFINEHASHING */
|
||||
} //end for
|
||||
} //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,
|
||||
token_t **firsttoken, token_t **lasttoken ) {
|
||||
token_t token;
|
||||
unsigned long t; // time_t t; //to prevent LCC warning
|
||||
time_t t;
|
||||
char *curtime;
|
||||
|
||||
memcpy( &token, &source->token, sizeof( token_t ) );
|
||||
|
|
|
@ -721,13 +721,13 @@ int PS_ReadNumber( script_t *script, token_t *token ) {
|
|||
{
|
||||
c = *script->script_p;
|
||||
//check for a LONG number
|
||||
if ( c == 'l' || c == 'L' &&
|
||||
if ( (c == 'l' || c == 'L') &&
|
||||
!( token->subtype & TT_LONG ) ) {
|
||||
script->script_p++;
|
||||
token->subtype |= TT_LONG;
|
||||
} //end if
|
||||
//check for an UNSIGNED number
|
||||
else if ( c == 'u' || c == 'U' &&
|
||||
//check for an UNSIGNED number
|
||||
else if ( (c == 'u' || c == 'U') &&
|
||||
!( token->subtype & ( TT_UNSIGNED | TT_FLOAT ) ) ) {
|
||||
script->script_p++;
|
||||
token->subtype |= TT_UNSIGNED;
|
||||
|
@ -736,7 +736,7 @@ int PS_ReadNumber( script_t *script, token_t *token ) {
|
|||
token->string[len] = '\0';
|
||||
#ifdef NUMBERVALUE
|
||||
NumberValue( token->string, token->subtype, &token->intvalue, &token->floatvalue );
|
||||
#endif //NUMBERVALUE
|
||||
#endif /* NUMBERVALUE */
|
||||
if ( !( token->subtype & TT_FLOAT ) ) {
|
||||
token->subtype |= TT_INTEGER;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue