aboutsummaryrefslogtreecommitdiff
path: root/cue-bin-split.c
diff options
context:
space:
mode:
authorDavid Phillips <dbphillipsnz@gmail.com>2015-07-06 11:47:24 +1200
committerDavid Phillips <dbphillipsnz@gmail.com>2015-07-06 11:47:24 +1200
commit0a13ff9a4815d1ad07f9655d1d662dd9e0a284f0 (patch)
tree4572f3b4c15d1d09e886367107149fe743672e15 /cue-bin-split.c
parent8416d0f0b1da0c4f5e89f1588f797df749b43a70 (diff)
downloadcue-bin-split-0a13ff9a4815d1ad07f9655d1d662dd9e0a284f0.tar.xz
Specify custom filename format
Diffstat (limited to 'cue-bin-split.c')
-rw-r--r--cue-bin-split.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/cue-bin-split.c b/cue-bin-split.c
index 69423ae..0a1e7ab 100644
--- a/cue-bin-split.c
+++ b/cue-bin-split.c
@@ -33,8 +33,9 @@ int main(int argc, char **argv)
{
FILE *fin = NULL;
FILE *fout = NULL;
+ char *format = NULL;
char *in_fname = NULL;
- char out_fname[] = "track-0000";
+ char out_fname[] = "track-000000000000"; /* That should do it */
int m = 0;
int s = 0;
int frame = 0;
@@ -53,17 +54,19 @@ int main(int argc, char **argv)
/* FIXME Use getopt */
/* FIXME Replace assertions with useful checks+messages */
- assert(argc == 5);
+ assert(argc == 6);
in_fname = argv[1];
channels = atoi(argv[2]);
rate = atoi(argv[3]);
sample_size = atoi(argv[4]);
+ format = argv[5];
assert(channels > 0);
assert(rate > 0);
assert(sample_size > 0);
assert(in_fname != NULL);
+ assert(format != NULL);
/* Open it up */
if ((fin = fopen(in_fname, "r")) == NULL)
@@ -83,13 +86,22 @@ int main(int argc, char **argv)
while ( ( items = fscanf(stdin, "%d:%d:%d\n", &m, &s, &frame) ) )
{
index++;
- sprintf(out_fname, "track_%04d", index);
+
+ 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;
+ }
+
/* Open output file */
if ((fout = fopen(out_fname, "w")) == NULL)
{
fprintf(stderr,"Failed to open '%s': ", out_fname);
perror("fopen");
+ fclose(fin);
return EXIT_FAILURE;
}
@@ -148,5 +160,6 @@ int main(int argc, char **argv)
if (finish < 0)
break;
}
+ return 0;
}