The track number and track index from the CUEX chunk are BCD-encoded
(Binary-Coded Decimal). Reading them as binary led to wrong track
numbers starting with track 10.
There is doubt whereas the index number is BCD or not, but two-digit
indices are seldom seen.
std::process::exit() was used mainly to be able to return an error code,
but it's pretty brutal (no destructors calls). This commit works around
the lack of return value for main() and calls exit() only at the very
end.
The audio data is now read up to the last track's end, rather than to
the NRG footer ("first chunk offset"), unless there are no DAOX tracks.
This should be strictly equivalent in normal cases.
The audio data was initially read and written by chunks of 2352 bytes,
which is the usual sector size for audio CDs. However, this didn't work
on images with a 2448-byte sector size (2352 bytes data + 96 bytes
sub-channel data): we would end up reading data from the NRG footer.
The data is now read/written by 4 MiB (which is faster anyway), and we
make sure to read the remaining bytes if the audio data size is not a
multiple of 4 MiB.
* Use PathBuf operations to generate output file names.
* Output files are now written to the working directory.
* The cue sheet contains only the image's base name, not the full path.
If an index #0 is present for a track but not for the next track, it
could be written for the following track (i.e. two tracks from where it
appeared), which would lead to an incoherent cue sheet.
In theory, this was a non-issue because in NRG, a track always has an
index #0, but you never know.