home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / old / ckermit60 / ckcplm.doc < prev    next >
Text File  |  2020-01-01  |  76KB  |  1,731 lines

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