home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / ckc190.zip / ckcplm.doc < prev    next >
Text File  |  1994-10-06  |  69KB  |  1,580 lines

  1. CKAPLM.DOC                                                         October 1994
  2.  
  3.             C-KERMIT PROGRAM LOGIC MANUAL
  4.  
  5. As of C-Kermit version:  5A(190)
  6. This file last updated:  October 4, 1994
  7. Author: F. da Cruz, Columbia University
  8. E-Mail: fdc@columbia.edu
  9.   
  10.   Copyright (C) 1985, 1994, Trustees of Columbia University in the City of New
  11.   York.  The C-Kermit software may not be, in whole or in part, licensed or
  12.   sold for profit as a software product itself, nor may it be included in or
  13.   distributed with commercial products or otherwise distributed by commercial
  14.   concerns to their clients or customers without written permission of the
  15.   Office of Kermit Development and Distribution, Columbia University.  This
  16.   copyright notice must not be removed, altered, or obscured.
  17.  
  18. DOCUMENTATION
  19.  
  20. C-Kermit 5A is documented in the book "Using C-Kermit" by Frank da Cruz and
  21. Christine M. Gianone, Digital Press / Butterworth-Heinemann, Woburn, MA, USA.
  22. Price: US $34.95.  The Kermit file transfer protocol is specified in the book
  23. "Kermit, A File Transfer Protocol" by Frank da Cruz, Digital Press.  Price: US
  24. $29.95.  To order, call Columbia University at +1 212 854-3703.
  25.  
  26.  
  27. INTRODUCTION
  28.  
  29. This is an attempt at describing the relationship among the modules and
  30. functions of C-Kermit version 5A.  Before reading this file, please read the
  31. file CKAAAA.HLP for an overview of C-Kermit file naming conventions.
  32.  
  33. C-Kermit is designed to be portable to any kind of computer that has a C
  34. compiler.  The source code is broken into many files that are grouped
  35. according to their function.  There are several major groups: 1 (the protocol
  36. kernel), 2 (the user interface), 3 (system-dependent primitives), 4 (network
  37. support), and 5 (formatted screen support).
  38.  
  39. FILES
  40.  
  41. C-Kermit source files begin with the two letters CK (lowercase on UNIX
  42. systems, uppercase on most others).  The third character denotes something
  43. about the function group and the expected level of portability.  See the file
  44. CKAAAA.HLP for details of file naming conventions and organization.
  45.  
  46. One hint before proceeding: functions are scattered all over the ckc*.c
  47. and ckuu*.c modules, where function size has begun to take precedence over
  48. the desirability of grouping related functions together, the aim being to
  49. keep any particular module from growing disproportionately large.  The easiest
  50. way (in UNIX) to find out what source file a given function is defined in is
  51. like this (where the desired function is foo()...):
  52.  
  53.   grep ^foo ck*.c
  54.  
  55. This works because the coding convention has been to make function names
  56. always start on the left margin, for example:
  57.  
  58. static char *
  59. foo(x,y) int x, y; {
  60.   ...
  61. }
  62.  
  63. Also please note the style for bracket placement.  This allows
  64. bracket-matching text editors (such as EMACS) to help you make sure you
  65. which opening bracket a closing bracket matches, particularly when it is
  66. no longer visible on the screen.
  67.  
  68.  
  69. SOURCE CODE PORTABILITY GUIDE
  70.  
  71. When writing code for the system-indendent C-Kermit modules, please stick to
  72. the following coding conventions to ensure portability to small or old C
  73. compilers and linkers, as well as certain network and/or email transports:
  74.  
  75. . All lines must no more than 79 characters wide after tab expansion, and
  76.   tabs should be assumed every 8 spaces.
  77. . Keep variable, function, and symbol names unique within 6 characters.
  78. . Don't use the #if preprocessor construction, only use #ifdef and #ifndef.
  79. . Put tokens after #endif in comment brackets, e.g. #endif /* FOO */.
  80. . Don't indent preprocessor statements - # must always be first char on line.
  81. . Don't put whitespace after # in preprocessor commands.
  82. . Don't use logical operators in preprocessor constructions.
  83. . Always cast strlen() to int, e.g. "if ((int)strlen(foo) < x)...".
  84. . Any variable whose value might exceed 16383 should be declared as long,
  85.   or if that is not possible, then as unsigned.
  86. . Avoid the construction *++p -- the order of evaluation varies.
  87. . Reportedly, some compilers even mess up with *(++p).
  88. . Structure members may not have the same names as other identifiers.
  89. . Avoid huge switch() statements with many case:s.
  90. . Don't make character-string constants longer than about 250.
  91. . Don't depend on '\r' being carriage return.
  92. . Don't depend on '\n' being linefeed.
  93. . Don't depend on '\r' and '\n' being different (e.g. in switch() statements).
  94. . Signals should always be re-armed to be used again.
  95. . If you are not absolutely sure that code is totally portable, put it
  96.   in #ifdef..#endif.
  97.  
  98. Assume nothing!  Don't assume header files are where they are supposed to be,
  99. that they contain what you think they contain, that the define specific
  100. symbols to have certain values -- or define them at all!  Don't assume that
  101. particular system or library calls are available, or that the arguments are
  102. what you think they are -- order, data type, passed by reference vs value, etc.
  103. Be very conservative when attempting to write portable code.
  104.  
  105. Feel free to violate any or all of these rules in system-specific modules for
  106. environments in which the rules are certain not to apply.  For example, in
  107. VMS-specific code, it is OK to use #if.
  108.  
  109. (many, many more...  This section needs massive filling in.)
  110.  
  111. CONTENTS:
  112.  
  113.   GROUP 1    System-independent file transfer protocol
  114.   GROUP 1.5  Character set translation
  115.   GROUP 2    User Interface
  116.   GROUP 3    File & communications i/o and other system dependencies
  117.   GROUP 4    Network support
  118.   GROUP 5    Formatted screen support
  119.  
  120. GROUP 1:
  121.  
  122. The Kermit protocol kernel.  The filenames start with CKC.  C means that these
  123. files are supposed to be totally portable C, and are expected to compile
  124. correctly on any operating system.  "Portable" does not mean the same as as
  125. "ANSI" -- these modules must compile on 10- and 15-year old computers, with C
  126. preprocessors, compilers, and/or linkers that have all sorts of restrictions.
  127. The group 1 modules do not include any header files other than those that
  128. come with Kermit itself.  They do not contain any library calls (like printf)
  129. or any system calls (like open, close, read, write).  Files:
  130.  
  131.   CKCSYM.H - For use by C compilers that don't allow -D on the command line.
  132.   CKCASC.H - ASCII character symbol definitions.
  133.   CKCDEB.H - Originally, debugging definitions.  Now this file also contains
  134.          all compiler-dependent definitions (such as typedefs) that must
  135.          be shared by all modules in all groups.
  136.   CKCKER.H - Kermit protocol symbol definitions.
  137.   CKCNET.H - Network-related symbol definitions.
  138.   CKCXLA.H - Character-set-related symbol definitions.
  139.  
  140.   CKCMAI.C - The main program.  This module contains the declarations of all
  141.   the protocol-related global variables that are shared among the other
  142.   modules.  If you want to imbed Kermit protocol within another program,
  143.   you'll have to copy the declarations from ckcmai.c into your program.
  144.  
  145.   CKCPRO.W - The protocol module itself, written in "wart", a lex-like
  146.   preprocessor that is distributed with Kermit under the name CKWART.C.
  147.  
  148.   CKCFN*.C - The protocol support functions used by the protocol module.
  149.  
  150. Group 1 modules may call upon functions from Group 3 modules, but not from
  151. Group 2 modules (with the single exception that the main program invokes the
  152. user interface, which is in Group 2).  (This last assertion is really only a
  153. conjecture.)
  154.  
  155. GROUP 1.5
  156.  
  157. Character set translation tables and functions.  Used by the Group I protocol
  158. modules, but may be specific to different computers.  (So far, all character
  159. character sets supported by C-Kermit are supported in CKUXLA.C and CKUXLA.H,
  160. including Macintosh and IBM character sets).  These modules should be
  161. completely portable, and not rely on any kind of system or library services.
  162.  
  163.   CKCXLA.H - Character-set definitions usable by all versions of C-Kermit.
  164.   CK?XLA.H - Character-set definitions for computer "?", e.g. U for UNIX.
  165.  
  166.   CK?XLA.C - Character-set translation tables and functions for computer "?",
  167.   For example, CKUXLA.C for UNIX, CKMXLA.C for Macintosh.  So far, these are
  168.   the only two such modules.  The UNIX module is used for all versions of
  169.   C-Kermit except the Macintosh version.
  170.  
  171.   Used for file transfer (SEND, RECEIVE, GET, REMOTE, etc), TRANSMIT,
  172.   CONNECT, etc.
  173.  
  174.   Here's how to add a new file character set.  Assuming it is based on the
  175.   Roman (Latin) alphabet.  Let's call it "Barbarian".  First, in CK?XLA.H,
  176.   add a definition for FC_BARBA (8 chars maximum length) and increase
  177.   MAXFCSETS by 1.  Then, in CK?XLA.C:
  178.  
  179.   . Add a barbarian entry into the fcsinfo array.
  180.   . Add a "barbarian" entry to file character set keyword table, fcstab.
  181.   . Add a "barbarian" entry to terminal character set keyword table, ttcstab.
  182.   . Add a translation table from Latin-1 to barbarian: yl1ba[].
  183.   . Add a translation table from barbarian to Latin-1: ybal1[].
  184.   . Add a translation function from Barbarian to ASCII: xbaas().
  185.   . Add a translation function from Barbarian to Latin-1: xbal1().
  186.   . Add a translation function from Latin-1 to Barbarian: xl1ba().
  187.   .  etc etc for each transfer character set...
  188.   . Add translation function pointers to the xls and xlr tables.
  189.  
  190.   Other translations involving Barbarian (e.g. from Barbarian to
  191.   Latin-Cyrillic) are performed through these tables and functions.  See
  192.   CKUXLA.H and CKUXLA.C for extensive examples.
  193.  
  194. GROUP 2:
  195.  
  196. The user interface.  This is the code that communicates with the user, gets
  197. her commands, informs her of the results.  It may be command-line oriented,
  198. interactive prompting dialog, menus and arrow keys, windows and mice, speech
  199. recognition, telepathy, etc.  The user interface has three major functions:
  200.  
  201. 1. Sets the parameters for the file transfer and then start it.  This is done
  202. by setting certain (many) global variables, such as the protocol machine start
  203. state, the file specification, file type, communication parameters, packet
  204. length, window size, character set, etc.
  205.  
  206. 2. Displays messages on the user's screen during the file transfer, using the
  207. screen() function, which is called by the group-1 modules.
  208.  
  209. 3. Executes any commands directly that do not require Kermit protocol, such
  210. as the CONNECT command, local file management commands, parameter-setting
  211. commands, etc.
  212.  
  213. If you plan to imbed the Group 1 files into a program with a different user
  214. interface, your interface must supply an appropriate screen() function, plus a
  215. couple related ones like chkint() and intmsg() for handling keyboard (or
  216. mouse, etc) interruptions during file transfer.  The best way to find out
  217. about this is to link all the C-Kermit modules together except the CKUU*.O
  218. and CKUCON.O modules, and see which missing symbols turn up.
  219.  
  220. C-Kermit's character-oriented user interface (as opposed to the Macintosh
  221. version's graphical user interface) consists of the following modules.
  222. C-Kermit can be built with an interactive command parser, a
  223. command-line-option-only parser, or (most commonly) both, and it can even
  224. be built with neither one (in which case it runs only as a remote-mode
  225. Kermit server).
  226.  
  227.   CKUUSR.H - Definitions of symbols used in Kermit's commands.
  228.  
  229.   CKUUSR.H, CKUUSR.C, CKUUS2.C, CKUUS3.C, CKUUS4.C, CKUUS5.C, ... -
  230.   Kermit's interactivbe command parser, including the script programming
  231.   language.
  232.  
  233.   CKUUSY.C - The command-line-option parser.
  234.  
  235.   CKUUSX.C - Functions that are common to both the interactive and 
  236.   command-line parsers.
  237.  
  238.   CKUCMD.H, CKUCMD.C - The command parsing primitives used by the
  239.   interactive command parser to parse keywords, numbers, filenames, etc,
  240.   and to give help, complete fields, supply defaults, allow abbreviations
  241.   and editing, etc.  This package is totally independent of Kermit, but
  242.   does depend on the Group 3 functions.
  243.  
  244.   CKUVER.H - Version heralds for different implementations.
  245.  
  246.   CKUSCR.C - The (old, uucp-like) SCRIPT command.
  247.   CKUDIA.C - The DIAL command.  Includes specific knowledge of many
  248.              types of modems.
  249.  
  250.   CK?CON.C - The CONNECT command.  Terminal connection, and in some cases
  251.              (Macintosh, OS/2) also terminal emulation.
  252.  
  253. For other implementations, the files may, and probably do, have different
  254. names.  For example, the Macintosh graphical user interface filenames start
  255. with CKM.  OS/2 uses the CKUCMD and CKUUS* modules, but has its own CONNECT
  256. command in CKOCON.C.  And so on.
  257.  
  258. Here is a brief description of C-Kermit's "user interface interface", from 
  259. CKUUSR.C.  It is nowhere near complete; in particular, hundreds of global
  260. variables are shared among the many modules.  These should, some day, be
  261. collected into classes or structures that can be passed around as needed;
  262. not only for purity's sake, but also to allow for multiple simultaneous
  263. communication sessions.
  264.  
  265. The ckuus*.c modules depend on the existence of C library features like fopen,
  266. fgets, feof, (f)printf, argv/argc, etc.  Other functions that are likely to
  267. vary among operating systems -- like setting terminal modes or interrupts --
  268. are invoked via calls to functions that are defined in the system-dependent
  269. modules, ck?[ft]io.c.  The command line parser processes any arguments found
  270. on the command line, as passed to main() via argv/argc.  The interactive
  271. parser uses the facilities of the cmd package (developed for this program, but
  272. usable by any program).  Any command parser may be substituted for this one.
  273. The only requirements for the Kermit command parser are these:
  274.  
  275. 1. Set parameters via global variables like duplex, speed, ttname, etc.  See
  276.    ckcmai.c for the declarations and descriptions of these variables.
  277.  
  278. 2. If a command can be executed without the use of Kermit protocol, then
  279.    execute the command directly and set the variable sstate to 0.  Examples
  280.    include 'set' commands, local directory listings, the 'connect' command.
  281.  
  282. 3. If a command requires the Kermit protocol, set the following variables:
  283.  
  284.    sstate                             string data
  285.      'x' (enter server mode)            (none)
  286.      'r' (send a 'get' command)         cmarg, cmarg2
  287.      'v' (enter receive mode)           cmarg2
  288.      'g' (send a generic command)       cmarg
  289.      's' (send files)                   nfils, cmarg & cmarg2 OR cmlist
  290.      'c' (send a remote host command)   cmarg
  291.  
  292.    cmlist is an array of pointers to strings.
  293.    cmarg, cmarg2 are pointers to strings.
  294.    nfils is an integer.
  295.  
  296.    cmarg can be a filename string (possibly wild), or
  297.       a pointer to a prefabricated generic command string, or
  298.       a pointer to a host command string.
  299.    cmarg2 is the name to send a single file under, or
  300.       the name under which to store an incoming file; must not be wild.
  301.       If it's the name for receiving, a null value means to store the
  302.       file under the name it arrives with.
  303.    cmlist is a list of nonwild filenames, such as passed via argv.
  304.    nfils is an integer, interpreted as follows:
  305.      -1: filespec (possibly wild) in cmarg, must be expanded internally.
  306.       0: send from stdin (standard input).
  307.      >0: number of files to send, from cmlist.
  308.  
  309. The screen() function is used to update the screen during file transfer.
  310. The tlog() function writes to a transaction log (if TLOG is defined).
  311. The debug() function writes to a debugging log (if DEBUG is defined).
  312. The intmsg() and chkint() functions provide the user i/o for interrupting
  313. file transfers.
  314.  
  315. GROUP 3:
  316.  
  317. System-dependent function definitions.  All the Kermit modules, including the
  318. command package, call upon these functions, which are designed to provide
  319. system-independent primitives for controlling and manipulating devices and
  320. files.  For UNIX, these functions are defined in the files CKUFIO.C (files)
  321. and CKUTIO.C (communication devices).  For VMS, the files are CKVFIO.C and
  322. CKVTIO.C.  For OS/2, CKOFIO.C, CKOTIO.C.  It doesn't really matter what the
  323. filenames are, except for Kermit distribution purposes (grouping related files
  324. together alphabetically), only that each function is provided with the name
  325. indicated, observes the same calling and return conventions, and has the same
  326. type.
  327.  
  328. The Group 3 modules contain both functions and global variables that are
  329. accessed by modules in the other groups.  These are now described.  Changes
  330. since version 4E of C-Kermit are flagged by the symbol *NEW* (use grep).
  331.  
  332. (By the way, I got this list by linking all the C-Kermit modules together
  333. except CKUTIO and CKUFIO.  These are the symbols that ld reported as undefined)
  334.  
  335. A. Variables:
  336.  
  337. char *DELCMD;
  338.   Pointer to string containing command for deleting files.
  339.   Example: char *DELCMD = "rm -f ";  (UNIX)
  340.   Example: char *DELCMD = "delete "; (VMS)
  341.   Note trailing space.  Filename is concatenated to end of this string.
  342.  
  343. char *DIRCMD;
  344.   Pointer to string containing command for listing files when a filespec
  345.   is given.
  346.   Example: char *DIRCMD = "/bin/ls -l "; (UNIX)
  347.   Example: char *DIRCMD = "directory ";  (VMS)
  348.   Note trailing space.  Filename is concatenated to end of this string.
  349.  
  350. char *DIRCM2;   *NEW*
  351.   Pointer to string containing command for listing files when a filespec
  352.   is not given.  (currently not used, handled in another way.)
  353.   Example: char *DIRCMD = "/bin/ls -ld *";
  354.   
  355. char *PWDCMD;
  356.   Pointer to string containing command to display current directory.
  357.   Example: char *PWDCMD = "pwd ";
  358.  
  359. char *SPACMD;
  360.   Pointer to command to display free disk space in current device/directory. 
  361.   Example: char *SPACMD = "df .";
  362.  
  363. char *SPACM2;
  364.   Pointer to command to display free disk space in another device/directory. 
  365.   Example: char *SPACM2 = "df ";
  366.   Note trailing space.  Device or directory name is added to this string.
  367.  
  368. char *TYPCMD;
  369.   Pointer to command for displaying the contents of a file.
  370.   Example: char *TYPCMD = "cat ";
  371.   Note trailing space.  Device or directory name is added to this string.
  372.  
  373. char *WHOCMD;
  374.   Pointer to command for displaying logged-in users.
  375.   Example: char *WHOCMD = "who ";
  376.   Note trailing space.  Specific user name may be added to this string.
  377.  
  378. int backgrd = 0;
  379.   Flag for whether program is running in foreground (0) or background
  380.   (nonzero).  Background operation implies that screen output should not be
  381.   done and that all errors should be fatal.
  382.  
  383. int ckxech;
  384.   Flag for who is to echo console typein:  
  385.   1 - The program (system is not echoing).
  386.   0 - The system, front end, terminal, etc (not this program)
  387.  
  388. char *ckxsys;
  389.   Pointer to string that names the computer and operating system.
  390.   Example: char *ckxsys = " NeXT Mach 1.0";
  391.   Tells what computer system ckxv applies to.
  392.   In UNIX Kermit, this variable is also used to print the program herald, 
  393.   and in the SHOW VERSION command.
  394.  
  395. char *ckxv;
  396.   Pointer to version/edit info of ck?tio.c module.
  397.   Example: char *ckxv = "Unix tty I/O, 5A(061), 13 Mar 90";
  398.   Used by SHOW VERSION command.
  399.  
  400. char *ckzsys;
  401.   Like ckxsys, but briefer.
  402.   Example: char *ckzsys = " 4.3 BSD";
  403.   Tells what computer system ckzv applies to.
  404.   Used by the SHOW VERSION command.
  405.  
  406. char *ckzv;
  407.   Pointer to version/edit info of ck?fio.c module.
  408.   Example: char *ckzv = "Unix file support, 5A(041) 27 Mar 90";
  409.   Used by SHOW VERSION command.
  410.  
  411. int dfflow;
  412.   Default flow control.
  413.   0 = none, 1 = Xon/Xoff, ... (see FLO_xxx symbols in ckcdeb.h)
  414.   Set to by group 3 module.
  415.   Used by ckcmai.c to initialize flow control variable.
  416.  
  417. int dfloc;
  418.   Default location.
  419.   0 = remote, 1 = local.
  420.   Set by group 3 module.
  421.   Used by ckcmai.c to initialize local variable.  Used in various places in
  422.   the user interface.
  423.  
  424. int dfprty;
  425.   Default parity.
  426.   0 = none, 'e' = even, 'o' = odd, 'm' = mark, 's' = space.
  427.   Set by Group 3 module.  Used by ckcmai.c to initialize parity variable.
  428.  
  429. char *dftty;
  430.   Default communication device.
  431.   Set by group 3 module.  Used in many places.
  432.   This variable should be initialized the the symbol CTTNAM, which is defined
  433.   in ckcdeb.h, e.g. as "/dev/tty" for UNIX, "TT:" for VAX/VMS, etc.
  434.   Example: char *dftty = CTTNAM;
  435.  
  436. char *mtchs[];  *NEW*
  437.   Array of string pointers to filenames that matched the most recent
  438.   wildcard match, i.e. the most recent call to zxpand().  Used (at least) by
  439.   command parsing package for partial filename completion.
  440.  
  441. int tilde_expand;  *NEW*
  442.   Flag for whether to attempt to expand leading tildes in directory names
  443.   (used in UNIX only, and then only when the symbol DTILDE is defined.
  444.  
  445. int ttnproto;  *NEW*
  446.   The protocol being used to communicate over a network device.  Values are
  447.   defined in ckcnet.h.  Example: NP_TELNET is network protocol "telnet".
  448.  
  449. int maxnam;  *NEW*
  450.   The maximum length for a filename, exclusive of any device or directory
  451.   information, in the format of the host operating system.
  452.  
  453. int maxpath;  *NEW*
  454.   The maximum length for a fully specified filename, including device 
  455.   designator, directory name, network node name, etc, in the format of
  456.   the host operating system, and including all punctuation.
  457.  
  458. int ttyfd;  *NEW*
  459.   File descriptor of the communication device.  -1 if there is no open
  460.   or usable connection, including when C-Kermit is in remote mode.
  461.  
  462. B. Functions.
  463.  
  464. These are divided into three categories: file-related functions (B.1),
  465. communication functions (B.2), and miscellaneous functions (B.3).
  466.  
  467. B.1.  File-related functions.
  468.  
  469. In most implementations, these are collected together into a module called
  470. CK?FIO.c, where ? = U (UNIX), V (VMS), O (OS/2), etc (see CKAAAA.HLP).  To be
  471. totally system-independent, C-Kermit maintains its own file numbers, and
  472. provides the functions described in this section to deal with the files
  473. associated with them.  The file numbers are referred to symbolically, and are
  474. defined as follows in CKCKER.H:
  475.  
  476. #define ZCTERM      0            /* Console terminal */
  477. #define ZSTDIO      1        /* Standard input/output */
  478. #define ZIFILE        2        /* Current input file for SEND command */
  479. #define ZOFILE      3            /* Current output file for RECEIVE command */
  480. #define ZDFILE      4            /* Current debugging log file */
  481. #define ZTFILE      5            /* Current transaction log file */
  482. #define ZPFILE      6            /* Current packet log file */
  483. #define ZSFILE      7        /* Current session log file */
  484. #define ZSYSFN        8        /* Input from a system function (pipe) */
  485. #define ZRFILE      9           /* Local file for READ command */  (NEW)
  486. #define ZWFILE     10           /* Local file for WRITE command */ (NEW)
  487. #define ZNFILS     11            /* How many defined file numbers */
  488.  
  489. In the descriptions below, fn refers to a filename, and n refers to one of
  490. these file numbers.  Functions are of type int unless otherwise noted, and are
  491. listed alphabetically.
  492.  
  493. int
  494. chkfn(n) int n;
  495.   Checks the file number n.  Returns:
  496.   -1: File number n is out of range
  497.    0: n is in range, but file is not open
  498.    1: n in range and file is open
  499.  
  500. int
  501. iswild(filspec) char *filespec; *NEW*
  502.   Checks if the file specification is "wild", i.e. contains metacharacters
  503.   or other notations intended to match multiple filenames.  Returns:
  504.    0: not wild
  505.    1: wild
  506.  
  507. int
  508. isdir(string) char *string; *NEW*
  509.   Checks if the string is the name of an existing directory.  Returns:
  510.    0: not a directory (including any kind of error)
  511.    1: it is an existing directory
  512.   The idea is to check whether the string can be "cd'd" to, so
  513.   in some cases (e.g. OS/2) it might also indicate any file structured
  514.   device, such as a disk drive (like A:).
  515.  
  516. char *
  517. zfcdat(name) char *name; *NEW*
  518.   Returns modification (preferably, otherwise creation) date/time of file
  519.   whose name is given in the argument string.  Return value is a pointer to a
  520.   string of the form yyyymmdd hh:mm:ss, for example 19931231 23:59:59, which
  521.   represents the local time (no timezone or daylight savings time finagling
  522.   required).  Returns the null string ("") on failure.  The text pointed to by
  523.   the string pointer might be in a static buffer, and so should be copied to a
  524.   safe place by the caller before any subsequent calls to this function.
  525.  
  526. int
  527. zfseek(pos) long pos; *NEW*
  528.   Positions the input pointer on the current input file to the given position.
  529.   The pos argument is 0-based, the offset (distance in bytes) from beginning
  530.   of the file.  Needed for RESEND, PSEND, and other recovery operations.  This
  531.   function is not necessarily possible on all systems, e.g. record-oriented
  532.   systems.  It should only be used on binary files (i.e. files we are sending
  533.   in binary mode) and stream-oriented file systems.  Returns -1 on failure, 0
  534.   on success.
  535.  
  536. int
  537. zchdir(dirnam) char *dirnam;
  538.   Change current or default directory to the one given in dirnam.
  539.   Returns 1 on success, 0 on failure.
  540.  
  541. long
  542. zchki(fn) char *fn;
  543.   Check to see if file with name fn is a regular, readable, existing file,
  544.   suitable for Kermit to send -- not a directory, not a symbolic link, etc.
  545.   Returns:
  546.   -3 if file exists but is not accessible (e.g. read-protected)
  547.   -2 if file exists but is not of a readable type
  548.   -1 on error (e.g. file does not exist, or fn is garbage)
  549.   >= 0 (length of file) if file exists and is readable
  550.  
  551. int
  552. zchko(fn) char *fn;
  553.   Checks to see if a file of the given name can be created.  Returns:
  554.   -1 if file cannot be created, or on any kind of error.
  555.    0 if file can be created.
  556.  
  557. int
  558. zchkspa(fn,len) char *f; long len;       *NEW*
  559.   Check to see if there is sufficient space to store the file named fn,
  560.   which is len bytes long.  Returns:
  561.   -1 on error.
  562.    0 if there is not enough space.
  563.    1 if there is enough space.
  564.   If you can't write a function to do this, then just make a dummy that
  565.   always returns 1.  Higher level code will recover from disk-full errors.
  566.   The receiving Kermit uses this function to refuse an incoming file based
  567.   on its size, via the attribute mechanism.
  568.  
  569. int
  570. zchin(n,c) int n; int *c;
  571.   Get a character from file number n, return it in c (call with &c).
  572.   Returns:
  573.   -1 on failure, including EOF.
  574.    0 on success with character in c.
  575.  
  576. int
  577. zchout(n,c) int n; char c;
  578.   Write the character c to file number n.  Returns:
  579.   -1 error
  580.    0 OK
  581.  
  582. int
  583. zclose(n) int n;
  584.   Close file number n.  Returns:
  585.   -1 error
  586.    1 OK
  587.  
  588. int
  589. zdelet(fn) char *name;  *NEW*
  590.   Attempts to delete the named file.  Returns:
  591.   -1 on error
  592.    0 if file was deleted successfully
  593.  
  594. char *
  595. zgtdir()  *NEW*
  596.   Returns a pointer to the name of the current directory, folder, etc, or a
  597.   NULL pointer if the current directory cannot be determined.  Most Kermit
  598.   versions currently do something like "system(PWDCMD)", but Macintoshes don't
  599.   support system().
  600.  
  601. char *
  602. zhome()
  603.   Returns a pointer to a string containing the user's home directory, or NULL
  604.   upon error.
  605.  
  606. int
  607. zinfill()  *NEW*
  608.   This function is used by the macro zminchar(), which is defined in ckcker.h.
  609.   zminchar() manages its own buffer, and calls zinfill() to fill it whenever
  610.   it becomes empty.  It is only used for sending files, and reads characters
  611.   only from file number ZIFILE.  zinfill() returns -1 upon end of file,
  612.   otherwise it returns the first character from the buffer it just read.
  613.  
  614. int
  615. zkself()
  616.   Kills the current job, session, process, etc, logs out, disappears.  Used by
  617.   the Kermit server when it receives a BYE command.  On failure, returns -1.
  618.   On success, does not return at all!  This function should not be called
  619.   until all other steps have been taken to close files, etc.
  620.  
  621. VOID
  622. zstrip(fn,&fn2) char *fn1, **fn2;
  623.   Strip device and directory, etc, from file specification, leaving only the 
  624.   filename.  For example DUA0:[PROGRAMS]OOFA.C;3 becomes OOFA.C, or
  625.   /usr/fdc/oofa.c becomes oofa.c.  Returns pointer to result in fn2.
  626.  
  627. VOID
  628. zltor(fn,fn2) char *fn1, *fn2;
  629.   Local-To-Remote filename translation.  Translates the local filename fn into
  630.   a format suitable for transmission to an arbitrary type of computer, and
  631.   copies the result into the buffer pointed to by fn2.  Translation may involve
  632.   (a) stripping the device and/or directory/path name, (b) converting
  633.   lowercase to uppercase, (c) removing spaces and strange characters, or
  634.   converting them to some innocuous alphabetic character like X, (d)
  635.   discarding or converting extra periods (there should not be more than one).
  636.   Does its best.  Returns no value.  name2 is a pointer to a buffer, furnished
  637.   by the caller, into which zltor() writes the resulting name.  No length
  638.   checking is done.
  639.  
  640. int
  641. zmail(addr,fn) char *addr, fn;  *NEW*
  642.   Send the local, existing file fn as e-mail to the address addr.  Returns:
  643.   Returns 0 on success
  644.    2 if mail delivered but temp file can't be deleted
  645.   -2 if mail can't be delivered
  646.  
  647. int
  648. zmkdir(path) char *path;  *NEW*
  649.   Given a pointer to a file specification that might contain directory
  650.   information, in which the filename is expected to be included,
  651.   this routine attempts to create any directories in the file specification
  652.   that don't already exist.  Returns:
  653.    0 on success: no directories needed creation,
  654.      or else all directories that needed creation were created successfully.
  655.   -1 on failure to create any of the needed directories.
  656.  
  657. VOID
  658. znewn(fn,s) char *fn, **s;
  659.   Transforms the name fn into a filename which is guaranteed to be unique.
  660.   If the file fn does not exist, then the new name will be the same as fn.
  661.   Otherwise, it will be different.  Does its best, returns no value.  New
  662.   name is created in caller's space.  Call like this: znewn(old,&new);.
  663.   The second parameter is a pointer to the new name.  This pointer is set
  664.   by znewn() to point to a static string in its own space.
  665.  
  666. int
  667. znext(fn) char *fn;
  668.   Copies the next file name from a file list created by zxpand() into the
  669.   string pointed to by fn (see zxpand).  If no more files, then the null
  670.   string is placed there.  Returns the number of files remaining in the list.
  671.  
  672. int
  673. zopeni(n,fn) int n; char *fn;
  674.   Opens the file named fn for input as file number n.  Returns:
  675.   0 on failure.
  676.   1 on success.
  677.  
  678. *NEW* (zopeno - the second two parameters are new)
  679. int
  680. zopeno(n,fn,zz,fcb) int n; char *name; struct zattr *zz; struct filinfo *fcb;
  681.   Attempts to open the named file for output as file number n.  zz is a Kermit
  682.   file attribute structure as defined in ckcdeb.h, containing various
  683.   information about the file, including its size, creation date, and so forth.
  684.   This function should attempt to honor as many of these as possible.  fcb is
  685.   a "file control block" in the traditional sense, defined in ckcdeb.h,
  686.   containing information of interest to complicated file systems like VAX/VMS,
  687.   IBM MVS, etc, like blocksize, record length, organization, record format,
  688.   carriage control, disposition (like create vs append), etc.  Returns:
  689.   0 on failure.
  690.   1 on success.
  691.  
  692. int
  693. zoutdump()  *NEW*
  694.   Dumps an output buffer.  Used with the macro zmchout() defined in ckcker.h.
  695.   Used only with file number ZOFILE, i.e. the file that is being received by
  696.   Kermit during file transfer.  Returns:
  697.   -1 on failure.
  698.    0 on success.
  699.  
  700. int
  701. zprint(p,fn) char *p, *f;  *NEW*
  702.   Prints the file with name fn on a local printer, with options p.  Returns:
  703.   Returns 0 on success
  704.    3 if file sent to printer but can't be deleted
  705.   -3 if file can't be printed
  706.  
  707. int
  708. zrename(fn,fn2) char *fn, *fn2;  *NEW*
  709.   Changes the name of file fn to fn2.  If fn2 is the name of an existing
  710.   directory, or a file-structured device, then file fn1 is moved to that
  711.   directory or device, keeping its original name.  Returns:
  712.   -1 on failure.
  713.    0 on success.
  714.  
  715. VOID
  716. zrtol(fn,fn2) char *fn, *fn2;
  717.   Remote-To-Local filename translation.  Translates a "standard" filename
  718.   (see zrtol) to a local filename.  For example, in Unix this function
  719.   converts uppercase letters to lowercase.  Does its best, returns no value.
  720.   New name is in string pointed to by fn2.
  721.  
  722. int
  723. zsattr(xx) struct zattr *xx; {  *NEW*
  724.   Fills in a Kermit file attribute structure for the file which is to be sent,
  725.   namely the currently open ZIFILE.
  726.   Returns:
  727.   -1 on failure.
  728.    0 on success with the structure filled in.
  729.   If any string member is null, then it should be ignored by the caller.
  730.   If any numeric member is -1, then it should be ignored by the caller.
  731.  
  732. int
  733. zshcmd(s) char *s;
  734.   s contains to pointer to a command to be executed by the host computer's
  735.   shell, command parser, or operating system.  If the system allows the user
  736.   to choose from a variety of command processors (shells), then this function
  737.   should employ the user's preferred shell.  If possible, the user's job
  738.   (environment, process, etc) should be set up to catch keyboard interruption
  739.   signals to allow the user to halt the system command and return to Kermit.
  740.   The command must run in ordinary, unprivileged user mode.
  741.   If possible, this function should return -1 on failure to start the command,
  742.   or else it should return 1 if the command succeeded and 0 if it failed.
  743.  
  744. int
  745. zsyscmd(s) char *s;  *NEW*
  746.   s contains to pointer to a command to be executed by the host computer's
  747.   shell, command parser, or operating system.  If the system allows the user
  748.   to choose from a variety of command processors (shells), then this function
  749.   should employ the system standard shell (e.g. /bin/sh for Unix), so that the
  750.   results will always be the same for everybody.  If possible, the user's job
  751.   (environment, process, etc) should be set up to catch keyboard interruption
  752.   signals to allow the user to halt the system command and return to Kermit.
  753.   The command must run in ordinary, unprivileged user mode.
  754.   If possible, this function should return -1 on failure to start the command,
  755.   or else it should return 1 if the command succeeded and 0 if it failed.
  756.  
  757. int
  758. zsinl(n,s,x) int n, x; char *s;  *NEW*
  759.   Reads a line from file number n.
  760.   Writes the line into the address s provided by the caller.
  761.   Writing terminates when newline is read, but with newline discarded.
  762.   Writing also terminates upon EOF or if length x is exhausted.
  763.   Returns:
  764.   -1 on EOF or error.
  765.    0 on success.
  766.  
  767. int
  768. zsout(n,s) int n; char *s;
  769.   Writes the string s out to file number n.  Returns:
  770.   -1 on failure.
  771.    0 on success.
  772.  
  773. int
  774. zsoutl(n,s) int n; char *s;
  775.   Writes the string s out to file number n and adds a line (record) terminator 
  776.   (boundary) appropriate for the system and the file format.
  777.   Returns:
  778.   -1 on failure.
  779.    0 on success.
  780.  
  781. int
  782. zsoutx(n,s,x) int n, x; char *s;
  783.   Writes exactly x characters from string s to file number n.  If s has
  784.   fewer than x characters, then the entire string s is written.  Returns:
  785.   -1 on error.
  786.   >= 0 on success, the number of characters actually written.
  787.  
  788. int
  789. zstime(f,yy,x) char *f; struct zattr *yy; int x;  *NEW*
  790.   Sets the creation date of an existing file, or compares a file's creation
  791.   date with a given date.  Call with:
  792.   f  = pointer to name of existing file.
  793.   yy = pointer to a Kermit file attribute structure in which yy->date.val
  794.        is a date of the form yyyymmdd hh:mm:ss, e.g. 19900208 13:00:00, which
  795.        is to be used for setting the date.
  796.   x  = is a function code: 0 means to set the file's creation date as given.
  797.        1 means compare the given date with the file creation date.      
  798.   Returns:
  799.   -1 on any kind of error.
  800.    0 if x is 0 and the file date was set successfully.
  801.    0 if x is 1 and date from attribute structure > file creation date.
  802.    1 if x is 1 and date from attribute structure <= file creation date.
  803.  
  804. VOID
  805. zstrip(name,name2) char *name, **name2;  *NEW*
  806.   Strips pathname from filename "name".  Constructs the resulting string
  807.   in a static buffer in its own space and returns a pointer to it in name2.
  808.   Also strips device name, file version numbers, and other "non-name" material.
  809.  
  810. *NEW* (zxcmd - arguments are new, writing to a command is new)
  811.  
  812. int
  813. zxcmd(n,s) char *s;
  814.   Runs a system command so its output can be accessed as if it were file n.
  815.   The command is run in ordinary, unprivileged user mode.
  816.   If n is ZSTDIO or ZCTERM, returns -1.
  817.   If n is ZIFILE or ZRFILE, then Kermit reads from the command, otherwise
  818.   Kermit writes to the command.  Returns 0 on error, 1 on success.
  819.  
  820. int
  821. zxpand(fn) char *fn;
  822.   Expands a wildcard string into an array of strings.
  823.   Returns the number of files that match fn1, with data structures set up
  824.   so that first filename (if any) will be returned by the next znext() call.
  825.   If no files match, or if there is any kind of error, zxpand returns 0.
  826.  
  827. int
  828. xsystem(cmd) char *cmd;
  829.   Executes the system command without redirecting any of its i/o, similar
  830.   (well, identical) to system() in Unix.  But before passing the command to
  831.   the system, xsystem() ensures that all privileges are turned off, so that
  832.   the system command will execute in ordinary unprivileged user mode.
  833.  
  834. B.1.5 Security/Privilege Functions (all *NEW*)
  835.  
  836. These functions are used by C-Kermit to adapt itself to operating systems
  837. where the program can be made to run in a "privileged" mode.  C-Kermit
  838. should NOT read and write files or start subprocesses as a privileged program.
  839. This would present a serious threat to system security.  The security package
  840. has been installed to prevent such security breaches by turning off the
  841. program's special privileges at all times except when they are needed.
  842.  
  843. In UNIX, the only need Kermit has for privileged status is access to the UUCP
  844. lockfile directory, in order to read, create, and destroy lockfiles, and to
  845. open communication devices that are normally protected against the user.
  846. Therefore, privileges should only be enabled for these operations and disabled
  847. at all other times.  This relieves the programmer of the responsibility of
  848. putting expensive and unreliable access checks around every file access and
  849. subprocess creation.
  850.  
  851. Strictly speaking, these functions are not required in all C-Kermit
  852. implementations, because their use (so far, at least) is internal to the group
  853. 3 modules.  However, they should be included in all C-Kermit implementations
  854. for operating systems that support the notion of a privileged program (UNIX,
  855. RSTS/E, what else?).
  856.  
  857. int
  858. priv_ini()  *NEW*
  859.   Determine whether the program is running in privileged status.  If so,
  860.   turn off the privileges, in such a way that they can be turned on again
  861.   when needed.  Called from sysinit() at program startup time.  Returns:
  862.     0 on success
  863.     nonzero on failure, in which case the program should halt immediately.
  864.  
  865. int
  866. priv_on()  *NEW*
  867.   If the program is not privileged, this function does nothing.  If the
  868.   program is privileged, this function returns it to privileged status.
  869.   priv_ini() must have been called first.  Returns:
  870.     0 on success
  871.     nonzero on failure
  872.  
  873. int
  874. priv_off()  *NEW*
  875.   Turns privileges off (if they are on) in such a way that they can be
  876.   turned back on again.  Returns:
  877.     0 on success
  878.     nonzero on failure
  879.  
  880. int
  881. priv_can()  *NEW*
  882.   Turns privileges off in such a way that they cannot be turned back on.
  883.   Returns:
  884.     0 on success
  885.     nonzero on failure
  886.  
  887. int
  888. priv_chk()  *NEW*
  889.   Attempts to turns privileges off in such a way that they can be turned on
  890.   again later.  Then checks to make sure that they were really turned off.
  891.   If they were not really turned off, then they are cancelled permanently.
  892.   Returns:
  893.     0 on success
  894.     nonzero on failure
  895.  
  896. B.2.  Console-Related Functions.
  897.  
  898. These relate to the program's "console", or controlling terminal, i.e. the
  899. terminal that the user is logged in on and types commands at, or on a PC or
  900. workstation, the actual keyboard and screen.
  901.  
  902. int
  903. conbin(esc) char esc;
  904.   Puts the console into "binary" mode, so that Kermit's command parser can
  905.   control echoing and other treatment of characters that the user types.
  906.   esc is the character that will be used to get Kermit's attention during
  907.   packet mode; puts this in a global place.  Sets the ckxech variable.
  908.   Returns:
  909.   -1 on error.
  910.    0 on success.
  911.  
  912. int
  913. concb(esc) char esc;
  914.   Put console in "cbreak" (single-character wakeup) mode.  That is, ensure
  915.   that each console character is available to the program immediately when the
  916.   user types it.  Otherwise just like conbin().  Returns:
  917.   -1 on error.
  918.    0 on success.
  919.  
  920. int
  921. conchk()
  922.   Returns a number, 0 or greater, the number of characters waiting to be read
  923.   from the console, i.e. the number of characters that the user has typed that
  924.   have not been read yet.
  925.  
  926. int
  927. congks(timo) int timo;   *NEW*
  928.   Get Keyboard Scancode.  Reads a keyboard scan code from the physical console
  929.   keyboard.  If the timo parameter is greater than zero, then times out and
  930.   returns -2 if no character appears within the given number of seconds.  Upon
  931.   any other kind of error, returns -1.  Upon success returns a scan code,
  932.   which may be any positive integer.  For situations where scan codes cannot
  933.   be read (for example, when an ASCII terminal is used as the job's
  934.   controlling terminal), this function is identical to coninc(), i.e. it
  935.   returns an 8-bit character value.  congks() is for use with workstations
  936.   whose keyboards have Alternate, Command, Option, and similar modifier keys,
  937.   and Function keys that generate codes greater than 255.
  938.  
  939. int
  940. congm()
  941.   Console get modes.  Gets the current console terminal modes and saves them 
  942.   so that conres() can restore them later.  Returns 1 if it got the modes OK,
  943.   0 if it did nothing (e.g. because Kermit is not connected with any terminal),
  944.   -1 on error.
  945.  
  946. int
  947. coninc(timo) int timo;
  948.   Console Input Character.  Reads a character from the console.  If the timo
  949.   parameter is greater than zero, then coninc() times out and returns -2 if no
  950.   character appears within the given number of seconds.  Upon any other kind
  951.   of error, returns -1.  Upon success, returns the character itself, with a
  952.   value in the range 0-255 decimal.
  953.  
  954. VOID
  955. conint(f,s) SIGTYP (*f)(), (*s)();  *NEW*
  956.   Sets the console to generate an interrupt if the user types a keyboard
  957.   interrupt character, and to transfer control the signal-handling function f.
  958.   For systems with job control, s is the address of the function that suspends
  959.   the job.  Sets the global variable "backgrd" to zero if Kermit is running in
  960.   the foreground, and to nonzero if Kermit is running in the background.
  961.   See ckcdeb.h for the definition of SIGTYP.  No return value.
  962.  
  963. VOID
  964. connoi()
  965.   Console no interrupts.  Disable keyboard interrupts on the console.
  966.   No return value.
  967.  
  968. int
  969. conoc(c) char c;
  970.   Write character c to the console terminal.  Returns:
  971.   0 on failure, 1 on success.
  972.  
  973. int
  974. conol(s) char *s;
  975.   Write string s to the console.  Returns -1 on error, 0 or greater on
  976.   success.
  977.  
  978. int
  979. conola(s) char *s[]; {
  980.   Write an array of strings to the console.  Returns -1 on error, 0 or greater
  981.   on success.
  982.  
  983. int
  984. conoll(s) char *s;
  985.   Write string s to the console, followed by the necessary line termination
  986.   characters to put the console cursor at the beginning of the next line.
  987.   Returns -1 on error, 0 or greater on success.
  988.  
  989. int
  990. conres()
  991.   Restore the console terminal to the modes obtained by congm().  Returns:
  992.   -1 on error, 0 on success.
  993.  
  994. int
  995. conxo(x,s) int x; char *s;
  996.   Write x characters from string s to the console.  Returns 0 or greater on
  997.   success, -1 on error.
  998.  
  999. char *
  1000. conkbg();  *NEW*
  1001.   Returns a pointer to the designator of the console keyboard type.
  1002.   For example, on a PC, this function would return "88", "101", etc.
  1003.   Upon failure, returns a pointer to the empty string.
  1004.  
  1005.  
  1006. B.3 - Communication Device Functions
  1007.  
  1008. The communication device is the device used for terminal emulation and file
  1009. transfer.  It may or may not be the same device as the console, and it may
  1010. or may not be a terminal device (it could also be a network device).  For
  1011. brevity, the communication device is referred to here as the "tty".  When the
  1012. communication device is the same as the console device, Kermit is said to be
  1013. in remote mode.  When the two devices are different, Kermit is in local mode.
  1014.  
  1015. int
  1016. ttchk()
  1017.   Returns the number of characters that have arrived at the communication
  1018.   device but have not yet been read by ttinc, ttinl, and friends.  If
  1019.   communication input is buffered (and it should be), this is the sum of the
  1020.   number of unread characters in Kermit's buffer PLUS the number of unread
  1021.   characters in the operating system's internal buffer.
  1022.  
  1023. int
  1024. ttclos()
  1025.   Closes the communication device (tty or network).  If there were any kind of
  1026.   exclusive access locks connected with the tty, these are released.  If the
  1027.   tty has a modem connection, it is hung up.  For true tty devices, the
  1028.   original tty device modes are restored.  Returns:
  1029.   -1 on failure.
  1030.    0 on success.
  1031.  
  1032. int
  1033. ttflui()
  1034.   Flush communications input buffer.  If any characters have arrived but have
  1035.   not yet been read, discard these characters.  If communications input is
  1036.   buffered by Kermit (and it should be), this function flushes Kermit's buffer
  1037.   as well as the operating system's internal input buffer.
  1038.   Returns:
  1039.   -1 on failure.
  1040.    0 on success.
  1041.  
  1042. int
  1043. ttfluo()  *NEW*
  1044.   Flush tty output buffer.  If any characters have been written but not
  1045.   actually transmitted (e.g. because the system has been flow-controlled),
  1046.   remove them from the system's output buffer.  (Note, this function is
  1047.   not actually used, but it is recommended that all C-Kermit programmers
  1048.   add it for future use, even if it is only a dummy function that returns 0
  1049.   always.)
  1050.  
  1051. int
  1052. ttgmdm()  *NEW*
  1053.   Looks for the modem signals CTS, DSR, and CTS, and returns those that are
  1054.   on in as its return value, in a bit mask as described for ttwmdm,
  1055.   in which a bit is on (1) or off (0) according to whether the corresponding
  1056.   signal is on (asserted) or off (not asserted).  Return values:
  1057.   -3 Not implemented
  1058.   -2 if the line does not have modem control
  1059.   -1 on error
  1060.   >= 0 on success, with bit mask containing the modem signals.
  1061.  
  1062. long
  1063. ttgspd()  *NEW*
  1064.   Returns the current tty speed in BITS (not CHARACTERS) per second, or -1
  1065.   if it is not known or if the tty is really a network, or upon any kind of
  1066.   error.  On success, the speed returned is the actual number of bits per
  1067.   second, like 1200, 9600, 19200, etc.
  1068.  
  1069. int
  1070. ttgwsiz()  *NEW*
  1071.   Get terminal window size.  Returns -1 on error, 0 if the window size can't
  1072.   be obtained, 1 if the window size has been successfully obtained.  Upon
  1073.   success, the external global variables tt_rows and tt_cols are set to the
  1074.   number of screen rows and number of screen columns, respectively.
  1075.  
  1076. int
  1077. tthang()
  1078.   Hang up the current tty device.  For real tty devices, turn off DTR for
  1079.   about 1/3-1/2 second (or other length of time, depending on the system).
  1080.   If the tty is really a network connection, close it.  Returns:
  1081.   -1 on failure.
  1082.    0 if it does not even try to hang up.
  1083.    1 if it believes it hung up successfully.
  1084.  
  1085. VOID
  1086. ttimoff()  *NEW*
  1087.   Turns off all pending timer interrupts.
  1088.  
  1089. int
  1090. ttinc(timo) int timo;  *NEW* (function is old, return codes are new)
  1091.   Reads one character from the communication device.  If timo is greater than
  1092.   zero, wait the given number of seconds and then time out if no character
  1093.   arrives, otherwise wait forever for a character.  Returns:
  1094.   -3 internal error (e.g. tty modes set wrong)
  1095.   -2 communications disconnect
  1096.   -1 timeout or other error
  1097.   >= 0 the character that was read.
  1098.   It is HIGHLY RECOMMENDED that ttinc() be internally buffered so that calls
  1099.   to it are relatively inexpensive.  If it is possible to to implement ttinc()
  1100.   as a macro, all the better, for example something like:
  1101.  
  1102.   #define ttinc(t) ( (--txbufn >= 0) ? txbuf[ttbufp++] : txbufr(t) )
  1103.  
  1104.   (see description of txbufr() below)
  1105.  
  1106. *NEW* (ttinl - 5th arg, requirement not to destroy read-ahead characters)
  1107. int
  1108. ttinl(dest,max,timo,eol,start) int max,timo; CHAR *dest, eol, start; 
  1109.   ttinl() is Kermit's packet reader.  Reads a packet from the tty device, or
  1110.   up to max characters, whichever occurs first.  A line is a string of
  1111.   characters starting with the start character up to and including the
  1112.   character given in eol.  If timo is greater than zero, then this function
  1113.   times out if the eol character is not encountered within the given number of
  1114.   seconds.  The characters that were input are copied into "dest" with their
  1115.   parity bits stripped if parity is not none.  The first character copied into
  1116.   dest should be the start character, and the last should be the eol
  1117.   character, followed by a null (0) character.  Returns the number of
  1118.   characters read.  Characters after the eol must be available upon the next
  1119.   call to this function.  (If they are discarded, sliding windows will not
  1120.   work.)  Optionally, ttinl() can sense the parity of incoming packets.  If it
  1121.   does this, then it should set the global variable ttprty accordingly.  This
  1122.   function should be coded to be as efficient as possible, since it is at the
  1123.   "inner loop" of packet reception.  Returns:
  1124.    -1 Timeout or other possibly correctable error.
  1125.    -2 Interrupted from keyboard.
  1126.    -3 Uncorrectable i/o error -- connection lost, configuration problem, etc.
  1127.    >= 0 on success, the number of characters that were actually read
  1128.         and placed in the dest buffer, not counting the trailing null.
  1129.   NOTE: This description is somewhat obsolete.  To implement "Doomsday
  1130.   Kermit", ttinl() (at least for UNIX and VMS) has got its fingers even more
  1131.   deeply into the packet format.  I would like to get rid of this function
  1132.   entirely, and move all packet-related operations to rpack() where they
  1133.   belong.  rpack() would simply call ttinc() to get each character.  But
  1134.   that demands that ttinc() be efficient and fully buffered, going to the
  1135.   operating system with relative infrequency.  See ttinc() and txbufr().
  1136.  
  1137. int
  1138. ttoc(c) char c;
  1139.   Outputs the character c to the communication line.  If the operation fails
  1140.   to complete within two seconds, this function returns -1.  Otherwise it
  1141.   returns the number of characters actually written to the tty (0 or 1).  This
  1142.   function should only be used for interactive, character-mode operations, like
  1143.   terminal connection, script execution, dialer i/o, where the overhead of the
  1144.   signals and alarms does not create a bottleneck.  (THIS DESCRIPTION NEEDS
  1145.   IMPROVEMENT -- If the operation fails within a "certain amount of time"...
  1146.   which might be dependent on the communication method, speed, etc.  In
  1147.   particular, flow-control deadlocks must be accounted for and broken out of
  1148.   to prevent the program from hanging indefinitely, etc.)
  1149.  
  1150. int
  1151. ttol(s,n) int n; char *s;
  1152.   Kermit's packet writer.  Writes the first n characters of the "line" pointed
  1153.   to by s.  NOTE: It is ttol's responsibility to write ALL of the characters,
  1154.   not just some of them.  Returns:
  1155.   -1 on a possibly correctable error (so it can be retried).
  1156.   -3 on a fatal error, e.g. connection lost.
  1157.   >= 0 on success, the actual number of characters written (the specific
  1158.      number is not actually used for anything).
  1159.  
  1160. *NEW* (ttopen - negative value for modem = network, new timeout feature)
  1161. int
  1162. ttopen(ttname,lcl,modem,timo) char *ttname; int *lcl, modem, timo;
  1163.   Opens a tty device, if it is not already open.  ttopen must check to make
  1164.   sure the SAME device is not already open; if it is, ttopen returns 
  1165.   successfully without doing anything.  If a DIFFERENT device is currently
  1166.   open, ttopen() must call ttclos() to close it before opening the new one.
  1167. Parameters:
  1168.     ttname: character string - device name or network host name.
  1169.     lcl:   If called with lcl < 0, sets value of lcl as follows:
  1170.       0: the terminal named by ttname is the job's controlling terminal.
  1171.       1: the terminal named by ttname is not the job's controlling terminal.
  1172.       If the line is already open, or if the requested line can't
  1173.       be opened, then lcl remains (and is returned as) -1.
  1174.     modem:
  1175.       Less than zero: this is the negative of the network type,
  1176.       and ttname is a network host name.  Network types (from ckcnet.h):
  1177.         NET_TCPB 1   TCP/IP Berkeley (socket)  (implemented in ckutio.c)
  1178.         NET_TCPA 2   TCP/IP AT&T (streams)     (not yet implemented)
  1179.         NET_DEC  3   DECnet                    (not yet implemented)
  1180.       Zero or greater: ttname is a terminal device name.    
  1181.       Zero means a direct connection (don't use modem signals).
  1182.       Positive means use modem signals depending on the current setting
  1183.       of ttcarr ( see ttscarr() ).
  1184.     timo:
  1185.       > 0: number of seconds to wait for open() to return before timing out.
  1186.       <=0: no timer, wait forever (e.g. for incoming call).
  1187.     For real tty devices, ttopen() attempts to gain exclusive access to the
  1188.     tty device, for example in UNIX by creating a "lockfile" (in other
  1189.     operating systems, like VMS, exclusive access probably requires no special
  1190.     action).
  1191.   Side effects:
  1192.     Copies its arguments and the tty file descriptor to global variables that
  1193.     are available to the other tty-related functions, with the lcl value
  1194.     altered as described above.   Gets all parameters and settings associated
  1195.     with the line and puts them in a global area, so that they can be restored
  1196.     by ttres(), e.g. when the device is closed.
  1197.   Returns:
  1198.     0 on success
  1199.    -5 if device is in use
  1200.    -4 if access to device is denied
  1201.    -3 if access to lock mechanism denied
  1202.    -2 upon timeout waiting for device to open
  1203.    -1 on other error
  1204.  
  1205. int
  1206. ttpkt(speed,flow,parity) long speed; int flow, parity;
  1207.   Puts the currently open tty device into the appropriate modes for
  1208.   transmitting Kermit packets.  The arguments are interpreted as follows:
  1209.   speed: if speed > -1, and the device is a true tty device, and Kermit is in
  1210.          local mode, ttpkt also sets the speed.
  1211.   flow:  if in the range 0-3, ttpkt selects the corresponding type of flow
  1212.          control.  Currently 0 is defined as no flow control, 1 is Xon/Xoff,
  1213.          and no other types are defined.  If (and this is a horrible hack, but
  1214.          it goes back many years and will be hard to eradicate) flow is 4,
  1215.          then the appropriate tty modes are set for modem dialing, a special
  1216.          case in which we talk to a modem-controlled line without requiring
  1217.          carrier.  If flow is 5, then we require carrier.
  1218.   parity:  This is simply copied into a global variable so that other
  1219.          functions (like ttinl, ttinc, etc) can use it.
  1220.   Side effects: Copies its arguments to global variables, flushes the terminal
  1221.          device input buffer.  
  1222.   Returns:
  1223.    -1 on error.
  1224.     0 on success.
  1225.  
  1226. int
  1227. ttres()
  1228.   Restores the tty device to the modes and settings that were in effect at
  1229.   the time it was opened (see ttopen).  Returns:
  1230.   -1 on error.
  1231.    0 on success.
  1232.  
  1233. int
  1234. ttruncmd(string) char * string; *NEW*
  1235.   Runs the given command on the local system, but redirects its input and
  1236.   output to the communication (SET LINE, SET PORT, or SET HOST) device.
  1237.   Returns 1 on success, 0 on failure.
  1238.  
  1239. int
  1240. ttscarr(carrier) int carrier;  *NEW*
  1241.   Copies its argument to a variable that is global to the other tty-related
  1242.   functions, and then returns it.  The values for carrier are defined in
  1243.   ckcdeb.h: CAR_ON, CAR_OFF, CAR_AUTO.  ttopen(), ttpkt(), and ttvt() use this
  1244.   variable when deciding how to open the tty device and what modes to select.
  1245.   The meanings are these:
  1246.   CAR_OFF:  Ignore carrier at all times.
  1247.   CAR_ON:   Require carrier at all times, except when dialing.
  1248.             This means, for example, that ttopen() could hang forever waiting 
  1249.             for carrier if it is not present.
  1250.   CAR_AUTO: If the modem type is zero (i.e. the connection is direct), this
  1251.             is the same as CAR_OFF.  If the modem type is positive, then heed
  1252.             carrier during CONNECT (ttvt mode), but ignore it at other times
  1253.             (packet mode, during SET LINE, etc).  Compatible with pre-5A
  1254.             versions of C-Kermit.  This should be the default carrier mode.
  1255.   Kermit's DIAL command ignores the carrier setting, but ttopen(), ttvt(), and
  1256.   ttpkt() all honor the carrier option in effect at the time they are called.
  1257.   None of this applies to remote mode (the tty device is the job's controlling
  1258.   terminal) or to network host connections (modem type is negative).
  1259.  
  1260. int
  1261. ttsndb()
  1262.   Send a BREAK signal on the tty device.  On a real tty device, send a real
  1263.   BREAK lasting approximately 275 milliseconds.  If this is not possible,
  1264.   simulate a BREAK by (for example) dropping down some very low baud rate,
  1265.   like 50, and sending a bunch of null characters.  On a network connection,
  1266.   do the appropriate network protocol for BREAK.  Returns:
  1267.   -1 on error.
  1268.    0 on success.
  1269.  
  1270. int
  1271. ttsndlb() *NEW*
  1272.   Like ttsndb(), but sends a "Long BREAK" (approx 1.5 seconds).
  1273.   For network connections, it is identical to ttsndb().
  1274.   Currently, this function is used only if CK_LBRK is defined (as it is
  1275.   for UNIX and VAX/VMS).
  1276.  
  1277. int
  1278. ttsspd(cps) int cps;  *NEW* (argument is now cps instead of bps)
  1279.   For real tty devices only, set the device transmission speed to (note
  1280.   carefully) TEN TIMES the argument.  The argument is in characters per
  1281.   second, but transmission speeds are in bits per second.  cps are used rather
  1282.   than bps because high speeds like 38400 are not expressible in a 16-bit int
  1283.   but longs cannot be used because keyword-table values are ints and not longs.
  1284.   If the argument is 7, then the bps is 75, not 70.  If the argument is 888,
  1285.   this is a special code for 75/1200 split-speed operation (75 bps out, 1200
  1286.   bps in).  Returns:
  1287.   -1 on error, meaning the requested speed is not valid or available.
  1288.   >= 0 on success (don't try to use this value for anything).
  1289.  
  1290. int
  1291. ttvt(speed,flow) long speed; int flow;
  1292.   Puts the currently open tty device into the appropriate modes for terminal
  1293.   emulation.  The arguments are interpreted as in ttpkt().  Side effects:
  1294.   ttvt() stores its arguments in global variables, and sets a flag that it has
  1295.   been called so that subsequent calls can be ignored so long as the arguments
  1296.   are the same as in the last effective call.  Other functions, such as
  1297.   ttopen(), ttclose(), ttres(), ttvt(), etc, that change the tty device in any
  1298.   way must unset this flag.  In UNIX Kermit, this flag is called tvtflg.
  1299.  
  1300. int
  1301. ttwmdm(mdmsig,timo) int mdmsig, timo;  *NEW*
  1302.   Waits up to timo seconds for all of the given modem signals to appear.
  1303.   mdmsig is a bit mask, in which a bit is on (1) or off (0) according to
  1304.   whether the corresponding signal is to be waited for.  These symbols are
  1305.   defined in ckcdeb.h:
  1306.      BM_CTS (bit 0) means wait for Clear To Send 
  1307.      BM_DSR (bit 1) means wait for Data Set Ready
  1308.      BM_DCD (bit 2) means wait for Carrier Detect
  1309.   Returns:
  1310.     -3 Not implemented.
  1311.     -2 This line does not have modem control.
  1312.     -1 Timeout: time limit exceeded before all signals were detected.
  1313.      1 Success.
  1314.  
  1315. int
  1316. ttxin(n,buf) int n; CHAR *buf;
  1317.   (note: CHAR is used throughout this program, and should be typedef'd to
  1318.   unsigned char if your C compiler supports it.  See ckcdeb.h.)
  1319.   Read x characters from the tty device into the specified buf, stripping
  1320.   parity if parity is not none.  This call waits forever, there is no timeout.
  1321.   This function is designed to be called only when you know that at least x
  1322.   characters are waiting to be read (as determined, for example, by ttchk()). 
  1323.   This function should use the same buffer as ttinc().
  1324.  
  1325. int
  1326. txbufr(timo) int timo; *NEW*
  1327.   Read characters into the interal communications input buffer.  timo is a
  1328.   timeout interval, in seconds.  0 means no timeout, wait forever.  Called by
  1329.   ttinc() (and possibly ttxin() and ttinl()) when the communications input
  1330.   buffer is empty.  The buffer should be called ttxbuf[], its length is
  1331.   defined by the symbol TXBUFL.  The global variable txbufn is the number of
  1332.   characters available to be read from ttxbuf[], and txbufp is the index of
  1333.   the next character to be read.  Should not be called if txbufn > 0, in which
  1334.   case the buffer does not need refilling.  This routine returns:
  1335.    -2    Communications disconnect
  1336.    -1    Timeout
  1337.    >= 0  A character (0 - 255), the first character that was read, with
  1338.          the variables txbufn and txbufp set appropriately for any remaining
  1339.          characters.
  1340.   NOTE: Currently this routine is used internally only by the UNIX and VMS
  1341.   versions.  The aim is to make it available to all versions so there is one
  1342.   single coherent and efficient way of reading from the communications device
  1343.   or network.
  1344.  
  1345. B.4 - Miscellaneous system-dependent functions.
  1346.  
  1347. VOID
  1348. ztime(s) char **s;
  1349.   Write the date/time string for the current date and time into the string
  1350.   pointed to by s.  This string should be in the fixed-field format associated
  1351.   with the C language "asctime()" function, like: "Sun Sep 16 13:23:45 1973\n"
  1352.   so that callers of this function can extract the different fields.
  1353.   ztime() has no return value.
  1354.     
  1355. int
  1356. gtimer()
  1357.   Returns the current value of the elapsed time counter in seconds (see
  1358.   rtimer), or 0 on any kind of error.
  1359.  
  1360. int
  1361. msleep(m) int m;
  1362.   Sleeps (pauses, does nothing) for m milliseconds (a millisecond is one
  1363.   thousandth of a second).  Returns:
  1364.   -1 on failure.
  1365.    0 on success.
  1366.  
  1367. VOID
  1368. rtimer()
  1369.   Sets the elapsed time counter to zero.  If you want to time how long an
  1370.   operation takes, call rtimer() when it starts and gtimer when it ends.
  1371.   rtimer() has no return value.
  1372.  
  1373. int
  1374. sysinit()
  1375.   Does whatever needs doing upon program start.  In particular, if the
  1376.   program is running in any kind of privileged mode, turns off the privileges
  1377.   (see priv_ini()).  Returns:
  1378.   -1 on error.
  1379.    0 on success.
  1380.  
  1381. int
  1382. syscleanup()
  1383.   Does whatever needs doing upon program exit.  Returns:
  1384.   -1 on error.
  1385.    0 on success.
  1386.  
  1387. int
  1388. psuspend()   *NEW*
  1389.   Suspends the Kermit process, puts it in the background so it can be
  1390.   continued ("foregrounded") later.  Returns:
  1391.   -1 if this function is not supported.
  1392.    0 on success.
  1393.  
  1394. GROUP 4 - Network Support.
  1395.  
  1396. As of version 5A, C-Kermit includes support for several networks.  Originally,
  1397. this was just worked into the ttopen(), ttclos(), ttinc(), ttinl(), and
  1398. similar routines in CKUTIO.C.  However, this made it impossible to share this
  1399. code with non-UNIX versions, like VMS.
  1400.  
  1401. As of edit 168, this support has been separated out into its own module and
  1402. header file, CKCNET.C and CKCNET.H.  The routines and variables in this module
  1403. fall into two categories: (1) support for specific network packages like
  1404. SunLink X.25 and TGV MultiNet, and (2) support for specific network virtual
  1405. terminal protocols like CCITT X.3 and TCP/IP telnet.  Category (1) functions
  1406. are analogs to the tt*() functions, and have names like netopen, netclos,
  1407. nettinc, etc.  Group I and II modules do not (and must not) know anything
  1408. about these functions -- they continue to call the old Group III functions
  1409. (ttopen, ttinc, etc).  Category (2) functions are protocol specific and have
  1410. names prefixed by a protocol identifier, like tn for telnet x25 for X.25.
  1411.  
  1412. CKCNET.H contains prototypes for all these functions, as well as symbol
  1413. definitions for network types, protocols, and network- and protocol- specific
  1414. symbols, as well as #includes for the header files necessary for each network
  1415. and protocol.
  1416.  
  1417. The following functions are to be provided for networks that do not use normal
  1418. system i/o (open, read, write, close):
  1419.  
  1420. int
  1421. netopen()
  1422.   To be called from within ttopen() when a network connection is requested.
  1423.   Calling conventions and purpose same as Group III ttopen().
  1424.  
  1425. int
  1426. netclos()
  1427.   To be called from within ttclos() when a network connection is being closed.
  1428.   Calling conventions and purpose same as Group III ttclos().
  1429.  
  1430. int
  1431. nettchk()
  1432.   To be called from within ttchk().
  1433.   Calling conventions and purpose same as Group III ttchk().
  1434.  
  1435. int
  1436. netflui()
  1437.   To be called from within ttflui().
  1438.   Calling conventions and purpose same as Group III ttflui().
  1439.  
  1440. int
  1441. netbreak()
  1442.   To send a network break (attention) signal.
  1443.   Calling conventions and purpose same as Group III ttsndbrk().
  1444.  
  1445. int
  1446. netinc()
  1447.   To get a character from the network.
  1448.   Calling conventions same as Group III ttsndbrk().
  1449.  
  1450. int
  1451. nettoc()
  1452.   Send a "character" (byte) to the network.
  1453.   Calling conventions same as Group III ttoc().
  1454.  
  1455. int
  1456. nettol()
  1457.   Send a "line" (sequence of bytes) to the network.
  1458.   Calling conventions same as Group III ttol().
  1459.  
  1460. Conceivably, some systems support network connections simply by letting
  1461. you open a device of a certain name and letting you do i/o to it.  Others
  1462. (like the Berkeley sockets TCP/IP library on UNIX) require you to open the
  1463. connection in a special way, but then do normal i/o (read, write).  In such
  1464. a case, you would use netopen(), but you would not use nettinc, nettoc, etc.
  1465.  
  1466. TGV MultiNET on VAX/VMS has its own set of functions for all network
  1467. operations, so in that case the full range of netxxx() functions is used.
  1468.  
  1469. The technique is to put a test in each corresponding ttxxx() function to
  1470. see if a network connection is active (or is being requested), test for which
  1471. kind of network it is, and if necessary route the call to the corresponding
  1472. netxxx() function.  The netxxx() function must also contain code to test for
  1473. the network type, which is available via the global variable ttnet.
  1474.  
  1475. TELNET SUPPORT:
  1476.  
  1477. The telnet protocol is supported by the following variables and routines:
  1478.  
  1479. (global) int tn_init: nonzero if telnet protocol initialized, zero otherwise.
  1480.  
  1481. int
  1482. tn_init()
  1483.   Initialize the telnet protocol (send initial options).
  1484.  
  1485. int
  1486. tn_sopt()
  1487.   Send a telnet option.
  1488.  
  1489. int
  1490. tn_doop()
  1491.   Receive and act on a telnet option from the remote.
  1492.  
  1493. int
  1494. tn_sttyp()
  1495.   Send terminal type using telnet protocol.
  1496.  
  1497. X.25 SUPPORT:
  1498.  
  1499. These are presently specific to SunLink X.25, but it is hoped that they can
  1500. be integrated better with the functions above, and made more general so they
  1501. could be used, for instance, with VAX PSI.
  1502.  
  1503. x25diag()
  1504.   Read and print X.25 diagnostic
  1505.  
  1506. x25oobh()
  1507.   X.25 out of band signal handler
  1508.  
  1509. x25intr()
  1510.   Send X.25 interrupt packet
  1511.  
  1512. x25reset()
  1513.   Reset X.25 virtual circuit
  1514.  
  1515. x25clear()
  1516.   Clear X.25 virtual circuit
  1517.  
  1518. x25stat()
  1519.   X.25 status
  1520.  
  1521. setqbit()
  1522.   Set X.25 Q-bit
  1523.  
  1524. resetqbit()
  1525.   Reset X.25 Q-bit
  1526.  
  1527. x25xin()
  1528.   Read n characters from X.25 circuit.
  1529.  
  1530. x25inl()
  1531.   Read a Kermit packet from X.25 circuit.
  1532.  
  1533.  
  1534. GROUP 5 - Formatted Screen Support
  1535.  
  1536. So far, this is used only for the fullscreen local-mode file transfer display.
  1537. In the future, it might be extended to other uses.  The fullscreen display
  1538. code is in and around the routine screenc() in ckuusx.c.
  1539.  
  1540. In the UNIX version, we use the curses library, plus one call from the termcap
  1541. library.  In other versions (OS/2, VMS, etc) we insert dummy routines that
  1542. have the same names as curses routines.  So far, there are two methods for
  1543. simulating curses routines:
  1544.  
  1545.  1. In VMS, we use the Screen Management Library (SMG), and insert stubs
  1546.     to convert curses calls into SMG calls.
  1547.  
  1548.  2. In OS/2, we use the MYCURSES code, in which the stub routines
  1549.     actually emit the appropriate escape sequences themselves.
  1550.  
  1551. Here are the stub routines:
  1552.  
  1553. tgetent(char *buf, char *term)
  1554.   Arguments are ignored.  Returns 1 if the user has a supported terminal
  1555.   type, 0 otherwise.  Sets a global variable (for example, "isvt52" or
  1556.   "isdasher") to indicate the terminal type.
  1557.  
  1558. move(int row, int col)
  1559.   Sends the escape sequence to position the cursor at the indicated row
  1560.   and column.  The numbers are 0-based, e.g. the home position is 0,0.
  1561.  
  1562. clear()
  1563.   Sends the escape sequence to clear the screen.
  1564.  
  1565. clrtoeol()
  1566.   Sends the escape sequence to clear from the current cursor position to
  1567.   the end of the line.
  1568.  
  1569. In the MYCURSES case, code must be added to each of the last three routines
  1570. to emit the appropriate escape sequences for a new terminal type.
  1571.  
  1572. clearok(curscr), wrefresh()
  1573.   In real curses, these two calls are required to refresh the screen, for
  1574.   example after it was fractured by a broadcast message.  These are useful
  1575.   only if the underlying screen management service keeps a copy of the entire
  1576.   screen, as curses and SMG do.  C-Kermit does not do this itself.
  1577.  
  1578. (End of CKAPLM.DOC)
  1579.  
  1580.