Description: <short summary of the patch>
 TODO: Put a short summary on the line above and replace this paragraph
 with a longer explanation of this change. Complete the meta-information
 with other relevant fields (see below for details). To make it easier, the
 information below has been extracted from the changelog. Adjust it or drop
 it.
 .
 bchunk (1.2.2+git20220715+ds-1) unstable; urgency=medium
 .
   * New upstream version from fork. (Closes: #261278, #271285)
   * Bump standards version to 4.6.1.
   * Bump debhelper version to 13, drop d/compat.
   * Update maintainer address.
Author: Gürkan Myczko <tar@debian.org>
Bug-Debian: https://bugs.debian.org/261278
Bug-Debian: https://bugs.debian.org/271285

---
The information above should follow the Patch Tagging Guidelines, please
checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:

Origin: <vendor|upstream|other>, <url of original patch>
Bug: <url in upstream bugtracker>
Bug-Debian: https://bugs.debian.org/<bugnumber>
Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
Forwarded: <no|not-needed|url proving that it has been forwarded>
Reviewed-By: <name and email of someone who approved the patch>
Last-Update: 2022-07-15

--- bchunk-1.2.2+git20220715+ds.orig/COPYING
+++ bchunk-1.2.2+git20220715+ds/COPYING
@@ -1,12 +1,13 @@
-                    GNU GENERAL PUBLIC LICENSE
-                       Version 2, June 1991
 
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+		    GNU GENERAL PUBLIC LICENSE
+		       Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+                       59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  Everyone is permitted to copy and distribute verbatim copies
  of this license document, but changing it is not allowed.
 
-                            Preamble
+			    Preamble
 
   The licenses for most software are designed to take away your
 freedom to share and change it.  By contrast, the GNU General Public
@@ -15,7 +16,7 @@ software--to make sure the software is f
 General Public License applies to most of the Free Software
 Foundation's software and to any other program whose authors commit to
 using it.  (Some other Free Software Foundation software is covered by
-the GNU Lesser General Public License instead.)  You can apply it to
+the GNU Library General Public License instead.)  You can apply it to
 your programs, too.
 
   When we speak of free software, we are referring to freedom, not
@@ -55,8 +56,8 @@ patent must be licensed for everyone's f
 
   The precise terms and conditions for copying, distribution and
 modification follow.
-
-                    GNU GENERAL PUBLIC LICENSE
+
+		    GNU GENERAL PUBLIC LICENSE
    TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
 
   0. This License applies to any program or other work which contains
@@ -110,7 +111,7 @@ above, provided that you also meet all o
     License.  (Exception: if the Program itself is interactive but
     does not normally print such an announcement, your work based on
     the Program is not required to print an announcement.)
-
+
 These requirements apply to the modified work as a whole.  If
 identifiable sections of that work are not derived from the Program,
 and can be reasonably considered independent and separate works in
@@ -168,7 +169,7 @@ access to copy from a designated place,
 access to copy the source code from the same place counts as
 distribution of the source code, even though third parties are not
 compelled to copy the source along with the object code.
-
+
   4. You may not copy, modify, sublicense, or distribute the Program
 except as expressly provided under this License.  Any attempt
 otherwise to copy, modify, sublicense or distribute the Program is
@@ -225,7 +226,7 @@ impose that choice.
 
 This section is intended to make thoroughly clear what is believed to
 be a consequence of the rest of this License.
-
+
   8. If the distribution and/or use of the Program is restricted in
 certain countries either by patents or by copyrighted interfaces, the
 original copyright holder who places the Program under this License
@@ -255,7 +256,7 @@ make exceptions for this.  Our decision
 of preserving the free status of all derivatives of our free software and
 of promoting the sharing and reuse of software generally.
 
-                            NO WARRANTY
+			    NO WARRANTY
 
   11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
 FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
@@ -277,9 +278,9 @@ YOU OR THIRD PARTIES OR A FAILURE OF THE
 PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
 POSSIBILITY OF SUCH DAMAGES.
 
-                     END OF TERMS AND CONDITIONS
-
-            How to Apply These Terms to Your New Programs
+		     END OF TERMS AND CONDITIONS
+
+	    How to Apply These Terms to Your New Programs
 
   If you develop a new program, and you want it to be of the greatest
 possible use to the public, the best way to achieve this is to make it
@@ -291,7 +292,7 @@ convey the exclusion of warranty; and ea
 the "copyright" line and a pointer to where the full notice is found.
 
     <one line to give the program's name and a brief idea of what it does.>
-    Copyright (C) <year>  <name of author>
+    Copyright (C) 19yy  <name of author>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -303,16 +304,17 @@ the "copyright" line and a pointer to wh
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.
 
-    You should have received a copy of the GNU General Public License along
-    with this program; if not, write to the Free Software Foundation, Inc.,
-    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
 
 Also add information on how to contact you by electronic and paper mail.
 
 If the program is interactive, make it output a short notice like this
 when it starts in an interactive mode:
 
-    Gnomovision version 69, Copyright (C) year name of author
+    Gnomovision version 69, Copyright (C) 19yy name of author
     Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
     This is free software, and you are welcome to redistribute it
     under certain conditions; type `show c' for details.
@@ -335,5 +337,5 @@ necessary.  Here is a sample; alter the
 This General Public License does not permit incorporating your program into
 proprietary programs.  If your program is a subroutine library, you may
 consider it more useful to permit linking proprietary applications with the
-library.  If this is what you want to do, use the GNU Lesser General
+library.  If this is what you want to do, use the GNU Library General
 Public License instead of this License.
--- bchunk-1.2.2+git20220715+ds.orig/ChangeLog
+++ bchunk-1.2.2+git20220715+ds/ChangeLog
@@ -63,19 +63,3 @@
 	Clarify manual page for input/output file types
 	Improvement from Reuben Thomas, debian bug: #503151
 
-1.2.3 - Jun 30 2022 - twojstaryzdomu
-
-	Added support for track # and multiple bin FILEs in cue sheet.
-	The output files are now named after the FILE with the appropriate
-	output extension added, without a track # inserted in between the
-	basename and the extension. The -t option includes the track # in
-	the output filenames as done by default in earlier releases.
-
-	Sealed various memory leaks. Refactored exit statements.
-
-	Abort further processing if output file already exists.
-
-	Added support for ## as track # replacement token in the basename
-	parameter.
-
-	Added support for splitting WAV files into individual tracks.
--- bchunk-1.2.2+git20220715+ds.orig/Makefile
+++ bchunk-1.2.2+git20220715+ds/Makefile
@@ -12,9 +12,6 @@ CFLAGS = -Wall -Wstrict-prototypes -O2
 
 # For BSD install: Which install to use and where to put the files
 INSTALL = install
-INSTALL_DIR = $(INSTALL) -d -m 0755
-INSTALL_DATA = $(INSTALL) -m 0644
-INSTALL_EXEC = $(INSTALL) -m 0755
 PREFIX  = /usr/local
 BIN_DIR = $(PREFIX)/bin
 MAN_DIR = $(PREFIX)/man
@@ -29,16 +26,14 @@ distclean: clean
 
 install: installbin installman
 installbin:
-	$(INSTALL_DIR) $(DESTDIR)$(BIN_DIR)
-	$(INSTALL_EXEC) -s bchunk $(DESTDIR)$(BIN_DIR)
+	$(INSTALL) -m 755 -s bchunk		$(BIN_DIR)
 installman:
-	$(INSTALL_DIR) $(DESTDIR)$(MAN_DIR)/man1
-	$(INSTALL_DATA) bchunk.1 $(DESTDIR)$(MAN_DIR)/man1
+	$(INSTALL) -m 644 bchunk.1	 	$(MAN_DIR)/man1
 
 BITS = bchunk.o
 
 bchunk: $(BITS)
-	$(LD) -o bchunk $(BITS) $(LDFLAGS)
+	$(LD) $(LDFLAGS) -o bchunk $(BITS)
 
 bchunk.o:	bchunk.c
 
--- bchunk-1.2.2+git20220715+ds.orig/README
+++ bchunk-1.2.2+git20220715+ds/README
@@ -1,5 +1,5 @@
 
-	binchunker for Unix, version 1.2.3
+	binchunker for Unix, version 1.2.2
 	Copyright (C) 1998-2004  Heikki Hannikainen <hessu@hes.iki.fi>
 	
 	Enhancements provided by:
@@ -9,7 +9,6 @@
 		Piotr Kaczuba <pepe@attika.ath.cx>, 2009
 		Reuben Thomas <rrt@femur.dyndns.org>, 2008
 		Yegor Timoshenko <yegortimoshenko@gmail.com>, 2017
-		twojstaryzdomu <@github.com>, 2022
 
 		
 	http://he.fi/bchunk/
@@ -53,7 +52,7 @@
 	Colas Nahaboo <Colas@Nahaboo.com> and Godmar Back <gback@cs.utah.edu>
 	added support for MODE2/2352 ISO data tracks in bchunk 1.1.0.
 	Matthew Green implemented the -r option for raw MODE2/2352
-	extraction for bchunk 1.2.0.
+	exctraction for bchunk 1.2.0.
   	
   	---
   
@@ -62,9 +61,6 @@
   	binchunker converts a CD image in a ".bin / .cue" format
   	(sometimes ".raw / .cue") to a set of .iso and .cdr tracks.
   	
-  	It also allows to split uncompressed PCM audio files in the
-  	WAV format into individual tracks.
-  	
   	The bin/cue format is used by some non-Unix cd-writing
   	software, but is not supported on most other cd-writing
   	programs.
@@ -89,8 +85,8 @@
   	
   How to install this stuff:
   	
-  	$ gzip -d -c bchunk-1.2.3.tar.gz | tar xvf -
-  	$ cd bchunk-1.2.3
+  	$ gzip -d -c bchunk-1.2.2.tar.gz | tar xvf -
+  	$ cd bchunk-1.2.2
   	$ make
   	# make install
   	
@@ -120,23 +116,13 @@
   	
   How to use this stuff:
   	
-  	bchunk [-t] [-v] [-p (PSX)] [-r (raw)] [-w (wav)] [-s (swabaudio)]
-         <image.bin | image.wav | track # | '*'> <image.cue> [ <basename> ]
+  	bchunk [-v] [-p (PSX)] [-r (raw)] [-w (wav)] [-s (swabaudio)]
+  	  <image.bin> <image.cue> <basename>
   	
-  	image.bin is a source raw cd image file and image.wav is an
-  	uncompressed PCM audio file, either listed in the
-  	cue sheet file as a FILE. track # identifies the track listed
-  	in the cue sheet as a TRACK. The wildcard '*' (quoted)
-  	selects all tracks for conversion. image.cue is the cue sheet
-  	file containing filenames, track types and offsets. The optional
-  	basename is used for the leading part of the output filenames.
-  	By default, the output files are now named after the basename
-  	of the source image file or the track #, ending with the
-  	appropriate format extension. basename may contain the track
-  	token ## which will be replaced by the track number.
-	
-	The -t flag adds the track # in the output filename between
-	the basename & the extension, as in versions prior to 1.2.3.
+  	image.bin is the raw cd image file. image.cue is the
+  	track index file containing track types and offsets.
+  	basename is used for the beginning part of the created
+  	track files.
 	
 	The -v flag makes binchunker print some more unnecessary
 	messages, which should not be of interest for anyone.
@@ -151,7 +137,7 @@
 	The -p and -r flags works only with MODE2/2352 input (if input
 	is in PSX mode pass -p flag or if it is in raw format pass
 	-r flag).
-	
+
 	The -w flag makes binchunker write audio tracks in WAV format.
 	
 	The -s flag makes binchunker swap byte order in the samples of
--- bchunk-1.2.2+git20220715+ds.orig/bchunk.1
+++ bchunk-1.2.2+git20220715+ds/bchunk.1
@@ -1,10 +1,8 @@
-.TH BCHUNK 1 "v1.2.3 30 Jun 2022" "Heikki Hannikainen"
+.TH BCHUNK 1 "v1.2.2 14 Nov 2017" "Heikki Hannikainen"
 .SH NAME
 bchunk \- CD image format conversion from bin/cue to iso/cdr
-and WAV file splitter
 .SH SYNOPSIS
-.B bchunk [-t] [-v] [-p] [-r] [-w] [-s]
-<image.bin | image.wav | track # | '*'> <image.cue> [ <basename> ]
+.B bchunk [-v] [-p] [-r] [-w] [-s] <image.bin> <image.cue> <basename>
 .SH DESCRIPTION
 .LP
 .B bchunk 
@@ -15,19 +13,10 @@ The bin/cue format is used by some non-U
 software, but is not supported on most other cd-writing
 programs.
 .LP
-It also allows to split uncompressed PCM audio files in the
-WAV format into individual tracks.
-.LP
-\fIimage.bin\fP is a raw cd image file and \fIimage.wav\fP is an
-uncompressed  PCM audio file, either listed in the cue sheet file
-as a FILE. \fItrack #\fP is the track number listed in the cue sheet
-as a TRACK. \fItrack #\fP may omit the leading 0s. The wildcard
-'\fI*\fP' (single quoted to prevent shell expansion) selects all
-tracks from a cue sheet for conversion. \fIimage.cue\fP is the cue
-sheet file containing track types and offsets. \fIbasename\fP is
-optionally used for the leading part of output filenames.
-\fIbasename\fP may contain the track token '##' which will be
-replaced by the track number.
+image.bin is the raw cd image file. image.cue is the
+track index file containing track types and offsets.
+basename is used for the beginning part of the created
+track files.
 .LP
 The produced .iso track contains an ISO file system, which can be
 mounted through a loop device on Linux systems, or
@@ -49,12 +38,6 @@ The format itself does not contain this
 case it can only guess.
 .SH OPTIONS
 .TP 10
-.BI \-t
-Adds the track # in the output filename between the basename &
-the extension, as in
-.B bchunk
-releases prior to 1.2.3.
-.TP 10
 .BI \-v
 Makes binchunker print some more unnecessary messages, which should
 not be of interest for anyone.
@@ -78,14 +61,10 @@ raw format.
 .LP
 .TP 5
 .B image.bin
-Raw CD image file, listed in the cue sheet as a FILE.
-.TP 5
-.B image.wav
-WAV file with uncompressed PCM audio, listed in the cue sheet
-as a FILE.
+Raw CD image file
 .TP 5
 .B image.cue
-Cue sheet, TOC (Track index, Table Of Contents) file.
+TOC (Track index, Table Of Contents) file
 .TP 5
 .B *.iso
 Tracks in ISO9660 CD filesystem format. Can be either written on a
@@ -116,5 +95,3 @@ Godmar Back <gback@cs.utah.edu>
 .br
 Matthew Green <mrg@eterna.com.au>
 .br
-twojstaryzdomu <@github.com>
-.br
--- bchunk-1.2.2+git20220715+ds.orig/bchunk.c
+++ bchunk-1.2.2+git20220715+ds/bchunk.c
@@ -19,22 +19,17 @@
   */
 
 #define _GNU_SOURCE
-#include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
 #include <unistd.h>
 
-#define VERSION "1.2.3"
-#define USAGE "Usage: bchunk [-t] [-v] [-r] [-p (PSX)] [-w (wav)] [-s (swabaudio)]\n" \
-	"         <image.bin | image.wav | track # | '*'> <image.cue> [ <basename> ]\n" \
+#define VERSION "1.2.2"
+#define USAGE "Usage: bchunk [-v] [-r] [-p (PSX)] [-w (wav)] [-s (swabaudio)]\n" \
+        "         <image.bin> <image.cue> <basename>\n" \
 	"Example: bchunk foo.bin foo.cue foo\n" \
-	"         bchunk foo.bin foo.cue\n" \
-	"         bchunk 2 foo.cue foo\n" \
-	"  -t  Insert track # in between the basename and the format extension\n" \
 	"  -v  Verbose mode\n" \
-	"  -d  Debug mode\n" \
 	"  -r  Raw mode for MODE2/2352: write all 2352 bytes from offset 0 (VCD/MPEG)\n" \
 	"  -p  PSX mode for MODE2/2352: write 2336 bytes from offset 24\n" \
 	"      (default MODE2/2352 mode writes 2048 bytes from offset 24)\n"\
@@ -46,11 +41,8 @@
 		"\tpartly based on his Pascal (Delphi) implementation.\n" \
 		"\tSupport for MODE2/2352 ISO tracks thanks to input from\n" \
 		"\tGodmar Back <gback@cs.utah.edu>, Colas Nahaboo <Colas@Nahaboo.com>\n" \
-		"\tMatthew Green <mrg@eterna.com.au> & twojstaryzdomu <@github.com>.\n" \
+		"\tand Matthew Green <mrg@eterna.com.au>.\n" \
 		"\tReleased under the GNU GPL, version 2 or later (at your option).\n\n"
-	
-#define HINT	"\nUse '-t' to include track # in output filename. " \
-		"Remaining tracks were not processed\n"
 
 #define CUELLEN 1024
 #define SECTLEN 2352
@@ -58,12 +50,7 @@
 #define WAV_RIFF_HLEN 12
 #define WAV_FORMAT_HLEN 24
 #define WAV_DATA_HLEN 8
-#define WAV_DATA_FOURCC "data"
-#define WAV_DATA_FLEN sizeof(WAV_DATA_FOURCC) - 1
 #define WAV_HEADER_LEN WAV_RIFF_HLEN + WAV_FORMAT_HLEN + WAV_DATA_HLEN
-#define WAV_HEADER_MAX WAV_HEADER_LEN + 100
-
-#define TRACK_TOKEN "##"
 
 /*
  *	Ugly way to convert integers to little-endian format.
@@ -72,11 +59,7 @@
  */
 
 #include <inttypes.h>
-#ifdef _WIN32
-#include <winsock2.h>
-#else
 #include <netinet/in.h>
-#endif
 
 #define bswap_16(x) \
      ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8))
@@ -93,13 +76,10 @@ struct track_t {
 	int num;
 	int mode;
 	int audio;
-	char *file;
-	char *output;
 	char *modes;
 	char *extension;
 	int bstart;
 	int bsize;
-	long dataoffs;
 	long startsect;
 	long stopsect;
 	long start;
@@ -110,65 +90,11 @@ struct track_t {
 char *basefile = NULL;
 char *binfile = NULL;
 char *cuefile = NULL;
-char *bname = NULL;
-char *file = NULL;
 int verbose = 0;
-int debug = 0;
 int psxtruncate = 0;
 int raw = 0;
 int swabaudio = 0;
 int towav = 0;
-int trackadd = 0;
-FILE *binf, *cuef;
-struct track_t *tracks = NULL;
-struct track_t *track = NULL;
-
-void free_all(void)
-{
-	if (binf)
-		fclose(binf);
-	if (cuef)
-		fclose(cuef);
-	struct track_t *next;
-	for (track = tracks; (track); track = next) {
-		next = track->next;
-		free(track->file);
-		free(track->output);
-		free(track->modes);
-		free(track);
-	}
-	free(basefile);
-	free(binfile);
-	free(cuefile);
-	free(file);
-	free(bname);
-}
-
-void die_format(int status, char *format, ...)
-{
-	va_list args;
-	va_start(args, format);
-	vfprintf(stderr, format, args);
-	va_end(args);
-	free_all();
-	exit(status);
-}
-#define die(status, error) die_format(status, "%s", error)
-
-/*
- *	Copy a string until the final '.'
- */
-
-char* prune_ext(char *src)
-{
-	char *dst;
-	char *e = strrchr(src, '.');
-	int l = e ? e - src : strlen(src);
-	if (!(dst = malloc(l + 1)))
-		die(4, "prune_ext(): malloc() failed, out of memory\n");
-	dst[l] = '\0';
-	return strncpy(dst, src, l);
-}
 
 /*
  *	Parse arguments
@@ -178,7 +104,7 @@ void parse_args(int argc, char *argv[])
 {
 	int s;
 	
-	while ((s = getopt(argc, argv, "swvp?hrtd")) != -1) {
+	while ((s = getopt(argc, argv, "swvp?hr")) != -1) {
 		switch (s) {
 			case 'r':
 				raw = 1;
@@ -186,9 +112,6 @@ void parse_args(int argc, char *argv[])
 			case 'v':
 				verbose = 1;
 				break;
-			case 'd':
-				debug = 1;
-				break;
 			case 'w':
 				towav = 1;
 				break;
@@ -198,32 +121,34 @@ void parse_args(int argc, char *argv[])
 			case 's':
 				swabaudio = 1;
 				break;
-			case 't':
-				trackadd = 1;
-				break;
 			case '?':
 			case 'h':
-				die_format(0, "%s", USAGE);
+				fprintf(stderr, "%s", USAGE);
+				exit(0);
 		}
 	}
 
-	if (argc - optind < 2)
-		die_format(1, "%s", USAGE);
+	if (argc - optind != 3) {
+		fprintf(stderr, "%s", USAGE);
+		exit(1);
+	}
 	
-	for (int i = optind; i < argc; i++) {
-		switch (i - optind) {
-			case 0:
-				binfile = strdup(argv[i]);
-				break;
-			case 1:
-				cuefile = strdup(argv[i]);
+	while (optind < argc) {
+		switch (argc - optind) {
+			case 3:
+				binfile = strdup(argv[optind]);
 				break;
 			case 2:
-				basefile = strdup(argv[i]);
+				cuefile = strdup(argv[optind]);
+				break;
+			case 1:
+				basefile = strdup(argv[optind]);
 				break;
 			default:
-				die_format(1, "Gratuitous argument %s\n%s", argv[i], USAGE);
+				fprintf(stderr, "%s", USAGE);
+				exit(1);
 		}
+		optind++;
 	}
 }
 
@@ -254,44 +179,6 @@ long time2frames(char *s)
 }
 
 /*
- *	Check WAV file name extension
- */
-
-int is_wav_file(struct track_t *track) {
-	static char ext_wav[] = ".wav";
-	return !strcasecmp(track->file + strlen(track->file) - strlen(ext_wav), ext_wav);
-}
-
-/*
- *	Set WAV data header offset
- */
-
-int set_wav_data_offset(FILE *bf, struct track_t *track) {
-	char s[WAV_DATA_FLEN+1];
-	s[WAV_DATA_FLEN] = '\0';
-	for (int offset = WAV_HEADER_LEN; offset < WAV_HEADER_MAX; offset++) {
-		if (fseek(binf, offset, SEEK_SET) == -1)
-			die_format(4, " Could not fseek to offset %d: %s\n", offset, strerror(errno));
-		fread(s, WAV_DATA_FLEN, 1, binf);
-		if (strcmp(WAV_DATA_FOURCC, s) == 0) {
-			track->dataoffs = offset + WAV_DATA_HLEN;
-			if (debug) {
-				fseek(binf, offset + WAV_DATA_FLEN, SEEK_SET);
-				uint32_t w;
-				fread(&w, WAV_DATA_FLEN, 1, binf);
-				fprintf(stderr, " data header at %d\n"
-						" WAV data at %ld\n"
-						" WAV data bytes %u\n",
-						offset, track->dataoffs, w);
-			}
-			return 1;
-		}
-	}
-	printf("No WAV data header found in %s for track %d\n", track->file, track->num);
-	return 0;
-}
-
-/*
  *	Parse the mode string
  */
 
@@ -333,7 +220,7 @@ void gettrackmode(struct track_t *track,
 		track->bsize = 2336;
 		track->extension = ext_iso;
 		
-	} else if (!strcasecmp(modes, "AUDIO") || is_wav_file(track)) {
+	} else if (!strcasecmp(modes, "AUDIO")) {
 		track->bstart = 0;
 		track->bsize = 2352;
 		track->audio = 1;
@@ -374,8 +261,9 @@ char *progressbar(float f, int l)
  *	Write a track
  */
 
-int writetrack(FILE *bf, struct track_t *track)
+int writetrack(FILE *bf, struct track_t *track, char *bname)
 {
+	char *fname;
 	FILE *f;
 	char buf[SECTLEN+10];
 	long sz, sect, realsz, reallen;
@@ -384,29 +272,30 @@ int writetrack(FILE *bf, struct track_t
 	int16_t i;
 	float fl;
 	
-	if (!(f = fopen(track->output, "wbx"))) {
-		if (errno == EEXIST)
-			die_format(5,	"%2d: skipped: output file %s already exists, aborting\n%s",
-					track->num, track->output, HINT);
-		else
-			die_format(4, " Could not fopen track file: %s\n", strerror(errno));
+	if (asprintf(&fname, "%s%2.2d.%s", bname, track->num, track->extension) == -1) {
+		fprintf(stderr, "writetrack(): asprintf() failed, out of memory\n");
+		exit(4);
 	}
 	
-	printf("%2d: %s ", track->num, track->output);
+	printf("%2d: %s ", track->num, fname);
 	
-	if (fseek(bf, track->start + track->dataoffs, SEEK_SET))
-		die_format(4, " Could not fseek to track location: %s\n", strerror(errno));
+	if (!(f = fopen(fname, "w"))) {
+		fprintf(stderr, " Could not fopen track file: %s\n", strerror(errno));
+		exit(4);
+	}
+	
+	if (fseek(bf, track->start, SEEK_SET)) {
+		fprintf(stderr, " Could not fseek to track location: %s\n", strerror(errno));
+		exit(4);
+	}
 	
 	reallen = (track->stopsect - track->startsect + 1) * track->bsize;
 	if (verbose) {
-		printf(	"\n mmc sectors %ld->%ld (%ld)"
-			"\n mmc bytes %ld->%ld (%ld)"
-			"\n sector data at %d, %d bytes per sector"
-			"\n real data %ld bytes\n",
-			track->startsect, track->stopsect, track->stopsect - track->startsect + 1,
-			track->start, track->stop, track->stop - track->start + 1,
-			track->bstart, track->bsize,
-			reallen);
+		printf("\n mmc sectors %ld->%ld (%ld)", track->startsect, track->stopsect, track->stopsect - track->startsect + 1);
+		printf("\n mmc bytes %ld->%ld (%ld)", track->start, track->stop, track->stop - track->start + 1);
+		printf("\n sector data at %d, %d bytes per sector", track->bstart, track->bsize);
+		printf("\n real data %ld bytes", (track->stopsect - track->startsect + 1) * track->bsize);
+		printf("\n");
 	}
 
 	printf("                                          ");
@@ -434,7 +323,7 @@ int writetrack(FILE *bf, struct track_t
 		i = htoles(2*8);	// bits per channel
 		fwrite(&i, 2, 1, f);
 		// DATA header
-		fputs(WAV_DATA_FOURCC, f);
+		fputs("data", f);
 		l = htolel(reallen);
 		fwrite(&l, 4, 1, f);
 	}
@@ -443,7 +332,6 @@ int writetrack(FILE *bf, struct track_t
 	sz = track->start;
 	sect = track->startsect;
 	fl = 0;
-
 	while ((sect <= track->stopsect) && (fread(buf, SECTLEN, 1, bf) > 0)) {
 		if (track->audio) {
 			if (swabaudio) {
@@ -459,8 +347,10 @@ int writetrack(FILE *bf, struct track_t
 				}
 			}
 		}
-		if (fwrite(&buf[track->bstart], track->bsize, 1, f) < 1)
-			die_format(4, " Could not write to track: %s\n", strerror(errno));
+		if (fwrite(&buf[track->bstart], track->bsize, 1, f) < 1) {
+			fprintf(stderr, " Could not write to track: %s\n", strerror(errno));
+			exit(4);
+		}
 		sect++;
 		sz += SECTLEN;
 		realsz += track->bsize;
@@ -475,131 +365,79 @@ int writetrack(FILE *bf, struct track_t
 	printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b%4ld/%-4ld MB  [%s] %3.0f %%", realsz/1024/1024, reallen/1024/1024, progressbar(1, 20), fl * 100);
 	fflush(stdout);
 	
-	if (ferror(bf))
-		die_format(4, " Could not read from %s: %s\n", binfile, strerror(errno));
-	if (fclose(f))
-		die_format(4, " Could not fclose track file: %s\n", strerror(errno));
+	if (ferror(bf)) {
+		fprintf(stderr, " Could not read from %s: %s\n", binfile, strerror(errno));
+		exit(4);
+	}
+	
+	if (fclose(f)) {
+		fprintf(stderr, " Could not fclose track file: %s\n", strerror(errno));
+		exit(4);
+	}
 	
 	printf("\n");
 	return 0;
 }
 
 /*
- *     Sets output filename
- */
-
-int set_output(struct track_t *track, char *binfile, char *basefile, int trackadd) {
-	char *e, *s, *t;
-	if (strchr(binfile, '*')) {
-		if (!basefile)
-			bname = prune_ext(track->file);
-		else
-			if (asprintf(&bname, "%s", basefile) == -1)
-				die(4, "set_output(): asprintf() failed, out of memory\n");
-	} else if (strcmp(track->file, binfile) != 0) {
-		long num = strtol(binfile, &t, 10);
-		if (strlen(t) || num != track->num) {
-			printf("%2d: skipped: %s not matching FILE or TRACK from cuesheet\n", track->num, binfile);
-			return 0;
-		}
-	}
-	if (!bname) {
-		if (!basefile)
-			bname = prune_ext(binfile);
-		else
-			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 = calloc(l + 1, 1)))
-				die(4, "set_output(): calloc() failed, out of memory\n");
-			strncpy(s, basefile, l);
-			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;
-		if (asprintf(&bname, "%s%2.2d", bname ? bname : "", track->num) == -1)
-			die(4, "set_output(): asprintf() failed, out of memory\n");
-		free(t);
-	}
-	if (asprintf(&track->output, "%s.%s", bname, track->extension) == -1)
-		die(4, "set_output(): asprintf() failed, out of memory\n");
-	free(bname);
-	bname = NULL;
-	if (strcmp(track->output, track->file) == 0)
-		die_format(5,   "%2d: skipped: output file %s same as input file, aborting\n%s",
-				track->num, track->output, HINT);
-	return 1;
-}
-
-/*
  *	Main
  */
 
 int main(int argc, char **argv)
 {
 	char s[CUELLEN+1];
-	char *b, *e, *i, *p, *t, *u;
+	char *p, *t;
+	struct track_t *tracks = NULL;
+	struct track_t *track = NULL;
 	struct track_t *prevtrack = NULL;
 	struct track_t **prevp = &tracks;
 	
+	FILE *binf, *cuef;
+	
 	printf("%s", VERSTR);
 	
 	parse_args(argc, argv);
 	
-	if (!((cuef = fopen(cuefile, "r"))))
-		die_format(2, "Could not open CUE %s: %s\n", cuefile, strerror(errno));
+	if (!((binf = fopen(binfile, "r")))) {
+		fprintf(stderr, "Could not open BIN %s: %s\n", binfile, strerror(errno));
+		return 2;
+	}
 	
-	if (verbose)
-		printf("Include track # in output filename: %s\n\n", trackadd ? "yes" : "no");
+	if (!((cuef = fopen(cuefile, "r")))) {
+		fprintf(stderr, "Could not open CUE %s: %s\n", cuefile, strerror(errno));
+		return 2;
+	}
 	
 	printf("Reading the CUE file:\n");
 	
+	/* We don't really care about the first line. */
+	if (!fgets(s, CUELLEN, cuef)) {
+		fprintf(stderr, "Could not read first line from %s: %s\n", cuefile, strerror(errno));
+		return 3;
+	}
+	
 	while (fgets(s, CUELLEN, cuef)) {
 		while ((p = strchr(s, '\r')) || (p = strchr(s, '\n')))
 			*p = '\0';
 			
-		if ((p = strstr(s, "FILE"))) {
-			if (!(b = strchr(p, ' ')))
-				die(3, "... ouch, no space after FILE.\n");
-			if (!(e = strrchr(p, ' ')))
-				die(3, "... ouch, no space after filename.\n");
-			if (e == b)
-				die(3, "... ouch, no filename after FILE.\n");
-			++b;
-			if (b == strchr(b, '"'))
-				b++;
-			--e;
-			if (e == strrchr(e, '"'))
-				*e = '\0';
-			if (e == b)
-				die(3, "... ouch, empty filename entry.\n");
-			if (file)
-				free(file);
-			if (asprintf(&file, "%s", b) == -1)
-				die(4, "main(): asprintf() failed, out of memory\n");
-			printf("\nFile: %s", file);
-		}
 		if ((p = strstr(s, "TRACK"))) {
 			printf("\nTrack ");
-			if (!(p = strchr(p, ' ')))
-				die(3, "... ouch, no space after TRACK.\n");
+			if (!(p = strchr(p, ' '))) {
+				fprintf(stderr, "... ouch, no space after TRACK.\n");
+				exit(3);
+			}
 			p++;
-			if (!(t = strchr(p, ' ')))
-				die(3, "... ouch, no space after track number.\n");
+			if (!(t = strchr(p, ' '))) {
+				fprintf(stderr, "... ouch, no space after track number.\n");
+				exit(3);
+			}
 			*t = '\0';
 			
 			prevtrack = track;
-			if (!(track = malloc(sizeof(struct track_t))))
-				die(4, "main(): malloc() failed, out of memory\n");
+			if (!(track = malloc(sizeof(struct track_t)))) {
+				fprintf(stderr, "main(): malloc() failed, out of memory\n");
+				exit(4);
+			}
 			*prevp = track;
 			prevp = &track->next;
 			track->next = NULL;
@@ -607,14 +445,10 @@ int main(int argc, char **argv)
 			
 			p = t + 1;
 			printf("%2d: %-12.12s ", track->num, p);
-			if (asprintf(&track->file, "%s", file) == -1)
-				die(4, "main(): asprintf() failed, out of memory\n");
 			track->modes = strdup(p);
 			track->extension = NULL;
-			track->output = NULL;
 			track->mode = 0;
 			track->audio = 0;
-			track->dataoffs = 0;
 			track->bsize = track->bstart = -1;
 			track->bsize = -1;
 			track->startsect = track->stopsect = -1;
@@ -622,70 +456,45 @@ int main(int argc, char **argv)
 			gettrackmode(track, p);
 			
 		} else if ((p = strstr(s, "INDEX"))) {
-			if (!(p = strchr(p, ' ')))
-				die(3, "... ouch, no space after INDEX.\n");
+			if (!(p = strchr(p, ' '))) {
+				printf("... ouch, no space after INDEX.\n");
+				exit(3);
+			}
 			p++;
-			if (!(t = strchr(p, ' ')))
-				die(3, "... ouch, no space after index number.\n");
+			if (!(t = strchr(p, ' '))) {
+				printf("... ouch, no space after index number.\n");
+				exit(3);
+			}
 			*t = '\0';
 			t++;
 			printf(" %s %s", p, t);
-			long index = strtol(p, &i, 10);
-			if (strlen(i))
-				die_format(3, "... ouch, non-digit found in INDEX %s: %s\n", p, i);
-			u = strdupa(t);
-			int ss;
-			// handle unordered pregap, ignore subtracks
-			for (ss = time2frames(t); ss > track->startsect && index < 2;) {
-				track->startsect = ss;
-				track->start = track->startsect * SECTLEN;
-			}
-			if (debug)
-				fprintf(stderr, "INDEX %s%s: %s startsect %d\n",
-						p, track->startsect + 1 ? "" : " updating",
-						u, ss);
+			track->startsect = time2frames(t);
+			track->start = track->startsect * SECTLEN;
 			if (verbose)
-				printf(" (%sstartsect %ld ofs %ld)",
-					index == 0 ? "" :
-					index == 1 ? "pregap " : "subtrack ",
-					track->startsect, track->start);
-			if (prevtrack) {
-				// only when files match, ignore subtracks
-				if (!(strcmp(prevtrack->file,track->file)) && index < 2) {
-					prevtrack->stopsect = track->startsect - 1;
-					prevtrack->stop = track->start - 1;
-				}
-				if (debug)
-					fprintf(stderr, "TRACK %.2d: stopsect %ld\n",
-							prevtrack->num, prevtrack->stopsect);
+				printf(" (startsect %ld ofs %ld)", track->startsect, track->start);
+			if ((prevtrack) && (prevtrack->stopsect < 0)) {
+				prevtrack->stopsect = track->startsect - 1;
+				prevtrack->stop = track->start - 1;
 			}
 		}
 	}
 	
-	printf("\n\nWriting tracks:\n\n");
-	
-	for (track = tracks; (track); track = track->next) {
-		if (!set_output(track, binfile, basefile, trackadd))
-			continue;
-		if (!(binf = fopen(track->file, "rb"))) {
-			fprintf(stderr, "Could not open BIN %s: %s\n", track->file, strerror(errno));
-			continue;
-		}
-		if (is_wav_file(track))
-			if (!set_wav_data_offset(binf, track))
-				continue;
-		if (track->stopsect < 0) { // if not set yet
-			if (fseek(binf, 0, SEEK_END) == -1)
-				die_format(4, "main(): fseek failure in %s\n", track->file);
-			track->stop = ftell(binf) - track->dataoffs - 1;
-			track->stopsect = track->stop / SECTLEN;
-		}
-		writetrack(binf, track);
-		fclose(binf);
-		binf = NULL;
+	if (track) {
+		fseek(binf, 0, SEEK_END);
+		track->stop = ftell(binf) - 1;
+		track->stopsect = track->stop / SECTLEN;
 	}
 	
-	free_all();
+	printf("\n\n");
+	
+	
+	printf("Writing tracks:\n\n");
+	for (track = tracks; (track); track = track->next)
+		writetrack(binf, track, basefile);
+		
+	fclose(binf);
+	fclose(cuef);
+	
 	return 0;
 }
 
--- bchunk-1.2.2+git20220715+ds.orig/bchunk.spec
+++ bchunk-1.2.2+git20220715+ds/bchunk.spec
@@ -1,5 +1,5 @@
 %define name bchunk
-%define version 1.2.3
+%define version 1.2.2
 %define release 0
 
 Summary: A CD image format converter from .bin/.cue to .iso/.cdr/.wav.
@@ -43,9 +43,6 @@ rm -r $RPM_BUILD_ROOT
 %{_mandir}/man1/bchunk.1.gz
 
 %changelog
-* Tue Jun 30 2022 twojstaryzdomu
-- updated to 1.2.3
-
 * Tue Nov 14 2017 Hessu <hessu@hes.iki.fi>
 - updated to 1.2.2
 
