/** ** The main program: initialise, parse options and arguments. ** ** @param argc Number of arguments. ** @param argv Vector of arguments. */ int main(int argc, char **argv) { #ifdef REDIRECT_OUTPUT RedirectOutput(); #endif #ifdef USE_BEOS // Parse arguments for BeOS beos_init(argc, argv); #endif // Setup some defaults. #ifndef MAC_BUNDLE StratagusLibPath = "."; #else freopen("/tmp/stdout.txt", "w", stdout); freopen("/tmp/stderr.txt", "w", stderr); // Look for the specified data set inside the application bundle // This should be a subdir of the Resources directory CFURLRef pluginRef = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR(MAC_BUNDLE_DATADIR), NULL, NULL); CFStringRef macPath = CFURLCopyFileSystemPath(pluginRef, kCFURLPOSIXPathStyle); const char *pathPtr = CFStringGetCStringPtr(macPath, CFStringGetSystemEncoding()); Assert(pathPtr); StratagusLibPath = pathPtr; #endif Parameters ¶meters = Parameters::Instance; parameters.SetDefaultValues(); parameters.LocalPlayerName = GetLocalPlayerNameFromEnv(); if (argc > 0) { parameters.applicationName = argv[0]; } // FIXME: Parse options before or after scripts? ParseCommandLine(argc, argv, parameters); // Init the random number generator. InitSyncRand(); makedir(parameters.GetUserDirectory().c_str(), 0777); // Init Lua and register lua functions! InitLua(); LuaRegisterModules(); // Initialise AI module InitAiModule(); LoadCcl(parameters.luaStartFilename); PrintHeader(); PrintLicense(); // Setup video display InitVideo(); // Setup sound card if (!InitSound()) { InitMusic(); } #ifndef DEBUG // For debug it's better not to have: srand(time(NULL)); // Random counter = random each start #endif // Show title screens. SetDefaultTextColors(FontYellow, FontWhite); LoadFonts(); SetClipping(0, 0, Video.Width - 1, Video.Height - 1); Video.ClearScreen(); ShowTitleScreens(); // Init player data ThisPlayer = NULL; //Don't clear the Players strucure as it would erase the allowed units. // memset(Players, 0, sizeof(Players)); NumPlayers = 0; UnitManager.Init(); // Units memory management PreMenuSetup(); // Load everything needed for menus MenuLoop(); Exit(0); return 0; }
/** ** The main program: initialise, parse options and arguments. ** ** @param argc Number of arguments. ** @param argv Vector of arguments. */ int stratagusMain(int argc, char **argv) { #ifdef USE_BEOS // Parse arguments for BeOS beos_init(argc, argv); #endif #ifdef USE_WIN32 SetUnhandledExceptionFilter(CreateDumpFile); #endif #if defined(USE_WIN32) && ! defined(REDIRECT_OUTPUT) SetupConsole(); #endif // Setup some defaults. #ifndef MAC_BUNDLE StratagusLibPath = "."; #else freopen("/tmp/stdout.txt", "w", stdout); freopen("/tmp/stderr.txt", "w", stderr); // Look for the specified data set inside the application bundle // This should be a subdir of the Resources directory CFURLRef pluginRef = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR(MAC_BUNDLE_DATADIR), NULL, NULL); CFStringRef macPath = CFURLCopyFileSystemPath(pluginRef, kCFURLPOSIXPathStyle); const char *pathPtr = CFStringGetCStringPtr(macPath, CFStringGetSystemEncoding()); Assert(pathPtr); StratagusLibPath = pathPtr; #endif #ifdef USE_PHYSFS if (PHYSFS_init(argv[0])) { PHYSFS_mount(PHYSFS_DATAFILE, "/", 0); } #endif #ifdef USE_STACKTRACE try { #endif Parameters ¶meters = Parameters::Instance; parameters.SetDefaultValues(); parameters.SetLocalPlayerNameFromEnv(); #ifdef REDIRECT_OUTPUT RedirectOutput(); #endif if (argc > 0) { parameters.applicationName = argv[0]; } // FIXME: Parse options before or after scripts? ParseCommandLine(argc, argv, parameters); // Init the random number generator. InitSyncRand(); makedir(parameters.GetUserDirectory().c_str(), 0777); // Init Lua and register lua functions! InitLua(); LuaRegisterModules(); // Initialise AI module InitAiModule(); LoadCcl(parameters.luaStartFilename, parameters.luaScriptArguments); PrintHeader(); PrintLicense(); // Setup video display InitVideo(); // Setup sound card if (!InitSound()) { InitMusic(); } #ifndef DEBUG // For debug it's better not to have: srand(time(NULL)); // Random counter = random each start #endif // Show title screens. SetDefaultTextColors(FontYellow, FontWhite); LoadFonts(); SetClipping(0, 0, Video.Width - 1, Video.Height - 1); Video.ClearScreen(); ShowTitleScreens(); // Init player data ThisPlayer = NULL; //Don't clear the Players structure as it would erase the allowed units. // memset(Players, 0, sizeof(Players)); NumPlayers = 0; UnitManager.Init(); // Units memory management PreMenuSetup(); // Load everything needed for menus MenuLoop(); Exit(0); #ifdef USE_STACKTRACE } catch (const std::exception &e) { fprintf(stderr, "Stratagus crashed!\n"); //Wyrmgus start // fprintf(stderr, "Please send this call stack to our bug tracker: https://github.com/Wargus/stratagus/issues\n"); fprintf(stderr, "Please send this call stack to our bug tracker: https://github.com/Andrettin/Wyrmgus/issues\n"); //Wyrmgus end fprintf(stderr, "and tell us what caused this bug to occur.\n"); fprintf(stderr, " === exception state traceback === \n"); fprintf(stderr, "%s", e.what()); exit(1); } #endif return 0; }
int main (int argc, char *argv[]) { /* variable declarations */ int ArgIdx; int CanSwitchFileMode; int ShouldExit; int RetVal = 0; CFlag *pFlag; char *ptr; #ifdef ENABLE_NLS char localedir[1024]; ptr = getenv("DOS2UNIX_LOCALEDIR"); if (ptr == NULL) strcpy(localedir,LOCALEDIR); else { if (strlen(ptr) < sizeof(localedir)) strcpy(localedir,ptr); else { fprintf(stderr, "%s", _("unix2dos: error: Value of environment variable UNIX2DOS_LOCALEDIR is too long.\n")); strcpy(localedir,LOCALEDIR); } } setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, localedir); textdomain (PACKAGE); #endif /* variable initialisations */ ArgIdx = 0; CanSwitchFileMode = 1; ShouldExit = 0; pFlag = (CFlag*)malloc(sizeof(CFlag)); pFlag->NewFile = 0; pFlag->Quiet = 0; pFlag->KeepDate = 0; pFlag->ConvMode = 0; pFlag->NewLine = 0; pFlag->Force = 0; pFlag->status = 0; pFlag->stdio_mode = 1; if ( ((ptr=strrchr(argv[0],'/')) == NULL) && ((ptr=strrchr(argv[0],'\\')) == NULL) ) ptr = argv[0]; else ptr++; if ((strcmpi("unix2mac", ptr) == 0) || (strcmpi("unix2mac.exe", ptr) == 0)) pFlag->ConvMode = 3; while ((++ArgIdx < argc) && (!ShouldExit)) { /* is it an option? */ if (argv[ArgIdx][0] == '-') { /* an option */ if ((strcmp(argv[ArgIdx],"-h") == 0) || (strcmp(argv[ArgIdx],"--help") == 0)) { PrintUsage(); return(0); } else if ((strcmp(argv[ArgIdx],"-k") == 0) || (strcmp(argv[ArgIdx],"--keepdate") == 0)) pFlag->KeepDate = 1; else if ((strcmp(argv[ArgIdx],"-f") == 0) || (strcmp(argv[ArgIdx],"--force") == 0)) pFlag->Force = 1; else if ((strcmp(argv[ArgIdx],"-q") == 0) || (strcmp(argv[ArgIdx],"--quiet") == 0)) pFlag->Quiet = 1; else if ((strcmp(argv[ArgIdx],"-l") == 0) || (strcmp(argv[ArgIdx],"--newline") == 0)) pFlag->NewLine = 1; else if ((strcmp(argv[ArgIdx],"-V") == 0) || (strcmp(argv[ArgIdx],"--version") == 0)) { PrintVersion(); #ifdef ENABLE_NLS PrintLocaledir(localedir); #endif return(0); } else if ((strcmp(argv[ArgIdx],"-L") == 0) || (strcmp(argv[ArgIdx],"--license") == 0)) { PrintLicense(); return(0); } else if ((strcmp(argv[ArgIdx],"-c") == 0) || (strcmp(argv[ArgIdx],"--convmode") == 0)) { if (++ArgIdx < argc) { if (strcmpi(argv[ArgIdx],"ascii") == 0) pFlag->ConvMode = 0; else if (strcmpi(argv[ArgIdx], "7bit") == 0) pFlag->ConvMode = 1; else if (strcmpi(argv[ArgIdx], "iso") == 0) pFlag->ConvMode = 2; else if (strcmpi(argv[ArgIdx], "mac") == 0) pFlag->ConvMode = 3; else { if (!pFlag->Quiet) fprintf(stderr, _("unix2dos: invalid %s conversion mode specified\n"),argv[ArgIdx]); ShouldExit = 1; } } else { ArgIdx--; if (!pFlag->Quiet) fprintf(stderr,_("unix2dos: option '%s' requires an argument\n"),argv[ArgIdx]); ShouldExit = 1; } } else if ((strcmp(argv[ArgIdx],"-o") == 0) || (strcmp(argv[ArgIdx],"--oldfile") == 0)) { /* last convert not paired */ if (!CanSwitchFileMode) { if (!pFlag->Quiet) fprintf(stderr, _("unix2dos: target of file %s not specified in new file mode\n"), argv[ArgIdx-1]); ShouldExit = 1; } pFlag->NewFile = 0; } else if ((strcmp(argv[ArgIdx],"-n") == 0) || (strcmp(argv[ArgIdx],"--newfile") == 0)) { /* last convert not paired */ if (!CanSwitchFileMode) { if (!pFlag->Quiet) fprintf(stderr, _("unix2dos: target of file %s not specified in new file mode\n"), argv[ArgIdx-1]); ShouldExit = 1; } pFlag->NewFile = 1; } else { /* wrong option */ PrintUsage(); return(0); } } else { pFlag->stdio_mode = 0; /* not an option */ if (pFlag->NewFile) { if (CanSwitchFileMode) CanSwitchFileMode = 0; else { RetVal = ConvertUnixToDosNewFile(argv[ArgIdx-1], argv[ArgIdx], pFlag); if (pFlag->status & NO_REGFILE) { if (!pFlag->Quiet) fprintf(stderr, _("unix2dos: Skipping %s, not a regular file.\n"), argv[ArgIdx-1]); } else if (pFlag->status & BINARY_FILE) { if (!pFlag->Quiet) fprintf(stderr, _("unix2dos: Skipping binary file %s\n"), argv[ArgIdx-1]); } else { if (!pFlag->Quiet) { if (pFlag->ConvMode == 3) fprintf(stderr, _("unix2dos: converting file %s to file %s in MAC format ...\n"), argv[ArgIdx-1], argv[ArgIdx]); else fprintf(stderr, _("unix2dos: converting file %s to file %s in DOS format ...\n"), argv[ArgIdx-1], argv[ArgIdx]); } if (RetVal) { if (!pFlag->Quiet) fprintf(stderr, _("unix2dos: problems converting file %s to file %s\n"), argv[ArgIdx-1], argv[ArgIdx]); ShouldExit = 1; } } CanSwitchFileMode = 1; } } else { RetVal = ConvertUnixToDosOldFile(argv[ArgIdx], pFlag); if (pFlag->status & NO_REGFILE) { if (!pFlag->Quiet) fprintf(stderr, _("unix2dos: Skipping %s, not a regular file.\n"), argv[ArgIdx]); } else if (pFlag->status & BINARY_FILE) { if (!pFlag->Quiet) fprintf(stderr, _("unix2dos: Skipping binary file %s\n"), argv[ArgIdx]); } else { if (!pFlag->Quiet) { if (pFlag->ConvMode == 3) fprintf(stderr, _("unix2dos: converting file %s to MAC format ...\n"), argv[ArgIdx]); else fprintf(stderr, _("unix2dos: converting file %s to DOS format ...\n"), argv[ArgIdx]); } if (RetVal) { if (!pFlag->Quiet) fprintf(stderr, _("unix2dos: problems converting file %s\n"), argv[ArgIdx]); ShouldExit = 1; } } } } } /* no file argument, use stdin and stdout */ if (pFlag->stdio_mode) { exit(ConvertUnixToDosStdio(pFlag)); } if ((!pFlag->Quiet) && (!CanSwitchFileMode)) { fprintf(stderr, _("unix2dos: target of file %s not specified in new file mode\n"), argv[ArgIdx-1]); ShouldExit = 1; } free(pFlag); return (ShouldExit); }
/// main int main(int argc,char **argv) { int quality = -1; int hdrquality = -1; int maxerror = 0; int levels = 0; int restart = 0; int lsmode = -1; // Use JPEGLS int hiddenbits = 0; // hidden DCT bits int riddenbits = 0; // hidden bits in the residual domain int ahiddenbits = 0; // hidden DCT bits in the base alpha codestream int ariddenbits = 0; // hidden DCT bits in the residual alpha codestream. int resprec = 8; // precision in the residual domain int aresprec = 8; // precision of the residual alpha double gamma = 0.0; bool pyramidal = false; bool residuals = false; int colortrafo = JPGFLAG_MATRIX_COLORTRANSFORMATION_YCBCR; bool lossless = false; bool optimize = false; bool accoding = false; bool qscan = false; bool progressive = false; bool writednl = false; bool noiseshaping = false; bool rprogressive = false; bool rsequential = false; bool raccoding = false; bool serms = false; bool aserms = false; bool abypass = false; bool losslessdct = false; bool dctbypass = false; bool openloop = false; bool deadzone = false; bool lagrangian = false; bool dering = false; bool aopenloop = false; bool adeadzone = false; bool alagrangian = false; bool adering = false; bool xyz = false; bool cxyz = false; bool separate = false; bool noclamp = false; bool setprofile = false; bool upsample = true; bool median = true; int splitquality = -1; int profile = 2; // profile C. const char *sub = NULL; const char *ressub = NULL; const char *ldrsource = NULL; const char *lsource = NULL; const char *alpha = NULL; // source or target of the alpha plane bool alpharesiduals = false; int alphamode = JPGFLAG_ALPHA_REGULAR; // alpha mode int matte_r = 0,matte_g = 0,matte_b = 0; // matte color for alpha. int alphaquality = 70; int alphahdrquality = 0; int alphasplitquality = -1; int tabletype = 0; // quantization table types int residualtt = 0; int alphatt = 0; int residualalphatt = 0; int smooth = 0; // histogram smoothing PrintLicense(); fflush(stdout); while(argc > 3 && argv[1][0] == '-') { if (!strcmp(argv[1],"-q")) { quality = ParseInt(argc,argv); } else if (!strcmp(argv[1],"-Q")) { hdrquality = ParseInt(argc,argv); } else if (!strcmp(argv[1],"-quality")) { splitquality = ParseInt(argc,argv); } else if (!strcmp(argv[1],"-profile")) { const char *s = ParseString(argc,argv); setprofile = true; if (!strcmp(s,"a") || !strcmp(s,"A")) { profile = 0; } else if (!strcmp(s,"b") || !strcmp(s,"B")) { profile = 1; } else if (!strcmp(s,"c") || !strcmp(s,"C")) { profile = 2; } else if (!strcmp(s,"d") || !strcmp(s,"D")) { profile = 4; } else { fprintf(stderr,"unknown profile definition %s, only profiles a,b,c and d exist", s); return 20; } } else if (!strcmp(argv[1],"-m")) { maxerror = ParseInt(argc,argv); } else if (!strcmp(argv[1],"-md")) { median = true; argv++; argc--; } else if (!strcmp(argv[1],"-ct")) { median = false; argv++; argc--; } else if (!strcmp(argv[1],"-sm")) { smooth = ParseInt(argc,argv); } else if (!strcmp(argv[1],"-z")) { restart = ParseInt(argc,argv); } else if (!strcmp(argv[1],"-r")) { residuals = true; argv++; argc--; } else if (!strcmp(argv[1],"-R")) { hiddenbits = ParseInt(argc,argv); if (hiddenbits < 0 || hiddenbits > 4) { fprintf(stderr,"JPEG XT allows only between 0 and 4 refinement bits.\n"); return 20; } } else if (!strcmp(argv[1],"-rR")) { riddenbits = ParseInt(argc,argv); } else if (!strcmp(argv[1],"-n")) { writednl = true; argv++; argc--; } else if (!strcmp(argv[1],"-c")) { colortrafo = JPGFLAG_MATRIX_COLORTRANSFORMATION_NONE; argv++; argc--; } else if (!strcmp(argv[1],"-cls")) { colortrafo = JPGFLAG_MATRIX_COLORTRANSFORMATION_LSRCT; argv++; argc--; } else if (!strcmp(argv[1],"-sp")) { separate = true; argv++; argc--; } else if (!strcmp(argv[1],"-s")) { sub = ParseString(argc,argv); } else if (!strcmp(argv[1],"-sr")) { ressub = ParseString(argc,argv); } else if (!strcmp(argv[1],"-ncl")) { noclamp = true; argv++; argc--; } else if (!strcmp(argv[1],"-al")) { alpha = ParseString(argc,argv); } else if (!strcmp(argv[1],"-am")) { alphamode = ParseInt(argc,argv); if (alphamode < 0 || alphamode > 3) { fprintf(stderr,"the alpha mode specified with -am must be between 0 and 3\n"); return 20; } } else if (!strcmp(argv[1],"-ab")) { const char *matte = ParseString(argc,argv); if (sscanf(matte,"%d,%d,%d",&matte_r,&matte_g,&matte_b) != 3) { fprintf(stderr,"-ab expects three numeric arguments separated comma, i.e. r,g,b\n"); return 20; } } else if (!strcmp(argv[1],"-all")) { aserms = true; argv++; argc--; } else if (!strcmp(argv[1],"-alo")) { abypass = true; argv++; argc--; } #if ACCUSOFT_CODE else if (!strcmp(argv[1],"-p")) { lossless = true; argv++; argc--; } #endif else if (!strcmp(argv[1],"-h")) { optimize = true; argv++; argc--; } #if ACCUSOFT_CODE else if (!strcmp(argv[1],"-a")) { accoding = true; argv++; argc--; } else if (!strcmp(argv[1],"-ra")) { raccoding = true; argv++; argc--; } #endif else if (!strcmp(argv[1],"-qv")) { qscan = true; argv++; argc--; } else if (!strcmp(argv[1],"-v")) { progressive = true; argv++; argc--; } else if (!strcmp(argv[1],"-rv")) { rprogressive = true; argv++; argc--; } else if (!strcmp(argv[1],"-rs")) { rsequential = true; argv++; argc--; } else if (!strcmp(argv[1],"-r12")) { resprec = 12; residuals = true; argv++; argc--; } else if (!strcmp(argv[1],"-rl")) { losslessdct = true; argv++; argc--; } else if (!strcmp(argv[1],"-ro")) { dctbypass = true; argv++; argc--; } else if (!strcmp(argv[1],"-xyz")) { xyz = true; argv++; argc--; } else if (!strcmp(argv[1],"-cxyz")) { cxyz = true; argv++; argc--; } else if (!strcmp(argv[1],"-N")) { noiseshaping = true; argv++; argc--; } else if (!strcmp(argv[1],"-ol")) { openloop = true; argv++; argc--; } else if (!strcmp(argv[1],"-U")) { upsample = false; argv++; argc--; } else if (!strcmp(argv[1],"-dz")) { deadzone = true; argv++; argc--; #if ACCUSOFT_CODE } else if (!strcmp(argv[1],"-oz")) { lagrangian = true; argv++; argc--; } else if (!strcmp(argv[1],"-ozn")) { oznew = true; argv++; argc--; } else if (!strcmp(argv[1],"-dr")) { dering = true; argv++; argc--; #endif } else if (!strcmp(argv[1],"-qt")) { tabletype = ParseInt(argc,argv); } else if (!strcmp(argv[1],"-rqt")) { residualtt = ParseInt(argc,argv); } else if (!strcmp(argv[1],"-aqt")) { alphatt = ParseInt(argc,argv); } else if (!strcmp(argv[1],"-arqt")) { residualalphatt = ParseInt(argc,argv); } else if (!strcmp(argv[1],"-aol")) { aopenloop = true; argv++; argc--; } else if (!strcmp(argv[1],"-adz")) { adeadzone = true; argv++; argc--; #if ACCUSOFT_CODE } else if (!strcmp(argv[1],"-aoz")) { alagrangian = true; argv++; argc--; } else if (!strcmp(argv[1],"-adr")) { adering = true; argv++; argc--; #endif } else if (!strcmp(argv[1],"-ldr")) { ldrsource = ParseString(argc,argv); } else if (!strcmp(argv[1],"-l")) { serms = true; argv++; argc--; } else if (!strcmp(argv[1],"-g")) { gamma = ParseDouble(argc,argv); } else if (!strcmp(argv[1],"-gf")) { lsource = ParseString(argc,argv); } else if (!strcmp(argv[1],"-aq")) { alphaquality = ParseInt(argc,argv); } else if (!strcmp(argv[1],"-aQ")) { alphahdrquality = ParseInt(argc,argv); } else if (!strcmp(argv[1],"-aquality")) { alphasplitquality = ParseInt(argc,argv); } else if (!strcmp(argv[1],"-ar")) { alpharesiduals = true; argv++; argc--; } else if (!strcmp(argv[1],"-ar12")) { alpharesiduals = true; aresprec = 12; argv++; argc--; } else if (!strcmp(argv[1],"-aR")) { ahiddenbits = ParseInt(argc,argv); } else if (!strcmp(argv[1],"-arR")) { ariddenbits = ParseInt(argc,argv); } #if ACCUSOFT_CODE else if (!strcmp(argv[1],"-y")) { levels = ParseInt(argc,argv); if (levels == 0 || levels == 1) { // In this mode, the hierarchical model is used for lossless coding levels++; pyramidal = false; } else { pyramidal = true; } } #endif else if (!strcmp(argv[1],"-ls")) { lsmode = ParseInt(argc,argv); } else { fprintf(stderr,"unsupported command line switch %s\n",argv[1]); return 20; } } // // Use a very simplistic quality split. if (splitquality >= 0) { switch(profile) { case 0: break; case 1: break; case 2: case 4: SplitQualityC(splitquality,residuals,quality,hdrquality); break; } } // // The alpha channel is encoded with something that works like part 6. if (alphasplitquality > 0) { SplitQualityC(alphasplitquality,alpharesiduals,alphaquality,alphahdrquality); } if (argc != 3) { if (argc > 3) { fprintf(stderr,"Error in argument parsing, argument %s not understood or parsed correctly.\n" "Run without arguments for a list of command line options.\n\n", argv[1]); exit(20); } PrintUsage(argv[0]); return 5; } if (quality < 0 && lossless == false && lsmode < 0) { Reconstruct(argv[1],argv[2],colortrafo,alpha,upsample); } else { switch(profile) { case 0: fprintf(stderr,"**** Profile A encoding not supported due to patented IPRs.\n"); break; case 1: fprintf(stderr,"**** Profile B encoding not supported due to patented IPRs.\n"); break; case 2: case 4: if (setprofile && ((residuals == false && hiddenbits == false && profile != 4) || profile == 2)) residuals = true; EncodeC(argv[1],ldrsource,argv[2],lsource,quality,hdrquality, tabletype,residualtt,maxerror, colortrafo,lossless,progressive, residuals,optimize,accoding, rsequential,rprogressive,raccoding, qscan,levels,pyramidal,writednl,restart, gamma, lsmode,noiseshaping,serms,losslessdct, openloop,deadzone,lagrangian,dering, xyz,cxyz, hiddenbits,riddenbits,resprec,separate, median,noclamp,smooth,dctbypass, sub,ressub, alpha,alphamode,matte_r,matte_g,matte_b, alpharesiduals,alphaquality,alphahdrquality, alphatt,residualalphatt, ahiddenbits,ariddenbits,aresprec, aopenloop,adeadzone,alagrangian,adering, aserms,abypass); break; } } return 0; }