aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Phillips <dbphillipsnz@gmail.com>2016-03-15 11:56:13 +1300
committerDavid Phillips <dbphillipsnz@gmail.com>2016-03-15 11:56:13 +1300
commite648fe8700dbc1afe97e7724ec892c2947ca0b41 (patch)
tree330cd9c089d8a853ddeb93fda0fe2918232b7bb3
parent69d62f539a4354d9cda85bb4748e1318abb0532f (diff)
downloadcue-bin-split-e648fe8700dbc1afe97e7724ec892c2947ca0b41.tar.xz
Segment the argument logic into own function
-rw-r--r--cue-bin-split.c69
1 files changed, 37 insertions, 32 deletions
diff --git a/cue-bin-split.c b/cue-bin-split.c
index 9959d82..3df2966 100644
--- a/cue-bin-split.c
+++ b/cue-bin-split.c
@@ -28,6 +28,42 @@
#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 +78,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 +90,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)