Allow to automatically copy part of wine.ini into generated file.

Small perl enhancement (work in strict mode).
Small updates in heuristics.
This commit is contained in:
Eric Pouech 1999-04-25 12:18:36 +00:00 committed by Alexandre Julliard
parent ef80cb1cc7
commit 455414cfb2
1 changed files with 100 additions and 83 deletions

View File

@ -44,6 +44,7 @@ $RCS_ID = '$Id$ ';
use Getopt::Long; use Getopt::Long;
use File::Basename; use File::Basename;
use strict;
use Carp; use Carp;
GetOptions('windir=s', 'sysdir=s', 'thorough', 'debug:s') || &Usage; GetOptions('windir=s', 'sysdir=s', 'thorough', 'debug:s') || &Usage;
@ -68,33 +69,34 @@ sub Usage {
} }
sub ReadFSTAB { sub ReadFSTAB {
$opt_f = $opt_f ? $opt_f : '/etc/fstab'; $::opt_f = $::opt_f ? $::opt_f : '/etc/fstab';
open(FSTAB, $opt_f) || die "Cannot read $opt_f\n"; open(FSTAB, $::opt_f) || die "Cannot read $::opt_f\n";
while(<FSTAB>) { while(<FSTAB>) {
next if /^\s*\#/; next if /^\s*\#/;
next if /^\s*$/; next if /^\s*$/;
($device, $mntpoint, $type, @rest) = split(' ', $_);
my ($device, $mntpoint, $type, @rest) = split(' ', $_);
if ($device !~ m"^/dev/fd") { if ($device !~ m"^/dev/fd") {
if ($type eq "msdos" || $type eq "vfat") { if ($type eq "msdos" || $type eq "vfat") {
push(@FatDrives, [$device, $mntpoint]); push(@::FatDrives, [$device, $mntpoint]);
} }
elsif ($type eq "iso9660") { elsif ($type eq "iso9660" || ($device eq '/dev/cdrom' && $type eq 'auto') ) {
push(@CdromDrives, [$device, $mntpoint]); push(@::CdromDrives, [$device, $mntpoint]);
} }
} }
} }
if (!@FatDrives) { if (!@::FatDrives) {
warn "ERROR ($0): Cannot find any MSDOS drives.\n"; warn "ERROR ($0): Cannot find any MSDOS drives.\n";
warn "This does not mean you cannot run Wine, but $0\n"; warn "This does not mean you cannot run Wine, but $0\n";
warn "cannot help you (yet)\n"; warn "cannot help you (yet)\n";
exit(1); exit(1);
} }
$MagicDrive = 'C'; my $MagicDrive = 'C';
@FatDrives = sort byDriveOrder @FatDrives; @::FatDrives = sort byDriveOrder @::FatDrives;
@CdromDrives = sort byCdOrder @CdromDrives; @::CdromDrives = sort byCdOrder @::CdromDrives;
foreach $FatDrive (@FatDrives) { foreach my $FatDrive (@::FatDrives) {
print "[Drive $MagicDrive]\n"; print "[Drive $MagicDrive]\n";
$MntPoint = $FatDrive->[1]; my $MntPoint = $FatDrive->[1];
print "Path=$MntPoint\n"; print "Path=$MntPoint\n";
print "Type=hd\n"; print "Type=hd\n";
print "\n"; print "\n";
@ -105,9 +107,9 @@ sub ReadFSTAB {
} }
$MagicDrive++; $MagicDrive++;
} }
foreach $CdromDrive (@CdromDrives) { foreach my $CdromDrive (@::CdromDrives) {
print "[Drive $MagicDrive]\n"; print "[Drive $MagicDrive]\n";
$MntPoint = $CdromDrive->[1]; my $MntPoint = $CdromDrive->[1];
print "Path=$MntPoint\n"; print "Path=$MntPoint\n";
print "Type=cdrom\n"; print "Type=cdrom\n";
print "\n"; print "\n";
@ -118,32 +120,34 @@ sub ReadFSTAB {
sub FindWindowsDir { sub FindWindowsDir {
my($MagicDrive) = 'C'; my($MagicDrive) = 'C';
my(@FATD)=@FatDrives; my(@FATD)=@::FatDrives;
my(@wininis) = (); my(@wininis) = ();
if (!$opt_windir && !$opt_fast && !$opt_thorough) { my ($winini);
$opt_thorough++;
if (!$::opt_windir && !$::opt_fast && !$::opt_thorough) {
$::opt_thorough++;
} }
if ($opt_windir) { if ($::opt_windir) {
$winini = &ToUnix($opt_windir); $winini = &ToUnix($::opt_windir);
if (!-e $winini) { if (!-e $winini) {
die "ERROR: Specified winini file does not exist\n"; die "ERROR: Specified winini file does not exist\n";
} }
} }
elsif ($opt_fast) { elsif ($::opt_fast) {
die "-fast code can be implemented\n"; die "-fast code can be implemented\n";
} }
elsif ($opt_thorough) { elsif ($::opt_thorough) {
if ($opt_debug) { print STDERR "DEBUG: Num FATD = ", $#FATD+1, "\n"; } if ($::opt_debug) { print STDERR "DEBUG: Num FATD = ", $#FATD+1, "\n"; }
foreach(@FATD) { foreach(@FATD) {
$ThisDrive = shift(@FATD); my $ThisDrive = shift(@FATD);
$MntPoint = $ThisDrive->[1]; my $MntPoint = $ThisDrive->[1];
push(@wininis, `find $MntPoint -name win.ini -print`); push(@wininis, `find $MntPoint -name win.ini -print`);
} }
foreach $winini (@wininis) { foreach $winini (@wininis) {
chomp $winini; chomp $winini;
} }
my($winini_cnt) = $#wininis+1; my ($winini_cnt) = $#wininis+1;
if ($opt_debug) { if ($::opt_debug) {
print STDERR "DEBUG: Num wininis found: $winini_cnt\n";} print STDERR "DEBUG: Num wininis found: $winini_cnt\n";}
if ($winini_cnt > 1) { if ($winini_cnt > 1) {
warn "$winini_cnt win.ini files found:\n"; warn "$winini_cnt win.ini files found:\n";
@ -162,14 +166,14 @@ sub FindWindowsDir {
else { else {
die "ERROR: None of -windir, -fast, or -thorough set\n"; die "ERROR: None of -windir, -fast, or -thorough set\n";
} }
$windir = &ToDos(dirname($winini)); $::windir = &ToDos(dirname($winini));
print "[wine]\n"; print "[wine]\n";
print "windows=$windir\n"; print "windows=$::windir\n";
if ($opt_sysdir) { if ($::opt_sysdir) {
print "system=$opt_sysdir\n"; print "system=$::opt_sysdir\n";
} }
else { else {
print "system=$windir\\SYSTEM\n"; print "system=$::windir\\SYSTEM\n";
} }
} }
@ -196,19 +200,19 @@ sub IsMounted {
sub RegisterDrive { sub RegisterDrive {
my($DOSdrive, $Drive) = @_; my($DOSdrive, $Drive) = @_;
$DOS2Unix{$DOSdrive} = $Drive; $::DOS2Unix{$DOSdrive} = $Drive;
$Device2DOS{$Drive->[0]} = $DOSdrive; $::Device2DOS{$Drive->[0]} = $DOSdrive;
$MntPoint2DOS{$Drive->[1]} = $DOSdrive; $::MntPoint2DOS{$Drive->[1]} = $DOSdrive;
$DOS2MntPoint{$DOSdrive} = $Drive->[1]; $::DOS2MntPoint{$DOSdrive} = $Drive->[1];
$DOS2Device{$DOSdrive} = $Drive->[0]; $::DOS2Device{$DOSdrive} = $Drive->[0];
} }
sub ReadAutoexecBat { sub ReadAutoexecBat {
if (!%DOS2Unix) { &ReadFSTAB; } if (!%::DOS2Unix) { &ReadFSTAB; }
my($DriveC) = $DOS2MntPoint{"C"}; my($DriveC) = $::DOS2MntPoint{"C"};
$DriveC =~ s%/$%%; $DriveC =~ s%/$%%;
my($path); my($path);
if ($opt_debug) { if ($::opt_debug) {
print STDERR "DEBUG: Looking for $DriveC/autoexec.bat\n"; } print STDERR "DEBUG: Looking for $DriveC/autoexec.bat\n"; }
if (-e "$DriveC/autoexec.bat") { if (-e "$DriveC/autoexec.bat") {
# Tested 1.4 # Tested 1.4
@ -222,16 +226,17 @@ sub ReadAutoexecBat {
chomp($varvalue); chomp($varvalue);
$varname =~ tr/A-Z/a-z/; $varname =~ tr/A-Z/a-z/;
while ($varvalue =~ /%(\w+)%/) { while ($varvalue =~ /%(\w+)%/) {
$matchname = $subname = $1; my $matchname = $1;
my $subname = $1;
$subname =~ tr/A-Z/a-z/; $subname =~ tr/A-Z/a-z/;
if ($opt_debug =~ /path/i) { if ($::opt_debug =~ /path/i) {
print STDERR "DEBUG: Found $matchname as $subname\n"; print STDERR "DEBUG: Found $matchname as $subname\n";
print STDERR "DEBUG: Old varvalue:\n$varvalue\n"; print STDERR "DEBUG: Old varvalue:\n$varvalue\n";
print STDERR "DEBUG: Old subname value:\n" . print STDERR "DEBUG: Old subname value:\n" .
$DOSenv{$subname} . "\n"; $::DOSenv{$subname} . "\n";
} }
if ($DOSenv{$subname}) { if ($::DOSenv{$subname}) {
$varvalue =~ s/\%$matchname\%/$DOSenv{$subname}/; $varvalue =~ s/\%$matchname\%/$::DOSenv{$subname}/;
} }
else { else {
warn "DOS environment variable $subname not\n"; warn "DOS environment variable $subname not\n";
@ -239,14 +244,14 @@ sub ReadAutoexecBat {
warn "is not implemented.) Using null value\n"; warn "is not implemented.) Using null value\n";
$varvalue =~ s/%$matchname%//; $varvalue =~ s/%$matchname%//;
} }
if ($opt_debug =~ /path/i) { if ($::opt_debug =~ /path/i) {
print STDERR "DEBUG: New varvalue:\n$varvalue\n"; print STDERR "DEBUG: New varvalue:\n$varvalue\n";
} }
} }
if ($opt_debug) { if ($::opt_debug) {
print STDERR "DEBUG: $varname = $varvalue\n"; print STDERR "DEBUG: $varname = $varvalue\n";
} }
$DOSenv{$varname} = $varvalue; $::DOSenv{$varname} = $varvalue;
} }
} }
close(AUTOEXEC); close(AUTOEXEC);
@ -256,21 +261,21 @@ sub ReadAutoexecBat {
warn "WARNING: C:\\AUTOEXEC.BAT was not found.\n"; warn "WARNING: C:\\AUTOEXEC.BAT was not found.\n";
} }
if ($DOSenv{"path"}) { if ($::DOSenv{"path"}) {
@pathdirs = split(/\s*;\s*/, $DOSenv{"path"}); my @pathdirs = split(/\s*;\s*/, $::DOSenv{"path"});
if ($opt_debug =~ /path/i) { if ($::opt_debug =~ /path/i) {
print STDERR "DEBUG (path): @pathdirs\n"; print STDERR "DEBUG (path): @pathdirs\n";
} }
foreach $pathdir (@pathdirs) { foreach my $pathdir (@pathdirs) {
if (-d &ToUnix($pathdir)) { if (-d &ToUnix($pathdir)) {
if ($DOSpathdir{$pathdir}++) { if ($::DOSpathdir{$pathdir}++) {
warn "Ignoring duplicate DOS path entry $pathdir\n"; warn "Ignoring duplicate DOS path entry $pathdir\n";
} }
else { else {
if ($opt_debug =~ /path/i) { if ($::opt_debug =~ /path/i) {
print STDERR "DEBUG (path): Found $pathdir\n"; print STDERR "DEBUG (path): Found $pathdir\n";
} }
push(@DOSpathlist, $pathdir); push(@::DOSpathlist, $pathdir);
} }
} }
else { else {
@ -278,46 +283,49 @@ sub ReadAutoexecBat {
warn "exist\n"; warn "exist\n";
} }
} }
print "path=" . join(";", @DOSpathlist) . "\n"; print "path=" . join(";", @::DOSpathlist) . "\n";
} }
else { else {
# Code status: tested 1.4 # Code status: tested 1.4
warn "WARNING: Making assumptions for PATH\n"; warn "WARNING: Making assumptions for PATH\n";
warn "Will scan windows directory for executables and generate\n"; warn "Will scan windows directory for executables and generate\n";
warn "path from that\n"; warn "path from that\n";
$shellcmd = 'find ' . &ToUnix($windir) . " -iregex '" . my $shellcmd = 'find ' . &ToUnix($::windir) . " -iregex '" .
'.*\.\(exe\|bat\|com\|dll\)' . "' -print"; '.*\.\(exe\|bat\|com\|dll\)' . "' -print";
if ($opt_debug) { if ($::opt_debug) {
print STDERR "DEBUG: autoexec.bat search command:\n $shellcmd\n"; print STDERR "DEBUG: autoexec.bat search command:\n $shellcmd\n";
} }
push(@DOScommand, `$shellcmd`); push(@::DOScommand, `$shellcmd`);
if ($opt_debug =~ /autoexec/i) { if ($::opt_debug && $::opt_debug =~ /autoexec/i) {
print STDERR "DEBUG: autoexec.bat search results:\n@DOScommand\n"; print STDERR "DEBUG: autoexec.bat search results:\n\@DOS::command\n";
} }
foreach $command (@DOScommand) { foreach my $command (@::DOScommand) {
$command =~ s%[^/]+$%%; $command =~ s%[^/]+$%%;
$DOSexecdir{$command}++; $::DOSexecdir{$command}++;
} }
print "path=" . print "path=" .
join(";", join(";",
grep(s%/$%%, grep(s%/$%%,
sort {$DOSexecdir{$b} <=> $DOSexecdir{$a}} sort {$::DOSexecdir{$b} <=> $::DOSexecdir{$a}}
(keys %DOSexecdir))) . "\n"; (keys %::DOSexecdir))) . "\n";
} }
if ($DOSenv{"temp"} && -d &ToUnix($DOSenv{"temp"})) { if ($::DOSenv{"temp"} && -d &ToUnix($::DOSenv{"temp"})) {
print "temp=" . $DOSenv{"temp"} . "\n"; print "temp=" . $::DOSenv{"temp"} . "\n";
} }
else { else {
my $TheTemp;
warn "WARNING: Making assumptions for TEMP\n"; warn "WARNING: Making assumptions for TEMP\n";
warn "Looking for \\TEMP and then \\TMP on every drive\n"; warn "Looking for \\TEMP and then \\TMP on every drive\n";
# Watch out .. might pick CDROM drive :-) # Watch out .. might pick CDROM drive :-)
foreach $DOSdrive (keys %DOS2Unix) { foreach my $DOSdrive (keys %::DOS2Unix) {
$tmp = &ToUnix("$DOSdrive:\\temp"); my $tmp = &ToUnix("$DOSdrive:\\temp");
if (-d $tmp) { $TheTemp = "$DOSdrive:\\temp"; last; } if (-d $tmp) { $TheTemp = "$DOSdrive:\\temp"; last; }
$tmp = &ToUnix("$DOSdrive:\\tmp"); $tmp = &ToUnix("$DOSdrive:\\tmp");
if (-d $tmp) { $TheTemp = "$DOSdrive:\\tmp"; last; } if (-d $tmp) { $TheTemp = "$DOSdrive:\\tmp"; last; }
} }
$TheTemp = '/tmp' if (!$TheTemp && -d '/tmp');
if ($TheTemp) { if ($TheTemp) {
warn "Using $TheTemp\n"; warn "Using $TheTemp\n";
print "temp=$TheTemp\n"; print "temp=$TheTemp\n";
@ -338,14 +346,14 @@ sub ToUnix {
my($FNunix); my($FNunix);
# Initialize tables if necessary. # Initialize tables if necessary.
if (!%DOS2Unix) { &ReadFSTAB; } if (!%::DOS2Unix) { &ReadFSTAB; }
# Determine which type of conversion is necessary # Determine which type of conversion is necessary
if ($FNdos =~ /^([A-Z])\:(.*)$/) { # DOS drive specified if ($FNdos =~ /^([A-Z])\:(.*)$/) { # DOS drive specified
$FNunix = $DOS2MntPoint{$1} . "/$2"; $FNunix = $::DOS2MntPoint{$1} . "/$2";
} }
elsif ($FNdos =~ m%\\%) { # DOS drive not specified, C: is default elsif ($FNdos =~ m%\\%) { # DOS drive not specified, C: is default
$FNunix = $DOS2MntPoint{"C"} . "/$FNdos"; $FNunix = $::DOS2MntPoint{"C"} . "/$FNdos";
} }
else { # Unix filename else { # Unix filename
$FNunix = $FNdos; $FNunix = $FNdos;
@ -360,8 +368,10 @@ sub ToUnix {
# Converts Unix filenames to DOS filenames # Converts Unix filenames to DOS filenames
sub ToDos { sub ToDos {
my($FNunix) = @_; my($FNunix) = @_;
my(@MntList) = keys %MntPoint2DOS; my(@MntList) = keys %::MntPoint2DOS;
foreach $MntPt (@MntList) { # Scan mount point list to see if path matches my ($TheMntPt, $FNdos);
foreach my $MntPt (@MntList) { # Scan mount point list to see if path matches
if ($FNunix =~ /^$MntPt/) { if ($FNunix =~ /^$MntPt/) {
$TheMntPt = $MntPt; $TheMntPt = $MntPt;
last; last;
@ -373,22 +383,29 @@ sub ToDos {
} }
$FNdos = $FNunix; $FNdos = $FNunix;
$FNdos =~ s/^$TheMntPt//; $FNdos =~ s/^$TheMntPt//;
$FNdos = $MntPoint2DOS{$TheMntPt} . ":" . $FNdos; $FNdos = $::MntPoint2DOS{$TheMntPt} . ":" . $FNdos;
1 while($FNdos =~ s%/%\\%); 1 while($FNdos =~ s%/%\\%);
return $FNdos; return $FNdos;
} }
sub InsertDefaultFile {
my ($fileName, $tag) = @_;
my $state = 0;
if (open(DEFFILE, "$fileName")) {
while (<DEFFILE>) {
$state = 0 if ($state == 1 && $_ =~ /^[ \t]*\#/o && index($_, "</$tag>") >= 0);
print $_ if ($state == 1);
$state = 1 if ($state == 0 && $_ =~ /^[ \t]*\#/o && index($_, "<$tag>" ) >= 0);
}
close(DEFFILE);
} else {
print STDERR "Cannot read $fileName\n";
}
}
sub StandardStuff { sub StandardStuff {
print "[serial]\n"; &InsertDefaultFile("./wine.ini", "wineconf");
print "com1=/dev/cua0\n";
print "com2=/dev/cua1\n";
print "\n";
print "[spy]\n";
print ";File=CON\n";
print ";File=spy.log\n";
print "Exclude=WM_TIMER;WM_SETCURSOR;WM_MOUSEMOVE;WM_NCHITTEST;\n";
print "Include=WM_COMMAND;\n";
} }
sub byFileAge { sub byFileAge {