Kermit Script Portability Reference

Most recent update: 1 September 2001.

This is a beginning at an attempt to delineate the script programming language differences among MS-DOS Kermit, Kermit 95, and C-Kermit. It will be fleshed out over time. The aim is to give you an idea which Kermit script language features can be used in which Kermit programs. Bear in mind that:

Compatibility among the major Kermit programs is always a goal, but sometimes an elusive one given the distributed (over space and time) nature of the Kermit Project. Scripts can be written that are totally portable among the three script-capable versions by avoiding features that are not common to all three, or by having the script test the Kermit program and version that's running it to enable circumlocutions where needed, and by storing system-dependent quantities (like path or device names) in variables rather than hardwiring into the script.

CONTENTS


Portability Features

If a script is to be portable among different Kermit implmentations, versions, and/or platforms, you can use the following constructions to determine the specific environment:

CHECK feature
Fails if the given feature is not included. Features that can be checked in all MS-DOS, C-Kermit, and K-95 versions are: IF (script programming) and NETWORK (ability to make network connections). Example:

set take error on   ; Stop execution of this file on any error.
check if            ; Is script programming included?
set take error off  ; Yes, so we can check errors ourselves

The items that can be checked are listed when you type "check ?". If you try to check an item that does not appear in the list, the check fails.

\v(program)
The value is either C-Kermit or MS-DOS_KERMIT. Note that the value of \v(program) for Kermit 95 is C-Kermit, since C-Kermit and K-95 share the same command language. Example:

if equal \v(program) "MS-DOS_KERMIT" set port tcp \%1
else set host \%1

\v(version)
The Kermit program version number as an integer (no decimal points or other punctuation). For Kermit 95, this is the version number of the underlying C-Kermit program. Example:

define badversion echo MS-DOS Kermit 3.15 required, exit 1
if < \v(version) 315 badversion

C-Kermit \v(version) numbers begin with 501188 (for version 5A(188)). For C-Kermit 7.0.197, \v(version) is 700197, which is bigger than a 16 bit integer. So if you want your version-number comparisons to be safe for 16-bit platforms, use lexical, rather than numeric comparisons:

define badversion echo C-Kermit 7.0 or K95 1.1.19 required, exit 1
if LLT \v(version) 70000 badversion

Finally, note that the version test, complete with error message, can be made in one statement, but only in C-Kermit 7.0 or K95 1.1.19 and later, so this form of the version test is not portable:

if LLT \v(version) 70000 exit 1 C-Kermit 7.0 or K95 1.1.19 required

\v(xprogram)
This one is used for distinguishing between C-Kermit and K95. The values are C-Kermit and K-95. In MS-DOS Kermit, this variable has a null (empty) value. In C-Kermit, the value of \v(xprogram) is the same as that of \v(program).

IF C-KERMIT
IF K-95
These can be used for distinguishing between C-Kermit and K95, but only in K95 1.1.18 and C-Kermit 7.0 and later.

\v(xversion)
Kermit 95 is based on C-Kermit, but has its own series of version numbers: 1.1.3, 1.1.17, 1.1.20, and so on. This variable gives the product-specific (in this case, Kermit 95) version number:

if < \v(version) 1117 exit K95 1.1.17 or later required

In C-Kermit, the value of \v(xversion) is the same as that of \v(version).

\v(system)
The general operating system name, e.g. "WIN32", "UNIX", "VMS".

\v(osname)
C-Kermit and K95 only, shows the specific operating system name, e.g. "Windows 95", "SunOS", "Solaris", "HP-UX", "OpenVMS Alpha", etc.

\v(osrelease)
C-Kermit and K95 only, shows the specific operating system release designation, e.g. "4.00", "4.1.3_U1", "V7.1-1H2", etc.

\v(platform)
This tells the specific platform for which the Kermit program was built, e.g. "IBM-PC", "32-bit_Windows", "Linux", "SunOS_4.1", etc.

\v(name)
C-Kermit and K-95 only. The name of the Kermit program file, e.g. "kermit", "KERMIT.EXE", "K95.EXE".

\v(cpu)
C-Kermit and K-95 only. The CPU type, if known, e.g. "i386", "intel-pentium", "sparc", "alpha", "mips", etc.

\v(model)
C-Kermit and K-95 only. The specific machine model, if known.

IF EMULATION command
Executes the command if the Kermit program includes a true terminal emulator (as do K95 and MS-DOS Kermit, but not C-Kermit).

To display the value of any variable, type:

  show variable name
where name is the variable name (the part inside the parentheses), or:
  echo \v(name)

Use SHOW VARIABLES to list the values of all built-in variables.

If your script is to contain file names, then for maximum portability, use names without paths containing no more than one period, with no more than 8 characters before the period and three after, containing only lowercase ASCII letters and digits, and no spaces. Also note all variables and functions whose values are directory names, such as \v(directory) and \fdirname(), include the terminating directory separator, so you don't have to hard-code it into your scripts:

send \fdirname(\%1)oofa.txt

End-of-line differences among platforms (CRLF versus LF versus CR) can be handled in C-Kermit with \v(newline). MS-DOS Kermit doesn't have this variable, but you can still script portably with:

if equal \v(program) C-Kermit assign eol \v(newline)
else assign eol \13\10

and then use \m(eol) wherever you need a line terminator.

Another useful device is the SWITCH statement, which can be used to select platform-appropriate constructions:

define noport echo Can't open port, exit 1
switch \v(system) {
  :MS-DOS, set port com1, if fail noport, break
  :WIN32, set tapi line,  if fail noport, break
  :UNIX
      switch \v(osname) {
        :Linux, set line /dev/ttyS1,  if fail noport, break
        :HP-UX, set line /dev/cua0p0, if fail noport, break
        :default, set line /dev/cua,  if fail noport, break
      }
  :VMS, set line tta0:, if fail noport, break
  :default, echo System "\v(system)" unexpected, exit 1  
}
; Port is open...


IF Commands

The IF command of C-Kermit and K95 is considerable more evolved than that of MS-DOS Kermit.

Feature                MS-DOS Kermit        K-95     C-Kermit
Extended IF (XIF)            3.15           1.1.0    5A(188)
Numeric conditions           No             1.1.8    6.0 
Consolidated IF and XIF      No             1.1.18   7.0
Boolean Expressions          No             1.1.18   7.0

The following table lists IF conditions. The program version numbers are not necessarily accurate; some of the conditions listed might also be available in earlier program versions, but they are definitely available as of the version numbers listed.

IF Condition           MS-DOS Kermit        K-95     C-Kermit
!                            No             1.1.18   7.0
!=                           No             1.1.18   7.0
&&                           No             1.1.18   7.0
(                            No             1.1.18   7.0
)                            No             1.1.18   7.0
<                            3.00           1.1.0    5A(188)
<=                           No             1.1.18   7.0
=                            3.00           1.1.0    5A(188)
>                            3.00           1.1.0    5A(188)
>=                           No             1.1.18   7.0
||                           No             1.1.18   7.0
absolute                     No             1.1.18   7.0
alarm                        3.00           1.1.0    5A(188)
and                          No             1.1.18   7.0
asktimeout                   No             1.1.18   7.0
available                    No             1.1.18   7.0
background                   No             1.1.18   7.0
c-kermit                     No             1.1.18   7.0
command                      No             1.1.18   7.0
count                        3.00           1.1.0    5A(188)
declared                     No             1.1.18   7.0
defined                      3.00           1.1.0    5A(188)
directory                    No             1.1.18   7.0
emulation                    3.15           1.1.18   7.0
equal                        3.00           1.1.0    5A(188)
exist                        3.00           1.1.0    5A(188)
errorlevel                   3.00           No       No
failure                      3.00           1.1.0    5A(188)
false                        No             1.1.18   7.0
flag                         No             1.1.18   7.0
float                        No             1.1.18   7.0
foreground                   No             1.1.18   7.0
gui                          No             1.1.21   8.0
iksd                         No             1.1.18   7.0
inpath                       3.14           No       No
k-95                         No             1.1.18   7.0
kbhit                        No             1.1.21   8.0
lgt                          3.14           1.1.0    5A(188)
llt                          3.14           1.1.0    5A(188)
local                        No             1.1.18   7.0
match                        No             1.1.18   7.0
newer                        3.14           1.1.?    6.0
not                          3.00           1.1.0    5A(188)
numeric                      3.14           1.1.0    5A(188)
open                         No             1.1.18   7.0
or                           No             1.1.18   7.0
quiet                        No             1.1.18   7.0
readable                     No             1.1.18   7.0
remote-only                  No             1.1.8    6.0
success                      3.00           1.1.0    5A(188)
tapi                         No             1.1.12   7.0
true                         3.15           1.1.8    6.0
version                      No             1.1.8    6.0
wild                         No             1.1.18   7.0
writeable                    No             1.1.18   7.0

In MS-DOS Kermit, IF EXIST filespec command allows wildcard file specifications. Thus "if exist *.txt" succeeds if there are any .txt files. C-Kermit and K-95 have finer-grained distinctions:

IF EXIST filename
Succeeds or fails depending on whether the given (single) file exists.

IF READABLE filename
Succeeds or fails depending on whether the given (single) file exists and is readable.

IF WRITEABLE filename
Succeeds or fails depending on whether the given (single) file can be created or is writeable.

IF WILD filename
Succeeds or fails depending on whether the given file specification contains wildcards, even if it doesn't match any files.

IF DIRECTORY filename
Succeeds or fails depending on whether the given (single) directory exists.

IF ABSOLUTE filename
Succeeds if the given file or directory name is absolute, fails if it is relative or invalid. The file need not exist.

IF \ffiles(filespec)
Succeeds if the given file specification matches one or more regular files. The function returns the number of files that match; 0 is treated as FALSE, nonzero as TRUE.

Besides \ffiles(), there are similar functions \frfiles() (regular files, recursive), \fdirectories() (directory files), \frdirectories() (directory files, recursive). The \f...() functions are supported by MS-DOS Kermit too, so to check portably whether a wildcard matches any existing files, use these functions rather than IF EXIST.


Command-Line Invocation

C-Kermit and K95 have UNIX-like command-line syntax, e.g.:

  kermit -p e -T -s oofa.txt

MS-DOS Kermit accepts ordinary interactive-mode commands on the command line with commands separated by commas, e.g.:

  kermit set parity even, set file type text, send oofa.txt

Thus the command-line syntaxes are incompatible. Nevertheless, C-Kermit and K95 can be given MS-DOS-Kermit-like command lines as the argument of the -C option:

  kermit -C "set parity even, set file type text, send oofa.txt"


Major Language Features

Feature                MS-DOS Kermit        K-95     C-Kermit
TAKE command                1.0             1.1.0      4.0
Macros                      2.26            1.1.0      5A(188)
INPUT                       2.29            1.1.0      5A(188)
GOTO                        2.31            1.1.0      5A(188)
IF                          2.31            1.1.0      5A(188)
Macro parameters            2.31            1.1.0      5A(188)
\%x variables               2.31            1.1.0      5A(188)
\v(xxx) variables           3.10            1.1.0      5A(188)
\m(xxx) variables           3.11            1.1.0      5A(188)
Local file i/o              3.11            1.1.0      5A(188)
\fxxx() functions           3.14            1.1.0      5A(188)
\&a[] Arrays                3.15            1.1.0      5A(188)
Commandline arg array \&@[] ----            1.1.0      5A(188)
Arithmetic                  3.15            1.1.0      5A(188)
FOR, WHILE, XIF             3.16            1.1.0      5A(188)
MINPUT                      3.15            1.1.0      5A(190)
Local scalar variables      3.15            1.1.5      6.0.192
Argument vector array \&_[] 3.15            1.1.5      6.0.192
Block structure             3.16            1.1.5      6.0.192
SWITCH                      3.16            1.1.5      6.0.192
Array initialization        ----            1.1.13     7.0.195
\%* variable                ----            1.1.13     7.0.195
Command switches            ----            1.1.14     7.0.195
Recursive file lists        3.16            1.1.14     7.0.195
Local arrays                ----            1.1.16     7.0.195
More than 9 macro arguments ----            1.1.16     7.0.195
Date conversion             ----            1.1.17     7.0.195
Relative dates              ----            1.1.18     7.0.195
Command-file arguments      ----            1.1.18     7.0.195
Pattern matching            ----            1.1.18     7.0.195
IF/XIF consolidation        ----            1.1.18     7.0.195
Compound booleans           ----            1.1.18     7.0.195
Assignment operators        ----            1.1.18     7.0.195
Kerbang scripts             ----            ------     7.0.195


Keycodes and Key Mapping in MS-DOS Kermit and K-95

DOS and Windows applications must use different methods to access the keyboard and, as a result, the keycodes that are the basis for key mapping in MS-DOS Kermit and Kermit 95 are different. For example, if you type SHOW KEY in MS-DOS Kermit and then press Alt-a, you are told that the Scan Code (keycode) is 2334, whereas in K-95 it is 2145.

Converting a large MS-DOS Kermit key map (i.e. a file containing many SET KEY commands) to Kermit 95 would be a laborious task indeed, if not for the following Kermit 95 commands:

SET MSKERMIT KEYCODES { ON, OFF }
Normally OFF, meaning that K95 should use native keycodes. When ON, keycodes used in SET KEY commands are automatically from MS-DOS Kermit values to K95 values.

SAVE KEYMAP filename
Saves current the current keymap as a series of SET KEY commands in the file whose name is given, with keycodes according to the current MSKERMIT KEYCODES setting.

MS-DOS Kermit and Kermit 95 both support a large repertoire of keyboard verbs ("Kverbs") such as \KdecF10 (meaning, "send what the DEC VT terminal F10 key would send"). A thorough census has not yet been done, but with very few exceptions, Kermit 95 should support every Kverb that MS-DOS Kermit supports. Of course Kermit 95 also supports a great many additional ones, mostly related its many additional terminal emulations.


Built-in variables as of MS-DOS Kermit 3.16, C-Kermit 7.0, K95 1.1.18:

Variable               MS-DOS Kermit        K-95     C-Kermit
\v(argc)                    Yes             Yes        Yes
\v(args)                    No              Yes        Yes
\v(blockcheck)              No              Yes        Yes
\v(browser)                 No              Yes        Yes
\v(browsopts)               No              Yes        Yes
\v(browsurl)                No              Yes        Yes
\v(charset)                 Yes             Yes        Yes
\v(cmdfile)                 Yes             Yes        Yes
\v(cmdlevel)                Yes             Yes        Yes
\v(cmdsource)               No              Yes        Yes
\v(cols)                    No              Yes        Yes
\v(connection)              No              Yes        Yes
\v(console)                 Yes             No         No
\v(count)                   Yes             Yes        Yes
\v(cps)                     Yes             Yes        Yes
\v(cpu)                     No              Yes        Yes
\v(crc16)                   Yes             Yes        Yes
\v(d$ac)                    No              Yes        Yes
\v(d$cc)                    No              Yes        Yes
\v(d$ip)                    No              Yes        Yes
\v(d$lc)                    No              Yes        Yes
\v(d$lp)                    No              Yes        Yes
\v(d$px)                    No              Yes        Yes
\v(date)                    Yes             Yes        Yes
\v(day)                     Yes             Yes        Yes
\v(dialnumber)              No              Yes        Yes
\v(dialresult)              No              Yes        Yes
\v(dialstatus)              No              Yes        Yes
\v(dialsuffix)              No              Yes        Yes
\v(dialtype)                No              Yes        Yes
\v(directory)               Yes             Yes        Yes
\v(disk)                    Yes             No         No
\v(dosversion)              Yes             No         No
\v(download)                No              Yes        Yes
\v(editor)                  No              Yes        Yes
\v(editfile)                No              Yes        Yes
\v(editopts)                No              Yes        Yes
\v(errno)                   No              Yes        Yes
\v(errorlevel)              Yes             No         No
\v(errstring)               No              Yes        Yes
\v(escape)                  No              Yes        Yes
\v(evaluate)                No              Yes        Yes
\v(exitstatus)              No              Yes        Yes
\v(filename)                No              Yes        Yes
\v(filenumber)              No              Yes        Yes
\v(filespec)                Yes             Yes        Yes
\v(fsize)                   Yes             Yes        Yes
\v(ftype)                   No              Yes        Yes
\v(herald)                  No              Yes        Yes
\v(home)                    No              Yes        Yes
\v(host)                    No              Yes        Yes
\v(hwparity)                No              Yes        Yes
\v(input)                   Yes             Yes        Yes
\v(inchar)                  No              Yes        Yes
\v(incount)                 No              Yes        Yes
\v(inidir)                  Yes             Yes        Yes
\v(instatus)                Yes             Yes        Yes
\v(intime)                  No              Yes        Yes
\v(inwait)                  No              Yes        Yes
\v(ipaddress)               No              Yes        Yes
\v(keyboard)                Yes             Yes        No
\v(line)                    Yes             Yes        Yes
\v(local)                   No              Yes        Yes
\v(lockdir)                 No              No         Yes
\v(lockpid)                 No              No         Yes
\v(macro)                   No              Yes        Yes
\v(minput)                  Yes             Yes        Yes
\v(model)                   No              Yes        Yes
\v(modem)                   No              Yes        Yes
\v(monitor)                 Yes             No         No
\v(mousecurx)               No              Yes        No
\v(mousecury)               No              Yes        No
\v(m_aa_off)                No              Yes        Yes
\v(m_aa_on)                 No              Yes        Yes
\v(m_dc_off)                No              Yes        Yes
\v(m_dc_on)                 No              Yes        Yes
\v(m_dial)                  No              Yes        Yes
\v(m_ec_off)                No              Yes        Yes
\v(m_ec_on)                 No              Yes        Yes
\v(m_fc_hw)                 No              Yes        Yes
\v(m_fc_no)                 No              Yes        Yes
\v(m_fc_sw)                 No              Yes        Yes
\v(m_hup)                   No              Yes        Yes
\v(m_init)                  No              Yes        Yes
\v(m_pulse)                 No              Yes        Yes
\v(m_tone)                  No              Yes        Yes
\v(name)                    No              Yes        Yes
\v(ndate)                   Yes             Yes        Yes
\v(nday)                    Yes             Yes        Yes
\v(newline)                 No              Yes        Yes
\v(ntime)                   Yes             Yes        Yes
\v(osname)                  No              Yes        Yes
\v(osrelease)               No              Yes        Yes
\v(osversion)               No              Yes        Yes
\v(packetlen)               No              Yes        Yes
\v(parity)                  No              Yes        Yes
\v(pexitstat)               No              Yes        Yes
\v(pid)                     No              Yes        Yes
\v(platform)                Yes             Yes        Yes
\v(printer)                 No              Yes        Yes
\v(program)                 Yes             Yes        Yes
\v(protocol)                No              Yes        Yes
\v(p_8bit)                  No              Yes        Yes
\v(p_ctl)                   No              Yes        Yes
\v(p_rpt)                   No              Yes        Yes
\v(query)                   Yes             Yes        Yes
\v(return)                  Yes             Yes        Yes
\v(rows)                    No              Yes        Yes
\v(serial)                  No              Yes        Yes
\v(sendlist)                No              Yes        Yes
\v(session)                 Yes             No         No
\v(speed)                   Yes             Yes        Yes
\v(startup)                 Yes             Yes        Yes
\v(status)                  Yes             Yes        Yes
\v(sysid)                   Yes             Yes        Yes
\v(system)                  Yes             Yes        Yes
\v(tcpip_status)            Yes             No         No
\v(terminal)                Yes             Yes        Yes
\v(test)                    No              Yes        Yes
\v(tfsize)                  No              Yes        Yes
\v(tftime)                  No              Yes        Yes
\v(time)                    Yes             Yes        Yes
\v(tmpdir)                  No              Yes        Yes
\v(trigger)                 No              Yes        Yes
\v(ttyfd)                   No              Yes        Yes
\v(userid)                  No              Yes        Yes
\v(version)                 Yes             Yes        Yes
\v(window)                  No              Yes        Yes
\v(xferstatus)              No              Yes        Yes
\v(xfermsg)                 No              Yes        Yes
\v(xprogram)                No              Yes        Yes
\v(xversion)                No              Yes        Yes


Functions in MS-DOS Kermit 3.16, C-Kermit 7.0, K95 1.1.18:

Function               MS-DOS Kermit        K-95     C-Kermit
\Fbasename()                No              Yes        Yes
\Fbreak()                   No              Yes        Yes
\Fcapitalize()              No              Yes        Yes
\Fcharacter()               Yes             Yes        Yes
\Fchecksum()                Yes             Yes        Yes
\Fcode()                    Yes             Yes        Yes
\Fcommand()                 No              Yes        Yes
\Fcontents()                Yes             Yes        Yes
\Fcrc16()                   No              Yes        Yes
\Fcvtdate()                 No              Yes        Yes
\Fdate()                    Yes             Yes        Yes
\Fday()                     No              Yes        Yes
\Fdayofyear()               No              Yes        Yes
\Fdefinition()              Yes             Yes        Yes
\Fdialconvert()             No              Yes        Yes
\Fdimension()               No              Yes        Yes
\Fdirectories()             Yes             Yes        Yes
\Fdirname()                 No              Yes        Yes
\Fdoy2date()                No              Yes        Yes
\Ferrstring()               No              Yes        Yes
\Fevaluate()                Yes             Yes        Yes
\Fexecute()                 No              Yes        Yes
\Ffiles()                   Yes             Yes        Yes
\Fhexify()                  No              Yes        Yes
\Findex()                   Yes             Yes        Yes
\Fipaddress()               No              Yes        Yes
\Flength()                  Yes             Yes        Yes
\Fliteral()                 Yes             Yes        Yes
\Flop()                     No              Yes        Yes
\Flower()                   Yes             Yes        Yes
\Flpad()                    Yes             Yes        Yes
\Fltrim()                   No              Yes        Yes
\Fmaximum()                 Yes             Yes        Yes
\Fminimim()                 Min             Yes        Yes
\Fmjd()                     No              Yes        Yes
\Fmjd2date()                No              Yes        Yes
\Fn2hex()                   No              Yes        Yes
\Fn2octal()                 No              Yes        Yes
\Fn2time()                  No              Yes        Yes
\Fnday()                    No              Yes        Yes
\Fnextfile()                Yes             Yes        Yes
\Fntime()                   No              Yes        Yes
\Fpathname()                No              Yes        Yes
\Fpermissions()             No              Yes        Yes
\Frandom()                  No              Yes        Yes
\Frawcommand()              No              Yes        Yes
\Frdirectories()            Yes             Yes        Yes
\Frfiles()                  Yes             Yes        Yes
\Frepeat()                  Yes             Yes        Yes
\Freplace()                 Yes             Yes        Yes
\Freverse()                 Yes             Yes        Yes
\Fright()                   Yes             Yes        Yes
\Frindex()                  Yes             Yes        Yes
\Frpad()                    Yes             Yes        Yes
\Fscrncurx()                No              Yes        No
\Fscrncury()                No              Yes        No
\Fscrnstr()                 No              Yes        No
\Fsize()                    Yes             Yes        Yes
\Fspan()                    No              Yes        Yes
\Fsplit()                   No              Yes        Yes
\Fstripn()                  No              Yes        Yes
\Fstripx()                  No              Yes        Yes
\Fsubstring()               Yes             Yes        Yes
\Ftime()                    No              Yes        Yes
\Ftrim()                    No              Yes        Yes
\Funhexify()                No              Yes        Yes
\Fupper()                   Yes             Yes        Yes
\Fverify()                  Yes             Yes        Yes
\Fword()                    No              Yes        Yes


Other notable differences between MS-DOS Kermit and C-Kermit/K95:

                                 MS-DOS Kermit          C-Kermit/K95
Direct access to hardware:       Yes                    No
SET NETWORK TYPE command:        No                     Yes
Network connections:             SET PORT net host      SET HOST host
Uses own built-in TCP stack:     Yes                    No
Uses OS TCP/IP stack:            No                     Yes
Built-in TELNET command:         No                     Yes
Built-in modem dialing:          No                     Yes
Multiple connections:            Yes                    No
REINPUT reads from connection:   Yes                    No


Links:


Kermit Script Portability Reference / Columbia University / [email protected] / 1 Sep 2001