updated git and svn scripts
[xrzperl.git] / getopts
blob5f7d40110081db9e4ffa63f59c7f14e4d6b7db64
1 #!/usr/bin/perl -w
2 ###APPNAME: getopts
3 ###APPAUTHOR: xiaoranzzz
4 ###APPDATE: Sat Oct 20 07:53:54 2007
5 ###APPVER: 0.1
6 ###APPDESC: bochs configure
7 ###APPUSAGE: [-hd{a,b,c,d} hdimage] [-cd{a,b} cdiso] [-fd{a,b} fdimage] [-boot {a,c,d}]
8 ###APPOPTION: -rom filename:Specify bios rom image|-vgabios:Specify vga bios rom image|-mem number:Memory|-display {x,sdl,wx}:Display mode|-interface {textconfig,wx}:Config Interface|-edit:Edit template
9 use strict;
10 $ARGV[0]="-h" unless(@ARGV);
11 foreach(@ARGV){
12 exit(system("plhelp",$0,@ARGV)) if($_ eq "-h" || $_ eq "--help");
15 #Parse options
16 sub getOpt(@) {
17 my $flag=0;
18 my $last="";
19 my %result;
20 foreach(@_) {
21 if(m/^-/) {
22 if($flag) {
23 $result{$last}=1;
25 else {
26 $result{noname}=$last if($last);
28 $flag=1;
29 $last=$_;
31 else {
32 if($flag) {
33 $result{$last}=$_;
35 else {
36 $result{noname}=$_;
38 $flag=0;
39 $last="";
42 if($flag) {
43 $result{$last}=1;
45 return %result;
48 my %OPTS=getOpt(@ARGV);
51 $OPTS{-hda}=$OPTS{noname} if($OPTS{noname} && !$OPTS{-hda});
52 foreach(keys(%OPTS)) {
53 print STDERR ("$_\t:\t$OPTS{$_}\n");
56 my $dir_bochs="/usr/share/bochs";
57 my $dir_vgabios="/usr/share/vgabios/";
59 sub pickBest(@) {
60 foreach(@_) {
61 return $_ if(-f $_);
65 my @prop_template=(
66 "/share/appdata/bochs/config-template",
67 "~/.getopts/config-template",
68 "config-template",
71 my @prop_rom=(
72 "$dir_bochs/BIOS-bochs-latest",
73 "/share/appdata/bochs/bios.rom",
74 $OPTS{-rom},
77 my @prop_vgarom=(
78 "$dir_bochs/VGABIOS-lgpl-latest",
79 "$dir_vgabios/vgabios.bin",
80 "$dir_vgabios/vgabios.cirrus.bin",
81 $OPTS{-vgabios},
84 my $template=pickBest(@prop_template);
85 die("Template not found in :\n" . join("\n",@prop_template)) unless(-f $template);
87 if ($OPTS{-edit}) {
88 system("vim",$template);
91 my $rom=pickBest(@prop_rom);
92 die("Bios rom not found in :\n" . join("\n",@prop_rom)) unless(-f $rom);
94 my $vgarom=pickBest(@prop_vgarom);
95 die("VGA Bios rom not found in :\n" . join("\n",@prop_vgarom)) unless(-f $vgarom);
98 my $interface = "textconfig";
99 $interface=$OPTS{-interface} if($OPTS{-interface});
101 my $display = "x";
102 $display=$OPTS{-display} if($OPTS{-display});
104 my $mem=128;
105 $mem=$OPTS{-mem} if($OPTS{-mem});
107 my $boot="floppy, cdrom , disk";
108 if($OPTS{-boot}) {
109 my $c=$OPTS{-boot};
110 $boot="floppy, cdrom, disk" if($c eq "a");
111 $boot="disk, floppy, cdrom" if($c eq "c");
112 $boot="cdrom, floppy, disk" if($c eq "d");
115 my $cdroma="/dev/cdrom";
116 $cdroma=$OPTS{-cda} if($OPTS{-cda});
119 open(TEMPLATE,"<",$template) or die("$!\n");
120 print <TEMPLATE>;
121 close TEMPLATE;
124 print "config_interface: $interface\n" if($interface);
125 print "display_library: $display\n" if($display);
126 print "megs: $mem\n" if($mem);
127 print "romimage: file=\"$rom\"\n" if($rom);
128 print "vgaromimage: file=\"$vgarom\"\n" if($vgarom);
130 #Boot
131 print "boot: $boot\n" if($boot);
133 #Floppy
134 print "floppya: 1_44=\"$OPTS{-fda}\", status=inserted\n" if($OPTS{-fda});
135 print "floppya: 1_44=\"$OPTS{-fdb}\", status=inserted\n" if($OPTS{-fdb});
137 #Hard Disk
138 print "ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14\n" if($OPTS{-hda} or $OPTS{-hdb});
139 print "ata1: enabled=1, ioaddr1=0x170, ioaddr2=0x370, irq=15\n" if($OPTS{-cda} or $OPTS{-cdb});
140 print "ata2: enabled=1, ioaddr1=0x1e8, ioaddr2=0x3e0, irq=2\n" if($OPTS{-hdc} or $OPTS{-hdd});
141 print "ata3: enabled=1, ioaddr1=0x168, ioaddr2=0x360, irq=3\n" if($OPTS{-hde} or $OPTS{-hdf});
144 #Channel 0
145 print ("ata0-master: type=disk, mode=flat, translation=auto, path=\"" . $OPTS{-hda} . "\", cylinders=0, heads=16, spt=63, biosdetect=auto, model=\"Generic 1234\"\n") if($OPTS{-hda});
146 print "ata0-slave: type=disk, mode=flat, translation=auto, path=\"$OPTS{-hdb}\", cylinders=0, heads=16, spt=63, biosdetect=auto, model=\"Generic 1234\"\n" if($OPTS{-hdb});
148 #Channel 2
149 print "ata2-master: type=disk, mode=flat, translation=auto, path=\"$OPTS{-hdc}\", cylinders=0, heads=16, spt=63, biosdetect=auto, model=\"Generic 1234\"\n" if($OPTS{-hdc});
150 print "ata2-slave: type=disk, mode=flat, translation=auto, path=\"$OPTS{-hdd}\", cylinders=0, heads=16, spt=63, biosdetect=auto, model=\"Generic 1234\"\n" if($OPTS{-hdd});
152 #CD-ROM
153 #print "ata1: enabled=1, ioaddr1=0x170, ioaddr2=0x370, irq=3\n";
154 print "ata1-master: type=cdrom, path=\"$cdroma\", status=inserted, biosdetect=auto, model=\"Generic 1234\"\n";
155 print "ata1-slave: type=cdrom, path=\"$OPTS{-cdb}\", status=inserted, biosdetect=auto, model=\"Generic 1234\"\n" if($OPTS{-cdb});