Contents of the EDME31.DOC file
EDME.EXE - EDit Master Environment 3.1 - Copyright 1990 - Bruce Scherzinger
This program is hereby submitted into the Public Domain. All rights are
reserved by the author. This program may be copied and distributed freely
provided this file always accompanies EDME.EXE. Use at your own risk.
TURBO PASCAL 5.5 SOURCE IS AVAILABLE UPON REQUEST FOR $5.00.
CALL ME AT HOME OR MAIL REQUESTS TO:
12015 Trossack Road
Herndon, Virginia 22070
EDME allows editing of the DOS master environment. This is not the copy of
the environment which is created when a program is started. EDME always
works on the master copy.
CHANGES SINCE VERSION EDME 3.0 (mostly bug fixes):
1. ADDED CHECKS FOR OUT OF MEMORY AND OUT OF ENVIRONMENT SPACE AND
CORRESPONDING MESSAGES. NOW DISPLAYS TOTAL MEMORY AVAILABLE IN UPPER
2. ADDED CODE TO RELEASE MEMORY BACK TO THE HEAP AFTER A SORT IS DONE FOR
EMPTY VARIABLE ASSIGNMENTS.
3. ASSIGNED THE "CUT" BUFFER AN INITIAL VALUE SO THAT IF PASTE WAS DONE
BEFORE CUT, GARBAGE WOULD NOT RESULT.
CHANGES SINCE VERSION EDME 2.0:
1. EDME 3.0 IS NOW COMPATIBLE WITH DOS 2.0 AND LATER. EARLIER VERSIONS
OF EDME WERE NOT COMPATIBLE WITH DOS 3.3 AND LATER.
2. THERE IS VIRTUALLY NO LIMIT ON THE SIZE OF THE ENVIRONMENT EDME CAN
HANDLE. THE SCREEN WILL SCROLL AS NECESSARY TO ACCESS VARIABLES NOT
VISIBLE. YES, EDME IS NOW EFFECTIVELY A FULL-SCREEN EDITOR!
3. THE EDITING WINDOW SIZE IS SET BASED ON THE SIZE OF THE SCREEN WHEN
EDME IS ENTERED. THIS SUPPORTS ALL EGA AND VGA SCREEN DIMENSIONS.
4. A FUNCTION HAS BEEN ADDED TO SORT THE ENVIRONMENT ALPHABETICALLY IN
ASCENDING ORDER. IT DID NOT SEEM USEFUL TO PROVIDE A DESCENDING SORT.
WHEN A SORT IS COMMANDED, ALL ERASED (OR NULL) ENTRIES ARE PURGED.
5. CUT AND PASTE FUNCTIONS HAVE BEEN ADDED. THIS ALLOWS YOU TO TAKE A
SNAPSHOT OF A VARIABLE ASSIGNMENT, COPY IT TO A VACANT LOCATION, AND
MAKE CHANGES TO IT (INCLUDING ASSIGNING IT A NEW NAME).
6. EDME IS COMPATIBLE WITH 4-DOS V3.0. FOR USE WITH 4-DOS 2.21, THE "/M"
FORM OF ENVIRONMENT SIZE SPECIFICATION MUST BE USED.
Command line syntax: EDME [variable]
If no variable is specified, EDME will highlight the first variable
encountered. Otherwise, it will highlight the specified variable.
EDME checks the type of monitor you are using. If you are using a non-
monochrome monitor, EDME will display color if the MODE is set to CO80.
For black & white set MODE BW80.
Example: EDME PATH
1) All IBM characters except , , and are valid.
2) "Enter","UP", & "DOWN" modify the variable assignment
3) "-->" moves cursor one character to right
4) "<--" moves cursor one character to left
5) "Ctrl-->" moves cursor eight characters to right
6) "Ctrl<--" moves cursor eight characters to left
7) "Home" moves cursor to beginning of line
8) "End" moves cursor to end of line
9) "Ctrl-End" deletes from cursor to end of line
10) "Ins" enables/disables insert mode (block cursor)
11) "backspace" deletes character to left of cursor
12) "Del" deletes character over cursor
13) "Ctrl-Home" retrieves original string (prior to Enter/Up/Down)
14) "Esc" clears the editing field
15) "UP arrow" moves the editing field up one line
16) "DOWN arrow" moves the editing field down one line
17) "PGUP" scrolls the screen down (and the highlighter up)
18) "PGDN" scrolls the screen up (and the highlighter down)
19) "Ctrl-PGUP" moves to the first variable
20) "Ctrl-PGDN" moves to the last variable
21) "F1" sorts the working copy of the environment alphabetically
22) "F2" saves ("cuts") a copy of the highlighted assignment
23) "F3" pastes the "cut" buffer at the current highlighter position
24) "F9" sets the master environment to exactly what is displayed
25) "F10" terminates EDME program
1) EDME will not allow the editing field to be moved nor the environ-
ment to be updated if an invalid variable assignment is detected. A
valid assignment is one with no blanks before an "=" sign and at least
one character after the "=" sign. Note that at the DOS prompt, envi-
ronment variables are deleted by typing "SET VAR=". With EDME, a
variable is deleted by moving the editing field to it and pressing ESC.
When the environment is updated, the deleted variable will not be saved.
EDME will automatically convert all alphabetic characters to the left
of the "=" sign to upper case as required by DOS. EDME will not allow
any variable to be assigned a second time.
2) EDME continuously displays the status of what you are doing. At the
top right, an indicator shows whether there is more to view beyond the
vertical screen limits. At the bottom, the available environment size
is displayed along with the amount currently used and the size of the
current variable assignment (all in bytes, excluding terminating ASCII
Each environment variable must be 128 or fewer characters in length.
If this is not the case, use of EDME will truncate the variable
assignment. If a variable assignment is > 80 characters, EDME will
scroll the line being edited as necessary. When this occurs, a
flashing arrow will appear on whichever end(s) of the editing window
characters are not visible.
1) EDME trims blanks off the rightmost end of a variable assignment
when it is revisited with the highlighter. This is only a factor
when it is desired to have blanks at the end of the assignment.
If you want your PROMPT to end with a blank, use the $S format.
Otherwise, once you have added trailing blanks to a variable
assignment, don't go back to it.
2) When you move to an unoccupied space to create a new variable with
EDME, the string "[new variable]" appears in the editing window.
This string must be removed either by pressing ESC before entering
the new variable assignment, or by pressing Ctrl-End after the new
assignment is fully typed. If the string is obliterated by what is
typed, no further action is required.
3) The size of the DOS environment can be set at system boot time by
inserting the following command in the CONFIG.SYS file:
SHELL=C:\path\COMMAND.COM /P /E:xxxx
where "path" is the subdirectory where COMMAND.COM is located and
"xxxx" is the desired size of the DOS environment in bytes. This
value will be rounded down to the nearest multiple of 16 bytes.
Generally, a value of 1024 is sufficient. EDME can handle any number
of environment variable assignments of up to 128 characters each, as
long as there is enough memory available to run EDME and make a copy
of the environment to edit. For each variable in the environment and
each new one created in EDME, 129 bytes are allocated, whether or not
the variable actually uses it all or not. The excess is trimmed off
when the environment is updated.
4) If your PATH assignment is longer than 128 characters, you can shorten
it by utilizing the DOS "SUBST" command to redefine any subdirectory in
the PATH. The format is as follows:
SUBST d: path
You then must replace the "path" in the PATH variable assignment with
the virtual disk drive. The following illustrates how to do this:
SUBST X: C:\MY\SUB\DIRECTORY
SUBST Y: C:\YOUR\SUB\DIRECTORY
Note that you will also have to include the following command in the
CONFIG.SYS file to extend the possible virtual drive assignments:
where 'Z' can be any letter in the alphabet beyond the last physical
drive in your system.
5) If your PROMPT assignment is longer than 128 characters, SHORTEN IT!
6) A batch file can access any environment variable as %name%. Beyond
this, everything works exactly the same as using %0-%9 imported from
the command line.
"GETTING A GRIP ON THE DOS MASTER ENVIRONMENT", by Bruce Scherzinger
I had been putting off writing this program for several years when my
interest was revived by an article and C program listing reviewed in the
"Languages" column of PC Magazine, Volume 7, Number 14, about modifying the
master DOS environment.
My original interest was to extend the capabilities of batch (.BAT) files
to include simple arithmetic using environment variables for managing loop
control among other omissions from the DOS batch language. Though there have
been several attempts at extending or "enhancing" the DOS batch environment,
what has been produced is a variety of replacements for it. I have always
thought of "enhancing" something as adding to it in a positive way, not
replacing it altogether (although some might argue this is truly needed in this
The first obstacle was to get a firm grasp on the DOS master environment.
This is the only copy of the environment batch files can "see", but finding it
is not a well-documented process. To start with, the start of the DOS Memory
Control Block (MCB) chain must be found. This is done by issuing a call to DOS
function 52h (undocumented), which returns in ES:BX the address of the
memory paragraph of the first (root) MCB. Actually, BX points one word
past the root segment address.
Searching the MCB chain is done by successively adding the MCB header
address (+1) and MCB size together (these are 1-word values stored at offsets 1
and 3 in the MCB header, respectively). To find the master environment, the
master copy of DOS must first be found. This is done by locating the first MCB
whose PSP address is the same as its parent PSP address (that is,
MCB^.PSP_addr = MCB^.PSP.parent_seg). This is not necessarily the first MCB.
DOS MCB CHAIN CONCEPT
offset in bytes 0 1 3 5 ...F
DOS call 52h >
'M' PSP_addr MCB_size reserved first MCB header
program or data bytes start of PSP
. . .
: : :
'M' PSP_addr MCB_size reserved MCB header
program or data bytes start of PSP
. . .
: : :
'Z' PSP_addr MCB_size reserved last MCB header
Once found, the master environment has all the attributes of any clone of
itself; that is, each variable string is separated by an ASCII nul (0)
character and the whole thing has one extra nul at the end. The DOS Technical
Reference contains a description of the environment.
To exemplify this, I decided to write a simple utility for which I
yearned every time I wanted to make a slight change to my PATH or PROMPT
statement (I use rather extravagant and lengthy PROMPT statements)
without retyping the whole thing. I also wanted a quicker way to SET or
delete several new variables at one time without having to type SET over
again. The result is a program called "EDit Master Environment", alias
The source code for EDME.PAS is available as explained above. It
illustrates the secrets to traversing the DOS memory allocation chain and
ultimately finding the master environment, the former being very important
for those wishing to write TSR (terminate and stay resident) programs which
do not reinstall themselves if activated multiple times. EDME is not a TSR
program because once within another program, altering the master environment
is pointless (it was already copied when the program was started). However,
when run from a DOS shell via programs like Lotus 123, EDME will update the
MASTER environment. EDME is also a good example of how to abuse pointers in
END OF README FILE FOR EDME31.ZIP