diff options
author | David Phillips <dbphillipsnz@gmail.com> | 2016-03-15 12:07:26 +1300 |
---|---|---|
committer | David Phillips <dbphillipsnz@gmail.com> | 2016-03-15 12:07:26 +1300 |
commit | a15bbce5f576ba248fa082a5341ed9be9c0e02ce (patch) | |
tree | 26733e60d37a94818a61e17b8fd560b56b511405 | |
parent | 69d62f539a4354d9cda85bb4748e1318abb0532f (diff) | |
parent | 1e161f2c7ae3602d2cf70e693ef3cee67ae786e9 (diff) | |
download | cue-bin-split-a15bbce5f576ba248fa082a5341ed9be9c0e02ce.tar.xz |
Merge branch 'develop'
-rw-r--r-- | cue-bin-split.c | 74 | ||||
-rw-r--r-- | cue-bin-split.h | 9 | ||||
-rw-r--r-- | misc.c | 3 | ||||
-rw-r--r-- | misc.h | 9 |
4 files changed, 45 insertions, 50 deletions
diff --git a/cue-bin-split.c b/cue-bin-split.c index 9959d82..8616aef 100644 --- a/cue-bin-split.c +++ b/cue-bin-split.c @@ -25,9 +25,50 @@ * SUCH DAMAGE. */ +#include <stdio.h> +#include <stdlib.h> +#include <limits.h> +#include <unistd.h> + #include "cue-bin-split.h" #include "misc.h" +void args_collect(int *argc, char ***argv, int *rate, int *channels, int *sample_size, char **in_fname, char **format) +{ + char opt = '\0'; + while ( ( opt = getopt(*argc, *argv, "r:c:i:s:f:") ) != -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 'f': *format = optarg; break; + + case '?': + default: + die_help(); + break; + } + } + + 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 || + *format == NULL) + { + fprintf(stderr, "ERROR: Input filename and output name format must be present\n"); + die_help(); + } +} + int main(int argc, char **argv) { /* File handles */ @@ -42,7 +83,6 @@ 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; @@ -55,37 +95,7 @@ int main(int argc, char **argv) unsigned long start_sample = 0; unsigned long finish_sample = 0; - while ( ( opt = getopt(argc, argv, "r:c:i:s:f:") ) != -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 'f': format = optarg; break; - - case '?': - default: - die_help(); - break; - } - } - - 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 || - format == NULL) - { - fprintf(stderr, "ERROR: Input filename and output name format must be present\n"); - die_help(); - } + args_collect(&argc, &argv, &rate, &channels, &sample_size, &in_fname, &format); /* Open it up */ if ((fin = fopen(in_fname, "r")) == NULL) diff --git a/cue-bin-split.h b/cue-bin-split.h index 604bea5..e689bbf 100644 --- a/cue-bin-split.h +++ b/cue-bin-split.h @@ -25,14 +25,5 @@ * SUCH DAMAGE. */ -#ifndef CUE_BIN_SPLIT_H -#define CUE_BIN_SPLIT_H - -#include <stdio.h> -#include <limits.h> -#include <getopt.h> - #define FRAMES_PER_SEC 75 #define BUFFER_SIZE 1024*1024 /* Meh, good enough */ - -#endif @@ -25,6 +25,9 @@ * SUCH DAMAGE. */ +#include <stdio.h> +#include <stdlib.h> + #include "misc.h" /* Grabs a 'mm:ss:ff' stamp from stdin */ @@ -25,12 +25,6 @@ * SUCH DAMAGE. */ -#ifndef MISC_H -#define MISC_H - -#include <stdio.h> -#include <stdlib.h> - #include "cue-bin-split.h" /* MIN is surely defined in a standard header */ @@ -40,6 +34,3 @@ double get_sec(); int construct_out_name(char *buffer, size_t buffer_size, char* format, unsigned int track); void die_help(); - - -#endif |