Skip to content

Commit e7be137

Browse files
committed
Check arguments.
1 parent 80b5cf6 commit e7be137

1 file changed

Lines changed: 19 additions & 10 deletions

File tree

src/main/java/xyz/meunier/wav2pzx/WAV2PZX.java

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,38 +45,43 @@
4545
* efficient format that can also represent some of the higher-level features
4646
* typically used in tape loading schemes from that time.
4747
* <p>
48-
* The home page is at {@link http://zxds.raxoft.cz/pzx.html}
48+
* The specification is at the <a href="http://zxds.raxoft.cz/pzx.html">PZX home page</a>
4949
* <p>
5050
* This program reads a WAV format audio sample of a tape recording for these
5151
* machines and converts it to the efficient PZX format.
5252
* @author Fredrick Meunier
5353
*/
5454
public class WAV2PZX {
55-
55+
5656
/*
5757
* Any durations are expressed in T cycles of standard 48k Spectrum CPU.
5858
* This means one cycle equals 1/3500000 second.
5959
*/
6060
private static final float TARGET_HZ = (float) 3500000.0;
61-
61+
6262
/**
63-
* Main entry point for WAV2PZX. Two arguments are expected, first the
63+
* Main entry point for WAV2PZX. Two arguments are expected, first the
6464
* source WAV filename and second the destination PZX file name.
6565
* @param args program arguments, two are expected - the source WAV and the destination PZX file names
6666
*/
6767
public static void main(String[] args) {
68+
if(args.length < 2) {
69+
usage();
70+
return;
71+
}
72+
6873
final String wavFileIn = args[0];
6974
final String pzxFileOut = args[1];
70-
71-
if(wavFileIn == null || pzxFileOut == null) {
72-
System.err.println("wav2pzx: usage: wav2pzx <infile> <outfile>");
75+
76+
if(wavFileIn.isEmpty() || pzxFileOut.isEmpty()) {
77+
usage();
7378
return;
7479
}
75-
80+
7681
try {
7782
// Read and convert the source WAV file from samples to a list of 0/1 pulses in units of TARGET_HZ
7883
PulseList pulseList = AudioFileTape.buildPulseList(wavFileIn, TARGET_HZ);
79-
84+
8085
// Analyse the source data and translate into an equivalent list of PZX tape blocks
8186
List<PZXBlock> pzxTape = LoaderContextImpl.buildPZXTapeList(pulseList);
8287

@@ -89,12 +94,16 @@ public static void main(String[] args) {
8994
out.write(data, 0, data.length);
9095
}
9196
} catch (IOException ex) {
92-
System.err.println(ex);
97+
System.err.println(ex.toString());
9398
Logger.getLogger(WAV2PZX.class.getName()).log(Level.SEVERE, ex.toString(), ex);
9499
}
95100
} catch (IOException | UnsupportedAudioFileException e) {
96101
System.err.println(e);
97102
Logger.getLogger(WAV2PZX.class.getName()).log(Level.SEVERE, e.toString(), e);
98103
}
99104
}
105+
106+
private static void usage() {
107+
System.err.println("wav2pzx: usage: wav2pzx <infile> <outfile>");
108+
}
100109
}

0 commit comments

Comments
 (0)