aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Phillips <dbphillipsnz@gmail.com>2015-07-06 22:41:42 +1200
committerDavid Phillips <dbphillipsnz@gmail.com>2015-07-06 22:41:42 +1200
commit7b34eeaf4ed9769398afd7a386b5a1b5ea7b6e64 (patch)
tree0fb5097de102cf93d468a6e2c9e0bbd24c02bab5
parenta1eb346eb16820b69f8f0a23ef27deb0b8f96ec7 (diff)
downloadcue-bin-split-7b34eeaf4ed9769398afd7a386b5a1b5ea7b6e64.tar.xz
Migration of stuff to misc.c
-rw-r--r--cue-bin-split.c42
-rw-r--r--misc.c25
-rw-r--r--misc.h1
3 files changed, 29 insertions, 39 deletions
diff --git a/cue-bin-split.c b/cue-bin-split.c
index 9092bc5..70de27f 100644
--- a/cue-bin-split.c
+++ b/cue-bin-split.c
@@ -33,22 +33,6 @@
#include "cue-bin-split.h"
#include "misc.h"
-
-/* FIXME move me */
-void die_help()
-{
- fprintf(stderr,
- "\n"
- "Options: \n"
- " -r bitrate_Hz\n"
- " -c channel_count\n"
- " -i input_file\n"
- " -s size of a single channel's sample (bytes)\n"
- " -f name_format (%%d and co are replaced with track number)\n"
- );
- exit(EXIT_FAILURE);
-}
-
int main(int argc, char **argv)
{
/* File handles */
@@ -85,26 +69,12 @@ int main(int argc, char **argv)
{
switch (opt)
{
- case 'r':
- rate = atoi(optarg);
- break;
-
- case 'c':
- channels = atoi(optarg);
- break;
-
- case 'i':
- in_fname = optarg;
- break;
-
- case 's':
- sample_size = atoi(optarg);
- break;
-
- case 'f':
- format = optarg;
- break;
-
+ 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();
diff --git a/misc.c b/misc.c
index a2e42ee..3b78d4a 100644
--- a/misc.c
+++ b/misc.c
@@ -27,13 +27,15 @@
#include "misc.h"
+/* Grabs a 'mm:ss:ff' stamp from stdin */
int get_stamp(int *m, int *s, int *f)
{
- int foo = 0;
- foo = fscanf(stdin, "%d:%d:%d\n", m, s, f);
- return foo;
+ return fscanf(stdin, "%d:%d:%d\n", m, s, f);
}
+/* Constructs an output filename in the specified buffer based on the given format and track number
+ * Main purpose is to catch buffer overflow with snprintf
+ */
void construct_out_name(char *buffer, size_t buffer_size, char* format, unsigned int track)
{
if (snprintf(buffer, buffer_size, format, track) == buffer_size)
@@ -43,3 +45,20 @@ void construct_out_name(char *buffer, size_t buffer_size, char* format, unsigned
}
return EXIT_SUCCESS;
}
+
+/* Displays the help/syntax message and dies
+ * Does what it says on the tin
+ */
+void die_help()
+{
+ fprintf(stderr,
+ "\n"
+ "Options: \n"
+ " -r bitrate_Hz\n"
+ " -c channel_count\n"
+ " -i input_file\n"
+ " -s size of a single channel's sample (bytes)\n"
+ " -f name_format (%%d and co are replaced with track number)\n"
+ );
+ exit(EXIT_FAILURE);
+}
diff --git a/misc.h b/misc.h
index 1a1fb7b..813c73b 100644
--- a/misc.h
+++ b/misc.h
@@ -33,6 +33,7 @@
int get_stamp(int *m, int *s, int *f);
void construct_out_name(char *buffer, size_t buffer_size, char* format, unsigned int track);
+void die_help();
#endif