3 # This program generates wine.conf files on STDOUT.
4 # (C) 1996 Stephen Simmons
5 # Redistributable under Wine License
9 # This program examines the contents of the DOS filesystems and
10 # attempts to generate a sensible wine.conf file. This is output
12 # It reads /etc/FSTAB to find mounting locations of the hard disk drives
13 # It uses the correct algorithm for ordering DOS drives, with the
14 # exception of the case of multiple drive controller types, where I don't
15 # know what DOS's algorithm is.
16 # It uses find to find all of the win.ini files on any DOS partition
17 # and sorts them by age to guess which is part of the active Windows
19 # It reads the autoexec.bat file (if found) and records all variable
20 # settings. There are some inaccuracies in its determination.
21 # First, while variables are interpolated properly, no control
22 # structures are supported so calls and execs to other batch files are
23 # ignored, and all variable settings take effect regardless of whether
24 # they would in DOS (i,e., both if and else clauses are read).
25 # This is used to determine the path and temp directories. Duplicate
26 # path directories and path directories that don't exist are thrown
28 # On failing to find C:\AUTOEXEC.BAT, wineconf finds all executables
29 # in the windows directory and subdirectories, and generates an
30 # optimized path statement encompassing all the executables.
31 # Then it also looks for \TEMP and \TMP on all drives taking the first
33 # wineconf doesn't support floppy drives, network drives, printers,
34 # and serial device configuration is hardcoded and not configured for
35 # the machine it runs on. Similarly, spy parameters are hard coded.
37 # It would make sense to incorporate much of the hueristic code in
38 # this program into a library to be shared with a dosemu configuration
39 # program, because it seems that at least some of the same stuff will
40 # be wanted. The program needs to be cleaned up still. A better tmp
41 # search algorithm could be written. A fast option is planned. Less
42 # Linux-dependence is desired. Should look for devices independent
43 # of /etc/fstab; then sanity checks on /etc/fstab can be performed.
49 GetOptions('windir=s', 'sysdir=s', 'thorough', 'debug:s') || &Usage;
57 print "Usage: $0 <options>\n";
58 # print "-fstab <filename> Location of alternate fstab file\n";
59 print "-windir <filename> Location of windows dir in DOS space\n";
60 print "-thorough Do careful analysis (default)\n";
61 print "-sysdir <filename> Location of systems dir in DOS space\n";
62 # print "-tmpdir <filename> Location of tmp directory\n";
63 print "Generates (to STDOUT) a wine configuration file based on\n";
64 print "/etc/fstab and searching around in DOS directories\n";
65 print "The options above can override certain values\n";
66 print "This should be considered ALPHA code\n";
71 $opt_f = $opt_f ? $opt_f : '/etc/fstab';
72 open(FSTAB, $opt_f) || die "Cannot read $opt_f\n";
76 ($device, $mntpoint, $type, @rest) = split(' ', $_);
77 if ($device !~ m"^/dev/fd") {
78 if ($type eq "msdos" || $type eq "vfat") {
79 push(@FatDrives, [$device, $mntpoint]);
81 elsif ($type eq "iso9660") {
82 push(@CdromDrives, [$device, $mntpoint]);
87 warn "ERROR ($0): Cannot find any MSDOS drives.\n";
88 warn "This does not mean you cannot run Wine, but $0\n";
89 warn "cannot help you (yet)\n";
93 @FatDrives = sort byDriveOrder @FatDrives;
94 @CdromDrives = sort byCdOrder @CdromDrives;
95 foreach $FatDrive (@FatDrives) {
96 print "[Drive $MagicDrive]\n";
97 $MntPoint = $FatDrive->[1];
98 print "Path=$MntPoint\n";
101 &RegisterDrive($MagicDrive, $FatDrive);
102 if(!&IsMounted($FatDrive->[0])) {
103 warn "WARNING: DOS Drive $MagicDrive (" . $FatDrive->[0] .
104 ") is not mounted\n";
108 foreach $CdromDrive (@CdromDrives) {
109 print "[Drive $MagicDrive]\n";
110 $MntPoint = $CdromDrive->[1];
111 print "Path=$MntPoint\n";
112 print "Type=cdrom\n";
114 &RegisterDrive($MagicDrive, $CdromDrive);
120 my($MagicDrive) = 'C';
121 my(@FATD)=@FatDrives;
123 if (!$opt_windir && !$opt_fast && !$opt_thorough) {
127 $winini = &ToUnix($opt_windir);
129 die "ERROR: Specified winini file does not exist\n";
133 die "-fast code can be implemented\n";
135 elsif ($opt_thorough) {
136 if ($opt_debug) { print STDERR "DEBUG: Num FATD = ", $#FATD+1, "\n"; }
138 $ThisDrive = shift(@FATD);
139 $MntPoint = $ThisDrive->[1];
140 push(@wininis, `find $MntPoint -name win.ini -print`);
142 foreach $winini (@wininis) {
145 my($winini_cnt) = $#wininis+1;
147 print STDERR "DEBUG: Num wininis found: $winini_cnt\n";}
148 if ($winini_cnt > 1) {
149 warn "$winini_cnt win.ini files found:\n";
150 @wininis = sort byFileAge @wininis;
151 warn join("\n", @wininis), "\n";
152 $winini = $wininis[0];
153 warn "Using most recent one: $winini\n";
155 elsif ($winini_cnt == 0) {
156 die "ERROR: No win.ini found in DOS partitions\n";
159 $winini = $wininis[0];
163 die "ERROR: None of -windir, -fast, or -thorough set\n";
165 $windir = &ToDos(dirname($winini));
167 print "windows=$windir\n";
169 print "system=$opt_sysdir\n";
172 print "system=$windir\\SYSTEM\n";
176 # Returns 1 if the device is mounted; -1 if mount check failed; 0 if not
178 # This code is Linux specific, and needs to be broadened.
182 if (-e "/proc/mounts") {
183 open(MOUNTS, "/proc/mounts") ||
184 (warn "Cannot open /proc/mounts, although it exists\n" &&
188 return 1; # Tested 1.4
191 return 0; # Tested 1.4
198 my($DOSdrive, $Drive) = @_;
199 $DOS2Unix{$DOSdrive} = $Drive;
200 $Device2DOS{$Drive->[0]} = $DOSdrive;
201 $MntPoint2DOS{$Drive->[1]} = $DOSdrive;
202 $DOS2MntPoint{$DOSdrive} = $Drive->[1];
203 $DOS2Device{$DOSdrive} = $Drive->[0];
206 sub ReadAutoexecBat {
207 if (!%DOS2Unix) { &ReadFSTAB; }
208 my($DriveC) = $DOS2MntPoint{"C"};
212 print STDERR "DEBUG: Looking for $DriveC/autoexec.bat\n"; }
213 if (-e "$DriveC/autoexec.bat") {
215 open(AUTOEXEC, "$DriveC/autoexec.bat") ||
216 die "Cannot read autoexec.bat\n";
219 if (/^\s*(set\s+)?(\w+)\s*[\s\=]\s*(.*)$/i) {
223 $varname =~ tr/A-Z/a-z/;
224 while ($varvalue =~ /%(\w+)%/) {
225 $matchname = $subname = $1;
226 $subname =~ tr/A-Z/a-z/;
227 if ($opt_debug =~ /path/i) {
228 print STDERR "DEBUG: Found $matchname as $subname\n";
229 print STDERR "DEBUG: Old varvalue:\n$varvalue\n";
230 print STDERR "DEBUG: Old subname value:\n" .
231 $DOSenv{$subname} . "\n";
233 if ($DOSenv{$subname}) {
234 $varvalue =~ s/\%$matchname\%/$DOSenv{$subname}/;
237 warn "DOS environment variable $subname not\n";
238 warn "defined in autoexec.bat. (Reading config.sys\n";
239 warn "is not implemented.) Using null value\n";
240 $varvalue =~ s/%$matchname%//;
242 if ($opt_debug =~ /path/i) {
243 print STDERR "DEBUG: New varvalue:\n$varvalue\n";
247 print STDERR "DEBUG: $varname = $varvalue\n";
249 $DOSenv{$varname} = $varvalue;
256 warn "WARNING: C:\\AUTOEXEC.BAT was not found.\n";
259 if ($DOSenv{"path"}) {
260 @pathdirs = split(/\s*;\s*/, $DOSenv{"path"});
261 if ($opt_debug =~ /path/i) {
262 print STDERR "DEBUG (path): @pathdirs\n";
264 foreach $pathdir (@pathdirs) {
265 if (-d &ToUnix($pathdir)) {
266 if ($DOSpathdir{$pathdir}++) {
267 warn "Ignoring duplicate DOS path entry $pathdir\n";
270 if ($opt_debug =~ /path/i) {
271 print STDERR "DEBUG (path): Found $pathdir\n";
273 push(@DOSpathlist, $pathdir);
277 warn "Ignoring DOS path directory $pathdir, as it does not\n";
281 print "path=" . join(";", @DOSpathlist) . "\n";
284 # Code status: tested 1.4
285 warn "WARNING: Making assumptions for PATH\n";
286 warn "Will scan windows directory for executables and generate\n";
287 warn "path from that\n";
288 $shellcmd = 'find ' . &ToUnix($windir) . " -iregex '" .
289 '.*\.\(exe\|bat\|com\|dll\)' . "' -print";
291 print STDERR "DEBUG: autoexec.bat search command:\n $shellcmd\n";
293 push(@DOScommand, `$shellcmd`);
294 if ($opt_debug =~ /autoexec/i) {
295 print STDERR "DEBUG: autoexec.bat search results:\n@DOScommand\n";
297 foreach $command (@DOScommand) {
298 $command =~ s%[^/]+$%%;
299 $DOSexecdir{$command}++;
304 sort {$DOSexecdir{$b} <=> $DOSexecdir{$a}}
305 (keys %DOSexecdir))) . "\n";
308 if ($DOSenv{"temp"} && -d &ToUnix($DOSenv{"temp"})) {
309 print "temp=" . $DOSenv{"temp"} . "\n";
312 warn "WARNING: Making assumptions for TEMP\n";
313 warn "Looking for \\TEMP and then \\TMP on every drive\n";
314 # Watch out .. might pick CDROM drive :-)
315 foreach $DOSdrive (keys %DOS2Unix) {
316 $tmp = &ToUnix("$DOSdrive:\\temp");
317 if (-d $tmp) { $TheTemp = "$DOSdrive:\\temp"; last; }
318 $tmp = &ToUnix("$DOSdrive:\\tmp");
319 if (-d $tmp) { $TheTemp = "$DOSdrive:\\tmp"; last; }
322 warn "Using $TheTemp\n";
323 print "temp=$TheTemp\n";
333 # FNunix = &ToUnix(FNdos);
334 # Converts DOS filenames to Unix filenames, leaving Unix filenames
340 # Initialize tables if necessary.
341 if (!%DOS2Unix) { &ReadFSTAB; }
343 # Determine which type of conversion is necessary
344 if ($FNdos =~ /^([A-Z])\:(.*)$/) { # DOS drive specified
345 $FNunix = $DOS2MntPoint{$1} . "/$2";
347 elsif ($FNdos =~ m%\\%) { # DOS drive not specified, C: is default
348 $FNunix = $DOS2MntPoint{"C"} . "/$FNdos";
350 else { # Unix filename
353 1 while ($FNunix =~ s%\\%/%); # Convert \ to /
354 $FNunix =~ tr/A-Z/a-z/; # Translate to lower case
355 1 while ($FNunix =~ s%//%/%); # Translate double / to /
359 # FNdos = &ToDOS(FNunix)
360 # Converts Unix filenames to DOS filenames
363 my(@MntList) = keys %MntPoint2DOS;
364 foreach $MntPt (@MntList) { # Scan mount point list to see if path matches
365 if ($FNunix =~ /^$MntPt/) {
371 Carp("ERROR: $FNunix not found in DOS directories\n");
375 $FNdos =~ s/^$TheMntPt//;
376 $FNdos = $MntPoint2DOS{$TheMntPt} . ":" . $FNdos;
377 1 while($FNdos =~ s%/%\\%);
384 print "com1=/dev/cua0\n";
385 print "com2=/dev/cua1\n";
389 print ";File=spy.log\n";
390 print "Exclude=WM_TIMER;WM_SETCURSOR;WM_MOUSEMOVE;WM_NCHITTEST;\n";
391 print "Include=WM_COMMAND;\n";
399 my($DeviceA) = $a->[0];
400 my($DeviceB) = $b->[0];
402 # Primary drives come first, logical drives last
403 # DOS User's Guide (version 6) p. 70, IBM version.
404 # If both drives are the same type, sort alphabetically
405 # This makes drive a come before b, etc.
406 # It also makes SCSI drives come before IDE drives;
407 # this may or may not be right :-(
408 my($Alogical, $Blogical);
409 if (substr($DeviceA, 3, 1) >= 5) { $Alogical++; }
410 if (substr($DeviceB, 3, 1) >= 5) { $Blogical++; }
411 if ($Alogical && !$Blogical) { return -1; }
412 elsif ($Blogical && !$Alogical) { return 1; }
413 else { return ($DeviceA cmp $DeviceB); }
417 my($DeviceA) = $a->[0];
418 my($DeviceB) = $b->[0];
419 $DeviceA cmp $DeviceB;