aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Phillips <dbphillipsnz@gmail.com>2015-07-06 22:34:11 +1200
committerDavid Phillips <dbphillipsnz@gmail.com>2015-07-06 22:34:11 +1200
commit0bfcc2118254ed640a897699e28fd34f2ba9ec68 (patch)
tree40c37d89c0f429fec2d32ab911538f2d9c6cfeae
parentb4968b46800ca1ee6064feea29754d1eaa04511b (diff)
downloadcue-bin-split-0bfcc2118254ed640a897699e28fd34f2ba9ec68.tar.xz
Removed FIXMEs, started condensing logic
Renamed `index` to `track`
-rw-r--r--Makefile2
-rw-r--r--cue-bin-split.c23
-rw-r--r--misc.c (renamed from timestamp.c)12
-rw-r--r--misc.h (renamed from timestamp.h)3
4 files changed, 21 insertions, 19 deletions
diff --git a/Makefile b/Makefile
index a2ea28f..62611f9 100644
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,7 @@ include config.mk
OBJECTS = \
cue-bin-split.o \
- timestamp.o
+ misc.o
CFLAGS += -Wall -Werror
diff --git a/cue-bin-split.c b/cue-bin-split.c
index 12d8e3a..2189516 100644
--- a/cue-bin-split.c
+++ b/cue-bin-split.c
@@ -31,7 +31,7 @@
#include <getopt.h>
#include "cue-bin-split.h"
-#include "timestamp.h"
+#include "misc.h"
/* FIXME move me */
@@ -65,7 +65,7 @@ int main(int argc, char **argv)
/* Misc */
char opt = 0;
char out_fname[] = "track-000000000000"; /* That should do it */
- int index = 0;
+ int track = 0;
int items = 0;
int i = 0;
char buffer[BUFFER_SIZE];
@@ -129,21 +129,15 @@ int main(int argc, char **argv)
return EXIT_FAILURE;
}
- index = 0;
+ track = 0;
items = get_stamp(&mm, &ss, &ff); /* FIXME doesn't check return value */
start_sec = (double)mm*60 + (double)ss + ((double)ff)/FRAMES_PER_SEC;
while ( ( items = get_stamp(&mm, &ss, &ff) ) )
{
- index++;
+ track++;
- i = snprintf(out_fname, sizeof(out_fname), format, index);
- if (i == sizeof(out_fname))
- {
- fprintf(stderr, "Filename too large for buffer\n");
- fclose(fin);
- return EXIT_FAILURE;
- }
+ construct_out_name(out_fname, sizeof(out_fname), format, track);
/* Open output file */
if ((fout = fopen(out_fname, "w")) == NULL)
@@ -162,7 +156,7 @@ int main(int argc, char **argv)
/* Following track starts at end of last */
if (items != 3)
{
- fprintf(stderr, "Timestamp #%d malformed\n", index);
+ fprintf(stderr, "Timestamp #%d malformed\n", track);
break;
}
finish_sec = (double)mm*60 + (double)ss + ((double)ff)/75;
@@ -172,7 +166,6 @@ int main(int argc, char **argv)
start_sample = start_sec * rate * channels;
finish_sample = finish_sec * rate * channels;
-
/* Seek to first sample of track */
fseek(fin, (start_sample * sample_size), SEEK_SET);
@@ -180,8 +173,6 @@ int main(int argc, char **argv)
{
for (i = (int)start_sample; i < (int)finish_sample; i += items)
{
- /* FIXME unnecessary call to fwrite with items == 0 possible */
- /* FIXME Handle EOF properly, silly! */
if ((items = fread(buffer, sample_size, sizeof(buffer)/sample_size, fin)))
{
if (feof(fin))
@@ -192,7 +183,6 @@ int main(int argc, char **argv)
} else {
for (i = (int)start_sample; ; i += items)
{
- /* FIXME unnecessary call to fwrite with items == 0 possible */
if ((items = fread(buffer, sample_size, sizeof(buffer)/sample_size, fin)))
{
if (feof(fin))
@@ -200,7 +190,6 @@ int main(int argc, char **argv)
fwrite(buffer, items, sample_size, fout);
}
}
-
}
fclose(fout);
start_sec = finish_sec;
diff --git a/timestamp.c b/misc.c
index 44f793b..a2e42ee 100644
--- a/timestamp.c
+++ b/misc.c
@@ -25,7 +25,7 @@
* SUCH DAMAGE.
*/
-#include "timestamp.h"
+#include "misc.h"
int get_stamp(int *m, int *s, int *f)
{
@@ -33,3 +33,13 @@ int get_stamp(int *m, int *s, int *f)
foo = fscanf(stdin, "%d:%d:%d\n", m, s, f);
return foo;
}
+
+void construct_out_name(char *buffer, size_t buffer_size, char* format, unsigned int track)
+{
+ if (snprintf(buffer, buffer_size, format, track) == buffer_size)
+ {
+ fprintf(stderr, "Filename too large for buffer (max %zd)\n", buffer_size);
+ return EXIT_FAILURE;
+ }
+ return EXIT_SUCCESS;
+}
diff --git a/timestamp.h b/misc.h
index 4706189..1a1fb7b 100644
--- a/timestamp.h
+++ b/misc.h
@@ -29,7 +29,10 @@
#define CUE_BIN_SPLIT_TIMESTAMP_H
#include <stdio.h>
+#include <stdlib.h>
int get_stamp(int *m, int *s, int *f);
+void construct_out_name(char *buffer, size_t buffer_size, char* format, unsigned int track);
+
#endif