#!/usr/bin/perl -w # rundos.pl # # This program modifies the dosbox configuration file so that when you type 'dosbox' in the # terminal, it automatically launches a program. Usage: perl rundos.pl # The workdir must be a full path using backslash as the separator and must be enclosed with # double quotes. The dos program must include the full location of the program and the # program name the same way.. Make sure that the path includes only 8+3 filenames and the # program itself also has a name that is 8+3 length. (Here "8+3" means the file name is # max 8 letters long, and the extension is 3 max letters long.) # # It does not matter whether the first and second arguments are in uppercase or lowercase, # because these will be used inside dosbox. In a dos environment, the directory and program # names can be in upper or lower case, and it's all the same. But it is important to always # enclose the first and second arguments with double quotes. # # When you run this program without any arguments, "perl rundos.pl" it will remove the program # launcher from the dosbox config file, so when you type "dosbox" in the terminal, # it will let you decide what you want to do... # # When you run this program with just one argument, "perl rundos.pl \home\owner\dos" it # will launch dosbox in that directory. # # Example for running with two arguments: # perl rundos.pl "\home\owner\dos" "\home\owner\dos\qbasic.exe" use strict; use warnings; -e '/usr/bin/dosbox' or die "\nError: /usr/bin/dosbox is not found. Please install it.\n"; my $WORKDIR = (@ARGV > 0) ? $ARGV[0] : ''; my $DOSPROG = (@ARGV > 1) ? $ARGV[1] : ''; my $HOMEDIR = $ENV{HOME}; # Read this file: my $F = $HOMEDIR . '/.dosbox/dosbox-0.74-3.conf'; -f $F or die "\nError: Dosbox configuration file not found - $F !!!\n\n"; # Read the config file's contents: @ARGV = ($F); my @LINES = <>; # Find the line that begins with [autoexec] my $FOUND = 0; for (my $i = 0; $i < @LINES; $i++) { $LINES[$i] =~ tr|\r\n||d; if ($FOUND) { $LINES[$i] = ''; } if (index($LINES[$i], '[autoexec]') >= 0) { $FOUND = $i; } } if ($FOUND) { splice(@LINES, $FOUND); } # Delete it and everything that follows... else { die "\nError: Dosbox config file doesn't contain [autoexec] section.\n"; } if (length($WORKDIR) && length($DOSPROG)) { push(@LINES, '[autoexec]'); push(@LINES, 'mount c /'); push(@LINES, 'c:'); push(@LINES, "cd $WORKDIR"); push(@LINES, 'cls'); push(@LINES, $DOSPROG); push(@LINES, 'exit'); } elsif (length($WORKDIR)) { push(@LINES, '[autoexec]'); push(@LINES, 'mount c /'); push(@LINES, 'c:'); push(@LINES, 'cd ' . $WORKDIR); push(@LINES, 'dir /w'); } else { push(@LINES, '[autoexec]'); push(@LINES, 'ver'); } # Save modified config file. open my $fh, '>', $F or die "\nError: Cannot update to $F !!!\n\n"; print $fh join("\n", @LINES), "\n"; close $fh; # Launch dosbox. exec('dosbox');