Merged changes from sfall 4.2.1 modderspack:

* Added -m<macro[=val]> and -I<path> options
* Changed the search order for Include files for the parser DLL.
* Removed embedded mcpp from Win2k build.
This commit is contained in:
NovaRain
2019-11-14 12:14:46 +08:00
parent 9b63b1886a
commit d93e812f9f
7 changed files with 639 additions and 566 deletions
+52 -18
View File
@@ -7,10 +7,15 @@
#include "parse.h" #include "parse.h"
#include <io.h> #include <io.h>
#ifdef BUILDING_DLL
int optimize = 0;
#else
int optimize = 1; // default for exe
#endif
int noinputwait = 0; int noinputwait = 0;
int warnings = 1; int warnings = 1;
int backwardcompat = 0; int backwardcompat = 0;
int optimize = 0;
int debug = 0; int debug = 0;
int preprocess_fullpath = 0; int preprocess_fullpath = 0;
int dumpTree = 0; int dumpTree = 0;
@@ -32,14 +37,19 @@ FILE *parseroutput;
static void PrintLogo() { static void PrintLogo() {
parseOutput("Startreck scripting language compiler (Fallout 2 sfall edition 4.2)\n\n" parseOutput("Startreck scripting language compiler (Fallout 2 sfall edition 4.2)\n\n"
#ifndef WIN2K
"Preprocessing handled by mcpp 2.7.2\n" "Preprocessing handled by mcpp 2.7.2\n"
"Copyright (c) 1998, 2002-2008 Kiyoshi Matsui <kmatsui@t3.rim.or.jp>\n" "Copyright (c) 1998, 2002-2008 Kiyoshi Matsui <kmatsui@t3.rim.or.jp>\n"
"All rights reserved.\n\n"); "All rights reserved.\n\n"
#else
"Win2K/Lite version (no built-in preprocessor)\n\n"
#endif
);
} }
extern int warn_level; //the mcpp warning level extern int warn_level; //the mcpp warning level
extern int mcpp_lib_main(FILE *fin, FILE *fout, const char* in_file, const char* dir); extern int mcpp_lib_main(FILE *fin, FILE *fout, const char* in_file, const char* dir, const char* def, const char* include_dir);
//extern void set_a_dir(const char * dirname); extern void mcpp_add_include_dir(char*);
#ifndef BUILDING_DLL #ifndef BUILDING_DLL
int main(int argc, char **argv) int main(int argc, char **argv)
@@ -52,6 +62,8 @@ int main(int argc, char **argv)
int preprocess=0; int preprocess=0;
int onlypreprocess=0; int onlypreprocess=0;
char* includeDir = NULL, *defMacro = NULL;
if (argc < 2) { if (argc < 2) {
PrintLogo(); PrintLogo();
parseOutput("Usage: compile {switches} filename [-o outputname] [filename [..]]\n"); parseOutput("Usage: compile {switches} filename [-o outputname] [filename [..]]\n");
@@ -59,13 +71,19 @@ int main(int argc, char **argv)
parseOutput(" -n no warnings\n"); parseOutput(" -n no warnings\n");
parseOutput(" -b use backward compatibility mode\n"); parseOutput(" -b use backward compatibility mode\n");
parseOutput(" -l no logo\n"); parseOutput(" -l no logo\n");
#ifndef WIN2K
parseOutput(" -p preprocess\n"); parseOutput(" -p preprocess\n");
parseOutput(" -P preprocess only. (Don't generate .int)\n"); parseOutput(" -P preprocess only. (Don't generate .int)\n");
parseOutput(" -F write full file paths in #line directives\n"); parseOutput(" -F write full file paths in #line directives\n");
parseOutput(" -O<level> optimize (0 - none, 1 - only remove unreferenced globals, 2 - full, 3 - full+experimental, don't use!)\n"); #endif
parseOutput(" -O<level> optimize (0 - none, 1 - only remove unreferenced globals (default), 2 - full, 3 - full+experimental, don't use!)\n");
parseOutput(" -d show debug info\n"); parseOutput(" -d show debug info\n");
parseOutput(" -s enable short-circuit evaluation for boolean operators (AND, OR)\n"); parseOutput(" -s enable short-circuit evaluation for boolean operators (AND, OR)\n");
parseOutput(" -D dump abstract syntax tree after optimizations\n"); parseOutput(" -D dump abstract syntax tree after optimizations\n");
#ifndef WIN2K
parseOutput(" -m<macro[=val]> define a macro named \"macro\" for conditional compilation\n");
parseOutput(" -I<path> specify an additional directory to search for include files\n");
#endif
return 1; return 1;
} }
@@ -87,13 +105,14 @@ int main(int argc, char **argv)
case 'b': case 'b':
backwardcompat = 1; backwardcompat = 1;
break; break;
case 'l': case 'l':
nologo=1; nologo=1;
break; break;
case 'O': case 'O':
if (strlen(argv[1]) == 2) optimize = 2; if (strlen(argv[1]) == 2) optimize = 2; // full
else optimize = atoi(&argv[1][2]); else optimize = atoi(&argv[1][2]);
break; break;
#ifndef WIN2K
case 'P': case 'P':
onlypreprocess = 1; onlypreprocess = 1;
case 'p': case 'p':
@@ -102,12 +121,24 @@ int main(int argc, char **argv)
case 'F': case 'F':
preprocess_fullpath = 1; preprocess_fullpath = 1;
break; break;
#endif
case 'D': case 'D':
dumpTree = 1; dumpTree = 1;
break; break;
case 's': case 's':
shortCircuit = 1; shortCircuit = 1;
break; break;
#ifndef WIN2K
case 'm':
defMacro = &argv[1][2];
break;
case 'I':
if (!includeDir)
includeDir = &argv[1][2];
else
mcpp_add_include_dir(&argv[1][2]);
break;
#endif
default: default:
parseOutput("Unknown option %c\n", argv[1][1]); parseOutput("Unknown option %c\n", argv[1][1]);
} }
@@ -115,7 +146,7 @@ int main(int argc, char **argv)
argv++; argv++;
argc--; argc--;
} }
// disabled - Fakels
/*if(backwardcompat&&(optimize||preprocess)) { /*if(backwardcompat&&(optimize||preprocess)) {
parseOutput("Invalid option combination; cannot run preprocess or optimization passes in backward compatibility mode\n"); parseOutput("Invalid option combination; cannot run preprocess or optimization passes in backward compatibility mode\n");
return -1; return -1;
@@ -124,7 +155,10 @@ int main(int argc, char **argv)
if(!nologo) PrintLogo(); if(!nologo) PrintLogo();
compilerErrorTotal = 0; compilerErrorTotal = 0;
#ifndef WIN2K
if (defMacro) parseOutput("Define macro: %s\n", defMacro);
if (includeDir) parseOutput("Set include directory: %s\n", includeDir);
#endif
while(argv[1]) { while(argv[1]) {
file = argv[1]; file = argv[1];
argv++; argv++;
@@ -173,7 +207,7 @@ int main(int argc, char **argv)
} }
} }
} }
#ifndef WIN2K
if(preprocess) { if(preprocess) {
FILE *newfile; FILE *newfile;
unsigned int letters; unsigned int letters;
@@ -190,7 +224,7 @@ int main(int argc, char **argv)
newfile=fopen(tmpbuf, "w+DT"); newfile=fopen(tmpbuf, "w+DT");
//#endif //#endif
} }
if(mcpp_lib_main(foo.file, newfile, buf.name, buf.name)) { if(mcpp_lib_main(foo.file, newfile, buf.name, buf.name, defMacro, includeDir)) {
parseOutput("*** An error occured during preprocessing of %s ***\n", buf.name); parseOutput("*** An error occured during preprocessing of %s ***\n", buf.name);
return 1; return 1;
} }
@@ -198,6 +232,7 @@ int main(int argc, char **argv)
rewind(newfile); rewind(newfile);
foo.file=newfile; foo.file=newfile;
} }
#endif
if(!onlypreprocess) { if(!onlypreprocess) {
parse(&foo, name); parse(&foo, name);
freeCurrentProgram(); freeCurrentProgram();
@@ -214,8 +249,7 @@ int main(int argc, char **argv)
getchar(); getchar();
return 1; return 1;
} }
} } else {
else {
parseOutput("Warning: %s not found\n", file); parseOutput("Warning: %s not found\n", file);
} }
} }
@@ -226,8 +260,8 @@ int main(int argc, char **argv)
#ifdef BUILDING_DLL #ifdef BUILDING_DLL
static int inited=0; static int inited=0;
// old parser
int _stdcall parse_main(const char *filePath, const char* origPath, const char* dir, int backMode) { int _stdcall parse_main(const char *filePath, const char* origPath, const char* dir/*, const char* def, const char* include_dir, int backMode*/) {
InputStream foo; InputStream foo;
char tmpbuf[260]; char tmpbuf[260];
//char cwd[1024]; //char cwd[1024];
@@ -239,12 +273,12 @@ int _stdcall parse_main(const char *filePath, const char* origPath, const char*
FreeFileNames(); FreeFileNames();
inited=0; inited=0;
} }
/*
if (backMode) { if (backMode) {
backwardcompat = 1; backwardcompat = 1;
lexClear(); lexClear();
} }
*/
foo.name=AddFileName(origPath); foo.name=AddFileName(origPath);
foo.file = fopen(filePath, "r"); foo.file = fopen(filePath, "r");
@@ -258,7 +292,7 @@ int _stdcall parse_main(const char *filePath, const char* origPath, const char*
compilerErrorTotal = 0; compilerErrorTotal = 0;
compilerSyntaxError = 0; compilerSyntaxError = 0;
preprocess_fullpath = 1; preprocess_fullpath = 1;
if (mcpp_lib_main(foo.file, newfile, origPath, dir)) { if (mcpp_lib_main(foo.file, newfile, origPath, dir, NULL, NULL)) { // prevent crash in old Script Editor - NR
fclose(foo.file); fclose(foo.file);
fclose(newfile); fclose(newfile);
if (parseroutput) if (parseroutput)
+1 -1
View File
@@ -454,7 +454,7 @@ extern int mcpp_fputs(const char *s, OUTDEST od);
extern int mcpp_fprintf( OUTDEST od, const char *format, ...); extern int mcpp_fprintf( OUTDEST od, const char *format, ...);
/* system.c */ /* system.c */
extern void do_options(); extern void do_options(const char* dir, const char* def, const char* include_dir, const char* second_dir);
/* Process command line args */ /* Process command line args */
extern void init_sys_macro( void); extern void init_sys_macro( void);
/* Define system-specific macro */ /* Define system-specific macro */
+10 -2
View File
@@ -250,6 +250,12 @@ static void devide_line( char * out);
static void put_a_line( char * out); static void put_a_line( char * out);
/* Put out the processed line */ /* Put out the processed line */
static char* second_include_dir = NULL;
void mcpp_add_include_dir(char* dir) /* added - Fakels */
{
second_include_dir = dir;
}
static void init_main( void) static void init_main( void)
/* Initialize global variables on re-entering. */ /* Initialize global variables on re-entering. */
{ {
@@ -274,7 +280,9 @@ int mcpp_lib_main
FILE *fin, FILE *fin,
FILE *fout, FILE *fout,
const char* in_file, const char* in_file,
const char* dir const char* dir,
const char* def,
const char* include_dir
) )
{ {
const char * stdin_name = "<stdin>"; const char * stdin_name = "<stdin>";
@@ -303,7 +311,7 @@ int mcpp_lib_main
inc_dirp = &null; /* Initialize to current (null) directory */ inc_dirp = &null; /* Initialize to current (null) directory */
cur_fname = cur_fullname = "(predefined)"; /* For predefined macros */ cur_fname = cur_fullname = "(predefined)"; /* For predefined macros */
init_defines(); /* Predefine macros */ init_defines(); /* Predefine macros */
do_options(dir); /* Command line options */ do_options(dir, def, include_dir, second_include_dir); /* Command line options */
init_sys_macro(); /* Initialize system-specific macros */ init_sys_macro(); /* Initialize system-specific macros */
add_file( fp_in, NULL, in_file, in_file, FALSE); add_file( fp_in, NULL, in_file, in_file, FALSE);
+34 -12
View File
@@ -221,7 +221,10 @@ void init_system( void)
#define OPTLISTLEN 80 #define OPTLISTLEN 80
void do_options( void do_options(
const char* dir const char* dir,
const char* def,
const char* include_dir,
const char* second_dir
) )
/* /*
* Process command line arguments, called only at MCPP startup. * Process command line arguments, called only at MCPP startup.
@@ -245,8 +248,11 @@ void do_options(
sprintf( cur_work_dir + strlen( cur_work_dir), "%c%c", PATH_DELIM, EOS); sprintf( cur_work_dir + strlen( cur_work_dir), "%c%c", PATH_DELIM, EOS);
/* Append trailing path-delimiter */ /* Append trailing path-delimiter */
if (dir) if (dir) set_a_dir(dir);
set_a_dir(dir); if (include_dir) set_a_dir(include_dir);
if (second_dir) set_a_dir(second_dir);
/* define macros */
if (def) def_list[def_cnt++] = (char*)def;
/* Check consistency of specified options, set some variables */ /* Check consistency of specified options, set some variables */
chk_opts( sflag, trad); chk_opts( sflag, trad);
@@ -898,7 +904,13 @@ static int open_include(
has_dir = has_dir_src || has_dir_fname has_dir = has_dir_src || has_dir_fname
|| (**(infile->dirp) != EOS); || (**(infile->dirp) != EOS);
} }
#ifdef BUILDING_DLL /* Reordered search include files for DLL (Fakels) */
if (full_path) {
if (open_file( &null, NULL, filename, FALSE, FALSE, FALSE))
return TRUE;
return FALSE;
}
#else
if ((searchlocal && ((search_rule & CURRENT) || !has_dir)) || full_path) { if ((searchlocal && ((search_rule & CURRENT) || !has_dir)) || full_path) {
/* /*
* Look in local directory first. * Look in local directory first.
@@ -910,7 +922,7 @@ static int open_include(
if (full_path) if (full_path)
return FALSE; return FALSE;
} }
#endif
if (searchlocal && (search_rule & SOURCE) && has_dir) { if (searchlocal && (search_rule & SOURCE) && has_dir) {
/* /*
* Look in local directory of source file. * Look in local directory of source file.
@@ -924,6 +936,16 @@ static int open_include(
if (search_dir( filename, searchlocal, next)) if (search_dir( filename, searchlocal, next))
return TRUE; return TRUE;
#ifdef BUILDING_DLL /* Reordered search include files for DLL (Fakels) */
if ((searchlocal && ((search_rule & CURRENT) || !has_dir))) {
/*
* Look in local directory.
* Try to open filename relative to the "current directory".
*/
if (open_file( &null, NULL, filename, searchlocal, FALSE, FALSE))
return TRUE;
}
#endif
return FALSE; return FALSE;
} }
@@ -1219,13 +1241,13 @@ static void cur_file(
if (sharp_file) { /* Main input file */ if (sharp_file) { /* Main input file */
name = file->filename; name = file->filename;
} else if (str_eq( file->filename, file->real_fname)) { } else if (str_eq( file->filename, file->real_fname)) {
// sfall: added // sfall: added
if (preprocess_fullpath) { // if (preprocess_fullpath) { //
name = file->full_fname; // name = file->full_fname; //
} else { // end of added } else { // end of added
sprintf( work_buf, "%s%s", *(file->dirp), cur_fname); sprintf( work_buf, "%s%s", *(file->dirp), cur_fname);
name = work_buf; name = work_buf;
} }
} else { /* Changed by '#line fname' directive */ } else { /* Changed by '#line fname' directive */
name = file->filename; name = file->filename;
} }
View File
+540 -527
View File
File diff suppressed because it is too large Load Diff
+2 -6
View File
@@ -124,7 +124,7 @@
<ClCompile> <ClCompile>
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild> <MinimalRebuild>false</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks> <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary> <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<PrecompiledHeader> <PrecompiledHeader>
@@ -145,10 +145,6 @@
<ModuleDefinitionFile> <ModuleDefinitionFile>
</ModuleDefinitionFile> </ModuleDefinitionFile>
</Link> </Link>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile> <ClCompile>
@@ -191,7 +187,7 @@
<ClCompile> <ClCompile>
<Optimization>Full</Optimization> <Optimization>Full</Optimization>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;WIN2K;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary> <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<PrecompiledHeader> <PrecompiledHeader>
</PrecompiledHeader> </PrecompiledHeader>