diff --git a/src/metaflac/main.c b/src/metaflac/main.c index 81596d0a..1183fe13 100644 --- a/src/metaflac/main.c +++ b/src/metaflac/main.c @@ -45,22 +45,22 @@ more powerful operations yet to add: */ static struct option long_options_[] = { /* global options */ - { "preserve-modtime", 0, 0, 0 }, - { "with-filename", 0, 0, 0 }, - { "no-filename", 0, 0, 0 }, - { "dont-use-padding", 0, 0, 0 }, + { "preserve-modtime", 0, 0, 0 }, + { "with-filename", 0, 0, 0 }, + { "no-filename", 0, 0, 0 }, + { "dont-use-padding", 0, 0, 0 }, /* shorthand operations */ - { "show-md5sum", 0, 0, 0 }, - { "show-min-blocksize", 0, 0, 0 }, - { "show-max-blocksize", 0, 0, 0 }, - { "show-min-framesize", 0, 0, 0 }, - { "show-max-framesize", 0, 0, 0 }, - { "show-sample-rate", 0, 0, 0 }, - { "show-channels", 0, 0, 0 }, - { "show-bps", 0, 0, 0 }, - { "show-total-samples", 0, 0, 0 }, - { "show-vc-vendor", 0, 0, 0 }, - { "show-vc-field", 1, 0, 0 }, + { "show-md5sum", 0, 0, 0 }, + { "show-min-blocksize", 0, 0, 0 }, + { "show-max-blocksize", 0, 0, 0 }, + { "show-min-framesize", 0, 0, 0 }, + { "show-max-framesize", 0, 0, 0 }, + { "show-sample-rate", 0, 0, 0 }, + { "show-channels", 0, 0, 0 }, + { "show-bps", 0, 0, 0 }, + { "show-total-samples", 0, 0, 0 }, + { "show-vc-vendor", 0, 0, 0 }, + { "show-vc-field", 1, 0, 0 }, { "remove-vc-all", 0, 0, 0 }, { "remove-vc-field", 1, 0, 0 }, { "remove-vc-firstfield", 1, 0, 0 }, @@ -73,6 +73,7 @@ static struct option long_options_[] = { { "remove-all", 0, 0, 0 }, { "merge-padding", 0, 0, 0 }, { "sort-padding", 0, 0, 0 }, + /* major operation arguments */ { "block-number", 1, 0, 0 }, { "block-type", 1, 0, 0 }, { "except-block-type", 1, 0, 0 }, @@ -98,21 +99,22 @@ typedef enum { OP__REMOVE_VC_FIELD, OP__REMOVE_VC_FIRSTFIELD, OP__SET_VC_FIELD, - OP__HELP, OP__LIST, OP__APPEND, OP__REMOVE, OP__REMOVE_ALL, OP__MERGE_PADDING, - OP__SORT_PADDING, - OP__BLOCK_NUMBER, - OP__BLOCK_TYPE, - OP__EXCEPT_BLOCK_TYPE, - OP__DATA_FORMAT, - OP__APPLICATION_DATA_FORMAT, - OP__FROM_FILE + OP__SORT_PADDING } OperationType; +typedef enum { + ARG__BLOCK_NUMBER, + ARG__BLOCK_TYPE, + ARG__EXCEPT_BLOCK_TYPE, + ARG__DATA_FORMAT, + ARG__FROM_FILE +} ArgumentType; + typedef struct { char *field_name; } Argument_VcFieldName; @@ -130,17 +132,20 @@ typedef struct { } Argument_BlockNumber; typedef struct { - int dummy; + FLAC__MetaDataType type; + char application_id[4]; /* only relevant if type == FLAC__STREAM_METADATA_TYPE_APPLICATION */ + FLAC__bool filter_application_by_id; +} Argument_BlockTypeEntry; + +typedef struct { + unsigned num_entries; + Argument_BlockTypeEntry *entries; } Argument_BlockType; typedef struct { FLAC__bool is_binary; } Argument_DataFormat; -typedef struct { - FLAC__bool is_hexdump; -} Argument_ApplicationDataFormat; - typedef struct { char *file_name; } Argument_FromFile; @@ -152,80 +157,128 @@ typedef struct { Argument_VcFieldName remove_vc_field; Argument_VcFieldName remove_vc_firstfield; Argument_VcField set_vc_field; - Argument_BlockNumber block_number; - Argument_BlockType block_type; - Argument_BlockType except_block_type; - Argument_DataFormat data_format; - Argument_ApplicationDataFormat application_data_format; - Argument_FromFile from_file; } argument; } Operation; +typedef struct { + ArgumentType type; + union { + Argument_BlockNumber block_number; + Argument_BlockType block_type; + Argument_DataFormat data_format; + Argument_FromFile from_file; + } value; +} Argument; + typedef struct { FLAC__bool preserve_modtime; FLAC__bool prefix_with_filename; FLAC__bool use_padding; - struct { - unsigned num_shorthand_ops; - unsigned num_major_ops; - FLAC__bool has_block_type; - FLAC__bool has_except_block_type; - } checks; + FLAC__bool show_long_help; + FLAC__bool application_data_format_is_hexdump; struct { Operation *operations; unsigned num_operations; unsigned capacity; } ops; + struct { + struct { + unsigned num_shorthand_ops; + unsigned num_major_ops; + FLAC__bool has_block_type; + FLAC__bool has_except_block_type; + } checks; + Argument *arguments; + unsigned num_arguments; + unsigned capacity; + } args; + unsigned num_files; + const char **filenames; } CommandLineOptions; +static void die(const char *message); static void init_options(CommandLineOptions *options); static FLAC__bool parse_options(int argc, char *argv[], CommandLineOptions *options); static FLAC__bool parse_option(int option_index, const char *option_argument, CommandLineOptions *options); static void free_options(CommandLineOptions *options); -static void append_operation(CommandLineOptions *options, Operation operation); +static void append_new_operation(CommandLineOptions *options, Operation operation); +static void append_new_argument(CommandLineOptions *options, Argument argument); static Operation *append_major_operation(CommandLineOptions *options, OperationType type); static Operation *append_shorthand_operation(CommandLineOptions *options, OperationType type); +static Argument *append_argument(CommandLineOptions *options, ArgumentType type); static int short_usage(const char *message, ...); static int long_usage(const char *message, ...); -static void hexdump(const FLAC__byte *buf, unsigned bytes, const char *indent); static char *local_strdup(const char *source); static FLAC__bool parse_vorbis_comment_field(const char *field, char **name, char **value, unsigned *length); static FLAC__bool parse_block_number(const char *in, Argument_BlockNumber *out); static FLAC__bool parse_block_type(const char *in, Argument_BlockType *out); static FLAC__bool parse_data_format(const char *in, Argument_DataFormat *out); -static FLAC__bool parse_application_data_format(const char *in, Argument_ApplicationDataFormat *out); +static FLAC__bool parse_application_data_format(const char *in, FLAC__bool *out); +static FLAC__bool do_operations(const CommandLineOptions *options); +static FLAC__bool do_major_operation(const CommandLineOptions *options); +static FLAC__bool do_major_operation_on_file(const char *filename, const CommandLineOptions *options); +static FLAC__bool do_major_operation__list(const char *filename, FLAC__MetaData_Chain *chain, const CommandLineOptions *options); +static FLAC__bool do_major_operation__append(FLAC__MetaData_Chain *chain, const CommandLineOptions *options); +static FLAC__bool do_major_operation__remove(FLAC__MetaData_Chain *chain, const CommandLineOptions *options); +static FLAC__bool do_major_operation__remove_all(FLAC__MetaData_Chain *chain, const CommandLineOptions *options); +static FLAC__bool do_shorthand_operations(const CommandLineOptions *options); +static FLAC__bool do_shorthand_operations_on_file(const char *fielname, const CommandLineOptions *options); +static FLAC__bool do_shorthand_operation(const char *filename, FLAC__MetaData_Chain *chain, const Operation *operation, FLAC__bool *needs_write); +static FLAC__bool do_shorthand_operation__streaminfo(const char *filename, FLAC__MetaData_Chain *chain, OperationType op); +static FLAC__bool do_shorthand_operation__vorbis_comment(const char *filename, FLAC__MetaData_Chain *chain, OperationType op, FLAC__bool *needs_write); +static FLAC__bool passes_filter(const CommandLineOptions *options, const FLAC__StreamMetaData *block, unsigned block_number); +static void write_metadata(const char *filename, FLAC__StreamMetaData *block, unsigned block_number, FLAC__bool hexdump_application); +static void hexdump(const char *filename, const FLAC__byte *buf, unsigned bytes, const char *indent); int main(int argc, char *argv[]) { CommandLineOptions options; - int ret; + int ret = 0; init_options(&options); - ret = !parse_options(argc, argv, &options); + if(parse_options(argc, argv, &options)) + ret = !do_operations(&options); free_options(&options); return ret; } +void die(const char *message) +{ + FLAC__ASSERT(0 != message); + fprintf(stderr, "ERROR: %s\n", message); + exit(1); +} + void init_options(CommandLineOptions *options) { options->preserve_modtime = false; - /* hack to mean "use default if not forced on command line" */ + /* '2' is hack to mean "use default if not forced on command line" */ FLAC__ASSERT(true != 2); options->prefix_with_filename = 2; options->use_padding = true; - options->checks.num_shorthand_ops = 0; - options->checks.num_major_ops = 0; - options->checks.has_block_type = false; - options->checks.has_except_block_type = false; + options->show_long_help = false; + options->application_data_format_is_hexdump = false; options->ops.operations = 0; options->ops.num_operations = 0; options->ops.capacity = 0; + + options->args.arguments = 0; + options->args.num_arguments = 0; + options->args.capacity = 0; + + options->args.checks.num_shorthand_ops = 0; + options->args.checks.num_major_ops = 0; + options->args.checks.has_block_type = false; + options->args.checks.has_except_block_type = false; + + options->num_files = 0; + options->filenames = 0; } FLAC__bool parse_options(int argc, char *argv[], CommandLineOptions *options) @@ -241,31 +294,61 @@ FLAC__bool parse_options(int argc, char *argv[], CommandLineOptions *options) break; case '?': case ':': - short_usage(0); - return false; - had_error = true; + had_error = true; + break; default: FLAC__ASSERT(0); + break; } } if(options->prefix_with_filename == 2) options->prefix_with_filename = (argc - optind > 1); - if(optind < argc) { - while(optind < argc) - printf("%s ", argv[optind++]); - printf("\n"); + if(optind >= argc && !options->show_long_help) { + fprintf(stderr,"ERROR: you must specify at least one FLAC file;\n"); + fprintf(stderr," metaflac cannot be used as a pipe\n"); + had_error = true; } - return had_error; + options->num_files = argc - optind; + + if(options->num_files > 0) { + unsigned i = 0; + if(0 == (options->filenames = malloc(sizeof(char *) * options->num_files))) + die("out of memory allocating space for file names list"); + while(optind < argc) + options->filenames[i++] = local_strdup(argv[optind++]); + } + + if(options->args.checks.num_major_ops > 0) { + if(options->args.checks.num_major_ops > 1) { + fprintf(stderr, "ERROR: you may only specify one major operation at a time\n"); + had_error = true; + } + else if(options->args.checks.num_shorthand_ops > 0) { + fprintf(stderr, "ERROR: you may not mix shorthand and major operations\n"); + had_error = true; + } + } + + if(options->args.checks.has_block_type && options->args.checks.has_except_block_type) { + fprintf(stderr, "ERROR: you may not specify both '--block-type' and '--except-block-type'\n"); + had_error = true; + } + + if(had_error) + short_usage(0); + + return !had_error; } FLAC__bool parse_option(int option_index, const char *option_argument, CommandLineOptions *options) { const char *opt = long_options_[option_index].name; Operation *op; - FLAC__bool ret = true; + Argument *arg; + FLAC__bool ok = true; if(0 == strcmp(opt, "preserve-modtime")) { options->preserve_modtime = true; @@ -332,11 +415,11 @@ FLAC__bool parse_option(int option_index, const char *option_argument, CommandLi FLAC__ASSERT(0 != option_argument); if(!parse_vorbis_comment_field(option_argument, &(op->argument.set_vc_field.field_name), &(op->argument.set_vc_field.field_value), &(op->argument.set_vc_field.field_value_length))) { fprintf(stderr, "ERROR: malformed vorbis comment field \"%s\"\n", option_argument); - ret = false; + ok = false; } } else if(0 == strcmp(opt, "help")) { - (void) append_major_operation(options, OP__HELP); + options->show_long_help = true; } else if(0 == strcmp(opt, "list")) { (void) append_major_operation(options, OP__LIST); @@ -357,89 +440,100 @@ FLAC__bool parse_option(int option_index, const char *option_argument, CommandLi (void) append_major_operation(options, OP__SORT_PADDING); } else if(0 == strcmp(opt, "block-number")) { - op = append_major_operation(options, OP__BLOCK_NUMBER); + arg = append_argument(options, ARG__BLOCK_NUMBER); FLAC__ASSERT(0 != option_argument); - if(!parse_block_number(option_argument, &(op->argument.block_number))) { + if(!parse_block_number(option_argument, &(arg->value.block_number))) { fprintf(stderr, "ERROR: malformed block number specification \"%s\"\n", option_argument); - ret = false; + ok = false; } } else if(0 == strcmp(opt, "block-type")) { - op = append_major_operation(options, OP__BLOCK_TYPE); + arg = append_argument(options, ARG__BLOCK_TYPE); FLAC__ASSERT(0 != option_argument); - if(!parse_block_type(option_argument, &(op->argument.block_type))) { + if(!parse_block_type(option_argument, &(arg->value.block_type))) { fprintf(stderr, "ERROR: malformed block type specification \"%s\"\n", option_argument); - ret = false; + ok = false; } + options->args.checks.has_block_type = true; } else if(0 == strcmp(opt, "except-block-type")) { - op = append_major_operation(options, OP__EXCEPT_BLOCK_TYPE); + arg = append_argument(options, ARG__EXCEPT_BLOCK_TYPE); FLAC__ASSERT(0 != option_argument); - if(!parse_block_type(option_argument, &(op->argument.except_block_type))) { + if(!parse_block_type(option_argument, &(arg->value.block_type))) { fprintf(stderr, "ERROR: malformed block type specification \"%s\"\n", option_argument); - ret = false; + ok = false; } + options->args.checks.has_except_block_type = true; } else if(0 == strcmp(opt, "data-format")) { - op = append_major_operation(options, OP__DATA_FORMAT); + arg = append_argument(options, ARG__DATA_FORMAT); FLAC__ASSERT(0 != option_argument); - if(!parse_data_format(option_argument, &(op->argument.data_format))) { + if(!parse_data_format(option_argument, &(arg->value.data_format))) { fprintf(stderr, "ERROR: illegal data format \"%s\"\n", option_argument); - ret = false; + ok = false; } } else if(0 == strcmp(opt, "application-data-format")) { - op = append_major_operation(options, OP__APPLICATION_DATA_FORMAT); FLAC__ASSERT(0 != option_argument); - if(!parse_application_data_format(option_argument, &(op->argument.application_data_format))) { + if(!parse_application_data_format(option_argument, &(options->application_data_format_is_hexdump))) { fprintf(stderr, "ERROR: illegal application data format \"%s\"\n", option_argument); - ret = false; + ok = false; } } else if(0 == strcmp(opt, "from-file")) { - op = append_major_operation(options, OP__FROM_FILE); + arg = append_argument(options, ARG__FROM_FILE); FLAC__ASSERT(0 != option_argument); - op->argument.from_file.file_name = local_strdup(option_argument); + arg->value.from_file.file_name = local_strdup(option_argument); } else { FLAC__ASSERT(0); } - return ret; + return ok; } void free_options(CommandLineOptions *options) { unsigned i; Operation *op; + Argument *arg; FLAC__ASSERT(0 == options->ops.operations || options->ops.num_operations > 0); + FLAC__ASSERT(0 == options->args.arguments || options->args.num_arguments > 0); - for(i = 0; i < options->ops.num_operations; i++) { - op = options->ops.operations + i; + for(i = 0, op = options->ops.operations; i < options->ops.num_operations; i++, op++) { switch(op->type) { case OP__SHOW_VC_FIELD: case OP__REMOVE_VC_FIELD: case OP__REMOVE_VC_FIRSTFIELD: - FLAC__ASSERT(0 != op->argument.show_vc_field.field_name); - free(op->argument.show_vc_field.field_name); + if(0 != op->argument.show_vc_field.field_name) + free(op->argument.show_vc_field.field_name); break; case OP__SET_VC_FIELD: - FLAC__ASSERT(0 != op->argument.set_vc_field.field_name); - free(op->argument.set_vc_field.field_name); + if(0 != op->argument.set_vc_field.field_name) + free(op->argument.set_vc_field.field_name); if(0 != op->argument.set_vc_field.field_value) free(op->argument.set_vc_field.field_value); break; - case OP__BLOCK_NUMBER: - /*@@@*/ + default: break; - case OP__BLOCK_TYPE: - case OP__EXCEPT_BLOCK_TYPE: - /*@@@*/ + } + } + + for(i = 0, arg = options->args.arguments; i < options->args.num_arguments; i++, arg++) { + switch(arg->type) { + case ARG__BLOCK_NUMBER: + if(0 != arg->value.block_number.entries) + free(arg->value.block_number.entries); break; - case OP__FROM_FILE: - FLAC__ASSERT(0 != op->argument.from_file.file_name); - free(op->argument.from_file.file_name); + case ARG__BLOCK_TYPE: + case ARG__EXCEPT_BLOCK_TYPE: + if(0 != arg->value.block_type.entries) + free(arg->value.block_type.entries); + break; + case ARG__FROM_FILE: + if(0 != arg->value.from_file.file_name) + free(arg->value.from_file.file_name); break; default: break; @@ -448,49 +542,81 @@ void free_options(CommandLineOptions *options) if(0 != options->ops.operations) free(options->ops.operations); + + if(0 != options->args.arguments) + free(options->args.arguments); + + if(0 != options->filenames) + free(options->filenames); } -void append_operation(CommandLineOptions *options, Operation operation) +void append_new_operation(CommandLineOptions *options, Operation operation) { if(options->ops.capacity == 0) { options->ops.capacity = 50; - if(0 == (options->ops.operations = malloc(sizeof(Operation) * options->ops.capacity))) { - fprintf(stderr, "ERROR: out of memory allocating space for option list\n"); - exit(1); - } + if(0 == (options->ops.operations = malloc(sizeof(Operation) * options->ops.capacity))) + die("out of memory allocating space for option list"); memset(options->ops.operations, 0, sizeof(Operation) * options->ops.capacity); } if(options->ops.capacity <= options->ops.num_operations) { unsigned original_capacity = options->ops.capacity; options->ops.capacity *= 4; - if(0 == (options->ops.operations = realloc(options->ops.operations, sizeof(Operation) * options->ops.capacity))) { - fprintf(stderr, "ERROR: out of memory allocating space for option list\n"); - exit(1); - } + if(0 == (options->ops.operations = realloc(options->ops.operations, sizeof(Operation) * options->ops.capacity))) + die("out of memory allocating space for option list"); memset(options->ops.operations + original_capacity, 0, sizeof(Operation) * (options->ops.capacity - original_capacity)); } options->ops.operations[options->ops.num_operations++] = operation; } +void append_new_argument(CommandLineOptions *options, Argument argument) +{ + if(options->args.capacity == 0) { + options->args.capacity = 50; + if(0 == (options->args.arguments = malloc(sizeof(Argument) * options->args.capacity))) + die("out of memory allocating space for option list"); + memset(options->args.arguments, 0, sizeof(Argument) * options->args.capacity); + } + if(options->args.capacity <= options->args.num_arguments) { + unsigned original_capacity = options->args.capacity; + options->args.capacity *= 4; + if(0 == (options->args.arguments = realloc(options->args.arguments, sizeof(Argument) * options->args.capacity))) + die("out of memory allocating space for option list"); + memset(options->args.arguments + original_capacity, 0, sizeof(Argument) * (options->args.capacity - original_capacity)); + } + + options->args.arguments[options->args.num_arguments++] = argument; +} + Operation *append_major_operation(CommandLineOptions *options, OperationType type) { Operation op; + memset(&op, 0, sizeof(op)); op.type = type; - append_operation(options, op); - options->checks.num_major_ops++; + append_new_operation(options, op); + options->args.checks.num_major_ops++; return options->ops.operations + (options->ops.num_operations - 1); } Operation *append_shorthand_operation(CommandLineOptions *options, OperationType type) { Operation op; + memset(&op, 0, sizeof(op)); op.type = type; - append_operation(options, op); - options->checks.num_shorthand_ops++; + append_new_operation(options, op); + options->args.checks.num_shorthand_ops++; return options->ops.operations + (options->ops.num_operations - 1); } +Argument *append_argument(CommandLineOptions *options, ArgumentType type) +{ + Argument arg; + memset(&arg, 0, sizeof(arg)); + arg.type = type; + append_new_argument(options, arg); + return options->args.arguments + (options->args.num_arguments - 1); +} + static void usage_header(FILE *out) { fprintf(out, "==============================================================================\n"); @@ -529,8 +655,8 @@ static void usage_summary(FILE *out) fprintf(out, " (the default if only one FLAC file is specified)\n"); fprintf(out, "--dont-use-padding By default metaflac tries to use padding where possible\n"); fprintf(out, " to avoid rewriting the entire file if the metadata size\n"); - fprintf(out, " changes. Use this option to tell metaflac to not use\n"); - fprintf(out, " padding at all.\n"); + fprintf(out, " changes. Use this option to tell metaflac to not take\n"); + fprintf(out, " advantage of padding this way.\n"); } int short_usage(const char *message, ...) @@ -599,9 +725,10 @@ int long_usage(const char *message, ...) fprintf(out, " created.\n"); fprintf(out, "\n"); fprintf(out, "Major operations:\n"); - fprintf(out, "--list : List the contents of one or more metadata blocks to stdout. By\n"); - fprintf(out, " default, all metadata blocks are listed in text format. Use the\n"); - fprintf(out, " following options to change this behavior:\n"); + fprintf(out, "--list\n"); + fprintf(out, " List the contents of one or more metadata blocks to stdout. By default,\n"); + fprintf(out, " all metadata blocks are listed in text format. Use the following options\n"); + fprintf(out, " to change this behavior:\n"); fprintf(out, "\n"); fprintf(out, " --block-number=#[,#[...]]\n"); fprintf(out, " An optional comma-separated list of block numbers to display. The first\n"); @@ -631,8 +758,8 @@ int long_usage(const char *message, ...) fprintf(out, " You may specify --data-format=binary to dump the raw binary form of each\n"); fprintf(out, " metadata block. The output can be read in using a subsequent call to\n"); fprintf(out, " "metaflac --append --from-file=..."\n"); -#endif fprintf(out, "\n"); +#endif fprintf(out, " --application-data-format=hexdump|text\n"); fprintf(out, " If the application block you are displaying contains binary data but your\n"); fprintf(out, " --data-format=text, you can display a hex dump of the application data\n"); @@ -640,8 +767,9 @@ int long_usage(const char *message, ...) fprintf(out, "\n"); #if 0 /*@@@ not implemented yet */ - fprintf(out, "--append : Insert a metadata block from a file. The input file must be in the\n"); - fprintf(out, " same format as generated with --list.\n"); + fprintf(out, "--append\n"); + fprintf(out, " Insert a metadata block from a file. The input file must be in the same\n"); + fprintf(out, " format as generated with --list.\n"); fprintf(out, "\n"); fprintf(out, " --block-number=#\n"); fprintf(out, " Specify the insertion point (defaults to last block). The new block will\n"); @@ -657,9 +785,10 @@ int long_usage(const char *message, ...) fprintf(out, " override this by specifying --data-format=text\n"); fprintf(out, "\n"); #endif - fprintf(out, "--remove : Remove one or more metadata blocks from the metadata. Unless\n"); - fprintf(out, " --dont-use-padding is specified, the blocks will be replaced with\n"); - fprintf(out, " padding. You may not remove the STREAMINFO block.\n"); + fprintf(out, "--remove\n"); + fprintf(out, " Remove one or more metadata blocks from the metadata. Unless\n"); + fprintf(out, " --dont-use-padding is specified, the blocks will be replaced with padding.\n"); + fprintf(out, " You may not remove the STREAMINFO block.\n"); fprintf(out, "\n"); fprintf(out, " --block-number=#[,#[...]]\n"); fprintf(out, " --block-type=type[,type[...]]\n"); @@ -669,28 +798,646 @@ int long_usage(const char *message, ...) fprintf(out, " NOTE: if both --block-number and --[except-]block-type are specified,\n"); fprintf(out, " the result is the logical AND of both arguments.\n"); fprintf(out, "\n"); - fprintf(out, "--remove-all : Remove all metadata blocks (except the STREAMINFO block) from\n"); - fprintf(out, " the metadata. Unless --dont-use-padding is specified, the\n"); - fprintf(out, " blocks will be replaced with padding.\n"); + fprintf(out, "--remove-all\n"); + fprintf(out, " Remove all metadata blocks (except the STREAMINFO block) from the\n"); + fprintf(out, " metadata. Unless --dont-use-padding is specified, the blocks will be\n"); + fprintf(out, " replaced with padding.\n"); fprintf(out, "\n"); - fprintf(out, "--merge-padding : Merge adjacent PADDING blocks into single blocks.\n"); + fprintf(out, "--merge-padding\n"); + fprintf(out, " Merge adjacent PADDING blocks into single blocks.\n"); fprintf(out, "\n"); - fprintf(out, "--sort-padding : Move all PADDING blocks to the end of the metadata and merge\n"); - fprintf(out, " them into a single block.\n"); + fprintf(out, "--sort-padding\n"); + fprintf(out, " Move all PADDING blocks to the end of the metadata and merge them into a\n"); + fprintf(out, " single block.\n"); return message? 1 : 0; } -void hexdump(const FLAC__byte *buf, unsigned bytes, const char *indent) +char *local_strdup(const char *source) +{ + char *ret; + FLAC__ASSERT(0 != source); + if(0 == (ret = strdup(source))) + die("out of memory during strdup()"); + return ret; +} + +FLAC__bool parse_vorbis_comment_field(const char *field, char **name, char **value, unsigned *length) +{ + char *p, *s = local_strdup(field); + + if(0 == (p = strchr(s, '='))) { + free(s); + return false; + } + *p++ = '\0'; + *name = local_strdup(s); + *value = local_strdup(p); + *length = strlen(p); + + free(s); + return true; +} + +FLAC__bool parse_block_number(const char *in, Argument_BlockNumber *out) +{ + char *p, *q, *s, *end; + long i; + unsigned entry; + + if(*in == '\0') + return false; + + s = local_strdup(in); + + /* first count the entries */ + for(out->num_entries = 1, p = strchr(s, ','); p; out->num_entries++, p = strchr(++p, ',')) + ; + + /* make space */ + FLAC__ASSERT(out->num_entries > 0); + if(0 == (out->entries = malloc(sizeof(unsigned) * out->num_entries))) + die("out of memory allocating space for option list"); + + /* load 'em up */ + entry = 0; + q = s; + while(q) { + FLAC__ASSERT(entry < out->num_entries); + if(0 != (p = strchr(q, ','))) + *p++ = '\0'; + if(!isdigit((int)(*q)) || (i = strtol(q, &end, 10)) < 0 || *end) { + free(s); + return false; + } + out->entries[entry++] = (unsigned)i; + q = p; + } + FLAC__ASSERT(entry == out->num_entries); + + free(s); + return true; +} + +FLAC__bool parse_block_type(const char *in, Argument_BlockType *out) +{ + char *p, *q, *r, *s; + unsigned entry; + + if(*in == '\0') + return false; + + s = local_strdup(in); + + /* first count the entries */ + for(out->num_entries = 1, p = strchr(s, ','); p; out->num_entries++, p = strchr(++p, ',')) + ; + + /* make space */ + FLAC__ASSERT(out->num_entries > 0); + if(0 == (out->entries = malloc(sizeof(Argument_BlockTypeEntry) * out->num_entries))) + die("out of memory allocating space for option list"); + + /* load 'em up */ + entry = 0; + q = s; + while(q) { + FLAC__ASSERT(entry < out->num_entries); + if(0 != (p = strchr(q, ','))) + *p++ = 0; + r = strchr(q, ':'); + if(r) + *r++ = '\0'; + if(0 != r && 0 != strcmp(q, "APPLICATION")) { + free(s); + return false; + } + if(0 == strcmp(q, "STREAMINFO")) { + out->entries[entry++].type = FLAC__METADATA_TYPE_STREAMINFO; + } + else if(0 == strcmp(q, "PADDING")) { + out->entries[entry++].type = FLAC__METADATA_TYPE_PADDING; + } + else if(0 == strcmp(q, "APPLICATION")) { + out->entries[entry].type = FLAC__METADATA_TYPE_APPLICATION; + out->entries[entry].filter_application_by_id = (0 != r); + if(0 != r) { + if(strlen(r) == 4) { + strcpy(out->entries[entry].application_id, r); + } + else if(strlen(r) == 10 && strncmp(r, "0x", 2) == 0 && strspn(r+2, "0123456789ABCDEFabcdef") == 8) { + FLAC__uint32 x = strtoul(r+2, 0, 16); + out->entries[entry].application_id[3] = (FLAC__byte)(x & 0xff); + out->entries[entry].application_id[2] = (FLAC__byte)((x>>=8) & 0xff); + out->entries[entry].application_id[1] = (FLAC__byte)((x>>=8) & 0xff); + out->entries[entry].application_id[0] = (FLAC__byte)((x>>=8) & 0xff); + } + else { + free(s); + return false; + } + } + entry++; + } + else if(0 == strcmp(q, "SEEKTABLE")) { + out->entries[entry++].type = FLAC__METADATA_TYPE_SEEKTABLE; + } + else if(0 == strcmp(q, "VORBIS_COMMENT")) { + out->entries[entry++].type = FLAC__METADATA_TYPE_VORBIS_COMMENT; + } + else { + free(s); + return false; + } + q = p; + } + FLAC__ASSERT(entry == out->num_entries); + + free(s); + return true; +} + +FLAC__bool parse_data_format(const char *in, Argument_DataFormat *out) +{ + if(0 == strcmp(in, "binary")) + out->is_binary = true; + else if(0 == strcmp(in, "text")) + out->is_binary = false; + else + return false; + return true; +} + +FLAC__bool parse_application_data_format(const char *in, FLAC__bool *out) +{ + if(0 == strcmp(in, "hexdump")) + *out = true; + else if(0 == strcmp(in, "text")) + *out = false; + else + return false; + return true; +} + +FLAC__bool do_operations(const CommandLineOptions *options) +{ + FLAC__bool ok = true; + + if(options->show_long_help) { + long_usage(0); + } + else if(options->args.checks.num_major_ops > 0) { + FLAC__ASSERT(options->args.checks.num_shorthand_ops == 0); + FLAC__ASSERT(options->args.checks.num_major_ops == 1); + FLAC__ASSERT(options->args.checks.num_major_ops == options->ops.num_operations); + ok = do_major_operation(options); + } + else if(options->args.checks.num_shorthand_ops > 0) { + FLAC__ASSERT(options->args.checks.num_shorthand_ops == options->ops.num_operations); + ok = do_shorthand_operations(options); + } + + return ok; +} + +FLAC__bool do_major_operation(const CommandLineOptions *options) +{ + unsigned i; + FLAC__bool ok = true; + + /*@@@ to die after first error, v--- add '&& ok' here */ + for(i = 0; i < options->num_files; i++) + ok &= do_major_operation_on_file(options->filenames[i], options); + + return ok; +} + +FLAC__bool do_major_operation_on_file(const char *filename, const CommandLineOptions *options) +{ + FLAC__bool ok = true, needs_write = false; + FLAC__MetaData_Chain *chain = FLAC__metadata_chain_new(); + + if(0 == chain) + die("out of memory allocating chain"); + + if(!FLAC__metadata_chain_read(chain, filename)) { + fprintf(stderr, "ERROR: reading metadata, status = \"%s\"\n", FLAC__MetaData_ChainStatusString[FLAC__metadata_chain_status(chain)]); + return false; + } + + switch(options->ops.operations[0].type) { + case OP__LIST: + ok = do_major_operation__list(options->prefix_with_filename? filename : 0, chain, options); + break; + case OP__APPEND: + ok = do_major_operation__append(chain, options); + needs_write = true; + break; + case OP__REMOVE: + ok = do_major_operation__remove(chain, options); + needs_write = true; + break; + case OP__REMOVE_ALL: + ok = do_major_operation__remove_all(chain, options); + needs_write = true; + break; + case OP__MERGE_PADDING: + FLAC__metadata_chain_merge_padding(chain); + needs_write = true; + break; + case OP__SORT_PADDING: + FLAC__metadata_chain_sort_padding(chain); + needs_write = true; + break; + default: + FLAC__ASSERT(0); + return false; + } + + if(ok && needs_write) { + if(options->use_padding) + FLAC__metadata_chain_sort_padding(chain); + ok = FLAC__metadata_chain_write(chain, options->use_padding, options->preserve_modtime); + if(!ok) + fprintf(stderr, "ERROR: writing FLAC file %s, error = %s\n", filename, FLAC__MetaData_ChainStatusString[FLAC__metadata_chain_status(chain)]); + } + + FLAC__metadata_chain_delete(chain); + + return ok; +} + +FLAC__bool do_major_operation__list(const char *filename, FLAC__MetaData_Chain *chain, const CommandLineOptions *options) +{ + FLAC__MetaData_Iterator *iterator = FLAC__metadata_iterator_new(); + FLAC__StreamMetaData *block; + FLAC__bool ok = true; + unsigned block_number; + + if(0 == iterator) + die("out of memory allocating iterator"); + + FLAC__metadata_iterator_init(iterator, chain); + + block_number = 0; + do { + block = FLAC__metadata_iterator_get_block(iterator); + ok &= (0 != block); + if(!ok) + fprintf(stderr, "ERROR: couldn't get block from chain\n"); + else if(passes_filter(options, FLAC__metadata_iterator_get_block(iterator), block_number)) + write_metadata(filename, block, block_number, options->application_data_format_is_hexdump); + block_number++; + } while(ok && FLAC__metadata_iterator_next(iterator)); + + FLAC__metadata_iterator_delete(iterator); + + return ok; +} + +FLAC__bool do_major_operation__append(FLAC__MetaData_Chain *chain, const CommandLineOptions *options) +{ + fprintf(stderr, "ERROR: --append not implemented yet\n"); /*@@@*/ + return false; +} + +FLAC__bool do_major_operation__remove(FLAC__MetaData_Chain *chain, const CommandLineOptions *options) +{ + FLAC__MetaData_Iterator *iterator = FLAC__metadata_iterator_new(); + FLAC__bool ok = true; + unsigned block_number; + + if(0 == iterator) + die("out of memory allocating iterator"); + + FLAC__metadata_iterator_init(iterator, chain); + + block_number = 0; + while(ok && FLAC__metadata_iterator_next(iterator)) { + block_number++; + if(passes_filter(options, FLAC__metadata_iterator_get_block(iterator), block_number)) + ok &= FLAC__metadata_iterator_delete_block(iterator, options->use_padding); + } + + FLAC__metadata_iterator_delete(iterator); + + return ok; +} + +FLAC__bool do_major_operation__remove_all(FLAC__MetaData_Chain *chain, const CommandLineOptions *options) +{ + FLAC__MetaData_Iterator *iterator = FLAC__metadata_iterator_new(); + FLAC__bool ok = true; + + if(0 == iterator) + die("out of memory allocating iterator"); + + FLAC__metadata_iterator_init(iterator, chain); + + while(ok && FLAC__metadata_iterator_next(iterator)) + ok &= FLAC__metadata_iterator_delete_block(iterator, options->use_padding); + + FLAC__metadata_iterator_delete(iterator); + + return ok; +} + +FLAC__bool do_shorthand_operations(const CommandLineOptions *options) +{ + unsigned i; + FLAC__bool ok = true; + + /*@@@ to die after first error, v--- add '&& ok' here */ + for(i = 0; i < options->num_files; i++) + ok &= do_shorthand_operations_on_file(options->filenames[i], options); + + return ok; +} + +FLAC__bool do_shorthand_operations_on_file(const char *filename, const CommandLineOptions *options) +{ + unsigned i; + FLAC__bool ok = true, needs_write = false; + FLAC__MetaData_Chain *chain = FLAC__metadata_chain_new(); + + if(0 == chain) + die("out of memory allocating chain"); + + if(!FLAC__metadata_chain_read(chain, filename)) { + fprintf(stderr, "ERROR: reading metadata, status = \"%s\"\n", FLAC__MetaData_ChainStatusString[FLAC__metadata_chain_status(chain)]); + return false; + } + + for(i = 0; i < options->ops.num_operations && ok; i++) + ok &= do_shorthand_operation(options->prefix_with_filename? filename : 0, chain, &options->ops.operations[i], &needs_write); + + if(ok) { + if(options->use_padding) + FLAC__metadata_chain_sort_padding(chain); + ok = FLAC__metadata_chain_write(chain, options->use_padding, options->preserve_modtime); + if(!ok) + fprintf(stderr, "ERROR: writing FLAC file %s, error = %s\n", filename, FLAC__MetaData_ChainStatusString[FLAC__metadata_chain_status(chain)]); + } + + FLAC__metadata_chain_delete(chain); + + return ok; +} + +FLAC__bool do_shorthand_operation(const char *filename, FLAC__MetaData_Chain *chain, const Operation *operation, FLAC__bool *needs_write) +{ + unsigned i; + FLAC__bool ok = true; + + switch(operation->type) { + case OP__SHOW_MD5SUM: + case OP__SHOW_MIN_BLOCKSIZE: + case OP__SHOW_MAX_BLOCKSIZE: + case OP__SHOW_MIN_FRAMESIZE: + case OP__SHOW_MAX_FRAMESIZE: + case OP__SHOW_SAMPLE_RATE: + case OP__SHOW_CHANNELS: + case OP__SHOW_BPS: + case OP__SHOW_TOTAL_SAMPLES: + ok = do_shorthand_operation__streaminfo(filename, chain, operation->type); + break; + case OP__SHOW_VC_VENDOR: + case OP__SHOW_VC_FIELD: + case OP__REMOVE_VC_ALL: + case OP__REMOVE_VC_FIELD: + case OP__REMOVE_VC_FIRSTFIELD: + case OP__SET_VC_FIELD: + ok = do_shorthand_operation__vorbis_comment(filename, chain, operation->type, needs_write); + break; + default: + ok = false; + FLAC__ASSERT(0); + break; + }; + + return ok; +} + +FLAC__bool do_shorthand_operation__streaminfo(const char *filename, FLAC__MetaData_Chain *chain, OperationType op) +{ + unsigned i; + FLAC__bool ok = true; + FLAC__StreamMetaData *block; + FLAC__MetaData_Iterator *iterator = FLAC__metadata_iterator_new(); + + if(0 == iterator) + die("out of memory allocating iterator"); + + FLAC__metadata_iterator_init(iterator, chain); + + block = FLAC__metadata_iterator_get_block(iterator); + + FLAC__ASSERT(0 != block); + FLAC__ASSERT(block->type == FLAC__METADATA_TYPE_STREAMINFO); + + if(0 != filename) + printf("%s:", filename); + + switch(op) { + case OP__SHOW_MD5SUM: + for(i = 0; i < 16; i++) + printf("%02x", block->data.stream_info.md5sum[i]); + printf("\n"); + break; + case OP__SHOW_MIN_BLOCKSIZE: + printf("%u\n", block->data.stream_info.min_blocksize); + break; + case OP__SHOW_MAX_BLOCKSIZE: + printf("%u\n", block->data.stream_info.max_blocksize); + break; + case OP__SHOW_MIN_FRAMESIZE: + printf("%u\n", block->data.stream_info.min_framesize); + break; + case OP__SHOW_MAX_FRAMESIZE: + printf("%u\n", block->data.stream_info.max_framesize); + break; + case OP__SHOW_SAMPLE_RATE: + printf("%u\n", block->data.stream_info.sample_rate); + break; + case OP__SHOW_CHANNELS: + printf("%u\n", block->data.stream_info.channels); + break; + case OP__SHOW_BPS: + printf("%u\n", block->data.stream_info.bits_per_sample); + break; + case OP__SHOW_TOTAL_SAMPLES: + printf("%llu\n", block->data.stream_info.total_samples); + break; + default: + ok = false; + FLAC__ASSERT(0); + break; + }; + + FLAC__metadata_iterator_delete(iterator); + + return ok; +} + +FLAC__bool do_shorthand_operation__vorbis_comment(const char *filename, FLAC__MetaData_Chain *chain, OperationType op, FLAC__bool *needs_write) +{ + FLAC__bool ok = true, found_vc_block = false; + FLAC__StreamMetaData *block = 0; + FLAC__MetaData_Iterator *iterator = FLAC__metadata_iterator_new(); + + if(0 == iterator) + die("out of memory allocating iterator"); + + FLAC__metadata_iterator_init(iterator, chain); + + do { + block = FLAC__metadata_iterator_get_block(iterator); + if(block->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) + found_vc_block = true; + } while(!found_vc_block && FLAC__metadata_iterator_next(iterator)); + + /* create a new block if necessary */ + if(!found_vc_block && op == OP__SET_VC_FIELD) { + block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT); + if(0 == block) + die("out of memory allocating VORBIS_COMMENT block"); + while(FLAC__metadata_iterator_next(iterator)) + ; + if(!FLAC__metadata_iterator_insert_block_after(iterator, block)) { + fprintf(stderr, "ERROR: adding new VORBIS_COMMENT block to metadata\n"); + return false; + } + /* iterator is left pointing to new block */ + FLAC__ASSERT(FLAC__metadata_iterator_get_block(iterator) == block); + } + + FLAC__ASSERT(0 != block); + FLAC__ASSERT(block->type == FLAC__METADATA_TYPE_VORBIS_COMMENT); + + /*@@@@ set needs_write = true where necessary */ + switch(op) { + case OP__SHOW_VC_VENDOR: + case OP__SHOW_VC_FIELD: + case OP__REMOVE_VC_ALL: + case OP__REMOVE_VC_FIELD: + case OP__REMOVE_VC_FIRSTFIELD: + case OP__SET_VC_FIELD: + default: + ok = false; + FLAC__ASSERT(0); + break; + }; + + return ok; +} + +FLAC__bool passes_filter(const CommandLineOptions *options, const FLAC__StreamMetaData *block, unsigned block_number) +{ + unsigned i, j; + FLAC__bool matches_number = false, matches_type = false; + FLAC__bool has_block_number_arg = false; + + for(i = 0; i < options->args.num_arguments; i++) { + if(options->args.arguments[i].type == ARG__BLOCK_TYPE || options->args.arguments[i].type == ARG__EXCEPT_BLOCK_TYPE) { + for(j = 0; j < options->args.arguments[i].value.block_type.num_entries; j++) { + if(options->args.arguments[i].value.block_type.entries[j].type == block->type) { + if(block->type != FLAC__METADATA_TYPE_APPLICATION || !options->args.arguments[i].value.block_type.entries[j].filter_application_by_id || 0 == memcmp(options->args.arguments[i].value.block_type.entries[j].application_id, block->data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8)) + matches_type = true; + } + } + } + else if(options->args.arguments[i].type == ARG__BLOCK_NUMBER) { + has_block_number_arg = true; + for(j = 0; j < options->args.arguments[i].value.block_number.num_entries; j++) { + if(options->args.arguments[i].value.block_number.entries[j] == block_number) + matches_number = true; + } + } + } + + if(!has_block_number_arg) + matches_number = true; + + if(options->args.checks.has_block_type) { + FLAC__ASSERT(!options->args.checks.has_except_block_type); + } + else if(options->args.checks.has_except_block_type) + matches_type = !matches_type; + else + matches_type = true; + + return matches_number && matches_type; +} + +void write_metadata(const char *filename, FLAC__StreamMetaData *block, unsigned block_number, FLAC__bool hexdump_application) +{ + unsigned i; + +#define PPR if(filename)printf("%s:",filename); + PPR; printf("METADATA block #%u\n", block_number); + PPR; printf(" type: %u (%s)\n", (unsigned)block->type, block->type<=FLAC__METADATA_TYPE_VORBIS_COMMENT? FLAC__MetaDataTypeString[block->type] : "UNKNOWN"); + PPR; printf(" is last: %s\n", block->is_last? "true":"false"); + PPR; printf(" length: %u\n", block->length); + + switch(block->type) { + case FLAC__METADATA_TYPE_STREAMINFO: + PPR; printf(" minumum blocksize: %u samples\n", block->data.stream_info.min_blocksize); + PPR; printf(" maximum blocksize: %u samples\n", block->data.stream_info.max_blocksize); + PPR; printf(" minimum framesize: %u bytes\n", block->data.stream_info.min_framesize); + PPR; printf(" maximum framesize: %u bytes\n", block->data.stream_info.max_framesize); + PPR; printf(" sample_rate: %u Hz\n", block->data.stream_info.sample_rate); + PPR; printf(" channels: %u\n", block->data.stream_info.channels); + PPR; printf(" bits-per-sample: %u\n", block->data.stream_info.bits_per_sample); + PPR; printf(" total samples: %llu\n", block->data.stream_info.total_samples); + PPR; printf(" MD5 signature: "); + for(i = 0; i < 16; i++) { + PPR; printf("%02x", block->data.stream_info.md5sum[i]); + } + PPR; printf("\n"); + break; + case FLAC__METADATA_TYPE_PADDING: + /* nothing to print */ + break; + case FLAC__METADATA_TYPE_APPLICATION: + PPR; printf(" application ID: "); + for(i = 0; i < 4; i++) { + PPR; printf("%02x", block->data.application.id[i]); + } + PPR; printf("\n"); + PPR; printf(" data contents:\n"); + if(0 != block->data.application.data) { + if(hexdump_application) + hexdump(filename, block->data.application.data, block->length - FLAC__STREAM_METADATA_HEADER_LENGTH, " "); + else + fwrite(block->data.application.data, 1, block->length - FLAC__STREAM_METADATA_HEADER_LENGTH, stdout); + } + break; + case FLAC__METADATA_TYPE_SEEKTABLE: + PPR; printf(" seek points: %u\n", block->data.seek_table.num_points); + for(i = 0; i < block->data.seek_table.num_points; i++) { + PPR; printf(" point %d: sample_number=%llu, stream_offset=%llu, frame_samples=%u\n", i, block->data.seek_table.points[i].sample_number, block->data.seek_table.points[i].stream_offset, block->data.seek_table.points[i].frame_samples); + } + break; + case FLAC__METADATA_TYPE_VORBIS_COMMENT: + break; + default: + PPR; printf("SKIPPING block of unknown type\n"); + break; + } +#undef PPR +} + +void hexdump(const char *filename, const FLAC__byte *buf, unsigned bytes, const char *indent) { unsigned i, left = bytes; const FLAC__byte *b = buf; for(i = 0; i < bytes; i += 16) { - printf("%s%08X: " + printf("%s%s%s%08X: " "%02X %02X %02X %02X %02X %02X %02X %02X " "%02X %02X %02X %02X %02X %02X %02X %02X " "%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n", + filename? filename:"", filename? ":":"", indent, i, left > 0? (unsigned char)b[ 0] : 0, left > 1? (unsigned char)b[ 1] : 0, @@ -729,100 +1476,3 @@ void hexdump(const FLAC__byte *buf, unsigned bytes, const char *indent) b += 16; } } - -char *local_strdup(const char *source) -{ - char *ret; - FLAC__ASSERT(0 != source); - if(0 == (ret = strdup(source))) { - fprintf(stderr, "ERROR: out of memory during strdup()\n"); - exit(1); - } - return ret; -} - -FLAC__bool parse_vorbis_comment_field(const char *field, char **name, char **value, unsigned *length) -{ - char *p, *s = local_strdup(field); - - if(0 == (p = strchr(s, '='))) { - free(s); - return false; - } - *p++ = '\0'; - *name = local_strdup(s); - *value = local_strdup(p); - *length = strlen(p); - - free(s); - return true; -} - -FLAC__bool parse_block_number(const char *in, Argument_BlockNumber *out) -{ - char *p, *q, *s; - int i; - unsigned entry; - - if(*in == '\0') - return false; - - s = local_strdup(in); - - /* first count the entries */ - for(out->num_entries = 1, p = strchr(s, ','); p; out->num_entries++, p = strchr(s, ',')) - ; - - /* make space */ - FLAC__ASSERT(out->num_entries > 0); - if(0 == (out->entries = malloc(sizeof(unsigned) * out->num_entries))) { - fprintf(stderr, "ERROR: out of memory allocating space for option list\n"); - exit(1); - } - - /* load 'em up */ - entry = 0; - q = s; - while(q) { - if(0 != (p = strchr(q, ','))) - *p++ = 0; - if(!isdigit((int)(*q)) || (i = atoi(q)) < 0) { - free(s); - return false; - } - FLAC__ASSERT(entry < out->num_entries); - out->entries[entry++] = (unsigned)i; - q = p; - } - FLAC__ASSERT(entry == out->num_entries); - - free(s); - return true; -} - -FLAC__bool parse_block_type(const char *in, Argument_BlockType *out) -{ - return true; -} - -FLAC__bool parse_data_format(const char *in, Argument_DataFormat *out) -{ - if(0 == strcmp(in, "binary")) - out->is_binary = true; - else if(0 == strcmp(in, "text")) - out->is_binary = false; - else - return false; - return true; -} - -FLAC__bool parse_application_data_format(const char *in, Argument_ApplicationDataFormat *out) -{ - if(0 == strcmp(in, "hexdump")) - out->is_hexdump = true; - else if(0 == strcmp(in, "text")) - out->is_hexdump = false; - else - return false; - return true; -}