From 0bfcc2118254ed640a897699e28fd34f2ba9ec68 Mon Sep 17 00:00:00 2001 From: David Phillips Date: Mon, 6 Jul 2015 22:34:11 +1200 Subject: Removed FIXMEs, started condensing logic Renamed `index` to `track` --- Makefile | 2 +- cue-bin-split.c | 23 ++++++----------------- misc.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ misc.h | 38 ++++++++++++++++++++++++++++++++++++++ timestamp.c | 35 ----------------------------------- timestamp.h | 35 ----------------------------------- 6 files changed, 90 insertions(+), 88 deletions(-) create mode 100644 misc.c create mode 100644 misc.h delete mode 100644 timestamp.c delete mode 100644 timestamp.h 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 #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/misc.c b/misc.c new file mode 100644 index 0000000..a2e42ee --- /dev/null +++ b/misc.c @@ -0,0 +1,45 @@ +/* + * Part of cue-bin-split - Splits raw PCM files on time boundaries + * Copyright (c) 2015 David Phillips + * All rights reserved + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include "misc.h" + +int get_stamp(int *m, int *s, int *f) +{ + int foo = 0; + 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/misc.h b/misc.h new file mode 100644 index 0000000..1a1fb7b --- /dev/null +++ b/misc.h @@ -0,0 +1,38 @@ +/* + * Part of cue-bin-split - Splits raw PCM files on time boundaries + * Copyright (c) 2015 David Phillips + * All rights reserved + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef CUE_BIN_SPLIT_TIMESTAMP_H +#define CUE_BIN_SPLIT_TIMESTAMP_H + +#include +#include + +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 diff --git a/timestamp.c b/timestamp.c deleted file mode 100644 index 44f793b..0000000 --- a/timestamp.c +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Part of cue-bin-split - Splits raw PCM files on time boundaries - * Copyright (c) 2015 David Phillips - * All rights reserved - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include "timestamp.h" - -int get_stamp(int *m, int *s, int *f) -{ - int foo = 0; - foo = fscanf(stdin, "%d:%d:%d\n", m, s, f); - return foo; -} diff --git a/timestamp.h b/timestamp.h deleted file mode 100644 index 4706189..0000000 --- a/timestamp.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Part of cue-bin-split - Splits raw PCM files on time boundaries - * Copyright (c) 2015 David Phillips - * All rights reserved - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef CUE_BIN_SPLIT_TIMESTAMP_H -#define CUE_BIN_SPLIT_TIMESTAMP_H - -#include - -int get_stamp(int *m, int *s, int *f); - -#endif -- cgit v1.1