Skip to content

Commit f1d9497

Browse files
author
twojstaryzdomu
committed
Support for ## as track # replacement token in basename
1 parent db68b68 commit f1d9497

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

ChangeLog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,6 @@
7474
Sealed various memory leaks. Refactored exit statements.
7575

7676
Abort further processing if output file already exists.
77+
78+
Added support for ## as track # replacement token in the basename
79+
parameter.

README

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@
128128
of the created track files. By default, the output files are
129129
now named after the basename of the source image file or the
130130
track #, ending with the appropriate format extension.
131+
basename may contain the track token '##' which will be
132+
replaced by the track number.
131133

132134
The -t flag adds the track # in the output filename between
133135
the basename & the extension, as in versions prior to 1.2.3.

bchunk.1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ as listed in the cue sheet. The wildcard '*' (single quoted to
1919
prevent shell expansion) selects all tracks from a cue sheet for
2020
conversion. image.cue is the cue sheet file containing track types
2121
and offsets. basename is optionally used for the beginning part of
22-
the created track files.
22+
the created track files. basename may contain the track token ##
23+
which will be replaced by the track number.
2324
.LP
2425
The produced .iso track contains an ISO file system, which can be
2526
mounted through a loop device on Linux systems, or

bchunk.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
#define WAV_DATA_HLEN 8
6060
#define WAV_HEADER_LEN WAV_RIFF_HLEN + WAV_FORMAT_HLEN + WAV_DATA_HLEN
6161

62+
#define TRACK_TOKEN "##"
63+
6264
/*
6365
* Ugly way to convert integers to little-endian format.
6466
* First let netinet's hton() functions decide if swapping should
@@ -439,7 +441,7 @@ int writetrack(FILE *bf, struct track_t *track)
439441
*/
440442

441443
int set_output(struct track_t *track, char *binfile, char *basefile, int trackadd) {
442-
char *t;
444+
char *e, *s, *t;
443445
if (strchr(binfile, '*')) {
444446
if (!basefile)
445447
bname = prune_ext(track->file);
@@ -460,6 +462,19 @@ int set_output(struct track_t *track, char *binfile, char *basefile, int trackad
460462
if (asprintf(&bname, "%s", basefile) == -1)
461463
die(4, "set_output(): asprintf() failed, out of memory\n");
462464
}
465+
if (basefile)
466+
if ((e = strstr(basefile, TRACK_TOKEN))) {
467+
int l = e - basefile;
468+
if (!(s = calloc(l + 1, 1)))
469+
die(4, "set_output(): calloc() failed, out of memory\n");
470+
strncpy(s, basefile, l);
471+
if (bname)
472+
t = bname;
473+
if (asprintf(&bname, "%s%.2d%s", s, track->num, e + strlen(TRACK_TOKEN)) == -1)
474+
die(4, "set_output(): asprintf() failed, out of memory\n");
475+
free(s);
476+
free(t);
477+
}
463478
if (trackadd) {
464479
if (bname)
465480
t = bname;

0 commit comments

Comments
 (0)