home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / cku200txt.tar / ckcplm.txt < prev    next >
Text File  |  2001-12-14  |  141KB  |  3,087 lines

  1.  
  2.                          C-Kermit Program Logic Manual
  3.                                        
  4.      Frank da Cruz
  5.      [1]The Kermit Project
  6.      [2]Columbia University
  7.      
  8.    As of: C-Kermit 8.0.200, 12 Dec 2001
  9.    This page last updated: Wed Dec 12 09:48:04 2001 (New York USA Time)
  10.    
  11.      IF YOU ARE READING A PLAIN-TEXT version of this document, note that
  12.      this file is a plain-text dump of a Web page. You can visit the
  13.      original (and possibly more up-to-date) Web page here:
  14.      
  15.   [3]http://www.columbia.edu/kermit/ckcplm.html
  16.  
  17.    [ [4]C-Kermit Home ] [ [5]Kermit Home ]
  18.     ________________________________________________________________________
  19.   
  20.   CONTENTS
  21.   
  22.   1. [6]INTRODUCTION
  23.   2. [7]FILES
  24.   3. [8]SOURCE CODE PORTABILITY AND STYLE
  25.   4. [9]MODULES
  26.      4.A. [10]Group A: Library Routines
  27.      4.B. [11]Group B: Kermit File Transfer
  28.      4.C. [12]Group C: Character-Set Conversion
  29.      4.D. [13]Group D: User Interface
  30.      4.E. [14]Group E: Platform-Dependent I/O
  31.      4.F. [15]Group F: Network Support
  32.      4.G. [16]Group G: Formatted Screen Support
  33.      4.H. [17]Group H: Pseudoterminal Support
  34.      4.I. [18]Group I: Security
  35.   I. [19]APPENDIX I: FILE PERMISSIONS
  36.     ________________________________________________________________________
  37.   
  38.   1. INTRODUCTION
  39.   
  40.    The Kermit Protocol is specified in the book Kermit, A File Transfer
  41.    Protocol by Frank da Cruz, Digital Press / Butterworth Heinemann,
  42.    Newton, MA, USA (1987), 379 pages, ISBN 0-932376-88-6. It is assumed
  43.    the reader is familiar with the Kermit protocol specification.
  44.    
  45.    This file describes the relationship among the modules and functions
  46.    of C-Kermit 5A and later, and other programming considerations.
  47.    C-Kermit is designed to be portable to any kind of computer that has a
  48.    C compiler. The source code is broken into many files that are grouped
  49.    according to their function, as shown in the [20]Contents.
  50.    
  51.    C-Kermit has seen constant development since 1985. Throughout its
  52.    history, there has been a neverending tug-of-war among:
  53.    
  54.     a. Functionality: adding new features, fixing bugs, improving
  55.        performance.
  56.     b. Adding support for new platforms.
  57.     c. "Buzzword 1.0 compliance".
  58.        
  59.    The latter category is the most frustrating, since it generally
  60.    involves massive changes just to keep the software doing what it did
  61.    before in some new setting: e.g. the K&R-to-ANSIC conversion (which
  62.    had to be done, of course, without breaking K&R); Y2K (not a big deal
  63.    in our case); the many and varied UNIX and other API "standards";
  64.    IPv6.
  65.    
  66.    [ [21]Contents ] [ [22]C-Kermit ] [ [23]Kermit Home ]
  67.     ________________________________________________________________________
  68.   
  69.   2. FILES
  70.   
  71.    C-Kermit source files begin with the two letters "ck", for example
  72.    ckutio.c. Filenames are kept short (6.3) for maximum portability and
  73.    (obviously I hope) do not contain spaces or more than one period. The
  74.    third character in the name denotes something about the function group
  75.    and the expected level of portability:
  76.    
  77.      a General descriptive material and documentation (text)
  78.      b BOO file encoders and decoders (obsolete)
  79.      c All platforms with C compilers (*)
  80.      d Data General AOS/VS
  81.      e Reserved for "ckermit" files, like ckermit.ini, ckermit2.txt
  82.      f (reserved)
  83.      g (reserved)
  84.      h (reserved)
  85.      i Commodore Amiga (Intuition)
  86.      j (unused)
  87.      k (unused)
  88.      l Stratus VOS
  89.      m Macintosh with Mac OS 1-9
  90.      n Microsoft Windows NT/2000/XP
  91.      o OS/2 and/or Microsoft Windows 9x/ME/NT/2000/XP
  92.      p Plan 9 from Bell Labs
  93.      q (reserved)
  94.      r DEC PDP-11 with RSTS/E (never used, open for reassigment)
  95.      s Atari ST GEMDOS (last supported in version 5A(189))
  96.      t DEC PDP-11 with RT-11 (never used, open for reassigment)
  97.      u Unix-based operating systems (*)
  98.      v VMS and OpenVMS
  99.      w Wart (Lex-like preprocessor, platform independent)
  100.      x (reserved)
  101.      y (reserved)
  102.      z (reserved)
  103.      0-3 (reserved)
  104.      4 IBM AS/400
  105.      5-8   (reserved)
  106.      9 Microware OS-9
  107.      _ Encryption modules
  108.      
  109.    (*) In fact there is little distinction between the ckc*.* and cku*.*
  110.    categories. It would make more sense for all cku*.* modules to be
  111.    ckc*.* ones, except ckufio.c, ckutio.c, ckucon.c, ckucns.c, and
  112.    ckupty.c, which truly are specific to Unix. The rest (ckuus*.c,
  113.    ckucmd.c, etc) are quite portable.
  114.    
  115.    One hint before proceeding: functions are scattered all over the
  116.    ckc*.c and cku*.c modules, where function size has begun to take
  117.    precedence over the desirability of grouping related functions
  118.    together, the aim being to keep any particular module from growing
  119.    disproportionately large. The easiest way (in UNIX) to find out in
  120.    what source file a given function is defined is like this (where the
  121.    desired function is foo()...):
  122.    
  123.   grep ^foo\( ck*.c
  124.  
  125.    This works because the coding convention has been to make function
  126.    names always start on the left margin with their contents indented,
  127.    for example:
  128.    
  129. static char *
  130. foo(x,y) int x, y; {
  131.     ...
  132. }
  133.  
  134.    Also note the style for bracket placement. This allows
  135.    bracket-matching text editors (such as EMACS) to help you make sure
  136.    you know which opening bracket a closing bracket matches, particularly
  137.    when the opening bracket is above the visible screen, and it also
  138.    makes it easy to find the end of a function (search for '}' on the
  139.    left margin).
  140.    
  141.    Of course EMACS tags work nicely with this format too:
  142.    
  143.   $ cd kermit-source-directory
  144.   $ etags ck[cu]*.c
  145.   $ emacs
  146.   Esc-X Visit-Tags-Table<CR><CR>
  147.  
  148.    (but remember that the source file for ckcpro.c is [24]ckcpro.w!)
  149.    
  150.    Also:
  151.    
  152.      * Tabs should be set every 8 spaces, as on a VT100.
  153.      * All lines must no more than 79 characters wide after tab
  154.        expansion.
  155.      * Note the distinction between physical tabs (ASCII 9) and the
  156.        indentation conventions, which are: 4 for block contents, 2 for
  157.        most other stuff (obviously this is not a portability issue, just
  158.        style).
  159.        
  160.    [ [25]Contents ] [ [26]C-Kermit ] [ [27]Kermit Home ]
  161.     ________________________________________________________________________
  162.   
  163.   3. SOURCE CODE PORTABILITY AND STYLE
  164.   
  165.    C-Kermit was designed in 1985 as a platform-independent replacement
  166.    for the earlier Unix Kermit. c-Kermit's design was expected to promote
  167.    portability, and judging from the number of platforms to which it has
  168.    been adapted since then, the model is effective, if not ideal
  169.    (obviously if we had it all to do over, we'd change a few things). To
  170.    answer the oft-repeated question: "Why are there so many #ifdefs?",
  171.    it's because:
  172.    
  173.      * Many of them are related to feature selection and program size,
  174.        and so need to be there anyway.
  175.      * Those that treat compiler, library, platform, header-file, and
  176.        similar differences have built up over time as hundreds of people
  177.        all over the world adapted C-Kermit to their particular
  178.        environments and sent back their changes. There might be more
  179.        politically-correct ways to achieve portability, but this one is
  180.        natural and proven. The basic idea is to introduce changes that
  181.        can be selected by defining a symbol, which, if not defined,
  182.        leaves the program exactly as it was before the changes.
  183.      * Although it might be possible to "clean up" the "#ifdef mess",
  184.        nobody has access to all the hundreds of platforms served by the
  185.        #ifdefs to check the results.
  186.        
  187.    And to answer the second-most-oft-repeated question: "Why don't you
  188.    just use GNU autoconfig / automake / autowhatever instead of
  189.    hard-coding all those #ifdefs?" Answers:
  190.    
  191.      * The GNU tools are not available on all the platforms where
  192.        C-Kermit must be built and I wouldn't necessarily trust them if
  193.        they were.
  194.      * Each platform is a moving target, so the tools themselves would
  195.        need to updated before Kermit could be updated.
  196.      * It would only add another layer of complexity to an already
  197.        complex process.
  198.      * Conversion at this point would not be practical unless there was a
  199.        way to test the results on all the hundreds of platforms where
  200.        C-Kermit is supposed to build.
  201.        
  202.    When writing code for the system-indendent C-Kermit modules, please
  203.    stick to the following coding conventions to ensure portability to the
  204.    widest possible variety of C preprocessors, compilers, and linkers, as
  205.    well as certain network and/or email transports. The same holds true
  206.    for many of the "system dependent" modules too; particularly the Unix
  207.    ones, since they must be buildable by a wide variety of compilers and
  208.    linkers, new and old.
  209.    
  210.    This list does not purport to be comprehensive, and although some
  211.    items on it might seem far-fetched, they would not be listed unless I
  212.    had encountered them somewhere, some time. I wish I had kept better
  213.    records so I could cite specific platforms and compilers.
  214.    
  215.      * Try to keep variable and function names unique within 6
  216.        characters, especially if they are used across modules, since 6 is
  217.        the maximum for some old linkers (actually, this goes back to
  218.        TOPS-10 and -20 and other old DEC OS's where C-Kermit never ran
  219.        anyway; a more realistic maximum is probably somewhere between 8
  220.        and 16). We know for certain that VAX C has a 31-character max
  221.        because it complains -- others might not complain, but just
  222.        silently truncate, thus folding two or more routines/variables
  223.        into one.
  224.      * Keep preprocessor symbols unique within 8 characters; that's the
  225.        max for some preprocessors (sorry, I can't give a specific
  226.        example, but in 1988 or thereabouts, I had to change character-set
  227.        symbols like TC_LATIN1 and TC_LATIN2 to TC_1LATIN and TC_2LATIN
  228.        because the digits were being truncated and ignored on a platform
  229.        where I actually had to build C-Kermit 5A; unfortunately I didn't
  230.        note which platform -- maybe some early Ultrix version?)
  231.      * Don't create preprocessor symbols, or variable or function names,
  232.        that start with underscore (_). These are usually reserved for
  233.        internal use by the compiler and header files.
  234.      * Don't put #include directives inside functions or { blocks }.
  235.      * Don't use the #if or #elif preprocessor constructions, only use
  236.        #ifdef, #ifndef, #define, #undef, and #endif.
  237.      * Put tokens after #endif in comment brackets, e.g.
  238.        #endif /* FOO */.
  239.      * Don't indent preprocessor statements - # must always be first char
  240.        on line.
  241.      * Don't put whitespace after # in preprocessor statements.
  242.      * Don't use #pragma, even within #ifdefs -- it makes some
  243.        preprocessors give up.
  244.      * Same goes for #module, #if, etc - #ifdefs do NOT protect them.
  245.      * Don't use logical operators in preprocessor constructions.
  246.      * Avoid #ifdefs inside argument list to function calls (I can't
  247.        remember why this one is here, but probably needn't be; we do this
  248.        all the time).
  249.      * Always cast strlen() in expressions to int:
  250.        if ((int)strlen(foo) < x)...
  251.      * Any variable whose value might exceed 16383 should be declared as
  252.        long, or if that is not possible, then as unsigned.
  253.      * Avoid typedefs; they might be portable but they are very confusing
  254.        and there's no way to test for their presence or absence at
  255.        compile time. Use preprocessor symbols instead if possible; at
  256.        least you can test their definitions.
  257.      * Unsigned long is not portable; use a preprocessor symbol (Kermit
  258.        uses ULONG for this).
  259.      * Long long is not portable. If you really need it, be creative.
  260.      * Similarly 1234LL is not portable, nor almost any other constant
  261.        modifier other than L.
  262.      * Unsigned char is not portable, use CHAR (a preprocessor symbol
  263.        defined in the Kermit header files) and always take precautions
  264.        against character signage (more about this [28]below).
  265.      * Don't use initializers with automatic arrays or structs: it's not
  266.        portable.
  267.      * Don't use big automatic arrays or structs in functions that might
  268.        be called recursively; some platforms have fixed-size stacks (e.g.
  269.        Windows 9x: 256K) and recursive functions crash with stack
  270.        overflow. Even when there is not a compiler limitation, this
  271.        causes memory to be consumed without bound, and can end up filling
  272.        swap space.
  273.      * Don't assume that struct assignment performs a copy, or that it
  274.        even exists.
  275.      * Don't use sizeof to get the size of an array; someone might come
  276.        along later and and change it from static to malloc'd. Always use
  277.        a symbol to refer to the array's size.
  278.      * Don't put prototypes for static functions into header files that
  279.        are used by modules that don't contain that function; the link
  280.        step can fail with unresolved references (e.g. on AOS/VS).
  281.      * Avoid the construction *++p (the order of evaluation varies; it
  282.        shouldn't but at least one compiler had a bug that made me include
  283.        this item).
  284.      * Don't use triple assignments, like a = b = c = 0; (or quadruple,
  285.        etc). Some compilers generate bad code for these, or crash, etc
  286.        (some version of DEC C as I recall).
  287.      * Some compilers don't allow structure members to have the same
  288.        names as other identifiers. Try give structure members unique
  289.        names.
  290.      * Don't assume anything about order of evaluation in boolean
  291.        expressions, or that they will stop early if a required condition
  292.        is not true, e.g.:
  293.  
  294.   if (i > 0 && p[i-1] == blah)
  295.        can still dump core if i == 0 (hopefully this is not true of any
  296.        modern compiler, but I would not have said this if it did not
  297.        actually happen somewhere).
  298.      * Don't have a switch() statement with no cases (e.g. because of
  299.        #ifdefs); this is a fatal error in some compilers.
  300.      * Don't put lots of code in a switch case; move it out to a separate
  301.        function; some compilers run out of memory when presented with a
  302.        huge switch() statement -- it's not the number of cases that
  303.        matters; it's the overall amount of code.
  304.      * Some compilers might also limit the number of switch() cases, e.g.
  305.        to 254.
  306.      * Don't put anything between "switch() {" and "case:" -- switch
  307.        blocks are not like other blocks.
  308.      * Don't jump into or out of switches.
  309.      * Don't make character-string constants longer than about 250 bytes.
  310.        Longer strings should be broken up into arrays of strings.
  311.      * Don't write into character-string constants (obviously). Even when
  312.        you know you are not writing past the end; the compiler or linker
  313.        might have put them into read-only and/or shared memory, and/or
  314.        coalesced multiple equal constants so if you change one you change
  315.        them all.
  316.      * Don't depend on '\r' being carriage return.
  317.      * Don't depend on '\n' being linefeed or for that matter any SINGLE
  318.        character.
  319.      * Don't depend on '\r' and '\n' being different (e.g. as separate
  320.        switch() cases).
  321.      * In other words, don't use \n or \r to stand for specific
  322.        characters; use \012 and \015 instead.
  323.      * Don't code for "buzzword 1.0 compliance", unless "buzzword" is K&R
  324.        and "1.0" is the first edition.
  325.      * Don't use or depend on anything_t (size_t, pid_t, etc), except
  326.        time_t, without #ifdef protection (time_t is the only one I've
  327.        found that accepted everywhere). This is a tough one because the
  328.        same function might require (say) a size_t arg on one platform,
  329.        whereas size_t is unheard of on another; or worse, it might
  330.        require a totally different data type, like int or long or some
  331.        other typedef'd thing. It has often proved necessary to define a
  332.        symbol to stand for the type of a particular argument to a
  333.        particular library or system function to get around this problem.
  334.      * Don't use or depend on internationalization ("i18n") features,
  335.        wchar_t, locales, etc, in portable code; they are not portable.
  336.        Anyway, locales are not the right model for Kermit's
  337.        multi-character-set support. Kermit does all character-set
  338.        conversion itself and does not use any external libraries or
  339.        functions.
  340.      * In particular, don't use any library functions that deal with wide
  341.        characters or Unicode in any form. These are not only nonportable,
  342.        but a constantly shifting target (e.g. the ones in glibc).
  343.      * Don't make any assumption about signal handler type. It can be
  344.        void, int, long, or anything else. Always declare signal handlers
  345.        as SIGTYP (see definition in ckcdeb.h and augment it if necessary)
  346.        and always use SIGRETURN at exit points from signal handlers.
  347.      * Signals should always be re-armed to be used again (this barely
  348.        scratches the surface -- the differences between BSD/V7 and System
  349.        V and POSIX signal handling are numerous, and some platforms do
  350.        not even support signals, alarms, or longjmps correctly or at all
  351.        -- avoid all of this if you can).
  352.      * On the other hand, don't assume that signals are disarmed after
  353.        being raised. In some platforms you have to re-arm them, in others
  354.        they stay armed.
  355.      * Don't call malloc() and friends from a signal handler; don't do
  356.        anything but setting integer global variables in a signal handler.
  357.      * malloc() does not initialize allocated memory -- it never said it
  358.        did. Don't expect it to be all 0's.
  359.      * Did You Know: malloc() can succeed and the program can still dump
  360.        core later when it attempts to use the malloc'd memory? (This
  361.        happens when allocation is deferred until use and swap space is
  362.        full.)
  363.      * memset(), memmove(), and memcpy() are not portable, don't use them
  364.        without protecting them in ifdefs (we have USE_MEMCPY for this).
  365.        bzero()/bcopy() too, except we're guaranteed to have
  366.        bzero()/bcopy() when using the sockets library (not really). See
  367.        examples in the source.
  368.      * Don't assume that strncpy() stops on the first null byte -- most
  369.        versions always copy the number of bytes given in arg 3, padding
  370.        out with 0's and overwriting whatever was there before. Use
  371.        C-Kermit ckstrncpy() if you want predictable non-padding behavior,
  372.        guaranteed NUL-termination, and a useful return code.
  373.      * DID YOU KNOW.. that some versions of inet_blah() routines return
  374.        IP addresses in network byte order, while others return them local
  375.        machine byte order? So passing them to ntohs() or whatever is not
  376.        always the right thing to do.
  377.      * Don't use ANSI-format function declarations without #ifdef
  378.        CK_ANSIC, and always provide an #else for the non-ANSI case.
  379.      * Use the Kermit _PROTOTYP() macro for declaring function
  380.        prototypes; it works in both the ANSI and non-ANSI cases.
  381.      * Don't depend on any other ANSI preprocessor features like
  382.        "pasting" -- they are often missing or nonoperational.
  383.      * Don't assume any C++ syntax or semantics.
  384.      * Don't use // as a comment introducer. C is not C++.
  385.      * Don't declare a string as "char foo[]" in one module and "extern
  386.        char * foo" in another, or vice-versa: this causes core dumps.
  387.      * With compiler makers falling all over themselves trying to outdo
  388.        each other in ANSI strictness, it has become increasingly
  389.        necessary to cast EVERYTHING. This is increasingly true for char
  390.        vs unsigned char. We need to use unsigned chars if we want to deal
  391.        with 8-bit character sets, but most character- and string-oriented
  392.        APIs want (signed) char arguments, so explicit casts are
  393.        necessary. It would be nice if every compiler had a
  394.        -funsigned-char option (as gcc does), but they don't.
  395.      * a[x], where x is an unsigned char, can produce a wild memory
  396.        reference if x, when promoted to an int, becomes negative. Cast it
  397.        to (unsigned), even though it ALREADY IS unsigned.
  398.      * Be careful how you declare functions that have char or long
  399.        arguments; for ANSI compilers you MUST use ANSI declarations to
  400.        avoid promotion problems, but you can't use ANSI declarations with
  401.        non-ANSI compilers. Thus declarations of such functions must be
  402.        hideously entwined in #ifdefs. Example: latter:
  403.  
  404.   int                          /*  Put character in server command buffer  */
  405.   #ifdef CK_ANSIC
  406.   putsrv(char c)
  407.   #else
  408.   putsrv(c) char c;
  409.   #endif /* CK_ANSIC */
  410.   /* putsrv */ {
  411.       *srvptr++ = c;
  412.       *srvptr = '\0';           /* Make sure buffer is null-terminated */
  413.       return(0);
  414.   }
  415.      * Be careful how you return characters from functions that return
  416.        int values -- "getc-like functions" -- in the ANSI world. Unless
  417.        you explicitly cast the return value to (unsigned), it is likely
  418.        to be "promoted" to an int and have its sign extended.
  419.      * At least one compiler (the one on DEC OSF/1 1.3) treats "/*" and
  420.        "*/" within string constants as comment begin and end. No amount
  421.        of #ifdefs will get around this one. You simply can't put these
  422.        sequences in a string constant, e.g. "/usr/local/doc/*.*".
  423.      * Avoid putting multiple macro references on a single line, e.g.:
  424.  
  425.   putchar(BS); putchar(SP); putchar(BS)
  426.  
  427.    This overflows the CPP output buffer of more than a few C
  428.    preprocessors (this happened, for example, with SunOS 4.1 cc, which
  429.    evidently has a 1K macro expansion buffer).
  430.    
  431.    C-Kermit needs constant adjustment to new OS and compiler releases.
  432.    Every new OS release shuffles header files or their contents, or
  433.    prototypes, or data types, or levels of ANSI strictness, etc. Every
  434.    time you make an adjustment to remove a new compilation error, BE VERY
  435.    CAREFUL to #ifdef it on a symbol unique to the new configuration so
  436.    that the previous configuration (and all other configurations on all
  437.    other platforms) remain as before.
  438.    
  439.    Assume nothing. Don't assume header files are where they are supposed
  440.    to be, that they contain what you think they contain, that they define
  441.    specific symbols to have certain values -- or define them at all!
  442.    Don't assume system header files protect themselves against multiple
  443.    inclusion. Don't assume that particular system or library calls are
  444.    available, or that the arguments are what you think they are -- order,
  445.    data type, passed by reference vs value, etc. Be conservative when
  446.    attempting to write portable code. Avoid all advanced features.
  447.    
  448.    If you see something that does not make sense, don't assume it's a
  449.    mistake -- it might be there for a reason, and changing it or removing
  450.    is likely to cause compilation, linking, or runtime failures sometime,
  451.    somewhere. Some huge percentage of the code, especially in the
  452.    platform-dependent modules, is workarounds for compiler, linker, or
  453.    API bugs.
  454.    
  455.    But finally... feel free to violate any or all of these rules in
  456.    platform-specific modules for environments in which the rules are
  457.    certain not to apply. For example, in VMS-specific code, it is OK to
  458.    use #if, because VAX C, DEC C, and VMS GCC all support it.
  459.    
  460.    [ [29]Contents ] [ [30]C-Kermit ] [ [31]Kermit Home ]
  461.     ________________________________________________________________________
  462.   
  463.   3.1. Memory Leaks
  464.   
  465.    The C language and standard C library are notoriously inadequate and
  466.    unsafe. Strings are arrays of characters, usually referenced through
  467.    pointers. There is no native string datatype. Buffers are fixed size,
  468.    and C provides no runtime bounds checking, thus allowing overwriting
  469.    of other data or even program code. With the popularization of the
  470.    Internet, the "buffer exploit" has become a preferred method for
  471.    hackers to hijack privileged programs; long data strings are fed to a
  472.    program in hopes that it uses unsafe C library calls such as strcpy()
  473.    or sprintf() to copy strings into automatic arrays, thus overwriting
  474.    the call stack, and therefore the routine's return address. When such
  475.    a hole is discovered, a "string" can be constructed that contains
  476.    machine code to hijack the program's privileges and penetrate the
  477.    system.
  478.    
  479.    This problem is partially addressed by the strn...() routines, which
  480.    should always be used in preference to their str...() equivalents
  481.    (except when the copy operation has already been prechecked, or there
  482.    is a good reason for not using them, e.g. the sometimes undesirable
  483.    side effect of strncpy() zeroing the remainder of the buffer). The
  484.    most gaping whole, however, is sprintf(), which performs no length
  485.    checking on its destination buffer, and is not easy to replace.
  486.    Although snprintf() routines are starting to appear, they are not yet
  487.    widespread, and certainly not universal, nor are they especially
  488.    portable, or even full-featured.
  489.    
  490.    For these reasons, we have started to build up our own little library
  491.    of C Library replacements, ckclib.[ch]. These are safe and highly
  492.    portable primitives for memory management and string manipulation,
  493.    such as:
  494.    
  495.    ckstrncpy()
  496.           Like strncpy but returns a useful value, doesn't zero buffer.
  497.           
  498.    ckitoa()
  499.           Opposite of atoi()
  500.           
  501.    ckltoa()
  502.           Opposite of atol()
  503.           
  504.    ckctoa()
  505.           Returns character as string
  506.           
  507.    ckmakmsg()
  508.           Used with ck?to?() as a safe sprintf() replacement for up to 4
  509.           items
  510.           
  511.    ckmakxmsg()
  512.           Like ckmakmsg() but accepts up to 12 items
  513.           
  514.    More about library functions in [32]Section 4.A.
  515.    
  516.    [ [33]Contents ] [ [34]C-Kermit ] [ [35]Kermit Home ]
  517.     ________________________________________________________________________
  518.   
  519.   3.2. The "char" vs "unsigned char" Dilemma
  520.   
  521.    This is one of the most aggravating and vexing characteristics of the
  522.    C language. By design, chars (and char *'s) are SIGNED. But in the
  523.    modern era, however, we need to process characters that can have (or
  524.    include) 8-bit values, as in the ISO Latin-1, IBM CP 850, or UTF-8
  525.    character sets, so this data must be treated as unsigned. But some C
  526.    compilers (such as those based on the Bell UNIX V7 compiler) do not
  527.    support "unsigned char" as a data type. Therefore we have the macro or
  528.    typedef CHAR, which we use when we need chars to be unsigned, but
  529.    which, unfortunately, resolves itself to "char" on those compilers
  530.    that don't support "unsigned char". AND SO... We have to do a lot of
  531.    fiddling at runtime to avoid sign extension and so forth.
  532.    
  533.    Some modern compilers (e.g. IBM, DEC, Microsoft) have options that say
  534.    "make all chars be unsigned" (e.g. GCC "-funsigned-char") and we use
  535.    them when they are available. Other compilers don't have this option,
  536.    and at the same time, are becoming increasingly strict about type
  537.    mismatches, and spew out torrents of warnings when we use a CHAR where
  538.    a char is expected, or vice versa. We fix these one by one using
  539.    casts, and the code becomes increasingly ugly. But there remains a
  540.    serious problem, namely that certain library and kernel functions have
  541.    arguments that are declared as signed chars (or pointers to them),
  542.    whereas our character data is unsigned. Fine, we can can use casts
  543.    here too -- but who knows what happens inside these routines.
  544.    
  545.    [ [36]Contents ] [ [37]C-Kermit ] [ [38]Kermit Home ]
  546.     ________________________________________________________________________
  547.   
  548.   4. MODULES
  549.   
  550.    When C-Kermit is on the far end of a connection, it is said to be in
  551.    remote mode. When C-Kermit has made a connection to another computer,
  552.    it is in local mode. (If C-Kermit is "in the middle" of a multihop
  553.    connection, it is still in local mode.)
  554.    
  555.    On another axis, C-Kermit can be in any of several major states:
  556.    
  557.    Command State
  558.           Reading and writing from the job's controlling terminal or
  559.           "console". In this mode, all i/o is handled by the Group E
  560.           conxxx() (console i/o) routines.
  561.           
  562.    Protocol State
  563.           Reading and writing from the communicatons device. In this
  564.           mode, all i/o is handled by the Group E ttxxx() (terminal i/o)
  565.           routines.
  566.           
  567.    Terminal State
  568.           Reading from the keyboard with conxxx() routines and writing to
  569.           the communications device with ttxxx() routines AND vice-versa.
  570.           
  571.    When in local mode, the console and communications device are
  572.    distinct. During file transfer, Kermit may put up a file-transfer
  573.    display on the console and sample the console for interruption
  574.    signals.
  575.    
  576.    When in remote mode, the console and communications device are the
  577.    same, and therefore there can be no file-transfer display on the
  578.    console or interruptions from it (except for "in-band" interruptions
  579.    such as ^C^C^C).
  580.    
  581.    [ [39]Contents ] [ [40]C-Kermit ] [ [41]Kermit Home ]
  582.     ________________________________________________________________________
  583.   
  584.   4.A. Group A: Library Functions
  585.   
  586.    Library functions, strictly portable, can be used by all modules on
  587.    all platforms: [42]ckclib.h, [43]ckclib.c.
  588.    
  589.    (To be filled in... For now, see [44]Section 3.1 and the comments in
  590.    ckclib.c.)
  591.    
  592.    [ [45]Contents ] [ [46]C-Kermit ] [ [47]Kermit Home ]
  593.     ________________________________________________________________________
  594.   
  595.   4.B. Group B: Kermit File Transfer
  596.   
  597.    The Kermit protocol kernel. These files, whose names start with "ckc
  598.    are supposed to be totally portable C, and are expected to compile
  599.    correctly on any platform with any C compiler. "Portable" does not
  600.    mean the same as as "ANSI" -- these modules must compile on 10- and
  601.    20-year old computers, with C preprocessors, compilers, and/or linkers
  602.    that have all sorts of restrictions. The Group B modules do not
  603.    include any header files other than those that come with Kermit
  604.    itself. They do not contain any library calls except from the standard
  605.    C library (e.g. printf()). They most certainly do not contain any
  606.    system calls. Files:
  607.    
  608.    [48]ckcsym.h
  609.           For use by C compilers that don't allow -D on the command line.
  610.           
  611.    [49]ckcasc.h
  612.           ASCII character symbol definitions.
  613.           
  614.    [50]ckcsig.h
  615.           System-independent signal-handling definitions and prototypes.
  616.           
  617.    [51]ckcdeb.h
  618.           Originally, debugging definitions. Now this file also contains
  619.           all definitions and prototypes that are shared by all modules
  620.           in all groups.
  621.           
  622.    [52]ckcker.h
  623.           Kermit protocol symbol definitions.
  624.           
  625.    [53]ckcxla.h
  626.           Character-set-related symbol definitions (see next section).
  627.           
  628.    [54]ckcmai.c
  629.           The main program. This module contains the declarations of all
  630.           the protocol-related global variables that are shared among the
  631.           other modules.
  632.           
  633.    [55]ckcpro.w
  634.           The protocol module itself, written in "wart", a lex-like
  635.           preprocessor that is distributed with Kermit under the name
  636.           CKWART.C.
  637.           
  638.    [56]ckcfns.c, [57]ckcfn2.c, [58]ckcfn3.c
  639.           The protocol support functions used by the protocol module.
  640.           
  641.    [59]Group B modules may call upon functions from [60]Group E, but not
  642.    from [61]Group D modules (with the single exception that the main
  643.    program invokes the user interface, which is in Group D). (This last
  644.    assertion is really only a conjecture.)
  645.    
  646.    [ [62]Contents ] [ [63]C-Kermit ] [ [64]Kermit Home ]
  647.     ________________________________________________________________________
  648.   
  649.   4.C. Group C: Character-Set Conversion
  650.   
  651.    Character set translation tables and functions. Used by the [65]Group
  652.    B, protocol modules, but may be specific to different computers. (So
  653.    far, all character character sets supported by C-Kermit are supported
  654.    in [66]ckuxla.c and [67]ckuxla.h, including Macintosh and IBM
  655.    character sets). These modules should be completely portable, and not
  656.    rely on any kind of system or library services.
  657.    
  658.    [68]ckcxla.h
  659.           Character-set definitions usable by all versions of C-Kermit.
  660.           
  661.    ck?xla.h
  662.           Character-set definitions for computer "?", e.g. [69]ckuxla.h
  663.           for UNIX, [70]ckmxla.h for Macintosh.
  664.           
  665.    [71]ck?xla
  666.           Character-set translation tables and functions for computer
  667.           "?", For example, CKUXLA.C for UNIX, CKMXLA.C for Macintosh. So
  668.           far, these are the only two such modules. The UNIX module is
  669.           used for all versions of C-Kermit except the Macintosh version.
  670.           
  671.    [72]ckcuni.h
  672.           Unicode definitions
  673.           
  674.    [73]ckcuni.c
  675.           Unicode module
  676.           
  677.    Here's how to add a new file character set in the original
  678.    (non-Unicode modules). Assuming it is based on the Roman (Latin)
  679.    alphabet. Let's call it "Barbarian". First, in ck?xla.h, add a
  680.    definition for FC_BARBA (8 chars maximum length) and increase
  681.    MAXFCSETS by 1. Then, in ck?xla.c:
  682.    
  683.      * Add a barbarian entry into the fcsinfo array.
  684.      * Add a "barbarian" entry to file character set keyword table,
  685.        fcstab.
  686.      * Add a "barbarian" entry to terminal character set keyword table,
  687.        ttcstab.
  688.      * Add a translation table from Latin-1 to barbarian: yl1ba[].
  689.      * Add a translation table from barbarian to Latin-1: ybal1[].
  690.      * Add a translation function from Barbarian to ASCII: xbaas().
  691.      * Add a translation function from Barbarian to Latin-1: xbal1().
  692.      * Add a translation function from Latin-1 to Barbarian: xl1ba().
  693.      * etc etc for each transfer character set...
  694.      * Add translation function pointers to the xls and xlr tables.
  695.        
  696.    Other translations involving Barbarian (e.g. from Barbarian to
  697.    Latin-Cyrillic) are performed through these tables and functions. See
  698.    ckuxla.h and ckuxla.c for extensive examples.
  699.    
  700.    To add a new Transfer Character Set, e.g. Latin Alphabet 9 (for the
  701.    Euro symbol), again in the "old" character-set modules:
  702.    
  703.    In ckcxla.h:
  704.           
  705.           + Add a TC_xxxx definition and increase MAXTCSETS accordingly.
  706.             
  707.    In ck?xla.h (since any transfer charset is also a file charset):
  708.           
  709.           + Add an FC_xxxx definition and increase MAXFCSETS accordingly.
  710.             
  711.    In ck?xla.c:
  712.           
  713.           + Add a tcsinfo[] entry.
  714.           + Make a tcstab[] keyword table entry.
  715.           + Make an fcsinfo[] table entry.
  716.           + Make an fcstab[] keyword table entry.
  717.           + Make a tcstab[] keyword table entry.
  718.           + If necessary, make a langinfo[] table entry.
  719.           + Make entries in the function pointer arrays.
  720.           + Provide any needed functions.
  721.             
  722.    As of C-Kermit 7.0, character sets are also handled in parallel by the
  723.    new (and very large) Unicode module, ckcuni.[ch]. Eventually we should
  724.    phase out the old way, described just above, and operate entirely in
  725.    (and through) Unicode. The advantages are many. The disadvantages are
  726.    size and performance. To add a character to the Unicode modules:
  727.    
  728.    In ckcuni.h:
  729.           
  730.           + (To be filled in...)
  731.             
  732.    In ckcuni.c:
  733.           
  734.           + (To be filled in...)
  735.             
  736.    [ [74]Contents ] [ [75]C-Kermit ] [ [76]Kermit Home ]
  737.     ________________________________________________________________________
  738.   
  739.   4.D. Group D: User Interface
  740.   
  741.    This is the code that communicates with the user, gets her commands,
  742.    informs her of the results. It may be command-line oriented,
  743.    interactive prompting dialog, menus and arrow keys, windows and mice,
  744.    speech recognition, telepathy, etc. The one provided is command-and
  745.    prompt, with the ability to read commands from various sources: the
  746.    console keyboard, a file, or a macro definition. The user interface
  747.    has three major functions:
  748.    
  749.     1. Sets the parameters for the file transfer and then starts it. This
  750.        is done by setting certain (many) global variables, such as the
  751.        protocol machine start state, the file specification, file type,
  752.        communication parameters, packet length, window size, character
  753.        set, etc.
  754.     2. Displays messages on the user's screen during the file transfer,
  755.        using the screen() function, which is called by the group-1
  756.        modules.
  757.     3. Executes any commands directly that do not require Kermit
  758.        protocol, such as the CONNECT command, local file management
  759.        commands, parameter-setting commands, FTP client commands, etc.
  760.        
  761.    If you plan to imbed the [77]Group B, files into a program with a
  762.    different user interface, your interface must supply an appropriate
  763.    screen() function, plus a couple related ones like chkint() and
  764.    intmsg() for handling keyboard (or mouse, etc) interruptions during
  765.    file transfer. The best way to find out about this is to link all the
  766.    C-Kermit modules together except the ckuu*.o and ckucon.o modules, and
  767.    see which missing symbols turn up.
  768.    
  769.    C-Kermit's character-oriented user interface (as opposed to the
  770.    Macintosh version's graphical user interface) consists of the
  771.    following modules. C-Kermit can be built with an interactive command
  772.    parser, a command-line-option-only parser, a graphical user interface,
  773.    or any combination, and it can even be built with no user interface at
  774.    all (in which case it runs as a remote-mode Kermit server).
  775.    
  776.    [78]ckucmd.h
  777.           
  778.    [79]ckucmd.c
  779.           The command parsing primitives used by the interactive command
  780.           parser to parse keywords, numbers, filenames, etc, and to give
  781.           help, complete fields, supply defaults, allow abbreviations and
  782.           editing, etc. This package is totally independent of Kermit,
  783.           but does depend on the [80]Group E functions.
  784.           
  785.    [81]ckuusr.h
  786.           Definitions of symbols used in Kermit's commands.
  787.           
  788.    ckuus*.c
  789.           Kermit's interactive command parser, including the script
  790.           programming language: [82]ckuusr.c (includes top-level keyword
  791.           tables); [83]ckuus2.c (HELP command text); [84]ckuus3.c (most
  792.           of the SET command); [85]ckuus4.c (includes variables and
  793.           functions); ckuus[567].c (miscellaneous);
  794.           
  795.    [86]ckuusy.c
  796.           The command-line-option parser.
  797.           
  798.    [87]ckuusx.c
  799.           User interface functions common to both the interactive and
  800.           command-line parsers.
  801.           
  802.    [88]ckuver.h
  803.           Version heralds for different implementations.
  804.           
  805.    [89]ckuscr.c
  806.           The (old, uucp-like) SCRIPT command
  807.           
  808.    [90]ckudia.c
  809.           The DIAL command. Includes specific knowledge of many types of
  810.           modems.
  811.           
  812.    Note that none of the above files is actually Unix-specific. Over time
  813.    they have proven to be portable among all platforms where C-Kermit is
  814.    built: Unix, VMS, AOS/VS, Amiga, OS-9, VOS, etc etc. Thus the third
  815.    letter should more properly be "c", but changing it would be too
  816.    confusing.
  817.    
  818.    ck?con.c, ckucns.c
  819.           The CONNECT command. Terminal connection, and in some cases
  820.           (Macintosh, Windows) also terminal emulation. NOTE: As of
  821.           C-Kermit 7.0, there are two different CONNECT modules for UNIX:
  822.           [91]ckucon.c -- the traditional, portable, fork()-based version
  823.           -- and [92]ckucns.c, a new version that uses select() rather
  824.           than forks so it can handle encryption. ckucns.c is the
  825.           preferred version for Unix; ckucon.c is not likely to keep pace
  826.           with it in terms of upgrades, etc. However, since select() is
  827.           not portable to every platform, ckucon.c will be kept
  828.           indefinitely for those platforms that can't use ckucns.c. NOTE:
  829.           SunLink X.25 support is available only in ckucon.c.
  830.           
  831.    ck_*.*, ckuat*.*
  832.           Modules having to do with authentication and encryption. Since
  833.           the relaxation of USA export laws, they are included with the
  834.           general source-code distribution. Secure C-Kermit binaries can
  835.           be built using special targets in the standard makefile.
  836.           However, secure prebuilt binaries may not be distributed.
  837.           
  838.    For other implementations, the files may, and probably do, have
  839.    different names. For example, the Macintosh graphical user interface
  840.    filenames start with "ckm". Kermit 95 uses the ckucmd and ckuus*
  841.    modules, but has its own CONNECT command modules. And so on.
  842.    
  843.    Here is a brief description of C-Kermit's "user interface interface",
  844.    from ckuusr.c. It is nowhere near complete; in particular, hundreds of
  845.    global variables are shared among the many modules. These should, some
  846.    day, be collected into classes or structures that can be passed around
  847.    as needed; not only for purity's sake, but also to allow for multiple
  848.    simultaneous communication sessions and or user interfaces. Our list
  849.    of things to do is endless, and reorganizing the source is almost
  850.    always at the bottom.
  851.    
  852.    The ckuus*.c modules (like many of the ckc*.c modules) depend on the
  853.    existence of C library features like fopen, fgets, feof, (f)printf,
  854.    argv/argc, etc. Other functions that are likely to vary among
  855.    operating systems -- like setting terminal modes or interrupts -- are
  856.    invoked via calls to functions that are defined in the [93]Group E
  857.    platform-dependent modules, ck?[ft]io.c. The command line parser
  858.    processes any arguments found on the command line, as passed to main()
  859.    via argv/argc. The interactive parser uses the facilities of the cmd
  860.    package (developed for this program, but, in theory, usable by any
  861.    program). Any command parser may be substituted for this one. The only
  862.    requirements for the Kermit command parser are these:
  863.    
  864.     1. Set parameters via global variables like duplex, speed, ttname,
  865.        etc. See [94]ckcmai.c for the declarations and descriptions of
  866.        these variables.
  867.     2. If a command can be executed without the use of Kermit protocol,
  868.        then execute the command directly and set the sstate (start state)
  869.        variable to 0. Examples include SET commands, local directory
  870.        listings, the CONNECT command.
  871.     3. If a command requires the Kermit protocol, set the following
  872.        variables:
  873.  
  874.  sstate                             string data
  875.    'x' (enter server mode)            (none)
  876.    'r' (send a 'get' command)         cmarg, cmarg2
  877.    'v' (enter receive mode)           cmarg2
  878.    'g' (send a generic command)       cmarg
  879.    's' (send files)                   nfils, cmarg & cmarg2 OR cmlist
  880.    'c' (send a remote host command)   cmarg
  881.  
  882.        cmlist is an array of pointers to strings.
  883.        cmarg, cmarg2 are pointers to strings.
  884.        nfils is an integer (hmmm, probably should be an unsigned long).
  885.        
  886.         cmarg can be:
  887.                 A filename string (possibly wild), or:
  888.                 a pointer to a prefabricated generic command string, or:
  889.                 a pointer to a host command string.
  890.                 
  891.         cmarg2 is:
  892.                 The name to send a single file under, or:
  893.                 the name under which to store an incoming file; must not
  894.                 be wild.
  895.                 If it's the name for receiving, a null value means to
  896.                 store the file under the name it arrives with.
  897.                 
  898.         cmlist is:
  899.                 A list of nonwild filenames, such as passed via argv.
  900.                 
  901.         nfils is an integer, interpreted as follows:
  902.                 -1: filespec (possibly wild) in cmarg, must be expanded
  903.                 internally.
  904.                 0: send from stdin (standard input).
  905.                 >0: number of files to send, from cmlist.
  906.                 
  907.    The screen() function is used to update the screen during file
  908.    transfer. The tlog() function writes to a transaction log (if TLOG is
  909.    defined). The debug() function writes to a debugging log (if DEBUG is
  910.    defined). The intmsg() and chkint() functions provide the user i/o for
  911.    interrupting file transfers.
  912.    
  913.    [ [95]Contents ] [ [96]C-Kermit ] [ [97]Kermit Home ]
  914.     ________________________________________________________________________
  915.   
  916.   4.E. Group E: Platform-Dependent I/O
  917.   
  918.    Platform-dependent function definitions. All the Kermit modules,
  919.    including the command package, call upon these functions, which are
  920.    designed to provide system-independent primitives for controlling and
  921.    manipulating devices and files. For Unix, these functions are defined
  922.    in the files [98]ckufio.c (files), [99]ckutio.c (communications), and
  923.    [100]ckusig.c (signal handling).
  924.    
  925.    For VMS, the files are [101]ckvfio.c, ckvtio.c, and [102]ckusig.c (VMS
  926.    can use the same signal handling routines as Unix). It doesn't really
  927.    matter what the files are called, except for Kermit distribution
  928.    purposes (grouping related files together alphabetically), only that
  929.    each function is provided with the name indicated, observes the same
  930.    calling and return conventions, and has the same type.
  931.    
  932.    The Group E modules contain both functions and global variables that
  933.    are accessed by modules in the other groups. These are now described.
  934.    
  935.    (By the way, I got this list by linking all the C-Kermit modules
  936.    together except ckutio and ckufio. These are the symbols that ld
  937.    reported as undefined. But that was a long time ago, probably circa
  938.    Version 6.)
  939.    
  940.   4.E.1. Global Variables
  941.   
  942.    char *DELCMD;
  943.           Pointer to string containing command for deleting files.
  944.           Example: char *DELCMD = "rm -f "; (UNIX)
  945.           Example: char *DELCMD = "delete "; (VMS)
  946.           Note trailing space. Filename is concatenated to end of this
  947.           string. NOTE: DELCMD is used only in versions that do not
  948.           provide their own built-in DELETE command.
  949.           
  950.    char *DIRCMD;
  951.           Pointer to string containing command for listing files when a
  952.           filespec is given.
  953.           Example: char *DIRCMD = "/bin/ls -l "; (UNIX)
  954.           Example: char *DIRCMD = "directory "; (VMS)
  955.           Note trailing space. Filename is concatenated to end of this
  956.           string. NOTE: DIRCMD is used only in versions that do not
  957.           provide their own built-in DIRECTORY command.
  958.           
  959.    char *DIRCM2;
  960.           Pointer to string containing command for listing files when a
  961.           filespec is not given. (currently not used, handled in another
  962.           way.)
  963.           Example: char *DIRCMD2 = "/bin/ls -ld *";
  964.           NOTE: DIRCMD2 is used only in versions that do not provide
  965.           their own built-in DIRECTORY command.
  966.           
  967.    char *PWDCMD;
  968.           Pointer to string containing command to display current
  969.           directory.
  970.           Example: char *PWDCMD = "pwd ";
  971.           NOTE: PWDCMD is used only in versions that do not provide their
  972.           own built-in PWD command.
  973.           
  974.    char *SPACMD;
  975.           Pointer to command to display free disk space in current
  976.           device/directory.
  977.           Example: char *SPACMD = "df .";
  978.           NOTE: SPACMD is used only in versions that do not provide their
  979.           own built-in SPACE command.
  980.           
  981.    char *SPACM2;
  982.           Pointer to command to display free disk space in another
  983.           device/directory.
  984.           Example: char *SPACM2 = "df ";
  985.           Note trailing space. Device or directory name is added to this
  986.           string. NOTE: SPACMD2 is used only in versions that do not
  987.           provide their own built-in SPACE command.
  988.           
  989.    char *TYPCMD;
  990.           Pointer to command for displaying the contents of a file.
  991.           Example: char *TYPCMD = "cat ";
  992.           Note trailing space. Device or directory name is added to this
  993.           string. NOTE: TYPCMD is used only in versions that do not
  994.           provide their own built-in TYPE command.
  995.           
  996.    char *WHOCMD;
  997.           Pointer to command for displaying logged-in users.
  998.           Example: char *WHOCMD = "who ";
  999.           Note trailing space. Specific user name may be added to this
  1000.           string.
  1001.           
  1002.    int backgrd = 0;
  1003.           Flag for whether program is running in foreground (0) or
  1004.           background (nonzero). Background operation implies that screen
  1005.           output should not be done and that all errors should be fatal.
  1006.           
  1007.    int ckxech;
  1008.           Flag for who is to echo console typein:
  1009.           1: The program (system is not echoing).
  1010.           0: The OS, front end, terminal, etc (not this program).
  1011.           
  1012.    char *ckxsys;
  1013.           Pointer to string that names the computer and operating system.
  1014.           Example: char *ckxsys = " NeXT Mach 1.0";
  1015.           Tells what computer system ckxv applies to. In UNIX Kermit,
  1016.           this variable is also used to print the program herald, and in
  1017.           the SHOW VERSION command.
  1018.           
  1019.    char *ckxv;
  1020.           Pointer to version/edit info of ck?tio.c module.
  1021.           Example: char *ckxv = "UNIX Communications Support, 6.0.169, 6
  1022.           Sep 96";
  1023.           Used by SHOW VERSION command.
  1024.           
  1025.    char *ckzsys;
  1026.           Like ckxsys, but briefer.
  1027.           Example: char *ckzsys = " 4.3 BSD";
  1028.           Tells what platform ckzv applies to. Used by the SHOW VERSION
  1029.           command.
  1030.           
  1031.    char *ckzv;
  1032.           Pointer to version/edit info of ck?fio.c module.
  1033.           Example: char *ckzv = "UNIX File support, 6.0.113, 6 Sep 96";
  1034.           Used by SHOW VERSION command.
  1035.           
  1036.    int dfflow;
  1037.           Default flow control. 0 = none, 1 = Xon/Xoff, ... (see FLO_xxx
  1038.           symbols in ckcdeb.h)
  1039.           Set by Group E module. Used by [103]ckcmai.c to initialize flow
  1040.           control variable.
  1041.           
  1042.    int dfloc;
  1043.           Default location. 0 = remote, 1 = local. Set by Group E module.
  1044.           Used by ckcmai.c to initialize local variable. Used in various
  1045.           places in the user interface.
  1046.           
  1047.    int dfprty;
  1048.           Default parity. 0 = none, 'e' = even, 'o' = odd, 'm' = mark,
  1049.           's' = space. Set by Group E module. Used by ckcmai.c to
  1050.           initialize parity variable.
  1051.           
  1052.    char *dftty;
  1053.           Default communication device. Set by Group E module. Used in
  1054.           many places. This variable should be initialized the the symbol
  1055.           CTTNAM, which is defined in ckcdeb.h, e.g. as "/dev/tty" for
  1056.           UNIX, "TT:" for VMS, etc. Example: char *dftty = CTTNAM;
  1057.           
  1058.    char *mtchs[];
  1059.           Array of string pointers to filenames that matched the most
  1060.           recent wildcard match, i.e. the most recent call to zxpand().
  1061.           Used (at least) by command parsing package for partial filename
  1062.           completion.
  1063.           
  1064.    int tilde_expand;
  1065.           Flag for whether to attempt to expand leading tildes in
  1066.           directory names (used in UNIX only, and then only when the
  1067.           symbol DTILDE is defined.
  1068.           
  1069.    int ttnproto;
  1070.           The protocol being used to communicate over a network device.
  1071.           Values are defined in ckcnet.h. Example: NP_TELNET is network
  1072.           protocol "telnet".
  1073.           
  1074.    int maxnam;
  1075.           The maximum length for a filename, exclusive of any device or
  1076.           directory information, in the format of the host operating
  1077.           system.
  1078.           
  1079.    int maxpath;
  1080.           The maximum length for a fully specified filename, including
  1081.           device designator, directory name, network node name, etc, in
  1082.           the format of the host operating system, and including all
  1083.           punctuation.
  1084.           
  1085.    int ttyfd;
  1086.           File descriptor of the communication device. -1 if there is no
  1087.           open or usable connection, including when C-Kermit is in remote
  1088.           mode. Since this is not implemented everywhere, references to
  1089.           it are in #ifdef CK_TTYFD..#endif.
  1090.           
  1091.    [ [104]Contents ] [ [105]C-Kermit ] [ [106]Kermit Home ]
  1092.     ________________________________________________________________________
  1093.   
  1094.   4.E.2. Functions
  1095.   
  1096.    These are divided into three categories: file-related functions (B.1),
  1097.    communication functions (B.2), and miscellaneous functions (B.3).
  1098.    
  1099.     4.E.2.1. File-Related Functions
  1100.     
  1101.    In most implementations, these are collected together into a module
  1102.    called ck?fio.c, where ? = "u" ([107]ckutio.c for Unix), "v"
  1103.    ([108]ckvtio.c for VMS), [109]etc. To be totally platform-independent,
  1104.    C-Kermit maintains its own file numbers, and provides the functions
  1105.    described in this section to deal with the files associated with them.
  1106.    The file numbers are referred to symbolically, and are defined as
  1107.    follows in ckcker.h:
  1108.    
  1109.   #define ZCTERM      0           /* Console terminal */
  1110.   #define ZSTDIO      1           /* Standard input/output */
  1111.   #define ZIFILE      2           /* Current input file for SEND command */
  1112.   #define ZOFILE      3           /* Current output file for RECEIVE command */
  1113.   #define ZDFILE      4           /* Current debugging log file */
  1114.   #define ZTFILE      5           /* Current transaction log file */
  1115.   #define ZPFILE      6           /* Current packet log file */
  1116.   #define ZSFILE      7           /* Current session log file */
  1117.   #define ZSYSFN      8           /* Input from a system function (pipe) */
  1118.   #define ZRFILE      9           /* Local file for READ command */  (NEW)
  1119.   #define ZWFILE     10           /* Local file for WRITE command */ (NEW)
  1120.   #define ZMFILE     11           /* Auxilliary file for internal use */ (NEW)
  1121.   #define ZNFILS     12           /* How many defined file numbers */
  1122.  
  1123.    In the descriptions below, fn refers to a filename, and n refers to
  1124.    one of these file numbers. Functions are of type int unless otherwise
  1125.    noted, and are listed mostly alphabetically.
  1126.    
  1127.    int
  1128.           chkfn(n) int n;
  1129.           Checks the file number n. Returns:
  1130.            -1: File number n is out of range
  1131.             0: n is in range, but file is not open
  1132.             1: n in range and file is open
  1133.           
  1134.    int
  1135.           iswild(filspec) char *filespec;
  1136.           Checks if the file specification is "wild", i.e. contains
  1137.           metacharacters or other notations intended to match multiple
  1138.           filenames. Returns:
  1139.             0: not wild
  1140.             1: wild.
  1141.           
  1142.    int
  1143.           isdir(string) char *string;
  1144.           Checks if the string is the name of an existing directory. The
  1145.           idea is to check whether the string can be "cd'd" to, so in
  1146.           some cases (e.g. DOS) it might also indicate any file
  1147.           structured device, such as a disk drive (like A:). Other
  1148.           nonzero returns indicate system-dependent information; e.g. in
  1149.           VMS isdir("[.FOO]") returns 1 but isdir("FOO.DIR;1") returns 2
  1150.           to indicate the directory-file name is in a format that needs
  1151.           conversion before it can be combined with a filename. Returns:
  1152.             0: not a directory (including any kind of error)
  1153.             1: it is an existing directory
  1154.           
  1155.    char *
  1156.           zfcdat(name) char *name;
  1157.           Returns modification (preferably, otherwise creation) date/time
  1158.           of file whose name is given in the argument string. Return
  1159.           value is a pointer to a string of the form yyyymmdd hh:mm:ss,
  1160.           for example 19931231 23:59:59, which represents the local time
  1161.           (no timezone or daylight savings time finagling required).
  1162.           Returns the null string ("") on failure. The text pointed to by
  1163.           the string pointer might be in a static buffer, and so should
  1164.           be copied to a safe place by the caller before any subsequent
  1165.           calls to this function.
  1166.           
  1167.    struct zfnfp *
  1168.           zfnqfp(fn, buflen, buf) char * fn; int buflen; char * buf;
  1169.           Given the filename fn, the corresponding fully qualified,
  1170.           absolute filename is placed into the buffer buf, whose length
  1171.           is buflen. On failure returns a NULL pointer. On success
  1172.           returns a pointer to a struct zfnfp containing pointers to the
  1173.           full pathname and to just the filename, and an int giving the
  1174.           length of the full pathname. All references to this function in
  1175.           mainline code must be protected by #ifdef ZFNQFP..#endif,
  1176.           because it is not present in all of the ck*fio.c modules. So if
  1177.           you implement this function in a version that did not have it
  1178.           before, be sure to add #define ZFNQFP in the appropriate spot
  1179.           in ckcdeb.h or in the build-procedure CFLAGS.
  1180.           
  1181.    int
  1182.           zcmpfn(s1,s2) char * s2, * s2;
  1183.           Compares two filenames to see if they refer to the same.
  1184.           Internally, the arguments can be converted to fully qualified
  1185.           pathnames, e.g. with zfnqfp(), realpath(), or somesuch. In Unix
  1186.           or other systems where symbolic links exist, the link should be
  1187.           resolved before making the comparison or looking at the inodes.
  1188.           Returns:
  1189.             0: Files are not identical.
  1190.             1: Files are identical.
  1191.           
  1192.    int
  1193.           zfseek(pos) long pos;
  1194.           Positions the input pointer on the current input file to the
  1195.           given position. The pos argument is 0-based, the offset
  1196.           (distance in bytes) from beginning of the file. Needed for
  1197.           RESEND, PSEND, and other recovery operations. This function is
  1198.           not necessarily possible on all systems, e.g. record-oriented
  1199.           systems. It should only be used on binary files (i.e. files we
  1200.           are sending in binary mode) and stream-oriented file systems.
  1201.           Returns:
  1202.            -1: on failure.
  1203.             0: On success.
  1204.           
  1205.    int
  1206.           zchdir(dirnam) char *dirnam;
  1207.           Changes current or default directory to the one given in
  1208.           dirnam. Returns:
  1209.             0: On failure.
  1210.             1: on success.
  1211.           
  1212.    long
  1213.           zchki(fn) char *fn;
  1214.           Check to see if file with name fn is a regular, readable,
  1215.           existing file, suitable for Kermit to send -- not a directory,
  1216.           not a symbolic link, etc. Returns:
  1217.            -3: if file exists but is not accessible (e.g.
  1218.           read-protected);
  1219.            -2: if file exists but is not of a readable type (e.g. a
  1220.           directory);
  1221.            -1: on error (e.g. file does not exist, or fn is garbage);
  1222.           >=0: (length of file) if file exists and is readable.
  1223.           Also see isdir(), zgetfs().
  1224.           
  1225.    int
  1226.           zchkpid(pid) unsigned long pid;
  1227.           Returns:
  1228.             1: If the given process ID (e.g. pid in UNIX) is valid and
  1229.           active
  1230.             0: otherwise.
  1231.           
  1232.    long
  1233.           zgetfs(fn) char *fn;
  1234.           Gets the size of the given file, regardless of accessibility.
  1235.           Used for directory listings. Unlike zchki(), should return the
  1236.           size of any kind of file, even a directory. zgetfs() also
  1237.           should serve as a mini "get file info" function that can be
  1238.           used until we design a better one, by also setting some global
  1239.           variables:
  1240.             int zgfs_link   = 1/0 = file is (not) a symbolic link.
  1241.             int zgfs_dir    = 1/0 = file is (not) a directory.
  1242.             char linkname[] = if zgfs_link != 0, name of file link points
  1243.           to.
  1244.           Returns:
  1245.            -1: on error (e.g. file does not exist, or fn is garbage);
  1246.           >=0: (length of file) if file exists and is readable.
  1247.           
  1248.    int
  1249.           zchko(fn) char *fn;
  1250.           Checks to see if a file of the given name can be created.
  1251.           Returns:
  1252.            -1: if file cannot be created, or on any kind of error.
  1253.             0: if file can be created.
  1254.           
  1255.    int
  1256.           zchkspa(fn,len) char *f; long len;
  1257.           Checks to see if there is sufficient space to store the file
  1258.           named fn, which is len bytes long. If you can't write a
  1259.           function to do this, then just make a dummy that always returns
  1260.           1; higher level code will recover from disk-full errors. The
  1261.           receiving Kermit uses this function to refuse an incoming file
  1262.           based on its size, via the attribute mechanism. Returns:
  1263.            -1: on error.
  1264.             0: if there is not enough space.
  1265.             1: if there is enough space.
  1266.           
  1267.    int
  1268.           zchin(n,c) int n; int *c;
  1269.           Gets a character from file number n, return it in c (call with
  1270.           &c). Returns:
  1271.            -1: on failure, including EOF.
  1272.             0: on success with character in c.
  1273.           
  1274.    int
  1275.           zchout(n,c) int n; char c;
  1276.           Writes the character c to file number n. Returns:
  1277.            -1: on error.
  1278.             0: on success.
  1279.           
  1280.    int
  1281.           zclose(n) int n;
  1282.           Closes file number n. Returns:
  1283.            -1: on error.
  1284.             1: on success.
  1285.           
  1286.    int
  1287.           zdelet(fn) char *name;
  1288.           Attempts to delete (remove, erase) the named file. Returns:
  1289.            -1: on error.
  1290.             1: if file was deleted successfully.
  1291.           
  1292.    char *
  1293.           zgperm(char * f)
  1294.           Returns a pointer to the system-dependent numeric
  1295.           permissions/protection string for file f, or NULL upon failure.
  1296.           Used if CK_PERMS is defined.
  1297.           
  1298.    char *
  1299.           ziperm(char * f)
  1300.           Returns a pointer to the system-dependent symbolic
  1301.           permissions/protection string for file f, or NULL upon failure.
  1302.           Used if CK_PERMS is defined. Example: In UNIX zgperm(f) might
  1303.           return "100770", but ziperm() might return "-rwxrwx---". In
  1304.           VMS, zgperm() would return a hexadecimal string, but ziperm()
  1305.           would return something like "(RWED,RWED,RE,)".
  1306.           
  1307.    char *
  1308.           zgtdir()
  1309.           Returns a pointer to the name of the current directory, folder,
  1310.           etc, or a NULL pointer if the current directory cannot be
  1311.           determined. If possible, the directory specification should be
  1312.           (a) fully specified, e.g. as a complete pathname, and (b) be
  1313.           suitable for appending a filename. Thus, for example, Unix
  1314.           directory names should end with '/'. VMS directory names should
  1315.           look like DEV:[NAME] (rather than, say, NAME.DIR;1).
  1316.           
  1317.    char *
  1318.           zhome()
  1319.           Returns a pointer to a string containing the user's home
  1320.           directory, or NULL upon error. Should be formatted like
  1321.           zgtdir() (q.v.).
  1322.           
  1323.    int
  1324.           zinfill()
  1325.           Fill buffer from input file. This function is used by the macro
  1326.           zminchar(), which is defined in ckcker.h. zminchar() manages
  1327.           its own buffer, and calls zinfill() to fill it whenever it
  1328.           becomes empty. It is used only for sending files, and reads
  1329.           characters only from file number ZIFILE. zinfill() returns -1
  1330.           upon end of file, -2 upon fatal error, and -3 upon timeout
  1331.           (e.g. when reading from a pipe); otherwise it returns the first
  1332.           character from the buffer it just read.
  1333.           
  1334.    int
  1335.           zkself()
  1336.           Kills the current job, session, process, etc, logs out,
  1337.           disappears. Used by the Kermit server when it receives a BYE
  1338.           command. On failure, returns -1. On success, does not return at
  1339.           all! This function should not be called until all other steps
  1340.           have been taken to close files, etc.
  1341.           
  1342.    VOID
  1343.           zstrip(fn,&fn2) char *fn1, **fn2;
  1344.           Strips device and directory, etc, from file specification fn,
  1345.           leaving only the filename (including "extension" or "filetype"
  1346.           -- the part after the dot). For example DUA0:[PROGRAMS]OOFA.C;3
  1347.           becomes OOFA.C, or /usr/fdc/oofa.c becomes oofa.c. Returns a
  1348.           pointer to result in fn2.
  1349.           
  1350.    int
  1351.           zsetperm(char * file, unsigned int code)
  1352.           Set permissions of file to given system-dependent code.   0: On
  1353.           failure.
  1354.             1: on success.
  1355.           
  1356.    int
  1357.           zsetroot(char * dir)
  1358.           Sets the root for the user's file access, like Unix chroot(),
  1359.           but does not require privilege. In Unix, this must be
  1360.           implemented entirely by Kermit's own file access routines.
  1361.           Returns:
  1362.             1: Success
  1363.            -1: Invalid argument
  1364.            -2:
  1365.            -3: Internal error
  1366.            -4: Access to given directory denied
  1367.            -5: New root not within old root
  1368.           
  1369.    int
  1370.           zinroot(char * file)
  1371.           If no root is set (zsetroot()), returns 1.
  1372.           Otherwise, if given file is in the root, returns 1.
  1373.           Otherwise, returns 0.
  1374.           
  1375.    VOID
  1376.           zltor(fn,fn2) char *fn1, *fn2;
  1377.           Local-To-Remote filename translation. OBSOLETE: replaced by
  1378.           nzltor() (q.v.). Translates the local filename fn into a format
  1379.           suitable for transmission to an arbitrary type of computer, and
  1380.           copies the result into the buffer pointed to by fn2.
  1381.           Translation may involve (a) stripping the device and/or
  1382.           directory/path name, (b) converting lowercase to uppercase, (c)
  1383.           removing spaces and strange characters, or converting them to
  1384.           some innocuous alphabetic character like X, (d) discarding or
  1385.           converting extra periods (there should not be more than one).
  1386.           Does its best. Returns no value. name2 is a pointer to a
  1387.           buffer, furnished by the caller, into which zltor() writes the
  1388.           resulting name. No length checking is done.
  1389.           
  1390.    #ifdef NZLTOR
  1391.           VOID
  1392.           nzltor(fn,fn2,convert,pathnames,max) char *fn1,*fn2; int
  1393.           convert,pathnames,max;
  1394.           Replaces zltor(). This new version handles pathnames and checks
  1395.           length. fn1 and fn2 are as in zltor(). This version is called
  1396.           unconditionally for each file, rather than only when filename
  1397.           conversion is enabled. Pathnames can have the following values:
  1398.           
  1399.             PATH_OFF: Pathname, if any, is to be stripped
  1400.             PATH_REL: The relative pathname is to be included
  1401.             PATH_ABS: The full pathname is to be included
  1402.           
  1403.           After handling pathnames, conversion is done to the result as
  1404.           in the zltor() description if convert != 0; if relative or
  1405.           absolute pathnames are included, they are converted to UNIX
  1406.           format, i.e. with slash (/) as the directory separator. The max
  1407.           parameter specifies the maximum size of fn2. If convert > 0,
  1408.           the regular conversions are done; if convert < 0, minimal
  1409.           conversions are done (we skip uppercasing the letters, we allow
  1410.           more than one period, etc; this can be used when we know our
  1411.           partner is UNIX or similar).
  1412.           
  1413.    #endif /* NZLTOR */
  1414.           
  1415.    int
  1416.           nzxpand(fn,flags) char *fn; int flags;
  1417.           Replaces zxpand(), which is obsolete as of C-Kermit 7.0.
  1418.           Call with:
  1419.             fn = Pointer to filename or pattern.
  1420.             flags = option bits:
  1421.               flags & ZX_FILONLY  Match regular files
  1422.               flags & ZX_DIRONLY  Match directories
  1423.               flags & ZX_RECURSE  Descend through directory tree
  1424.               flags & ZX_MATCHDOT Match "dot files"
  1425.               flags & ZX_NOBACKUP Don't match "backup files"
  1426.               flags & ZX_NOLINKS  Don't follow symlinks.
  1427.           
  1428.           Returns the number of files that match fn, with data structures
  1429.           set up so the first file (if any) will be returned by the next
  1430.           znext() call. If ZX_FILONLY and ZX_DIRONLY are both set, or
  1431.           neither one is set, files and directories are matched. Notes:
  1432.           
  1433.          1. It is essential that the number returned by nzxpand() reflect
  1434.             the actual number of filenames that will be returned by
  1435.             znext() calls. In other words:
  1436.  
  1437.   for (n = nzxpand(string,flags); n > 0; n--) {
  1438.       znext(buf);
  1439.       printf("%s\n", buf);
  1440.   }
  1441.             should print all the file names; no more, no less.
  1442.          2. In UNIX, DOS, OS-9, etc, where directories contain entries
  1443.             for themselves (.) and the superior directory (..), these
  1444.             should NOT be included in the list under any circumstances,
  1445.             including when ZX_MATCHDOT is set.
  1446.          3. Additional option bits might be added in the future, e.g. for
  1447.             sorting (sort by date/name/size, reverse/ascending, etc).
  1448.             Currently this is done only in higher level code (through a
  1449.             hack in which the nzxpand() exports its filename array, which
  1450.             is not portable because not all OS's can use this mechanism).
  1451.             
  1452.    int
  1453.           zmail(addr,fn) char *addr, fn;
  1454.           Send the local, existing file fn as e-mail to the address addr.
  1455.           Returns:
  1456.             0: on success
  1457.             2: if mail delivered but temp file can't be deleted
  1458.            -2: if mail can't be delivered
  1459.           
  1460.    int
  1461.           zmkdir(path) char *path;
  1462.           The path can be a file specification that might contain
  1463.           directory information, in which the filename is expected to be
  1464.           included, or an unambiguous directory specification (e.g. in
  1465.           UNIX it must end with "/"). This routine attempts to create any
  1466.           directories in the given path that don't already exist. Returns
  1467.           0 or greater success: no directories needed creation, or else
  1468.           all directories that needed creation were created successfully;
  1469.           the return code is the number of directories that were created.
  1470.           Returns -1 on failure to create any of the needed directories.
  1471.           
  1472.    int
  1473.           zrmdir(path) char *path;
  1474.           Attempts to remove the given directory. Returns 0 on success,
  1475.           -1 on failure. The detailed semantics are open -- should it
  1476.           fail if the directory contains any files or subdirectories,
  1477.           etc. It is probably best for this routine to behave in whatever
  1478.           manner is customary on the underlying platform; e.g. in UNIX,
  1479.           VMS, DOS, etc, where directories can not be removed unless they
  1480.           are empty.
  1481.           
  1482.    VOID
  1483.           znewn(fn,s) char *fn, **s;
  1484.           Transforms the name fn into a filename that is guaranteed to be
  1485.           unique. If the file fn does not exist, then the new name is the
  1486.           same as fn; Otherwise, it's different. this function does its
  1487.           best, returns no value. New name is created in caller's space.
  1488.           Call like this: znewn(old,&new);. The second parameter is a
  1489.           pointer to the new name. This pointer is set by znewn() to
  1490.           point to a static string in its own space, so be sure to the
  1491.           result to a safe place before calling this function again.
  1492.           
  1493.    int
  1494.           znext(fn) char *fn;
  1495.           Copies the next file name from a file list created by zxpand()
  1496.           into the string pointed to by fn (see zxpand). If no more
  1497.           files, then the null string is placed there. Returns 0 if there
  1498.           are no more filenames, with 0th element the array pointed to by
  1499.           fn set to NUL. If there is a filename, it is stored in the
  1500.           array pointed to by fn and a positive number is returned. NOTE:
  1501.           This is a change from earlier definitions of this function
  1502.           (pre-1999), which returned the number of files remaining; thus
  1503.           0 was the return value when returning the final file. However,
  1504.           no mainline code ever depended on the return value, so this
  1505.           change should be safe.
  1506.           
  1507.    int
  1508.           zopeni(n,fn) int n; char *fn;
  1509.           Opens the file named fn for input as file number n. Returns:
  1510.             0: on failure.
  1511.             1: on success.
  1512.           
  1513.    int
  1514.           zopeno(n,fn,zz,fcb) int n; char *name; struct zattr *zz; struct
  1515.           filinfo *fcb;
  1516.           Attempts to open the named file for output as file number n. zz
  1517.           is a Kermit file attribute structure as defined in ckcdeb.h,
  1518.           containing various information about the file, including its
  1519.           size, creation date, and so forth. This function should attempt
  1520.           to honor as many of these as possible. fcb is a "file control
  1521.           block" in the traditional sense, defined in ckcdeb.h,
  1522.           containing information relevant to complicated file systems
  1523.           like VMS (RMS), IBM MVS, etc, like blocksize, record length,
  1524.           organization, record format, carriage control, etc. Returns:
  1525.             0: on failure.
  1526.             1: on success.
  1527.           
  1528.    int
  1529.           zoutdump()
  1530.           Dumps a file output buffer. Used with the macro zmchout()
  1531.           defined in ckcker.h. Used only with file number ZOFILE, i.e.
  1532.           the file that is being received by Kermit during file transfer.
  1533.           Returns:
  1534.            -1: on failure.
  1535.             0: on success.
  1536.           
  1537.    int
  1538.           zprint(p,fn) char *p, *f;
  1539.           Prints the file with name fn on a local printer, with options
  1540.           p. Returns:
  1541.             0: on success
  1542.             3: if file sent to printer but can't be deleted
  1543.            -3: if file can't be printed
  1544.           
  1545.    int
  1546.           zrename(fn,fn2) char *fn, *fn2;
  1547.           Changes the name of file fn to fn2. If fn2 is the name of an
  1548.           existing directory, or a file-structured device, then file fn
  1549.           is moved to that directory or device, keeping its original
  1550.           name. If fn2 lacks a directory separator when passed to this
  1551.           function, an appropriate one is supplied. Returns:
  1552.            -1: on failure.
  1553.             0: on success.
  1554.           
  1555.    int
  1556.           zcopy(source,dest) char * source, * dest;
  1557.           Copies the source file to the destination. One file only. No
  1558.           wildcards. The destination string may be a filename or a
  1559.           directory name. Returns:
  1560.             0: on success.
  1561.            <0: on failure:
  1562.             -2: source file is not a regular file.
  1563.             -3: source file not found.
  1564.             -4: permission denied.
  1565.             -5: source and destination are the same file.
  1566.             -6: i/o error.
  1567.             -1: other error.
  1568.           
  1569.    char *
  1570.           zlocaltime(char *)
  1571.           Call with: "yyyymmdd hh:mm:ss" GMT/UTC date-time. Returns
  1572.           pointer to local date-time string "yyyymmdd hh:mm:ss" on
  1573.           success, NULL on failure.
  1574.           
  1575.    VOID
  1576.           zrtol(fn,fn2) char *fn, *fn2;
  1577.           Remote-To-Local filename translation. OBSOLETE: replaced by
  1578.           nzrtol(). Translates a "standard" filename to a local filename.
  1579.           For example, in Unix this function might convert an
  1580.           all-uppercase name to lowercase, but leave lower- or mix-case
  1581.           names alone. Does its best, returns no value. New name is in
  1582.           string pointed to by fn2. No length checking is done.
  1583.           
  1584.    #ifdef NZLTOR
  1585.           
  1586.    int
  1587.           nzrtol(fn,fn2,convert,pathnames,max) char *fn1,*fn2; int
  1588.           convert,pathnames,max;
  1589.           Replaces zrtol. Like zrtol but handles pathnames and checks
  1590.           length. See nzltor for detailed description of parameters.
  1591.           
  1592.    #endif /* NZLTOR */
  1593.           
  1594.    int
  1595.           zsattr(xx) struct zattr *xx;
  1596.           Fills in a Kermit file attribute structure for the file which
  1597.           is to be sent, namely the currently open ZIFILE. Note that this
  1598.           is not a very good design, but we're stuck with it. Callers
  1599.           must ensure that zsattr() is called only on real files, not on
  1600.           pipes, internally generated file-like objects such as server
  1601.           REMOTE command responses, etc. Returns:
  1602.            -1: on failure.
  1603.             0: on success with the structure filled in.
  1604.           If any string member is null, it should be ignored by the
  1605.           caller.
  1606.           If any numeric member is -1, it should be ignored by the
  1607.           caller.
  1608.           
  1609.    int
  1610.           zshcmd(s) char *s;
  1611.           s contains to pointer to a command to be executed by the host
  1612.           computer's shell, command parser, or operating system. If the
  1613.           system allows the user to choose from a variety of command
  1614.           processors (shells), then this function should employ the
  1615.           user's preferred shell. If possible, the user's job
  1616.           (environment, process, etc) should be set up to catch keyboard
  1617.           interruption signals to allow the user to halt the system
  1618.           command and return to Kermit. The command must run in ordinary,
  1619.           unprivileged user mode. If possible, this function should
  1620.           return -1 on failure to start the command, or else it should
  1621.           return 1 if the command succeeded and 0 if it failed.
  1622.           
  1623.    int
  1624.           pexitstatus
  1625.           zshcmd() and zsyscmd() should set this to the command's actual
  1626.           exit status code if possible.
  1627.           
  1628.    int
  1629.           zsyscmd(s) char *s;
  1630.           s contains to pointer to a command to be executed by the host
  1631.           computer's shell, command parser, or operating system. If the
  1632.           system allows the user to choose from a variety of command
  1633.           processors (shells), then this function should employ the
  1634.           system standard shell (e.g. /bin/sh for Unix), so that the
  1635.           results will always be the same for everybody. If possible, the
  1636.           user's job (environment, process, etc) should be set up to
  1637.           catch keyboard interruption signals to allow the user to halt
  1638.           the system command and return to Kermit. The command must run
  1639.           in ordinary, unprivileged user mode. If possible, this function
  1640.           should return -1 on failure to start the command, or else it
  1641.           should return 1 if the command succeeded and 0 if it failed.
  1642.           
  1643.    VOID
  1644.           z_exec(s,args) char * s; char * args[];
  1645.           This one executes the command s (which is searched for using
  1646.           the system's normal searching mechanism, such as PATH in UNIX),
  1647.           with the given argument vector, which follows the conventions
  1648.           of UNIX argv[]: the name of the command pointed to by element
  1649.           0, the first arg by element 1, and so on. A null args[] pointer
  1650.           indicates the end of the arugment list. All open files must
  1651.           remain open so the exec'd process can use them. Returns only if
  1652.           unsuccessful.
  1653.           
  1654.    int
  1655.           zsinl(n,s,x) int n, x; char *s;
  1656.           Reads a line from file number n. Writes the line into the
  1657.           address s provided by the caller. Writing terminates when
  1658.           newline is read, but with newline discarded. Writing also
  1659.           terminates upon EOF or if length x is exhausted. Returns:
  1660.            -1: on EOF or error.
  1661.             0: on success.
  1662.           
  1663.    int
  1664.           zsout(n,s) int n; char *s;
  1665.           Writes the string s out to file number n. Returns:
  1666.            -1: on failure.
  1667.             0: on success.
  1668.           
  1669.    int
  1670.           zsoutl(n,s) int n; char *s;
  1671.           Writes the string s out to file number n and adds a line
  1672.           (record) terminator (boundary) appropriate for the system and
  1673.           the file format. Returns:
  1674.            -1: on failure.
  1675.             0: on success.
  1676.           
  1677.    int
  1678.           zsoutx(n,s,x) int n, x; char *s;
  1679.           Writes exactly x characters from string s to file number n. If
  1680.           s has fewer than x characters, then the entire string s is
  1681.           written. Returns:
  1682.            -1: on failure.
  1683.           >= 0: on success, the number of characters actually written.
  1684.           
  1685.    int
  1686.           zstime(fn,yy,x) char *fn; struct zattr *yy; int x;
  1687.           Sets the creation date (and other attributes) of an existing
  1688.           file, or compares a file's creation date with a given date.
  1689.           Call with:
  1690.           fn: pointer to name of existing file.
  1691.           yy: Pointer to a Kermit file attribute structure in which
  1692.           yy->date.val is a date of the form yyyymmdd hh:mm:ss, e.g.
  1693.           19900208 13:00:00, which is to be used for setting or comparing
  1694.           the file date. Other attributes in the struct can also be set,
  1695.           such as the protection/permission (See [110]Appendix I), when
  1696.           it makes sense (e.g. "yy->lprotect.val" can be set if the
  1697.           remote system ID matches the local one).
  1698.            x: A function code: 0 means to set the file's creation date as
  1699.           given. 1 means compare the date from the yy struct with the
  1700.           file's date.
  1701.           Returns:
  1702.            -1: on any kind of error.
  1703.             0: if x is 0 and the file date was set successfully.
  1704.             0: if x is 1 and date from attribute structure > file
  1705.           creation date.
  1706.             1: if x is 1 and date from attribute structure <= file
  1707.           creation date.
  1708.           
  1709.    VOID
  1710.           zstrip(name,name2) char *name, **name2;
  1711.           Strips pathname from filename "name". Constructs the resulting
  1712.           string in a static buffer in its own space and returns a
  1713.           pointer to it in name2. Also strips device name, file version
  1714.           numbers, and other "non-name" material.
  1715.           
  1716.    int
  1717.           zxcmd(n,s) char *s;
  1718.           Runs a system command so its output can be accessed as if it
  1719.           were file n. The command is run in ordinary, unprivileged user
  1720.           mode.
  1721.           If n is ZSTDIO or ZCTERM, returns -1.
  1722.           If n is ZIFILE or ZRFILE, then Kermit reads from the command,
  1723.           otherwise Kermit writes to the command.
  1724.           Returns 0 on error, 1 on success.
  1725.           
  1726.    int
  1727.           zxpand(fn) char *fn;
  1728.           OBSOLETE: Replaced by nzxpand(), q.v.
  1729.           
  1730.    #ifdef ZXREWIND
  1731.           
  1732.    int
  1733.           zxrewind()
  1734.           Returns the number of files returned by the most recent
  1735.           nzxpand() call, and resets the list to the beginning so the
  1736.           next znext() call returns the first file. Returns -1 if zxpand
  1737.           has not yet been called. If this function is available,
  1738.           ZXREWIND should be defined; otherwise it should not be
  1739.           referenced.
  1740.           
  1741.    #endif /* ZXREWIND */
  1742.           
  1743.    int
  1744.           xsystem(cmd) char *cmd;
  1745.           Executes the system command without redirecting any of its i/o,
  1746.           similar (well, identical) to system() in Unix. But before
  1747.           passing the command to the system, xsystem() ensures that all
  1748.           privileges are turned off, so that the system command executes
  1749.           in ordinary unprivileged user mode. If possible, xsystem()
  1750.           returns the return code of the command that was executed.
  1751.           
  1752.     4.E.2.2. IKSD Variables and Functions
  1753.     
  1754.    These must be implemented in any C-Kermit version that is to be
  1755.    installed as an Internet Kermit Service Daemon (IKSD). IKSD is
  1756.    expected to be started by the Internet Daemon (e.g. inetd) with its
  1757.    standard i/o redirected to the incoming connection.
  1758.    
  1759.    int ckxanon;
  1760.           Nonzero if anonymous logins allowed.
  1761.           
  1762.    extern int inserver;
  1763.           Nonzero if started in IKSD mode.
  1764.           
  1765.    extern int isguest;
  1766.           Nonzero if IKSD and user logged in anonymously.
  1767.           
  1768.    extern char * homdir;
  1769.           Pointer to user's home directory.
  1770.           
  1771.    extern char * anonroot;
  1772.           Pointer to file-system root for anonymous users.
  1773.           
  1774.    Existing functions must make "if (inserver && isguest)" checks for
  1775.    actions that would not be legal for guests: zdelete(), zrmdir(),
  1776.    zprint(), zmail(), etc.
  1777.    
  1778.    int
  1779.           zvuser(name) char * name;
  1780.           Verifies that user "name" exists and is allowed to log in. If
  1781.           the name is "ftp" or "anonymous" and ckxanon != 0, a guest
  1782.           login is set up. Returns 0 if user not allowed to log in,
  1783.           nonzero if user may log in.
  1784.           
  1785.    int
  1786.           zvpass(string) char * string;
  1787.           Verifies password of the user from the most recent zvuser()
  1788.           call. Returns nonzero if password is valid for user, 0 if it
  1789.           isn't. Makes any appropriate system log entries (IKSD logins,
  1790.           failed login attempts, etc). If password is valid, logs the
  1791.           user in as herself (if real user), or sets up restricted
  1792.           anonymous access if user is guest (e.g. changes file-system
  1793.           root to anonroot and sets isguest = 1).
  1794.           
  1795.    VOID
  1796.           zsyslog()
  1797.           Begins any desired system logging of an IKSD session.
  1798.           
  1799.    VOID
  1800.           zvlogout()
  1801.           Terminates an IKSD session. In most cases this is simply a
  1802.           wrapper for exit() or doexit(), with some system logging added.
  1803.           
  1804.     4.E.2.3. Privilege Functions
  1805.     
  1806.    These functions are used by C-Kermit to adapt itself to operating
  1807.    systems where the program can be made to run in a "privileged" mode,
  1808.    e.g. setuid or setgid in Unix. C-Kermit should NOT read and write
  1809.    files or start subprocesses as a privileged program. This would
  1810.    present a serious threat to system security. The security package has
  1811.    been installed to prevent such security breaches by turning off the
  1812.    program's special privileges at all times except when they are needed.
  1813.    
  1814.    In UNIX, the only need Kermit has for privileged status is access to
  1815.    the UUCP lockfile directory, in order to read, create, and destroy
  1816.    lockfiles, and to open communication devices that are normally
  1817.    protected against the user (see the [111]Unix C-Kermit Installation
  1818.    Instructions for discussion). Therefore, privileges should only be
  1819.    enabled for these operations and disabled at all other times. This
  1820.    relieves the programmer of the responsibility of putting expensive and
  1821.    unreliable access checks around every file access and subprocess
  1822.    creation.
  1823.    
  1824.    Strictly speaking, these functions are not required in all C-Kermit
  1825.    implementations, because their use (so far, at least) is internal to
  1826.    the Group E modules. However, they should be included in all C-Kermit
  1827.    implementations for operating systems that support the notion of a
  1828.    privileged program (UNIX, RSTS/E, what others?).
  1829.    
  1830.    int
  1831.           priv_ini()
  1832.           Determine whether the program is running in privileged status.
  1833.           If so, turn off the privileges, in such a way that they can be
  1834.           turned on again when needed. Called from sysinit() at program
  1835.           startup time. Returns:
  1836.             0 on success
  1837.             nonzero on failure, in which case the program should halt
  1838.           immediately.
  1839.           
  1840.    int
  1841.           priv_on()
  1842.           If the program is not privileged, this function does nothing.
  1843.           If the program is privileged, this function returns it to
  1844.           privileged status. priv_ini() must have been called first.
  1845.           Returns:
  1846.             0 on success
  1847.             nonzero on failure
  1848.           
  1849.    int
  1850.           priv_off()
  1851.           Turns privileges off (if they are on) in such a way that they
  1852.           can be turned back on again. Returns:
  1853.             0 on success
  1854.             nonzero on failure
  1855.           
  1856.    int
  1857.           priv_can()
  1858.           Turns privileges off in such a way that they cannot be turned
  1859.           back on. Returns:
  1860.             0 on success
  1861.             nonzero on failure
  1862.           
  1863.    int
  1864.           priv_chk()
  1865.           Attempts to turns privileges off in such a way that they can be
  1866.           turned on again later. Then checks to make sure that they were
  1867.           really turned off. If they were not really turned off, then
  1868.           they are cancelled permanently. Returns:
  1869.             0 on success
  1870.             nonzero on failure
  1871.           
  1872.     4.E.2.4. Console-Related Functions
  1873.     
  1874.    These relate to the program's "console", or controlling terminal, i.e.
  1875.    the terminal that the user is logged in on and types commands at, or
  1876.    on a PC or workstation, the actual keyboard and screen.
  1877.    
  1878.    int
  1879.           conbin(esc) char esc;
  1880.           Puts the console into "binary" mode, so that Kermit's command
  1881.           parser can control echoing and other treatment of characters
  1882.           that the user types. esc is the character that will be used to
  1883.           get Kermit's attention during packet mode; puts this in a
  1884.           global place. Sets the ckxech variable. Returns:
  1885.            -1: on error.
  1886.             0: on success.
  1887.           
  1888.    int
  1889.           concb(esc) char esc;
  1890.           Put console in "cbreak" (single-character wakeup) mode. That
  1891.           is, ensure that each console character is available to the
  1892.           program immediately when the user types it. Otherwise just like
  1893.           conbin(). Returns:
  1894.            -1: on error.
  1895.             0: on success.
  1896.           
  1897.    int
  1898.           conchk()
  1899.           Returns a number, 0 or greater, the number of characters
  1900.           waiting to be read from the console, i.e. the number of
  1901.           characters that the user has typed that have not been read yet
  1902.           by Kermit.
  1903.           
  1904.    long
  1905.           congspd();
  1906.           Returns the speed ("baud rate") of the controlling terminal, if
  1907.           known, otherwise -1L.
  1908.           
  1909.    int
  1910.           congks(timo) int timo;
  1911.           Get Keyboard Scancode. Reads a keyboard scan code from the
  1912.           physical console keyboard. If the timo parameter is greater
  1913.           than zero, then times out and returns -2 if no character
  1914.           appears within the given number of seconds. Upon any other kind
  1915.           of error, returns -1. Upon success returns a scan code, which
  1916.           may be any positive integer. For situations where scan codes
  1917.           cannot be read (for example, when an ASCII terminal is used as
  1918.           the job's controlling terminal), this function is identical to
  1919.           coninc(), i.e. it returns an 8-bit character value. congks() is
  1920.           for use with workstations whose keyboards have Alternate,
  1921.           Command, Option, and similar modifier keys, and Function keys
  1922.           that generate codes greater than 255.
  1923.           
  1924.    int
  1925.           congm()
  1926.           Console get modes. Gets the current console terminal modes and
  1927.           saves them so that conres() can restore them later. Returns 1
  1928.           if it got the modes OK, 0 if it did nothing (e.g. because
  1929.           Kermit is not connected with any terminal), -1 on error.
  1930.           
  1931.    int
  1932.           coninc(timo) int timo;
  1933.           Console Input Character. Reads a character from the console. If
  1934.           the timo parameter is greater than zero, then coninc() times
  1935.           out and returns -2 if no character appears within the given
  1936.           number of seconds. Upon any other kind of error, returns -1.
  1937.           Upon success, returns the character itself, with a value in the
  1938.           range 0-255 decimal.
  1939.           
  1940.    VOID
  1941.           conint(f,s) SIGTYP (*f)(), (*s)();
  1942.           Sets the console to generate an interrupt if the user types a
  1943.           keyboard interrupt character, and to transfer control the
  1944.           signal-handling function f. For systems with job control, s is
  1945.           the address of the function that suspends the job. Sets the
  1946.           global variable "backgrd" to zero if Kermit is running in the
  1947.           foreground, and to nonzero if Kermit is running in the
  1948.           background. See ckcdeb.h for the definition of SIGTYP. No
  1949.           return value.
  1950.           
  1951.    VOID
  1952.           connoi()
  1953.           Console no interrupts. Disable keyboard interrupts on the
  1954.           console. No return value.
  1955.           
  1956.    int
  1957.           conoc(c) char c;
  1958.           Writes character c to the console terminal. Returns:
  1959.           0 on failure, 1 on success.
  1960.           
  1961.    int
  1962.           conol(s) char *s;
  1963.           Writes string s to the console. Returns -1 on error, 0 or
  1964.           greater on success.
  1965.           
  1966.    int
  1967.           conola(s) char *s[]; {
  1968.           Writes an array of strings to the console. Returns -1 on error,
  1969.           0 or greater on success.
  1970.           
  1971.    int
  1972.           conoll(s) char *s;
  1973.           Writes string s to the console, followed by the necessary line
  1974.           termination characters to put the console cursor at the
  1975.           beginning of the next line. Returns -1 on error, 0 or greater
  1976.           on success.
  1977.           
  1978.    int
  1979.           conres()
  1980.           Restores the console terminal to the modes obtained by congm().
  1981.           Returns: -1 on error, 0 on success.
  1982.           
  1983.    int
  1984.           conxo(x,s) int x; char *s;
  1985.           Write x characters from string s to the console. Returns 0 or
  1986.           greater on success, -1 on error.
  1987.           
  1988.    char *
  1989.           conkbg();
  1990.           Returns a pointer to the designator of the console keyboard
  1991.           type. For example, on a PC, this function would return "88",
  1992.           "101", etc. Upon failure, returns a pointer to the empty
  1993.           string.
  1994.           
  1995.     4.E.2.5. Communications Functions
  1996.     
  1997.    The communication device is the device used for terminal emulation and
  1998.    file transfer. It may or may not be the same device as the console,
  1999.    and it may or may not be a terminal (serial-port) device; it could
  2000.    also be a network connection. For brevity, the communication device is
  2001.    referred to here as the "tty". When the communication device is the
  2002.    same as the console device, Kermit is said to be in remote mode. When
  2003.    the two devices are different, Kermit is in local mode.
  2004.    
  2005.    int
  2006.           ttchk()
  2007.           Returns the number of characters that have arrived at the
  2008.           communication device but have not yet been read by ttinc(),
  2009.           ttinl(), and friends. If communication input is buffered (and
  2010.           it should be), this is the sum of the number of unread
  2011.           characters in Kermit's buffer PLUS the number of unread
  2012.           characters in the operating system's internal buffer. The call
  2013.           must be nondestructive and nonblocking, and as inexpensive as
  2014.           possible. Returns:
  2015.             0: or greater on success,
  2016.             0: in case of internal error,
  2017.            -1: or less when it determines the connection has been broken,
  2018.           or there is no connection.
  2019.           
  2020.           That is, a negative return from ttchk() should reliably
  2021.           indicate that there is no usable connection. Furthermore,
  2022.           ttchk() should be callable at any time to see if the connection
  2023.           is open. When the connection is open, every effort must be made
  2024.           to ensure that ttchk returns an accurate number of characters
  2025.           waiting to be read, rather than just 0 (no characters) or 1 (1
  2026.           or more characters), as would be the case when we use select().
  2027.           This aspect of ttchk's operation is critical to successful
  2028.           operation of sliding windows and streaming, but "nondestructive
  2029.           buffer peeking" is an obscure operating system feature, and so
  2030.           when it is not available, we have to do it ourselves by
  2031.           managing our own internal buffer at a level below ttinc(),
  2032.           ttinl(), etc, as in the UNIX version (non-FIONREAD case).
  2033.           
  2034.           An external global variable, clsondisc, if nonzero, means that
  2035.           if a serial connection drops (carrier on-to-off transition
  2036.           detected by ttchk()), the device should be closed and released
  2037.           automatically.
  2038.           
  2039.    int
  2040.           ttclos()
  2041.           Closes the communication device (tty or network). If there were
  2042.           any kind of exclusive access locks connected with the tty,
  2043.           these are released. If the tty has a modem connection, it is
  2044.           hung up. For true tty devices, the original tty device modes
  2045.           are restored. Returns:
  2046.            -1: on failure.
  2047.             0: on success.
  2048.           
  2049.    int
  2050.           ttflui()
  2051.           Flush communications input buffer. If any characters have
  2052.           arrived but have not yet been read, discard these characters.
  2053.           If communications input is buffered by Kermit (and it should
  2054.           be), this function flushes Kermit's buffer as well as the
  2055.           operating system's internal input buffer. Returns:
  2056.            -1: on failure.
  2057.             0: on success.
  2058.           
  2059.    int
  2060.           ttfluo()
  2061.           Flush tty output buffer. If any characters have been written
  2062.           but not actually transmitted (e.g. because the system has been
  2063.           flow-controlled), remove them from the system's output buffer.
  2064.           (Note, this function is not actually used, but it is
  2065.           recommended that all C-Kermit programmers add it for future
  2066.           use, even if it is only a dummy function that returns 0
  2067.           always.)
  2068.           
  2069.    int
  2070.           ttgmdm()
  2071.           Looks for the modem signals CTS, DSR, and CTS, and returns
  2072.           those that are on in as its return value, in a bit mask as
  2073.           described for ttwmdm, in which a bit is on (1) or off (0)
  2074.           according to whether the corresponding signal is on (asserted)
  2075.           or off (not asserted). Return values:
  2076.            -3: Not implemented
  2077.            -2: if the line does not have modem control
  2078.            -1: on error
  2079.           >=0: on success, with bit mask containing the modem signals.
  2080.           
  2081.    long
  2082.           ttgspd()
  2083.           Returns the current tty speed in BITS (not CHARACTERS) per
  2084.           second, or -1 if it is not known or if the tty is really a
  2085.           network, or upon any kind of error. On success, the speed
  2086.           returned is the actual number of bits per second, like 1200,
  2087.           9600, 19200, etc.
  2088.           
  2089.    int
  2090.           ttgwsiz()
  2091.           Get terminal window size. Returns -1 on error, 0 if the window
  2092.           size can't be obtained, 1 if the window size has been
  2093.           successfully obtained. Upon success, the external global
  2094.           variables tt_rows and tt_cols are set to the number of screen
  2095.           rows and number of screen columns, respectively. As this
  2096.           function is not implemented in all ck*tio.c modules, calls to
  2097.           it must be wrapped in #ifdef CK_TTGWSIZ..#endif. NOTE: This
  2098.           function must be available to use the TELNET NAWS feature
  2099.           (Negotiate About Window Size) as well as Rlogin.
  2100.           
  2101.    int
  2102.           tthang()
  2103.           Hang up the current tty device. For real tty devices, turn off
  2104.           DTR for about 1/3-1/2 second (or other length of time,
  2105.           depending on the system). If the tty is really a network
  2106.           connection, close it. Returns:
  2107.            -1: on failure.
  2108.             0: if it does not even try to hang up.
  2109.             1: if it believes it hung up successfully.
  2110.           
  2111.    VOID
  2112.           ttimoff()
  2113.           Turns off all pending timer interrupts.
  2114.           
  2115.    int
  2116.           ttinc(timo) int timo; (function is old, return codes are new)
  2117.           Reads one character from the communication device. If timo is
  2118.           greater than zero, wait the given number of seconds and then
  2119.           time out if no character arrives, otherwise wait forever for a
  2120.           character. Returns:
  2121.            -3: internal error (e.g. tty modes set wrong)
  2122.            -2: communications disconnect
  2123.            -1: timeout or other error
  2124.           >=0: the character that was read.
  2125.           It is HIGHLY RECOMMENDED that ttinc() be internally buffered so
  2126.           that calls to it are relatively inexpensive. If it is possible
  2127.           to to implement ttinc() as a macro, all the better, for example
  2128.           something like:
  2129.           
  2130.   #define ttinc(t) ( (--txbufn >= 0) ? txbuf[ttbufp++] : txbufr(t) )
  2131.  
  2132.           (see description of txbufr() below)
  2133.           
  2134.    int
  2135.           ttinl(dest,max,timo,eol,start,turn) int max,timo,turn; CHAR
  2136.           *dest, eol, start;
  2137.           ttinl() is Kermit's packet reader. Reads a packet from the
  2138.           communications device, or up to max characters, whichever
  2139.           occurs first. A line is a string of characters starting with
  2140.           the start character up to and including the character given in
  2141.           eol or until the length is exhausted, or, if turn != 0, until
  2142.           the line turnaround character (turn) is read. If turn is 0,
  2143.           ttinl() *should* use the packet length field to detect the end,
  2144.           to allow for the possibility that the eol character appears
  2145.           unprefixed in the packet data. (The turnaround character is for
  2146.           half-duplex linemode connections.)
  2147.           
  2148.           If timo is greater than zero, ttinl() times out if the eol
  2149.           character is not encountered within the given number of seconds
  2150.           and returns -1.
  2151.           
  2152.           The characters that were input are copied into "dest" with
  2153.           their parity bits stripped if parity is not none. The first
  2154.           character copied into dest should be the start character, and
  2155.           the last should be the final character of the packet (the last
  2156.           block check character). ttinl() should also absorb and discard
  2157.           the eol and turn characters, and any other characters that are
  2158.           waiting to be read, up until the next start character, so that
  2159.           subsequent calls to ttchk() will not succeed simply because
  2160.           there are some terminators still sitting in the buffer that
  2161.           ttinl() didn't read. This operation, if performed, MUST NOT
  2162.           BLOCK (so if it can't be performed in a guaranteed nonblocking
  2163.           way, don't do it).
  2164.           
  2165.           On success, ttinl() returns the number of characters read.
  2166.           Optionally, ttinl() can sense the parity of incoming packets.
  2167.           If it does this, then it should set the global variable ttprty
  2168.           accordingly. ttinl() should be coded to be as efficient as
  2169.           possible, since it is at the "inner loop" of packet reception.
  2170.           ttinl() returns:
  2171.            -1: Timeout or other possibly correctable error.
  2172.            -2: Interrupted from keyboard.
  2173.            -3: Uncorrectable i/o error -- connection lost, configuration
  2174.           problem, etc.
  2175.           >=0: on success, the number of characters that were actually
  2176.           read and placed in the dest buffer, not counting the trailing
  2177.           null.
  2178.           
  2179.    int
  2180.           ttoc(c) char c;
  2181.           Outputs the character c to the communication line. If the
  2182.           operation fails to complete within two seconds, this function
  2183.           returns -1. Otherwise it returns the number of characters
  2184.           actually written to the tty (0 or 1). This function should only
  2185.           be used for interactive, character-mode operations, like
  2186.           terminal connection, script execution, dialer i/o, where the
  2187.           overhead of the signals and alarms does not create a
  2188.           bottleneck. (THIS DESCRIPTION NEEDS IMPROVEMENT -- If the
  2189.           operation fails within a "certain amount of time"... which
  2190.           might be dependent on the communication method, speed, etc. In
  2191.           particular, flow-control deadlocks must be accounted for and
  2192.           broken out of to prevent the program from hanging indefinitely,
  2193.           etc.)
  2194.           
  2195.    int
  2196.           ttol(s,n) int n; char *s;
  2197.           Kermit's packet writer. Writes the n characters of the string
  2198.           pointed to to by s. NOTE: It is ttol's responsibility to write
  2199.           ALL of the characters, not just some of them. Returns:
  2200.            -1: on a possibly correctable error (so it can be retried).
  2201.            -3: on a fatal error, e.g. connection lost.
  2202.           >=0: on success, the actual number of characters written (the
  2203.           specific number is not actually used for anything).
  2204.           
  2205.    int
  2206.           ttopen(ttname,lcl,modem,timo) char *ttname; int *lcl, modem,
  2207.           timo;
  2208.           Opens a tty device, if it is not already open. ttopen must
  2209.           check to make sure the SAME device is not already open; if it
  2210.           is, ttopen returns successfully without doing anything. If a
  2211.           DIFFERENT device is currently open, ttopen() must call ttclos()
  2212.           to close it before opening the new one.
  2213.           
  2214.         Parameters:
  2215.                 
  2216.               ttname:
  2217.                       character string - device name or network host
  2218.                       name.
  2219.                       
  2220.               lcl:
  2221.                       If called with lcl < 0, sets value of lcl as
  2222.                       follows:
  2223.                       0: the terminal named by ttname is the job's
  2224.                       controlling terminal.
  2225.                       1: the terminal named by ttname is not the job's
  2226.                       controlling terminal.
  2227.                       If the device is already open, or if the requested
  2228.                       device can't be opened, then lcl remains (and is
  2229.                       returned as) -1.
  2230.                       
  2231.               modem:
  2232.                       Less than zero: this is the negative of the network
  2233.                       type, and ttname is a network host name. Network
  2234.                       types (from [112]ckcnet.h:
  2235.                       
  2236.  
  2237.   NET_TCPB 1   TCP/IP Berkeley (socket)  (implemented in [113]ckutio.c)
  2238.   NET_TCPA 2   TCP/IP AT&T (streams)     (not yet implemented)
  2239.   NET_DEC  3   DECnet                    (not yet implemented)
  2240.  
  2241.               Zero or greater: ttname is a terminal device name. Zero
  2242.                       means a direct connection (don't use modem
  2243.                       signals). Positive means use modem signals
  2244.                       depending on the current setting of ttcarr (see
  2245.                       ttscarr()).
  2246.                       
  2247.               timo:
  2248.                       > 0: number of seconds to wait for open() to return
  2249.                       before timing out.
  2250.                       <=0: no timer, wait forever (e.g. for incoming
  2251.                       call).
  2252.                       For real tty devices, ttopen() attempts to gain
  2253.                       exclusive access to the tty device, for example in
  2254.                       UNIX by creating a "lockfile" (in other operating
  2255.                       systems, like VMS, exclusive access probably
  2256.                       requires no special action).
  2257.                       
  2258.         Side effects:
  2259.                 Copies its arguments and the tty file descriptor to
  2260.                 global variables that are available to the other
  2261.                 tty-related functions, with the lcl value altered as
  2262.                 described above. Gets all parameters and settings
  2263.                 associated with the line and puts them in a global area,
  2264.                 so that they can be restored by ttres(), e.g. when the
  2265.                 device is closed.
  2266.                 
  2267.         Returns:
  2268.                   0: on success
  2269.                  -5: if device is in use
  2270.                  -4: if access to device is denied
  2271.                  -3: if access to lock mechanism denied
  2272.                  -2: upon timeout waiting for device to open
  2273.                  -1: on other error
  2274.                 
  2275.    int
  2276.           ttpkt(speed,flow,parity) long speed; int flow, parity;
  2277.           Puts the currently open tty device into the appropriate modes
  2278.           for transmitting and receiving Kermit packets.
  2279.           
  2280.         Arguments:
  2281.                 
  2282.               speed:
  2283.                       if speed > -1, and the device is a true tty device,
  2284.                       and Kermit is in local mode, ttpkt also sets the
  2285.                       speed.
  2286.                       
  2287.               flow:
  2288.                       if in the range 0-3, ttpkt selects the
  2289.                       corresponding type of flow control. Currently 0 is
  2290.                       defined as no flow control, 1 is Xon/Xoff, and no
  2291.                       other types are defined. If (and this is a horrible
  2292.                       hack, but it goes back many years and will be hard
  2293.                       to eradicate) flow is 4, then the appropriate tty
  2294.                       modes are set for modem dialing, a special case in
  2295.                       which we talk to a modem-controlled line without
  2296.                       requiring carrier. If flow is 5, then we require
  2297.                       carrier.
  2298.                       
  2299.               parity:
  2300.                       This is simply copied into a global variable so
  2301.                       that other functions (like ttinl, ttinc, etc) can
  2302.                       use it.
  2303.                       
  2304.         Side effects:
  2305.                 Copies its arguments to global variables, flushes the
  2306.                 terminal device input buffer.
  2307.                 
  2308.         Returns:
  2309.                  -1: on error.
  2310.                   0: on success.
  2311.                 
  2312.    int
  2313.           ttsetflow(int)
  2314.           Enables the given type of flow control on the open serial
  2315.           communications device immediately. Arguments are the FLO_xxx
  2316.           values from ckcdeb.h, except FLO_DIAL, FLO_DIAX, or FLO_AUTO,
  2317.           which are not actual flow-control types. Returns 0 on success,
  2318.           -1 on failure.
  2319.           
  2320.    #ifdef TTSPDLIST
  2321.           
  2322.    long *
  2323.           ttspdlist()
  2324.           Returns a pointer to an array of longs, or NULL on failure. On
  2325.           success, element 0 of the array contains number, n, indicating
  2326.           how many follow. Elements 1-n are serial speeds, expressed in
  2327.           bits per second, that are legal on this platform. The user
  2328.           interface may use this list to construct a menu, keyword table,
  2329.           etc.
  2330.           
  2331.    #endif /* TTSPDLIST */
  2332.           
  2333.    int
  2334.           ttres()
  2335.           Restores the tty device to the modes and settings that were in
  2336.           effect at the time it was opened (see ttopen). Returns:
  2337.            -1: on error.
  2338.             0: on success.
  2339.           
  2340.    int
  2341.           ttruncmd(string) char * string;
  2342.           Runs the given command on the local system, but redirects its
  2343.           input and output to the communication (SET LINE, SET PORT, or
  2344.           SET HOST) device. Returns:
  2345.             0: on failure.
  2346.             1: on success.
  2347.           
  2348.    int
  2349.           ttscarr(carrier) int carrier;
  2350.           Copies its argument to a variable that is global to the other
  2351.           tty-related functions, and then returns it. The values for
  2352.           carrier are defined in ckcdeb.h: CAR_ON, CAR_OFF, CAR_AUTO.
  2353.           ttopen(), ttpkt(), and ttvt() use this variable when deciding
  2354.           how to open the tty device and what modes to select. The
  2355.           meanings are these:
  2356.           
  2357.           CAR_OFF: Ignore carrier at all times.
  2358.           CAR_ON: Require carrier at all times, except when dialing. This
  2359.           means, for example, that ttopen() could hang forever waiting
  2360.           for carrier if it is not present.
  2361.           CAR_AUTO: If the modem type is zero (i.e. the connection is
  2362.           direct), this is the same as CAR_OFF. If the modem type is
  2363.           positive, then heed carrier during CONNECT (ttvt mode), but
  2364.           ignore it at other times (packet mode, during SET LINE, etc).
  2365.           Compatible with pre-5A versions of C-Kermit. This should be the
  2366.           default carrier mode.
  2367.           
  2368.           Kermit's DIAL command ignores the carrier setting, but
  2369.           ttopen(), ttvt(), and ttpkt() all honor the carrier option in
  2370.           effect at the time they are called. None of this applies to
  2371.           remote mode (the tty device is the job's controlling terminal)
  2372.           or to network host connections (modem type is negative).
  2373.           
  2374.    int
  2375.           ttsndb()
  2376.           Sends a BREAK signal on the tty device. On a real tty device,
  2377.           send a real BREAK lasting approximately 275 milliseconds. If
  2378.           this is not possible, simulate a BREAK by (for example)
  2379.           dropping down some very low baud rate, like 50, and sending a
  2380.           bunch of null characters. On a network connection, do the
  2381.           appropriate network protocol for BREAK. Returns:
  2382.            -1: on error.
  2383.             0: on success.
  2384.           
  2385.    int
  2386.           ttsndlb()
  2387.           Like ttsndb(), but sends a "Long BREAK" (approx 1.5 seconds).
  2388.           For network connections, it is identical to ttsndb().
  2389.           Currently, this function is used only if CK_LBRK is defined (as
  2390.           it is for UNIX and VMS).
  2391.           
  2392.    int
  2393.           ttsspd(cps) int cps;
  2394.           For serial devices only, set the device transmission speed to
  2395.           (note carefully) TEN TIMES the argument. The argument is in
  2396.           characters per second, but transmission speeds are in bits per
  2397.           second. cps are used rather than bps because high speeds like
  2398.           38400 are not expressible in a 16-bit int but longs cannot be
  2399.           used because keyword-table values are ints and not longs. If
  2400.           the argument is 7, then the bps is 75, not 70. If the argument
  2401.           is 888, this is a special code for 75/1200 split-speed
  2402.           operation (75 bps out, 1200 bps in). Returns:
  2403.            -1: on error, meaning the requested speed is not valid or
  2404.           available.
  2405.           >=0: on success (don't try to use this value for anything).
  2406.           
  2407.    int
  2408.           ttvt(speed,flow) long speed; int flow;
  2409.           Puts the currently open tty device into the appropriate modes
  2410.           for terminal emulation. The arguments are interpreted as in
  2411.           ttpkt(). Side effects: ttvt() stores its arguments in global
  2412.           variables, and sets a flag that it has been called so that
  2413.           subsequent calls can be ignored so long as the arguments are
  2414.           the same as in the last effective call. Other functions, such
  2415.           as ttopen(), ttclose(), ttres(), ttvt(), etc, that change the
  2416.           tty device in any way must unset this flag. In UNIX Kermit,
  2417.           this flag is called tvtflg.
  2418.           
  2419.    int
  2420.           ttwmdm(mdmsig,timo) int mdmsig, timo;
  2421.           Waits up to timo seconds for all of the given modem signals to
  2422.           appear. mdmsig is a bit mask, in which a bit is on (1) or off
  2423.           (0) according to whether the corresponding signal is to be
  2424.           waited for. These symbols are defined in ckcdeb.h:
  2425.             BM_CTS (bit 0) means wait for Clear To Send
  2426.             BM_DSR (bit 1) means wait for Data Set Ready
  2427.             BM_DCD (bit 2) means wait for Carrier Detect
  2428.           Returns:
  2429.            -3: Not implemented.
  2430.            -2: This line does not have modem control.
  2431.            -1: Timeout: time limit exceeded before all signals were
  2432.           detected.
  2433.             1: Success.
  2434.           
  2435.    int
  2436.           ttxin(n,buf) int n; CHAR *buf;
  2437.           Reads x characters from the tty device into the specified buf,
  2438.           stripping parity if parity is not none. This call waits
  2439.           forever, there is no timeout. This function is designed to be
  2440.           called only when you know that at least x characters are
  2441.           waiting to be read (as determined, for example, by ttchk()).
  2442.           This function should use the same buffer as ttinc().
  2443.           
  2444.    int
  2445.           txbufr(timo) int timo;
  2446.           Reads characters into the internal communications input buffer.
  2447.           timo is a timeout interval, in seconds. 0 means no timeout,
  2448.           wait forever. Called by ttinc() (and possibly ttxin() and
  2449.           ttinl()) when the communications input buffer is empty. The
  2450.           buffer should be called ttxbuf[], its length is defined by the
  2451.           symbol TXBUFL. The global variable txbufn is the number of
  2452.           characters available to be read from ttxbuf[], and txbufp is
  2453.           the index of the next character to be read. Should not be
  2454.           called if txbufn > 0, in which case the buffer does not need
  2455.           refilling. This routine returns:
  2456.             -2: Communications disconnect
  2457.             -1: Timeout
  2458.           >=0: A character (0 - 255) On success, the first character that
  2459.           was read, with the variables txbufn and txbufp set
  2460.           appropriately for any remaining characters.
  2461.           NOTE: Currently this routine is used internally only by the
  2462.           UNIX and VMS versions. The aim is to make it available to all
  2463.           versions so there is one single coherent and efficient way of
  2464.           reading from the communications device or network.
  2465.           
  2466.     4.E.2.6. Miscellaneous system-dependent functions
  2467.     
  2468.    VOID
  2469.           ztime(s) char **s;
  2470.           Returns a pointer, s, to the current date-and-time string in s.
  2471.           This string must be in the fixed-field format associated with
  2472.           the C runtime asctime() function, like: "Sun Sep 16 13:23:45
  2473.           1973\n" so that callers of this function can extract the
  2474.           different fields. The pointer value is filled in by ztime, and
  2475.           the data it points to is not safe, so should be copied to a
  2476.           safe place before use. ztime() has no return value. As a side
  2477.           effect, this routine can also fill in the following two
  2478.           external variables (which must be defined in the
  2479.           system-dependendent modules for each platform):
  2480.             long ztusec: Fraction of seconds of clock time, microseconds.
  2481.             long ztmsec: Fraction of seconds of clock time, milliseconds.
  2482.           If these variables are not set by zstime(), they remain at
  2483.           their initial value of -1L.
  2484.           
  2485.    int
  2486.           gtimer()
  2487.           Returns the current value of the elapsed time counter in
  2488.           seconds (see rtimer), or 0 on any kind of error.
  2489.           
  2490.    #ifdef GFTIMER
  2491.           CKFLOAT
  2492.           gftimer()
  2493.           Returns the current value of the elapsed time counter in
  2494.           seconds, as a floating point number, capable of representing
  2495.           not only whole seconds, but also the fractional part, to the
  2496.           millisecond or microsecond level, whatever precision is
  2497.           available. Requires a function to get times at subsecond
  2498.           precision, as well as floating-point support. That's why it's
  2499.           #ifdef'd.
  2500.           
  2501.    #endif /* GFTIMER */
  2502.           
  2503.    int
  2504.           msleep(m) int m;
  2505.           Sleeps (pauses, does nothing) for m milliseconds (a millisecond
  2506.           is one thousandth of a second). Returns:
  2507.            -1: on failure.
  2508.             0: on success.
  2509.           
  2510.    VOID
  2511.           rtimer()
  2512.           Sets the elapsed time counter to zero. If you want to time how
  2513.           long an operation takes, call rtimer() when it starts and
  2514.           gtimer when it ends. rtimer() has no return value.
  2515.           
  2516.    #ifdef GFTIMER
  2517.           VOID
  2518.           rftimer()
  2519.           Sets the elapsed time counter to zero. If you want to time how
  2520.           long an operation takes, call rftimer() when it starts and
  2521.           gftimer when it ends. rftimer() has no return value. Note:
  2522.           rftimer() is to be used with gftimer() and rtimer() is to be
  2523.           used with gtimer(). See the rftimer() description.
  2524.           
  2525.    #endif /* GFTIMER */
  2526.           
  2527.    int
  2528.           sysinit()
  2529.           Does whatever needs doing upon program start. In particular, if
  2530.           the program is running in any kind of privileged mode, turns
  2531.           off the privileges (see priv_ini()). Returns:
  2532.            -1: on error.
  2533.             0: on success.
  2534.           
  2535.    int
  2536.           syscleanup()
  2537.           Does whatever needs doing upon program exit. Returns:
  2538.            -1: on error.
  2539.             0: on success.
  2540.           
  2541.    int
  2542.           psuspend()
  2543.           Suspends the Kermit process, puts it in the background so it
  2544.           can be continued ("foregrounded") later. Returns:
  2545.            -1: if this function is not supported.
  2546.             0: on success.
  2547.           
  2548.    [ [114]Contents ] [ [115]C-Kermit ] [ [116]Kermit Home ]
  2549.     ________________________________________________________________________
  2550.   
  2551.   4.F. Group F: Network Support
  2552.   
  2553.    As of version 5A, C-Kermit includes support for several networks.
  2554.    Originally, this was just worked into the ttopen(), ttclos(), ttinc(),
  2555.    ttinl(), and similar routines in [117]ckutio.c. But this made it
  2556.    impossible to share this code with non-UNIX versions, like VMS,
  2557.    AOS/VS, OS/2, etc. So as of edit 168, network code has been separated
  2558.    out into its own module and header file, ckcnet.c and ckcnet.h:
  2559.    
  2560.      [118]ckcnet.h: Network-related symbol definitions.
  2561.      [119]ckcnet.c: Network i/o (TCP/IP, X.25, etc), shared by most
  2562.    platforms.
  2563.      [120]cklnet.c: Network i/o (TCP/IP, X.25, etc) specific to Stratus
  2564.    VOS.
  2565.    
  2566.    The routines and variables in these modules fall into two categories:
  2567.    
  2568.     1. Support for specific network packages like SunLink X.25 and TGV
  2569.        MultiNet, and:
  2570.     2. support for specific network virtual terminal protocols like CCITT
  2571.        X.3 and TCP/IP Telnet.
  2572.        
  2573.    Category (1) functions are analogs to the tt*() functions, and have
  2574.    names like netopen, netclos, nettinc, etc. Group A-D modules do not
  2575.    (and must not) know anything about these functions -- they continue to
  2576.    call the old Group E functions (ttopen, ttinc, etc). Category (2)
  2577.    functions are protocol specific and have names prefixed by a protocol
  2578.    identifier, like tn for telnet x25 for X.25.
  2579.    
  2580.    ckcnet.h contains prototypes for all these functions, as well as
  2581.    symbol definitions for network types, protocols, and network- and
  2582.    protocol- specific symbols, as well as #includes for the header files
  2583.    necessary for each network and protocol.
  2584.    
  2585.    The following functions are to be provided for networks that do not
  2586.    use normal system i/o (open, read, write, close):
  2587.    
  2588.    int
  2589.           netopen()
  2590.           To be called from within ttopen() when a network connection is
  2591.           requested. Calling conventions and purpose same as Group E
  2592.           ttopen().
  2593.           
  2594.    int
  2595.           netclos()
  2596.           To be called from within ttclos() when a network connection is
  2597.           being closed. Calling conventions and purpose same as Group E
  2598.           ttclos().
  2599.           
  2600.    int
  2601.           nettchk()
  2602.           To be called from within ttchk(). Calling conventions and
  2603.           purpose same as Group E ttchk().
  2604.           
  2605.    int
  2606.           netflui()
  2607.           To be called from within ttflui(). Calling conventions and
  2608.           purpose same as Group E ttflui().
  2609.           
  2610.    int
  2611.           netbreak()
  2612.           To send a network break (attention) signal. Calling conventions
  2613.           and purpose same as Group E ttsndbrk().
  2614.           
  2615.    int
  2616.           netinc()
  2617.           To get a character from the network. Calling conventions same
  2618.           as Group E ttsndbrk().
  2619.           
  2620.    int
  2621.           nettoc()
  2622.           Send a "character" (byte) to the network. Calling conventions
  2623.           same as Group E ttoc().
  2624.           
  2625.    int
  2626.           nettol()
  2627.           Send a "line" (sequence of bytes) to the network. Calling
  2628.           conventions same as Group E ttol().
  2629.           
  2630.    Conceivably, some systems support network connections simply by
  2631.    letting you open a device of a certain name and letting you do i/o to
  2632.    it. Others (like the Berkeley sockets TCP/IP library on UNIX) require
  2633.    you to open the connection in a special way, but then do normal i/o
  2634.    (read, write). In such a case, you would use netopen(), but you would
  2635.    not use nettinc, nettoc, etc.
  2636.    
  2637.    VMS TCP/IP products have their own set of functions for all network
  2638.    operations, so in that case the full range of netxxx() functions is
  2639.    used.
  2640.    
  2641.    The technique is to put a test in each corresponding ttxxx() function
  2642.    to see if a network connection is active (or is being requested), test
  2643.    for which kind of network it is, and if necessary route the call to
  2644.    the corresponding netxxx() function. The netxxx() function must also
  2645.    contain code to test for the network type, which is available via the
  2646.    global variable ttnet.
  2647.    
  2648.    [ [121]Contents ] [ [122]C-Kermit ] [ [123]Kermit Home ]
  2649.       ______________________________________________________________________
  2650.     
  2651.     4.F.1. Telnet Protocol
  2652.     
  2653.    (This section needs a great deal of updating...)
  2654.    
  2655.    As of edit 195, Telnet protocol is split out into its own files, since
  2656.    it can be implemented in remote mode, which does not have a network
  2657.    connection:
  2658.    
  2659.       [124]ckctel.h: Telnet protocol symbol definitions.
  2660.       [125]ckctel.c: Telnet protocol.
  2661.    
  2662.    The Telnet protocol is supported by the following variables and
  2663.    routines:
  2664.    
  2665.    int tn_init
  2666.           Nonzero if telnet protocol initialized, zero otherwise.
  2667.           
  2668.    int
  2669.           tn_init()
  2670.           Initialize the telnet protocol (send initial options).
  2671.           
  2672.    int
  2673.           tn_sopt()
  2674.           Send a telnet option.
  2675.           
  2676.    int
  2677.           tn_doop()
  2678.           Receive and act on a telnet option from the remote.
  2679.           
  2680.    int
  2681.           tn_sttyp()
  2682.           Send terminal type using telnet protocol.
  2683.       ______________________________________________________________________
  2684.     
  2685.     4.F.2. FTP Protocol
  2686.     
  2687.    (To be filled in...)
  2688.       ______________________________________________________________________
  2689.     
  2690.     4.F.3. HTTP Protocol
  2691.     
  2692.    (To be filled in...)
  2693.       ______________________________________________________________________
  2694.     
  2695.     4.F.4. X.25 Networks
  2696.     
  2697.    These routines were written SunLink X.25 and have since been adapted
  2698.    to at least on one other: IBM AIXLink/X.25.
  2699.    
  2700.    int
  2701.           x25diag()
  2702.           Reads and prints X.25 diagnostics
  2703.           
  2704.    int
  2705.           x25oobh()
  2706.           X.25 out of band signal handler
  2707.           
  2708.    int
  2709.           x25intr()
  2710.           Sends X.25 interrupt packet
  2711.           
  2712.    int
  2713.           x25reset()
  2714.           Resets X.25 virtual circuit
  2715.           
  2716.    int
  2717.           x25clear()
  2718.           Clear X.25 virtual circuit
  2719.           
  2720.    int
  2721.           x25stat()
  2722.           X.25 status
  2723.           
  2724.    int
  2725.           setqbit()
  2726.           Sets X.25 Q-bit
  2727.           
  2728.    int
  2729.           resetqbit()
  2730.           Resets X.25 Q-bit
  2731.           
  2732.    int
  2733.           x25xin()
  2734.           Reads n characters from X.25 circuit.
  2735.           
  2736.    int
  2737.           x25inl()
  2738.           Read a Kermit packet from X.25 circuit.
  2739.           
  2740.    [ [126]Contents ] [ [127]C-Kermit ] [ [128]Kermit Home ]
  2741.       ______________________________________________________________________
  2742.     
  2743.     4.F.5. Adding New Network Types
  2744.     
  2745.    Example: Adding support for IBM X.25 and Hewlett Packard X.25. First,
  2746.    add new network type symbols for each one. There are already some
  2747.    network types defined for other X.25 packages:
  2748.    
  2749.   NET_SX25 is the network-type ID for SunLink X.25.
  2750.   NET_VX25 is the network-type ID for VOS X.25.
  2751.  
  2752.    So first you should new symbols for the new network types, giving them
  2753.    the next numbers in the sequence, e.g.:
  2754.    
  2755. #define NET_HX25 11                     /* Hewlett-Packard X.25 */
  2756. #define NET_IX25 12                     /* IBM X.25 */
  2757.  
  2758.    This is in ckcnet.h.
  2759.    
  2760.    Then we need symbols to say that we are actually compiling in the code
  2761.    for these platforms. These would be defined on the cc command line:
  2762.    
  2763.   -DIBMX25  (for IBM)
  2764.   -DHPX25   (for HP)
  2765.  
  2766.    So we can build C-Kermit versions for AIX and HP-UX both with and
  2767.    without X.25 support (since not all AIX and IBM systems have the
  2768.    needed libraries, and so an executable that was linked with them might
  2769.    no load).
  2770.    
  2771.    Then in ckcnet.h:
  2772.    
  2773. #ifdef IBMX25
  2774. #define ANYX25
  2775. #endif /* IBMX25 */
  2776.  
  2777. #ifdef HPX25
  2778. #define ANYX25
  2779. #endif /* HPX25 */
  2780.  
  2781.    And then use ANYX25 for code that is common to all of them, and IBMX25
  2782.    or HPX25 for code specific to IBM or HP.
  2783.    
  2784.    It might also happen that some code can be shared between two or more
  2785.    of these, but not the others. Suppose, for example, that you write
  2786.    code that applies to both IBM and HP, but not Sun or VOS X.25. Then
  2787.    you add the following definition to ckcnet.h:
  2788.    
  2789. #ifndef HPORIBMX25
  2790. #ifdef HPX25
  2791. #define HPORIBMX25
  2792. #else
  2793. #ifdef IBMX25
  2794. #define HPORIBMX25
  2795. #endif /* IBMX25 */
  2796. #endif /* HPX25 */
  2797. #endif /* HPORIBMX25 */
  2798.  
  2799.    You can NOT use constructions like "#if defined (HPX25 || IBMX25)";
  2800.    they are not portable.
  2801.    
  2802.    [ [129]Contents ] [ [130]C-Kermit ] [ [131]Kermit Home ]
  2803.     ________________________________________________________________________
  2804.   
  2805.   4.G. Group G: Formatted Screen Support
  2806.   
  2807.    So far, this is used only for the fullscreen local-mode file transfer
  2808.    display. In the future, it might be extended to other uses. The
  2809.    fullscreen display code is in and around the routine screenc() in
  2810.    [132]ckuusx.c.
  2811.    
  2812.    In the UNIX version, we use the curses library, plus one call from the
  2813.    termcap library. In other versions (OS/2, VMS, etc) we insert dummy
  2814.    routines that have the same names as curses routines. So far, there
  2815.    are two methods for simulating curses routines:
  2816.    
  2817.     1. In VMS, we use the Screen Management Library (SMG), and insert
  2818.        stubs to convert curses calls into SMG calls.
  2819.     2. In OS/2, we use the MYCURSES code, in which the stub routines
  2820.        actually emit the appropriate escape sequences themselves.
  2821.        
  2822.    Here are the stub routines:
  2823.    
  2824.    int
  2825.           tgetent(char *buf, char *term)
  2826.           Arguments are ignored. Returns 1 if the user has a supported
  2827.           terminal type, 0 otherwise. Sets a global variable (for
  2828.           example, "isvt52" or "isdasher") to indicate the terminal type.
  2829.           
  2830.    VOID
  2831.           move(int row, int col)
  2832.           Sends the escape sequence to position the cursor at the
  2833.           indicated row and column. The numbers are 0-based, e.g. the
  2834.           home position is 0,0.
  2835.           
  2836.    int
  2837.           clear()
  2838.           Sends the escape sequence to clear the screen.
  2839.           
  2840.    int
  2841.           clrtoeol()
  2842.           Sends the escape sequence to clear from the current cursor
  2843.           position to the end of the line.
  2844.           
  2845.    In the MYCURSES case, code must be added to each of the last three
  2846.    routines to emit the appropriate escape sequences for a new terminal
  2847.    type.
  2848.    
  2849.    clearok(curscr), wrefresh()
  2850.           In real curses, these two calls are required to refresh the
  2851.           screen, for example after it was fractured by a broadcast
  2852.           message. These are useful only if the underlying screen
  2853.           management service keeps a copy of the entire screen, as curses
  2854.           and SMG do. C-Kermit does not do this itself.
  2855.           
  2856.    [ [133]Contents ] [ [134]C-Kermit ] [ [135]Kermit Home ]
  2857.     ________________________________________________________________________
  2858.   
  2859.   4.H. Group H: Pseudoterminal Support
  2860.   
  2861.    (To be filled in...)
  2862.     ________________________________________________________________________
  2863.   
  2864.   4.I. Group I: Security
  2865.   
  2866.    (To be filled in...)
  2867.    
  2868.    [ [136]Contents ] [ [137]C-Kermit ] [ [138]Kermit Home ]
  2869.     ________________________________________________________________________
  2870.   
  2871.   APPENDIX I. FILE PERMISSIONS
  2872.   
  2873.   I.1. Format of System-Dependent File Permissions in A-Packets
  2874.   
  2875.    The format of this field (the "," attribute) is interpreted according
  2876.    to the System ID ("." Attribute).
  2877.    
  2878.    For UNIX (System ID = U1), it's the familiar 3-digit octal number, the
  2879.    low-order 9 bits of the filemode: Owner, Group, World, e.g. 660 =
  2880.    read/write access for owner and group, none for world, recorded as a
  2881.    3-digit octal string. High-order UNIX permission bits are not
  2882.    transmitted.
  2883.    
  2884.    For VMS (System ID = D7), it's a 4-digit hex string, representing the
  2885.    16-bit file protection WGOS fields (World,Group,Owner,System), in that
  2886.    order (which is the reverse of how they're shown in a directory
  2887.    listing); in each field, Bit 0 = Read, 1 = Write, 2 = Execute, 3 =
  2888.    Delete. A bit value of 0 means permission is granted, 1 means
  2889.    permission is denied. Sample:
  2890.    
  2891.   r-01-00-^A/!FWERMIT.EXE'"
  2892.   s-01-00-^AE!Y/amd/watsun/w/fdc/new/wermit.exe.DV
  2893.   r-02-01-^A]"A."D7""B8#119980101 18:14:05!#8531&872960,$A20B-!7(#512@ #.Y
  2894.   s-02-01-^A%"Y.5!
  2895.  
  2896.    A VMS directory listing shows the file's protection as (E,RWED,RED,RE)
  2897.    which really means (S=E,O=RWED,G=RED,W=RE), which is reverse order
  2898.    from the internal storage, so (RE,RED,RWED,E). Now translate each
  2899.    letter to its corresponding bit:
  2900.    
  2901.   RE=0101, RED=1101, RWED=1111, E=0010
  2902.  
  2903.    Now reverse the bits:
  2904.    
  2905.   RE=1010, RED=0010, RWED=0000, E=1101
  2906.  
  2907.    This gives the 16-bit quantity:
  2908.    
  2909.   1010001000001101
  2910.  
  2911.    This is the internal representation of the VMS file permission; in
  2912.    hex:
  2913.    
  2914.   A20B
  2915.  
  2916.    as shown in the sample packet above.
  2917.    
  2918.    The VMS format probably would also apply to RSX or any other FILES-11
  2919.    system.
  2920.    
  2921.   I.2. Handling of Generic Protection
  2922.   
  2923.    To be used when the two systems are different (and/or do not recognize
  2924.    or understand each other's local protection codes).
  2925.    
  2926.    First of all, the book is wrong. This should not be the World
  2927.    protection, but the Owner protection. The other fields should be set
  2928.    according to system defaults (e.g. UNIX umask, VMS default protection,
  2929.    etc), except that no non-Owner field should give more permissions than
  2930.    the Owner field.
  2931.    
  2932.    [ [139]Top ] [ [140]Contents ] [ [141]C-Kermit Home ] [ [142]Kermit
  2933.    Home ]
  2934.      _________________________________________________________________
  2935.    
  2936.    
  2937.     C-Kermit Program Logic Manual / [143]The Kermit Project /
  2938.     [144]Columbia University / [145]kermit@columbia.edu / 12 Dec 2001
  2939.  
  2940. References
  2941.  
  2942.    1. http://www.columbia.edu/kermit/
  2943.    2. http://www.columbia.edu/
  2944.    3. http://www.columbia.edu/kermit/ckcplm.html
  2945.    4. http://www.columbia.edu/kermit/ckermit.html
  2946.    5. http://www.columbia.edu/kermit/index.html
  2947.    6. http://www.columbia.edu/kermit/ckcplm.html#x1
  2948.    7. http://www.columbia.edu/kermit/ckcplm.html#x2
  2949.    8. http://www.columbia.edu/kermit/ckcplm.html#x3
  2950.    9. http://www.columbia.edu/kermit/ckcplm.html#x4
  2951.   10. http://www.columbia.edu/kermit/ckcplm.html#x4.A
  2952.   11. http://www.columbia.edu/kermit/ckcplm.html#x4.B
  2953.   12. http://www.columbia.edu/kermit/ckcplm.html#x4.C
  2954.   13. http://www.columbia.edu/kermit/ckcplm.html#x4.D
  2955.   14. http://www.columbia.edu/kermit/ckcplm.html#x4.E
  2956.   15. http://www.columbia.edu/kermit/ckcplm.html#x4.F
  2957.   16. http://www.columbia.edu/kermit/ckcplm.html#x4.G
  2958.   17. http://www.columbia.edu/kermit/ckcplm.html#x4.H
  2959.   18. http://www.columbia.edu/kermit/ckcplm.html#x4.I
  2960.   19. http://www.columbia.edu/kermit/ckcplm.html#xa1
  2961.   20. http://www.columbia.edu/kermit/ckcplm.html#contents
  2962.   21. http://www.columbia.edu/kermit/ckcplm.html#contents
  2963.   22. http://www.columbia.edu/kermit/ckermit.html
  2964.   23. http://www.columbia.edu/kermit/index.html
  2965.   24. ftp://kermit.columbia.edu/kermit/c-kermit/ckcpro.w
  2966.   25. http://www.columbia.edu/kermit/ckcplm.html#contents
  2967.   26. http://www.columbia.edu/kermit/ckermit.html
  2968.   27. http://www.columbia.edu/kermit/index.html
  2969.   28. http://www.columbia.edu/kermit/ckcplm.html#x3.2
  2970.   29. http://www.columbia.edu/kermit/ckcplm.html#contents
  2971.   30. http://www.columbia.edu/kermit/ckermit.html
  2972.   31. http://www.columbia.edu/kermit/index.html
  2973.   32. http://www.columbia.edu/kermit/ckcplm.html#x4.A
  2974.   33. http://www.columbia.edu/kermit/ckcplm.html#contents
  2975.   34. http://www.columbia.edu/kermit/ckermit.html
  2976.   35. http://www.columbia.edu/kermit/index.html
  2977.   36. http://www.columbia.edu/kermit/ckcplm.html#contents
  2978.   37. http://www.columbia.edu/kermit/ckermit.html
  2979.   38. http://www.columbia.edu/kermit/index.html
  2980.   39. http://www.columbia.edu/kermit/ckcplm.html#contents
  2981.   40. http://www.columbia.edu/kermit/ckermit.html
  2982.   41. http://www.columbia.edu/kermit/index.html
  2983.   42. ftp://kermit.columbia.edu/kermit/c-kermit/ckclib.h
  2984.   43. ftp://kermit.columbia.edu/kermit/c-kermit/ckclib.c
  2985.   44. http://www.columbia.edu/kermit/ckcplm.html#x3.1
  2986.   45. http://www.columbia.edu/kermit/ckcplm.html#contents
  2987.   46. http://www.columbia.edu/kermit/ckermit.html
  2988.   47. http://www.columbia.edu/kermit/index.html
  2989.   48. ftp://kermit.columbia.edu/kermit/c-kermit/ckcsym.h
  2990.   49. ftp://kermit.columbia.edu/kermit/c-kermit/ckcasc.h
  2991.   50. ftp://kermit.columbia.edu/kermit/c-kermit/ckcsig.h
  2992.   51. ftp://kermit.columbia.edu/kermit/c-kermit/ckcdeb.h
  2993.   52. ftp://kermit.columbia.edu/kermit/c-kermit/ckcker.h
  2994.   53. ftp://kermit.columbia.edu/kermit/c-kermit/ckcxla.h
  2995.   54. ftp://kermit.columbia.edu/kermit/c-kermit/ckcmai.c
  2996.   55. ftp://kermit.columbia.edu/kermit/c-kermit/ckcpro.w
  2997.   56. ftp://kermit.columbia.edu/kermit/c-kermit/ckcfns.c
  2998.   57. ftp://kermit.columbia.edu/kermit/c-kermit/ckcfn2.c
  2999.   58. ftp://kermit.columbia.edu/kermit/c-kermit/ckcfn3.c
  3000.   59. http://www.columbia.edu/kermit/ckcplm.html#x4.B
  3001.   60. http://www.columbia.edu/kermit/ckcplm.html#x4.E
  3002.   61. http://www.columbia.edu/kermit/ckcplm.html#x4.D
  3003.   62. http://www.columbia.edu/kermit/ckcplm.html#contents
  3004.   63. http://www.columbia.edu/kermit/ckermit.html
  3005.   64. http://www.columbia.edu/kermit/index.html
  3006.   65. http://www.columbia.edu/kermit/ckcplm.html#x4.B
  3007.   66. ftp://kermit.columbia.edu/kermit/c-kermit/ckuxla.c
  3008.   67. ftp://kermit.columbia.edu/kermit/c-kermit/ckuxla.h
  3009.   68. ftp://kermit.columbia.edu/kermit/c-kermit/ckcxla.h
  3010.   69. ftp://kermit.columbia.edu/kermit/c-kermit/ckuxla.h
  3011.   70. ftp://kermit.columbia.edu/kermit/c-kermit/ckmxla.h
  3012.   71. ftp://kermit.columbia.edu/kermit/c-kermit/ck?xla
  3013.   72. ftp://kermit.columbia.edu/kermit/c-kermit/ckcuni.h
  3014.   73. ftp://kermit.columbia.edu/kermit/c-kermit/ckcuni.c
  3015.   74. http://www.columbia.edu/kermit/ckcplm.html#contents
  3016.   75. http://www.columbia.edu/kermit/ckermit.html
  3017.   76. http://www.columbia.edu/kermit/index.html
  3018.   77. http://www.columbia.edu/kermit/ckcplm.html#x4.B
  3019.   78. ftp://kermit.columbia.edu/kermit/c-kermit/ckucmd.h
  3020.   79. ftp://kermit.columbia.edu/kermit/c-kermit/ckucmd.c
  3021.   80. http://www.columbia.edu/kermit/ckcplm.html#x4.E
  3022.   81. ftp://kermit.columbia.edu/kermit/c-kermit/ckuusr.h
  3023.   82. ftp://kermit.columbia.edu/kermit/c-kermit/ckuusr.c
  3024.   83. ftp://kermit.columbia.edu/kermit/c-kermit/ckuus2.c
  3025.   84. ftp://kermit.columbia.edu/kermit/c-kermit/ckuus3.c
  3026.   85. ftp://kermit.columbia.edu/kermit/c-kermit/ckuus4.c
  3027.   86. ftp://kermit.columbia.edu/kermit/c-kermit/ckuusy.c
  3028.   87. ftp://kermit.columbia.edu/kermit/c-kermit/ckuusx.c
  3029.   88. ftp://kermit.columbia.edu/kermit/c-kermit/ckuver.h
  3030.   89. ftp://kermit.columbia.edu/kermit/c-kermit/ckuscr.c
  3031.   90. ftp://kermit.columbia.edu/kermit/c-kermit/ckudia.c
  3032.   91. ftp://kermit.columbia.edu/kermit/c-kermit/ckucon.c
  3033.   92. ftp://kermit.columbia.edu/kermit/c-kermit/ckucns.c
  3034.   93. http://www.columbia.edu/kermit/ckcplm.html#x4.E
  3035.   94. ftp://kermit.columbia.edu/kermit/c-kermit/ckcmai.c
  3036.   95. http://www.columbia.edu/kermit/ckcplm.html#contents
  3037.   96. http://www.columbia.edu/kermit/ckermit.html
  3038.   97. http://www.columbia.edu/kermit/index.html
  3039.   98. ftp://kermit.columbia.edu/kermit/c-kermit/ckufio.c
  3040.   99. ftp://kermit.columbia.edu/kermit/c-kermit/ckutio.c
  3041.  100. ftp://kermit.columbia.edu/kermit/c-kermit/ckusig.c
  3042.  101. ftp://kermit.columbia.edu/kermit/c-kermit/ckvfio.c
  3043.  102. ftp://kermit.columbia.edu/kermit/c-kermit/ckusig.c
  3044.  103. ftp://kermit.columbia.edu/kermit/c-kermit/ckcmai.c
  3045.  104. http://www.columbia.edu/kermit/ckcplm.html#contents
  3046.  105. http://www.columbia.edu/kermit/ckermit.html
  3047.  106. http://www.columbia.edu/kermit/index.html
  3048.  107. ftp://kermit.columbia.edu/kermit/c-kermit/ckutio.c
  3049.  108. ftp://kermit.columbia.edu/kermit/c-kermit/ckvtio.c
  3050.  109. http://www.columbia.edu/kermit/ckcplm.html#x2
  3051.  110. http://www.columbia.edu/kermit/ckcplm.html#xa1
  3052.  111. http://www.columbia.edu/kermit/ckuins.html
  3053.  112. ftp://kermit.columbia.edu/kermit/c-kermit/ckcnet.h
  3054.  113. ftp://kermit.columbia.edu/kermit/c-kermit/ckutio.c
  3055.  114. http://www.columbia.edu/kermit/ckcplm.html#contents
  3056.  115. http://www.columbia.edu/kermit/ckermit.html
  3057.  116. http://www.columbia.edu/kermit/index.html
  3058.  117. ftp://kermit.columbia.edu/kermit/c-kermit/ckutio.c
  3059.  118. ftp://kermit.columbia.edu/kermit/c-kermit/ckcnet.h
  3060.  119. ftp://kermit.columbia.edu/kermit/c-kermit/ckcnet.c
  3061.  120. ftp://kermit.columbia.edu/kermit/c-kermit/cklnet.c
  3062.  121. http://www.columbia.edu/kermit/ckcplm.html#contents
  3063.  122. http://www.columbia.edu/kermit/ckermit.html
  3064.  123. http://www.columbia.edu/kermit/index.html
  3065.  124. ftp://kermit.columbia.edu/kermit/c-kermit/ckctel.h
  3066.  125. ftp://kermit.columbia.edu/kermit/c-kermit/ckctel.c
  3067.  126. http://www.columbia.edu/kermit/ckcplm.html#contents
  3068.  127. http://www.columbia.edu/kermit/ckermit.html
  3069.  128. http://www.columbia.edu/kermit/index.html
  3070.  129. http://www.columbia.edu/kermit/ckcplm.html#contents
  3071.  130. http://www.columbia.edu/kermit/ckermit.html
  3072.  131. http://www.columbia.edu/kermit/index.html
  3073.  132. ftp://kermit.columbia.edu/kermit/c-kermit/ckuusx.c
  3074.  133. http://www.columbia.edu/kermit/ckcplm.html#contents
  3075.  134. http://www.columbia.edu/kermit/ckermit.html
  3076.  135. http://www.columbia.edu/kermit/index.html
  3077.  136. http://www.columbia.edu/kermit/ckcplm.html#contents
  3078.  137. http://www.columbia.edu/kermit/ckermit.html
  3079.  138. http://www.columbia.edu/kermit/index.html
  3080.  139. http://www.columbia.edu/kermit/ckcplm.html#top
  3081.  140. http://www.columbia.edu/kermit/ckcplm.html#contents
  3082.  141. http://www.columbia.edu/kermit/ckermit.html
  3083.  142. http://www.columbia.edu/kermit/index.html
  3084.  143. http://www.columbia.edu/kermit/index.html
  3085.  144. http://www.columbia.edu/
  3086.  145. mailto:kermit@columbia.edu
  3087.