void AutoCompile() { bool save = compilercfg.OnlyCompileUpdatedScripts; compilercfg.OnlyCompileUpdatedScripts = compilercfg.UpdateOnlyOnAutoCompile; if (compilercfg.ThreadedCompilation) { vector<string> files; recurse_compile( normalized_dir_form( compilercfg.PolScriptRoot ),&files ); for( size_t i = 0; i < packages.size(); ++i ) { const Package* pkg = packages[i]; recurse_compile( normalized_dir_form( pkg->dir() ), &files ); } parallel_compile(files); } else { recurse_compile( normalized_dir_form( compilercfg.PolScriptRoot ),NULL ); for( size_t i = 0; i < packages.size(); ++i ) { const Package* pkg = packages[i]; recurse_compile( normalized_dir_form( pkg->dir() ), NULL ); } } compilercfg.OnlyCompileUpdatedScripts = save; }
int xmain( int argc, char* argv[] ) { StoreCmdArgs( argc, argv ); if (FindArg2( "uodata=" ) != NULL) { config.uo_datafile_root = FindArg2( "uodata=" ); config.uo_datafile_root = normalized_dir_form( config.uo_datafile_root ); } else { cout << "Reading pol.cfg." << endl; ConfigFile cf( "pol.cfg" ); ConfigElem elem; cf.readraw( elem ); config.uo_datafile_root = elem.remove_string( "UoDataFileRoot" ); config.uo_datafile_root = normalized_dir_form( config.uo_datafile_root ); unsigned short max_tile = elem.remove_ushort( "MaxTileID", 0x3FFF ); if (max_tile != 0x3FFF && max_tile != 0x7FFF) config.max_tile_id = 0x3FFF; else config.max_tile_id = max_tile; } string main_cfg = "uoconvert.cfg"; if (FileExists( main_cfg.c_str() ) ) { string temp; ConfigElem elem; cout << "Reading uoconvert.cfg." << endl; ConfigFile cf_main( main_cfg.c_str() ); while( cf_main.read( elem ) ) { if (elem.type_is( "MultiTypes" )) { temp = elem.remove_string( "Boats" ); ISTRINGSTREAM is_boats( temp ); string graphicnum; while (is_boats >> graphicnum) BoatTypes.insert(strtoul(graphicnum.c_str(),NULL,0)); temp = elem.remove_string( "Houses" ); ISTRINGSTREAM is_houses( temp ); while (is_houses >> graphicnum) HouseTypes.insert(strtoul(graphicnum.c_str(),NULL,0)); temp = elem.remove_string( "Stairs" ); ISTRINGSTREAM is_stairs( temp ); while (is_stairs >> graphicnum) StairTypes.insert(strtoul(graphicnum.c_str(),NULL,0)); } else if (elem.type_is( "LOSOptions" ))
void CompilerConfig::SetDefaults() { const char* tmp; tmp = getenv( "ECOMPILE_PATH_EM" ); ModuleDirectory = tmp ? normalized_dir_form(tmp) : xmain_exedir; tmp = getenv( "ECOMPILE_PATH_INC" ); IncludeDirectory = tmp ? normalized_dir_form(tmp) : xmain_exedir; PolScriptRoot = IncludeDirectory; DisplayUpToDateScripts = true; }
BObjectImp* FileAccessExecutorModule::mf_ListDirectory() { const String* dirname; const String* extension; short listdirs; if ((!getStringParam( 0, dirname )) || (!getStringParam( 1, extension )) || (!getParam( 2, listdirs )) ) return new BError( "Invalid parameter type" ); const Package* outpkg; string path; if (!pkgdef_split( dirname->value(), exec.prog()->pkg, &outpkg, &path )) return new BError( "Error in dirname descriptor" ); if (path.find( ".." ) != string::npos) return new BError( "No parent path traversal please." ); if (outpkg != NULL) path = outpkg->dir() + path; path = normalized_dir_form(path); if ( !IsDirectory( path.c_str() ) ) return new BError( "Directory not found." ); bool asterisk = false; bool nofiles = false; if ( extension->getStringRep().find('*',0) != string::npos) asterisk = true; else if ( extension->length() == 0 ) nofiles = true; ObjArray* arr = new ObjArray; for( DirList dl( path.c_str() ); !dl.at_end(); dl.next() ) { string name = dl.name(); if (name[0] == '.') continue; if ( IsDirectory( (path+name).c_str() ) ) { if ( listdirs == 0 ) continue; } else if ( nofiles ) continue; else if (!asterisk) { string::size_type extensionPointPos = name.rfind('.'); if (extensionPointPos == string::npos) continue; if (name.substr(extensionPointPos + 1) != extension->value()) continue; } arr->addElement( new String(name) ); } return arr; }
std::string curdir() { #ifdef MAX_PATH char cdir[_MAX_PATH]; #else char cdir[256]; #endif if ( getcwd( cdir, sizeof cdir ) == NULL ) return normalized_dir_form( cdir ); return ""; }
BObjectImp* FileAccessExecutorModule::mf_CreateDirectory() { const String* dirname; if (!getStringParam( 0, dirname )) return new BError( "Invalid parameter type" ); const Package* outpkg; string path; if (!pkgdef_split( dirname->value(), exec.prog()->pkg, &outpkg, &path )) return new BError( "Error in dirname descriptor" ); if (path.find( ".." ) != string::npos) return new BError( "No parent path traversal please." ); if (outpkg != NULL) path = outpkg->dir() + path; path = normalized_dir_form(path); if ( IsDirectory( path.c_str() ) ) return new BError( "Directory already exists." ); int res = make_dir(path.c_str()); if (res != 0) return new BError( "Could not create directory." ); return new BLong(1); }
void CompilerConfig::Read( const string& path ) { ConfigFile cf( path.c_str() ); ConfigElem elem; cf.readraw( elem ); PackageRoot.clear(); IncludeDirectory.clear(); string tmp; while (elem.remove_prop( "PackageRoot", &tmp )) { PackageRoot.push_back( normalized_dir_form(tmp) ); } if (elem.remove_prop( "IncludeDirectory", &tmp )) { IncludeDirectory = normalized_dir_form(tmp); } ModuleDirectory = normalized_dir_form(elem.remove_string( "ModuleDirectory" )); PolScriptRoot = normalized_dir_form(elem.remove_string( "PolScriptRoot" )); GenerateListing = elem.remove_bool( "GenerateListing", false ); GenerateDebugInfo = elem.remove_bool( "GenerateDebugInfo", false ); GenerateDebugTextInfo = elem.remove_bool( "GenerateDebugTextInfo", false ); DisplayWarnings = elem.remove_bool( "DisplayWarnings", false ); CompileAspPages = elem.remove_bool( "CompileAspPages", false ); AutoCompileByDefault = elem.remove_bool( "AutoCompileByDefault", false ); UpdateOnlyOnAutoCompile = elem.remove_bool( "UpdateOnlyOnAutoCompile", false ); OnlyCompileUpdatedScripts = elem.remove_bool( "OnlyCompileUpdatedScripts", false ); DisplaySummary = elem.remove_bool( "DisplaySummary", false ); OptimizeObjectMembers = elem.remove_bool( "OptimizeObjectMembers", true); GenerateDependencyInfo = elem.remove_bool( "GenerateDependencyInfo", OnlyCompileUpdatedScripts ); ThreadedCompilation = elem.remove_bool( "ThreadedCompilation", false ); DisplayUpToDateScripts = elem.remove_bool( "DisplayUpToDateScripts", true ); // This is where we TRY to validate full paths from what was provided in the // ecompile.cfg. Maybe Turley or Shini can find the best way to do this in *nix. #ifdef WIN32 string MyPath = path.c_str(); // If it's just "ecompile.cfg", let's change it to the exe's path which it SHOULD be // with. if (stricmp(MyPath.c_str(), "ecompile.cfg") == 0) { // Let's find the NEXT-TO-LAST / in the path, and remove from there on. Oh yay! // To bad we can't just force everyone to use ABSOLUTE PATHS NANDO. :o MyPath = xmain_exedir.substr(0, xmain_exedir.length()-1); MyPath = MyPath.substr(0, MyPath.find_last_of( '/')+1); } if (IncludeDirectory.find(':') == string::npos) { if (IncludeDirectory.substr(0, 1) != ".") // Let's make sure they didn't try using this method { IncludeDirectory = MyPath + IncludeDirectory; } } if (ModuleDirectory.find(':') == string::npos) { if (ModuleDirectory.substr(0, 1) != ".") // Let's make sure they didn't try using this method { ModuleDirectory = MyPath + ModuleDirectory; } } if (PolScriptRoot.find(':') == string::npos) { if (PolScriptRoot.substr(0, 1) != ".") // Let's make sure they didn't try using this method { PolScriptRoot = MyPath + PolScriptRoot; } } for( unsigned pr = 0; pr < PackageRoot.size(); ++pr ) { if (PackageRoot[pr].find(':') == string::npos) { if (PackageRoot[pr].substr(0, 1) != ".") // Let's make sure they didn't try using this method { PackageRoot[pr] = MyPath + PackageRoot[pr]; } } } #endif }
bool run(int argc, char **argv) { for( unsigned pi = 0; pi < compilercfg.PackageRoot.size(); ++pi ) { load_packages( compilercfg.PackageRoot[pi], true /* quiet */ ); } replace_packages(); check_package_deps(); wallclock_t start = wallclock(); bool any = false; for(int i=1;i<argc;i++) { #ifdef __linux__ if (argv[i][0] == '-') #else if (argv[i][0] == '/' || argv[i][0] == '-') #endif { // -r[i] [<dir>] if (argv[i][1] == 'A') { compilercfg.UpdateOnlyOnAutoCompile = (argv[i][2] == 'u'); any = true; AutoCompile(); } else if (argv[i][1] == 'r') { any = true; string dir("."); bool compile_inc = (argv[i][2] == 'i'); // compile .inc files ++i; if (i<argc && argv[i] && argv[i][0] != '-') dir.assign(argv[i]); if (compilercfg.ThreadedCompilation) { vector<string> files; if (compile_inc) recurse_compile_inc( normalized_dir_form( dir ), &files ); else recurse_compile( normalized_dir_form( dir ),&files ); parallel_compile(files); } else { if (compile_inc) recurse_compile_inc( normalized_dir_form( dir ), NULL ); else recurse_compile( normalized_dir_form( dir ),NULL ); } } else if (argv[i][1] == 'C') { ++i; // skip the config file pathname } // and skip any other option. } else { any = true; #ifdef _WIN32 forspec(argv[i], compile_file_wrapper); #else compile_file_wrapper( argv[i] ); #endif } } if (!any && compilercfg.AutoCompileByDefault) { any = true; AutoCompile(); } wallclock_t finish = wallclock(); unload_packages(); if (any && compilercfg.DisplaySummary && !quiet) { cout << "Compilation Summary:" << endl; if (summary.CompiledScripts) cout << " Compiled " << summary.CompiledScripts << " script" << (summary.CompiledScripts==1?"":"s") << " in " << wallclock_diff_ms( start, finish ) << " ms." << endl; if (summary.ScriptsWithCompileErrors) cout << " " << summary.ScriptsWithCompileErrors << " of those script" << (summary.ScriptsWithCompileErrors==1?"":"s") << " had errors." << endl; if (summary.UpToDateScripts) cout << " " << summary.UpToDateScripts << " script" << (summary.UpToDateScripts==1?" was":"s were") << " already up-to-date." << endl; } return any; }
int xmain( int argc, char* argv[] ) { StoreCmdArgs( argc, argv ); ConfigFile cf( "pol.cfg" ); ConfigElem elem; cf.readraw( elem ); config.uo_datafile_root = elem.remove_string( "UoDataFileRoot" ); config.uo_datafile_root = normalized_dir_form( config.uo_datafile_root ); unsigned short max_tile = elem.remove_ushort( "MaxTileID", 0x3FFF ); if (max_tile != 0x3FFF && max_tile != 0x7FFF) config.max_tile_id = 0x3FFF; else config.max_tile_id = max_tile; if (argc <= 1) return Usage(1); if (argv[1][0] == '/' || argv[1][1] == ':') { config.uo_datafile_root = argv[1]; --argc; ++argv; } if (stricmp( argv[1], "tiledump" ) == 0) { return tiledump( argc, argv ); } else if (stricmp( argv[1], "vertile" ) == 0) { return vertile( argc, argv ); } else if (stricmp( argv[1], "verlandtile" ) == 0) { return verlandtile( argc, argv ); } else if (stricmp( argv[1], "landtilehist" ) == 0) { return landtilehist( argc, argv ); } else if (stricmp( argv[1], "flagsearch" ) == 0) { return flagsearch( argc, argv ); } else if (stricmp( argv[1], "landtileflagsearch" ) == 0) { return landtileflagsearch( argc, argv ); } else if (stricmp( argv[1], "loschange" ) == 0) { return loschange( argc, argv ); } else if (stricmp( argv[1], "rawdump" ) == 0) { return rawdump( argc, argv ); } else if (stricmp( argv[1], "ctable" ) == 0) { return print_ctable(); } else if (stricmp( argv[1], "sndlist" ) == 0) { return print_sndlist(argc, argv); } else if (stricmp( argv[1], "statics" ) == 0) { return print_statics(); } else if (stricmp( argv[1], "verdata" ) == 0) { return print_verdata_info(); } else if (stricmp( argv[1], "multis" ) == 0) { return print_multis(); } else if (stricmp( argv[1], "water" ) == 0) { return print_water_data(); } else if (stricmp( argv[1], "newstatics" ) == 0) { return write_pol_static_files( "main" ); } else if (stricmp( argv[1], "staticsmax" ) == 0) { void staticsmax(); open_uo_data_files(); staticsmax(); return 0; } else if (stricmp( argv[1], "watersearch" ) == 0) { return water_search(argc,argv); } else if (stricmp( argv[1], "zhist" ) == 0) { return z_histogram(); } else if (stricmp( argv[1], "staticshist" ) == 0) { return statics_histogram(); } else if (stricmp( argv[1], "writedungmap" ) == 0) { return write_polmap(); } else if (stricmp( argv[1], "writekeys" ) == 0) { printf( "Keys written to current.key" ); return 0; } else if (stricmp( argv[1], "mapdump" ) == 0) { return mapdump( argc, argv ); } else if (stricmp( argv[1], "contour" ) == 0) { return contour( argc, argv ); } else if (stricmp( argv[1], "findlandtile" ) == 0) { return findlandtile( argc-1, argv+1 ); } else if (stricmp( argv[1], "findlandtileflags" ) == 0) { return findlandtileflags( argc-1, argv+1 ); } else if (stricmp( argv[1], "findgraphic" ) == 0) { return findgraphic( argc-1, argv+1 ); } else if (stricmp( argv[1], "defragstatics" ) == 0) { return defragstatics( argc-1, argv+1 ); } return 0; }