-#! /usr/bin/perl
-
-$sim = "bochs";
-$debug = "";
-$mem = 4;
-$headless = 0;
-while (@ARGV) {
- my ($arg) = shift (@ARGV);
- if ($arg =~ /--(bochs|qemu|gsx)$/) {
- $sim = $1;
- } elsif ($arg =~ /--(monitor|gdb)$/) {
- $debug = $1;
- } elsif ($arg eq 'run') {
- run_vm (@ARGV);
- exit 0;
- } elsif ($arg =~ /^mem(?:ory)?=(\d+)/) {
- $mem = $1;
- } elsif ($arg eq '--headless') {
- $headless = 1;
- } elsif ($arg eq 'make-disk') {
- my ($force) = @ARGV > 0 && $ARGV[0] eq '--force';
- shift @ARGV if $force;
- usage () if @ARGV != 2;
- my ($file, $mb) = @ARGV;
- usage () if $mb !~ /^\d+$/;
- die "$file: already exists\n" if -e $file;
-
- if ($mb != .5 && $mb != 1 && $mb != 1.5 && $mb != 2) {
- print "$file: recommended sizes are .5, 1, 1.5, or 2 MB\n";
- die "use --force to override\n" if !$force;
- }
+#! /usr/bin/perl -w
+
+use strict;
+
+our ($mem) = 4;
+our ($serial_out) = 1;
+our (@disks) = ("os.dsk", "fs.dsk", "scratch.dsk", "swap.dsk");
+our ($sim);
+our ($debug);
+our ($vga);
+our ($jitter, $realtime);
+
+use Getopt::Long qw(:config require_order bundling);
+GetOptions ("sim=s" => sub { set_sim (@_) },
+ "bochs" => sub { set_sim ("bochs") },
+ "qemu" => sub { set_sim ("qemu") },
+ "gsx" => sub { set_sim ("gsx") },
+
+ "debug=s" => sub { set_debug (@_) },
+ "no-debug" => sub { set_debug ("no-debug") },
+ "monitor" => sub { set_debug ("monitor") },
+ "gdb" => sub { set_debug ("gdb") },
+
+ "run|get|put|make-disk" => \&cmd_option,
+
+ "m|memory=i" => \$mem,
+ "j|jitter=i" => sub { set_jitter (@_) },
+ "r|realtime" => sub { set_realtime () },
+
+ "v|no-vga" => sub { set_vga ('none'); },
+ "s|no-serial" => sub { $serial_out = 0; },
+ "t|terminal" => sub { set_vga ('terminal'); },
+
+ "h|help" => sub { usage (0); },
+
+ "0|os-disk|disk-0|hda=s" => \$disks[0],
+ "1|fs-disk|disk-1|hdb=s" => \$disks[1],
+ "2|scratch-disk|disk-2|hdc=s" => \$disks[2],
+ "3|swap-disk|disk-3|hdd=s" => \$disks[3])
+ or exit 1;
+
+$sim = "bochs" if !defined $sim;
+$debug = "no-debug" if !defined $debug;
+$vga = "window" if !defined $vga;
+
+sub set_sim {
+ my ($new_sim) = @_;
+ die "--$new_sim conflicts with --$sim\n"
+ if defined ($sim) && $sim ne $new_sim;
+ $sim = $new_sim;
+}