static inline unsigned parseOptions(const QStringList ¶mList, int *tabletAbsoluteRange, QtWindows::ProcessDpiAwareness *dpiAwareness) { unsigned options = 0; foreach (const QString ¶m, paramList) { if (param.startsWith(QLatin1String("fontengine="))) { if (param.endsWith(QLatin1String("freetype"))) { options |= QWindowsIntegration::FontDatabaseFreeType; } else if (param.endsWith(QLatin1String("native"))) { options |= QWindowsIntegration::FontDatabaseNative; } } else if (param.startsWith(QLatin1String("dialogs="))) { if (param.endsWith(QLatin1String("xp"))) { options |= QWindowsIntegration::XpNativeDialogs; } else if (param.endsWith(QLatin1String("none"))) { options |= QWindowsIntegration::NoNativeDialogs; } } else if (param == QLatin1String("gl=gdi")) { options |= QWindowsIntegration::DisableArb; } else if (param == QLatin1String("nomousefromtouch")) { options |= QWindowsIntegration::DontPassOsMouseEventsSynthesizedFromTouch; } else if (parseIntOption(param, QLatin1String("verbose"), 0, INT_MAX, &QWindowsContext::verbose) || parseIntOption(param, QLatin1String("tabletabsoluterange"), 0, INT_MAX, tabletAbsoluteRange) || parseIntOption(param, QLatin1String("dpiawareness"), QtWindows::ProcessDpiUnaware, QtWindows::ProcessPerMonitorDpiAware, dpiAwareness)) { } else { qWarning() << "Unknown option" << param; } } return options; }
static int parseOptions (int argc, char *argv[], struct options_struct *options) { int optionIndex; BOOLEAN badArg = FALSE; options->addons = HMalloc (1 * sizeof (const char *)); options->addons[0] = NULL; options->numAddons = 0; if (argc == 0) { log_add (log_Fatal, "Error: Bad command line."); return EXIT_FAILURE; } while (!badArg) { int c; optionIndex = -1; c = getopt_long (argc, argv, optString, longOptions, &optionIndex); if (c == -1) break; switch (c) { case 'r': { int width, height; if (sscanf (optarg, "%dx%d", &width, &height) != 2) { log_add (log_Fatal, "Error: invalid argument specified " "as resolution."); badArg = TRUE; break; } options->width = width; options->height = height; break; } case 'f': options->gfxFlags |= TFB_GFXFLAGS_FULLSCREEN; break; case 'o': options->gfxDriver = TFB_GFXDRIVER_SDL_OPENGL; break; case 'c': // make sure whatever was set by saved config is cleared options->gfxFlags &= ~TFB_GFXFLAGS_SCALE_ANY; if (!strcmp (optarg, "bilinear")) options->gfxFlags |= TFB_GFXFLAGS_SCALE_BILINEAR; else if (!strcmp (optarg, "biadapt")) options->gfxFlags |= TFB_GFXFLAGS_SCALE_BIADAPT; else if (!strcmp (optarg, "biadv")) options->gfxFlags |= TFB_GFXFLAGS_SCALE_BIADAPTADV; else if (!strcmp (optarg, "triscan")) options->gfxFlags |= TFB_GFXFLAGS_SCALE_TRISCAN; else if (!strcmp (optarg, "hq")) options->gfxFlags |= TFB_GFXFLAGS_SCALE_HQXX; else if (strcmp (optarg, "none") != 0) { InvalidArgument (optarg, "--scale or -c"); badArg = TRUE; } break; case 'b': if (!strcmp (optarg, "smooth") || !strcmp (optarg, "3do")) options->meleeScale = TFB_SCALE_TRILINEAR; else if (!strcmp (optarg, "step") || !strcmp (optarg, "pc")) options->meleeScale = TFB_SCALE_STEP; else { InvalidArgument (optarg, "--meleezoom or -b"); badArg = TRUE; } break; case 's': options->gfxFlags |= TFB_GFXFLAGS_SCANLINES; break; case 'p': options->gfxFlags |= TFB_GFXFLAGS_SHOWFPS; break; case 'n': options->contentDir = optarg; break; case 'M': { int err = parseVolume (optarg, &options->musicVolumeScale, "music volume"); if (err) badArg = TRUE; break; } case 'S': { int err = parseVolume (optarg, &options->sfxVolumeScale, "sfx volume"); if (err) badArg = TRUE; break; } case 'T': { int err = parseVolume (optarg, &options->speechVolumeScale, "speech volume"); if (err) badArg = TRUE; break; } case 'q': if (!strcmp (optarg, "high")) { options->soundFlags &= ~(audio_QUALITY_MEDIUM | audio_QUALITY_LOW); options->soundFlags |= audio_QUALITY_HIGH; } else if (!strcmp (optarg, "medium")) { options->soundFlags &= ~(audio_QUALITY_MEDIUM | audio_QUALITY_LOW); options->soundFlags |= audio_QUALITY_MEDIUM; } else if (!strcmp (optarg, "low")) { options->soundFlags &= ~(audio_QUALITY_MEDIUM | audio_QUALITY_LOW); options->soundFlags |= audio_QUALITY_LOW; } else { InvalidArgument (optarg, "--audioquality or -q"); badArg = TRUE; } break; case 'u': options->subTitles = FALSE; break; case 'm': { if (Check_PC_3DO_opt (optarg, OPT_PC | OPT_3DO, optionIndex >= 0 ? longOptions[optionIndex].name : "m", &options->whichMusic) == -1) badArg = TRUE; break; } case 'g': { int result = parseFloatOption (optarg, &options->gamma, "gamma correction"); if (result == -1) badArg = TRUE; else options->gammaSet = TRUE; break; } case 'l': case 'C': // -l and -C are no-ops on the second pass. break; case 'i': { if (Check_PC_3DO_opt (optarg, OPT_PC | OPT_3DO, optionIndex >= 0 ? longOptions[optionIndex].name : "i", &options->whichIntro) == -1) badArg = TRUE; break; } case CSCAN_OPT: if (Check_PC_3DO_opt (optarg, OPT_PC | OPT_3DO, longOptions[optionIndex].name, &options->whichCoarseScan) == -1) badArg = TRUE; break; case MENU_OPT: if (Check_PC_3DO_opt (optarg, OPT_PC | OPT_3DO, longOptions[optionIndex].name, &options->whichMenu) == -1) badArg = TRUE; break; case FONT_OPT: if (Check_PC_3DO_opt (optarg, OPT_PC | OPT_3DO, longOptions[optionIndex].name, &options->whichFonts) == -1) badArg = TRUE; break; case SHIELD_OPT: if (Check_PC_3DO_opt (optarg, OPT_PC | OPT_3DO, longOptions[optionIndex].name, &options->whichShield) == -1) badArg = TRUE; break; case SCROLL_OPT: if (Check_PC_3DO_opt (optarg, OPT_PC | OPT_3DO, longOptions[optionIndex].name, &options->smoothScroll) == -1) badArg = TRUE; break; case SOUND_OPT: if (!strcmp (optarg, "openal")) options->soundDriver = audio_DRIVER_OPENAL; else if (!strcmp (optarg, "mixsdl")) options->soundDriver = audio_DRIVER_MIXSDL; else if (!strcmp (optarg, "none")) { options->soundDriver = audio_DRIVER_NOSOUND; options->speechVolumeScale = 0.0f; } else { log_add (log_Fatal, "Error: Invalid sound driver " "specified."); badArg = TRUE; } break; case STEREOSFX_OPT: options->stereoSFX = TRUE; break; case ADDON_OPT: options->numAddons++; options->addons = HRealloc ((void *) options->addons, (options->numAddons + 1) * sizeof (const char *)); options->addons[options->numAddons - 1] = optarg; options->addons[options->numAddons] = NULL; break; case ACCEL_OPT: force_platform = PLATFORM_NULL; if (!strcmp (optarg, "mmx")) force_platform = PLATFORM_MMX; else if (!strcmp (optarg, "sse")) force_platform = PLATFORM_SSE; else if (!strcmp (optarg, "3dnow")) force_platform = PLATFORM_3DNOW; else if (!strcmp (optarg, "none")) force_platform = PLATFORM_C; else if (strcmp (optarg, "detect") != 0) { InvalidArgument (optarg, "--accel"); badArg = TRUE; } break; #ifdef NETPLAY case NETHOST1_OPT: netplayOptions.peer[0].isServer = false; netplayOptions.peer[0].host = optarg; break; case NETPORT1_OPT: netplayOptions.peer[0].port = optarg; break; case NETHOST2_OPT: netplayOptions.peer[1].isServer = false; netplayOptions.peer[1].host = optarg; break; case NETPORT2_OPT: netplayOptions.peer[1].port = optarg; break; case NETDELAY_OPT: { if (parseIntOption (optarg, &netplayOptions.inputDelay, "network input delay") == -1) { badArg = TRUE; break; } if (netplayOptions.inputDelay > 60 * BATTLE_FRAME_RATE) { log_add (log_Fatal, "Network input delay is absurdly " "large."); badArg = TRUE; } break; } #endif default: log_add (log_Fatal, "Error: Invalid option '%s' not found.", longOptions[optionIndex].name); badArg = TRUE; break; } } if (optind != argc) { log_add (log_Fatal, "\nError: Extra arguments found on the command " "line."); badArg = TRUE; } if (badArg) { log_add (log_Fatal, "Run with -h to see the allowed arguments."); return EXIT_FAILURE; } return EXIT_SUCCESS; }