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
441443int 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,20 @@ 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 = malloc (l + 1 )))
469+ die (4 , "set_output(): malloc() failed, out of memory\n" );
470+ strncpy (s , basefile , l );
471+ s [l ] = '\0' ;
472+ if (bname )
473+ t = bname ;
474+ if (asprintf (& bname , "%s%.2d%s" , s , track -> num , e + strlen (TRACK_TOKEN )) == -1 )
475+ die (4 , "set_output(): asprintf() failed, out of memory\n" );
476+ free (s );
477+ free (t );
478+ }
463479 if (trackadd ) {
464480 if (bname )
465481 t = bname ;
0 commit comments