int parse_error (parse_code_t pcode, int lineno, const char *filename, char *line) { if (pcode == parse_syserr) { if (errno != EEXIST && errno != ENOENT) perror (_("System error")); return -1; } else { status_error (_("=== Parse error: %s on line %d of %s (%s)\n"), parse_error_string(pcode), lineno, filename, line); return 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; }
static int parse_input_file(const char *file_name, struct errors **top_error, struct languages **top_lang) { FILE *file; char *str, buff[1000]; struct errors *current_error= 0, **tail_error= top_error; struct message current_message; int rcount= 0; /* Number of error codes in current section. */ int ecount= 0; /* Number of error codes in total. */ DBUG_ENTER("parse_input_file"); *top_error= 0; *top_lang= 0; if (!(file= my_fopen(file_name, O_RDONLY | O_SHARE, MYF(MY_WME)))) DBUG_RETURN(0); while ((str= fgets(buff, sizeof(buff), file))) { if (is_prefix(str, "language")) { if (!(*top_lang= parse_charset_string(str))) { fprintf(stderr, "Failed to parse the charset string!\n"); DBUG_RETURN(0); } continue; } if (is_prefix(str, "start-error-number")) { if (!(er_offset= parse_error_offset(str))) { fprintf(stderr, "Failed to parse the error offset string!\n"); DBUG_RETURN(0); } rcount= 0; /* Reset count if a fixed number is set. */ continue; } if (is_prefix(str, "default-language")) { if (!(default_language= parse_default_language(str))) { DBUG_PRINT("info", ("default_slang: %s", default_language)); fprintf(stderr, "Failed to parse the default language line. Aborting\n"); DBUG_RETURN(0); } continue; } if (*str == '\t' || *str == ' ') { /* New error message in another language for previous error */ if (!current_error) { fprintf(stderr, "Error in the input file format\n"); DBUG_RETURN(0); } if (!parse_message_string(¤t_message, str)) { fprintf(stderr, "Failed to parse message string for error '%s'", current_error->er_name); DBUG_RETURN(0); } if (find_message(current_error, current_message.lang_short_name, TRUE)) { fprintf(stderr, "Duplicate message string for error '%s'" " in language '%s'\n", current_error->er_name, current_message.lang_short_name); DBUG_RETURN(0); } if (check_message_format(current_error, current_message.text)) { fprintf(stderr, "Wrong formatspecifier of error message string" " for error '%s' in language '%s'\n", current_error->er_name, current_message.lang_short_name); DBUG_RETURN(0); } if (insert_dynamic(¤t_error->msg, ¤t_message)) DBUG_RETURN(0); continue; } if (is_prefix(str, ER_PREFIX) || is_prefix(str, WARN_PREFIX)) { if (!(current_error= parse_error_string(str, rcount))) { fprintf(stderr, "Failed to parse the error name string\n"); DBUG_RETURN(0); } rcount++; ecount++; /* Count number of unique errors */ /* add error to the list */ *tail_error= current_error; tail_error= ¤t_error->next_error; continue; } if (*str == '#' || *str == '\n') continue; /* skip comment or empty lines */ fprintf(stderr, "Wrong input file format. Stop!\nLine: %s\n", str); DBUG_RETURN(0); } *tail_error= 0; /* Mark end of list */ my_fclose(file, MYF(0)); DBUG_RETURN(ecount); }
static int parse_input_file(const char *file_name, struct errors **top_error, struct languages **top_lang) { FILE *file; char *str, buff[1000]; struct errors *current_error= 0, **tail_error= top_error; struct message current_message; uint rcount= 0; my_bool er_offset_found= 0; DBUG_ENTER("parse_input_file"); *top_error= 0; *top_lang= 0; if (!(file= my_fopen(file_name, O_RDONLY | O_SHARE, MYF(MY_WME)))) DBUG_RETURN(0); while ((str= fgets(buff, sizeof(buff), file))) { if (is_prefix(str, "language")) { if (!(*top_lang= parse_charset_string(str))) { fprintf(stderr, "Failed to parse the charset string!\n"); DBUG_RETURN(0); } continue; } if (is_prefix(str, "start-error-number")) { uint tmp_er_offset; if (!(tmp_er_offset= parse_error_offset(str))) { fprintf(stderr, "Failed to parse the error offset string!\n"); DBUG_RETURN(0); } if (!er_offset_found) { er_offset_found= 1; er_offset= tmp_er_offset; } else { /* Create empty error messages between er_offset and tmp_err_offset */ if (tmp_er_offset < er_offset + rcount) { fprintf(stderr, "new start-error-number %u is smaller than current error message: %u\n", tmp_er_offset, er_offset + rcount); DBUG_RETURN(0); } for ( ; er_offset + rcount < tmp_er_offset ; rcount++) { current_error= generate_empty_message(er_offset + rcount); *tail_error= current_error; tail_error= ¤t_error->next_error; } } continue; } if (is_prefix(str, "default-language")) { if (!(default_language= parse_default_language(str))) { DBUG_PRINT("info", ("default_slang: %s", default_language)); fprintf(stderr, "Failed to parse the default language line. Aborting\n"); DBUG_RETURN(0); } continue; } if (*str == '\t' || *str == ' ') { /* New error message in another language for previous error */ if (!current_error) { fprintf(stderr, "Error in the input file format\n"); DBUG_RETURN(0); } if (!parse_message_string(¤t_message, str)) { fprintf(stderr, "Failed to parse message string for error '%s'", current_error->er_name); DBUG_RETURN(0); } if (find_message(current_error, current_message.lang_short_name, TRUE)) { fprintf(stderr, "Duplicate message string for error '%s'" " in language '%s'\n", current_error->er_name, current_message.lang_short_name); DBUG_RETURN(0); } if (check_message_format(current_error, current_message.text)) { fprintf(stderr, "Wrong formatspecifier of error message string" " for error '%s' in language '%s'\n", current_error->er_name, current_message.lang_short_name); DBUG_RETURN(0); } if (insert_dynamic(¤t_error->msg, (uchar *) & current_message)) DBUG_RETURN(0); continue; } if (is_prefix(str, ER_PREFIX) || is_prefix(str, WARN_PREFIX) || is_prefix(str, ER_PREFIX2)) { if (!(current_error= parse_error_string(str, rcount))) { fprintf(stderr, "Failed to parse the error name string\n"); DBUG_RETURN(0); } rcount++; /* Count number of unique errors */ /* add error to the list */ *tail_error= current_error; tail_error= ¤t_error->next_error; continue; } if (*str == '#' || *str == '\n') continue; /* skip comment or empty lines */ fprintf(stderr, "Wrong input file format. Stop!\nLine: %s\n", str); DBUG_RETURN(0); } *tail_error= 0; /* Mark end of list */ my_fclose(file, MYF(0)); DBUG_RETURN(rcount); }