home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / ckv197.zip / ckcplm.txt < prev    next >
Text File  |  2000-02-27  |  99KB  |  2,252 lines

  1. CKCPLM.TXT                                                            Feb 2000
  2.  
  3.             C-KERMIT PROGRAM LOGIC MANUAL
  4.  
  5. As of C-Kermit version:  7.0.197
  6. This file last updated:  Tue Feb  8 16:30:55 2000
  7. Author: Frank da Cruz, Columbia University
  8. E-Mail: fdc@columbia.edu
  9.  
  10.   Copyright (C) 1985, 2000,
  11.     Trustees of Columbia University in the City of New York.
  12.     All rights reserved.  See the C-Kermit COPYING.TXT file or the
  13.     copyright text in the ckcmai.c module for disclaimer and permissions.
  14.  
  15.  
  16. INTRODUCTION
  17.  
  18. The Kermit Protocol is specified in the book "Kermit, A File Transfer
  19. Protocol" by Frank da Cruz, Digital Press / Butterworth Heinemann, Newton, MA,
  20. USA (1987), 379 pages, ISBN 0-932376-88-6.  It is assumed the reader is
  21. familiar with the Kermit protocol specification.
  22.  
  23. This file attempts to describe the relationship among the modules and
  24. functions of C-Kermit 5A and later.  Before reading this file, please read the
  25. file CKAAAA.TXT for an overview of C-Kermit file naming conventions.
  26.  
  27. C-Kermit is designed to be portable to any kind of computer that has a C
  28. compiler.  The source code is broken into many files that are grouped
  29. according to their function.  There are several major groups: 1 (the protocol
  30. kernel), 2 (the user interface), 3 (system-dependent primitives), 4 (network
  31. support), and 5 (formatted screen support).
  32.  
  33.  
  34. CONTENTS:
  35.  
  36.   FILES
  37.   SOURCE CODE PORTABILITY GUIDE
  38.  
  39.   GROUP 0    Library functions
  40.   GROUP 1    System-independent file transfer protocol
  41.   GROUP 1.5  Character set translation
  42.   GROUP 2    User Interface
  43.   GROUP 3    File & communications i/o and other system dependencies
  44.   GROUP 4    Network support
  45.   GROUP 5    Formatted screen support
  46.  
  47.   APPENDIX I File Permissions
  48.  
  49. WARNING: C-Kermit 6.1 is probably the last version preserving this
  50. organization and naming.  The next major release after 6.1 will apply some
  51. lessons we have learned about modularity and separation, and allow easier
  52. integration of the code with other applications and/or user interfaces.
  53.  
  54.  
  55. FILES
  56.  
  57. C-Kermit source files begin with the two letters CK (lowercase on UNIX
  58. systems, uppercase on most others).  The third character denotes something
  59. about the function group and the expected level of portability.  See the file
  60. CKAAAA.TXT for details of file naming conventions and organization.
  61.  
  62. One hint before proceeding: functions are scattered all over the ckc*.c
  63. and ckuu*.c modules, where function size has begun to take precedence over
  64. the desirability of grouping related functions together, the aim being to
  65. keep any particular module from growing disproportionately large.  The easiest
  66. way (in UNIX) to find out what source file a given function is defined in is
  67. like this (where the desired function is foo()...):
  68.  
  69.   grep ^foo ck*.c
  70.  
  71. This works because the coding convention has been to make function names
  72. always start on the left margin with their contents indented, for example:
  73.  
  74. static char *
  75. foo(x,y) int x, y; {
  76.     ...
  77. }
  78.  
  79. Also please note the style for bracket placement.  This allows
  80. bracket-matching text editors (such as EMACS) to help you make sure you know
  81. which opening bracket a closing bracket matches, particularly when it is no
  82. longer visible on the screen, and it also makes it easy to find the end of a
  83. function (search for '}' on the right margin).
  84.  
  85. Of course EMACS tags work nicely with this format too:
  86.  
  87.   $ cd <kermit-source-directory>
  88.   $ etags ck[cu]*.[ch]
  89.   $ emacs
  90.   Esc-X Visit-Tags-Table<CR><CR>
  91.  
  92. (but remember that the source file for ckcpro.c is ckcpro.w!)
  93.  
  94.  
  95. SOURCE CODE PORTABILITY GUIDE
  96.  
  97. When writing code for the system-indendent C-Kermit modules, please stick to
  98. the following coding conventions to ensure portability to the widest possible
  99. variety of C preprocessors, compilers, and linkers, as well as certain network
  100. and/or email transports:
  101.  
  102. . Tabs should be set every 8 spaces, as on a VT100.
  103. . All lines must no more than 79 characters wide after tab expansion.
  104. . Note the distinction between physical tabs (ASCII 9) and the indentation
  105.   conventions, which are: 4 for block contents, 2 for most other stuff.
  106. . Try to keep variable and function names unique within 6 characters,
  107.   especially if they are used across modules, since 6 is the maximum for
  108.   some linkers.  (Actually, I think the last system that had this limitation
  109.   was turned off in the 1980s -- remember SIXBIT? -- no now maybe it's 8?)
  110. . Keep preprocessor symbols unique within 8 characters.
  111. . Don't put #include directives inside functions or { blocks }.
  112. . Don't use the #if preprocessor construction, only use #ifdef, #ifndef, #undef
  113. . Put tokens after #endif in comment brackets, e.g. #endif /* FOO */.
  114. . Don't indent preprocessor statements - # must always be first char on line.
  115. . Don't put whitespace after # in preprocessor statements.
  116. . Don't use #pragma, even within #ifdefs - it makes some preprocessors give up.
  117. . Same goes for #module, #if, etc - #ifdefs do NOT protect them.
  118. . Don't use logical operators in preprocessor constructions.
  119. . Avoid #ifdefs inside argument list to function calls.
  120. . Always cast strlen() in expressions to int: "if ((int)strlen(foo) < x)...".
  121. . Any variable whose value might exceed 16383 should be declared as long,
  122.   or if that is not possible, then as unsigned.
  123. . Unsigned long is not portable.
  124. . Don't use initializers with automatic arrays or structs.
  125. . Don't assume that struct assignment performs a copy.
  126. . Don't put prototypes for static functions into header files that are used
  127.   by modules that don't contain that function.
  128. . Avoid the construction *++p -- the order of evaluation varies.
  129. . Reportedly, some compilers even mess up with *(++p).
  130. . Don't use triple assignments, like a = b = c = 0; (or quadruple, etc).
  131.   Some compilers generate bad code for these, or crash, etc.
  132. . Structure members may not have the same names as other identifiers.
  133. . Avoid huge switch() statements with many cases.
  134. . Don't have a switch() statement with no cases (e.g. because of #ifdefs).
  135. . Don't put anything between "switch() {" and case: --   switch blocks are not
  136.   like other blocks.
  137. . Don't make character-string constants longer than about 250.
  138. . Don't write into character-string constants even when you know you are not
  139.   writing past the end because the compiler or linker might have put them into
  140.   read-only and/or shared memory, and/or coalesced multiple equal constants
  141.   so if you change one you change them all.
  142. . Don't depend on '\r' being carriage return.
  143. . Don't depend on '\n' being linefeed or for that matter any SINGLE character.
  144. . Don't depend on '\r' and '\n' being different (e.g. in switch() statements).
  145. . In other words, don't use \n or \r to stand for specific characters;
  146.   use \012 and \015 instead.
  147. . Don't code for "buzzword 1.0 compliance", unless "buzzword" is K&R and
  148.   "1.0" is the first edition.
  149. . Don't use or depend on anything_t (size_t, time_t, etc).
  150. . Don't use or depend on internationalization ("i18n") features, wchar_t,
  151.   locales, etc, in portable code; they are not portable.  Anyway, locales are
  152.   not the right model for Kermit's multi-character-set support.
  153. . Don't make any assumption about signal handler type.  It can be void, int,
  154.   long, or anything else.  Always declare signal handlers as SIGTYP (see
  155.   definition in ckcdeb.h and augment it if necessary) and always use
  156.   SIGRETURN at exit points from signal handlers.
  157. . Signals should always be re-armed to be used again (this barely scratches
  158.   the surface -- the difference between BSD/V7 and System V and POSIX signal
  159.   handling are numerous, and some platforms do not even support signals,
  160.   alarms, or longjmps correctly or at all -- avoid all of this stuff if you
  161.   can).
  162. . Don't call malloc() & friends from a signal handler.
  163. . memset(), memmove(), and memcpy() are not portable, don't use them without
  164.   protecting them in ifdefs.  bzero() too, except we're guaranteed to have
  165.   bzero() when using the sockets library.  See examples in the source.
  166. . Don't assume that strncpy() stops on the first null byte -- some versions
  167.   always copy the number of bytes given in arg 3.  Probably also true of
  168.   other strnblah() functions.
  169. . DID YOU KNOW.. that some versions of inet_blah() routines return IP addresses
  170.   in network byte order, while others return them local machine byte order?
  171.   So passing them to htons(), etc, is not always the right thing to do.
  172. . Don't use ANSI-format function declarations without #ifdef CK_ANSIC,
  173.   and always provide an #else for the non-ANSI case.
  174. . Don't depend on any other ANSI preprocessor features like "pasting" -- they
  175.   are often missing or nonoperational.
  176. . Don't assume any C++ syntax or semantics.
  177. . Don't declare a string as "char foo[]" in one module and "extern char * foo"
  178.   in another, or vice-versa.
  179. . With compiler makers falling all over themselves trying to outdo each other
  180.   in ANSI strictness, it has become increasingly necessary to cast EVERYTHING.
  181. . a[x], where x is an unsigned char, can produce a wild memory reference if x,
  182.   when promoted to an int, becomes negative.  Cast it to (unsigned), even
  183.   though it ALREADY IS unsigned.
  184. . Be careful how you declare functions that have char or long arguments;
  185.   for ANSI compilers you MUST use ANSI declarations to avoid promotion
  186.   problems, but you can't use ANSI declarations with non-ANSI compilers.
  187.   Thus declarations of such functions must be hideously entwined in #ifdefs.
  188.   Example of the latter:
  189.  
  190.   int                   /*  Put character in server command buffer  */
  191.   #ifdef CK_ANSIC
  192.   putsrv(char c)
  193.   #else
  194.   putsrv(c) char c;
  195.   #endif /* CK_ANSIC */
  196.   /* putsrv */ {
  197.       *srvptr++ = c;
  198.       *srvptr = '\0';        /* Make sure buffer is null-terminated */
  199.       return(0);
  200.   }
  201.  
  202. . Be careful how you return characters from functions that return int values --
  203.   "getc-like functions" -- in the ANSI world.  Unless you explicitly cast the
  204.   return value to (unsigned), it is likely to be "promoted" to an int and have
  205.   its sign extended.
  206.  
  207. . Here's a good one.  At least one compiler (the one on DEC OSF/1 1.3) treats
  208.   /* and */ within string constants as comment begin and end.  No amount of
  209.   #ifdefs will get around this one.  You simply can't put an unbalanced
  210.   /* or */ in a string constant, e.g. "/usr/local/doc/*.*".
  211.  
  212. . Avoid putting multiple macro references on a single line, e.g.:
  213.  
  214.     putchar(BS); putchar(SP); putchar(BS)
  215.  
  216.   This will overflow the CPP output buffer of more than a few C preprocessors.
  217.  
  218. (many, many more...  This section needs massive filling in.)
  219.  
  220. C-Kermit needs constant adjustment to new OS and compiler releases.  Every
  221. new release shuffles header files or their contents, or prototypes, or data
  222. types, or levels of ANSI strictness, etc.  Every time you make an adjustment
  223. to remove a new compilation error, BE VERY CAREFUL to #ifdef it on a symbol
  224. unique to the new configuration so that the previous configuration (and all
  225. other configurations on all other platforms) remain as before.
  226.  
  227. Assume nothing.  Don't assume header files are where they are supposed to be,
  228. that they contain what you think they contain, that they define specific
  229. symbols to have certain values -- or define them at all!  Don't assume system
  230. header files protect themselves against multiple inclusion.  Don't assume that
  231. particular system or library calls are available, or that the arguments are
  232. what you think they are -- order, data type, passed by reference vs value,
  233. etc.  Be very conservative when attempting to write portable code.  Avoid all
  234. advanced features.  Stick with K&R First Edition, and even then you're on
  235. shaky ground.
  236.  
  237. If you see something that does not make sense, don't assume it's a mistake --
  238. it is probably there for a reason, and changing it or removing is very likely
  239. to cause compilation, linking, or runtime failures sometime, somewhere.  Some
  240. huge percentage of the code, especially in the system-dependent modules, is
  241. workarounds for compiler, linker, or API bugs.
  242.  
  243. BUT... feel free to violate any or all of these rules in system-specific
  244. modules for environments in which the rules are certain not to apply.  For
  245. example, in VMS-specific code, it is OK to use #if.  But even then, allow for
  246. different compilers or compiler versions used in that same environment,
  247. e.g. VAX C vs DEC C vs GNU C.
  248.  
  249. THE "CHAR" VS "UNSIGNED CHAR" DILEMMA
  250.  
  251. This is one of the most aggravating and vexing things about C.  By default,
  252. chars (and char *'s) are SIGNED.  But in the modern era, we need to process
  253. characters that can have 8-bit values, such as ISO Latin-1, IBM CP 850, and
  254. other 8-bit (or 16-bit, etc) character sets, and so this data MUST be treated
  255. as unsigned.  BUT...  Some C compilers (such as those based on the Bell UNIX
  256. V7 compiler) do not support "unsigned char" as a data type.  Therefore we have
  257. the macro or typedef CHAR, which we use when we need chars to be unsigned, but
  258. which, unfortunately, resolves itself to "char" on those compilers that don't
  259. support "unsigned char".  AND SO...  We have to do a lot of fiddling at
  260. runtime to avoid sign extension and so forth.  BUT THAT'S NOT ALL...  Now some
  261. modern compilers (e.g. IBM, DEC, Microsoft) have switches that say "make all
  262. chars be unsigned" (e.g. GNU cc "-funsigned-char").  We use these switches
  263. when they are available.  Other compilers don't have these, and at the same
  264. time, are becoming increasingly strict about type mismatches, and spew out
  265. torrents of warnings when we use a CHAR where a char is expected, or vice
  266. versa.  We fix these one by one using casts, and the code becomes increasingly
  267. ugly.  But there remains a serious problem, namely that certain library and
  268. kernel functions have arguments that are declared as signed chars (or pointers
  269. to them), whereas our character data is unsigned.  Fine, we can can use casts
  270. here too -- but who knows what happens inside these routines.
  271.  
  272. MODES OF OPERATION
  273.  
  274. When C-Kermit is on the far end of a connection, it is said to be in
  275. remote mode.  When C-Kermit has made a connection to another computer, it
  276. is in local mode.  (If C-Kermit is "in the middle" of a multihop connection,
  277. it is still in local mode.)
  278.  
  279. On another axis, C-Kermit has three major modes of operation:
  280.  
  281. Command Mode
  282.   Reading and writing from the job's controlling terminal or "console".
  283.   In this mode, all i/o is handled by the Group 3 conxxx() (console i/o)
  284.   routines.
  285.  
  286. Protocol Mode
  287.   Reading and writing from the communicatons device.  In this mode, all i/o is
  288.   handled by the Group 3 ttxxx() (terminal i/o) routines.
  289.  
  290. Connect Mode
  291.   Reading from the keyboard with conxxx() routines and writing to the
  292.   communications device with ttxxx() routines AND vice-versa.
  293.  
  294. When in local mode, the console and communications device are distinct.
  295. During file transfer, Kermit may put up a file-transfer display on the console
  296. and sample the console for interruption signals.
  297.  
  298. When in remote mode, the console and communications device are the same, and
  299. therefore there can be no file-transfer display on the console or
  300. interruptions from it (except for "in-band" interruptions such as ^C^C^C).
  301.  
  302. GROUP 0:
  303.  
  304. Library functions, strictly portable, can be used by all modules on all
  305. platforms.  CKCLIB.H, CKCLIB.C.
  306.  
  307. GROUP 1:
  308.  
  309. The Kermit protocol kernel.  The filenames start with CKC.  C means that these
  310. files are supposed to be totally portable C, and are expected to compile
  311. correctly on any platform with any C compiler.  "Portable" does not mean the
  312. same as as "ANSI" -- these modules must compile on 10- and 20-year old
  313. computers, with C preprocessors, compilers, and/or linkers that have all sorts
  314. of restrictions.  The group 1 modules do not include any header files other
  315. than those that come with Kermit itself.  They do not contain any library
  316. calls (like printf) or any system calls (like open, close, read, write).
  317. Files:
  318.  
  319.   CKCSYM.H - For use by C compilers that don't allow -D on the command line.
  320.   CKCASC.H - ASCII character symbol definitions.
  321.   CKCSIG.H - System-independent signal-handling definitions and prototypes.
  322.   CKCDEB.H - Originally, debugging definitions.  Now this file also contains
  323.          all definitions and prototypes that are shared by all modules in
  324.              all groups.
  325.   CKCKER.H - Kermit protocol symbol definitions.
  326.   CKCXLA.H - Character-set-related symbol definitions (see next section).
  327.  
  328.   CKCMAI.C - The main program.  This module contains the declarations of all
  329.   the protocol-related global variables that are shared among the other
  330.   modules.
  331.  
  332.   CKCPRO.W - The protocol module itself, written in "wart", a lex-like
  333.   preprocessor that is distributed with Kermit under the name CKWART.C.
  334.  
  335.   CKCFN*.C - The protocol support functions used by the protocol module.
  336.  
  337. Group 1 modules may call upon functions from Group 3 modules, but not from
  338. Group 2 modules (with the single exception that the main program invokes the
  339. user interface, which is in Group 2).  (This last assertion is really only a
  340. conjecture.)
  341.  
  342. GROUP 1.5
  343.  
  344. Character set translation tables and functions.  Used by the Group I protocol
  345. modules, but may be specific to different computers.  (So far, all character
  346. character sets supported by C-Kermit are supported in CKUXLA.C and CKUXLA.H,
  347. including Macintosh and IBM character sets).  These modules should be
  348. completely portable, and not rely on any kind of system or library services.
  349.  
  350.   CKCXLA.H - Character-set definitions usable by all versions of C-Kermit.
  351.   CK?XLA.H - Character-set definitions for computer "?", e.g. U for UNIX.
  352.  
  353.   CK?XLA.C - Character-set translation tables and functions for computer "?",
  354.   For example, CKUXLA.C for UNIX, CKMXLA.C for Macintosh.  So far, these are
  355.   the only two such modules.  The UNIX module is used for all versions of
  356.   C-Kermit except the Macintosh version.
  357.  
  358.   CKCUNI.H - Unicode definitions
  359.   CKCUNI.C - Unicode module
  360.  
  361.   Used for file transfer (SEND, RECEIVE, GET, REMOTE, etc), TRANSMIT,
  362.   CONNECT, etc.
  363.  
  364. Here's how to add a new file character set.  Assuming it is based on the
  365. Roman (Latin) alphabet.  Let's call it "Barbarian".  First, in CK?XLA.H,
  366. add a definition for FC_BARBA (8 chars maximum length) and increase
  367. MAXFCSETS by 1.  Then, in CK?XLA.C:
  368.  
  369.   . Add a barbarian entry into the fcsinfo array.
  370.   . Add a "barbarian" entry to file character set keyword table, fcstab.
  371.   . Add a "barbarian" entry to terminal character set keyword table, ttcstab.
  372.   . Add a translation table from Latin-1 to barbarian: yl1ba[].
  373.   . Add a translation table from barbarian to Latin-1: ybal1[].
  374.   . Add a translation function from Barbarian to ASCII: xbaas().
  375.   . Add a translation function from Barbarian to Latin-1: xbal1().
  376.   . Add a translation function from Latin-1 to Barbarian: xl1ba().
  377.   .  etc etc for each transfer character set...
  378.   . Add translation function pointers to the xls and xlr tables.
  379.  
  380. Other translations involving Barbarian (e.g. from Barbarian to Latin-Cyrillic)
  381. are performed through these tables and functions.  See CKUXLA.H and CKUXLA.C
  382. for extensive examples.
  383.  
  384. To add a new Transfer Character Set, e.g. Latin Alphabet 9 (for the Euro
  385. symbol)...
  386.  
  387. In ckcxla.h:
  388.  . Add a TC_xxxx definition and increase MAXTCSETS accordingly.
  389.  
  390. In ck?xla.h (since any transfer charset is also a file charset):
  391.  . Add an FC_xxxx definition and increase MAXFCSETS accordingly.
  392.  
  393. In ck?xla.c:
  394.  . Add a tcsinfo[] entry.
  395.  . Make a tcstab[] keyword table entry.
  396.  . Make an fcsinfo[] table entry.
  397.  . Make an fcstab[] keyword table entry.
  398.  . Make a tcstab[] keyword table entry.
  399.  . If necessary, make a langinfo[] table entry.
  400.  . Make entries in the function pointer arrays.
  401.  . Provide any needed functions.
  402.  
  403. In ckcuni.h:
  404.  . (to be filled in)
  405.  
  406. In ckcuni.c:
  407.  . (to be filled in)
  408.  
  409.  
  410. GROUP 2:
  411.  
  412. The user interface.  This is the code that communicates with the user, gets
  413. her commands, informs her of the results.  It may be command-line oriented,
  414. interactive prompting dialog, menus and arrow keys, windows and mice, speech
  415. recognition, telepathy, etc.  The user interface has three major functions:
  416.  
  417. 1. Sets the parameters for the file transfer and then starts it.  This is done
  418. by setting certain (many) global variables, such as the protocol machine start
  419. state, the file specification, file type, communication parameters, packet
  420. length, window size, character set, etc.
  421.  
  422. 2. Displays messages on the user's screen during the file transfer, using the
  423. screen() function, which is called by the group-1 modules.
  424.  
  425. 3. Executes any commands directly that do not require Kermit protocol, such
  426. as the CONNECT command, local file management commands, parameter-setting
  427. commands, etc.
  428.  
  429. If you plan to imbed the Group 1 files into a program with a different user
  430. interface, your interface must supply an appropriate screen() function, plus a
  431. couple related ones like chkint() and intmsg() for handling keyboard (or
  432. mouse, etc) interruptions during file transfer.  The best way to find out
  433. about this is to link all the C-Kermit modules together except the CKUU*.O
  434. and CKUCON.O modules, and see which missing symbols turn up.
  435.  
  436. C-Kermit's character-oriented user interface (as opposed to the Macintosh
  437. version's graphical user interface) consists of the following modules.
  438. C-Kermit can be built with an interactive command parser, a command-line-
  439. option-only parser, a graphical user interface, or any combination, and it
  440. can even be built with no user interface at all (in which case it runs as a
  441. remote-mode Kermit server).
  442.  
  443.   CKUUSR.H - Definitions of symbols used in Kermit's commands.
  444.  
  445.   CKUUSR.H, CKUUSR.C, CKUUS2.C, CKUUS3.C, CKUUS4.C, CKUUS5.C, ... -
  446.   Kermit's interactive command parser, including the script programming
  447.   language.
  448.  
  449.   CKUUSY.C - The command-line-option parser.
  450.  
  451.   CKUUSX.C - Functions that are common to both the interactive and
  452.   command-line parsers.
  453.  
  454.   CKUCMD.H, CKUCMD.C - The command parsing primitives used by the
  455.   interactive command parser to parse keywords, numbers, filenames, etc,
  456.   and to give help, complete fields, supply defaults, allow abbreviations
  457.   and editing, etc.  This package is totally independent of Kermit, but
  458.   does depend on the Group 3 functions.
  459.  
  460.   CKUVER.H - Version heralds for different implementations.
  461.  
  462.   CKUSCR.C - The (old, uucp-like) SCRIPT command.
  463.   CKUDIA.C - The DIAL command.  Includes specific knowledge of many
  464.              types of modems.
  465.  
  466.   CK?CON.C - The CONNECT command.  Terminal connection, and in some
  467.              cases (Macintosh, OS/2, etc) also terminal emulation.
  468.              NOTE: As of C-Kermit 6.1, there are two different CONNECT
  469.              modules for UNIX: ckucon.c -- the regular, portable version
  470.              -- and ckucns.c, a new version that uses select() rather
  471.              than forks so it can handle encryption.  ckucns.c is the
  472.              preferred version; ckucon.c is not likely to keep pace with
  473.              it in terms of upgrades, etc.  However, since select() is
  474.              not portable to every platform, ckucon.c will be kept
  475.              indefinitely for those platforms that can't use ckucns.c.
  476.              NOTE: SunLink X.25 support is available only in ckucon.c.
  477.  
  478.   CK_CRP.* - Modules having to do with authentication and encryption.
  479.   CKUAT*.*   These are not part of the general distribution since they
  480.              contain code and algorithms that are restricted by USA
  481.              export law.
  482.  
  483. For other implementations, the files may, and probably do, have different
  484. names.  For example, the Macintosh graphical user interface filenames start
  485. with CKM.  OS/2 uses the CKUCMD and CKUUS* modules, but has its own CONNECT
  486. command in CKOCON.C.  And so on.
  487.  
  488. Here is a brief description of C-Kermit's "user interface interface", from
  489. CKUUSR.C.  It is nowhere near complete; in particular, hundreds of global
  490. variables are shared among the many modules.  These should, some day, be
  491. collected into classes or structures that can be passed around as needed;
  492. not only for purity's sake, but also to allow for multiple simultaneous
  493. communication sessions and or user interfaces.
  494.  
  495. The ckuus*.c modules depend on the existence of C library features like fopen,
  496. fgets, feof, (f)printf, argv/argc, etc.  Other functions that are likely to
  497. vary among operating systems -- like setting terminal modes or interrupts --
  498. are invoked via calls to functions that are defined in the system-dependent
  499. modules, ck?[ft]io.c.  The command line parser processes any arguments found
  500. on the command line, as passed to main() via argv/argc.  The interactive
  501. parser uses the facilities of the cmd package (developed for this program, but
  502. usable by any program).  Any command parser may be substituted for this one.
  503. The only requirements for the Kermit command parser are these:
  504.  
  505. 1. Set parameters via global variables like duplex, speed, ttname, etc.  See
  506.    ckcmai.c for the declarations and descriptions of these variables.
  507.  
  508. 2. If a command can be executed without the use of Kermit protocol, then
  509.    execute the command directly and set the variable sstate to 0.  Examples
  510.    include 'set' commands, local directory listings, the 'connect' command.
  511.  
  512. 3. If a command requires the Kermit protocol, set the following variables:
  513.  
  514.    sstate                             string data
  515.      'x' (enter server mode)            (none)
  516.      'r' (send a 'get' command)         cmarg, cmarg2
  517.      'v' (enter receive mode)           cmarg2
  518.      'g' (send a generic command)       cmarg
  519.      's' (send files)                   nfils, cmarg & cmarg2 OR cmlist
  520.      'c' (send a remote host command)   cmarg
  521.  
  522.    cmlist is an array of pointers to strings.
  523.    cmarg, cmarg2 are pointers to strings.
  524.    nfils is an integer.
  525.  
  526.    cmarg can be a filename string (possibly wild), or
  527.       a pointer to a prefabricated generic command string, or
  528.       a pointer to a host command string.
  529.    cmarg2 is the name to send a single file under, or
  530.       the name under which to store an incoming file; must not be wild.
  531.       If it's the name for receiving, a null value means to store the
  532.       file under the name it arrives with.
  533.    cmlist is a list of nonwild filenames, such as passed via argv.
  534.    nfils is an integer, interpreted as follows:
  535.      -1: filespec (possibly wild) in cmarg, must be expanded internally.
  536.       0: send from stdin (standard input).
  537.      >0: number of files to send, from cmlist.
  538.  
  539. The screen() function is used to update the screen during file transfer.
  540. The tlog() function writes to a transaction log (if TLOG is defined).
  541. The debug() function writes to a debugging log (if DEBUG is defined).
  542. The intmsg() and chkint() functions provide the user i/o for interrupting
  543. file transfers.
  544.  
  545. GROUP 3:
  546.  
  547. System-dependent function definitions.  All the Kermit modules, including the
  548. command package, call upon these functions, which are designed to provide
  549. system-independent primitives for controlling and manipulating devices and
  550. files.  For UNIX, these functions are defined in the files CKUFIO.C (files),
  551. CKUTIO.C (communication devices), and CKUSIG.C (signal handling).
  552.  
  553. For VMS, the files are CKVFIO.C, CKVTIO.C, and CKUSIG.C (VMS can use the same
  554. signal handling routines as UNIX).  For OS/2, CKOFIO.C, CKOTIO.C, CKOSIG.C
  555. (OS/2 has its own signal handling).  It doesn't really matter what the files
  556. are called, except for Kermit distribution purposes (grouping related files
  557. together alphabetically), only that each function is provided with the name
  558. indicated, observes the same calling and return conventions, and has the same
  559. type.
  560.  
  561. The Group 3 modules contain both functions and global variables that are
  562. accessed by modules in the other groups.  These are now described.
  563.  
  564. (By the way, I got this list by linking all the C-Kermit modules together
  565. except CKUTIO and CKUFIO.  These are the symbols that ld reported as undefined)
  566.  
  567. A. Variables:
  568.  
  569. char *DELCMD;
  570.   Pointer to string containing command for deleting files.
  571.   Example: char *DELCMD = "rm -f ";  (UNIX)
  572.   Example: char *DELCMD = "delete "; (VMS)
  573.   Note trailing space.  Filename is concatenated to end of this string.
  574.   NOTE: DELCMD is used only in versions that do not provide their own
  575.   built-in DELETE command.
  576.  
  577. char *DIRCMD;
  578.   Pointer to string containing command for listing files when a filespec
  579.   is given.
  580.   Example: char *DIRCMD = "/bin/ls -l "; (UNIX)
  581.   Example: char *DIRCMD = "directory ";  (VMS)
  582.   Note trailing space.  Filename is concatenated to end of this string.
  583.   NOTE: DIRCMD is used only in versions that do not provide their own
  584.   built-in DIRECTORY command.
  585.  
  586. char *DIRCM2;
  587.   Pointer to string containing command for listing files when a filespec
  588.   is not given.  (currently not used, handled in another way.)
  589.   Example: char *DIRCMD2 = "/bin/ls -ld *";
  590.   NOTE: DIRCMD2 is used only in versions that do not provide their own
  591.   built-in DIRECTORY command.
  592.  
  593. char *PWDCMD;
  594.   Pointer to string containing command to display current directory.
  595.   Example: char *PWDCMD = "pwd ";
  596.   NOTE: PWDCMD is used only in versions that do not provide their own
  597.   built-in PWD command.
  598.  
  599. char *SPACMD;
  600.   Pointer to command to display free disk space in current device/directory.
  601.   Example: char *SPACMD = "df .";
  602.   NOTE: SPACMD is used only in versions that do not provide their own
  603.   built-in SPACE command.
  604.  
  605. char *SPACM2;
  606.   Pointer to command to display free disk space in another device/directory.
  607.   Example: char *SPACM2 = "df ";
  608.   Note trailing space.  Device or directory name is added to this string.
  609.   NOTE: SPACMD2 is used only in versions that do not provide their own
  610.   built-in SPACE command.
  611.  
  612. char *TYPCMD;
  613.   Pointer to command for displaying the contents of a file.
  614.   Example: char *TYPCMD = "cat ";
  615.   Note trailing space.  Device or directory name is added to this string.
  616.   NOTE: TYPCMD is used only in versions that do not provide their own
  617.   built-in TYPE command.
  618.  
  619. char *WHOCMD;
  620.   Pointer to command for displaying logged-in users.
  621.   Example: char *WHOCMD = "who ";
  622.   Note trailing space.  Specific user name may be added to this string.
  623.  
  624. int backgrd = 0;
  625.   Flag for whether program is running in foreground (0) or background
  626.   (nonzero).  Background operation implies that screen output should not be
  627.   done and that all errors should be fatal.
  628.  
  629. int ckxech;
  630.   Flag for who is to echo console typein:
  631.   1 - The program (system is not echoing).
  632.   0 - The system, front end, terminal, etc (not this program)
  633.  
  634. char *ckxsys;
  635.   Pointer to string that names the computer and operating system.
  636.   Example: char *ckxsys = " NeXT Mach 1.0";
  637.   Tells what computer system ckxv applies to.
  638.   In UNIX Kermit, this variable is also used to print the program herald,
  639.   and in the SHOW VERSION command.
  640.  
  641. char *ckxv;
  642.   Pointer to version/edit info of ck?tio.c module.
  643.   Example: char *ckxv = "UNIX Communications Support, 6.0.169, 6 Sep 96";
  644.   Used by SHOW VERSION command.
  645.  
  646. char *ckzsys;
  647.   Like ckxsys, but briefer.
  648.   Example: char *ckzsys = " 4.3 BSD";
  649.   Tells what platform ckzv applies to.
  650.   Used by the SHOW VERSION command.
  651.  
  652. char *ckzv;
  653.   Pointer to version/edit info of ck?fio.c module.
  654.   Example: char *ckzv = "UNIX File support, 6.0.113, 6 Sep 96";
  655.   Used by SHOW VERSION command.
  656.  
  657. int dfflow;
  658.   Default flow control.
  659.   0 = none, 1 = Xon/Xoff, ... (see FLO_xxx symbols in ckcdeb.h)
  660.   Set to by group 3 module.
  661.   Used by ckcmai.c to initialize flow control variable.
  662.  
  663. int dfloc;
  664.   Default location.
  665.   0 = remote, 1 = local.
  666.   Set by group 3 module.
  667.   Used by ckcmai.c to initialize local variable.  Used in various places in
  668.   the user interface.
  669.  
  670. int dfprty;
  671.   Default parity.
  672.   0 = none, 'e' = even, 'o' = odd, 'm' = mark, 's' = space.
  673.   Set by Group 3 module.  Used by ckcmai.c to initialize parity variable.
  674.  
  675. char *dftty;
  676.   Default communication device.
  677.   Set by group 3 module.  Used in many places.
  678.   This variable should be initialized the the symbol CTTNAM, which is defined
  679.   in ckcdeb.h, e.g. as "/dev/tty" for UNIX, "TT:" for VAX/VMS, etc.
  680.   Example: char *dftty = CTTNAM;
  681.  
  682. char *mtchs[];
  683.   Array of string pointers to filenames that matched the most recent
  684.   wildcard match, i.e. the most recent call to zxpand().  Used (at least) by
  685.   command parsing package for partial filename completion.
  686.  
  687. int tilde_expand;
  688.   Flag for whether to attempt to expand leading tildes in directory names
  689.   (used in UNIX only, and then only when the symbol DTILDE is defined.
  690.  
  691. int ttnproto;
  692.   The protocol being used to communicate over a network device.  Values are
  693.   defined in ckcnet.h.  Example: NP_TELNET is network protocol "telnet".
  694.  
  695. int maxnam;
  696.   The maximum length for a filename, exclusive of any device or directory
  697.   information, in the format of the host operating system.
  698.  
  699. int maxpath;
  700.   The maximum length for a fully specified filename, including device
  701.   designator, directory name, network node name, etc, in the format of
  702.   the host operating system, and including all punctuation.
  703.  
  704. int ttyfd;
  705.   File descriptor of the communication device.  -1 if there is no open
  706.   or usable connection, including when C-Kermit is in remote mode.
  707.   Since this is not implemented everywhere, references to it are in
  708.   #ifdef CK_TTYFD..#endif.
  709.  
  710. B. Functions.
  711.  
  712. These are divided into three categories: file-related functions (B.1),
  713. communication functions (B.2), and miscellaneous functions (B.3).
  714.  
  715. B.1.  File-related functions.
  716.  
  717. In most implementations, these are collected together into a module called
  718. CK?FIO.c, where ? = U (UNIX), V (VMS), O (OS/2), etc (see CKAAAA.TXT).  To be
  719. totally system-independent, C-Kermit maintains its own file numbers, and
  720. provides the functions described in this section to deal with the files
  721. associated with them.  The file numbers are referred to symbolically, and are
  722. defined as follows in CKCKER.H:
  723.  
  724. #define ZCTERM      0            /* Console terminal */
  725. #define ZSTDIO      1        /* Standard input/output */
  726. #define ZIFILE        2        /* Current input file for SEND command */
  727. #define ZOFILE      3            /* Current output file for RECEIVE command */
  728. #define ZDFILE      4            /* Current debugging log file */
  729. #define ZTFILE      5            /* Current transaction log file */
  730. #define ZPFILE      6            /* Current packet log file */
  731. #define ZSFILE      7        /* Current session log file */
  732. #define ZSYSFN        8        /* Input from a system function (pipe) */
  733. #define ZRFILE      9           /* Local file for READ command */  (NEW)
  734. #define ZWFILE     10           /* Local file for WRITE command */ (NEW)
  735. #define ZMFILE     11           /* Auxilliary file for internal use */ (NEW)
  736. #define ZNFILS     12            /* How many defined file numbers */
  737.  
  738. In the descriptions below, fn refers to a filename, and n refers to one of
  739. these file numbers.  Functions are of type int unless otherwise noted, and are
  740. listed alphabetically.
  741.  
  742. int
  743. chkfn(n) int n;
  744.   Checks the file number n.  Returns:
  745.   -1: File number n is out of range
  746.    0: n is in range, but file is not open
  747.    1: n in range and file is open
  748.  
  749. int
  750. iswild(filspec) char *filespec;
  751.   Checks if the file specification is "wild", i.e. contains metacharacters
  752.   or other notations intended to match multiple filenames.  Returns:
  753.    0: not wild
  754.    1: wild
  755.  
  756. int
  757. isdir(string) char *string;
  758.   Checks if the string is the name of an existing directory.  Returns:
  759.    0: not a directory (including any kind of error)
  760.    1: it is an existing directory
  761.   The idea is to check whether the string can be "cd'd" to, so in some cases
  762.   (e.g. OS/2) it might also indicate any file structured device, such as a
  763.   disk drive (like A:).  Other nonzero returns indicate system-dependent
  764.   information; e.g. in VMS isdir("[.FOO]") returns 1 but isdir("FOO.DIR;1")
  765.   returns 2 to indicate the directory-file name is in a format that needs
  766.   conversion before it can be combined with a filename.
  767.  
  768. char *
  769. zfcdat(name) char *name;
  770.   Returns modification (preferably, otherwise creation) date/time of file
  771.   whose name is given in the argument string.  Return value is a pointer to a
  772.   string of the form yyyymmdd hh:mm:ss, for example 19931231 23:59:59, which
  773.   represents the local time (no timezone or daylight savings time finagling
  774.   required).  Returns the null string ("") on failure.  The text pointed to by
  775.   the string pointer might be in a static buffer, and so should be copied to a
  776.   safe place by the caller before any subsequent calls to this function.
  777.  
  778. struct zfnfp *
  779. zfnqfp(fname, buflen, buf)  char * fname; int buflen; char * buf;
  780.   Given the filename "fname", the corresponding fully qualified, absolute
  781.   filename is placed into the buffer buf, with maximum length buflen.
  782.   On failure returns a NULL pointer.  On success returns a pointer to
  783.   a struct zfnfp (see ckcdeb.h) containing pointers to the full pathname
  784.   and to just the filename.  All references to this function in mainline
  785.   code must be protected by #ifdef ZFNQFP..#endif, because it is not present
  786.   in all of the ck*fio.c modules.  So if you implement this function in a
  787.   version that did not have it before, be sure to add #define ZFNQFP in the
  788.   appropriate spot in ckcdeb.h.
  789.  
  790. int
  791. zfseek(pos) long pos;
  792.   Positions the input pointer on the current input file to the given position.
  793.   The pos argument is 0-based, the offset (distance in bytes) from beginning
  794.   of the file.  Needed for RESEND, PSEND, and other recovery operations.  This
  795.   function is not necessarily possible on all systems, e.g. record-oriented
  796.   systems.  It should only be used on binary files (i.e. files we are sending
  797.   in binary mode) and stream-oriented file systems.  Returns -1 on failure, 0
  798.   on success.
  799.  
  800. int
  801. zchdir(dirnam) char *dirnam;
  802.   Change current or default directory to the one given in dirnam.
  803.   Returns 1 on success, 0 on failure.
  804.  
  805. long
  806. zchki(fn) char *fn;
  807.   Check to see if file with name fn is a regular, readable, existing file,
  808.   suitable for Kermit to send -- not a directory, not a symbolic link, etc.
  809.   Returns:
  810.   -3 if file exists but is not accessible (e.g. read-protected);
  811.   -2 if file exists but is not of a readable type (e.g. a directory);
  812.   -1 on error (e.g. file does not exist, or fn is garbage);
  813.   >= 0 (length of file) if file exists and is readable.
  814.   Also see isdir(), zgetfs().
  815.  
  816. int
  817. zchkpid(pid) unsigned long pid;
  818.   Returns 1 if the given process ID (e.g. pid in UNIX) is valid and active,
  819.   0 otherwise.
  820.  
  821. long
  822. zgetfs(fn) char *fn;
  823.   Get the size of the given file, regardless of accessibility.  Used for
  824.   directory listings.  Unlike zchki(), should return the size of any kind
  825.   of file, even a directory.  zgetfs() also should serve as a mini "get
  826.   file info" function that can be used until we design a better one, by
  827.   also setting some global variables:
  828.     int zgfs_link   = 1/0 = file is (not) a symbolic link.
  829.     int zgfs_dir    = 1/0 = file is (not) a directory.
  830.     char linkname[] = if zgfs_link != 0, name of file link points to.
  831.   Returns:
  832.     -1 on error (e.g. file does not exist, or fn is garbage);
  833.     >= 0 (length of file) if file exists and is readable.
  834.  
  835. int
  836. zchko(fn) char *fn;
  837.   Checks to see if a file of the given name can be created.  Returns:
  838.   -1 if file cannot be created, or on any kind of error.
  839.    0 if file can be created.
  840.  
  841. int
  842. zchkspa(fn,len) char *f; long len;
  843.   Check to see if there is sufficient space to store the file named fn,
  844.   which is len bytes long.  Returns:
  845.   -1 on error.
  846.    0 if there is not enough space.
  847.    1 if there is enough space.
  848.   If you can't write a function to do this, then just make a dummy that
  849.   always returns 1.  Higher level code will recover from disk-full errors.
  850.   The receiving Kermit uses this function to refuse an incoming file based
  851.   on its size, via the attribute mechanism.
  852.  
  853. int
  854. zchin(n,c) int n; int *c;
  855.   Get a character from file number n, return it in c (call with &c).
  856.   Returns:
  857.   -1 on failure, including EOF.
  858.    0 on success with character in c.
  859.  
  860. int
  861. zchout(n,c) int n; char c;
  862.   Write the character c to file number n.  Returns:
  863.   -1 error
  864.    0 OK
  865.  
  866. int
  867. zclose(n) int n;
  868.   Close file number n.  Returns:
  869.   -1 error
  870.    1 OK
  871.  
  872. int
  873. zdelet(fn) char *name;
  874.   Attempts to delete the named file.  Returns:
  875.   -1 on error
  876.    0 if file was deleted successfully
  877.  
  878. char *
  879. zgperm(char * f)
  880.   Returns a pointer to the system-dependent numeric permissions/protection
  881.   string for file f, or NULL upon failure.  Used if CK_PERMS is defined.
  882.  
  883. char *
  884. ziperm(char * f)
  885.   Returns a pointer to the system-dependent symbolic permissions/protection
  886.   string for file f, or NULL upon failure.  Used if CK_PERMS is defined.
  887.   Example: In UNIX zgperm(f) might return "100770", but ziperm() might
  888.   return "-rwxrwx---".  In VMS, zgperm() would return a hexadecimal string,
  889.   but ziperm() would return something like "(RWED,RWED,RE,)".
  890.  
  891. char *
  892. zgtdir()
  893.   Returns a pointer to the name of the current directory, folder, etc, or a
  894.   NULL pointer if the current directory cannot be determined.  If possible,
  895.   the directory specification should be (a) fully specified, e.g. as a
  896.   complete pathname, and (b) be suitable for appending a filename.  Thus, for
  897.   example, UNIX directory names should end with '/'.  VMS directory names
  898.   should look like DEV:[NAME] (rather than, say, NAME.DIR;1).
  899.  
  900. char *
  901. zhome()
  902.   Returns a pointer to a string containing the user's home directory, or NULL
  903.   upon error.  Should be formatted like zgtdir() (q.v.).
  904.  
  905. int
  906. zinfill()
  907.   This function is used by the macro zminchar(), which is defined in ckcker.h.
  908.   zminchar() manages its own buffer, and calls zinfill() to fill it whenever
  909.   it becomes empty.  It is only used for sending files, and reads characters
  910.   only from file number ZIFILE.  zinfill() returns -1 upon end of file,
  911.   -2 upon fatal error, and -3 upon timeout (e.g. when reading from a pipe);
  912.   otherwise it returns the first character from the buffer it just read.
  913.  
  914. int
  915. zkself()
  916.   Kills the current job, session, process, etc, logs out, disappears.  Used by
  917.   the Kermit server when it receives a BYE command.  On failure, returns -1.
  918.   On success, does not return at all!  This function should not be called
  919.   until all other steps have been taken to close files, etc.
  920.  
  921. VOID
  922. zstrip(fn,&fn2) char *fn1, **fn2;
  923.   Strip device and directory, etc, from file specification, leaving only the
  924.   filename.  For example DUA0:[PROGRAMS]OOFA.C;3 becomes OOFA.C, or
  925.   /usr/fdc/oofa.c becomes oofa.c.  Returns pointer to result in fn2.
  926.  
  927. VOID
  928. zltor(fn,fn2) char *fn1, *fn2;
  929.   Local-To-Remote filename translation.  Translates the local filename fn into
  930.   a format suitable for transmission to an arbitrary type of computer, and
  931.   copies the result into the buffer pointed to by fn2.  Translation may involve
  932.   (a) stripping the device and/or directory/path name, (b) converting
  933.   lowercase to uppercase, (c) removing spaces and strange characters, or
  934.   converting them to some innocuous alphabetic character like X, (d)
  935.   discarding or converting extra periods (there should not be more than one).
  936.   Does its best.  Returns no value.  name2 is a pointer to a buffer, furnished
  937.   by the caller, into which zltor() writes the resulting name.  No length
  938.   checking is done.
  939.  
  940. #ifdef NZLTOR
  941. VOID
  942. nzltor(fn,fn2,convert,pathnames,max) char *fn1,*fn2; int convert,pathnames,max;
  943.   Replaces zltor.  This new version handles pathnames and checks length.  fn1
  944.   and fn2 are as in zltor.  This version is called unconditionally for each
  945.   file, rather than only when filename conversion is enabled.  Pathnames can
  946.   have the following values:
  947.     PATH_OFF: Pathname, if any, is to be stripped
  948.     PATH_REL: The relative pathname is to be included
  949.     PATH_ABS: The full pathname is to be included
  950.  
  951.   After handling pathnames, conversion is done to the result as in the zltor
  952.   description if convert != 0; if relative or absolute pathnames are included,
  953.   they are converted to UNIX format, i.e. with slash (/) as the directory
  954.   separator.  The max parameter specifies the maximum size of fn2.
  955. #endif /* NZLTOR */
  956.  
  957. int
  958. nzxpand(fn,flags) char *fn; int flags;
  959.   Replaces zxpand(), which is obsolete as of C-Kermit 7.0.
  960.   Call with:
  961.    s = pointer to filename or pattern.
  962.    flags = option bits:
  963.  
  964.      flags & ZX_FILONLY   Match regular files
  965.      flags & ZX_DIRONLY   Match directories
  966.      flags & ZX_RECURSE   Descend through directory tree
  967.      flags & ZX_MATCHDOT  Match "dot files"
  968.      flags & ZX_NOBACKUP  Don't match "backup files"
  969.  
  970.   Returns the number of files that match s, with data structures set up
  971.   so that first file (if any) will be returned by the next znext() call.
  972.   If ZX_FILONLY and ZX_DIRONLY are both set, or neither one is set, files and
  973.   directories are matched.
  974.  
  975.   NOTE: It is essential that the number returned by nzxpand() reflect the
  976.   actual number of filenames that will be returned by znext calls().  In
  977.   other words:
  978.  
  979.     for (n = nzxpand(string,flags); n > 0; n--) {
  980.         znext(buf);
  981.         printf("%s\n", buf);
  982.     }
  983.  
  984.   should print all the file names; no more, no less.
  985.  
  986.   NOTE 2: In UNIX, DOS, OS-9, etc, where directories contain entries
  987.   for themselves (.) and the superior directory (..), these should NOT be
  988.   included in the list under any circumstances, including when ZX_MATCHDOT
  989.   is set.
  990.  
  991.   NOTE 3: Additional option bits might be added in the future, e.g. for
  992.   sorting (sort by date/name/size, reverse/ascending, etc).
  993.  
  994. int
  995. zmail(addr,fn) char *addr, fn;
  996.   Send the local, existing file fn as e-mail to the address addr.  Returns:
  997.   Returns 0 on success
  998.    2 if mail delivered but temp file can't be deleted
  999.   -2 if mail can't be delivered
  1000.  
  1001. int
  1002. zmkdir(path) char *path;
  1003.   The path can be a file specification that might contain directory
  1004.   information, in which the filename is expected to be included, or an
  1005.   unambiguous directory specification (e.g. in UNIX it must end with "/").
  1006.   This routine attempts to create any directories in the given path
  1007.   that don't already exist.  Returns:
  1008.    0 or greater success: no directories needed creation,
  1009.      or else all directories that needed creation were created successfully;
  1010.      the return code is the number of directories that were created.
  1011.   -1 on failure to create any of the needed directories.
  1012.  
  1013. int
  1014. zrmdir(path) char *path;
  1015.   Attempts to remove the given directory.  Returns 0 on success, -1 on
  1016.   failure.  The detailed semantics are open -- should it fail if the directory
  1017.   contains any files or subdirectories, etc.  It is probably best for this
  1018.   routine to behave in whatever manner is customary on the underlying
  1019.   platform; e.g. in UNIX, VMS, DOS, etc, where directories can not be removed
  1020.   unless they are empty.
  1021.  
  1022. VOID
  1023. znewn(fn,s) char *fn, **s;
  1024.   Transforms the name fn into a filename which is guaranteed to be unique.
  1025.   If the file fn does not exist, then the new name will be the same as fn.
  1026.   Otherwise, it will be different.  Does its best, returns no value.  New
  1027.   name is created in caller's space.  Call like this: znewn(old,&new);.
  1028.   The second parameter is a pointer to the new name.  This pointer is set
  1029.   by znewn() to point to a static string in its own space.
  1030.  
  1031. int
  1032. znext(fn) char *fn;
  1033.   Copies the next file name from a file list created by zxpand() into the
  1034.   string pointed to by fn (see zxpand).  If no more files, then the null
  1035.   string is placed there.  Returns 0 if there are no more filenames, with
  1036.   0th element the array pointed to by fn set to NUL.  If there is a filename,
  1037.   it is stored in the array pointed to by fn, and a positive number is
  1038.   returned.  NOTE: This is a change from earlier definitions of this function
  1039.   (pre-1999), which returned the number of files remaining; thus 0 was the
  1040.   return value when returning the final file.  However, no mainline code
  1041.   ever depended on the return value, so this change should be safe.
  1042.  
  1043. int
  1044. zopeni(n,fn) int n; char *fn;
  1045.   Opens the file named fn for input as file number n.  Returns:
  1046.     0 on failure.
  1047.     1 on success.
  1048.  
  1049. (zopeno - the second two parameters are new to C-Kermit 5A)
  1050. int
  1051. zopeno(n,fn,zz,fcb) int n; char *name; struct zattr *zz; struct filinfo *fcb;
  1052.   Attempts to open the named file for output as file number n.  zz is a Kermit
  1053.   file attribute structure as defined in ckcdeb.h, containing various
  1054.   information about the file, including its size, creation date, and so forth.
  1055.   This function should attempt to honor as many of these as possible.  fcb is
  1056.   a "file control block" in the traditional sense, defined in ckcdeb.h,
  1057.   containing information of interest to complicated file systems like VAX/VMS,
  1058.   IBM MVS, etc, like blocksize, record length, organization, record format,
  1059.   carriage control, disposition (like create vs append), etc.  Returns:
  1060.     0 on failure.
  1061.     1 on success.
  1062.  
  1063. int
  1064. zoutdump()
  1065.   Dumps an output buffer.  Used with the macro zmchout() defined in ckcker.h.
  1066.   Used only with file number ZOFILE, i.e. the file that is being received by
  1067.   Kermit during file transfer.  Returns:
  1068.    -1 on failure.
  1069.     0 on success.
  1070.  
  1071. int
  1072. zprint(p,fn) char *p, *f;
  1073.   Prints the file with name fn on a local printer, with options p.  Returns:
  1074.   Returns 0 on success
  1075.     3 if file sent to printer but can't be deleted
  1076.    -3 if file can't be printed
  1077.  
  1078. int
  1079. zrename(fn,fn2) char *fn, *fn2;
  1080.   Changes the name of file fn to fn2.  If fn2 is the name of an existing
  1081.   directory, or a file-structured device, then file fn1 is moved to that
  1082.   directory or device, keeping its original name.  If fn2 lacks a directory
  1083.   separator when passed to this function, an appropriate one is supplied.
  1084.   Returns:
  1085.    -1 on failure.
  1086.     0 on success.
  1087.  
  1088. int
  1089. zcopy(source,dest) char * source, * dest;
  1090.   Copies the source file to the destination.  One file only.
  1091.   No wildcards.  The destination string may be a filename or a directory
  1092.   name.  Returns:
  1093.    0 on success.
  1094.   <0 on failure:
  1095.   -2 = source file is not a regular file.
  1096.   -3 = source file not found.
  1097.   -4 = permission denied.
  1098.   -5 = source and destination are the same file.
  1099.   -6 = i/o error.
  1100.   -1 = other error.
  1101.  
  1102. VOID
  1103. zrtol(fn,fn2) char *fn, *fn2;
  1104.   Remote-To-Local filename translation.  Translates a "standard" filename
  1105.   (see zrtol) to a local filename.  For example, in Unix this function might
  1106.   convert an all-uppercase name to lowercase, but leave lower- or mix-case
  1107.   names alone.  Does its best, returns no value.  New name is in string
  1108.   pointed to by fn2.  No length checking is done.
  1109.  
  1110. #ifdef NZLTOR
  1111. nzrtol(fn,fn2,convert,pathnames,max) char *fn1,*fn2; int convert,pathnames,max;
  1112.   Replaces zrtol.  Like zrtol but handles pathnames and checks length.  See
  1113.   nzltor for detailed description of parameters.
  1114. #endif /* NZLTOR */
  1115.  
  1116. int
  1117. zsattr(xx) struct zattr *xx; {
  1118.   Fills in a Kermit file attribute structure for the file which is to be sent,
  1119.   namely the currently open ZIFILE.
  1120.   Returns:
  1121.   -1 on failure.
  1122.    0 on success with the structure filled in.
  1123.   If any string member is null, then it should be ignored by the caller.
  1124.   If any numeric member is -1, then it should be ignored by the caller.
  1125.  
  1126. int
  1127. zshcmd(s) char *s;
  1128.   s contains to pointer to a command to be executed by the host computer's
  1129.   shell, command parser, or operating system.  If the system allows the user
  1130.   to choose from a variety of command processors (shells), then this function
  1131.   should employ the user's preferred shell.  If possible, the user's job
  1132.   (environment, process, etc) should be set up to catch keyboard interruption
  1133.   signals to allow the user to halt the system command and return to Kermit.
  1134.   The command must run in ordinary, unprivileged user mode.
  1135.   If possible, this function should return -1 on failure to start the command,
  1136.   or else it should return 1 if the command succeeded and 0 if it failed.
  1137.  
  1138. int
  1139. pexitstatus
  1140.   zshcmd() and zsyscmd() should set this to the command's actual exit status
  1141.   code if possible.
  1142.  
  1143. int
  1144. zsyscmd(s) char *s;
  1145.   s contains to pointer to a command to be executed by the host computer's
  1146.   shell, command parser, or operating system.  If the system allows the user
  1147.   to choose from a variety of command processors (shells), then this function
  1148.   should employ the system standard shell (e.g. /bin/sh for Unix), so that the
  1149.   results will always be the same for everybody.  If possible, the user's job
  1150.   (environment, process, etc) should be set up to catch keyboard interruption
  1151.   signals to allow the user to halt the system command and return to Kermit.
  1152.   The command must run in ordinary, unprivileged user mode.
  1153.   If possible, this function should return -1 on failure to start the command,
  1154.   or else it should return 1 if the command succeeded and 0 if it failed.
  1155.  
  1156. VOID
  1157. z_exec(s,args) char * s; char * args[];
  1158.   This one executes the command s (which is searched for using the system's
  1159.   normal searching mechanism, such as PATH in UNIX), with the given argument
  1160.   vector, which follows the conventions of UNIX argv[]: the name of the
  1161.   command pointed to by element 0, the first arg by element 1, and so on.
  1162.   A null args[] pointer indicates the end of the arugment list.  All open
  1163.   files must remain open so the exec'd process can use them.  Returns only
  1164.   if unsuccessful.
  1165.  
  1166. int
  1167. zsinl(n,s,x) int n, x; char *s;
  1168.   Reads a line from file number n.
  1169.   Writes the line into the address s provided by the caller.
  1170.   Writing terminates when newline is read, but with newline discarded.
  1171.   Writing also terminates upon EOF or if length x is exhausted.
  1172.   Returns:
  1173.   -1 on EOF or error.
  1174.    0 on success.
  1175.  
  1176. int
  1177. zsout(n,s) int n; char *s;
  1178.   Writes the string s out to file number n.  Returns:
  1179.   -1 on failure.
  1180.    0 on success.
  1181.  
  1182. int
  1183. zsoutl(n,s) int n; char *s;
  1184.   Writes the string s out to file number n and adds a line (record) terminator
  1185.   (boundary) appropriate for the system and the file format.
  1186.   Returns:
  1187.   -1 on failure.
  1188.    0 on success.
  1189.  
  1190. int
  1191. zsoutx(n,s,x) int n, x; char *s;
  1192.   Writes exactly x characters from string s to file number n.  If s has
  1193.   fewer than x characters, then the entire string s is written.  Returns:
  1194.   -1 on error.
  1195.   >= 0 on success, the number of characters actually written.
  1196.  
  1197. int
  1198. zstime(f,yy,x) char *f; struct zattr *yy; int x;
  1199.   Sets the creation date (and other attributes) of an existing file, or
  1200.   compares a file's creation date with a given date.  Call with:
  1201.   f  = pointer to name of existing file.
  1202.   yy = pointer to a Kermit file attribute structure in which yy->date.val
  1203.        is a date of the form yyyymmdd hh:mm:ss, e.g. 19900208 13:00:00, which
  1204.        is to be used for setting or comparing the date.  Other attributes
  1205.        in the struct can also be set, such as the protection/permission
  1206.        (See Appendix I), when it makes sense (e.g. "yy->lprotect.val" can be
  1207.        set if the remote system ID matches the local one).
  1208.   x  = is a function code: 0 means to set the file's creation date as given.
  1209.        1 means compare the date from the yy struct with the file's date.
  1210.   Returns:
  1211.   -1 on any kind of error.
  1212.    0 if x is 0 and the file date was set successfully.
  1213.    0 if x is 1 and date from attribute structure > file creation date.
  1214.    1 if x is 1 and date from attribute structure <= file creation date.
  1215.  
  1216. VOID
  1217. zstrip(name,name2) char *name, **name2;
  1218.   Strips pathname from filename "name".  Constructs the resulting string
  1219.   in a static buffer in its own space and returns a pointer to it in name2.
  1220.   Also strips device name, file version numbers, and other "non-name" material.
  1221.  
  1222. (zxcmd - arguments are new, writing to a command is new)
  1223.  
  1224. int
  1225. zxcmd(n,s) char *s;
  1226.   Runs a system command so its output can be accessed as if it were file n.
  1227.   The command is run in ordinary, unprivileged user mode.
  1228.   If n is ZSTDIO or ZCTERM, returns -1.
  1229.   If n is ZIFILE or ZRFILE, then Kermit reads from the command, otherwise
  1230.   Kermit writes to the command.  Returns 0 on error, 1 on success.
  1231.  
  1232. int
  1233. zxpand(fn) char *fn;
  1234.   OBSOLETE!  Replaced by nzxpand(), q.v.
  1235.  
  1236. int
  1237. zxrewind()
  1238.   Returns the number of files returned by the most recent zxpand call,
  1239.   and resets the list to the beginning so the next znext() call returns the
  1240.   first file.  Returns -1 if zxpand has not yet been called.  If this function
  1241.   is available, ZXREWIND should be defined; otherwise it should not be
  1242.   referenced.
  1243.  
  1244. int
  1245. xsystem(cmd) char *cmd;
  1246.   Executes the system command without redirecting any of its i/o, similar
  1247.   (well, identical) to system() in Unix.  But before passing the command to
  1248.   the system, xsystem() ensures that all privileges are turned off, so that
  1249.   the system command will execute in ordinary unprivileged user mode.
  1250.  
  1251. B.1.2 IKSD Functions
  1252.  
  1253. These must be implemented in any C-Kermit version that is to be installed as
  1254. an Internet Kermit Service Daemon (IKSD).  IKSD is expected to be started by
  1255. the Internet Daemon (e.g. inetd) with its standard i/o redirected to the
  1256. incoming connection.
  1257.  
  1258. int ckxanon;
  1259.   Nonzero if anonymous logins allowed.
  1260.  
  1261. extern int inserver;
  1262.   Nonzero if started in IKSD mode.
  1263.  
  1264. extern int isguest;
  1265.   Nonzero if IKSD and user logged in anonymously.
  1266.  
  1267. extern char * homdir;
  1268.   Pointer to user's home directory.
  1269.  
  1270. extern char * anonroot;
  1271.   Pointer to file-system root for anonymous users.
  1272.  
  1273. Existing functions must make "if (inserver && isguest)" checks for actions
  1274. that would not be legal for guests: zdelete(), zrmdir(), zprint(), zmail(),
  1275. etc.
  1276.  
  1277. int
  1278. zvuser(name) char * name;
  1279.   Verifies that user "name" exists and is allowed to log in.  If the name is
  1280.   "ftp" or "anonymous" and ckxanon != 0, a guest login is set up.  Returns 0
  1281.   if user not allowed to log in, nonzero if user may log in.
  1282.  
  1283. zvpass(string) char * string;
  1284.   Verifies password of the user from the most recent zvuser() call.  Returns
  1285.   nonzero if password is valid for user, 0 if it isn't.  Makes any appropriate
  1286.   system log entries (IKSD logins, failed login attempts, etc).  If password
  1287.   is valid, logs the user in as herself (if real user), or sets up restricted
  1288.   anonymous access if user is guest (e.g. changes file-system root to
  1289.   anonroot and sets isguest = 1).
  1290.  
  1291. void
  1292. zsyslog()
  1293.   Begins any desired system logging of an IKSD session.
  1294.  
  1295. void
  1296. zvlogout()
  1297.   Terminates an IKSD session.  In most cases this is simply a wrapper for
  1298.   exit() or doexit(), with some system logging added.
  1299.  
  1300. B.1.3 Security/Privilege Functions (all)
  1301.  
  1302. These functions are used by C-Kermit to adapt itself to operating systems
  1303. where the program can be made to run in a "privileged" mode.  C-Kermit
  1304. should NOT read and write files or start subprocesses as a privileged program.
  1305. This would present a serious threat to system security.  The security package
  1306. has been installed to prevent such security breaches by turning off the
  1307. program's special privileges at all times except when they are needed.
  1308.  
  1309. In UNIX, the only need Kermit has for privileged status is access to the UUCP
  1310. lockfile directory, in order to read, create, and destroy lockfiles, and to
  1311. open communication devices that are normally protected against the user.
  1312. Therefore, privileges should only be enabled for these operations and disabled
  1313. at all other times.  This relieves the programmer of the responsibility of
  1314. putting expensive and unreliable access checks around every file access and
  1315. subprocess creation.
  1316.  
  1317. Strictly speaking, these functions are not required in all C-Kermit
  1318. implementations, because their use (so far, at least) is internal to the group
  1319. 3 modules.  However, they should be included in all C-Kermit implementations
  1320. for operating systems that support the notion of a privileged program (UNIX,
  1321. RSTS/E, what else?).
  1322.  
  1323. int
  1324. priv_ini()
  1325.   Determine whether the program is running in privileged status.  If so,
  1326.   turn off the privileges, in such a way that they can be turned on again
  1327.   when needed.  Called from sysinit() at program startup time.  Returns:
  1328.     0 on success
  1329.     nonzero on failure, in which case the program should halt immediately.
  1330.  
  1331. int
  1332. priv_on()
  1333.   If the program is not privileged, this function does nothing.  If the
  1334.   program is privileged, this function returns it to privileged status.
  1335.   priv_ini() must have been called first.  Returns:
  1336.     0 on success
  1337.     nonzero on failure
  1338.  
  1339. int
  1340. priv_off()
  1341.   Turns privileges off (if they are on) in such a way that they can be
  1342.   turned back on again.  Returns:
  1343.     0 on success
  1344.     nonzero on failure
  1345.  
  1346. int
  1347. priv_can()
  1348.   Turns privileges off in such a way that they cannot be turned back on.
  1349.   Returns:
  1350.     0 on success
  1351.     nonzero on failure
  1352.  
  1353. int
  1354. priv_chk()
  1355.   Attempts to turns privileges off in such a way that they can be turned on
  1356.   again later.  Then checks to make sure that they were really turned off.
  1357.   If they were not really turned off, then they are cancelled permanently.
  1358.   Returns:
  1359.     0 on success
  1360.     nonzero on failure
  1361.  
  1362. B.2.  Console-Related Functions.
  1363.  
  1364. These relate to the program's "console", or controlling terminal, i.e. the
  1365. terminal that the user is logged in on and types commands at, or on a PC or
  1366. workstation, the actual keyboard and screen.
  1367.  
  1368. int
  1369. conbin(esc) char esc;
  1370.   Puts the console into "binary" mode, so that Kermit's command parser can
  1371.   control echoing and other treatment of characters that the user types.
  1372.   esc is the character that will be used to get Kermit's attention during
  1373.   packet mode; puts this in a global place.  Sets the ckxech variable.
  1374.   Returns:
  1375.   -1 on error.
  1376.    0 on success.
  1377.  
  1378. int
  1379. concb(esc) char esc;
  1380.   Put console in "cbreak" (single-character wakeup) mode.  That is, ensure
  1381.   that each console character is available to the program immediately when the
  1382.   user types it.  Otherwise just like conbin().  Returns:
  1383.   -1 on error.
  1384.    0 on success.
  1385.  
  1386. int
  1387. conchk()
  1388.   Returns a number, 0 or greater, the number of characters waiting to be read
  1389.   from the console, i.e. the number of characters that the user has typed that
  1390.   have not been read yet.
  1391.  
  1392. long
  1393. congspd();
  1394.   Returns the speed ("baud rate") of the controlling terminal, if known,
  1395.   otherwise -1L.
  1396.  
  1397. int
  1398. congks(timo) int timo;
  1399.   Get Keyboard Scancode.  Reads a keyboard scan code from the physical console
  1400.   keyboard.  If the timo parameter is greater than zero, then times out and
  1401.   returns -2 if no character appears within the given number of seconds.  Upon
  1402.   any other kind of error, returns -1.  Upon success returns a scan code,
  1403.   which may be any positive integer.  For situations where scan codes cannot
  1404.   be read (for example, when an ASCII terminal is used as the job's
  1405.   controlling terminal), this function is identical to coninc(), i.e. it
  1406.   returns an 8-bit character value.  congks() is for use with workstations
  1407.   whose keyboards have Alternate, Command, Option, and similar modifier keys,
  1408.   and Function keys that generate codes greater than 255.
  1409.  
  1410. int
  1411. congm()
  1412.   Console get modes.  Gets the current console terminal modes and saves them
  1413.   so that conres() can restore them later.  Returns 1 if it got the modes OK,
  1414.   0 if it did nothing (e.g. because Kermit is not connected with any terminal),
  1415.   -1 on error.
  1416.  
  1417. int
  1418. coninc(timo) int timo;
  1419.   Console Input Character.  Reads a character from the console.  If the timo
  1420.   parameter is greater than zero, then coninc() times out and returns -2 if no
  1421.   character appears within the given number of seconds.  Upon any other kind
  1422.   of error, returns -1.  Upon success, returns the character itself, with a
  1423.   value in the range 0-255 decimal.
  1424.  
  1425. VOID
  1426. conint(f,s) SIGTYP (*f)(), (*s)();
  1427.   Sets the console to generate an interrupt if the user types a keyboard
  1428.   interrupt character, and to transfer control the signal-handling function f.
  1429.   For systems with job control, s is the address of the function that suspends
  1430.   the job.  Sets the global variable "backgrd" to zero if Kermit is running in
  1431.   the foreground, and to nonzero if Kermit is running in the background.
  1432.   See ckcdeb.h for the definition of SIGTYP.  No return value.
  1433.  
  1434. VOID
  1435. connoi()
  1436.   Console no interrupts.  Disable keyboard interrupts on the console.
  1437.   No return value.
  1438.  
  1439. int
  1440. conoc(c) char c;
  1441.   Write character c to the console terminal.  Returns:
  1442.   0 on failure, 1 on success.
  1443.  
  1444. int
  1445. conol(s) char *s;
  1446.   Write string s to the console.  Returns -1 on error, 0 or greater on
  1447.   success.
  1448.  
  1449. int
  1450. conola(s) char *s[]; {
  1451.   Write an array of strings to the console.  Returns -1 on error, 0 or greater
  1452.   on success.
  1453.  
  1454. int
  1455. conoll(s) char *s;
  1456.   Write string s to the console, followed by the necessary line termination
  1457.   characters to put the console cursor at the beginning of the next line.
  1458.   Returns -1 on error, 0 or greater on success.
  1459.  
  1460. int
  1461. conres()
  1462.   Restore the console terminal to the modes obtained by congm().  Returns:
  1463.   -1 on error, 0 on success.
  1464.  
  1465. int
  1466. conxo(x,s) int x; char *s;
  1467.   Write x characters from string s to the console.  Returns 0 or greater on
  1468.   success, -1 on error.
  1469.  
  1470. char *
  1471. conkbg();
  1472.   Returns a pointer to the designator of the console keyboard type.
  1473.   For example, on a PC, this function would return "88", "101", etc.
  1474.   Upon failure, returns a pointer to the empty string.
  1475.  
  1476.  
  1477. B.3 - Communication Device Functions
  1478.  
  1479. The communication device is the device used for terminal emulation and file
  1480. transfer.  It may or may not be the same device as the console, and it may
  1481. or may not be a terminal device (it could also be a network device).  For
  1482. brevity, the communication device is referred to here as the "tty".  When the
  1483. communication device is the same as the console device, Kermit is said to be
  1484. in remote mode.  When the two devices are different, Kermit is in local mode.
  1485.  
  1486. int
  1487. ttchk()
  1488.   Returns the number of characters that have arrived at the communication
  1489.   device but have not yet been read by ttinc(), ttinl(), and friends.  If
  1490.   communication input is buffered (and it should be), this is the sum of the
  1491.   number of unread characters in Kermit's buffer PLUS the number of unread
  1492.   characters in the operating system's internal buffer.  The call must be
  1493.   nondestructive and nonblocking, and as inexpensive as possible.
  1494.   Returns:
  1495.    0 or greater on success,
  1496.    0 in case of internal error,
  1497.   -1 or less when it determines the  connection has been broken,
  1498.      or there is no connection.
  1499.   That is, a negative return from ttchk() should reliably indicate that there
  1500.   is no usable connection.  Furthermore, ttchk() should be callable at any
  1501.   time to see if the connection is open.  When the connection is open, every
  1502.   effort must be made to ensure that ttchk returns an accurate number of
  1503.   characters waiting to be read, rather than just 0 (no characters) or 1
  1504.   (1 or more characters), as would be the case when we use select().  This
  1505.   aspect of ttchk's operation is critical to successful operation of sliding
  1506.   windows and streaming, but "nondestructive buffer peeking" is an obscure
  1507.   operating system feature, and so when it is not available, we have to do it
  1508.   ourselves by managing our own internal buffer at a level below ttinc(),
  1509.   ttinl(), etc, as in the UNIX version (non-FIONREAD case).
  1510.  
  1511.   An external global variable, clsondisc, if nonzero, means that if a serial
  1512.   connection drops (carrier on-to-off transition detected by ttchk()), the
  1513.   device should be closed and released automatically.
  1514.  
  1515.  
  1516. int
  1517. ttclos()
  1518.   Closes the communication device (tty or network).  If there were any kind of
  1519.   exclusive access locks connected with the tty, these are released.  If the
  1520.   tty has a modem connection, it is hung up.  For true tty devices, the
  1521.   original tty device modes are restored.  Returns:
  1522.   -1 on failure.
  1523.    0 on success.
  1524.  
  1525. int
  1526. ttflui()
  1527.   Flush communications input buffer.  If any characters have arrived but have
  1528.   not yet been read, discard these characters.  If communications input is
  1529.   buffered by Kermit (and it should be), this function flushes Kermit's buffer
  1530.   as well as the operating system's internal input buffer.
  1531.   Returns:
  1532.   -1 on failure.
  1533.    0 on success.
  1534.  
  1535. int
  1536. ttfluo()
  1537.   Flush tty output buffer.  If any characters have been written but not
  1538.   actually transmitted (e.g. because the system has been flow-controlled),
  1539.   remove them from the system's output buffer.  (Note, this function is
  1540.   not actually used, but it is recommended that all C-Kermit programmers
  1541.   add it for future use, even if it is only a dummy function that returns 0
  1542.   always.)
  1543.  
  1544. int
  1545. ttgmdm()
  1546.   Looks for the modem signals CTS, DSR, and CTS, and returns those that are
  1547.   on in as its return value, in a bit mask as described for ttwmdm,
  1548.   in which a bit is on (1) or off (0) according to whether the corresponding
  1549.   signal is on (asserted) or off (not asserted).  Return values:
  1550.   -3 Not implemented
  1551.   -2 if the line does not have modem control
  1552.   -1 on error
  1553.   >= 0 on success, with bit mask containing the modem signals.
  1554.  
  1555. long
  1556. ttgspd()
  1557.   Returns the current tty speed in BITS (not CHARACTERS) per second, or -1
  1558.   if it is not known or if the tty is really a network, or upon any kind of
  1559.   error.  On success, the speed returned is the actual number of bits per
  1560.   second, like 1200, 9600, 19200, etc.
  1561.  
  1562. int
  1563. ttgwsiz()
  1564.   Get terminal window size.  Returns -1 on error, 0 if the window size can't
  1565.   be obtained, 1 if the window size has been successfully obtained.  Upon
  1566.   success, the external global variables tt_rows and tt_cols are set to the
  1567.   number of screen rows and number of screen columns, respectively.
  1568.   As this function is not implemented in all ck*tio.c modules, calls to it
  1569.   must be wrapped in #ifdef CK_TTGWSIZ..#endif.  NOTE: This function must
  1570.   be available to use the TELNET NAWS feature (Negotiate About Window Size)
  1571.   as well as Rlogin.
  1572.  
  1573. int
  1574. tthang()
  1575.   Hang up the current tty device.  For real tty devices, turn off DTR for
  1576.   about 1/3-1/2 second (or other length of time, depending on the system).
  1577.   If the tty is really a network connection, close it.  Returns:
  1578.   -1 on failure.
  1579.    0 if it does not even try to hang up.
  1580.    1 if it believes it hung up successfully.
  1581.  
  1582. VOID
  1583. ttimoff()
  1584.   Turns off all pending timer interrupts.
  1585.  
  1586. int
  1587. ttinc(timo) int timo; (function is old, return codes are new)
  1588.   Reads one character from the communication device.  If timo is greater than
  1589.   zero, wait the given number of seconds and then time out if no character
  1590.   arrives, otherwise wait forever for a character.  Returns:
  1591.   -3 internal error (e.g. tty modes set wrong)
  1592.   -2 communications disconnect
  1593.   -1 timeout or other error
  1594.   >= 0 the character that was read.
  1595.   It is HIGHLY RECOMMENDED that ttinc() be internally buffered so that calls
  1596.   to it are relatively inexpensive.  If it is possible to to implement ttinc()
  1597.   as a macro, all the better, for example something like:
  1598.  
  1599.   #define ttinc(t) ( (--txbufn >= 0) ? txbuf[ttbufp++] : txbufr(t) )
  1600.  
  1601.   (see description of txbufr() below)
  1602.  
  1603. (ttinl - 5th arg, requirement not to destroy read-ahead characters)
  1604. int
  1605. ttinl(dest,max,timo,eol,start,turn)
  1606.  int max,timo,turn; CHAR *dest, eol, start;
  1607.  
  1608.   ttinl() is Kermit's packet reader.  Reads a packet from the communications
  1609.   device, or up to max characters, whichever occurs first.  A line is a string
  1610.   of characters starting with the start character up to and including the
  1611.   character given in eol or until the length is exhausted, or, if turn != 0,
  1612.   until the line turnaround character (turn) is read.  If turn is 0, ttinl()
  1613.   *should* use the packet length field to detect the end, to allow for the
  1614.   possibility that the eol character appears unprefixed in the packet data.
  1615.   (The turnaround character is for half-duplex linemode connections.)
  1616.  
  1617.   If timo is greater than zero, ttinl() times out if the eol character is not
  1618.   encountered within the given number of seconds and returns -1.
  1619.  
  1620.   The characters that were input are copied into "dest" with their parity bits
  1621.   stripped if parity is not none.  The first character copied into dest should
  1622.   be the start character, and the last should be the final character of the
  1623.   packet (the last block check character).  ttinl() should also absorb and
  1624.   discard the eol and turn characters, and any other characters that are
  1625.   waiting to be read, up until the next start character, so that subsequent
  1626.   calls to ttchk() will not succeed simply because there are some terminators
  1627.   still sitting in the buffer that ttinl() didn't read.  This operation, if
  1628.   performed, MUST NOT BLOCK (so if it can't be performed in a guaranteed
  1629.   nonblocking way, don't do it).
  1630.  
  1631.   On success, ttinl() returns the number of characters read.  Optionally,
  1632.   ttinl() can sense the parity of incoming packets.  If it does this, then it
  1633.   should set the global variable ttprty accordingly.  ttinl() should be coded
  1634.   to be as efficient as possible, since it is at the "inner loop" of packet
  1635.   reception.  ttinl() returns:
  1636.  
  1637.    -1 Timeout or other possibly correctable error.
  1638.    -2 Interrupted from keyboard.
  1639.    -3 Uncorrectable i/o error -- connection lost, configuration problem, etc.
  1640.    >= 0 on success, the number of characters that were actually read
  1641.         and placed in the dest buffer, not counting the trailing null.
  1642.  
  1643. int
  1644. ttoc(c) char c;
  1645.   Outputs the character c to the communication line.  If the operation fails
  1646.   to complete within two seconds, this function returns -1.  Otherwise it
  1647.   returns the number of characters actually written to the tty (0 or 1).  This
  1648.   function should only be used for interactive, character-mode operations, like
  1649.   terminal connection, script execution, dialer i/o, where the overhead of the
  1650.   signals and alarms does not create a bottleneck.  (THIS DESCRIPTION NEEDS
  1651.   IMPROVEMENT -- If the operation fails within a "certain amount of time"...
  1652.   which might be dependent on the communication method, speed, etc.  In
  1653.   particular, flow-control deadlocks must be accounted for and broken out of
  1654.   to prevent the program from hanging indefinitely, etc.)
  1655.  
  1656. int
  1657. ttol(s,n) int n; char *s;
  1658.   Kermit's packet writer.  Writes the n characters of the string pointed to
  1659.   to by s.  NOTE: It is ttol's responsibility to write ALL of the characters,
  1660.   not just some of them.  Returns:
  1661.   -1 on a possibly correctable error (so it can be retried).
  1662.   -3 on a fatal error, e.g. connection lost.
  1663.   >= 0 on success, the actual number of characters written (the specific
  1664.      number is not actually used for anything).
  1665.  
  1666. (ttopen - negative value for modem = network, new timeout feature)
  1667. int
  1668. ttopen(ttname,lcl,modem,timo) char *ttname; int *lcl, modem, timo;
  1669.   Opens a tty device, if it is not already open.  ttopen must check to make
  1670.   sure the SAME device is not already open; if it is, ttopen returns
  1671.   successfully without doing anything.  If a DIFFERENT device is currently
  1672.   open, ttopen() must call ttclos() to close it before opening the new one.
  1673. Parameters:
  1674.     ttname: character string - device name or network host name.
  1675.     lcl:   If called with lcl < 0, sets value of lcl as follows:
  1676.       0: the terminal named by ttname is the job's controlling terminal.
  1677.       1: the terminal named by ttname is not the job's controlling terminal.
  1678.       If the line is already open, or if the requested line can't
  1679.       be opened, then lcl remains (and is returned as) -1.
  1680.     modem:
  1681.       Less than zero: this is the negative of the network type,
  1682.       and ttname is a network host name.  Network types (from ckcnet.h):
  1683.         NET_TCPB 1   TCP/IP Berkeley (socket)  (implemented in ckutio.c)
  1684.         NET_TCPA 2   TCP/IP AT&T (streams)     (not yet implemented)
  1685.         NET_DEC  3   DECnet                    (not yet implemented)
  1686.       Zero or greater: ttname is a terminal device name.
  1687.       Zero means a direct connection (don't use modem signals).
  1688.       Positive means use modem signals depending on the current setting
  1689.       of ttcarr ( see ttscarr() ).
  1690.     timo:
  1691.       > 0: number of seconds to wait for open() to return before timing out.
  1692.       <=0: no timer, wait forever (e.g. for incoming call).
  1693.     For real tty devices, ttopen() attempts to gain exclusive access to the
  1694.     tty device, for example in UNIX by creating a "lockfile" (in other
  1695.     operating systems, like VMS, exclusive access probably requires no special
  1696.     action).
  1697.   Side effects:
  1698.     Copies its arguments and the tty file descriptor to global variables that
  1699.     are available to the other tty-related functions, with the lcl value
  1700.     altered as described above.   Gets all parameters and settings associated
  1701.     with the line and puts them in a global area, so that they can be restored
  1702.     by ttres(), e.g. when the device is closed.
  1703.   Returns:
  1704.     0 on success
  1705.    -5 if device is in use
  1706.    -4 if access to device is denied
  1707.    -3 if access to lock mechanism denied
  1708.    -2 upon timeout waiting for device to open
  1709.    -1 on other error
  1710.  
  1711. int
  1712. ttpkt(speed,flow,parity) long speed; int flow, parity;
  1713.   Puts the currently open tty device into the appropriate modes for
  1714.   transmitting Kermit packets.  The arguments are interpreted as follows:
  1715.   speed: if speed > -1, and the device is a true tty device, and Kermit is in
  1716.          local mode, ttpkt also sets the speed.
  1717.   flow:  if in the range 0-3, ttpkt selects the corresponding type of flow
  1718.          control.  Currently 0 is defined as no flow control, 1 is Xon/Xoff,
  1719.          and no other types are defined.  If (and this is a horrible hack, but
  1720.          it goes back many years and will be hard to eradicate) flow is 4,
  1721.          then the appropriate tty modes are set for modem dialing, a special
  1722.          case in which we talk to a modem-controlled line without requiring
  1723.          carrier.  If flow is 5, then we require carrier.
  1724.   parity:  This is simply copied into a global variable so that other
  1725.          functions (like ttinl, ttinc, etc) can use it.
  1726.   Side effects: Copies its arguments to global variables, flushes the terminal
  1727.          device input buffer.
  1728.   Returns:
  1729.    -1 on error.
  1730.     0 on success.
  1731.  
  1732. int
  1733. ttsetflow(int)
  1734.   Enables the given type of flow control on the open serial communications
  1735.   device immediately.  Arguments are the FLO_xxx values from ckcdeb.h, except
  1736.   FLO_DIAL, FLO_DIAX, or FLO_AUTO, which are not actual flow-control types.
  1737.   Returns 0 on success, -1 on failure.  This definition added 6 Sep 96.
  1738.  
  1739. long *
  1740. ttspdlist() 6 Sep 1997
  1741.   Returns a pointer to an array of longs, or NULL on failure.  On success,
  1742.   element 0 of the array contains number, n, indicating how many follow.
  1743.   Elements 1-n are serial speeds, expressed in bits per second, that are legal
  1744.   on this platform.  The user interface may use this list to construct a menu,
  1745.   keyword table, etc.  As this is a new function, its use is protected by
  1746.   #ifdef TTSPDLIST..#endif.
  1747.  
  1748. int
  1749. ttres()
  1750.   Restores the tty device to the modes and settings that were in effect at
  1751.   the time it was opened (see ttopen).  Returns:
  1752.   -1 on error.
  1753.    0 on success.
  1754.  
  1755. int
  1756. ttruncmd(string) char * string;
  1757.   Runs the given command on the local system, but redirects its input and
  1758.   output to the communication (SET LINE, SET PORT, or SET HOST) device.
  1759.   Returns 1 on success, 0 on failure.
  1760.  
  1761. int
  1762. ttscarr(carrier) int carrier;
  1763.   Copies its argument to a variable that is global to the other tty-related
  1764.   functions, and then returns it.  The values for carrier are defined in
  1765.   ckcdeb.h: CAR_ON, CAR_OFF, CAR_AUTO.  ttopen(), ttpkt(), and ttvt() use this
  1766.   variable when deciding how to open the tty device and what modes to select.
  1767.   The meanings are these:
  1768.   CAR_OFF:  Ignore carrier at all times.
  1769.   CAR_ON:   Require carrier at all times, except when dialing.
  1770.             This means, for example, that ttopen() could hang forever waiting
  1771.             for carrier if it is not present.
  1772.   CAR_AUTO: If the modem type is zero (i.e. the connection is direct), this
  1773.             is the same as CAR_OFF.  If the modem type is positive, then heed
  1774.             carrier during CONNECT (ttvt mode), but ignore it at other times
  1775.             (packet mode, during SET LINE, etc).  Compatible with pre-5A
  1776.             versions of C-Kermit.  This should be the default carrier mode.
  1777.   Kermit's DIAL command ignores the carrier setting, but ttopen(), ttvt(), and
  1778.   ttpkt() all honor the carrier option in effect at the time they are called.
  1779.   None of this applies to remote mode (the tty device is the job's controlling
  1780.   terminal) or to network host connections (modem type is negative).
  1781.  
  1782. int
  1783. ttsndb()
  1784.   Send a BREAK signal on the tty device.  On a real tty device, send a real
  1785.   BREAK lasting approximately 275 milliseconds.  If this is not possible,
  1786.   simulate a BREAK by (for example) dropping down some very low baud rate,
  1787.   like 50, and sending a bunch of null characters.  On a network connection,
  1788.   do the appropriate network protocol for BREAK.  Returns:
  1789.   -1 on error.
  1790.    0 on success.
  1791.  
  1792. int
  1793. ttsndlb()
  1794.   Like ttsndb(), but sends a "Long BREAK" (approx 1.5 seconds).
  1795.   For network connections, it is identical to ttsndb().
  1796.   Currently, this function is used only if CK_LBRK is defined (as it is
  1797.   for UNIX and VAX/VMS).
  1798.  
  1799. int
  1800. ttsspd(cps) int cps; (argument is now cps instead of bps)
  1801.   For real tty devices only, set the device transmission speed to (note
  1802.   carefully) TEN TIMES the argument.  The argument is in characters per
  1803.   second, but transmission speeds are in bits per second.  cps are used rather
  1804.   than bps because high speeds like 38400 are not expressible in a 16-bit int
  1805.   but longs cannot be used because keyword-table values are ints and not longs.
  1806.   If the argument is 7, then the bps is 75, not 70.  If the argument is 888,
  1807.   this is a special code for 75/1200 split-speed operation (75 bps out, 1200
  1808.   bps in).  Returns:
  1809.   -1 on error, meaning the requested speed is not valid or available.
  1810.   >= 0 on success (don't try to use this value for anything).
  1811.  
  1812. int
  1813. ttvt(speed,flow) long speed; int flow;
  1814.   Puts the currently open tty device into the appropriate modes for terminal
  1815.   emulation.  The arguments are interpreted as in ttpkt().  Side effects:
  1816.   ttvt() stores its arguments in global variables, and sets a flag that it has
  1817.   been called so that subsequent calls can be ignored so long as the arguments
  1818.   are the same as in the last effective call.  Other functions, such as
  1819.   ttopen(), ttclose(), ttres(), ttvt(), etc, that change the tty device in any
  1820.   way must unset this flag.  In UNIX Kermit, this flag is called tvtflg.
  1821.  
  1822. int
  1823. ttwmdm(mdmsig,timo) int mdmsig, timo;
  1824.   Waits up to timo seconds for all of the given modem signals to appear.
  1825.   mdmsig is a bit mask, in which a bit is on (1) or off (0) according to
  1826.   whether the corresponding signal is to be waited for.  These symbols are
  1827.   defined in ckcdeb.h:
  1828.      BM_CTS (bit 0) means wait for Clear To Send
  1829.      BM_DSR (bit 1) means wait for Data Set Ready
  1830.      BM_DCD (bit 2) means wait for Carrier Detect
  1831.   Returns:
  1832.     -3 Not implemented.
  1833.     -2 This line does not have modem control.
  1834.     -1 Timeout: time limit exceeded before all signals were detected.
  1835.      1 Success.
  1836.  
  1837. int
  1838. ttxin(n,buf) int n; CHAR *buf;
  1839.   (note: CHAR is used throughout this program, and should be typedef'd to
  1840.   unsigned char if your C compiler supports it.  See ckcdeb.h.)
  1841.   Read x characters from the tty device into the specified buf, stripping
  1842.   parity if parity is not none.  This call waits forever, there is no timeout.
  1843.   This function is designed to be called only when you know that at least x
  1844.   characters are waiting to be read (as determined, for example, by ttchk()).
  1845.   This function should use the same buffer as ttinc().
  1846.  
  1847. int
  1848. txbufr(timo) int timo;
  1849.   Read characters into the interal communications input buffer.  timo is a
  1850.   timeout interval, in seconds.  0 means no timeout, wait forever.  Called by
  1851.   ttinc() (and possibly ttxin() and ttinl()) when the communications input
  1852.   buffer is empty.  The buffer should be called ttxbuf[], its length is
  1853.   defined by the symbol TXBUFL.  The global variable txbufn is the number of
  1854.   characters available to be read from ttxbuf[], and txbufp is the index of
  1855.   the next character to be read.  Should not be called if txbufn > 0, in which
  1856.   case the buffer does not need refilling.  This routine returns:
  1857.    -2    Communications disconnect
  1858.    -1    Timeout
  1859.    >= 0  A character (0 - 255), the first character that was read, with
  1860.          the variables txbufn and txbufp set appropriately for any remaining
  1861.          characters.
  1862.   NOTE: Currently this routine is used internally only by the UNIX and VMS
  1863.   versions.  The aim is to make it available to all versions so there is one
  1864.   single coherent and efficient way of reading from the communications device
  1865.   or network.
  1866.  
  1867. B.4 - Miscellaneous system-dependent functions.
  1868.  
  1869. VOID
  1870. ztime(s) char **s;
  1871.   Returns a pointer, s, to the current date-and-time string in s.  This string
  1872.   must be in the fixed-field format associated with the C runtime asctime()
  1873.   function, like: "Sun Sep 16 13:23:45 1973\n" so that callers of this
  1874.   function can extract the different fields.  The pointer value is filled in
  1875.   by ztime, and the data it points to is not safe, so should be copied to a
  1876.   safe place before use.  ztime() has no return value.  As a side effect,
  1877.   this routine can also fill in the following two external variables (which
  1878.   must be defined in the system-dependendent modules for each platform):
  1879.     long ztusec:  Fraction of seconds of clock time, microseconds.
  1880.     long ztmsec:  Fraction of seconds of clock time, milliseconds.
  1881.   If these variables are not set by zstime(), they remain at their initial
  1882.   value of -1L.
  1883.  
  1884. int
  1885. gtimer()
  1886.   Returns the current value of the elapsed time counter in seconds (see
  1887.   rtimer), or 0 on any kind of error.
  1888.  
  1889. #ifdef GFTIMER
  1890. float
  1891. gtimer()
  1892.   Returns the current value of the elapsed time counter in seconds, as
  1893.   a floating point number, capable of representing not only whole seconds,
  1894.   but also the fractional part, to the millisecond or microsecond level,
  1895.   whatever precision is available.  Requires a function to get times at
  1896.   subsecond precision, as well as floating-point support.  That's why it's
  1897.   #ifdef'd.
  1898. #endif /* GFTIMER */
  1899.  
  1900. int
  1901. msleep(m) int m;
  1902.   Sleeps (pauses, does nothing) for m milliseconds (a millisecond is one
  1903.   thousandth of a second).  Returns:
  1904.   -1 on failure.
  1905.    0 on success.
  1906.  
  1907. VOID
  1908. rtimer()
  1909.   Sets the elapsed time counter to zero.  If you want to time how long an
  1910.   operation takes, call rtimer() when it starts and gtimer when it ends.
  1911.   rtimer() has no return value.
  1912.  
  1913. #ifdef GFTIMER
  1914. VOID
  1915. rftimer()
  1916.   Sets the elapsed time counter to zero.  If you want to time how long an
  1917.   operation takes, call rftimer() when it starts and gftimer when it ends.
  1918.   rftimer() has no return value.  Note: rftimer() is to be used with gftimer()
  1919.   and rtimer() is to be used with gtimer().  See rftimer() description.
  1920. #endif /* GFTIMER */
  1921.  
  1922. int
  1923. sysinit()
  1924.   Does whatever needs doing upon program start.  In particular, if the
  1925.   program is running in any kind of privileged mode, turns off the privileges
  1926.   (see priv_ini()).  Returns:
  1927.   -1 on error.
  1928.    0 on success.
  1929.  
  1930. int
  1931. syscleanup()
  1932.   Does whatever needs doing upon program exit.  Returns:
  1933.   -1 on error.
  1934.    0 on success.
  1935.  
  1936. int
  1937. psuspend()
  1938.   Suspends the Kermit process, puts it in the background so it can be
  1939.   continued ("foregrounded") later.  Returns:
  1940.   -1 if this function is not supported.
  1941.    0 on success.
  1942.  
  1943. GROUP 4 - Network Support.
  1944.  
  1945. As of version 5A, C-Kermit includes support for several networks.  Originally,
  1946. this was just worked into the ttopen(), ttclos(), ttinc(), ttinl(), and
  1947. similar routines in CKUTIO.C.  However, this made it impossible to share this
  1948. code with non-UNIX versions, like VMS.
  1949.  
  1950. As of edit 168, this support has been separated out into its own module and
  1951. header file, CKCNET.C and CKCNET.H.
  1952.  
  1953. As of edit 195, Telnet protocol is split out into its own files, since it
  1954. can be implemented in remote mode, which does not have a network connection:
  1955.  
  1956.   CKCNET.H - Network-related symbol definitions.
  1957.   CKCNET.C - Network i/o (TCP/IP, X.25, etc), shared by most platforms.
  1958.   CKLNET.C - Network i/o (TCP/IP, X.25, etc) specific to Stratus VOS.
  1959.   CKCTEL.H - Telnet protocol symbol definitions.
  1960.   CKCTEL.C - Telnet protocol.
  1961.  
  1962. The routines and variables in these modules fall into two categories: (1)
  1963. support for specific network packages like SunLink X.25 and TGV MultiNet, and
  1964. (2) support for specific network virtual terminal protocols like CCITT X.3 and
  1965. TCP/IP telnet.  Category (1) functions are analogs to the tt*() functions, and
  1966. have names like netopen, netclos, nettinc, etc.  Group I and II modules do not
  1967. (and must not) know anything about these functions -- they continue to call
  1968. the old Group III functions (ttopen, ttinc, etc).  Category (2) functions are
  1969. protocol specific and have names prefixed by a protocol identifier, like tn
  1970. for telnet x25 for X.25.
  1971.  
  1972. CKCNET.H contains prototypes for all these functions, as well as symbol
  1973. definitions for network types, protocols, and network- and protocol- specific
  1974. symbols, as well as #includes for the header files necessary for each network
  1975. and protocol.
  1976.  
  1977. The following functions are to be provided for networks that do not use normal
  1978. system i/o (open, read, write, close):
  1979.  
  1980. int
  1981. netopen()
  1982.   To be called from within ttopen() when a network connection is requested.
  1983.   Calling conventions and purpose same as Group III ttopen().
  1984.  
  1985. int
  1986. netclos()
  1987.   To be called from within ttclos() when a network connection is being closed.
  1988.   Calling conventions and purpose same as Group III ttclos().
  1989.  
  1990. int
  1991. nettchk()
  1992.   To be called from within ttchk().
  1993.   Calling conventions and purpose same as Group III ttchk().
  1994.  
  1995. int
  1996. netflui()
  1997.   To be called from within ttflui().
  1998.   Calling conventions and purpose same as Group III ttflui().
  1999.  
  2000. int
  2001. netbreak()
  2002.   To send a network break (attention) signal.
  2003.   Calling conventions and purpose same as Group III ttsndbrk().
  2004.  
  2005. int
  2006. netinc()
  2007.   To get a character from the network.
  2008.   Calling conventions same as Group III ttsndbrk().
  2009.  
  2010. int
  2011. nettoc()
  2012.   Send a "character" (byte) to the network.
  2013.   Calling conventions same as Group III ttoc().
  2014.  
  2015. int
  2016. nettol()
  2017.   Send a "line" (sequence of bytes) to the network.
  2018.   Calling conventions same as Group III ttol().
  2019.  
  2020. Conceivably, some systems support network connections simply by letting
  2021. you open a device of a certain name and letting you do i/o to it.  Others
  2022. (like the Berkeley sockets TCP/IP library on UNIX) require you to open the
  2023. connection in a special way, but then do normal i/o (read, write).  In such
  2024. a case, you would use netopen(), but you would not use nettinc, nettoc, etc.
  2025.  
  2026. TGV MultiNET on VAX/VMS has its own set of functions for all network
  2027. operations, so in that case the full range of netxxx() functions is used.
  2028.  
  2029. The technique is to put a test in each corresponding ttxxx() function to
  2030. see if a network connection is active (or is being requested), test for which
  2031. kind of network it is, and if necessary route the call to the corresponding
  2032. netxxx() function.  The netxxx() function must also contain code to test for
  2033. the network type, which is available via the global variable ttnet.
  2034.  
  2035. TELNET SUPPORT:
  2036.  
  2037. The telnet protocol is supported by the following variables and routines:
  2038.  
  2039. (global) int tn_init: nonzero if telnet protocol initialized, zero otherwise.
  2040.  
  2041. int
  2042. tn_init()
  2043.   Initialize the telnet protocol (send initial options).
  2044.  
  2045. int
  2046. tn_sopt()
  2047.   Send a telnet option.
  2048.  
  2049. int
  2050. tn_doop()
  2051.   Receive and act on a telnet option from the remote.
  2052.  
  2053. int
  2054. tn_sttyp()
  2055.   Send terminal type using telnet protocol.
  2056.  
  2057. X.25 SUPPORT:
  2058.  
  2059. These are presently specific to SunLink X.25, but it is hoped that they can
  2060. be integrated better with the functions above, and made more general so they
  2061. could be used, for instance, with VAX PSI.
  2062.  
  2063. x25diag()
  2064.   Read and print X.25 diagnostic
  2065.  
  2066. x25oobh()
  2067.   X.25 out of band signal handler
  2068.  
  2069. x25intr()
  2070.   Send X.25 interrupt packet
  2071.  
  2072. x25reset()
  2073.   Reset X.25 virtual circuit
  2074.  
  2075. x25clear()
  2076.   Clear X.25 virtual circuit
  2077.  
  2078. x25stat()
  2079.   X.25 status
  2080.  
  2081. setqbit()
  2082.   Set X.25 Q-bit
  2083.  
  2084. resetqbit()
  2085.   Reset X.25 Q-bit
  2086.  
  2087. x25xin()
  2088.   Read n characters from X.25 circuit.
  2089.  
  2090. x25inl()
  2091.   Read a Kermit packet from X.25 circuit.
  2092.  
  2093. ADDING SUPPORT FOR A NEW NETWORK TYPE
  2094.  
  2095. Example: Adding support for IBM X.25 and Hewlett Packard X.25.
  2096. First, add new network type symbols for each one.  There are already
  2097. some network types defined for other X.25 packages:
  2098.  
  2099.   NET_SX25 is the network-type ID for SunLink X.25.
  2100.   NET_VX25 is the network-type ID for VOS X.25.
  2101.  
  2102. So first you should new symbols for the new network types, giving them
  2103. the next numbers in the sequence, e.g.:
  2104.  
  2105. #define NET_HX25 11            /* Hewlett-Packard X.25 */
  2106. #define NET_IX25 12            /* IBM X.25 */
  2107.  
  2108. This is in ckcnet.h.
  2109.  
  2110. Then we need symbols to say that we are actually compiling in the code
  2111. for these platforms.  These would be defined on the cc command line:
  2112.  
  2113.   -DIBMX25  (for IBM)
  2114.   -DHPX25   (for HP)
  2115.  
  2116. So we can build C-Kermit versions for AIX and HP-UX both with and without
  2117. X.25 support (since not all AIX and IBM systems have the needed libraries,
  2118. and so an executable that was linked with them might no load).
  2119.  
  2120. Then in ckcnet.h:
  2121.  
  2122. #ifdef IBMX25
  2123. #define ANYX25
  2124. #endif /* IBMX25 */
  2125.  
  2126. #ifdef HPX25
  2127. #define ANYX25
  2128. #endif /* HPX25 */
  2129.  
  2130. And then use ANYX25 for code that is common to all of them,
  2131. and IBMX25 or HPX25 for code specific to IBM or HP.
  2132.  
  2133. It might also happen that some code can be shared between two or more of
  2134. these, but not the others.  Suppose, for example, that you write code that
  2135. applies to both IBM and HP, but not Sun or VOS X.25.  Then you add the
  2136. following definition to ckcnet.h:
  2137.  
  2138. #ifndef HPORIBMX25
  2139. #ifdef HPX25
  2140. #define HPORIBMX25
  2141. #else
  2142. #ifdef IBMX25
  2143. #define HPORIBMX25
  2144. #endif /* IBMX25 */
  2145. #endif /* HPX25 */
  2146. #endif /* HPORIBMX25 */
  2147.  
  2148. You can NOT use constructions like "#if defined (HPX25 || IBMX25)"; they
  2149. are not portable (see ckcplm.txt).
  2150.  
  2151. GROUP 5 - Formatted Screen Support
  2152.  
  2153. So far, this is used only for the fullscreen local-mode file transfer display.
  2154. In the future, it might be extended to other uses.  The fullscreen display
  2155. code is in and around the routine screenc() in ckuusx.c.
  2156.  
  2157. In the UNIX version, we use the curses library, plus one call from the termcap
  2158. library.  In other versions (OS/2, VMS, etc) we insert dummy routines that
  2159. have the same names as curses routines.  So far, there are two methods for
  2160. simulating curses routines:
  2161.  
  2162.  1. In VMS, we use the Screen Management Library (SMG), and insert stubs
  2163.     to convert curses calls into SMG calls.
  2164.  
  2165.  2. In OS/2, we use the MYCURSES code, in which the stub routines
  2166.     actually emit the appropriate escape sequences themselves.
  2167.  
  2168. Here are the stub routines:
  2169.  
  2170. tgetent(char *buf, char *term)
  2171.   Arguments are ignored.  Returns 1 if the user has a supported terminal
  2172.   type, 0 otherwise.  Sets a global variable (for example, "isvt52" or
  2173.   "isdasher") to indicate the terminal type.
  2174.  
  2175. move(int row, int col)
  2176.   Sends the escape sequence to position the cursor at the indicated row
  2177.   and column.  The numbers are 0-based, e.g. the home position is 0,0.
  2178.  
  2179. clear()
  2180.   Sends the escape sequence to clear the screen.
  2181.  
  2182. clrtoeol()
  2183.   Sends the escape sequence to clear from the current cursor position to
  2184.   the end of the line.
  2185.  
  2186. In the MYCURSES case, code must be added to each of the last three routines
  2187. to emit the appropriate escape sequences for a new terminal type.
  2188.  
  2189. clearok(curscr), wrefresh()
  2190.   In real curses, these two calls are required to refresh the screen, for
  2191.   example after it was fractured by a broadcast message.  These are useful
  2192.   only if the underlying screen management service keeps a copy of the entire
  2193.   screen, as curses and SMG do.  C-Kermit does not do this itself.
  2194.  
  2195. APPENDIX I - File Permissions
  2196.  
  2197. I.1. Format of System-Dependent File Permissions in A-Packets
  2198.  
  2199. The format of this field (the "," attribute) is interpreted according to the
  2200. System ID ("." Attribute).
  2201.  
  2202. For UNIX (System ID = U1), it's the familiar 3-digit octal number, the
  2203. low-order 9 bits of the filemode: Owner, Group, World, e.g. 660 = read/write
  2204. access for owner and group, none for world, recorded as a 3-digit octal string.
  2205. High-order UNIX permission bits are not transmitted.
  2206.  
  2207. For VMS (System ID = D7), it's a 4-digit hex string, representing the 16-bit
  2208. file protection WGOS fields (World,Group,Owner,System), in that order (which
  2209. is the reverse of how they're shown in a directory listing); in each field,
  2210. Bit 0 = Read, 1 = Write, 2 = Execute, 3 = Delete.  A bit value of 0 means
  2211. permission is granted, 1 means permission is denied.  Sample:
  2212.  
  2213.   r-01-00-^A/!FWERMIT.EXE'"
  2214.   s-01-00-^AE!Y/amd/watsun/w/fdc/new/wermit.exe.DV
  2215.   r-02-01-^A]"A."D7""B8#119980101 18:14:05!#8531&872960,$A20B-!7(#512@ #.Y
  2216.   s-02-01-^A%"Y.5!                                     ^^^^^^
  2217.  
  2218. A VMS directory listing shows the file's protection as (E,RWED,RED,RE) which
  2219. really means (S=E,O=RWED,G=RED,W=RE), which is reverse order from the internal
  2220. storage, so (RE,RED,RWED,E).  Now translate each letter to its corresponding
  2221. bit:
  2222.  
  2223.   RE=0101, RED=1101, RWED=1111, E=0010
  2224.  
  2225. Now reverse the bits:
  2226.  
  2227.   RE=1010, RED=0010, RWED=0000, E=1101
  2228.  
  2229. This gives the 16-bit quantity:
  2230.  
  2231.   1010001000001101
  2232.  
  2233. This is the internal representation of the VMS file permission; in hex:
  2234.  
  2235.   A20B
  2236.  
  2237. as shown in the sample packet above.
  2238.  
  2239. The VMS format probably would also apply to RSX or any other FILES-11 system.
  2240.  
  2241. I.2. Handling of Generic Protection
  2242.  
  2243. To be used when the two systems are different (and/or do not recognize or
  2244. understand each other's local protection codes).
  2245.  
  2246. First of all, the book is wrong.  This should not be the World protection,
  2247. but the Owner protection.  The other fields should be set according to system
  2248. defaults (e.g. UNIX umask, VMS default protection, etc), except that no
  2249. non-Owner field should give more permissions than the Owner field.
  2250.  
  2251. (End of CKCPLM.TXT)
  2252.