From 84dad69b341c481c9c9503768174359cc9dc55f1 Mon Sep 17 00:00:00 2001 From: David Phillips Date: Mon, 5 Sep 2016 21:30:33 +1200 Subject: Pull ugly parse_args back out --- cue-bin-split.c | 67 ++++++++++++++++++++++++++------------------------------- 1 file changed, 31 insertions(+), 36 deletions(-) diff --git a/cue-bin-split.c b/cue-bin-split.c index 89b4114..d4711b3 100644 --- a/cue-bin-split.c +++ b/cue-bin-split.c @@ -57,41 +57,6 @@ void die_help() exit(1); } -void args_collect(int *argc, char ***argv, int *rate, int *channels, int *sample_size, char **in_fname, char **name) -{ - char opt = '\0'; - while ( ( opt = getopt(*argc, *argv, "r:c:i:s:n:") ) != -1 ) - { - switch (opt) - { - case 'r': *rate = atoi(optarg); break; - case 'c': *channels = atoi(optarg); break; - case 's': *sample_size = atoi(optarg); break; - case 'i': *in_fname = optarg; break; - case 'n': *name = optarg; break; - - case '?': - default: - die_help(); - } - } - - if (*channels <= 0 || - *rate <= 0 || - *sample_size <= 0) - { - fprintf(stderr, "ERROR: Channel count, bitrate and sample size must all be present and positive\n"); - die_help(); - } - - if (*in_fname == NULL || - *name == NULL) - { - fprintf(stderr, "ERROR: Input filename and output name must be present\n"); - die_help(); - } -} - int main(int argc, char **argv) { /* File handles */ @@ -106,6 +71,7 @@ int main(int argc, char **argv) int sample_size = 0; /* Misc */ + char opt = '\0'; char out_fname[1024]; /* That should do it. Note: overflow IS caught */ int track = 0; int items = 0; @@ -118,7 +84,36 @@ int main(int argc, char **argv) unsigned long start_sample = 0; unsigned long finish_sample = 0; - args_collect(&argc, &argv, &rate, &channels, &sample_size, &in_fname, &name); + while ( ( opt = getopt(argc, argv, "r:c:i:s:n:") ) != -1 ) + { + switch (opt) + { + case 'r': rate = atoi(optarg); break; + case 'c': channels = atoi(optarg); break; + case 's': sample_size = atoi(optarg); break; + case 'i': in_fname = optarg; break; + case 'n': name = optarg; break; + + case '?': + default: + die_help(); + } + } + + if (channels <= 0 || + rate <= 0 || + sample_size <= 0) + { + fprintf(stderr, "ERROR: Channel count, bitrate and sample size must all be present and positive\n"); + die_help(); + } + + if (in_fname == NULL || + name == NULL) + { + fprintf(stderr, "ERROR: Input filename and output name must be present\n"); + die_help(); + } /* Open it up */ if ((fin = fopen(in_fname, "r")) == NULL) -- cgit v1.1