mirror of
https://github.com/yquake2/extractfunctions.git
synced 2024-11-10 06:31:50 +00:00
Add knightmares "extractfuncs" tool to generate the function- and
structtables for his savegame system
This commit is contained in:
commit
abe6536eba
16 changed files with 7132 additions and 0 deletions
27
ChangeLog.txt
Normal file
27
ChangeLog.txt
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
2011-07-19 Knightmare <knightmare66@yahoo.com>
|
||||||
|
|
||||||
|
Added -t option to export data type
|
||||||
|
|
||||||
|
Changed command line syntax to:
|
||||||
|
|
||||||
|
Extractfuncs <file1> [<file2> ..] [-t <structname>] [-o <func_list> <func_decs>] [-d <define>]
|
||||||
|
|
||||||
|
Added skipping the parsing of macros with parameters (not relevant to extraction)
|
||||||
|
|
||||||
|
2001-12-07 Timothee Besset <ttimo@idsoftware.com>
|
||||||
|
|
||||||
|
Imported from the Wolf MP version, Mac/Linux friendly version
|
||||||
|
Fixed argbase bug in *nix main
|
||||||
|
Escape BoxOnPlaneSide on linux (taken out by preprocessing)
|
||||||
|
|
||||||
|
2001-11-02 Timothee Besset <ttimo@idsoftware.com>
|
||||||
|
|
||||||
|
Modified extractfuncs to works on linux
|
||||||
|
Would still need to integrate it correctly with the build system
|
||||||
|
Changed the command line syntax of the linux ver:
|
||||||
|
screwup [-o <basename>] <file1> [<file2> ..]
|
||||||
|
|
||||||
|
if none specified, <basename> is "g_funcs"
|
||||||
|
|
||||||
|
on linux at least, those header files need to be tweaked by hand
|
||||||
|
because unresolved externs are not ignored by gcc (otherwise harmless on win32)
|
9
Conscript
Normal file
9
Conscript
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
# extractfuncs building
|
||||||
|
|
||||||
|
$env = new cons(
|
||||||
|
CC => 'gcc',
|
||||||
|
CFLAGS => '-g -DSCREWUP '
|
||||||
|
);
|
||||||
|
|
||||||
|
Program $env 'extractfuncs', 'extractfuncs.c', 'l_log.c', 'l_memory.c', 'l_precomp.c', 'l_script.c';
|
||||||
|
Install $env '#', 'extractfuncs';
|
BIN
ef_local.h
Normal file
BIN
ef_local.h
Normal file
Binary file not shown.
4
extractfuncs.bat
Normal file
4
extractfuncs.bat
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
cd ..\game
|
||||||
|
..\tools_bin\extractfuncs *.c -o g_func_list.h g_func_decs.h
|
||||||
|
..\tools_bin\extractfuncs *.c -t mmove_t -o g_mmove_list.h g_mmove_decs.h
|
||||||
|
cd ..
|
834
extractfuncs.c
Normal file
834
extractfuncs.c
Normal file
|
@ -0,0 +1,834 @@
|
||||||
|
/*
|
||||||
|
===========================================================================
|
||||||
|
|
||||||
|
Return to Castle Wolfenstein single player GPL Source Code
|
||||||
|
Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
|
||||||
|
|
||||||
|
This file is part of the Return to Castle Wolfenstein single player GPL Source Code (RTCW SP Source Code).
|
||||||
|
|
||||||
|
RTCW SP Source Code is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
RTCW SP Source Code is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with RTCW SP Source Code. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
In addition, the RTCW SP Source Code is also subject to certain additional terms.
|
||||||
|
You should have received a copy of these additional terms immediately following the
|
||||||
|
terms and conditions of the GNU General Public License which accompanied the RTCW SP
|
||||||
|
Source Code. If not, please request a copy in writing from id Software at the address below.
|
||||||
|
|
||||||
|
If you have questions concerning this license or the applicable additional terms,
|
||||||
|
you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
|
||||||
|
|
||||||
|
===========================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ef_local.h"
|
||||||
|
|
||||||
|
replacefunc_t *replacefuncs;
|
||||||
|
int numfuncs;
|
||||||
|
|
||||||
|
#define MAX_TOKEN_LIST 64
|
||||||
|
tokenList_t tokenList[MAX_TOKEN_LIST];
|
||||||
|
int tokenListHead = 0;
|
||||||
|
int verbose = 0;
|
||||||
|
|
||||||
|
// the function names
|
||||||
|
//#define DEFAULT_FUNCBASE "g_func"
|
||||||
|
static char *func_listfile = "g_func_list.h";
|
||||||
|
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
|
||||||
|
=================
|
||||||
|
*/
|
||||||
|
void WriteWhiteSpace (FILE *fp, script_t *script)
|
||||||
|
{
|
||||||
|
int c;
|
||||||
|
//write out the white space
|
||||||
|
c = PS_NextWhiteSpaceChar( script );
|
||||||
|
while ( c )
|
||||||
|
{
|
||||||
|
//NOTE: do NOT write out carriage returns (for unix/linux compatibility
|
||||||
|
if ( c != 13 ) {
|
||||||
|
fputc( c, fp );
|
||||||
|
}
|
||||||
|
c = PS_NextWhiteSpaceChar( script );
|
||||||
|
} //end while
|
||||||
|
} //end of the function WriteWhiteSpace
|
||||||
|
|
||||||
|
/*
|
||||||
|
=================
|
||||||
|
WriteString
|
||||||
|
=================
|
||||||
|
*/
|
||||||
|
void WriteString (FILE *fp, script_t *script)
|
||||||
|
{
|
||||||
|
char *ptr;
|
||||||
|
|
||||||
|
ptr = script->endwhitespace_p;
|
||||||
|
while ( ptr < script->script_p )
|
||||||
|
{
|
||||||
|
fputc( *ptr, fp );
|
||||||
|
ptr++;
|
||||||
|
} //end while
|
||||||
|
} //end of the function WriteString
|
||||||
|
|
||||||
|
/*
|
||||||
|
=================
|
||||||
|
ScrewUpFile
|
||||||
|
=================
|
||||||
|
*/
|
||||||
|
void ScrewUpFile (char *oldfile, char *newfile)
|
||||||
|
{
|
||||||
|
FILE *fp;
|
||||||
|
script_t *script;
|
||||||
|
token_t token;
|
||||||
|
replacefunc_t *f;
|
||||||
|
char *ptr;
|
||||||
|
|
||||||
|
printf( "screwing up file %s\n", oldfile );
|
||||||
|
script = LoadScriptFile( oldfile );
|
||||||
|
if ( !script ) {
|
||||||
|
Error( "error opening %s\n", oldfile );
|
||||||
|
}
|
||||||
|
fp = fopen( newfile, "wb" );
|
||||||
|
if ( !fp ) {
|
||||||
|
Error( "error opening %s\n", newfile );
|
||||||
|
}
|
||||||
|
//
|
||||||
|
while ( PS_ReadToken( script, &token ) )
|
||||||
|
{
|
||||||
|
WriteWhiteSpace( fp, script );
|
||||||
|
if ( token.type == TT_NAME )
|
||||||
|
{
|
||||||
|
f = FindFunctionName( token.string );
|
||||||
|
if ( f ) {
|
||||||
|
ptr = f->newname;
|
||||||
|
} else { ptr = token.string;}
|
||||||
|
while ( *ptr )
|
||||||
|
{
|
||||||
|
fputc( *ptr, fp );
|
||||||
|
ptr++;
|
||||||
|
} //end while
|
||||||
|
} //end if
|
||||||
|
else
|
||||||
|
{
|
||||||
|
WriteString( fp, script );
|
||||||
|
} //end else
|
||||||
|
} //end while
|
||||||
|
WriteWhiteSpace( fp, script );
|
||||||
|
FreeMemory( script );
|
||||||
|
fclose( fp );
|
||||||
|
} //end of the function ScrewUpFile
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
=================
|
||||||
|
Error
|
||||||
|
=================
|
||||||
|
*/
|
||||||
|
void Error (char *error, ...)
|
||||||
|
{
|
||||||
|
va_list argptr;
|
||||||
|
|
||||||
|
va_start( argptr, error );
|
||||||
|
vprintf( error, argptr );
|
||||||
|
va_end( argptr );
|
||||||
|
|
||||||
|
exit( 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
=================
|
||||||
|
DumpReplaceFunctions
|
||||||
|
=================
|
||||||
|
*/
|
||||||
|
void DumpReplaceFunctions (char *typeName)
|
||||||
|
{
|
||||||
|
replacefunc_t *rf;
|
||||||
|
char path[_MAX_PATH];
|
||||||
|
FILE *f;
|
||||||
|
int len, newlen;
|
||||||
|
unsigned char *buf, *newbuf;
|
||||||
|
int updated;
|
||||||
|
|
||||||
|
updated = 0;
|
||||||
|
|
||||||
|
// dump the function header
|
||||||
|
strcpy( path, "." );
|
||||||
|
strcat( path, PATHSEPERATOR_STR );
|
||||||
|
strcat( path, TEMP_LIST_NAME );
|
||||||
|
Log_Open( path );
|
||||||
|
for ( rf = replacefuncs; rf; rf = rf->next )
|
||||||
|
{
|
||||||
|
if (typeName)
|
||||||
|
Log_Print( "{\"%s\", &%s},\n", rf->name, rf->name );
|
||||||
|
else
|
||||||
|
Log_Print( "{\"%s\", (byte *)%s},\n", rf->name, rf->name );
|
||||||
|
} //end for
|
||||||
|
Log_Print( "{0, 0}\n" );
|
||||||
|
Log_Close();
|
||||||
|
|
||||||
|
// if it's different, rename the file over the real header
|
||||||
|
strcpy( path, TEMP_LIST_NAME );
|
||||||
|
f = fopen( path, "rb" );
|
||||||
|
fseek( f, 0, SEEK_END );
|
||||||
|
len = ftell( f );
|
||||||
|
buf = (unsigned char *) malloc( len + 1 );
|
||||||
|
fseek( f, 0, SEEK_SET );
|
||||||
|
fread( buf, len, 1, f );
|
||||||
|
buf[len] = 0;
|
||||||
|
fclose( f );
|
||||||
|
|
||||||
|
strcpy( path, func_listfile );
|
||||||
|
if ( f = fopen( path, "rb" ) )
|
||||||
|
{
|
||||||
|
fseek( f, 0, SEEK_END );
|
||||||
|
newlen = ftell( f );
|
||||||
|
newbuf = (unsigned char *) malloc( newlen + 1 );
|
||||||
|
fseek( f, 0, SEEK_SET );
|
||||||
|
fread( newbuf, newlen, 1, f );
|
||||||
|
newbuf[newlen] = 0;
|
||||||
|
fclose( f );
|
||||||
|
|
||||||
|
if ( len != newlen || Q_stricmp( buf, newbuf ) )
|
||||||
|
{
|
||||||
|
char newpath[_MAX_PATH];
|
||||||
|
|
||||||
|
// delete the old file, rename the new one
|
||||||
|
strcpy( path, func_listfile );
|
||||||
|
remove( path );
|
||||||
|
|
||||||
|
strcpy( newpath, TEMP_LIST_NAME );
|
||||||
|
rename( newpath, path );
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
// make g_save recompile itself
|
||||||
|
remove( "debug\\g_save.obj" );
|
||||||
|
remove( "debug\\g_save.sbr" );
|
||||||
|
remove( "release\\g_save.obj" );
|
||||||
|
remove( "release\\g_save.sbr" );
|
||||||
|
#endif
|
||||||
|
|
||||||
|
updated = 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// delete the old file
|
||||||
|
strcpy( path, TEMP_LIST_NAME );
|
||||||
|
remove( path );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
rename( TEMP_LIST_NAME, func_listfile );
|
||||||
|
}
|
||||||
|
|
||||||
|
free( buf );
|
||||||
|
free( newbuf );
|
||||||
|
|
||||||
|
// dump the function declarations
|
||||||
|
strcpy( path, TEMP_DECS_NAME );
|
||||||
|
Log_Open( path );
|
||||||
|
for ( rf = replacefuncs; rf; rf = rf->next )
|
||||||
|
{
|
||||||
|
if (typeName)
|
||||||
|
Log_Print( "extern %s %s;\n", typeName, rf->dec );
|
||||||
|
else
|
||||||
|
Log_Print( "extern %s;\n", rf->dec );
|
||||||
|
} //end for
|
||||||
|
Log_Close();
|
||||||
|
|
||||||
|
// if it's different, rename the file over the real header
|
||||||
|
strcpy( path, TEMP_DECS_NAME );
|
||||||
|
f = fopen( path, "rb" );
|
||||||
|
fseek( f, 0, SEEK_END );
|
||||||
|
len = ftell( f );
|
||||||
|
buf = (unsigned char *) malloc( len + 1 );
|
||||||
|
fseek( f, 0, SEEK_SET );
|
||||||
|
fread( buf, len, 1, f );
|
||||||
|
buf[len] = 0;
|
||||||
|
fclose( f );
|
||||||
|
|
||||||
|
strcpy( path, func_decsfile );
|
||||||
|
if ( f = fopen( path, "rb" ) )
|
||||||
|
{
|
||||||
|
fseek( f, 0, SEEK_END );
|
||||||
|
newlen = ftell( f );
|
||||||
|
newbuf = (unsigned char *) malloc( newlen + 1 );
|
||||||
|
fseek( f, 0, SEEK_SET );
|
||||||
|
fread( newbuf, newlen, 1, f );
|
||||||
|
newbuf[newlen] = 0;
|
||||||
|
fclose( f );
|
||||||
|
|
||||||
|
if ( len != newlen || Q_stricmp( buf, newbuf ) )
|
||||||
|
{
|
||||||
|
char newpath[_MAX_PATH];
|
||||||
|
|
||||||
|
// delete the old file, rename the new one
|
||||||
|
strcpy( path, func_decsfile );
|
||||||
|
remove( path );
|
||||||
|
|
||||||
|
strcpy( newpath, TEMP_DECS_NAME );
|
||||||
|
rename( newpath, path );
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
// make g_save recompile itself
|
||||||
|
// NOTE TTimo win32 only? (harmless on *nix anyway)
|
||||||
|
remove( "debug\\g_save.obj" );
|
||||||
|
remove( "debug\\g_save.sbr" );
|
||||||
|
remove( "release\\g_save.obj" );
|
||||||
|
remove( "release\\g_save.sbr" );
|
||||||
|
#endif
|
||||||
|
|
||||||
|
updated = 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// delete the old file
|
||||||
|
strcpy( path, TEMP_DECS_NAME );
|
||||||
|
remove( path );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
rename( TEMP_DECS_NAME, func_decsfile );
|
||||||
|
}
|
||||||
|
|
||||||
|
free( buf );
|
||||||
|
free( newbuf );
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
if ( updated ) {
|
||||||
|
printf( "Updated the function table, recompile required.\n" );
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
} // end of the function DumpReplaceFunctions
|
||||||
|
|
||||||
|
/*
|
||||||
|
=================
|
||||||
|
FindFunctionName
|
||||||
|
=================
|
||||||
|
*/
|
||||||
|
replacefunc_t *FindFunctionName (char *funcname)
|
||||||
|
{
|
||||||
|
replacefunc_t *f;
|
||||||
|
|
||||||
|
for (f = replacefuncs; f; f = f->next)
|
||||||
|
{
|
||||||
|
if ( !strcmp(f->name, funcname) )
|
||||||
|
{
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
} //end for
|
||||||
|
return NULL;
|
||||||
|
} //end of the function FindFunctionName
|
||||||
|
|
||||||
|
/*
|
||||||
|
=================
|
||||||
|
MayScrewUp
|
||||||
|
=================
|
||||||
|
*/
|
||||||
|
int MayScrewUp (char *funcname)
|
||||||
|
{
|
||||||
|
if ( !strcmp(funcname, "GetBotAPI") )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ( !strcmp(funcname, "main") )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ( !strcmp(funcname, "WinMain") )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} //end of the function MayScrewUp
|
||||||
|
|
||||||
|
/*
|
||||||
|
=================
|
||||||
|
ConcatDec
|
||||||
|
=================
|
||||||
|
*/
|
||||||
|
void ConcatDec (tokenList_t *list, char *str, int inc)
|
||||||
|
{
|
||||||
|
/* if (!((list->token.type == TT_NAME) || (list->token.string[0] == '*'))) {
|
||||||
|
if (list->token.string[0] == ')' || list->token.string[0] == '(') {
|
||||||
|
if (inc++ >= 2)
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
if (list->next)
|
||||||
|
{
|
||||||
|
ConcatDec (list->next, str, inc);
|
||||||
|
}
|
||||||
|
strcat(str, list->token.string);
|
||||||
|
strcat(str, " " );
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
=================
|
||||||
|
AddFunctionName
|
||||||
|
=================
|
||||||
|
*/
|
||||||
|
void AddFunctionName (char *funcname, char *filename, tokenList_t *head)
|
||||||
|
{
|
||||||
|
replacefunc_t *f;
|
||||||
|
tokenList_t *list;
|
||||||
|
|
||||||
|
if ( FindFunctionName(funcname) )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined( __linux__ )
|
||||||
|
// the bad thing is, this doesn't preprocess .. on __linux__ this
|
||||||
|
// function is not implemented (q_math.c)
|
||||||
|
if ( !Q_stricmp( funcname, "BoxOnPlaneSide" ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// NERVE - SMF - workaround for Graeme's predifined MACOSX functions
|
||||||
|
// TTimo - looks like linux version needs to escape those too
|
||||||
|
#if defined( _WIN32 ) || defined( __linux__ )
|
||||||
|
if ( !Q_stricmp(funcname, "qmax") ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if ( !Q_stricmp(funcname, "qmin") ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
// -NERVE - SMF
|
||||||
|
|
||||||
|
f = (replacefunc_t *) GetMemory( sizeof( replacefunc_t ) + strlen( funcname ) + 1 + 6 + strlen( filename ) + 1 );
|
||||||
|
f->name = (char *) f + sizeof( replacefunc_t );
|
||||||
|
strcpy( f->name, funcname );
|
||||||
|
f->newname = (char *) f + sizeof( replacefunc_t ) + strlen( funcname ) + 1;
|
||||||
|
sprintf( f->newname, "F%d", numfuncs++ );
|
||||||
|
f->filename = (char *) f + sizeof( replacefunc_t ) + strlen( funcname ) + 1 + strlen( f->newname ) + 1;
|
||||||
|
strcpy( f->filename, filename );
|
||||||
|
f->next = replacefuncs;
|
||||||
|
replacefuncs = f;
|
||||||
|
|
||||||
|
// construct the declaration
|
||||||
|
list = head;
|
||||||
|
f->dec[0] = '\0';
|
||||||
|
ConcatDec( list, f->dec, 0 );
|
||||||
|
|
||||||
|
} //end of the function AddFunctionName
|
||||||
|
|
||||||
|
/*
|
||||||
|
=================
|
||||||
|
AddTokenToList
|
||||||
|
=================
|
||||||
|
*/
|
||||||
|
void AddTokenToList (tokenList_t **head, token_t *token)
|
||||||
|
{
|
||||||
|
tokenList_t *newhead;
|
||||||
|
|
||||||
|
newhead = &tokenList[tokenListHead++]; //GetMemory( sizeof( tokenList_t ) );
|
||||||
|
if ( tokenListHead == MAX_TOKEN_LIST ) {
|
||||||
|
tokenListHead = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
newhead->next = *head;
|
||||||
|
newhead->token = *token;
|
||||||
|
|
||||||
|
*head = newhead;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
/*
|
||||||
|
=================
|
||||||
|
KillTokenList
|
||||||
|
=================
|
||||||
|
*/
|
||||||
|
void KillTokenList (tokenList_t *head)
|
||||||
|
{
|
||||||
|
if (head->next) {
|
||||||
|
KillTokenList( head->next );
|
||||||
|
FreeMemory( head->next );
|
||||||
|
head->next = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
=================
|
||||||
|
StripTokenList
|
||||||
|
=================
|
||||||
|
*/
|
||||||
|
void StripTokenList (tokenList_t *head)
|
||||||
|
{
|
||||||
|
tokenList_t *trav, *lastTrav;
|
||||||
|
|
||||||
|
trav = head;
|
||||||
|
|
||||||
|
// now go back to the start of the declaration
|
||||||
|
lastTrav = trav;
|
||||||
|
trav = trav->next; // should be on the function name now
|
||||||
|
while ( ( trav->token.type == TT_NAME ) || ( trav->token.string[0] == '*' ) )
|
||||||
|
{
|
||||||
|
lastTrav = trav;
|
||||||
|
trav = trav->next;
|
||||||
|
if ( !trav ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// now kill everything after lastTrav
|
||||||
|
// KillTokenList( lastTrav );
|
||||||
|
lastTrav->next = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
=================
|
||||||
|
GetTypeNamesFromFile
|
||||||
|
|
||||||
|
Knightmare- this gets structs / vars of a given type
|
||||||
|
=================
|
||||||
|
*/
|
||||||
|
void GetTypeNamesFromFile (char *filename, char *typeName)
|
||||||
|
{
|
||||||
|
source_t *source;
|
||||||
|
token_t token, lasttoken;
|
||||||
|
int indent = 0;//, brace;
|
||||||
|
int isStatic = 0;
|
||||||
|
int isExtern = 0;
|
||||||
|
tokenList_t *listHead;
|
||||||
|
|
||||||
|
listHead = NULL;
|
||||||
|
source = LoadSourceFile( filename );
|
||||||
|
if ( !source ) {
|
||||||
|
Error( "error opening %s", filename );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
while ( 1 )
|
||||||
|
{
|
||||||
|
if ( !PC_ReadToken( source, &token ) ) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if ( token.type == TT_PUNCTUATION )
|
||||||
|
{
|
||||||
|
switch ( token.string[0] )
|
||||||
|
{
|
||||||
|
case ';':
|
||||||
|
isStatic = 0;
|
||||||
|
isExtern = 0;
|
||||||
|
break;
|
||||||
|
case '{':
|
||||||
|
indent++;
|
||||||
|
break;
|
||||||
|
case '}':
|
||||||
|
indent--;
|
||||||
|
if ( indent < 0 )
|
||||||
|
indent = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( token.type == TT_NAME )
|
||||||
|
{ // type declarations for pointer table must be non-static, non-extern, and global in scope
|
||||||
|
if ( token.string[0] == 's' && !strcmp( token.string, "static" ) ) {
|
||||||
|
isStatic = 1;
|
||||||
|
}
|
||||||
|
if ( token.string[0] == 'e' && !strcmp( token.string, "extern" ) ) {
|
||||||
|
isExtern = 1;
|
||||||
|
}
|
||||||
|
if ( !isStatic && !isExtern && indent == 0 && !strcmp(token.string, typeName) )
|
||||||
|
{
|
||||||
|
if ( PC_ReadToken( source, &token ) )
|
||||||
|
{
|
||||||
|
if ( token.type == TT_NAME )
|
||||||
|
{
|
||||||
|
if (listHead)
|
||||||
|
listHead->next = NULL;
|
||||||
|
listHead = NULL;
|
||||||
|
AddTokenToList( &listHead, &token );
|
||||||
|
AddFunctionName( token.string, filename, listHead );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
memcpy( &lasttoken, &token, sizeof( token_t ) );
|
||||||
|
}
|
||||||
|
FreeSource( source );
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
=================
|
||||||
|
GetFunctionNamesFromFile
|
||||||
|
=================
|
||||||
|
*/
|
||||||
|
void GetFunctionNamesFromFile (char *filename)
|
||||||
|
{
|
||||||
|
source_t *source;
|
||||||
|
token_t token, lasttoken;
|
||||||
|
int indent = 0, brace;
|
||||||
|
int isStatic = 0;
|
||||||
|
tokenList_t *listHead;
|
||||||
|
|
||||||
|
// filter some files out
|
||||||
|
if ( !Q_stricmp( filename, "bg_lib.c" ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
listHead = NULL;
|
||||||
|
source = LoadSourceFile( filename );
|
||||||
|
if ( !source ) {
|
||||||
|
Error( "error opening %s", filename );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// printf("loaded %s\n", filename);
|
||||||
|
// if (!PC_ReadToken(source, &lasttoken))
|
||||||
|
// {
|
||||||
|
// FreeSource(source);
|
||||||
|
// return;
|
||||||
|
// } //end if
|
||||||
|
while ( 1 )
|
||||||
|
{
|
||||||
|
if ( !PC_ReadToken( source, &token ) ) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
AddTokenToList( &listHead, &token );
|
||||||
|
if ( token.type == TT_PUNCTUATION )
|
||||||
|
{
|
||||||
|
switch ( token.string[0] )
|
||||||
|
{
|
||||||
|
case ';':
|
||||||
|
isStatic = 0;
|
||||||
|
break;
|
||||||
|
case '{':
|
||||||
|
indent++;
|
||||||
|
break;
|
||||||
|
case '}':
|
||||||
|
indent--;
|
||||||
|
if ( indent < 0 )
|
||||||
|
indent = 0;
|
||||||
|
break;
|
||||||
|
case '(':
|
||||||
|
if ( indent <= 0 && lasttoken.type == TT_NAME )
|
||||||
|
{
|
||||||
|
StripTokenList( listHead );
|
||||||
|
|
||||||
|
brace = 1;
|
||||||
|
while ( PC_ReadToken( source, &token ) )
|
||||||
|
{
|
||||||
|
AddTokenToList( &listHead, &token );
|
||||||
|
if ( token.string[0] == '(' ) {
|
||||||
|
brace++;
|
||||||
|
}
|
||||||
|
else if ( token.string[0] == ')' )
|
||||||
|
{
|
||||||
|
brace--;
|
||||||
|
if ( brace <= 0 )
|
||||||
|
{
|
||||||
|
if ( !PC_ReadToken( source, &token ) ) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if ( token.string[0] == '{' ) {
|
||||||
|
indent++;
|
||||||
|
if ( !isStatic && MayScrewUp( lasttoken.string ) ) {
|
||||||
|
AddFunctionName( lasttoken.string, filename, listHead );
|
||||||
|
}
|
||||||
|
} //end if
|
||||||
|
break;
|
||||||
|
} //end if
|
||||||
|
} //end if
|
||||||
|
} //end while
|
||||||
|
} //end if
|
||||||
|
break;
|
||||||
|
} //end switch
|
||||||
|
} //end if
|
||||||
|
if ( token.type == TT_NAME )
|
||||||
|
{
|
||||||
|
if ( token.string[0] == 's' && !strcmp( token.string, "static" ) ) {
|
||||||
|
isStatic = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
memcpy( &lasttoken, &token, sizeof( token_t ) );
|
||||||
|
} //end while
|
||||||
|
FreeSource( source );
|
||||||
|
} //end of the function GetFunctionNamesFromFile
|
||||||
|
|
||||||
|
/*
|
||||||
|
=================
|
||||||
|
Usage
|
||||||
|
=================
|
||||||
|
*/
|
||||||
|
void Usage (void)
|
||||||
|
{
|
||||||
|
// Error( "USAGE SCREWUP: extractfuncs <file filter>\n" );
|
||||||
|
Error( "USAGE SCREWUP: extractfuncs <file1> [<file2> ..] [-t <structname>] [-o <func_list> <func_decs>] [-d <define>]\n"
|
||||||
|
"no -o defaults to g_func_list.h g_func_decs.h or g_<structname>_list.h g_<structname>_decs.h\n" );
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
=================
|
||||||
|
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;
|
||||||
|
|
||||||
|
// 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] != '-') )
|
||||||
|
{
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (argc < 1 || (firstParmSet && firstParm < 1))
|
||||||
|
Usage ();
|
||||||
|
// end Knightmare
|
||||||
|
|
||||||
|
handle = FindFirstFile (argv[1], &filedata);
|
||||||
|
done = (handle == INVALID_HANDLE_VALUE);
|
||||||
|
while (!done)
|
||||||
|
{
|
||||||
|
if ( !(filedata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) )
|
||||||
|
{
|
||||||
|
if (typeExtract)
|
||||||
|
GetTypeNamesFromFile (filedata.cFileName, typeName);
|
||||||
|
else
|
||||||
|
GetFunctionNamesFromFile (filedata.cFileName);
|
||||||
|
}
|
||||||
|
//find the next file
|
||||||
|
done = !FindNextFile (handle, &filedata);
|
||||||
|
}
|
||||||
|
if (typeExtract)
|
||||||
|
DumpReplaceFunctions (typeName);
|
||||||
|
else
|
||||||
|
DumpReplaceFunctions (NULL);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
/*
|
||||||
|
*nix version, let the shell do the pattern matching
|
||||||
|
(that's what shells are for :-))
|
||||||
|
*/
|
||||||
|
int main (int argc, char *argv[])
|
||||||
|
{
|
||||||
|
int i, firstParm;
|
||||||
|
int argbase = 1;
|
||||||
|
char typeName[128];
|
||||||
|
qboolean typeExtract = false;
|
||||||
|
qboolean firstParmSet = false;
|
||||||
|
|
||||||
|
/* if ( argc < 2 )
|
||||||
|
Usage();
|
||||||
|
|
||||||
|
if ( !Q_stricmp(argv[1],"-o") )
|
||||||
|
{
|
||||||
|
if ( argc < 5 ) {
|
||||||
|
Usage ();
|
||||||
|
}
|
||||||
|
func_listfile = argv[2];
|
||||||
|
func_decsfile = argv[3];
|
||||||
|
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] != '-') )
|
||||||
|
{
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (argc < 1 || (firstParmSet && firstParm < 1))
|
||||||
|
Usage ();
|
||||||
|
// end Knightmare
|
||||||
|
|
||||||
|
// for ( i = argbase; i < argc; i++ )
|
||||||
|
for ( i = argbase; i < firstParm; i++ )
|
||||||
|
{
|
||||||
|
printf( "%d: %s\n", i, argv[i] );
|
||||||
|
GetFunctionNamesFromFile (argv[i]);
|
||||||
|
}
|
||||||
|
if (typeExtract)
|
||||||
|
DumpReplaceFunctions (typeName);
|
||||||
|
else
|
||||||
|
DumpReplaceFunctions (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
BIN
extractfuncs.exe
Normal file
BIN
extractfuncs.exe
Normal file
Binary file not shown.
20
extractfuncs.sln
Normal file
20
extractfuncs.sln
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 10.00
|
||||||
|
# Visual Studio 2008
|
||||||
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "extractfuncs", "extractfuncs_2008.vcproj", "{0FC559FD-6DCD-4A81-B286-688F79286AEF}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Win32 = Debug|Win32
|
||||||
|
Release|Win32 = Release|Win32
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{0FC559FD-6DCD-4A81-B286-688F79286AEF}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||||
|
{0FC559FD-6DCD-4A81-B286-688F79286AEF}.Debug|Win32.Build.0 = Debug|Win32
|
||||||
|
{0FC559FD-6DCD-4A81-B286-688F79286AEF}.Release|Win32.ActiveCfg = Release|Win32
|
||||||
|
{0FC559FD-6DCD-4A81-B286-688F79286AEF}.Release|Win32.Build.0 = Release|Win32
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
352
extractfuncs_2008.vcproj
Normal file
352
extractfuncs_2008.vcproj
Normal file
|
@ -0,0 +1,352 @@
|
||||||
|
<?xml version="1.0" encoding="Windows-1252"?>
|
||||||
|
<VisualStudioProject
|
||||||
|
ProjectType="Visual C++"
|
||||||
|
Version="9.00"
|
||||||
|
Name="extractfuncs"
|
||||||
|
ProjectGUID="{0FC559FD-6DCD-4A81-B286-688F79286AEF}"
|
||||||
|
TargetFrameworkVersion="0"
|
||||||
|
>
|
||||||
|
<Platforms>
|
||||||
|
<Platform
|
||||||
|
Name="Win32"
|
||||||
|
/>
|
||||||
|
</Platforms>
|
||||||
|
<ToolFiles>
|
||||||
|
</ToolFiles>
|
||||||
|
<Configurations>
|
||||||
|
<Configuration
|
||||||
|
Name="Debug|Win32"
|
||||||
|
OutputDirectory=".\Debug"
|
||||||
|
IntermediateDirectory=".\Debug"
|
||||||
|
ConfigurationType="1"
|
||||||
|
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
|
||||||
|
UseOfMFC="0"
|
||||||
|
ATLMinimizesCRunTimeLibraryUsage="false"
|
||||||
|
CharacterSet="2"
|
||||||
|
>
|
||||||
|
<Tool
|
||||||
|
Name="VCPreBuildEventTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCCustomBuildTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCXMLDataGeneratorTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCWebServiceProxyGeneratorTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCMIDLTool"
|
||||||
|
TypeLibraryName=".\Debug/extractfuncs.tlb"
|
||||||
|
HeaderFileName=""
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="0"
|
||||||
|
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;SCREWUP;_CRT_SECURE_NO_WARNINGS"
|
||||||
|
RuntimeLibrary="1"
|
||||||
|
PrecompiledHeaderFile=".\Debug/extractfuncs.pch"
|
||||||
|
AssemblerListingLocation=".\Debug/"
|
||||||
|
ObjectFile=".\Debug/"
|
||||||
|
ProgramDataBaseFileName=".\Debug/"
|
||||||
|
BrowseInformation="1"
|
||||||
|
WarningLevel="3"
|
||||||
|
SuppressStartupBanner="true"
|
||||||
|
DebugInformationFormat="4"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCManagedResourceCompilerTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCResourceCompilerTool"
|
||||||
|
PreprocessorDefinitions="_DEBUG"
|
||||||
|
Culture="1033"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCPreLinkEventTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCLinkerTool"
|
||||||
|
OutputFile="extractfuncs.exe"
|
||||||
|
LinkIncremental="2"
|
||||||
|
SuppressStartupBanner="true"
|
||||||
|
GenerateDebugInformation="true"
|
||||||
|
GenerateMapFile="true"
|
||||||
|
MapFileName=".\Debug/extractfuncs.map"
|
||||||
|
SubSystem="1"
|
||||||
|
RandomizedBaseAddress="1"
|
||||||
|
DataExecutionPrevention="0"
|
||||||
|
TargetMachine="1"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCALinkTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCManifestTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCXDCMakeTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCBscMakeTool"
|
||||||
|
SuppressStartupBanner="true"
|
||||||
|
OutputFile=".\Debug/extractfuncs.bsc"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCFxCopTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCAppVerifierTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCPostBuildEventTool"
|
||||||
|
/>
|
||||||
|
</Configuration>
|
||||||
|
<Configuration
|
||||||
|
Name="Release|Win32"
|
||||||
|
OutputDirectory=".\Release"
|
||||||
|
IntermediateDirectory=".\Release"
|
||||||
|
ConfigurationType="1"
|
||||||
|
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
|
||||||
|
UseOfMFC="0"
|
||||||
|
ATLMinimizesCRunTimeLibraryUsage="false"
|
||||||
|
CharacterSet="2"
|
||||||
|
>
|
||||||
|
<Tool
|
||||||
|
Name="VCPreBuildEventTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCCustomBuildTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCXMLDataGeneratorTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCWebServiceProxyGeneratorTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCMIDLTool"
|
||||||
|
TypeLibraryName=".\Release/extractfuncs.tlb"
|
||||||
|
HeaderFileName=""
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="2"
|
||||||
|
InlineFunctionExpansion="1"
|
||||||
|
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;SCREWUP;_CRT_SECURE_NO_WARNINGS"
|
||||||
|
StringPooling="true"
|
||||||
|
RuntimeLibrary="0"
|
||||||
|
EnableFunctionLevelLinking="true"
|
||||||
|
PrecompiledHeaderFile=".\Release/extractfuncs.pch"
|
||||||
|
AssemblerListingLocation=".\Release/"
|
||||||
|
ObjectFile=".\Release/"
|
||||||
|
ProgramDataBaseFileName=".\Release/"
|
||||||
|
WarningLevel="3"
|
||||||
|
SuppressStartupBanner="true"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCManagedResourceCompilerTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCResourceCompilerTool"
|
||||||
|
PreprocessorDefinitions="NDEBUG"
|
||||||
|
Culture="1033"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCPreLinkEventTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCLinkerTool"
|
||||||
|
OutputFile="extractfuncs.exe"
|
||||||
|
LinkIncremental="1"
|
||||||
|
SuppressStartupBanner="true"
|
||||||
|
ProgramDatabaseFile=".\Release/extractfuncs.pdb"
|
||||||
|
SubSystem="1"
|
||||||
|
RandomizedBaseAddress="1"
|
||||||
|
DataExecutionPrevention="0"
|
||||||
|
TargetMachine="1"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCALinkTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCManifestTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCXDCMakeTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCBscMakeTool"
|
||||||
|
SuppressStartupBanner="true"
|
||||||
|
OutputFile=".\Release/extractfuncs.bsc"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCFxCopTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCAppVerifierTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCPostBuildEventTool"
|
||||||
|
/>
|
||||||
|
</Configuration>
|
||||||
|
</Configurations>
|
||||||
|
<References>
|
||||||
|
</References>
|
||||||
|
<Files>
|
||||||
|
<Filter
|
||||||
|
Name="Source Files"
|
||||||
|
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||||
|
>
|
||||||
|
<File
|
||||||
|
RelativePath="extractfuncs.c"
|
||||||
|
>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Debug|Win32"
|
||||||
|
>
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
PreprocessorDefinitions=""
|
||||||
|
/>
|
||||||
|
</FileConfiguration>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release|Win32"
|
||||||
|
>
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
PreprocessorDefinitions=""
|
||||||
|
/>
|
||||||
|
</FileConfiguration>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="l_log.c"
|
||||||
|
>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Debug|Win32"
|
||||||
|
>
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
PreprocessorDefinitions=""
|
||||||
|
/>
|
||||||
|
</FileConfiguration>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release|Win32"
|
||||||
|
>
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
PreprocessorDefinitions=""
|
||||||
|
/>
|
||||||
|
</FileConfiguration>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="l_memory.c"
|
||||||
|
>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Debug|Win32"
|
||||||
|
>
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
PreprocessorDefinitions=""
|
||||||
|
/>
|
||||||
|
</FileConfiguration>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release|Win32"
|
||||||
|
>
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
PreprocessorDefinitions=""
|
||||||
|
/>
|
||||||
|
</FileConfiguration>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="l_precomp.c"
|
||||||
|
>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Debug|Win32"
|
||||||
|
>
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
PreprocessorDefinitions=""
|
||||||
|
/>
|
||||||
|
</FileConfiguration>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release|Win32"
|
||||||
|
>
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
PreprocessorDefinitions=""
|
||||||
|
/>
|
||||||
|
</FileConfiguration>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="l_script.c"
|
||||||
|
>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Debug|Win32"
|
||||||
|
>
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
PreprocessorDefinitions=""
|
||||||
|
/>
|
||||||
|
</FileConfiguration>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release|Win32"
|
||||||
|
>
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
PreprocessorDefinitions=""
|
||||||
|
/>
|
||||||
|
</FileConfiguration>
|
||||||
|
</File>
|
||||||
|
</Filter>
|
||||||
|
<Filter
|
||||||
|
Name="Header Files"
|
||||||
|
Filter="h;hpp;hxx;hm;inl"
|
||||||
|
>
|
||||||
|
<File
|
||||||
|
RelativePath=".\l_log.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\l_memory.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\l_precomp.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\l_script.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
</Filter>
|
||||||
|
<Filter
|
||||||
|
Name="Resource Files"
|
||||||
|
Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||||
|
>
|
||||||
|
</Filter>
|
||||||
|
<File
|
||||||
|
RelativePath="extractfuncs.bat"
|
||||||
|
>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Debug|Win32"
|
||||||
|
ExcludedFromBuild="true"
|
||||||
|
>
|
||||||
|
<Tool
|
||||||
|
Name="VCCustomBuildTool"
|
||||||
|
/>
|
||||||
|
</FileConfiguration>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release|Win32"
|
||||||
|
ExcludedFromBuild="true"
|
||||||
|
>
|
||||||
|
<Tool
|
||||||
|
Name="VCCustomBuildTool"
|
||||||
|
/>
|
||||||
|
</FileConfiguration>
|
||||||
|
</File>
|
||||||
|
</Files>
|
||||||
|
<Globals>
|
||||||
|
</Globals>
|
||||||
|
</VisualStudioProject>
|
204
l_log.c
Normal file
204
l_log.c
Normal file
|
@ -0,0 +1,204 @@
|
||||||
|
/*
|
||||||
|
===========================================================================
|
||||||
|
|
||||||
|
Return to Castle Wolfenstein single player GPL Source Code
|
||||||
|
Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
|
||||||
|
|
||||||
|
This file is part of the Return to Castle Wolfenstein single player GPL Source Code (RTCW SP Source Code).
|
||||||
|
|
||||||
|
RTCW SP Source Code is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
RTCW SP Source Code is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with RTCW SP Source Code. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
In addition, the RTCW SP Source Code is also subject to certain additional terms.
|
||||||
|
You should have received a copy of these additional terms immediately following the
|
||||||
|
terms and conditions of the GNU General Public License which accompanied the RTCW SP
|
||||||
|
Source Code. If not, please request a copy in writing from id Software at the address below.
|
||||||
|
|
||||||
|
If you have questions concerning this license or the applicable additional terms,
|
||||||
|
you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
|
||||||
|
|
||||||
|
===========================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
//===========================================================================
|
||||||
|
//
|
||||||
|
// Name: l_log.c
|
||||||
|
// Function: log file stuff
|
||||||
|
// Programmer: Mr Elusive (MrElusive@demigod.demon.nl)
|
||||||
|
// Last update: 1997-12-31
|
||||||
|
// Tab Size: 3
|
||||||
|
//===========================================================================
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "ef_local.h"
|
||||||
|
|
||||||
|
#define MAX_QPATH 64
|
||||||
|
//#include "qbsp.h"
|
||||||
|
|
||||||
|
#define MAX_LOGFILENAMESIZE 1024
|
||||||
|
|
||||||
|
typedef struct logfile_s
|
||||||
|
{
|
||||||
|
char filename[MAX_LOGFILENAMESIZE];
|
||||||
|
FILE *fp;
|
||||||
|
int numwrites;
|
||||||
|
} logfile_t;
|
||||||
|
|
||||||
|
logfile_t logfile;
|
||||||
|
|
||||||
|
//===========================================================================
|
||||||
|
//
|
||||||
|
// Parameter: -
|
||||||
|
// Returns: -
|
||||||
|
// Changes Globals: -
|
||||||
|
//===========================================================================
|
||||||
|
void Log_Open( char *filename ) {
|
||||||
|
if ( !filename || !strlen( filename ) ) {
|
||||||
|
printf( "openlog <filename>\n" );
|
||||||
|
return;
|
||||||
|
} //end if
|
||||||
|
if ( logfile.fp ) {
|
||||||
|
printf( "log file %s is already opened\n", logfile.filename );
|
||||||
|
return;
|
||||||
|
} //end if
|
||||||
|
logfile.fp = fopen( filename, "wb" );
|
||||||
|
if ( !logfile.fp ) {
|
||||||
|
printf( "can't open the log file %s\n", filename );
|
||||||
|
return;
|
||||||
|
} //end if
|
||||||
|
strncpy( logfile.filename, filename, MAX_LOGFILENAMESIZE );
|
||||||
|
// printf("Opened log %s\n", logfile.filename);
|
||||||
|
} //end of the function Log_Create
|
||||||
|
//===========================================================================
|
||||||
|
//
|
||||||
|
// Parameter: -
|
||||||
|
// Returns: -
|
||||||
|
// Changes Globals: -
|
||||||
|
//===========================================================================
|
||||||
|
void Log_Close( void ) {
|
||||||
|
if ( !logfile.fp ) {
|
||||||
|
printf( "no log file to close\n" );
|
||||||
|
return;
|
||||||
|
} //end if
|
||||||
|
if ( fclose( logfile.fp ) ) {
|
||||||
|
printf( "can't close log file %s\n", logfile.filename );
|
||||||
|
return;
|
||||||
|
} //end if
|
||||||
|
logfile.fp = NULL;
|
||||||
|
// printf("Closed log %s\n", logfile.filename);
|
||||||
|
} //end of the function Log_Close
|
||||||
|
//===========================================================================
|
||||||
|
//
|
||||||
|
// Parameter: -
|
||||||
|
// Returns: -
|
||||||
|
// Changes Globals: -
|
||||||
|
//===========================================================================
|
||||||
|
void Log_Shutdown( void ) {
|
||||||
|
if ( logfile.fp ) {
|
||||||
|
Log_Close();
|
||||||
|
}
|
||||||
|
} //end of the function Log_Shutdown
|
||||||
|
//===========================================================================
|
||||||
|
//
|
||||||
|
// Parameter: -
|
||||||
|
// Returns: -
|
||||||
|
// Changes Globals: -
|
||||||
|
//===========================================================================
|
||||||
|
void Log_Print( char *fmt, ... ) {
|
||||||
|
va_list ap;
|
||||||
|
#ifdef WINBSPC
|
||||||
|
char buf[2048];
|
||||||
|
#endif //WINBSPC
|
||||||
|
|
||||||
|
if ( verbose ) {
|
||||||
|
va_start( ap, fmt );
|
||||||
|
#ifdef WINBSPC
|
||||||
|
vsprintf( buf, fmt, ap );
|
||||||
|
WinBSPCPrint( buf );
|
||||||
|
#else
|
||||||
|
vprintf( fmt, ap );
|
||||||
|
#endif //WINBSPS
|
||||||
|
va_end( ap );
|
||||||
|
} //end if
|
||||||
|
|
||||||
|
va_start( ap, fmt );
|
||||||
|
if ( logfile.fp ) {
|
||||||
|
vfprintf( logfile.fp, fmt, ap );
|
||||||
|
fflush( logfile.fp );
|
||||||
|
} //end if
|
||||||
|
va_end( ap );
|
||||||
|
} //end of the function Log_Print
|
||||||
|
//===========================================================================
|
||||||
|
//
|
||||||
|
// Parameter: -
|
||||||
|
// Returns: -
|
||||||
|
// Changes Globals: -
|
||||||
|
//===========================================================================
|
||||||
|
void Log_Write( char *fmt, ... ) {
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
if ( !logfile.fp ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
va_start( ap, fmt );
|
||||||
|
vfprintf( logfile.fp, fmt, ap );
|
||||||
|
va_end( ap );
|
||||||
|
fflush( logfile.fp );
|
||||||
|
} //end of the function Log_Write
|
||||||
|
//===========================================================================
|
||||||
|
//
|
||||||
|
// Parameter: -
|
||||||
|
// Returns: -
|
||||||
|
// Changes Globals: -
|
||||||
|
//===========================================================================
|
||||||
|
void Log_WriteTimeStamped( char *fmt, ... ) {
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
if ( !logfile.fp ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
/* fprintf(logfile.fp, "%d %02d:%02d:%02d:%02d ",
|
||||||
|
logfile.numwrites,
|
||||||
|
(int) (botlibglobals.time / 60 / 60),
|
||||||
|
(int) (botlibglobals.time / 60),
|
||||||
|
(int) (botlibglobals.time),
|
||||||
|
(int) ((int) (botlibglobals.time * 100)) -
|
||||||
|
((int) botlibglobals.time) * 100);*/
|
||||||
|
va_start( ap, fmt );
|
||||||
|
vfprintf( logfile.fp, fmt, ap );
|
||||||
|
va_end( ap );
|
||||||
|
logfile.numwrites++;
|
||||||
|
fflush( logfile.fp );
|
||||||
|
} //end of the function Log_Write
|
||||||
|
//===========================================================================
|
||||||
|
//
|
||||||
|
// Parameter: -
|
||||||
|
// Returns: -
|
||||||
|
// Changes Globals: -
|
||||||
|
//===========================================================================
|
||||||
|
FILE *Log_FileStruct( void ) {
|
||||||
|
return logfile.fp;
|
||||||
|
} //end of the function Log_FileStruct
|
||||||
|
//===========================================================================
|
||||||
|
//
|
||||||
|
// Parameter: -
|
||||||
|
// Returns: -
|
||||||
|
// Changes Globals: -
|
||||||
|
//===========================================================================
|
||||||
|
void Log_Flush( void ) {
|
||||||
|
if ( logfile.fp ) {
|
||||||
|
fflush( logfile.fp );
|
||||||
|
}
|
||||||
|
} //end of the function Log_Flush
|
63
l_log.h
Normal file
63
l_log.h
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
/*
|
||||||
|
===========================================================================
|
||||||
|
|
||||||
|
Return to Castle Wolfenstein single player GPL Source Code
|
||||||
|
Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
|
||||||
|
|
||||||
|
This file is part of the Return to Castle Wolfenstein single player GPL Source Code (RTCW SP Source Code).
|
||||||
|
|
||||||
|
RTCW SP Source Code is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
RTCW SP Source Code is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with RTCW SP Source Code. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
In addition, the RTCW SP Source Code is also subject to certain additional terms.
|
||||||
|
You should have received a copy of these additional terms immediately following the
|
||||||
|
terms and conditions of the GNU General Public License which accompanied the RTCW SP
|
||||||
|
Source Code. If not, please request a copy in writing from id Software at the address below.
|
||||||
|
|
||||||
|
If you have questions concerning this license or the applicable additional terms,
|
||||||
|
you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
|
||||||
|
|
||||||
|
===========================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
//===========================================================================
|
||||||
|
//
|
||||||
|
// Name: l_log.h
|
||||||
|
// Function: log file stuff
|
||||||
|
// Programmer: Mr Elusive (MrElusive@demigod.demon.nl)
|
||||||
|
// Last update: 1997-12-31
|
||||||
|
// Tab Size: 3
|
||||||
|
//===========================================================================
|
||||||
|
|
||||||
|
//open a log file
|
||||||
|
void Log_Open( char *filename );
|
||||||
|
//close the current log file
|
||||||
|
void Log_Close( void );
|
||||||
|
//close log file if present
|
||||||
|
void Log_Shutdown( void );
|
||||||
|
//print on stdout and write to the current opened log file
|
||||||
|
void Log_Print( char *fmt, ... );
|
||||||
|
//write to the current opened log file
|
||||||
|
void Log_Write( char *fmt, ... );
|
||||||
|
//write to the current opened log file with a time stamp
|
||||||
|
void Log_WriteTimeStamped( char *fmt, ... );
|
||||||
|
//returns the log file structure
|
||||||
|
FILE *Log_FileStruct( void );
|
||||||
|
//flush log file
|
||||||
|
void Log_Flush( void );
|
||||||
|
|
||||||
|
int Log_Written( void );
|
||||||
|
|
||||||
|
#ifdef WINBSPC
|
||||||
|
void WinBSPCPrint( char *str );
|
||||||
|
#endif //WINBSPC
|
455
l_memory.c
Normal file
455
l_memory.c
Normal file
|
@ -0,0 +1,455 @@
|
||||||
|
/*
|
||||||
|
===========================================================================
|
||||||
|
|
||||||
|
Return to Castle Wolfenstein single player GPL Source Code
|
||||||
|
Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
|
||||||
|
|
||||||
|
This file is part of the Return to Castle Wolfenstein single player GPL Source Code (RTCW SP Source Code).
|
||||||
|
|
||||||
|
RTCW SP Source Code is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
RTCW SP Source Code is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with RTCW SP Source Code. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
In addition, the RTCW SP Source Code is also subject to certain additional terms.
|
||||||
|
You should have received a copy of these additional terms immediately following the
|
||||||
|
terms and conditions of the GNU General Public License which accompanied the RTCW SP
|
||||||
|
Source Code. If not, please request a copy in writing from id Software at the address below.
|
||||||
|
|
||||||
|
If you have questions concerning this license or the applicable additional terms,
|
||||||
|
you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
|
||||||
|
|
||||||
|
===========================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************
|
||||||
|
* name: l_memory.c
|
||||||
|
*
|
||||||
|
* desc: memory allocation
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
//#include "q_shared.h"
|
||||||
|
//#include "../game/botlib.h"
|
||||||
|
//#include "../../src/botlib/be_interface.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include "l_log.h"
|
||||||
|
|
||||||
|
//#define MEMDEBUG
|
||||||
|
//#define MEMORYMANEGER
|
||||||
|
|
||||||
|
#define MEM_ID 0x12345678l
|
||||||
|
#define HUNK_ID 0x87654321l
|
||||||
|
|
||||||
|
int allocatedmemory;
|
||||||
|
int totalmemorysize;
|
||||||
|
int numblocks;
|
||||||
|
|
||||||
|
#ifdef MEMORYMANEGER
|
||||||
|
|
||||||
|
typedef struct memoryblock_s
|
||||||
|
{
|
||||||
|
unsigned long int id;
|
||||||
|
void *ptr;
|
||||||
|
int size;
|
||||||
|
#ifdef MEMDEBUG
|
||||||
|
char *label;
|
||||||
|
char *file;
|
||||||
|
int line;
|
||||||
|
#endif //MEMDEBUG
|
||||||
|
struct memoryblock_s *prev, *next;
|
||||||
|
} memoryblock_t;
|
||||||
|
|
||||||
|
memoryblock_t *memory;
|
||||||
|
|
||||||
|
//===========================================================================
|
||||||
|
//
|
||||||
|
// Parameter: -
|
||||||
|
// Returns: -
|
||||||
|
// Changes Globals: -
|
||||||
|
//===========================================================================
|
||||||
|
void LinkMemoryBlock( memoryblock_t *block ) {
|
||||||
|
block->prev = NULL;
|
||||||
|
block->next = memory;
|
||||||
|
if ( memory ) {
|
||||||
|
memory->prev = block;
|
||||||
|
}
|
||||||
|
memory = block;
|
||||||
|
} //end of the function LinkMemoryBlock
|
||||||
|
//===========================================================================
|
||||||
|
//
|
||||||
|
// Parameter: -
|
||||||
|
// Returns: -
|
||||||
|
// Changes Globals: -
|
||||||
|
//===========================================================================
|
||||||
|
void UnlinkMemoryBlock( memoryblock_t *block ) {
|
||||||
|
if ( block->prev ) {
|
||||||
|
block->prev->next = block->next;
|
||||||
|
} else { memory = block->next;}
|
||||||
|
if ( block->next ) {
|
||||||
|
block->next->prev = block->prev;
|
||||||
|
}
|
||||||
|
} //end of the function UnlinkMemoryBlock
|
||||||
|
//===========================================================================
|
||||||
|
//
|
||||||
|
// Parameter: -
|
||||||
|
// Returns: -
|
||||||
|
// Changes Globals: -
|
||||||
|
//===========================================================================
|
||||||
|
#ifdef MEMDEBUG
|
||||||
|
void *GetMemoryDebug( unsigned long size, char *label, char *file, int line )
|
||||||
|
#else
|
||||||
|
void *GetMemory( unsigned long size )
|
||||||
|
#endif //MEMDEBUG
|
||||||
|
{
|
||||||
|
void *ptr;
|
||||||
|
memoryblock_t *block;
|
||||||
|
|
||||||
|
ptr = malloc( size + sizeof( memoryblock_t ) );
|
||||||
|
block = (memoryblock_t *) ptr;
|
||||||
|
block->id = MEM_ID;
|
||||||
|
block->ptr = (char *) ptr + sizeof( memoryblock_t );
|
||||||
|
block->size = size + sizeof( memoryblock_t );
|
||||||
|
#ifdef MEMDEBUG
|
||||||
|
block->label = label;
|
||||||
|
block->file = file;
|
||||||
|
block->line = line;
|
||||||
|
#endif //MEMDEBUG
|
||||||
|
LinkMemoryBlock( block );
|
||||||
|
allocatedmemory += block->size;
|
||||||
|
totalmemorysize += block->size + sizeof( memoryblock_t );
|
||||||
|
numblocks++;
|
||||||
|
return block->ptr;
|
||||||
|
} //end of the function GetMemoryDebug
|
||||||
|
//===========================================================================
|
||||||
|
//
|
||||||
|
// Parameter: -
|
||||||
|
// Returns: -
|
||||||
|
// Changes Globals: -
|
||||||
|
//===========================================================================
|
||||||
|
#ifdef MEMDEBUG
|
||||||
|
void *GetClearedMemoryDebug( unsigned long size, char *label, char *file, int line )
|
||||||
|
#else
|
||||||
|
void *GetClearedMemory( unsigned long size )
|
||||||
|
#endif //MEMDEBUG
|
||||||
|
{
|
||||||
|
void *ptr;
|
||||||
|
#ifdef MEMDEBUG
|
||||||
|
ptr = GetMemoryDebug( size, label, file, line );
|
||||||
|
#else
|
||||||
|
ptr = GetMemory( size );
|
||||||
|
#endif //MEMDEBUG
|
||||||
|
memset( ptr, 0, size );
|
||||||
|
return ptr;
|
||||||
|
} //end of the function GetClearedMemory
|
||||||
|
//===========================================================================
|
||||||
|
//
|
||||||
|
// Parameter: -
|
||||||
|
// Returns: -
|
||||||
|
// Changes Globals: -
|
||||||
|
//===========================================================================
|
||||||
|
#ifdef MEMDEBUG
|
||||||
|
void *GetHunkMemoryDebug( unsigned long size, char *label, char *file, int line )
|
||||||
|
#else
|
||||||
|
void *GetHunkMemory( unsigned long size )
|
||||||
|
#endif //MEMDEBUG
|
||||||
|
{
|
||||||
|
void *ptr;
|
||||||
|
memoryblock_t *block;
|
||||||
|
|
||||||
|
ptr = malloc( size + sizeof( memoryblock_t ) );
|
||||||
|
block = (memoryblock_t *) ptr;
|
||||||
|
block->id = HUNK_ID;
|
||||||
|
block->ptr = (char *) ptr + sizeof( memoryblock_t );
|
||||||
|
block->size = size + sizeof( memoryblock_t );
|
||||||
|
#ifdef MEMDEBUG
|
||||||
|
block->label = label;
|
||||||
|
block->file = file;
|
||||||
|
block->line = line;
|
||||||
|
#endif //MEMDEBUG
|
||||||
|
LinkMemoryBlock( block );
|
||||||
|
allocatedmemory += block->size;
|
||||||
|
totalmemorysize += block->size + sizeof( memoryblock_t );
|
||||||
|
numblocks++;
|
||||||
|
return block->ptr;
|
||||||
|
} //end of the function GetHunkMemoryDebug
|
||||||
|
//===========================================================================
|
||||||
|
//
|
||||||
|
// Parameter: -
|
||||||
|
// Returns: -
|
||||||
|
// Changes Globals: -
|
||||||
|
//===========================================================================
|
||||||
|
#ifdef MEMDEBUG
|
||||||
|
void *GetClearedHunkMemoryDebug( unsigned long size, char *label, char *file, int line )
|
||||||
|
#else
|
||||||
|
void *GetClearedHunkMemory( unsigned long size )
|
||||||
|
#endif //MEMDEBUG
|
||||||
|
{
|
||||||
|
void *ptr;
|
||||||
|
#ifdef MEMDEBUG
|
||||||
|
ptr = GetHunkMemoryDebug( size, label, file, line );
|
||||||
|
#else
|
||||||
|
ptr = GetHunkMemory( size );
|
||||||
|
#endif //MEMDEBUG
|
||||||
|
memset( ptr, 0, size );
|
||||||
|
return ptr;
|
||||||
|
} //end of the function GetClearedHunkMemory
|
||||||
|
//===========================================================================
|
||||||
|
//
|
||||||
|
// Parameter: -
|
||||||
|
// Returns: -
|
||||||
|
// Changes Globals: -
|
||||||
|
//===========================================================================
|
||||||
|
memoryblock_t *BlockFromPointer( void *ptr, char *str ) {
|
||||||
|
memoryblock_t *block;
|
||||||
|
|
||||||
|
if ( !ptr ) {
|
||||||
|
#ifdef MEMDEBUG
|
||||||
|
//char *crash = (char *) NULL;
|
||||||
|
//crash[0] = 1;
|
||||||
|
printf( PRT_FATAL, "%s: NULL pointer\n", str );
|
||||||
|
#endif MEMDEBUG
|
||||||
|
return NULL;
|
||||||
|
} //end if
|
||||||
|
block = ( memoryblock_t * )( (char *) ptr - sizeof( memoryblock_t ) );
|
||||||
|
if ( block->id != MEM_ID && block->id != HUNK_ID ) {
|
||||||
|
printf( PRT_FATAL, "%s: invalid memory block\n", str );
|
||||||
|
return NULL;
|
||||||
|
} //end if
|
||||||
|
if ( block->ptr != ptr ) {
|
||||||
|
printf( PRT_FATAL, "%s: memory block pointer invalid\n", str );
|
||||||
|
return NULL;
|
||||||
|
} //end if
|
||||||
|
return block;
|
||||||
|
} //end of the function BlockFromPointer
|
||||||
|
//===========================================================================
|
||||||
|
//
|
||||||
|
// Parameter: -
|
||||||
|
// Returns: -
|
||||||
|
// Changes Globals: -
|
||||||
|
//===========================================================================
|
||||||
|
void FreeMemory( void *ptr ) {
|
||||||
|
memoryblock_t *block;
|
||||||
|
|
||||||
|
block = BlockFromPointer( ptr, "FreeMemory" );
|
||||||
|
if ( !block ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
UnlinkMemoryBlock( block );
|
||||||
|
allocatedmemory -= block->size;
|
||||||
|
totalmemorysize -= block->size + sizeof( memoryblock_t );
|
||||||
|
numblocks--;
|
||||||
|
//
|
||||||
|
if ( block->id == MEM_ID ) {
|
||||||
|
free( block );
|
||||||
|
} //end if
|
||||||
|
} //end of the function FreeMemory
|
||||||
|
//===========================================================================
|
||||||
|
//
|
||||||
|
// Parameter: -
|
||||||
|
// Returns: -
|
||||||
|
// Changes Globals: -
|
||||||
|
//===========================================================================
|
||||||
|
int MemoryByteSize( void *ptr ) {
|
||||||
|
memoryblock_t *block;
|
||||||
|
|
||||||
|
block = BlockFromPointer( ptr, "MemoryByteSize" );
|
||||||
|
if ( !block ) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return block->size;
|
||||||
|
} //end of the function MemoryByteSize
|
||||||
|
//===========================================================================
|
||||||
|
//
|
||||||
|
// Parameter: -
|
||||||
|
// Returns: -
|
||||||
|
// Changes Globals: -
|
||||||
|
//===========================================================================
|
||||||
|
void PrintUsedMemorySize( void ) {
|
||||||
|
printf( PRT_MESSAGE, "total allocated memory: %d KB\n", allocatedmemory >> 10 );
|
||||||
|
printf( PRT_MESSAGE, "total botlib memory: %d KB\n", totalmemorysize >> 10 );
|
||||||
|
printf( PRT_MESSAGE, "total memory blocks: %d\n", numblocks );
|
||||||
|
} //end of the function PrintUsedMemorySize
|
||||||
|
//===========================================================================
|
||||||
|
//
|
||||||
|
// Parameter: -
|
||||||
|
// Returns: -
|
||||||
|
// Changes Globals: -
|
||||||
|
//===========================================================================
|
||||||
|
void PrintMemoryLabels( void ) {
|
||||||
|
memoryblock_t *block;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
PrintUsedMemorySize();
|
||||||
|
i = 0;
|
||||||
|
Log_Write( "\r\n" );
|
||||||
|
for ( block = memory; block; block = block->next )
|
||||||
|
{
|
||||||
|
#ifdef MEMDEBUG
|
||||||
|
if ( block->id == HUNK_ID ) {
|
||||||
|
Log_Write( "%6d, hunk %p, %8d: %24s line %6d: %s\r\n", i, block->ptr, block->size, block->file, block->line, block->label );
|
||||||
|
} //end if
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Log_Write( "%6d, %p, %8d: %24s line %6d: %s\r\n", i, block->ptr, block->size, block->file, block->line, block->label );
|
||||||
|
} //end else
|
||||||
|
#endif //MEMDEBUG
|
||||||
|
i++;
|
||||||
|
} //end for
|
||||||
|
} //end of the function PrintMemoryLabels
|
||||||
|
//===========================================================================
|
||||||
|
//
|
||||||
|
// Parameter: -
|
||||||
|
// Returns: -
|
||||||
|
// Changes Globals: -
|
||||||
|
//===========================================================================
|
||||||
|
void DumpMemory( void ) {
|
||||||
|
memoryblock_t *block;
|
||||||
|
|
||||||
|
for ( block = memory; block; block = memory )
|
||||||
|
{
|
||||||
|
FreeMemory( block->ptr );
|
||||||
|
} //end for
|
||||||
|
totalmemorysize = 0;
|
||||||
|
allocatedmemory = 0;
|
||||||
|
} //end of the function DumpMemory
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
//===========================================================================
|
||||||
|
//
|
||||||
|
// Parameter: -
|
||||||
|
// Returns: -
|
||||||
|
// Changes Globals: -
|
||||||
|
//===========================================================================
|
||||||
|
#ifdef MEMDEBUG
|
||||||
|
void *GetMemoryDebug( unsigned long size, char *label, char *file, int line )
|
||||||
|
#else
|
||||||
|
void *GetMemory( unsigned long size )
|
||||||
|
#endif //MEMDEBUG
|
||||||
|
{
|
||||||
|
void *ptr;
|
||||||
|
unsigned long int *memid;
|
||||||
|
|
||||||
|
ptr = malloc( size + sizeof( unsigned long int ) );
|
||||||
|
if ( !ptr ) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
memid = (unsigned long int *) ptr;
|
||||||
|
*memid = MEM_ID;
|
||||||
|
return (unsigned long int *) ( (char *) ptr + sizeof( unsigned long int ) );
|
||||||
|
} //end of the function GetMemory
|
||||||
|
//===========================================================================
|
||||||
|
//
|
||||||
|
// Parameter: -
|
||||||
|
// Returns: -
|
||||||
|
// Changes Globals: -
|
||||||
|
//===========================================================================
|
||||||
|
#ifdef MEMDEBUG
|
||||||
|
void *GetClearedMemoryDebug( unsigned long size, char *label, char *file, int line )
|
||||||
|
#else
|
||||||
|
void *GetClearedMemory( unsigned long size )
|
||||||
|
#endif //MEMDEBUG
|
||||||
|
{
|
||||||
|
void *ptr;
|
||||||
|
#ifdef MEMDEBUG
|
||||||
|
ptr = GetMemoryDebug( size, label, file, line );
|
||||||
|
#else
|
||||||
|
ptr = GetMemory( size );
|
||||||
|
#endif //MEMDEBUG
|
||||||
|
memset( ptr, 0, size );
|
||||||
|
return ptr;
|
||||||
|
} //end of the function GetClearedMemory
|
||||||
|
//===========================================================================
|
||||||
|
//
|
||||||
|
// Parameter: -
|
||||||
|
// Returns: -
|
||||||
|
// Changes Globals: -
|
||||||
|
//===========================================================================
|
||||||
|
#ifdef MEMDEBUG
|
||||||
|
void *GetHunkMemoryDebug( unsigned long size, char *label, char *file, int line )
|
||||||
|
#else
|
||||||
|
void *GetHunkMemory( unsigned long size )
|
||||||
|
#endif //MEMDEBUG
|
||||||
|
{
|
||||||
|
void *ptr;
|
||||||
|
unsigned long int *memid;
|
||||||
|
|
||||||
|
ptr = malloc( size + sizeof( unsigned long int ) );
|
||||||
|
if ( !ptr ) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
memid = (unsigned long int *) ptr;
|
||||||
|
*memid = HUNK_ID;
|
||||||
|
return (unsigned long int *) ( (char *) ptr + sizeof( unsigned long int ) );
|
||||||
|
} //end of the function GetHunkMemory
|
||||||
|
//===========================================================================
|
||||||
|
//
|
||||||
|
// Parameter: -
|
||||||
|
// Returns: -
|
||||||
|
// Changes Globals: -
|
||||||
|
//===========================================================================
|
||||||
|
#ifdef MEMDEBUG
|
||||||
|
void *GetClearedHunkMemoryDebug( unsigned long size, char *label, char *file, int line )
|
||||||
|
#else
|
||||||
|
void *GetClearedHunkMemory( unsigned long size )
|
||||||
|
#endif //MEMDEBUG
|
||||||
|
{
|
||||||
|
void *ptr;
|
||||||
|
#ifdef MEMDEBUG
|
||||||
|
ptr = GetHunkMemoryDebug( size, label, file, line );
|
||||||
|
#else
|
||||||
|
ptr = GetHunkMemory( size );
|
||||||
|
#endif //MEMDEBUG
|
||||||
|
memset( ptr, 0, size );
|
||||||
|
return ptr;
|
||||||
|
} //end of the function GetClearedHunkMemory
|
||||||
|
//===========================================================================
|
||||||
|
//
|
||||||
|
// Parameter: -
|
||||||
|
// Returns: -
|
||||||
|
// Changes Globals: -
|
||||||
|
//===========================================================================
|
||||||
|
void FreeMemory( void *ptr ) {
|
||||||
|
unsigned long int *memid;
|
||||||
|
|
||||||
|
memid = (unsigned long int *) ( (char *) ptr - sizeof( unsigned long int ) );
|
||||||
|
|
||||||
|
if ( *memid == MEM_ID ) {
|
||||||
|
free( memid );
|
||||||
|
} //end if
|
||||||
|
} //end of the function FreeMemory
|
||||||
|
//===========================================================================
|
||||||
|
//
|
||||||
|
// Parameter: -
|
||||||
|
// Returns: -
|
||||||
|
// Changes Globals: -
|
||||||
|
//===========================================================================
|
||||||
|
void PrintUsedMemorySize( void ) {
|
||||||
|
} //end of the function PrintUsedMemorySize
|
||||||
|
//===========================================================================
|
||||||
|
//
|
||||||
|
// Parameter: -
|
||||||
|
// Returns: -
|
||||||
|
// Changes Globals: -
|
||||||
|
//===========================================================================
|
||||||
|
void PrintMemoryLabels( void ) {
|
||||||
|
} //end of the function PrintMemoryLabels
|
||||||
|
|
||||||
|
#endif
|
84
l_memory.h
Normal file
84
l_memory.h
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
/*
|
||||||
|
===========================================================================
|
||||||
|
|
||||||
|
Return to Castle Wolfenstein single player GPL Source Code
|
||||||
|
Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
|
||||||
|
|
||||||
|
This file is part of the Return to Castle Wolfenstein single player GPL Source Code (RTCW SP Source Code).
|
||||||
|
|
||||||
|
RTCW SP Source Code is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
RTCW SP Source Code is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with RTCW SP Source Code. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
In addition, the RTCW SP Source Code is also subject to certain additional terms.
|
||||||
|
You should have received a copy of these additional terms immediately following the
|
||||||
|
terms and conditions of the GNU General Public License which accompanied the RTCW SP
|
||||||
|
Source Code. If not, please request a copy in writing from id Software at the address below.
|
||||||
|
|
||||||
|
If you have questions concerning this license or the applicable additional terms,
|
||||||
|
you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
|
||||||
|
|
||||||
|
===========================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************
|
||||||
|
* name: l_memory.h
|
||||||
|
*
|
||||||
|
* desc: memory management
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
//#define MEMDEBUG
|
||||||
|
|
||||||
|
#ifdef MEMDEBUG
|
||||||
|
#define GetMemory( size ) GetMemoryDebug( size, # size, __FILE__, __LINE__ );
|
||||||
|
#define GetClearedMemory( size ) GetClearedMemoryDebug( size, # size, __FILE__, __LINE__ );
|
||||||
|
//allocate a memory block of the given size
|
||||||
|
void *GetMemoryDebug( unsigned long size, char *label, char *file, int line );
|
||||||
|
//allocate a memory block of the given size and clear it
|
||||||
|
void *GetClearedMemoryDebug( unsigned long size, char *label, char *file, int line );
|
||||||
|
//
|
||||||
|
#define GetHunkMemory( size ) GetHunkMemoryDebug( size, # size, __FILE__, __LINE__ );
|
||||||
|
#define GetClearedHunkMemory( size ) GetClearedHunkMemoryDebug( size, # size, __FILE__, __LINE__ );
|
||||||
|
//allocate a memory block of the given size
|
||||||
|
void *GetHunkMemoryDebug( unsigned long size, char *label, char *file, int line );
|
||||||
|
//allocate a memory block of the given size and clear it
|
||||||
|
void *GetClearedHunkMemoryDebug( unsigned long size, char *label, char *file, int line );
|
||||||
|
#else
|
||||||
|
//allocate a memory block of the given size
|
||||||
|
void *GetMemory( unsigned long size );
|
||||||
|
//allocate a memory block of the given size and clear it
|
||||||
|
void *GetClearedMemory( unsigned long size );
|
||||||
|
//
|
||||||
|
#ifdef BSPC
|
||||||
|
#define GetHunkMemory GetMemory
|
||||||
|
#define GetClearedHunkMemory GetClearedMemory
|
||||||
|
#else
|
||||||
|
//allocate a memory block of the given size
|
||||||
|
void *GetHunkMemory( unsigned long size );
|
||||||
|
//allocate a memory block of the given size and clear it
|
||||||
|
void *GetClearedHunkMemory( unsigned long size );
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//free the given memory block
|
||||||
|
void FreeMemory( void *ptr );
|
||||||
|
//prints the total used memory size
|
||||||
|
void PrintUsedMemorySize( void );
|
||||||
|
//print all memory blocks with label
|
||||||
|
void PrintMemoryLabels( void );
|
||||||
|
//returns the size of the memory block in bytes
|
||||||
|
int MemoryByteSize( void *ptr );
|
||||||
|
//free all allocated memory
|
||||||
|
void DumpMemory( void );
|
3225
l_precomp.c
Normal file
3225
l_precomp.c
Normal file
File diff suppressed because it is too large
Load diff
162
l_precomp.h
Normal file
162
l_precomp.h
Normal file
|
@ -0,0 +1,162 @@
|
||||||
|
/*
|
||||||
|
===========================================================================
|
||||||
|
|
||||||
|
Return to Castle Wolfenstein single player GPL Source Code
|
||||||
|
Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
|
||||||
|
|
||||||
|
This file is part of the Return to Castle Wolfenstein single player GPL Source Code (RTCW SP Source Code).
|
||||||
|
|
||||||
|
RTCW SP Source Code is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
RTCW SP Source Code is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with RTCW SP Source Code. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
In addition, the RTCW SP Source Code is also subject to certain additional terms.
|
||||||
|
You should have received a copy of these additional terms immediately following the
|
||||||
|
terms and conditions of the GNU General Public License which accompanied the RTCW SP
|
||||||
|
Source Code. If not, please request a copy in writing from id Software at the address below.
|
||||||
|
|
||||||
|
If you have questions concerning this license or the applicable additional terms,
|
||||||
|
you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
|
||||||
|
|
||||||
|
===========================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************
|
||||||
|
* name: l_precomp.h
|
||||||
|
*
|
||||||
|
* desc: pre compiler
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef _MAX_PATH
|
||||||
|
#define MAX_PATH MAX_QPATH
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef PATH_SEPERATORSTR
|
||||||
|
#if defined( WIN32 ) | defined( _WIN32 ) | defined( __NT__ ) | defined( __WINDOWS__ ) | defined( __WINDOWS_386__ )
|
||||||
|
#define PATHSEPERATOR_STR "\\"
|
||||||
|
#else
|
||||||
|
#define PATHSEPERATOR_STR "/"
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#ifndef PATH_SEPERATORCHAR
|
||||||
|
#if defined( WIN32 ) | defined( _WIN32 ) | defined( __NT__ ) | defined( __WINDOWS__ ) | defined( __WINDOWS_386__ )
|
||||||
|
#define PATHSEPERATOR_CHAR '\\'
|
||||||
|
#else
|
||||||
|
#define PATHSEPERATOR_CHAR '/'
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#define DEFINE_FIXED 0x0001
|
||||||
|
|
||||||
|
#define BUILTIN_LINE 1
|
||||||
|
#define BUILTIN_FILE 2
|
||||||
|
#define BUILTIN_DATE 3
|
||||||
|
#define BUILTIN_TIME 4
|
||||||
|
#define BUILTIN_STDC 5
|
||||||
|
|
||||||
|
#define INDENT_IF 0x0001
|
||||||
|
#define INDENT_ELSE 0x0002
|
||||||
|
#define INDENT_ELIF 0x0004
|
||||||
|
#define INDENT_IFDEF 0x0008
|
||||||
|
#define INDENT_IFNDEF 0x0010
|
||||||
|
|
||||||
|
//macro definitions
|
||||||
|
typedef struct define_s
|
||||||
|
{
|
||||||
|
char *name; //define name
|
||||||
|
int flags; //define flags
|
||||||
|
int builtin; // > 0 if builtin define
|
||||||
|
int numparms; //number of define parameters
|
||||||
|
token_t *parms; //define parameters
|
||||||
|
token_t *tokens; //macro tokens (possibly containing parm tokens)
|
||||||
|
struct define_s *next; //next defined macro in a list
|
||||||
|
struct define_s *hashnext; //next define in the hash chain
|
||||||
|
} define_t;
|
||||||
|
|
||||||
|
//indents
|
||||||
|
//used for conditional compilation directives:
|
||||||
|
//#if, #else, #elif, #ifdef, #ifndef
|
||||||
|
typedef struct indent_s
|
||||||
|
{
|
||||||
|
int type; //indent type
|
||||||
|
int skip; //true if skipping current indent
|
||||||
|
script_t *script; //script the indent was in
|
||||||
|
struct indent_s *next; //next indent on the indent stack
|
||||||
|
} indent_t;
|
||||||
|
|
||||||
|
//source file
|
||||||
|
typedef struct source_s
|
||||||
|
{
|
||||||
|
char filename[_MAX_PATH]; //file name of the script
|
||||||
|
char includepath[_MAX_PATH]; //path to include files
|
||||||
|
punctuation_t *punctuations; //punctuations to use
|
||||||
|
script_t *scriptstack; //stack with scripts of the source
|
||||||
|
token_t *tokens; //tokens to read first
|
||||||
|
define_t *defines; //list with macro definitions
|
||||||
|
define_t **definehash; //hash chain with defines
|
||||||
|
indent_t *indentstack; //stack with indents
|
||||||
|
int skip; // > 0 if skipping conditional code
|
||||||
|
token_t token; //last read token
|
||||||
|
} source_t;
|
||||||
|
|
||||||
|
|
||||||
|
//read a token from the source
|
||||||
|
int PC_ReadToken( source_t *source, token_t *token );
|
||||||
|
//expect a certain token
|
||||||
|
int PC_ExpectTokenString( source_t *source, char *string );
|
||||||
|
//expect a certain token type
|
||||||
|
int PC_ExpectTokenType( source_t *source, int type, int subtype, token_t *token );
|
||||||
|
//expect a token
|
||||||
|
int PC_ExpectAnyToken( source_t *source, token_t *token );
|
||||||
|
//returns true when the token is available
|
||||||
|
int PC_CheckTokenString( source_t *source, char *string );
|
||||||
|
//returns true an reads the token when a token with the given type is available
|
||||||
|
int PC_CheckTokenType( source_t *source, int type, int subtype, token_t *token );
|
||||||
|
//skip tokens until the given token string is read
|
||||||
|
int PC_SkipUntilString( source_t *source, char *string );
|
||||||
|
//unread the last token read from the script
|
||||||
|
void PC_UnreadLastToken( source_t *source );
|
||||||
|
//unread the given token
|
||||||
|
void PC_UnreadToken( source_t *source, token_t *token );
|
||||||
|
//read a token only if on the same line, lines are concatenated with a slash
|
||||||
|
int PC_ReadLine( source_t *source, token_t *token );
|
||||||
|
//returns true if there was a white space in front of the token
|
||||||
|
int PC_WhiteSpaceBeforeToken( token_t *token );
|
||||||
|
//add a define to the source
|
||||||
|
int PC_AddDefine( source_t *source, char *string );
|
||||||
|
//add a globals define that will be added to all opened sources
|
||||||
|
int PC_AddGlobalDefine( char *string );
|
||||||
|
//remove the given global define
|
||||||
|
int PC_RemoveGlobalDefine( char *name );
|
||||||
|
//remove all globals defines
|
||||||
|
void PC_RemoveAllGlobalDefines( void );
|
||||||
|
//add builtin defines
|
||||||
|
void PC_AddBuiltinDefines( source_t *source );
|
||||||
|
//set the source include path
|
||||||
|
void PC_SetIncludePath( source_t *source, char *path );
|
||||||
|
//set the punction set
|
||||||
|
void PC_SetPunctuations( source_t *source, punctuation_t *p );
|
||||||
|
//load a source file
|
||||||
|
source_t *LoadSourceFile( char *filename );
|
||||||
|
//load a source from memory
|
||||||
|
source_t *LoadSourceMemory( char *ptr, int length, char *name );
|
||||||
|
//free the given source
|
||||||
|
void FreeSource( source_t *source );
|
||||||
|
//print a source error
|
||||||
|
void QDECL SourceError( source_t *source, char *str, ... );
|
||||||
|
//print a source warning
|
||||||
|
void QDECL SourceWarning( source_t *source, char *str, ... );
|
||||||
|
|
1423
l_script.c
Normal file
1423
l_script.c
Normal file
File diff suppressed because it is too large
Load diff
270
l_script.h
Normal file
270
l_script.h
Normal file
|
@ -0,0 +1,270 @@
|
||||||
|
/*
|
||||||
|
===========================================================================
|
||||||
|
|
||||||
|
Return to Castle Wolfenstein single player GPL Source Code
|
||||||
|
Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
|
||||||
|
|
||||||
|
This file is part of the Return to Castle Wolfenstein single player GPL Source Code (RTCW SP Source Code).
|
||||||
|
|
||||||
|
RTCW SP Source Code is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
RTCW SP Source Code is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with RTCW SP Source Code. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
In addition, the RTCW SP Source Code is also subject to certain additional terms.
|
||||||
|
You should have received a copy of these additional terms immediately following the
|
||||||
|
terms and conditions of the GNU General Public License which accompanied the RTCW SP
|
||||||
|
Source Code. If not, please request a copy in writing from id Software at the address below.
|
||||||
|
|
||||||
|
If you have questions concerning this license or the applicable additional terms,
|
||||||
|
you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
|
||||||
|
|
||||||
|
===========================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************
|
||||||
|
* name: l_script.h
|
||||||
|
*
|
||||||
|
* desc: lexicographical parser
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
// Ridah, can't get it to compile without this
|
||||||
|
#ifndef QDECL
|
||||||
|
|
||||||
|
// for windows fastcall option
|
||||||
|
#define QDECL
|
||||||
|
//======================= WIN32 DEFINES =================================
|
||||||
|
#ifdef WIN32
|
||||||
|
#undef QDECL
|
||||||
|
#define QDECL __cdecl
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
// done.
|
||||||
|
|
||||||
|
//undef if binary numbers of the form 0b... or 0B... are not allowed
|
||||||
|
#define BINARYNUMBERS
|
||||||
|
//undef if not using the token.intvalue and token.floatvalue
|
||||||
|
#define NUMBERVALUE
|
||||||
|
//use dollar sign also as punctuation
|
||||||
|
#define DOLLAR
|
||||||
|
|
||||||
|
//maximum token length
|
||||||
|
#define MAX_TOKEN 1024
|
||||||
|
//maximum path length
|
||||||
|
#ifndef MAX_QPATH
|
||||||
|
#define MAX_QPATH 64
|
||||||
|
#endif
|
||||||
|
#ifndef _MAX_PATH
|
||||||
|
#define _MAX_PATH MAX_QPATH
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//script flags
|
||||||
|
#define SCFL_NOERRORS 0x0001
|
||||||
|
#define SCFL_NOWARNINGS 0x0002
|
||||||
|
#define SCFL_NOSTRINGWHITESPACES 0x0004
|
||||||
|
#define SCFL_NOSTRINGESCAPECHARS 0x0008
|
||||||
|
#define SCFL_PRIMITIVE 0x0010
|
||||||
|
#define SCFL_NOBINARYNUMBERS 0x0020
|
||||||
|
#define SCFL_NONUMBERVALUES 0x0040
|
||||||
|
|
||||||
|
//token types
|
||||||
|
#define TT_STRING 1 // string
|
||||||
|
#define TT_LITERAL 2 // literal
|
||||||
|
#define TT_NUMBER 3 // number
|
||||||
|
#define TT_NAME 4 // name
|
||||||
|
#define TT_PUNCTUATION 5 // punctuation
|
||||||
|
|
||||||
|
//string sub type
|
||||||
|
//---------------
|
||||||
|
// the length of the string
|
||||||
|
//literal sub type
|
||||||
|
//----------------
|
||||||
|
// the ASCII code of the literal
|
||||||
|
//number sub type
|
||||||
|
//---------------
|
||||||
|
#define TT_DECIMAL 0x0008 // decimal number
|
||||||
|
#define TT_HEX 0x0100 // hexadecimal number
|
||||||
|
#define TT_OCTAL 0x0200 // octal number
|
||||||
|
#ifdef BINARYNUMBERS
|
||||||
|
#define TT_BINARY 0x0400 // binary number
|
||||||
|
#endif //BINARYNUMBERS
|
||||||
|
#define TT_FLOAT 0x0800 // floating point number
|
||||||
|
#define TT_INTEGER 0x1000 // integer number
|
||||||
|
#define TT_LONG 0x2000 // long number
|
||||||
|
#define TT_UNSIGNED 0x4000 // unsigned number
|
||||||
|
//punctuation sub type
|
||||||
|
//--------------------
|
||||||
|
#define P_RSHIFT_ASSIGN 1
|
||||||
|
#define P_LSHIFT_ASSIGN 2
|
||||||
|
#define P_PARMS 3
|
||||||
|
#define P_PRECOMPMERGE 4
|
||||||
|
|
||||||
|
#define P_LOGIC_AND 5
|
||||||
|
#define P_LOGIC_OR 6
|
||||||
|
#define P_LOGIC_GEQ 7
|
||||||
|
#define P_LOGIC_LEQ 8
|
||||||
|
#define P_LOGIC_EQ 9
|
||||||
|
#define P_LOGIC_UNEQ 10
|
||||||
|
|
||||||
|
#define P_MUL_ASSIGN 11
|
||||||
|
#define P_DIV_ASSIGN 12
|
||||||
|
#define P_MOD_ASSIGN 13
|
||||||
|
#define P_ADD_ASSIGN 14
|
||||||
|
#define P_SUB_ASSIGN 15
|
||||||
|
#define P_INC 16
|
||||||
|
#define P_DEC 17
|
||||||
|
|
||||||
|
#define P_BIN_AND_ASSIGN 18
|
||||||
|
#define P_BIN_OR_ASSIGN 19
|
||||||
|
#define P_BIN_XOR_ASSIGN 20
|
||||||
|
#define P_RSHIFT 21
|
||||||
|
#define P_LSHIFT 22
|
||||||
|
|
||||||
|
#define P_POINTERREF 23
|
||||||
|
#define P_CPP1 24
|
||||||
|
#define P_CPP2 25
|
||||||
|
#define P_MUL 26
|
||||||
|
#define P_DIV 27
|
||||||
|
#define P_MOD 28
|
||||||
|
#define P_ADD 29
|
||||||
|
#define P_SUB 30
|
||||||
|
#define P_ASSIGN 31
|
||||||
|
|
||||||
|
#define P_BIN_AND 32
|
||||||
|
#define P_BIN_OR 33
|
||||||
|
#define P_BIN_XOR 34
|
||||||
|
#define P_BIN_NOT 35
|
||||||
|
|
||||||
|
#define P_LOGIC_NOT 36
|
||||||
|
#define P_LOGIC_GREATER 37
|
||||||
|
#define P_LOGIC_LESS 38
|
||||||
|
|
||||||
|
#define P_REF 39
|
||||||
|
#define P_COMMA 40
|
||||||
|
#define P_SEMICOLON 41
|
||||||
|
#define P_COLON 42
|
||||||
|
#define P_QUESTIONMARK 43
|
||||||
|
|
||||||
|
#define P_PARENTHESESOPEN 44
|
||||||
|
#define P_PARENTHESESCLOSE 45
|
||||||
|
#define P_BRACEOPEN 46
|
||||||
|
#define P_BRACECLOSE 47
|
||||||
|
#define P_SQBRACKETOPEN 48
|
||||||
|
#define P_SQBRACKETCLOSE 49
|
||||||
|
#define P_BACKSLASH 50
|
||||||
|
|
||||||
|
#define P_PRECOMP 51
|
||||||
|
#define P_DOLLAR 52
|
||||||
|
//name sub type
|
||||||
|
//-------------
|
||||||
|
// the length of the name
|
||||||
|
|
||||||
|
//punctuation
|
||||||
|
typedef struct punctuation_s
|
||||||
|
{
|
||||||
|
char *p; //punctuation character(s)
|
||||||
|
int n; //punctuation indication
|
||||||
|
struct punctuation_s *next; //next punctuation
|
||||||
|
} punctuation_t;
|
||||||
|
|
||||||
|
//token
|
||||||
|
typedef struct token_s
|
||||||
|
{
|
||||||
|
char string[MAX_TOKEN]; //available token
|
||||||
|
int type; //last read token type
|
||||||
|
int subtype; //last read token sub type
|
||||||
|
#ifdef NUMBERVALUE
|
||||||
|
unsigned long int intvalue; //integer value
|
||||||
|
long double floatvalue; //floating point value
|
||||||
|
#endif //NUMBERVALUE
|
||||||
|
char *whitespace_p; //start of white space before token
|
||||||
|
char *endwhitespace_p; //start of white space before token
|
||||||
|
int line; //line the token was on
|
||||||
|
int linescrossed; //lines crossed in white space
|
||||||
|
struct token_s *next; //next token in chain
|
||||||
|
} token_t;
|
||||||
|
|
||||||
|
//script file
|
||||||
|
typedef struct script_s
|
||||||
|
{
|
||||||
|
char filename[_MAX_PATH]; //file name of the script
|
||||||
|
char *buffer; //buffer containing the script
|
||||||
|
char *script_p; //current pointer in the script
|
||||||
|
char *end_p; //pointer to the end of the script
|
||||||
|
char *lastscript_p; //script pointer before reading token
|
||||||
|
char *whitespace_p; //begin of the white space
|
||||||
|
char *endwhitespace_p; //end of the white space
|
||||||
|
int length; //length of the script in bytes
|
||||||
|
int line; //current line in script
|
||||||
|
int lastline; //line before reading token
|
||||||
|
int tokenavailable; //set by UnreadLastToken
|
||||||
|
int flags; //several script flags
|
||||||
|
punctuation_t *punctuations; //the punctuations used in the script
|
||||||
|
punctuation_t **punctuationtable;
|
||||||
|
token_t token; //available token
|
||||||
|
struct script_s *next; //next script in a chain
|
||||||
|
} script_t;
|
||||||
|
|
||||||
|
//read a token from the script
|
||||||
|
int PS_ReadToken( script_t *script, token_t *token );
|
||||||
|
//expect a certain token
|
||||||
|
int PS_ExpectTokenString( script_t *script, char *string );
|
||||||
|
//expect a certain token type
|
||||||
|
int PS_ExpectTokenType( script_t *script, int type, int subtype, token_t *token );
|
||||||
|
//expect a token
|
||||||
|
int PS_ExpectAnyToken( script_t *script, token_t *token );
|
||||||
|
//returns true when the token is available
|
||||||
|
int PS_CheckTokenString( script_t *script, char *string );
|
||||||
|
//returns true an reads the token when a token with the given type is available
|
||||||
|
int PS_CheckTokenType( script_t *script, int type, int subtype, token_t *token );
|
||||||
|
//skip tokens until the given token string is read
|
||||||
|
int PS_SkipUntilString( script_t *script, char *string );
|
||||||
|
//unread the last token read from the script
|
||||||
|
void PS_UnreadLastToken( script_t *script );
|
||||||
|
//unread the given token
|
||||||
|
void PS_UnreadToken( script_t *script, token_t *token );
|
||||||
|
//returns the next character of the read white space, returns NULL if none
|
||||||
|
char PS_NextWhiteSpaceChar( script_t *script );
|
||||||
|
//remove any leading and trailing double quotes from the token
|
||||||
|
void StripDoubleQuotes( char *string );
|
||||||
|
//remove any leading and trailing single quotes from the token
|
||||||
|
void StripSingleQuotes( char *string );
|
||||||
|
//read a possible signed integer
|
||||||
|
signed long int ReadSignedInt( script_t *script );
|
||||||
|
//read a possible signed floating point number
|
||||||
|
long double ReadSignedFloat( script_t *script );
|
||||||
|
//set an array with punctuations, NULL restores default C/C++ set
|
||||||
|
void SetScriptPunctuations( script_t *script, punctuation_t *p );
|
||||||
|
//set script flags
|
||||||
|
void SetScriptFlags( script_t *script, int flags );
|
||||||
|
//get script flags
|
||||||
|
int GetScriptFlags( script_t *script );
|
||||||
|
//reset a script
|
||||||
|
void ResetScript( script_t *script );
|
||||||
|
//returns true if at the end of the script
|
||||||
|
int EndOfScript( script_t *script );
|
||||||
|
//returns a pointer to the punctuation with the given number
|
||||||
|
char *PunctuationFromNum( script_t *script, int num );
|
||||||
|
//load a script from the given file at the given offset with the given length
|
||||||
|
script_t *LoadScriptFile( char *filename );
|
||||||
|
//load a script from the given memory with the given length
|
||||||
|
script_t *LoadScriptMemory( char *ptr, int length, char *name );
|
||||||
|
//free a script
|
||||||
|
void FreeScript( script_t *script );
|
||||||
|
//print a script error with filename and line number
|
||||||
|
void QDECL ScriptError( script_t *script, char *str, ... );
|
||||||
|
//print a script warning with filename and line number
|
||||||
|
void QDECL ScriptWarning( script_t *script, char *str, ... );
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue