mirror of
https://github.com/kanjitalk755/macemu.git
synced 2024-12-19 09:31:26 +00:00
- added help for command line options
- PrefsInit() removes all processed options
This commit is contained in:
parent
5ffe6505dc
commit
e0307117d2
@ -1,4 +1,6 @@
|
||||
V0.9 - <insert date here>
|
||||
- added help for command line arguments, PrefsInit() now removes
|
||||
all processed options
|
||||
- Unix: some performance improvements to VOSF screen update code
|
||||
[Brian J. Johnson]
|
||||
- Unix: -Ofast option is supplied to MIPSPro compiler [Brian J. Johnson]
|
||||
|
@ -26,8 +26,8 @@
|
||||
|
||||
// Platform-specific preferences items
|
||||
prefs_desc platform_prefs_items[] = {
|
||||
{"sound", TYPE_STRING, false}, // Sound output mode description (audio_amiga.cpp)
|
||||
{NULL, TYPE_END, false} // End of list
|
||||
{"sound", TYPE_STRING, false, "sound output mode description"},
|
||||
{NULL, TYPE_END, false, NULL} // End of list
|
||||
};
|
||||
|
||||
|
||||
|
@ -30,8 +30,8 @@
|
||||
|
||||
// Platform-specific preferences items
|
||||
prefs_desc platform_prefs_items[] = {
|
||||
{"powerrom", TYPE_STRING, false}, // Path of PowerMac ROM (powerrom_cpu.cpp)
|
||||
{NULL, TYPE_END, false} // End of list
|
||||
{"powerrom", TYPE_STRING, false, "path of PowerMac ROM"},
|
||||
{NULL, TYPE_END, false, NULL} // End of list
|
||||
};
|
||||
|
||||
|
||||
|
@ -195,6 +195,17 @@ char *strdup(const char *s)
|
||||
* Main program
|
||||
*/
|
||||
|
||||
static void usage(const char *prg_name)
|
||||
{
|
||||
printf("Usage: %s [OPTION...]\n", prg_name);
|
||||
printf("\nUnix options:\n");
|
||||
printf(" --display STRING\n X display to use\n");
|
||||
printf(" --break ADDRESS\n set ROM breakpoint\n");
|
||||
printf(" --rominfo\n dump ROM information\n");
|
||||
PrefsPrintUsage();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char str[256];
|
||||
@ -216,35 +227,26 @@ int main(int argc, char **argv)
|
||||
x_display_name = gdk_get_display(); // gtk_init() handles and removes the "--display" argument
|
||||
#endif
|
||||
|
||||
// Parse and remove arguments
|
||||
// Read preferences
|
||||
PrefsInit(argc, argv);
|
||||
|
||||
// Parse command line arguments
|
||||
for (int i=1; i<argc; i++) {
|
||||
if (strcmp(argv[i], "--display") == 0) {
|
||||
argv[i] = NULL;
|
||||
if ((i + 1) < argc && argv[i + 1]) {
|
||||
argv[i++] = NULL;
|
||||
if (strcmp(argv[i], "--help") == 0) {
|
||||
usage(argv[0]);
|
||||
} else if (strcmp(argv[i], "--display") == 0) {
|
||||
i++;
|
||||
if (i < argc)
|
||||
x_display_name = strdup(argv[i]);
|
||||
}
|
||||
} else if (strcmp(argv[i], "--break") == 0) {
|
||||
argv[i] = NULL;
|
||||
if ((i + 1) < argc && argv[i + 1]) {
|
||||
argv[i++] = NULL;
|
||||
i++;
|
||||
if (i < argc)
|
||||
ROMBreakpoint = strtol(argv[i], NULL, 0);
|
||||
}
|
||||
} else if (strcmp(argv[i], "--rominfo") == 0) {
|
||||
argv[i] = NULL;
|
||||
PrintROMInfo = true;
|
||||
}
|
||||
}
|
||||
for (int i=1; i<argc; i++) {
|
||||
int k;
|
||||
for (k=i; k<argc; k++)
|
||||
if (argv[k] != NULL)
|
||||
break;
|
||||
if (k > i) {
|
||||
k -= i;
|
||||
for (int j=i+k; j<argc; j++)
|
||||
argv[j-k] = argv[j];
|
||||
argc -= k;
|
||||
} else if (argv[i][0] == '-') {
|
||||
fprintf(stderr, "Unrecognized option '%s'\n", argv[i]);
|
||||
usage(argv[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -262,9 +264,6 @@ int main(int argc, char **argv)
|
||||
XF86DGAForkApp(DefaultScreen(x_display));
|
||||
#endif
|
||||
|
||||
// Read preferences
|
||||
PrefsInit(argc, argv);
|
||||
|
||||
// Init system routines
|
||||
SysInit();
|
||||
|
||||
|
@ -28,12 +28,12 @@
|
||||
|
||||
// Platform-specific preferences items
|
||||
prefs_desc platform_prefs_items[] = {
|
||||
{"keycodes", TYPE_BOOLEAN, false}, // Use keycodes rather than keysyms to decode keyboard (video_x.cpp)
|
||||
{"keycodefile", TYPE_STRING, false}, // File name of keycode translation table (video_x.cpp)
|
||||
{"fbdevicefile", TYPE_STRING, false}, // File name of frame buffer device specifications (video_x.cpp)
|
||||
{"mousewheelmode", TYPE_INT32, false}, // Mouse wheel support mode (0=Page up/down, 1=Cursor up/down) (video_x.cpp)
|
||||
{"mousewheellines", TYPE_INT32, false}, // Number of lines to scroll in mouse whell mode 1 (video_x.cpp)
|
||||
{NULL, TYPE_END, false} // End of list
|
||||
{"keycodes", TYPE_BOOLEAN, false, "use keycodes rather than keysyms to decode keyboard"},
|
||||
{"keycodefile", TYPE_STRING, false, "path of keycode translation file"},
|
||||
{"fbdevicefile", TYPE_STRING, false, "path of frame buffer device specification file"},
|
||||
{"mousewheelmode", TYPE_INT32, false, "mouse wheel support mode (0=page up/down, 1=cursor up/down)"},
|
||||
{"mousewheellines", TYPE_INT32, false, "number of lines to scroll in mouse wheel mode 1"},
|
||||
{NULL, TYPE_END, false, NULL} // End of list
|
||||
};
|
||||
|
||||
|
||||
|
@ -23,9 +23,11 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
extern void PrefsInit(int argc, char **argv);
|
||||
extern void PrefsInit(int &argc, char **&argv);
|
||||
extern void PrefsExit(void);
|
||||
|
||||
extern void PrefsPrintUsage(void);
|
||||
|
||||
extern void AddPrefsDefaults(void);
|
||||
extern void AddPlatformPrefsDefaults(void);
|
||||
|
||||
@ -70,6 +72,7 @@ struct prefs_desc {
|
||||
const char *name; // Name of keyword
|
||||
prefs_type type; // Type (see above)
|
||||
bool multiple; // Can this item occur multiple times (only for TYPE_STRING)?
|
||||
const char *help; // Help/descriptive text about this item
|
||||
};
|
||||
|
||||
// List of common preferences items (those which exist on all platforms)
|
||||
|
@ -47,7 +47,7 @@ static const prefs_desc *find_prefs_desc(const char *name);
|
||||
* Initialize preferences
|
||||
*/
|
||||
|
||||
void PrefsInit(int argc, char **argv)
|
||||
void PrefsInit(int &argc, char **&argv)
|
||||
{
|
||||
// Set defaults
|
||||
AddPrefsDefaults();
|
||||
@ -56,57 +56,71 @@ void PrefsInit(int argc, char **argv)
|
||||
// Load preferences from settings file
|
||||
LoadPrefs();
|
||||
|
||||
// Override prefs with command line arguments
|
||||
argc--; argv++;
|
||||
for (; argc>0; argc--, argv++) {
|
||||
// Override prefs with command line options
|
||||
for (int i=1; i<argc; i++) {
|
||||
|
||||
// Arguments are of the form '--keyword'
|
||||
if (strlen(*argv) < 3 || argv[0][0] != '-' || argv[0][1] != '-') {
|
||||
printf("WARNING: Unrecognized argument '%s'\n", *argv);
|
||||
// Options are of the form '--keyword'
|
||||
const char *option = argv[i];
|
||||
if (strlen(option) < 3 || option[0] != '-' || option[1] != '-')
|
||||
continue;
|
||||
}
|
||||
const char *keyword = *argv + 2;
|
||||
const char *keyword = option + 2;
|
||||
|
||||
// Find descriptor for keyword
|
||||
const prefs_desc *d = find_prefs_desc(keyword);
|
||||
if (d == NULL) {
|
||||
printf("WARNING: Unrecognized argument '%s'\n", *argv);
|
||||
if (d == NULL)
|
||||
continue;
|
||||
argv[i] = NULL;
|
||||
|
||||
// Get value
|
||||
i++;
|
||||
if (i >= argc) {
|
||||
fprintf(stderr, "Option '%s' must be followed by a value\n", option);
|
||||
continue;
|
||||
}
|
||||
const char *value = argv[i];
|
||||
argv[i] = NULL;
|
||||
|
||||
// Add/replace prefs item
|
||||
switch (d->type) {
|
||||
case TYPE_STRING:
|
||||
if (argc < 2) {
|
||||
printf("WARNING: Argument '%s' must be followed by value\n", *argv);
|
||||
break;
|
||||
}
|
||||
argc--; argv++;
|
||||
if (d->multiple)
|
||||
PrefsAddString(keyword, *argv);
|
||||
PrefsAddString(keyword, value);
|
||||
else
|
||||
PrefsReplaceString(keyword, *argv);
|
||||
PrefsReplaceString(keyword, value);
|
||||
break;
|
||||
|
||||
case TYPE_BOOLEAN:
|
||||
if (argc > 1 && argv[1][0] != '-') {
|
||||
argc--; argv++;
|
||||
PrefsReplaceBool(keyword, !strcmp(*argv, "true") || !strcmp(*argv, "on"));
|
||||
} else
|
||||
case TYPE_BOOLEAN: {
|
||||
if (!strcmp(value, "true") || !strcmp(value, "on") || !strcmp(value, "yes"))
|
||||
PrefsReplaceBool(keyword, true);
|
||||
else if (!strcmp(value, "false") || !strcmp(value, "off") || !strcmp(value, "no"))
|
||||
PrefsReplaceBool(keyword, false);
|
||||
else
|
||||
fprintf(stderr, "Value for option '%s' must be 'true' or 'false'\n", option);
|
||||
break;
|
||||
}
|
||||
|
||||
case TYPE_INT32:
|
||||
if (argc < 2) {
|
||||
printf("WARNING: Argument '%s' must be followed by value\n", *argv);
|
||||
break;
|
||||
}
|
||||
argc--; argv++;
|
||||
PrefsReplaceInt32(keyword, atoi(*argv));
|
||||
PrefsReplaceInt32(keyword, atoi(value));
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove processed arguments
|
||||
for (int i=1; i<argc; i++) {
|
||||
int k;
|
||||
for (k=i; k<argc; k++)
|
||||
if (argv[k] != NULL)
|
||||
break;
|
||||
if (k > i) {
|
||||
k -= i;
|
||||
for (int j=i+k; j<argc; j++)
|
||||
argv[j-k] = argv[j];
|
||||
argc -= k;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -128,6 +142,56 @@ void PrefsExit(void)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Print preferences options help
|
||||
*/
|
||||
|
||||
static void print_options(const prefs_desc *list)
|
||||
{
|
||||
while (list->type != TYPE_END) {
|
||||
if (list->help) {
|
||||
const char *typestr, *defstr;
|
||||
char numstr[32];
|
||||
switch (list->type) {
|
||||
case TYPE_STRING:
|
||||
typestr = "STRING";
|
||||
defstr = PrefsFindString(list->name);
|
||||
if (defstr == NULL)
|
||||
defstr = "none";
|
||||
break;
|
||||
case TYPE_BOOLEAN:
|
||||
typestr = "BOOL";
|
||||
if (PrefsFindBool(list->name))
|
||||
defstr = "true";
|
||||
else
|
||||
defstr = "false";
|
||||
break;
|
||||
case TYPE_INT32:
|
||||
typestr = "NUMBER";
|
||||
sprintf(numstr, "%d", PrefsFindInt32(list->name));
|
||||
defstr = numstr;
|
||||
break;
|
||||
default:
|
||||
typestr = "<unknown>";
|
||||
defstr = "none";
|
||||
break;
|
||||
}
|
||||
printf(" --%s %s\n %s [default=%s]\n", list->name, typestr, list->help, defstr);
|
||||
}
|
||||
list++;
|
||||
}
|
||||
}
|
||||
|
||||
void PrefsPrintUsage(void)
|
||||
{
|
||||
printf("\nGeneral options:\n");
|
||||
print_options(common_prefs_items);
|
||||
printf("\nPlatform-specific options:\n");
|
||||
print_options(platform_prefs_items);
|
||||
printf("\nBoolean options are specified as '--OPTION true|on|yes' or\n'--OPTION false|off|no'.\n");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Find preferences descriptor by keyword
|
||||
*/
|
||||
|
@ -28,34 +28,34 @@
|
||||
// Except for "disk", "floppy", "cdrom", "scsiX", "screen", "rom" and "ether",
|
||||
// these are guaranteed to be in the prefs.
|
||||
prefs_desc common_prefs_items[] = {
|
||||
{"disk", TYPE_STRING, true}, // Device/file names of Mac volumes (disk.cpp)
|
||||
{"floppy", TYPE_STRING, true}, // Device/file names of Mac floppy drives (sony.cpp)
|
||||
{"cdrom", TYPE_STRING, true}, // Device/file names of Mac CD-ROM drives (cdrom.cpp)
|
||||
{"extfs", TYPE_STRING, false}, // Root path of ExtFS (extfs.cpp)
|
||||
{"scsi0", TYPE_STRING, false}, // SCSI targets for Mac SCSI ID 0..6 (scsi_*.cpp)
|
||||
{"scsi1", TYPE_STRING, false},
|
||||
{"scsi2", TYPE_STRING, false},
|
||||
{"scsi3", TYPE_STRING, false},
|
||||
{"scsi4", TYPE_STRING, false},
|
||||
{"scsi5", TYPE_STRING, false},
|
||||
{"scsi6", TYPE_STRING, false},
|
||||
{"screen", TYPE_STRING, false}, // Video mode (video.cpp)
|
||||
{"seriala", TYPE_STRING, false}, // Device name of Mac serial port A (serial_*.cpp)
|
||||
{"serialb", TYPE_STRING, false}, // Device name of Mac serial port B (serial_*.cpp)
|
||||
{"ether", TYPE_STRING, false}, // Device name of Mac ethernet adapter (ether_*.cpp)
|
||||
{"rom", TYPE_STRING, false}, // Path of ROM file (main_*.cpp)
|
||||
{"bootdrive", TYPE_INT32, false}, // Boot drive number (main.cpp)
|
||||
{"bootdriver", TYPE_INT32, false}, // Boot driver number (main.cpp)
|
||||
{"ramsize", TYPE_INT32, false}, // Size of Mac RAM in bytes (main_*.cpp)
|
||||
{"frameskip", TYPE_INT32, false}, // Number of frames to skip in refreshed video modes (video_*.cpp)
|
||||
{"modelid", TYPE_INT32, false}, // Mac Model ID (Gestalt Model ID minus 6) (rom_patches.cpp)
|
||||
{"cpu", TYPE_INT32, false}, // CPU type (0 = 68000, 1 = 68010 etc.) (main.cpp)
|
||||
{"fpu", TYPE_BOOLEAN, false}, // Enable FPU emulation (main.cpp)
|
||||
{"nocdrom", TYPE_BOOLEAN, false}, // Don't install CD-ROM driver (cdrom.cpp/rom_patches.cpp)
|
||||
{"nosound", TYPE_BOOLEAN, false}, // Don't enable sound output (audio_*.cpp)
|
||||
{"noclipconversion", TYPE_BOOLEAN, false}, // Don't convert clipboard contents (clip_*.cpp)
|
||||
{"nogui", TYPE_BOOLEAN, false}, // Disable GUI (main_*.cpp)
|
||||
{NULL, TYPE_END, false} // End of list
|
||||
{"disk", TYPE_STRING, true, "device/file name of Mac volume"},
|
||||
{"floppy", TYPE_STRING, true, "device/file name of Mac floppy drive"},
|
||||
{"cdrom", TYPE_STRING, true, "device/file names of Mac CD-ROM drive"},
|
||||
{"extfs", TYPE_STRING, false, "root path of ExtFS"},
|
||||
{"scsi0", TYPE_STRING, false, "SCSI target for Mac SCSI ID 0"},
|
||||
{"scsi1", TYPE_STRING, false, "SCSI target for Mac SCSI ID 1"},
|
||||
{"scsi2", TYPE_STRING, false, "SCSI target for Mac SCSI ID 2"},
|
||||
{"scsi3", TYPE_STRING, false, "SCSI target for Mac SCSI ID 3"},
|
||||
{"scsi4", TYPE_STRING, false, "SCSI target for Mac SCSI ID 4"},
|
||||
{"scsi5", TYPE_STRING, false, "SCSI target for Mac SCSI ID 5"},
|
||||
{"scsi6", TYPE_STRING, false, "SCSI target for Mac SCSI ID 6"},
|
||||
{"screen", TYPE_STRING, false, "video mode"},
|
||||
{"seriala", TYPE_STRING, false, "device name of Mac serial port A"},
|
||||
{"serialb", TYPE_STRING, false, "device name of Mac serial port B"},
|
||||
{"ether", TYPE_STRING, false, "device name of Mac ethernet adapter"},
|
||||
{"rom", TYPE_STRING, false, "path of ROM file"},
|
||||
{"bootdrive", TYPE_INT32, false, "boot drive number"},
|
||||
{"bootdriver", TYPE_INT32, false, "boot driver number"},
|
||||
{"ramsize", TYPE_INT32, false, "size of Mac RAM in bytes"},
|
||||
{"frameskip", TYPE_INT32, false, "number of frames to skip in refreshed video modes"},
|
||||
{"modelid", TYPE_INT32, false, "Mac Model ID (Gestalt Model ID minus 6)"},
|
||||
{"cpu", TYPE_INT32, false, "CPU type (0 = 68000, 1 = 68010 etc.)"},
|
||||
{"fpu", TYPE_BOOLEAN, false, "enable FPU emulation"},
|
||||
{"nocdrom", TYPE_BOOLEAN, false, "don't install CD-ROM driver"},
|
||||
{"nosound", TYPE_BOOLEAN, false, "don't enable sound output"},
|
||||
{"noclipconversion", TYPE_BOOLEAN, false, "don't convert clipboard contents"},
|
||||
{"nogui", TYPE_BOOLEAN, false, "disable GUI"},
|
||||
{NULL, TYPE_END, false, NULL} // End of list
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user