int main(int argc, char **argv) { int optind; char **playlist_array; int items; struct stat stat_buf; int i; setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); ao_initialize(); stat_format = stat_format_create(); options_init(&options); file_options_init(file_opts); parse_std_configs(file_opts); options.playlist = playlist_create(); optind = parse_cmdline_options(argc, argv, &options, file_opts); audio_play_arg.devices = options.devices; audio_play_arg.stat_format = stat_format; /* Add remaining arguments to playlist */ for (i = optind; i < argc; i++) { if (stat(argv[i], &stat_buf) == 0) { if (S_ISDIR(stat_buf.st_mode)) { if (playlist_append_directory(options.playlist, argv[i]) == 0) fprintf(stderr, _("Warning: Could not read directory %s.\n"), argv[i]); } else { playlist_append_file(options.playlist, argv[i]); } } else /* If we can't stat it, it might be a non-disk source */ playlist_append_file(options.playlist, argv[i]); } /* Do we have anything left to play? */ if (playlist_length(options.playlist) == 0) { cmdline_usage(); exit(1); } else { playlist_array = playlist_to_array(options.playlist, &items); playlist_destroy(options.playlist); options.playlist = NULL; } /* Don't use status_message until after this point! */ status_set_verbosity(options.verbosity); print_audio_devices_info(options.devices); /* Setup buffer */ if (options.buffer_size > 0) { audio_buffer = buffer_create(options.buffer_size, options.buffer_size * options.prebuffer / 100, audio_play_callback, &audio_play_arg, AUDIO_CHUNK_SIZE); if (audio_buffer == NULL) { status_error(_("Error: Could not create audio buffer.\n")); exit(1); } } else audio_buffer = NULL; /* Shuffle playlist */ if (options.shuffle) { int i; srandom(time(NULL)); for (i = 0; i < items; i++) { int j = i + random() % (items - i); char *temp = playlist_array[i]; playlist_array[i] = playlist_array[j]; playlist_array[j] = temp; } } /* Setup signal handlers and callbacks */ ATEXIT (exit_cleanup); signal (SIGINT, signal_handler); signal (SIGTSTP, signal_handler); signal (SIGCONT, signal_handler); signal (SIGTERM, signal_handler); /* Play the files/streams */ i = 0; while (i < items && !sig_request.exit) { play(playlist_array[i]); i++; } playlist_array_destroy(playlist_array, items); exit (0); }
int parse_cmdline_options (int argc, char **argv, ogg123_options_t *ogg123_opts, file_option_t *file_opts) { int option_index = 1; ao_option *temp_options = NULL; ao_option ** current_options = &temp_options; ao_info *info; int temp_driver_id = -1; audio_device_t *current; int ret; while (-1 != (ret = getopt_long(argc, argv, "b:c::d:f:hl:k:K:o:p:qvVx:y:z@:", long_options, &option_index))) { switch (ret) { case 0: if(!strcmp(long_options[option_index].name, "audio-buffer")) { ogg123_opts->buffer_size = 1024 * atoi(optarg); } else { status_error(_("Internal error parsing command line options.\n")); exit(1); } break; case 'b': ogg123_opts->input_buffer_size = atoi(optarg) * 1024; if (ogg123_opts->input_buffer_size < MIN_INPUT_BUFFER_SIZE * 1024) { status_error(_("Input buffer size smaller than minimum size of %dkB."), MIN_INPUT_BUFFER_SIZE); ogg123_opts->input_buffer_size = MIN_INPUT_BUFFER_SIZE * 1024; } break; case 'c': if (optarg) { char *tmp = strdup (optarg); parse_code_t pcode = parse_line(file_opts, tmp); if (pcode != parse_ok) status_error(_("=== Error \"%s\" while parsing config option from command line.\n" "=== Option was: %s\n"), parse_error_string(pcode), optarg); free (tmp); } else { /* not using the status interface here */ fprintf (stdout, _("Available options:\n")); file_options_describe(file_opts, stdout); exit (0); } break; case 'd': temp_driver_id = ao_driver_id(optarg); if (temp_driver_id < 0) { status_error(_("=== No such device %s.\n"), optarg); exit(1); } current = append_audio_device(ogg123_opts->devices, temp_driver_id, NULL, NULL); if(ogg123_opts->devices == NULL) ogg123_opts->devices = current; current_options = ¤t->options; break; case 'f': if (temp_driver_id >= 0) { info = ao_driver_info(temp_driver_id); if (info->type == AO_TYPE_FILE) { free(current->filename); current->filename = strdup(optarg); } else { status_error(_("=== Driver %s is not a file output driver.\n"), info->short_name); exit(1); } } else { status_error(_("=== Cannot specify output file without specifying a driver.\n")); exit (1); } break; case 'k': ogg123_opts->seekpos = strtotime(optarg); break; case 'K': ogg123_opts->endpos = strtotime(optarg); break; case 'l': ogg123_opts->delay = atoi(optarg); break; case 'o': if (optarg && !add_ao_option(current_options, optarg)) { status_error(_("=== Incorrect option format: %s.\n"), optarg); exit(1); } break; case 'h': cmdline_usage(); exit(0); break; case 'p': ogg123_opts->input_prebuffer = atof (optarg); if (ogg123_opts->input_prebuffer < 0.0f || ogg123_opts->input_prebuffer > 100.0f) { status_error (_("--- Prebuffer value invalid. Range is 0-100.\n")); ogg123_opts->input_prebuffer = ogg123_opts->input_prebuffer < 0.0f ? 0.0f : 100.0f; } break; case 'q': ogg123_opts->verbosity = 0; break; case 'v': ogg123_opts->verbosity++; break; case 'V': status_error(_("ogg123 from %s %s\n"), PACKAGE, VERSION); exit(0); break; case 'x': ogg123_opts->nth = atoi(optarg); if (ogg123_opts->nth == 0) { status_error(_("--- Cannot play every 0th chunk!\n")); ogg123_opts->nth = 1; } break; case 'y': ogg123_opts->ntimes = atoi(optarg); if (ogg123_opts->ntimes == 0) { status_error(_("--- Cannot play every chunk 0 times.\n" "--- To do a test decode, use the null output driver.\n")); ogg123_opts->ntimes = 1; } break; case 'z': ogg123_opts->shuffle = 1; break; case '@': if (playlist_append_from_file(ogg123_opts->playlist, optarg) == 0) status_error(_("--- Cannot open playlist file %s. Skipped.\n"), optarg); break; case '?': break; default: cmdline_usage(); exit(1); } } /* Sanity check bad option combinations */ if (ogg123_opts->endpos > 0.0 && ogg123_opts->seekpos > ogg123_opts->endpos) { status_error(_("=== Option conflict: End time is before start time.\n")); exit(1); } /* Add last device to device list or use the default device */ if (temp_driver_id < 0) { /* First try config file setting */ if (ogg123_opts->default_device) { temp_driver_id = ao_driver_id(ogg123_opts->default_device); if (temp_driver_id < 0) status_error(_("--- Driver %s specified in configuration file invalid.\n"), ogg123_opts->default_device); } /* Then try libao autodetect */ if (temp_driver_id < 0) temp_driver_id = ao_default_driver_id(); /* Finally, give up */ if (temp_driver_id < 0) { status_error(_("=== Could not load default driver and no driver specified in config file. Exiting.\n")); exit(1); } ogg123_opts->devices = append_audio_device(ogg123_opts->devices, temp_driver_id, temp_options, NULL); } return optind; }
/*///////////////////////////////////////////////////////////////*/ int cmdline_args (KConfig K, int argc, char *argv[]) { const char* thisfunction = "cmdline_args"; int i; if (K->genotypes != 1) { not_implemented(thisfunction, "genotypes != 1"); } enum { o_help, o_progress, o_generation_cutoff, o_nested, o_unnested, o_U_mutation, o_s_selection, o_h_dominance, o_S_selfing_rate, o_A_apomixis_rate, o_truncate, o_no_lethal, o_table_heading_only, o_table, o_load_savefile, o_load_savefile_name, o_save_savefile, o_save_savefile_name, }; CSimpleOpt::SOption K_options[] = { { o_help, "-?", SO_NONE }, { o_help, "--help", SO_NONE }, { o_progress, "--progress", SO_REQ_SEP }, { o_generation_cutoff, "--generation-cutoff", SO_REQ_SEP }, { o_nested, "--nested", SO_NONE }, { o_unnested, "--unnested", SO_NONE }, { o_U_mutation, "-U", SO_REQ_SEP }, { o_s_selection, "-s", SO_REQ_SEP }, { o_h_dominance, "-h", SO_REQ_SEP }, { o_S_selfing_rate, "-S", SO_REQ_SEP }, { o_A_apomixis_rate, "-A", SO_REQ_SEP }, { o_truncate, "--truncate", SO_NONE }, { o_no_lethal, "--no-lethal-shortcut", SO_NONE }, { o_table_heading_only, "--table-heading-only", SO_NONE }, { o_table, "--table", SO_NONE }, { o_load_savefile, "--load-savefile", SO_NONE }, { o_load_savefile_name, "--load-savefile-name", SO_REQ_SEP }, { o_save_savefile, "--save-savefile", SO_NONE }, { o_save_savefile_name, "--save-savefile-name", SO_REQ_SEP }, SO_END_OF_OPTIONS }; CSimpleOpt args(argc, argv, K_options); while (args.Next()) { if (args.LastError() != SO_SUCCESS) { cerr << "invalid argument '" << args.OptionText() << "'" << endl; cmdline_usage(K); exit(0); } switch (args.OptionId()) { case o_help: cmdline_usage(K); exit(0); break; case o_progress: K->progress = atol(args.OptionArg()); break; case o_generation_cutoff: GENERATION_CUTOFF = atoi(args.OptionArg()); break; case o_nested: cerr << "Unnested simulation, option invalid '" << args.OptionText() << "'" << endl; break; exit(1); case o_unnested: /* ignored here */ break; case o_U_mutation: K->U = atof(args.OptionArg()); break; case o_s_selection: K->fit_s = atof(args.OptionArg()); break; case o_h_dominance: K->fit_h = atof(args.OptionArg()); break; case o_S_selfing_rate: K->S[0] = atof(args.OptionArg()); break; case o_A_apomixis_rate: K->A[0] = atof(args.OptionArg()); break; case o_truncate: K->option_truncate = 1; break; case o_no_lethal: K->option_nolethal = 1; break; case o_table_heading_only: stats_print_table_heading(K); exit(0); break; case o_table: K->option_table = 1; break; case o_load_savefile: K->load_savefile = 1; break; case o_load_savefile_name: K->load_savefile_name = args.OptionArg(); break; case o_save_savefile: K->save_savefile = 1; break; case o_save_savefile_name: K->save_savefile_name = args.OptionArg(); break; default: cerr << "Invalid option '" << args.OptionText() << "'" << endl; exit(1); break; /* } else if (!strcmp( argv[i], "-inita1" )) { // initial frequency of allele 1 INITIAL_A1 = (double)atof( argv[i+1] ); i += 2; } else if (!strcmp( argv[i], "-n" )) { N = atol( argv[i+1] ); i += 2; } else if (!strcmp( argv[i], "-fecm" )) { FECM = atol( argv[i+1] ); i += 2; } else if (!strcmp( argv[i], "-fecf" )) { FECF = atol( argv[i+1] ); i += 2; } else if (!strcmp( argv[i], "-gens" )) { GENS = atol( argv[i+1] ); i += 2; } else if (!strcmp( argv[i], "-selmod" )) { selection_model = atoi( argv[i+1] ); i += 2; } else if (!strcmp( argv[i], "-popmod" )) { selection_model = atoi( argv[i+1] ); i += 2; } else if (!strcmp( argv[i], "-selfsurv" )) { self_survival = (double)atof( argv[i+1] ); i += 2; */ } } return 0; }