Dec 272017
 
Allows the setting of Dos variables in its environment space. Includes complete ASM source.
File SETENVJW.ZIP from The Programmer’s Corner in
Category Utilities for DOS and Windows Machines
Allows the setting of Dos variables in its environment space. Includes complete ASM source.
File Name File Size Zip Size Zip Type
SETENV.ASM 30365 7147 deflated
SETENV.COM 3339 2045 deflated
SETENV.DOC 8710 3434 deflated
SETENV.HLP 1404 605 deflated
SETENV.UPD 1059 419 deflated

Download File SETENVJW.ZIP Here

Contents of the SETENV.DOC file







SETENV utility V1.4 (c) 02-Jun-1990
The SETENV program for a DOS version 2 allows setting
an environment variable. SETENV utility will run under
DOS 3.0 and 4.0. I have never seen DOS version 1.



SETENV : Copyright (c) 1988 to 1990 by John Wolchak.
I give permission to alter the code, but not to copy
or redistribute the altered code without my explicit
permission. If you alter the code, please document
changes and send me a copy, so all can have it.
This document must always accompany the SETENV
program when a copy is made for another machine.
This code, to the best of my knowledge works well.
I disclaim any responsibility for the codes actions
(use at your own risk).
John


The syntax of the command is:

SETENV

is any valid environment variable you wish to
define or re-define.

is a string of printable characters. Keys can be
embedded in the character string. The Keys are:
%cwd will return the current directory.
%dosv will return the DOS major version.
%dosm will return the DOS minor version.
%drive will return the current disk drive letter.
%-n will return the current disk drive minus 'n' letter(s).
%+n will return the current disk drive plus 'n' letter(s).

can be '%rep', where
will replace in the environment variable value.

can be '%prompt '
can be '%prompt %noecho '.
can be '%prompt %upper '
can be '%prompt %def '.
can be '%prompt %upper %def '.
can be '%prompt %noecho %def '.
can be '%prompt %noecho %upper %def ',
where the is displayed on the console and the
response is set into the variable. %def is optional, and
is the if just a return is given. is a one character
delimter, to quote the . %noecho is optional meaning not to
display the response on the screen. %upper is is optional meaning
to convert the lower case letters to upper case letters.



In batch (BAT files) use %% to represent a single % for use
to SETENV. ie. SETENV DRV_DIR %%drive:%%cwd






Note: SETENV can not expand the environment space. The DOS
SET command can do that, by creating temporary variables with
long values and then removing them before any resident program
is run. Resident programs are PRINT, MODE. Documentation is
available for versions of DOS 2 thru 3.20 that modify DOS to
have a larger environment area beyond the normal 160 bytes.




SETENV terminates with int 21h, AH=4ch, the intention is
that the program can be called from another program.

SETENV returns errorlevel codes, which are:

no command, help issued00h
root environment set01h
environment variable erased02h
environment variable created03h
environment space over written04h
environment variable updated05h
unmatched delimiter06h
don't know about MS-DOS V1.x07h
environment variable not found08h
offset of drive will be invalid09h
environment space is full10h


Code 04h environment space over written means that there
was non-zero data bytes encountered in the environment
space. This happens when environment variable is the
last one in the environment space and is deleted, the
variable is removed but the space is not erased. Code
04h will not have precedence over a higher code.



Example:

This example batch file can demonstrate the usage of SETENV.

setenv version MS-DOS V%%dosv.%%dosm in %%drive:%%cwd drv/dir.
setenv drvs Drive is %%+0:, with %%-1: prev and %%+1: next.
setenv first %%prompt Your First Name:
setenv last %%prompt %first% Your Last Name:
setenv answer %%prompt %%def/Y/ %first% %last% [Y/N] :
set

First note the %% for a single % in batch. In batch you can
use %% to reflect the value of a previous
environment variable. Make sure you have enough environment
space to store this amount of data.






History:

At work we have Disk and File Serving using DOS version 3.
When a machine optional has or not a hard disk, one or more
hard disk partitions and maybe a ramdisk, locating the disk
or file server is a little tricky. The disk and file servers
are located after your hard disk partitions. To find them we
copy a file, to a redefined disk. Then test to see if the
file exists. If the file exists, then what drive are we on.
Example is:
assign b=g >nul
assign b=h >nul
assign b=i >nul
assign b=j >nul
assign b=k >nul
copy command.com b:\
assign b=b >nul
if not exist k:\command.com goto jdrv
...
jdrv:
if not exist j:\command.com goto idrv
...
idrv:
...
...

(We no longer do this now that we have SETENV.)


I wrote a program called CURDRV. This program would put the
current disk drive letter in an environment variable called
CURDRV. The first problem was that when I set the environment
variable, then exited the program it was gone, because a
program has a copy of the environment space.

Then we went looking for a program that would return the current
disk drive, we came across a program written in C by Richard
Marks called SETENV. He says that his program would not work
under DoubleDOS, so this program as well will not work under
DoubleDOS. From Richard Marks's program I used the idea of
getting at the environment space by finding the program segment
prefix (PSP) of command.com. This is where the real environment
space lies.

For the users of DOS version 3 there is int 21h, and register
AH=52h, call to find the PSP. It is definitely alot easier
then what Richard Mark layed out, but his way is the only
way to find the PSP under DOS version 2 (to my knowledge).
This method still works under DOS version 3 and version 4,
but future releases may prove to be a problem.






Special sectiom:

If SETENV is called from within a shell there is sometimes a need
to set the environment variable into the most root environment space.
The means to set the root environment space is use %rce after the
program name followed by the usual arguments.
Example is:

SETENV %rce

A special note about calling Command.Com a second time is that all
environment variables are duplicated for the second call and that
changing any environment variable at this local call will not change
the original variable. That is purpose of the special argument.
When the exit command is used the original environment varilables are
restored.

Also note that environment space is allocated in 16 byte segments and
that when the environment space is copied only the necessary segments
are copied. (DOS V3.30 and DOS V4.0 allow you to set the size of the
environment space.) So if only one byte is in the last segment then
you have only 15 bytes to use. In the 15 bytes you also have to count
the variable name space as well. A way to get around this restriction
is to create a environment variable with a large environment space
before you call Command.Com, then remove the dummy environment variable.
This should give you some elbow room at the local Command.Com.



Restrictions:

SETENV programs traces the program segment prefix to find the environment
space, but when it finds the environment space SETENV first check if one
of PATH=, PROMPT= or COMSPEC= exists at the first segment boundary. I
am finding that there can be allot of changes to these variables, which
causes SETENV to search for ever looking for this arrangement. So SETENV
can now sink to a new variable SETENV=. Remember that when you type SET
to DOS PATH=, PROMPT=, COMSPEC=, or SETENV= must be the first varible.



Acknowledgement:

Richard Marks's C program because without it, I would not have found the
true system environment.
I wrote this program on a Rainbow, because that is what I have. At work
I use SEDT as my editor by Anker Berg-Sonne, (also runs on IBM PC's) but
at home it is a little large for a diskette based system. So at home I
use KEDT by Jay Jervey. I would like to thank these people because without
a good editor it can become near impossible to write any program.


John Wolchak
56 Physics Building
University of SaskatchewanPhone: (306) 966-4852
Saskatoon, SaskatchewanNetNorth (BITNET): Wolchak[email protected]
Canada S7K 0W0Inter_Network:[email protected]


 December 27, 2017  Add comments

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)