5656#define WAV_DATA_HLEN 8
5757#define WAV_HEADER_LEN WAV_RIFF_HLEN + WAV_FORMAT_HLEN + WAV_DATA_HLEN
5858
59+ #define TRACK_TOKEN "##"
60+
5961/*
6062 * Ugly way to convert integers to little-endian format.
6163 * First let netinet's hton() functions decide if swapping should
@@ -435,7 +437,7 @@ int writetrack(FILE *bf, struct track_t *track)
435437 */
436438
437439int set_output (struct track_t * track , char * binfile , char * basefile , int trackadd ) {
438- char * t ;
440+ char * e , * s , * t ;
439441 if (strchr (binfile , '*' )) {
440442 if (!basefile )
441443 bname = prune_ext (track -> file );
@@ -456,6 +458,20 @@ int set_output(struct track_t *track, char *binfile, char *basefile, int trackad
456458 if (asprintf (& bname , "%s" , basefile ) == -1 )
457459 die (3 , "set_output(): asprintf() failed, out of memory\n" );
458460 }
461+ if (basefile )
462+ if (e = strstr (basefile , TRACK_TOKEN )) {
463+ int l = e - basefile ;
464+ if (!(s = malloc (l + 1 )))
465+ die (3 , "set_output(): malloc() failed, out of memory\n" );
466+ strncpy (s , basefile , l );
467+ s [l ] = '\0' ;
468+ if (bname )
469+ t = bname ;
470+ if (asprintf (& bname , "%s%.2d%s" , s , track -> num , e + strlen (TRACK_TOKEN )) == -1 )
471+ die (3 , "set_output(): asprintf() failed, out of memory\n" );
472+ free (s );
473+ free (t );
474+ }
459475 if (trackadd ) {
460476 if (bname )
461477 t = bname ;
@@ -469,9 +485,9 @@ int set_output(struct track_t *track, char *binfile, char *basefile, int trackad
469485 bname = NULL ;
470486 if (strcmp (track -> output , track -> file ) == 0 )
471487 die_format (3 , "%2d: skipped: output file %s same as input file, aborting\n"
472- "\nUse '-t' to include track # in output filename. "
488+ "\nUse '-t' to include track # in filename or set '%s' in basename . "
473489 "Remaining tracks were not processed\n" ,
474- track -> num , track -> output );
490+ track -> num , track -> output , TRACK_TOKEN );
475491 return 1 ;
476492}
477493
0 commit comments