home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / cku196.zip / ckcplm.txt < prev    next >
Text File  |  2000-01-01  |  98KB  |  2,241 lines

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