示例#1
0
BYTE cmd_line_parse(int argc, char **argv) {
	int longIndex = 0, opt = 0;

	opt = getopt_long(argc, argv, opt_short, opt_long, &longIndex);
	while (opt != -1) {
		switch (opt) {
			case 0:
				/* long options */
				if (!(strcmp(opt_long[longIndex].name, "swap-duty"))) {
					set_int(cfg_from_file.swap_duty, SET_SWAP_DUTY);
				} else if (!(strcmp(opt_long[longIndex].name, "swap-emphasis"))) {
					set_int(cfg_from_file.disable_swap_emphasis_pal, SET_SWAP_EMPHASIS_PAL);
				} else if (!(strcmp(opt_long[longIndex].name, "portable"))) {
					/* l'ho gia' controllato quindi qui non faccio niente */
				} else if (!(strcmp(opt_long[longIndex].name, "txt-on-screen"))) {
					set_int(cfg_from_file.txt_on_screen, SET_TEXT_ON_SCREEN);
				} else if (!(strcmp(opt_long[longIndex].name, "overscan-brd-ntsc"))) {
					set_oscan(SET_OVERSCAN_BRD_NTSC, 0);
				} else if (!(strcmp(opt_long[longIndex].name, "overscan-brd-pal"))) {
					set_oscan(SET_OVERSCAN_BRD_PAL, 1);
				} else if (!(strcmp(opt_long[longIndex].name, "par-soft-stretch"))) {
					set_int(cfg_from_file.PAR_soft_stretch, SET_PAR_SOFT_STRETCH);
				} else if (!(strcmp(opt_long[longIndex].name, "background-pause"))) {
					set_int(cfg_from_file.bck_pause, SET_BCK_PAUSE);
				} else if (!(strcmp(opt_long[longIndex].name, "language"))) {
					set_int(cfg_from_file.language, SET_GUI_LANGUAGE);
				}
				break;
			case 'a':
				set_int(cfg_from_file.apu.channel[APU_MASTER], SET_AUDIO);
				break;
			case 'b':
				set_int(cfg_from_file.audio_buffer_factor, SET_AUDIO_BUFFER_FACTOR);
				break;
			case 'c':
				set_int(cfg_from_file.channels_mode, SET_CHANNELS);
				break;
			case 'd':
				cfg_from_file.stereo_delay = set_double(5);
				break;
			case 'f':
				set_int(cfg_from_file.fps, SET_FPS);
				break;
			case 'g':
				set_int(cfg_from_file.cheat_mode, SET_CHEAT_MODE);
				break;
			case 'h':
			case '?':
				usage(basename(argv[0]));
				break;
			case 'V': {
				if (!info.portable) {
					fprintf(stdout, "%s %s\n", NAME, VERSION);
				} else {
					fprintf(stdout, "Portable %s %s\n", NAME, VERSION);
				}
				emu_quit(EXIT_SUCCESS);
				break;
			}
			case 'k':
				set_int(cfg_from_file.frameskip, SET_FRAMESKIP);
				break;
			case 'i':
				set_int(cfg_from_file.filter, SET_FILTER);
				break;
			case 'l':
				set_int(cfg_from_file.samplerate, SET_SAMPLERATE);
				break;
			case 'm':
				set_int(cfg_from_file.mode, SET_MODE);
				break;
			case 'n':
				set_int(cfg_from_file.ntsc_format, SET_NTSC_FORMAT);
				break;
			case 'o':
				set_int(cfg_from_file.oscan, SET_OVERSCAN_DEFAULT);
				break;
			case 'p':
				set_int(cfg_from_file.palette, SET_PALETTE);
				break;
			case 'q':
				set_int(cfg_from_file.audio_quality, SET_AUDIO_QUALITY);
				break;
#if defined (WITH_OPENGL)
			case 'r':
				set_int(cfg_from_file.render, SET_RENDERING);
				gfx_set_render(cfg_from_file.render);
				break;
#endif
			case 's':
				set_int(cfg_from_file.scale, SET_SCALE);
				gfx.scale_before_fscreen = cfg_from_file.scale;
				break;
			case 't':
				{
					int rc = settings_val_to_int(SET_STRETCH_FULLSCREEN, optarg);

					if (rc >= 0) {
						cfg_from_file.scale = !rc;
					}
				}
				break;
			case 'u':
				set_int(cfg_from_file.fullscreen, SET_FULLSCREEN);
				break;
			case 'v':
				set_int(cfg_from_file.vsync, SET_VSYNC);
				break;
			case 'e':
				set_int(cfg_from_file.pixel_aspect_ratio, SET_PAR);
				break;
			case 'j':
				set_int(cfg_from_file.interpolation, SET_INTERPOLATION);
				break;
			default:
				break;
		}

		opt = getopt_long(argc, argv, opt_short, opt_long, &longIndex);
	}
	return (optind);
}
示例#2
0
void cmd_line_parse(int argc, uTCHAR **argv) {
	QStringList splitted;
	QString arg, key, skey, value, exe = QFileInfo(uQString(argv[0])).baseName();
	int opt = 0;

	for (int a = 1; a < argc; a++) {
		arg = uQString(argv[a]);
		splitted = arg.split("=");
		key = QString(splitted.at(0));

		if (key.startsWith("--") || key.startsWith("-")) {
			key = key.replace("-", "");

			for (unsigned int b = 0; b < LENGTH(opt_long); b++) {
				if ((opt_long[b].lopt == key) || (opt_long[b].sopt == key)) {
					skey = opt_long[b].sopt;
					if (opt_long[b].ra == req_arg) {
						if (splitted.count() > 1) {
							value = QString(splitted.at(1));
						} else {
							if ((a + 1) >= argc) {
								QMessageBox::warning(0,
									"Error",
									QString("%1: the option needs an arguments -- \"%2\"").arg(exe, key));
								usage(exe);
							} else {
								value = uQString(argv[++a]);
							}
						}
					}
					opt = (*((char *) skey.toLatin1().constData()));
				}
			}
		} else {
			umemset(info.rom_file, 0x00, usizeof(info.rom_file));
			ustrncpy(info.rom_file, uQStringCD(key), usizeof(info.rom_file) - 1);
			continue;
		}

		switch (opt) {
			case 0:
				// long options
				if (key == "swap-duty") {
					set_int(cfg_from_file.swap_duty, SET_SWAP_DUTY);
				} else if (key == "swap-emphasis") {
					set_int(cfg_from_file.disable_swap_emphasis_pal, SET_SWAP_EMPHASIS_PAL);
				} else if (key == "portable") {
					// l'ho gia' controllato quindi qui non faccio niente
				} else if (key == "txt-on-screen") {
					set_int(cfg_from_file.txt_on_screen, SET_TEXT_ON_SCREEN);
				} else if (key == "input-display") {
					set_int(cfg_from_file.input_display, SET_INPUT_DISPLAY);
				} else if (key == "disable-tv-noise") {
					set_int(cfg_from_file.disable_tv_noise, SET_DISABLE_TV_NOISE);
				} else if (key == "disable-sepia") {
					set_int(cfg_from_file.disable_sepia_color, SET_DISABLE_SEPIA_PAUSE);
#if defined (WITH_OPENGL)
				} else if (key == "disable-srgb-fbo") {
					set_int(cfg_from_file.disable_srgb_fbo, SET_DISABLE_SRGB_FBO);
#endif
				} else if (key == "overscan-brd-ntsc") {
					set_oscan(SET_OVERSCAN_BRD_NTSC, 0);
				} else if (key == "overscan-brd-pal") {
					set_oscan(SET_OVERSCAN_BRD_PAL, 1);
				} else if (key == "par-soft-stretch") {
					set_int(cfg_from_file.PAR_soft_stretch, SET_PAR_SOFT_STRETCH);
				} else if (key == "hide-sprites") {
					set_int(cfg_from_file.hide_sprites, SET_HIDE_SPRITES);
				} else if (key == "hide-background") {
					set_int(cfg_from_file.hide_background, SET_HIDE_BACKGROUND);
				} else if (key == "unlimited-sprites") {
					set_int(cfg_from_file.unlimited_sprites, SET_UNLIMITED_SPRITES);
				} else if (key == "save-battery-ram-file") {
					set_int(cfg_from_file.save_battery_ram_file, SET_BATTERY_RAM_FILE_EVEY_TOT);
				} else if (key == "background-pause") {
					set_int(cfg_from_file.bck_pause, SET_BCK_PAUSE);
				} else if (key == "language") {
					set_int(cfg_from_file.language, SET_GUI_LANGUAGE);
				} else if (key == "disable-new-menu") {
					set_int(cfg_from_file.disable_new_menu, SET_GUI_DISABLE_NEW_MENU);
				}
				break;
			case 'a':
				set_int(cfg_from_file.apu.channel[APU_MASTER], SET_AUDIO);
				break;
			case 'b':
				set_int(cfg_from_file.audio_buffer_factor, SET_AUDIO_BUFFER_FACTOR);
				break;
			case 'c':
				set_int(cfg_from_file.channels_mode, SET_CHANNELS);
				break;
			case 'd':
				cfg_from_file.stereo_delay = set_double(5);
				break;
			case 'f':
				set_int(cfg_from_file.fps, SET_FPS);
				break;
			case 'g':
				set_int(cfg_from_file.cheat_mode, SET_CHEAT_MODE);
				break;
			case 'h':
			case '?':
				usage(exe);
				break;
			case 'V': {
				if (!info.portable) {
					fprintf(stdout, "%s %s\n", NAME, VERSION);
				} else {
					fprintf(stdout, "Portable %s %s\n", NAME, VERSION);
				}
				emu_quit(EXIT_SUCCESS);
				break;
			}
			case 'k':
				set_int(cfg_from_file.frameskip, SET_FRAMESKIP);
				break;
			case 'i':
				set_int(cfg_from_file.filter, SET_FILTER);
				break;
			case 'l':
				set_int(cfg_from_file.samplerate, SET_SAMPLERATE);
				break;
			case 'm':
				set_int(cfg_from_file.mode, SET_MODE);
				break;
			case 'n':
				set_int(cfg_from_file.ntsc_format, SET_NTSC_FORMAT);
				break;
			case 'o':
				set_int(cfg_from_file.oscan, SET_OVERSCAN_DEFAULT);
				break;
			case 'p':
				set_int(cfg_from_file.palette, SET_PALETTE);
				break;
			case 'q':
				set_int(cfg_from_file.audio_quality, SET_AUDIO_QUALITY);
				break;
#if defined (WITH_OPENGL)
			case 'r':
				set_int(cfg_from_file.render, SET_RENDERING);
				gfx_set_render(cfg_from_file.render);
				break;
#endif
			case 's':
				set_int(cfg_from_file.scale, SET_SCALE);
				gfx.scale_before_fscreen = cfg_from_file.scale;
				break;
			case 't':
				{
					int rc = settings_val_to_int(SET_STRETCH_FULLSCREEN, oarg);

					if (rc >= 0) {
						cfg_from_file.scale = !rc;
					}
				}
				break;
			case 'u':
				set_int(cfg_from_file.fullscreen, SET_FULLSCREEN);
				break;
			case 'v':
				set_int(cfg_from_file.vsync, SET_VSYNC);
				break;
			case 'e':
				set_int(cfg_from_file.pixel_aspect_ratio, SET_PAR);
				break;
			case 'j':
				set_int(cfg_from_file.interpolation, SET_INTERPOLATION);
				break;
			default:
				break;
		}
	}
}