Dec 092017
Allows a user to customize and remap 4DOS key definitions. In addition, 4DOS command line editing functions may be expanded.
File 4MAP.ZIP from The Programmer’s Corner in
Category Utilities for DOS and Windows Machines
Allows a user to customize and remap 4DOS key definitions. In addition, 4DOS command line editing functions may be expanded.
File Name File Size Zip Size Zip Type
4MAP.DOC 16100 5611 deflated
4MAP.EXE 2752 1364 deflated
EDIT.ZIP 23303 18464 deflated
MAPDEF 2028 588 deflated
PUTMAP.EXE 18551 11006 deflated

Download File 4MAP.ZIP Here

Contents of the 4MAP.DOC file

Version 1.01

A Keybinding Program for 4DOS
Ho-Ping Tseng

(c) Copyright 1990 by Ho-Ping Tseng, ALL RIGHTS RESERVED

4DOS a registered trademark of J.P. Software

This program may be freely distributed for non-commercial, non-business,
and non-governmental uses, provided this notice is attached with it. My
only request is that if you plan to use it regularly, you let me know of
it through e-mail or postal mail, so that I have an idea of how useful
this program is. Please let me know of any comments that you may have
and any suggestions or criticisms.

Ho-Ping Tseng
575 S. Rengstorff Ave., #26
Mountain View, Ca. 94040
e-mail: [email protected]


This program provides two basic capabilities for the 4DOS command
line processing. First, it filters keyboard inputs through a user-defined
keymap, before they reach 4DOS. Second, it can launch executable programs
in response to keystrokes while within the 4DOS command line.

With these two functions, a user can customize and remap 4DOS key
definitions. In addition, 4DOS command line editing functions may be
expanded. As an example, a minimal vi-like implementation is included that
uses many of the keys familiar to vi users and provides similar edit and
insert modes.

Note that this program differs in purpose to that of the conventional
keymapping programs. It is meant to take effect only during command line
processing, and it can map keystrokes sequences, not just a single keystroke.
Also, editing functions can be added on top of that provided by 4DOS with
its program launching capability.


This program is implemented as a terminate and stay resident routine
(TSR). It takes up about 2500 bytes of memory. It has been tested on the
latest versions of 4DOS (3.01 and 3.02).


The basic functionalities of this program is included in 3 files:
"4map.exe," "putmap.exe," and "mapdef." 4map.exe implements the filter and
stays resident in memory. Putmap.exe installs the user-defined keymap into
memory. And finally, mapdef contains an example keymap.

Also included is "," which contains programs that perform
miscellaneous command line editing functions. They are invoked by 4map.exe
in response to keystroke sequences defined by mapdef.


4map.exe and putmap.exe can be run from the command line or more
conveniently placed in autoexec.bat. They can be run either before or
after starting 4DOS. To run, type the following or include them in
putmap mapdef

This assumes, of course, that 4map.exe and putmap.exe are placed
in a directory that is in the search path. Also, if mapdef is not in the
current directory (root if these were invoked in autoexec.bat), its full
pathname must be specified.

To install the programs in, as defined by the contents of
mapdef, make a directory on the C partition of the disk called MAP and copy into it. Then unzip

Note that the functionalities provided by is optional, and
map.exe would function equally well (albeit without these functions) even
if it is not installed.

The contents and format of the map definition are discussed next,
plus a description of mapdef and


A keymap file contains definitions of keystroke mappings that 4MAP
uses to perform its operations. Several sets of mappings are allowed in
this file (with the first set being the default used when a keymap is first
installed), and 4MAP gives provisions for switching from one to another.
This will be described in more detail later. For convenience, when a "map"
is referred to below, it will mean a set of these mappings.

Each map is defined by the construct:

mapname = {rule1 ;
rule2 ;
ruleN ; }

where "mapname" is a name given to this map and "ruleX" refers to the Xth
mapping rule. '= {', ';', and '}' correspond to delimiters required by

Each rule is further represented by two fields, the "pattern" and
its "binding", defined by the construct:

pattern => binding

"Pattern" denotes a sequence of keystrokes that is used to match the
keyboard input. 4MAP successively examines each pattern according to
its location in the map, with the ones closer to the beginning of the
map searched first. When a partial match occurs (the input sequence
matches the pattern so far but is shorter than the pattern), the search
is suspended until more input is received. At the first instance that
4MAP can determine whether or not the input sequence produces a match,
certain actions are performed. If a match did occur, "binding" is
executed. Otherwise the input sequence is sent to 4DOS unmodified.

5.1 The Pattern

Each pattern may contain keynames (such as "del" and "home")
ascii codes, random keystrokes (e.g. abcd), and wildcard characters.
Keynames are reserved words and are provided for convenience. A list
of them is provided in the Appendix. Ascii codes may be specified in
octal (preceded by 0, such as 0101 for the character 'A'), decimal
(such as 65 for 'A'), or hex format (preceded by 0x, such as 0x41 for
'A'). Wildcard characters include '?' for matching any single keystroke
and '*' for matching any sequence of keystrokes. The special character
'\' is used as an escape character, so that the character immediately
following it is used literally as part of the pattern. To use '\' in
the pattern, just enter '\\' instead. Also, commas, spaces, tabs, and
carriage returns are treated as delimiters and ignored; they must be
preceded by '\' to be part of the pattern (or specified by keynames
where appropriate or in ascii codes).

For example,

ab, del \4 ?s

denotes a keystroke sequence of: 'a', 'b', the delete key, '4', any keystroke,
and 's'. Note that in order to avoid '4' from being treated as control-d
rather than the key '4', it must be preceded by the escape character. In
general, all numerals are treated as ascii codes unless preceded by '\'.

To use the sequence 'd', 'e', 'l' as part of the pattern rather
than to specify the delete key, the above pattern may be changed to:

ab, \del \4 ?s
orab, d el \4 ?s

or variations of these.

5.2 The Binding

A binding represents a list of actions that is performed when
its corresponding pattern matches the keyboard input. It is separated
from the pattern by the delimiter '=>' and can be classified into two
basic types. Each of these are described below.

The first type simply performs the mapping function--given an
input that matches the pattern, certain keystroke sequence is sent to
4DOS as though it had just been typed by the user. To specify the
sequence, similar mechanism to that used to specify the patterns is
used here--it is specified with keynames, ascii codes, and random
keystrokes. As with patterns, commas, spaces, tabs, and carriage
returns are used as delimiters, and '\' is used as the escape character.
The various rules described above for the pattern specifications apply
here as well (except wildcard characters are not used here). For example,

k=>del ins a ins

maps 'k' into the sequence: del, ins, 'a', and ins. In the context of 4DOS,
this would mean that whenever 'k' is typed, the character at the cursor is
replaced by the character 'a'.

The second type consists of command requests to 4MAP. It currently
includes a command to change the current map and one to invoke a program.

Switching to another map is facilitated by the keyword "changemap".
When the binding containing this keyword is executed, the current map is
changed to the one specified by the argument of "changemap", and subsequent
inputs are mapped according to the definitions given in this new map. Thus,

i=>changemap insert

would change the current map to "insert". Using this mechanism, several
maps may be defined that could provide different mapping characteristics
or "modes." In the keymap provided, this is used to simulate the insert
and edit modes of vi. Note that when a keymap file is first installed,
the first map becomes the current one.

Invoking a program requires enclosing the full pathname of the
program file and its arguments inside the special character '`' (back
quote). It is used to launch a program in response to an input sequence.
For example,

i=>changemap insert, `\map\prog.exe 2`

changes the current map to "insert" and executes \map\prog.exe with an
argument of 2 when 'i' is typed. Note that to accommodate DOS and for
convenience, '\' is not recognized as an escape character within the back
quotes--there is no escape mechanism for program name specification. Also,
no error message is displayed if an error is encountered while executing the
program. In particular, if the program file does not exist, no action is


Comments may be inserted anywhere in the keymap file to increase
readability. They are delimited by '/*' at the beginning and '*/' at
the end--everything in between is ignored.

5.4 Special Characters

As a summary, characters or character sequences possessing special
meanings to 4MAP are listed below:

\Escape character used in the patterns and the parts
of the bindings which specify the character mappings
= {Beginning of a map definition
=>End of pattern field and beginning of binding field
;End of binding field and a mapping rule definition
}End of a map definition
/*Beginning of a comment
*/End of a comment
,Delimiter used in the pattern and binding
0 through 9Denote literal ascii codes
white spacesDelimit keynames and otherwise ignored


As an example of the capabilities of 4MAP, a keymap definition
file is included. It defines three modes: command, insert, and edit.
In the following descriptions, '^X' will denote control-X (the keystroke
where the control key is held down while simultaneously hitting 'X').

6.1 Command Mode

At the beginning of each command line editing session, the command map
is used. This mode has very similar key-bindings to the 4DOS specifications,
with a few modifications:

^UDeletes the whole line
^WDeletes the previous word
^DFilename completion
^BFilename completion looping opposite direction to ^D
^KPrevious command line in the history list
^JNext command line in the history list
escChanges to edit mode
insChanges to insert mode

6.2 Insert Mode

In this mode, all inputs are entered onto the command line without
deleting what was originally there. Aside from that, it is very similar
to the command mode:

^UDeletes the whole line
^WDeletes the previous word
^DFilename completion
^BFilename completion looping opposite direction to ^D
escChanges to edit mode
insChanges to command mode

6.3 Edit Mode

In this mode, all keystrokes correspond to commands and are not
considered input to the command line:

aMoves one space to the right and changes to insert mode
bMoves one word back
ddDeletes the whole line
dwDeletes the word to the right of the cursor
f Finds the character to the right corresponding to
the character
hMoves one character to the left
iChanges to insert mode
jNext command line in the history list
kPrevious command line in the history list
lMoves one character to the right
r Changes the character to
wMoves one word forward
xDeletes character
DDeletes the rest of the line
0Goes to the beginning of the line
$Goes to the end of the line
spaceMoves one character to the right
^UDeletes the whole line
^WDeletes the previous word
^DFilename completion
^BFilename completion looping opposite direction to ^D
^KPrevious command line in the history list
^JNext command line in the history list
escChanges to command mode
insChanges to insert mode


This file contains programs that are invoked in mapdef. These
include the following:

f.exeImplements the find character function in edit mode
on.exePrints 'EDIT' on the right upper corner of the screen
off.exeErases 'EDIT' on the right upper corner of the screen
ion.exePrints 'INS' on the right upper corner of the screen
ioff.exeErases 'INS' on the right upper corner of the screen
r.exeImplements the replace character function in edit mode

As it is, these programs must be located in C:\MAP. To move them into
a different directory, mapdef must be modified to incorporate the new path.


Care should be taken if a program is to be bound and launched. In
particular, it is found that launching does not work and may
hang the machine.

To keep the size down, the internal buffer sizes are minimized.
This reduces the size of the resident keymap definitions to a total of
about 550 bytes. (The keymap file can be slightly larger than this but
is roughly proportional.) Mapdef, as it is, takes up a great portion of
the 550 bytes. Also as a consequence of the small buffers, "f.exe" can
only advance at most 16 characters to the right at a time, even though it
may find a matching character farther away.

These limitation and further improvements may occur in future
versions depending on the demand and the author's time.


Here is a list of keynames that 4MAP recognizes with their
corresponding scan code or ascii code:

f10x00 0x3b
f20x00 0x3c
f30x00 0x3d
f40x00 0x3e
f50x00 0x3f
f60x00 0x40
f70x00 0x41
f80x00 0x42
f90x00 0x43
f100x00 0x44
home0x00 0x47
up0x00 0x48
pageup0x00 0x49
left0x00 0x4b
right0x00 0x4d
end0x00 0x4f
down0x00 0x50
pagedown0x00 0x51
ins0x00 0x52
del0x00 0x53
shft_f10x00 0x54
shft_f20x00 0x55
shft_f30x00 0x56
shft_f40x00 0x57
shft_f50x00 0x58
shft_f60x00 0x59
shft_f70x00 0x5a
shft_f80x00 0x5b
shft_f90x00 0x5c
shft_f100x00 0x5d
ctrl_f10x00 0x5e
ctrl_f20x00 0x5f
ctrl_f30x00 0x60
ctrl_f40x00 0x61
ctrl_f50x00 0x62
ctrl_f60x00 0x63
ctrl_f70x00 0x64
ctrl_f80x00 0x65
ctrl_f90x00 0x66
ctrl_f100x00 0x67
alt_f10x00 0x68
alt_f20x00 0x69
alt_f30x00 0x6a
alt_f40x00 0x6b
alt_f50x00 0x6c
alt_f60x00 0x6d
alt_f70x00 0x6e
alt_f80x00 0x6f
alt_f90x00 0x70
alt_f100x00 0x71
ctrl_left0x00 0x73
ctrl_right0x00 0x74
ctrl_end0x00 0x75
ctrl_pagedown0x00 0x76
ctrl_home0x00 0x77
ctrl_pageup0x00 0x84

 December 9, 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>