int main (int argc, char **argv) { // int i = 0; // char buf[MAXBUFSIZE]; int c = 0, option_index = 0; int x = 0, y = 0; struct option long_only_options[ARGS_MAX]; int result = 0; // const char *p = NULL; const st_property_t props[] = { { "ansi_color", "1", "use ANSI colors in output? (1=yes; 0=no)" }, { "default_cmdline", "", "will be used when quh is started w/o args" }, { "settings", "100", "internal settings like volume, etc." }, #if 0 { "quh_configdir", PROPERTY_MODE_DIR ("quh"), "directory with additional config files" }, #endif {NULL, NULL, NULL} }; memset (&quh, 0, sizeof (st_quh_t)); // defaults quh.pid = 1; tmpnam3 (quh.tmp_file, 0); set_suffix (quh.tmp_file, ".wav"); if(!(quh.o = cache_open (MAXBUFSIZE, CACHE_MEM|CACHE_LIFO))) { fprintf (stderr, "ERROR: Could not malloc %d bytes\n", MAXBUFSIZE); return -1; } realpath2 (PROPERTY_HOME_RC ("quh"), quh.configfile); result = property_check (quh.configfile, QUH_CONFIG_VERSION, 1); if (result == 1) // update needed result = set_property_array (quh.configfile, props); if (result == -1) // property_check() or update failed return -1; signal (SIGINT, quh_signal_handler); signal (SIGTERM, quh_signal_handler); atexit (quh_exit); quh.ansi_color = get_property_int (quh.configfile, "ansi_color"); quh.settings = get_property_int (quh.configfile, "settings"); quh.argc = argc; quh.argv = argv; #if 0 // memorize cmdline if (quh.argc > 2) { for (; quh.argv[i] && i < quh.argc; i++) sprintf (strchr (buf, 0), "%s ", quh.argv[i]); set_property (quh.configfile, "default_cmdline", buf, "will be used when quh is started w/o args"); } else { p = get_property (quh.configfile, "default_cmdline", PROPERTY_MODE_TEXT); if (p) { strncpy (buf, p, MAXBUFSIZE)[MAXBUFSIZE - 1] = 0; quh.argc = strarg (quh.argv, buf, " ", QUH_MAX_ARGS); } } #endif // set default filter chain filters = 0; quh.filter_id[filters++] = QUH_CACHE_PASS; quh.filter_id[filters++] = QUH_CONSOLE_PASS; #ifdef USE_ID3 // quh.filter_id[filters++] = QUH_ID3_IN; #endif // quh.filter_id[filters++] = QUH_CDDB_IN; #ifdef USE_OSS quh.filter_id[filters++] = QUH_OSS_OUT; #elif defined USE_SDL quh.filter_id[filters++] = QUH_SDL_OUT; #endif // convert (st_getopt2_t **) to (st_getopt2_t *) memset (&options, 0, sizeof (st_getopt2_t) * QUH_MAX_ARGS); for (c = x = 0; option[x]; x++) for (y = 0; option[x][y].name || option[x][y].help; y++) if (c < QUH_MAX_ARGS) { memcpy (&options[c], &option[x][y], sizeof (st_getopt2_t)); c++; } #if 0 for (x = 0; quh_decode_usage[x]; x++) if (c < QUH_MAX_ARGS) { memcpy (&options[c], quh_decode_usage[x], sizeof (st_getopt2_t)); c++; } #endif for (x = 0; quh_filter_usage[x]; x++) if (c < QUH_MAX_ARGS) { memcpy (&options[c], quh_filter_usage[x], sizeof (st_getopt2_t)); c++; } for (x = 0; option2[x]; x++) for (y = 0; option2[x][y].name || option2[x][y].help; y++) if (c < QUH_MAX_ARGS) { memcpy (&options[c], &option2[x][y], sizeof (st_getopt2_t)); c++; } getopt2_long_only (long_only_options, options, ARGS_MAX); #if 0 // if no options or filenames were specified we use a default cmdline if (argc < 2) // || !optind) { p = get_property (quh.configfile, "default_cmdline", PROPERTY_MODE_TEXT); if (p) { strncpy (quh.cmdline, p, ARGS_MAX)[ARGS_MAX - 1] = 0; quh.argc = strarg (quh.argv, quh.cmdline, " ", QUH_MAX_ARGS); } } else // store cmdline { strcpy (quh.cmdline, argv[0]); for (x = 1; x < argc; x++) sprintf (strchr (quh.cmdline, 0), " \"%s\"", quh.argv[x]); set_property (quh.configfile, "default_cmdline", quh.cmdline, NULL); } for (x = 0; x < quh.argc; x++) printf ("quh.argv[%d] == %s\n", x, quh.argv[x]); fflush (stdout); #endif while ((c = getopt_long_only (quh.argc, quh.argv, "", long_only_options, &option_index)) != -1) quh_opts (c); // if (quh.verbose) if (!quh.quiet) fputs ("Quh " QUH_VERSION_S " 'Having ears makes sense again' 2005-2006 by NoisyB\n" "This may be freely redistributed under the terms of the GNU Public License\n\n", stdout); if (quh.argc < 2) // || !optind) { getopt2_usage (options); return -1; } #warning files? #if 0 if (!getfile (quh.argc, quh.argv, quh_set_fname, (GETFILE_FILES_ONLY | (quh.flags & QUH_RECURSIVE ? GETFILE_RECURSIVE : 0)))) // recursively? { if (!quh.quiet) getopt2_usage (options); return -1; } #endif if (!quh.filter_id[0]) { fputs ("ERROR: you haven't specified any filters\n", stderr); fflush (stderr); return -1; } if (!quh.files) { fputs ("ERROR: you haven't specified any files to play\n", stderr); fflush (stderr); return -1; } if (!(quh.filter_chain = filter_malloc_chain (quh_filter))) { fputs ("ERROR: filter_malloc_chain() failed\n", stderr); fflush (stderr); return -1; } if (filter_init (quh.filter_chain, NULL, NULL) == -1) { fputs ("ERROR: filter_init() failed\n", stderr); fflush (stderr); return -1; } quh_play (); return 0; }
void ucon64_usage (int argc, char *argv[]) { int x = 0, y = 0, c = 0, single = 0; const char *name_exe = basename2 (argv[0]); #ifdef USE_DISCMAGE char *name_discmage; #endif (void) argc; // warning remover #ifdef USE_ZLIB printf ("Usage: %s [OPTION]... [ROM|IMAGE|SRAM|FILE|DIR|ARCHIVE]...\n\n", name_exe); #else printf ("Usage: %s [OPTION]... [ROM|IMAGE|SRAM|FILE|DIR]...\n\n", name_exe); #endif // single usage for (x = 0; arg[x].val; x++) if (arg[x].console) // IS console for (y = 0; option[y]; y++) for (c = 0; option[y][c].name || option[y][c].help; c++) if (option[y][c].object) if (((st_ucon64_obj_t *) option[y][c].object)->console == arg[x].console) { getopt2_usage (option[y]); single = 1; break; } if (!single) getopt2_usage (options); fputc ('\n', stdout); printf ("DATabase: %d known ROMs (DAT files: %s)\n\n", ucon64_dat_total_entries (), ucon64.datdir); #ifdef USE_DISCMAGE name_discmage = #ifdef DLOPEN ucon64.discmage_path; #else #if defined __MSDOS__ "discmage.dxe"; #elif defined __CYGWIN__ || defined _WIN32 "discmage.dll"; #elif defined __APPLE__ // Mac OS X actually "libdiscmage.dylib"; #elif defined __unix__ || defined __BEOS__ "libdiscmage.so"; #else "unknown"; #endif #endif if (!ucon64.discmage_enabled) { printf (ucon64_msg[NO_LIB], name_discmage); fputc ('\n', stdout); } #endif #ifdef USE_PARALLEL puts ("NOTE: You only need to specify PORT if uCON64 doesn't detect the (right)\n" " parallel port. If that is the case give a hardware address. For example:\n" " ucon64 " OPTION_LONG_S "xswc \"rom.swc\" " OPTION_LONG_S "port=0x378\n" " In order to connect a copier to a PC's parallel port you need a standard\n" " bidirectional parallel cable\n"); #endif printf ("TIP: %s " OPTION_LONG_S "help " OPTION_LONG_S "snes (would show only SNES related help)\n", name_exe); #if defined __MSDOS__ || defined _WIN32 printf (" %s " OPTION_LONG_S "help|more (to see everything in more)\n", name_exe); #else printf (" %s " OPTION_LONG_S "help|less (to see everything in less)\n", name_exe); // less is more ;-) #endif puts (" Give the force recognition switch a try if something went wrong\n" "\n" "Please report any problems/ideas/fixes to [email protected] or\n" "[email protected] or visit http://ucon64.sf.net\n"); }
static int quh_opts (int c) { int i = 0; // uint32_t flags = 0; int value = 0; static char buf[MAXBUFSIZE]; // const st_getopt2_t *p = NULL; switch (c) { case QUH_START: if (optarg) quh.start_optarg = optarg; break; case QUH_LEN: if (optarg) quh.len_optarg = optarg; break; case QUH_INTRO: quh.start_optarg = "60000"; quh.len_optarg = "10000"; break; case QUH_RR: quh.start_optarg = "min=0:max=eof"; if (optarg) quh.len_optarg = optarg; else quh.len_optarg = "min=500:max=1500"; quh.random = 1; quh.loop = 1; break; case QUH_BPM: if (optarg) { value = strtol (optarg, NULL, 10); // turn BPM into ms sprintf (buf, "%ld", (unsigned long) 60000 / value); quh.len_optarg = buf; } break; case QUH_V: quh.verbose = 1; break; case QUH_Q: quh.quiet = 1; break; case QUH_R: quh.flags |= QUH_RECURSIVE; break; case QUH_HELP: getopt2_usage (options); exit (0); case QUH_VER: fputs ("quh version: " QUH_VERSION_S "\n", stdout); case QUH_S: printf ("filter: %s\n", filter_get_all_id_s_in_array (quh_filter)); exit (0); case QUH_RANDOM: quh.random = 1; break; case QUH_LOOP: quh.loop = optarg ? strtol (optarg, NULL, 10) + 1 : 1; break; case QUH_SHUFFLE: quh.shuffle = 1; break; // filter case QUH_NEW: quh.filter_id[0] = 0; filters = 0; break; case QUH_STDOUT: case QUH_STDERR: quh.verbose = 0; quh.quiet = 1; #ifdef USE_GTK case QUH_GTK: #endif case QUH_CACHE: // case QUH_PIPE: #ifdef USE_ST case QUH_ST: #endif #ifdef USE_SDL case QUH_SDL: #endif #ifdef USE_OSS case QUH_OSS: #endif case QUH_RAW: #ifdef USE_CDDB case QUH_CDDB: #endif #ifdef USE_ID3 case QUH_ID3: #endif case QUH_WAV: #ifdef USE_JOYSTICK case QUH_JOY: #endif #ifdef USE_PCSPKR case QUH_SPEAKER: #endif #ifdef USE_ALSA case QUH_ALSA: #endif #ifdef USE_ESD case QUH_ESD: #endif case QUH_CONSOLE: #ifdef USE_CDDA case QUH_CDDA: #endif #ifdef USE_LIBAO case QUH_AO: #endif case QUH_VOL: case QUH_LYRICS: case QUH_ECHO: for (i = 0; quh_option[i].option; i++) if (quh_option[i].option == c) { if (quh_option[i].f) { quh.filter_id[filters] = quh_option[i].f->id; if (optarg) if (*optarg) quh.filter_option[filters] = optarg; quh.filter_id[++filters] = 0; } break; } break; default: printf ("Try '%s --help' for more information.\n", quh.argv[0]); exit (-1); } return 0; }