nather@ut-sally.UUCP (Ed Nather) (04/18/86)
The attached "shar" file includes the uuencoded version of an executable
file -- use uudecode to reover the original.
# This is a shell archive. Remove anything before this line,
# then unpack it by saving it in a file and typing "sh file".
#
# Wrapped by sally!nather on Thu Apr 17 16:47:40 CST 1986
# Contents: drv.doc testdrv.bat drv.asm drv.uue
echo x - drv.doc
sed 's/^@//' > "drv.doc" <<'@//E*O*F drv.doc//'
The new "subst" command in MS-DOS 3.1 is designed to allow the construction of
".bat" files to run older programs on a hard disk -- programs designed for
earlier versions of DOS that did not understand hierarchical directories and
pathnames. It almost does this, but not quite.
The command
subst e: c:\compile\desmet
will create an equivalence such that the path "c:\compile\desmet" can be
referred to as "e:" -- just like a separate drive. If that directory contains
all the files needed to compile a program, then a simple .bat file that first
makes "e:" the default drive and then runs the compiler should work as
expected -- IF you know what drive WAS the default before you made the change.
Ay, there's the rub: what drive WERE you on before you changed to "e:" --
important, since that's where your source file is.
Attached is a small (9 byte) program which can be run from a .bat file and
will report, in a manner a .bat file can test, the drive number of the (now)
current drive. If you run this first before you change to "e:" then you will
know the drive your source file is on, you can compile it, and then return to
the original default drive.
The attached test file "testdrv.bat" makes use of the (undocumented) feature
of .batfile processing that causes an environment string to be substituted for
the environment variable name if it is surrounded by %-signs. That is, if you
have preset a path string, that string will be substituted, in a .bat file,
for the variable name %PATH%. "testdrv.bat" shows how this works. Note that
the ".bat variable" %DRV% in the example can also be used as an executable
command to return control to the original default drive, and can be prepended
to incoming arguments as a drive designator:
C88 %DRV%%1
will become
C88 c:prog
if the original default drive was "c:" and the 1st argument "prog."
The sequence of operations would look like this:
1. Run "drv.com" to find out the number of the current drive.
2. Save the drive designator in the environment variable "DRV".
3. Use "subst" to create a drive alias for a pathname -- say "e:".
4. Change to "drive" e:.
5. Run the program, prepending %DRV% to incoming arguments.
6. Return to the original drive by using %DRV% as a .batfile command.
7. Clean up. ("subst e: -D" removes the drive alias, "set DRV=" removes
the temporary environment variable).
@//E*O*F drv.doc//
chmod u=rw,g=r,o=r drv.doc
echo x - testdrv.bat
sed 's/^@//' > "testdrv.bat" <<'@//E*O*F testdrv.bat//'
:get current drive and report what it is
:note that all drives beyond "e" are reported as "e:"
drv
if errorlevel 0 set DRV=a:
if errorlevel 1 set DRV=b:
if errorlevel 2 set DRV=c:
if errorlevel 3 set DRV=d:
if errorlevel 4 set DRV=e:
echo current drive is %DRV%
set DRV=
@//E*O*F testdrv.bat//
chmod u=rw,g=r,o=r testdrv.bat
echo x - drv.asm
sed 's/^@//' > "drv.asm" <<'@//E*O*F drv.asm//'
; drv - return current drive number as errorlevel
CSEG SEGMENT PARA PUBLIC 'CODE'
ASSUME CS:CSEG,DS:CSEG,SS:CSEG,ES:CSEG
ORG 100H
START PROC NEAR
mov ax,1900h ; get current drive number
int 21h
mov ah,4ch ; return AL as errorlevel
int 21h
START ENDP
CSEG ENDS
END START
@//E*O*F drv.asm//
chmod u=rw,g=r,o=r drv.asm
echo x - drv.uue
sed 's/^@//' > "drv.uue" <<'@//E*O*F drv.uue//'
begin 644 drv.com
)N``9S2&T3,TA
`
end
@//E*O*F drv.uue//
chmod u=rw,g=r,o=r drv.uue
echo Inspecting for damage in transit...
temp=/tmp/shar$$; dtemp=/tmp/.shar$$
trap "rm -f $temp $dtemp; exit" 0 1 2 3 15
cat > $temp <<\!!!
51 413 2433 drv.doc
11 51 272 testdrv.bat
14 45 280 drv.asm
4 6 38 drv.uue
80 515 3023 total
!!!
wc drv.doc testdrv.bat drv.asm drv.uue | sed 's=[^ ]*/==' | diff -b $temp - >$dtemp
if [ -s $dtemp ]
then echo "Ouch [diff of wc output]:" ; cat $dtemp
else echo "No problems found."
fi
exit 0
--
Ed Nather
Astronomy Dept, U of Texas @ Austin
{allegra,ihnp4}!{noao,ut-sally}!utastro!nather
nather@astro.AS.UTEXAS.EDU