Skip to content

Commit

Permalink
Permit ## as track token in basename
Browse files Browse the repository at this point in the history
  • Loading branch information
twojstaryzdomu committed Jun 28, 2022
1 parent 96cad2e commit b541537
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion bchunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
#define WAV_DATA_HLEN 8
#define WAV_HEADER_LEN WAV_RIFF_HLEN + WAV_FORMAT_HLEN + WAV_DATA_HLEN

#define TRACK_TOKEN "##"

/*
* Ugly way to convert integers to little-endian format.
* First let netinet's hton() functions decide if swapping should
Expand Down Expand Up @@ -439,7 +441,7 @@ int writetrack(FILE *bf, struct track_t *track)
*/

int set_output(struct track_t *track, char *binfile, char *basefile, int trackadd) {
char *t;
char *e, *s, *t;
if (strchr(binfile, '*')) {
if (!basefile)
bname = prune_ext(track->file);
Expand All @@ -460,6 +462,20 @@ int set_output(struct track_t *track, char *binfile, char *basefile, int trackad
if (asprintf(&bname, "%s", basefile) == -1)
die(4, "set_output(): asprintf() failed, out of memory\n");
}
if (basefile)
if (e = strstr(basefile, TRACK_TOKEN)) {
int l = e - basefile;
if (!(s = malloc(l + 1)))
die(4, "set_output(): malloc() failed, out of memory\n");
strncpy(s, basefile, l);
s[l] = '\0';
if (bname)
t = bname;
if (asprintf(&bname, "%s%.2d%s", s, track->num, e + strlen(TRACK_TOKEN)) == -1)
die(4, "set_output(): asprintf() failed, out of memory\n");
free(s);
free(t);
}
if (trackadd) {
if (bname)
t = bname;
Expand Down

0 comments on commit b541537

Please sign in to comment.