home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / old / ckermit60 / ckvtio.c < prev    next >
C/C++ Source or Header  |  2020-01-01  |  100KB  |  3,169 lines

  1. #ifndef VMS
  2. # error -- CKVTIO.C is used only on the VMS(tm) or OpenVMS(tm) Operating System
  3. #endif /* VMS */
  4.  
  5. #ifdef __ALPHA
  6. # define CKVTIO_OS_ARCH_STRING " OpenVMS(tm) Alpha(tm)"
  7. #else
  8. # ifdef VAX
  9. #  define CKVTIO_OS_ARCH_STRING " OpenVMS(tm) VAX(tm)"
  10. # else
  11. #  ifdef __GNUC__
  12. #   define CKVTIO_OS_ARCH_STRING " OpenVMS(tm) VAX(tm) (GCC)"
  13. #  else
  14. #   error -- CKVTIO.C unknown architecture, neither VAX(tm) nor Alpha(tm)
  15. #  endif /* __GNUC__ */
  16. # endif /* VAX */
  17. #endif /* __ALPHA */
  18. /*
  19.   Module version number and date.
  20.   Also update the module number above accordingly.
  21. */
  22. char *ckxv = "Communications I/O 6.0.088, 6 Sep 96";
  23. /*
  24.   This is the default architecture and operating system herald string.
  25.   It is redetermined dynamically in sysinit() below.  
  26. */
  27. char *ckxsys = CKVTIO_OS_ARCH_STRING;
  28.  
  29. /*  C K V T I O  --  Terminal and Interrupt Functions for VAX/VMS  */
  30.  
  31. /* C-Kermit interrupt, terminal control & i/o functions for VMS systems */
  32.  
  33. /*
  34.   Author: Frank da Cruz <fdc@columbia.edu>
  35.   The Kermit Project, Columbia University, New York City.
  36.  
  37.   Copyright (C) 1985, 1994, Trustees of Columbia University in the City of New
  38.   York.  The C-Kermit software may not be, in whole or in part, licensed or
  39.   sold for profit as a software product itself, nor may it be included in or
  40.   distributed with commercial products or otherwise distributed by commercial
  41.   concerns to their clients or customers without written permission of the
  42.   Office of Kermit Development and Distribution, Columbia University.  This
  43.   copyright notice must not be removed, altered, or obscured.
  44. */
  45.  
  46. /* Edit History
  47.  *
  48.  * Originally adapted to VMS by:
  49.  * Stew Rubenstein, Harvard University Chemical Labs, 1985.
  50.  *
  51.  * Cast of characters:
  52.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  53.  * wb  William Bader     Lehigh University
  54.  * mab Mark Buda         Digital (DEC)
  55.  * fdc Frank da Cruz     Columbia U
  56.  * HG  Hunter Goatley    Western Kentucky University
  57.  * jh  James Harvey      Indiana / Purdue University
  58.  * ttj Tarjei T. Jensen  Norwegian Hydrographic Service
  59.  * tmk Terry Kennedy     Saint Peters College
  60.  * MM  Martin Minow      Digital
  61.  * mlo Mike O'Malley     Digital
  62.  * DS  Dan Schullman     Digital
  63.  * js  James Sturdevant
  64.  * LT  Lee Tibbert       Digital
  65.  * mpjz Martin PJ Zinzer Gesellschaft fuer Schwerionenforschung GSI Darmstadt
  66.  * cf  Carl Friedberg    Comet & Co., NYC
  67.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  68.  * 006  8-May-85 MM   Got rid of "typeahead buffer" code as it didn't
  69.  *              solve the problem of data overruns at 4800 Baud.
  70.  *              Added vms "read a char" routine that checks for
  71.  *              CTRL/C, CTRL/Z, etc.
  72.  * 007 16-May-85 fdc  Changed calling convention of ttopen(), make it
  73.  *                    set value of its argument "lcl", to tell whether
  74.  *                    C-Kermit is in local or remote mode.
  75.  * 008 11 Jun 85 MM   Fix definition of CTTNAM
  76.  * 009 18 Jun 85 fdc  Move def of CTTNAM to ckcdeb.h so it can be shared.
  77.  * 010 25 Jun 85 MM   Added sysinit() to open console.
  78.  * 011  5 Jul 85 DS   Treat hangup of closed line as success.
  79.  * 012 11 Jul 85 fdc  Add gtimer(), rtimer() for timing statistics.
  80.  * 013 14 Sep 87 fdc  Add parity strip to ttinl(), add syscleanup().
  81.  * 014 14 Feb 89 mab  Make break REALLY work.  Add IOSB's to all QIO's.
  82.  * 015 26 Feb 89 mab  Add dcl exit handler and minor cleanup
  83.  * 016 23-Mar-89 mab  Add IO$M_BREAKTHRU to IO$_WRITEVBLK.
  84.  *              Add zchkspd() function to check for valid speed.
  85.  * 017 04-Apr-89 mab  Fix some minor bugs to local/remote code
  86.  * 018 23-Apr-89 mab  Add some of Valerie Mates' parity changes.
  87.  * 019 25-Apr-89 mab  Change baud to 110 for V4.x break routine as
  88.  *               50 baud is not supported on most Muxes by VMS.
  89.  * 020 13-Jun-89 mab  Fix on exquota problem on qiow(readvblk)
  90.  * 021 08-Jul-89 mab  Add ^C/^Y abort server mode code.
  91.  * 022 11-May-90 mab  Add V5A code 
  92.  * 023 20-Jul-90 wb   Add support for old VAX C and VMS versions
  93.  * 024 22-Sep-90 wb   Fixes to cps/bps confusion
  94.  * 025 26-Sep-90 tmk  Fix the ztime() function
  95.  * 026 29-Sep-90 tmk  Edit 024 cause a server command to give some blither-
  96.  *              ings about unsupported line speeds.  Added a simple hack
  97.  *              to exit quietly if the passed speed is 0.  Adventurous
  98.  *              maintainers may want to look in ttpkt(), where ttsspd()
  99.  *              is being called with a value of -1/10.
  100.  * 027 11-Oct-90 fdc  Made ttol return number of chars successfully written.
  101.  *                    Made ztime() use ctime() in all cases.
  102.  *                    Another fix (from tmk) for bps/cps confusion.
  103.  *                    Wrapped source lines longer than 80 characters.
  104.  * 028 18-Oct-90 fdc  Added comments to concb() and vms_getchar() to show
  105.  *                    how to make Ctrl-C trap work.  Didn't actually do it,
  106.  *                    though, because Ctrl-Y apparently still can't be caught.
  107.  *                    Also, more minor reformatting.  Adjust time() declare.
  108.  *                    Added support for automatic parity sense in ttinl(),
  109.  *                    within #ifdef PARSENSE conditionals.  Built with PARSENSE
  110.  *                    defined, works ok.
  111.  * 029  5-Apr-91 fdc  Extensive reworking of many routines to allow for
  112.  *              network connections, addition of TGV MultiNet support.
  113.  * 030 31-Aug-91 tmk  Fix problem with INPUT statements not timing out due to
  114.  *              extraneous rtimer() inside gtimer().
  115.  * 032  6-Nov-91 fdc  Correct parity problem.
  116.  * 032  6-Nov-91 fdc  Cosmetic cleanup in sysinit().
  117.  * 033 14-Jan-91 fdc  Fix to get_qio_maxbuf_size to prevent crashes:
  118.  *                    remove "&" from "!test_qio(ttychn,max,&tmpbuf)",
  119.  *                    from John Schultz at 3M.
  120.  * 034  8-Feb-92 fdc  Don't change EIGHTBIT setting in ttvt, concb, or conbin.
  121.  *                    Set EIGHTBIT in ttpkt only if parity is not NONE.  From
  122.  *                    Alan Robiette, Oxford U, UK.
  123.  * 035 10-Jun-92 fdc  Added code from Ray Hunter of The Wollongong Group to
  124.  *                    support both WIN/TCP and TGV Multinet.  Network section
  125.  *                    of contti() redone to eliminate polling loop.  It's
  126.  *                    infinitely faster.
  127.  * 036 11-Jun-92 tmk  Fixed up edit 034 so 8-bit characters could be passed
  128.  *                    in connect mode.
  129.  * 037 19-Jun-92 fdc  Totally rewrote all the serial input and mode-setting 
  130.  *                    routines in this module to use nonblocking, fully
  131.  *                    buffered input and to share a common buffer.  All
  132.  *                    serial-line input is localized to a single routine,
  133.  *                    txbufr(), which, in turn is known only to ttinc().  The
  134.  *                    other input routines, ttxin() and ttinl(), simply call
  135.  *                    ttinc().  ttchk() and ttflui() are totally cognizant of
  136.  *                    the buffer.  ttinl() now recognizes packets with
  137.  *                    printable start characters and/or lacking terminators,
  138.  *                    so VMS C-Kermit can now engage in "Doomsday Kermit"
  139.  *                    protocol.  ttvt() and ttpkt() were merged into a single
  140.  *                    new (static) routine, ttbin(), which no longer puts the
  141.  *                    device into PASALL mode (which defeats flow control).
  142.  *                    Added ttsndlb() to send a Long BREAK.  Much fine-tuning,
  143.  *                    testing, and filling-in remains to be done, including
  144.  *                    (a) make ttopen() and ttclos() aware of LAT devices; (b)
  145.  *                    check remaining BYTLM quota before issuing a read, (c)
  146.  *                    integrate network and serial buffers, and much more.
  147.  *                    Anyway, this code seems to run faster than ever before,
  148.  *                    and for the first time I can actually use sliding
  149.  *                    windows AND long packets on my 8-year old MicroVAX-II.
  150.  * 038 28-Jun-92 tmk  Additional work on edit 37, general cleanup of old defs.
  151.  * 039  1-Jul-92 wb   Changes for VMS 4.4.
  152.  * 040  4-Jul-92 tmk  Add modem signal support (ttgmdm routine).
  153.  * 041  4-Jul-92 tmk  Add tgetent(), worker routine for el-cheapo curses.
  154.  * 042  4-Jul-92 jh   Enable typeahead in ttbin().
  155.  * 043 21-Aug-92 fdc  Make default flow control be KEEP instead of Xon/Xoff.
  156.  * 044  6-Sep-92 fdc  Put default flow back to Xon/Xoff, but allow KEEP to be
  157.  *                    used to restore device's original flow-control setting.
  158.  * 045 23-Sep-92 fdc  Add sleep(1) to tthang().  Seems to fix HANGUP command.
  159.  *                    Suggested by Lee Tibbert.  Change ttbin() to use global
  160.  *                    flow variable rather than its flow parameter for setting
  161.  *                    flow control, to ensure the desired type of flow control
  162.  *                    is used during DIAL operations.
  163.  * 046 26-Sep-92 fdc  Change sleep(1) in tthang() to sleep(3).  Annoying but
  164.  *                    necessary.  IO$M_HANGUP takes about 3 seconds, but the
  165.  *                    sys$qiow() function returns immediately instead of
  166.  *                    waiting for the action to complete.
  167.  * 047 08-Oct-92 HG   Add call to sys$alloc in ttopen() to prevent user with
  168.  *              SHARE from getting port in use.  Some add'l cleanup.
  169.  * 048 12-Oct-92 LT   Minor changes to support DEC TCP/IP (nee UCX).
  170.  * 049 25-Oct-92 fdc  Adapt (ck_)cancio() to DEC TCP/IP.
  171.  *                    Remove superfluous ttflui() call from ttpkt().
  172.  *                    Add code from Lee Tibbert to sysinit() to figure out OS
  173.  *                    and architecture name at runtime.
  174.  * 050 18-Nov-92 fdc  Read from comm device in 1024-byte chunks, rather than
  175.  *                    trusting the qio_maxbuf_size.  This should reduce BYTLM
  176.  *                    quota-exceeded errors.  Suggested by tmk as a temporary
  177.  *                    workaround.
  178.  * 051 10-May-93 fdc  Add support for SET TRANSFER CANCELLATION.
  179.  * 052 16-May-93 fdc  Change VMSTCPIP to TCPIPLIB to agree with new CKCNET.H.
  180.  * 053 16-May-93 fdc  ANSIfication for GNU CC, from James Sturdevant.
  181.  * 054 08-Jun-83 fdc  Add TT$M_LOCALECHO and TT$M_ESCAPE to the terminal modes
  182.  *                    we handle, to prevent "getty babble" with modems, VAX
  183.  *                    PSI, etc.
  184.  * 055 16-Jun-93 fdc  Edit 054 only affected ttbin().  This edit does the same
  185.  *                    for conbin() and concb().  Fixes double echoing in
  186.  *                    command mode when coming in via VAX PSI.
  187.  * 056  8-Aug-93 fdc  Add types to all function declarations.
  188.  * 057 17-Aug-93 fdc  Add GET_SDC macro as in CKVIOC.C, accounting for GCC.
  189.  *                    From Tarjei T. Jensen <tarjeij@extern.uio.no>.
  190.  * 058 27-Sep-93 HG   Fix for real the SHARE issue when allocating terminal
  191.  *              by dropping SHARE before trying to assign the channel.
  192.  * 059  7-Oct-93 mlo  Added support for CMU-OpenVMS/IP ("CMU/Tek").  Requires
  193.  *                    CMU-OpenVMS/IP sockets library, also by mlo.
  194.  * 060  9-Oct-93 HG   Fix improper call to vms_assign_channel in edit 058,
  195.  *                    noticed by Fritz@GEMS.VCU.EDU.
  196.  * 061  9-Oct-93 fdc  For some reason, conbin() was turning off flow control.
  197.  *                    This caused massive data loss during CONNECT mode when
  198.  *                    running C-Kermit from a low-speed connection through
  199.  *                    a DECserver.  Now conbin() leaves the console flow
  200.  *                    control setting alone.
  201.  * 062 10-Oct-93 ttj  Change parameters to time() and ctime() from long to
  202.  *                    time_t (pointers).  Made prototype for vms_assign_channel
  203.  *                    and caught an erroneous function call.
  204.  * 063  9-Nov-93 fdc  In sysinit(), don't run sys$getdviw() on the "console"
  205.  *                    if the console is not a terminal (from tcwkw@sf.msc.edu).
  206.  *                    And (blame this one on me) _never_ set the backgrd flag.
  207.  * 064 25-Nov-93 fdc  Fixed coninc(n) to return -1 on timeout.
  208.  * 065  9-Dec-93 fdc  Fix transfer cancellation to account for parity, and
  209.  *                    allow it only in remote mode.
  210.  * 066 13-Dec-93 fdc  Make debug logging in ttol() show why packet writes fail.
  211.  * 067 15-Dec-93 fdc  New, MAXBUF-proof ttol() recovers from failures by
  212.  *                    writing the packet in chunks, whose size is computed
  213.  *                    dynamically.  This seems to cause no noticable slowdown
  214.  *                    in the transfer rate.
  215.  * 068 31-Dec-93 fdc  Fix bug in parity-detection code in ttinl().
  216.  * 069 14-Dec-93 fdc  Add ttgwsiz() routine, code from John Berryman.
  217.  * 070 14-MAR-94 mlo  CMU_TCPIP modifications: contti - return error (-1)
  218.  *                    if number of characters read is zero; (ck_)cancio - pass
  219.  *                    correct i/o channel for ttyfd to sys$cancel.
  220.  * 071 15-MAR-94 mlo  ttol() - add #ifdef DEBUG for compiles with NODEBUG
  221.  * 072 27-Mar-94 fdc  Straighten out some ttsspd()/ttgspd() confusion.
  222.  * 073 11-AUG-94 fdc  Make conoll() return a proper return code.
  223.  * 074 12-AUG-94 fdc  Make syscleanup() handle conres() error.  Make 
  224.  * 075 20-AUG-94 js   Make congm() get terminal type, etc, to remove annoying
  225.  *                    "Sorry, terminal type not supported" messages when
  226.  *                    running from a .COM file, etc.
  227.  * 076 02-Sep-94 fdc  Call con_cancel() in syscleanup() to cancel any pending
  228.  *                    console i/o, hopefully eliminating zombies after
  229.  *                    after disconnection, etc.
  230.  * 077 22-Sep-94 mlo  Don't call sys$cancel() in (ck_k)cancio() on CMU/Tek
  231.  *                    network connections - it breaks the connection.
  232.  * 078 24-Feb-95 mpjz Fix for DECC on VAX.
  233.  * 079 08-Feb-96 fdc  Add symbols for higher serial speeds.
  234.  * 080 30-May-96 fdc  Fix netopen() to work with Rlogin.
  235.  * 081 25-Aug-96 mpjz More DECC/VAXC fixups.
  236.  * 082 05-Sep-96 fdc  Remove #module, change (ck_)cancio() declaration.
  237.  * 083 06-Sep-96 fdc  Fix loss of parity setting on network connections.
  238.  * 084 06-Sep-96 cf   Add missing speeds to ttspeeds[] (Carl Freidberg)
  239.  * 085 06-Sep-96 fdc  Add conspd() routine (for use by RLOGIN).
  240.  * 086 06-Sep-96 fdc  Try to fix parity confusion again.
  241.  * 087 06-Sep-96 fdc  And again: culprit is DECC sign-extension: see ttinc, etc
  242.  * 088 06-Sep-96 fdc  Unravel the network-file-descriptor reusability tangle
  243.  */
  244.  
  245. /*
  246.  Variables available to outside world:
  247.  
  248.    dftty  -- Pointer to default tty name string, like "/dev/tty".
  249.    dfloc  -- 0 if dftty is console(remote), 1 if external line(local).
  250.    dfprty -- Default parity
  251.    dfflow -- Default flow control
  252.    ckxech -- Flag for who echoes console typein:
  253.      1 - The program (system echo is turned off)
  254.      0 - The system (or front end, or terminal).
  255.    functions that want to do their own echoing should check this flag
  256.    before doing so.
  257.  
  258.    backgrd
  259.      Flag indicating program not executing interactively.
  260.      Used to ignore INT and QUIT signals, suppress messages, etc.
  261.    vms_status
  262.      Status returned by most recent VMS system service,
  263.      can be used for error reporting.
  264.  
  265.  Functions for assigned communication line (either external or console tty):
  266.  
  267.    ttopen(ttname,local,mdmtyp) -- Open the named tty for exclusive access.
  268.    ttclos()                -- Close & reset the tty, releasing any access lock.
  269.    ttpkt(speed,flow)       -- Put the tty in packet mode and set the speed.
  270.    ttvt(speed,flow)        -- Put the tty in virtual terminal mode.
  271.                 or in DIALING or CONNECTED modem control state.
  272.    ttinl(dest,max,timo)    -- Timed read line from the tty.
  273.    ttinc(timo)             -- Timed read character from tty.
  274.    ttchk()                 -- See how many characters in tty input buffer.
  275.    ttxin(n,buf)            -- Read n characters from tty (untimed).
  276.    ttol(string,length)     -- Write a string to the tty.
  277.    ttoc(c)                 -- Write a character to the tty.
  278.    ttflui()                -- Flush tty input buffer.
  279.    tt_cancel()           -- Cancel any asynch I/O to tty
  280. */
  281.  
  282. /*
  283. Functions for console terminal:
  284.    congm()   -- Get console terminal modes.
  285.    concb(esc) -- Put the console in single-character wakeup mode with no echo.
  286.    conbin(esc) -- Put the console in binary (raw) mode.
  287.    conres()  -- Restore the console to mode obtained by congm().
  288.    conoc(c)  -- Unbuffered output, one character to console.
  289.    conol(s)  -- Unbuffered output, null-terminated string to the console.
  290.    conola(s) -- Unbuffered output, array of lines to the console, CRLFs added.
  291.    conxo(n,s) -- Unbuffered output, n characters to the console.
  292.    conchk()  -- Check if characters available at console (bsd 4.2).
  293.         Check if escape char (^\) typed at console (System III/V).
  294.    coninc(timo)  -- Timed get a character from the console.
  295.    conint()  -- Enable terminal interrupts on the console if not background.
  296.    connoi()  -- Disable terminal interrupts on the console if not background.
  297.    contti()  -- Get a character from either console or tty, whichever is first.
  298.  
  299. Time functions
  300.  
  301.    msleep(m) -- Millisecond sleep
  302.    ztime(&s) -- Return pointer to date/time string
  303.    rtimer()  -- Reset elapsed time counter
  304.    gtimer()  -- Get elapsed time
  305. */
  306.  
  307. /* Includes */
  308. #include "ckcdeb.h"            /* Formats for debug() */
  309. #include "ckcasc.h"
  310. #include "ckcker.h"
  311.  
  312. #include "ckvvms.h"
  313.  
  314. #include <stdio.h>            /* Unix Standard i/o */
  315. #include <signal.h>            /* Interrupts */
  316. #include <setjmp.h>            /* Longjumps */
  317. #include <iodef.h>
  318. #include <ttdef.h>
  319. #include <tt2def.h>
  320. #include <ssdef.h>
  321. #include <descrip.h>
  322. #include <dvidef.h>
  323. #include <dcdef.h>
  324. #include <devdef.h>
  325. #include <time.h>
  326. #include <syidef.h>
  327. #include <prvdef.h>
  328.  
  329. /* lt 1992-10-08 Begin
  330.  */
  331. #ifndef __DECC                /* (was __ALPHA) */
  332. # ifndef __GNUC__
  333. #  define void int
  334. # endif /* __GNUC__ */
  335. #endif /* __DECC */
  336. /* lt 1992-10-08 End
  337.  */
  338.  
  339. #if defined(VMS_V40) || defined(VMS_V42) || defined(VMS_V44) /* No starlet */
  340. #define IO$_TTY_PORT 41
  341. #else
  342. #include <starlet.h>
  343. #endif /* (Old VMS) */
  344.  
  345. /* Macros */
  346.  
  347. #define xx_inc(timo) (--ttxbn>=0?(unsigned)(ttxbuf[ttxbp++]&0xff):txbufr(timo))
  348.  
  349. /* Declarations */
  350.  
  351. #ifndef __ALPHA
  352. #ifndef MULTINET
  353.     time_t time();
  354. #endif
  355. #endif
  356.     char *ctime();            /* Convert to asctime() string */
  357.  
  358.     void dcl_exit_h();            /* Exit handler */
  359.     unsigned short vms_assign_channel(struct dsc$descriptor_s *ttname);
  360.     VOID tt_cancel();
  361. /*
  362.   This is the device name for the console.
  363.   When we use SYS$INPUT, it prevents CONNECT from working in DCL
  364.   procedures that do not "$ DEFINE SYS$INPUT SYS$COMMAND".
  365.   When we use SYS$COMMAND, it allows CONNECT to work in DCL procedures,
  366.   but it forces the command parser to read from the terminal, and therefore
  367.   prevents inclusion of Kermit commands as "image data" in DCL procedures.
  368. */
  369. #define CONDEVICE    "SYS$INPUT"
  370. #define CONDEV_COLON "SYS$INPUT:"
  371.  
  372. /* dftty is the device name of the default device for file transfer */
  373. /* dfloc is 1 if dftty is the user's console terminal, 0 if an external line */
  374.  
  375.     char *dftty = CTTNAM;
  376.     int dfloc = 0;            /* Default location is local */
  377.     int dfprty = 0;            /* Parity (0 = none) */
  378.     int ttprty = 0;            /* Parity in use */
  379.     int ttpflg = 0;            /* Parity not sensed yet. */
  380.     int backgrd = 0;            /* Running in "background" (no tty) */
  381.     static int ttpmsk = 0xff;        /* Communication device parity mask */
  382.     int ttmdm = 0;                      /* Modem in use. */
  383.     int dfflow = FLO_XONX;        /* Default flow control is Xon/Xoff */
  384.     int batch = 0;            /* Assume interactive */
  385.     int ttcarr = CAR_AUT;        /* Carrier Handling Mode */
  386.     int tvtflg = 0;            /* Flag that ttvt has been called */
  387.     long ttspeed = -1;            /* For saving speed */
  388.     long conspd = -1;            /* Console terminal speed */
  389.     int ttflow = -9;            /* For saving flow */
  390.  
  391. int ckxech = 0; /* 0 if system normally echoes console characters, else 1 */
  392.  
  393. unsigned int vms_status;        /* Used for system service return status */
  394.  
  395. /* Structures used within this module */
  396.  
  397. #ifndef TT$C_BAUD_38400
  398. #define TT$C_BAUD_38400    17
  399. #endif /* TT$C_BAUD_38400 */
  400.  
  401. #ifndef TT$C_BAUD_57600
  402. #define TT$C_BAUD_57600 18
  403. #endif /* TT$C_BAUD_57600 */
  404.  
  405. #ifndef TT$C_BAUD_76800
  406. #define TT$C_BAUD_76800 19
  407. #endif /* TT$C_BAUD_76800 */
  408.  
  409. #ifndef TT$C_BAUD_115200
  410. #define TT$C_BAUD_115200 20
  411. #endif /* TT$C_BAUD_115200 */
  412.  
  413. static struct {
  414.     unsigned char dec;
  415.     unsigned short int line;
  416.     } ttspeeds[] = {
  417.     {TT$C_BAUD_50,       5},
  418.     {TT$C_BAUD_75,       7},
  419.     {TT$C_BAUD_110,     11},
  420.     {TT$C_BAUD_134,     13},
  421.         {TT$C_BAUD_150,     15},
  422.     {TT$C_BAUD_300,     30},
  423.     {TT$C_BAUD_600,     60},
  424.     {TT$C_BAUD_1200,   120},
  425.     {TT$C_BAUD_1800,   180},
  426.     {TT$C_BAUD_2000,   200},
  427.     {TT$C_BAUD_2400,   240},
  428.     {TT$C_BAUD_3600,   360},
  429.     {TT$C_BAUD_4800,   480},
  430.     {TT$C_BAUD_7200,   720},
  431.     {TT$C_BAUD_9600,   960},
  432.     {TT$C_BAUD_19200, 1920},
  433.     {TT$C_BAUD_38400, 3840},
  434.     {TT$C_BAUD_57600, 5760},
  435.     {TT$C_BAUD_76800, 7680},
  436.     {TT$C_BAUD_115200,11520},
  437.     {0,                   0} };
  438.  
  439. /* Declarations of variables global within this module */
  440.  
  441. /* was long... */
  442. #define TIME_T time_t
  443. #ifdef __ALPHA
  444. #ifdef WINTCP
  445. #undef TIME_T
  446. #define TIME_T long
  447. #endif /* WINTCP */
  448. #endif /* __ALPHA */
  449.  
  450. static TIME_T tcount = 0;        /* For timing statistics */
  451.  
  452. static char brkarray[] = {        /* For simulating BREAK */
  453.  
  454.  '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
  455.  '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
  456.  '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
  457.  '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0'
  458. };
  459.  
  460. int ttyfd = -1;                /* TTY file descriptor */
  461.  
  462. #ifdef COMMENT /* old */
  463. static int conif = 0,            /* Console interrupts on/off flag */
  464.     conclass = 0,            /* Console device type */
  465.     cgmf = 0,                /* Flag that console modes saved */
  466.     xlocal = 0,                         /* Flag for tty local or remote */
  467.     ttychn = 0,                /* TTY i/o channe; */
  468.     conchn = 0,                /* Console i/o channel */
  469.     con_queued = 0,            /* console i/o queued in contti() */
  470.     tt_queued = 0,            /* tty i/o queued in contti() */
  471.     conch,                /* console input character buffer  */
  472.     curcarr = 0,            /* Carrier mode: require/ignore */
  473.     ttch;                /* tty input character buffer */
  474. #else /* new */
  475. static unsigned short
  476.     ttychn = 0,                /* TTY i/o channe; */
  477.     conchn = 0,                /* Console i/o channel */
  478.     con_queued = 0,            /* console i/o queued in contti() */
  479.     tt_queued = 0;            /* tty i/o queued in contti() */
  480.  
  481. static int conif = 0,            /* Console interrupts on/off flag */
  482.     conclass = 0,            /* Console device type */
  483.     cgmf = 0,                /* Flag that console modes saved */
  484.     xlocal = 0,                         /* Flag for tty local or remote */
  485.     conch,                /* console input character buffer  */
  486.     curcarr = 0,            /* Carrier mode: require/ignore */
  487.     ttch;                /* tty input character buffer */
  488. #endif /* COMMENT */
  489.  
  490. static unsigned char escchr;        /* Escape or attn character */
  491. static char ttnmsv[80];              /* copy of open path for tthang */
  492. static char lclnam[80];            /* Local device name */
  493.  
  494. static char tt_fulldevnam[65];
  495. static struct dsc$descriptor_s tt_fulldevnam_d;    /* Descriptor for line name */
  496.  
  497. static long int qio_maxbuf_size;    /* Maximum size of QIO to succeed */
  498. static long dclexh_status;            /* Exit status for DCL exit handler */
  499. static struct iosb_struct coniosb, ttiosb, wrk_iosb;
  500. static struct tt_mode
  501.     ttold, ttraw, tttvt,        /* for communication line */
  502.     ccold, ccraw, cccbrk,        /* and for console */
  503.     cctmp;
  504.  
  505. /* Network support */
  506.  
  507. #include "ckcnet.h"            /* Network type symbols */
  508. extern int ttnet;            /* Network type */
  509. static int network = 0;            /* 1 if network connection */
  510. #ifdef TCPSOCKET
  511. extern int ttnproto;
  512. #endif /* TCPSOCKET */
  513. extern int xfrcan, xfrchr, xfrnum;    /* Transfer cancellation */
  514.  
  515. /*
  516.   Select proper library function for getting socket device channel.
  517. */
  518. #ifdef TCPIPLIB
  519. #if defined (__DECC)
  520. # define GET_SDC (short)decc$get_sdc
  521. #elif (defined (VAXC) || defined (__VAXC) || defined (__GNUC__))
  522. # define GET_SDC vaxc$get_sdc
  523. #else
  524. # error unknown compiler, not DECC and not VAXC
  525. #endif /* __DECC */
  526. #endif /* TCPIPLIB */
  527.  
  528. /* Needed for parity fixes in edit 036 */
  529. extern int parity;            /* current parity setting */
  530.  
  531. /*
  532.   New buffered input scheme.
  533. */
  534. #define TTXBUF
  535.  
  536. #ifdef TTXBUF
  537. #define TTXBUFL RBSIZ            /* Internal buffer size */
  538.  
  539. CHAR     ttxbuf[TTXBUFL+1];        /* The buffer */
  540. int     ttxbp = 0, ttxbn = 0;        /* Buffer pointer and count */
  541.  
  542. int get_qio_maxbuf_size(unsigned long int ttychn); 
  543. int test_qio(unsigned long int ttychn, long int max, unsigned char *dest);
  544. int ttispd(); 
  545.  
  546. /*
  547.   T X B U F R
  548.  
  549.   Read bytes from communication device into internal buffer ttxbuf[].
  550.   To be called only when input buffer is empty, i.e. when ttxbn == 0.
  551.  
  552.   Other comm-device reading routines, like ttinc, ttinl, ttxin, should check
  553.   the internal buffer first, and call this routine for a refill if necessary.
  554.  
  555.   When data is read successfully, the first character is returned and
  556.   the global buffer count, ttxbn, is set to the number of characters remaining
  557.   in ttxbuf after it, and the global buffer offset, ttxbp, is set to 1.
  558.  
  559.   When data is not read successfully, -1 is returned indicating a timeout,
  560.   or -2 indicating disconnection.
  561. */
  562. int
  563. txbufr(timo) int timo; {        /* TT Buffer Read */
  564.     int count;
  565.     int func;                /* Read function code */
  566.     int mask;                /* Event mask */
  567.     int vms_status;            /* Read QIO return code */
  568.     static int trmmsk[2] = {0,0};    /* Terminal read break mask */
  569.     static int trmlong[8] = {0,0,0,0,0,0,0,0}; /* Break on nothing */
  570.  
  571.     debug(F101,"txbufr entry, ttxbn","",ttxbn);
  572.     if (ttxbn > 0) {            /* Should not be called */
  573.     debug(F101,"txbufr called with ttxbn","",ttxbn); /* if ttxbn > 0! */
  574.     ttxbn--;
  575.     return(ttxbuf[ttxbp++] & 0xff);
  576.     }
  577.     ttxbp = ttxbn = 0;            /* Reset buffer pointer and count */
  578.     ttxbuf[0] = NUL;
  579.  
  580.     if (timo < 0)            /* Be safe */
  581.       timo = 0;
  582.     debug(F101,"txbufr timo","",timo);
  583.  
  584.     func = IO$_READVBLK | IO$M_NOFILTR;    /* Read virtual block, no filtering */
  585.     trmmsk[0] = sizeof(trmlong);    /* No terminators */
  586.     trmmsk[1] = (int)&trmlong;        /* Keep all characters */
  587.  
  588. /*
  589.   We try to scoop up as many as we can in a nonblocking read (timed, but with
  590.   timeout value of 0).  This is supposed to return immediately with up to
  591.   "count" characters placed in our buffer.
  592. */
  593.     count = TTXBUFL;            /* Maximum characters to read */
  594.  
  595. #ifdef COMMENT
  596. /*
  597.   This causes problems because we are not adjusting according to the CURRENT
  598.   BYTLM quota, but rather to the one that was obtained when Kermit started.
  599.   Since the quota is dynamic, it might have been reduced since then.
  600. */
  601.     if (count > qio_maxbuf_size)
  602.     count = qio_maxbuf_size;
  603. #else
  604. /*
  605.   So for now we use 1024, which tends to be smaller than the value obtained
  606.   above.  Later, this should be changed to find out the remaining BYTLM quota
  607.   and use that instead.  This size can be overridden at compile time by
  608.   defining the symbol...
  609. */
  610. #ifndef CKV_IO_SIZE
  611. #define CKV_IO_SIZE 1024
  612. #endif /* CKV_IO_SIZE */
  613.  
  614.     if (count > CKV_IO_SIZE)
  615.     count = CKV_IO_SIZE;
  616. #endif /* COMMENT */
  617.  
  618.     debug(F101,"txbufr 1 read","",count);
  619.     vms_status = sys$qiow(QIOW_EFN, ttychn, func|IO$M_TIMED, &wrk_iosb, 0, 0,
  620.               ttxbuf, count, 0, &trmmsk, 0, 0);
  621. /*
  622.  * Did something _really_ bad happen?
  623.  */
  624.     if (vms_status != SS$_NORMAL) {
  625.     debug(F101,"txbufr 1 serious error, status","",vms_status);
  626.     return(-2);
  627.     }
  628.     debug(F101,"txbufr 1 size","",wrk_iosb.size);
  629.     debug(F101,"txbufr 1 iosb","",wrk_iosb.status);
  630.     debug(F110,"txbufr 1 ttxbuf",ttxbuf,0);
  631. /*
  632.  * How about a hangup?
  633.  */
  634.     if (wrk_iosb.status == SS$_HANGUP) { /* Check for disconnection */
  635.     debug(F100,"txbufr 1 hangup","",0);
  636.     return(-2);
  637.     }
  638. /*
  639.  * Did anything useful happen?
  640.  */
  641.     if (wrk_iosb.size > 0) {
  642.     ttxbn = wrk_iosb.size;        /* Set buffer count. */
  643.     ttxbn--;            /* Less one for the one we return */
  644.     return(ttxbuf[ttxbp++] & 0xff);    /* Return it, bump offset */
  645.     }
  646. /*
  647.  * An unexpected status?
  648.  */
  649.     if (wrk_iosb.status != SS$_TIMEOUT) {
  650.     debug(F101, "txbufr 1 unexpected iosb status", "", wrk_iosb.status);
  651.     return(-2);            /* Call it a hangup */
  652.     }
  653. /*
  654.  * If we didn't get any characters, then try a blocking, possibly timed,
  655.  * read for a single character.  Since this routine will be called again very
  656.  * soon, the first read with a zero timeout will have the rest of the user
  657.  * data in it.  Thus, this isn't as inefficient as it first appears.
  658.  */
  659.     if (timo > 0)
  660.       func |= IO$M_TIMED;
  661.     debug(F101,"txbufr 2 read","",count);
  662.     vms_status = sys$qiow(QIOW_EFN, ttychn, func, &wrk_iosb, 0, 0,
  663.               ttxbuf, 1, timo, &trmmsk, 0, 0);
  664.     debug(F101,"txbufr 2 vms_status", "",vms_status);
  665.     debug(F101,"txbufr 2 iosb status","",wrk_iosb.status);
  666. /*
  667.  * Did something _really_ bad happen?
  668.  */
  669.     if (vms_status != SS$_NORMAL) {
  670.     debug(F101,"txbufr fails","",-2);
  671.     return(-2);
  672.     }
  673.     debug(F101,"txbufr 2 size","",wrk_iosb.size);
  674.     debug(F101,"txbufr 2 iosb","",wrk_iosb.status);
  675.     debug(F110,"txbufr 2 ttxbuf",ttxbuf,0);
  676.  
  677. /*
  678.  * How about a hangup?
  679.  */
  680.     if (wrk_iosb.status == SS$_HANGUP) { /* Check for disconnection */
  681.     debug(F100,"txbufr 2 hangup","",0);
  682.     return(-2);
  683.     }
  684.  
  685. /*
  686.  * Did anything useful happen?
  687.  */
  688.     if(wrk_iosb.size > 0) {
  689.     ttxbn = wrk_iosb.size;        /* Set buffer count. */
  690.     ttxbn--;            /* Less one for the one we return */
  691.     return(ttxbuf[ttxbp++] & 0xff);    /* Return it, bump offset */
  692.     }
  693.  
  694. /*
  695.  * An unexpected status?
  696.  */
  697.     if (wrk_iosb.status != SS$_TIMEOUT) {
  698.     debug(F101, "txbufr 2 unexpected iosb status", "", wrk_iosb.status);
  699.     return(-2);            /* Call it a hangup */
  700.     }
  701.  
  702. /*
  703.  * Otherwise it's a timeout
  704.  */
  705.     debug(F100, "txbufr 2 returning timeout", "", 0);
  706.     return(-1);
  707. }
  708.  
  709. /*  T T I N C  --  Read a character from the communication device  */
  710. /*
  711.   ttinc() maintains an internal buffer to minimize system calls.
  712.   Returns the next character, or -1 if there is a timeout, or -2
  713.   on communications disconnect.  Calls txbufr() to refill its buffer
  714.   when necessary.
  715. */
  716. int
  717. ttinc(timo) int timo; {
  718.     int x; unsigned char c;
  719.  
  720. #ifdef NETCONN
  721.     if (network) {
  722. #ifdef COMMENT
  723.     int x;
  724.     x = netinc(timo);
  725.     if ((ttnproto == NP_TELNET) && (x > -1))
  726.       return((unsigned)(x & 0xff));
  727.     else
  728.       return(x < 0 ? x : (unsigned)(x & ttpmsk));
  729. #else
  730.     return(netinc(timo));
  731. #endif /* COMMENT */
  732.     }
  733. #endif /* NETCONN */
  734.  
  735.     debug(F101,"ttinc ttxbn","",ttxbn);
  736.     if (--ttxbn >= 0) {            /* Something in internal buffer? */
  737.     c = ttxbuf[ttxbp++];        /* Yes, return next character. */
  738.     debug(F101,"ttinc returns c","",c);
  739.     return((unsigned)(c & 0xff));
  740.     } else if ((x = txbufr(timo)) < 0) { /* No, fill buffer */
  741.     debug(F101,"ttinc timed out","",x); /* Pass along failure. */
  742.     return(x);
  743.     } else {                /* Success. */
  744.     debug(F101,"ttinc returns x","",x);
  745.     return((unsigned)(x & 0xff));        /* Return the character */
  746.     }
  747. }
  748.  
  749. /*  T T X I N  --  Get n bytes from tty input buffer  */
  750. /*
  751.   Call with n = number of bytes to get, buf = where to put them.
  752.  
  753.   This routine assumes that the given number of bytes is available
  754.   and will not return until they are gotten.  You should only call this
  755.   routine after calling ttchk to find out how many bytes are waiting to
  756.   to be read.
  757.  
  758.   Returns:
  759.   -1 on error, number of chars gotten on success.
  760. */
  761. int
  762. ttxin(n,buf) int n; CHAR *buf; {
  763.     int i, x;
  764.  
  765.     debug(F101,"ttxin","",n);
  766.  
  767. #ifdef NETCONN
  768.     if (network) {
  769.     for (i = 0; i < n; i++) {
  770.         if ((x = ttinc(0)) < 0) return(-1);
  771.         buf[i] = (char) x;
  772.     }
  773.     } else {
  774. #endif /* NETCONN */
  775. /* xx_inc() is a macro */
  776.     for (i = 0; i < n; i++) {
  777.         if ((x = xx_inc(0)) < 0) return(-1);
  778.         buf[i] = (char) x;
  779.     }
  780. #ifdef NETCONN
  781.     }
  782. #endif /* NETCONN */
  783.     buf[i] = NUL;
  784.     return(i);
  785. }
  786.  
  787. /*  T T F L U I  --  Flush communication device input buffer  */
  788.  
  789. int
  790. ttflui() {
  791.     int n;
  792.     debug(F100,"ttflui","",0);
  793. #ifdef NETCONN
  794.     if (network)
  795.       return(netflui());
  796. #endif /* NETCONN */
  797.  
  798.     ttxbn = ttxbp = 0;            /* Flush internal buffer *FIRST* */
  799.     if ((n = ttchk()) > 0) {
  800.     debug(F101,"ttflui count","",n);
  801.     while ((n--) && xx_inc(2) > -1) ; /* Don't worry, it's buffered. */
  802.     }
  803.     return(0);
  804. }
  805.  
  806. /*  T T C H K  --  Check how many bytes are waiting to be read */
  807. /*
  808.   Returns number of bytes waiting, or -1 if connection has been dropped.
  809.   The number of bytes waiting includes those in our internal buffer plus
  810.   those in VMS's internal input buffer.
  811. */
  812. int                    /* Check how many bytes are ready */
  813. ttchk() {                /* for reading from network */
  814.     static struct {
  815.     unsigned short count;
  816.     unsigned char first;
  817.     unsigned char reserved1;
  818.     long reserved2; } ttchk_struct;
  819.  
  820.     if (network && ttyfd < 0)
  821.       return(0);
  822.     if (!network && !ttychn) {
  823.     debug(F101,"ttchk called with no ttychn","",0);
  824.     return(0);
  825.     }
  826. #ifdef NETCONN
  827.     if (network)            /* If network connection active... */
  828.       return(nettchk());        /* Check real network. */
  829. #endif /* NETCONN */
  830.  
  831.     CHECK_ERR("ttchk: sys$qiow",
  832.     sys$qiow(QIOW_EFN, ttychn, IO$_SENSEMODE|IO$M_TYPEAHDCNT, &wrk_iosb,
  833.          0, 0, &ttchk_struct, sizeof(ttchk_struct), 0, 0, 0, 0));
  834. #ifdef DEBUG
  835.     debug(F101,"ttchk count","",(int)ttchk_struct.count);
  836.     if (ttchk_struct.count)
  837.       debug(F101,"ttchk first","",(int)ttchk_struct.first);
  838. #endif /* DEBUG */
  839.     return(vms_status & 1 ? ttchk_struct.count + ttxbn : ttxbn);
  840. }
  841.  
  842. #ifdef CTRLC
  843. #undef CTRLC
  844. #endif /* CTRLC */
  845. #define CTRLC '\03'
  846.  
  847. /*  T T I N L  --  Read a record (up to break character) from comm line.  */
  848. /*
  849.   Reads up to "max" characters from the communication line, terminating on:
  850.  
  851.     (a) the packet length field if the "turn" argument is zero, or
  852.     (b) on the packet-end character (eol) if the "turn" argument is nonzero
  853.     (c) two Ctrl-C's in a row
  854.  
  855.   and returns the number of characters read upon success, or if "max" was
  856.   exceeded or the timeout interval expired before (a) or (b), returns -1.
  857.  
  858.   The characters that were input are copied into "dest" with their parity bits
  859.   stripped if parity was selected.  Returns the number of characters read.
  860.   Characters after the eol are available upon the next call to this function.
  861.  
  862.   Since this function has grown to have its fingers so deeply into the
  863.   protocol, it is slated for removal: rpack() will take care of everything.
  864. */
  865.  
  866. int
  867. #ifdef CK_ANSIC
  868. ttinl(CHAR *dest, int max, int timo, CHAR eol, CHAR start, int turn)
  869. #else
  870. ttinl(dest,max,timo,eol,start,turn) int max,timo,turn; CHAR *dest,eol,start;
  871. #endif /* CK_ANSIC */
  872. /* ttinl */ {
  873.     int x, y, c, i, j;
  874.     int ccn = 0;        /* Control C counter */
  875.     int flag;
  876.     int cc;
  877.     unsigned char *cp;
  878.     int pktlen = -1;
  879.     int lplen = 0;
  880.     int havelen = 0;
  881.  
  882.     debug(F101,"ttinl start","",start);
  883.     debug(F101,"ttinl turn","",turn);
  884.     i = j = flag = 0;
  885. #ifdef COMMENT
  886.     ttpmsk = (ttprty) ? 0177 : 0377;    /* Set parity stripping mask. */
  887. #endif /* COMMENT */
  888.     debug(F101,"ttinl loop entry, network","",network);
  889.     while (i < max) {
  890.     cc = network ? netinc(timo) : xx_inc(timo); /* Read a byte */
  891.     if (cc < 0) {
  892.         debug(F101,"ttinl cc","",cc);
  893.         if (cc == -1 || cc == -2) {
  894.         return(cc);
  895.         } else {            /* I hate C ... */
  896.         debug(F100,
  897.               "ttinl: SIGN EXTENSION BOTCH - FIX SOURCE CODE","",0
  898.               );
  899.         /* This doesn't really help because 255 becomes -1, etc. */
  900.         cc &= 0xff; 
  901.         }
  902.     }
  903.  
  904.     /* Check for cancellation */
  905.     if (!xlocal && xfrcan && ((cc & ttpmsk) == xfrchr)) {
  906.         if (++ccn >= xfrnum) {    /* If xfrnum in a row, bail out. */
  907.         fprintf(stderr,"^C...\r\n"); /* Echo Ctrl-C */
  908.         return(-2);
  909.         }
  910.     } else ccn = 0;            /* No cancel, so reset counter, */
  911.  
  912.     if ((flag == 0) && ((cc & 0x7f) == start)) {
  913.         debug(F100,"ttinl got start","",0);
  914.         flag = 1;            /* Got packet start. */
  915.     }
  916.     if (flag) {            /* If we're in a packet... */
  917.         dest[i++] = cc & ttpmsk;
  918.         if ((cc & 0x7f) == eol) { /* Stop at eol. */
  919.         debug(F101,"ttinl got eol, i","",i);
  920.         break;
  921.         }
  922.     }
  923. /*
  924.   If we have not been instructed to wait for a turnaround character, we
  925.   can go by the packet length field.  If turn != 0, we must wait for the
  926.   end of line (eol) character before returning.
  927. */
  928. #ifndef xunchar
  929. #define xunchar(ch) (((ch) - 32 ) & 0xFF )    /* Character to number */
  930. #endif /* xunchar */
  931.  
  932.     if (i == 2) {
  933.         pktlen = xunchar(dest[1] & 0x7f);
  934.         havelen = (pktlen > 1);
  935.         debug(F101,"ttinl length","",pktlen);
  936.     } else if (i == 5 && pktlen == 0) {
  937.         lplen = xunchar(dest[4] & 0x7f);
  938.     } else if (i == 6 && pktlen == 0) {
  939.         pktlen = lplen * 95 + xunchar(dest[5] & 0x7f) + 5;
  940.         havelen = 1;
  941.         debug(F101,"ttinl length","",pktlen);
  942.     }
  943.     if (havelen && !turn && (i > pktlen+1)) { /* Use length field */
  944.         debug(F101,"ttinl break on length","",i);
  945.         break;
  946.     }
  947.     }
  948.     dest[i] = '\0';            /* Terminate the string */
  949.     debug(F101,"ttinl loop done, i","",i);
  950.     debug(F101,"ttinl max","",max);
  951.     debug(F101,"ttinl dest[i-1]","",dest[i-1]);
  952.     debug(F101,"ttinl eol","",eol);
  953.  
  954.     if (i >= max) {
  955.     debug(F100,"ttinl buffer overflow","",0);
  956.     return(-1);    /* Overflowed dest buffer without getting eol */
  957.     }
  958.     x = i;                /* Size. */
  959.     dest[x] = '\0';            /* Terminate with null */
  960.  
  961.     debug(F110,"ttinl packet",dest,0);
  962.     debug(F101,"ttinl size","",x);    /* Log the size */
  963.     debug(F101,"ttinl ttprty 1","",ttprty);
  964.  
  965.     if (ttpflg++ == 0 && ttprty == 0) {    /* Check and adjust the parity. */
  966.         if ((ttprty = parchk(dest,start,x)) > 0) {
  967.         debug(F000,"ttinl parchk senses parity","",ttprty);
  968.         ttpmsk = 0x7f;
  969.         for (i = 0; i < x; i++)    /* Strip parity from this packet */
  970.           dest[i] &= 0x7f;
  971.     }
  972.     if (ttprty < 0) ttprty = 0;    /* Restore if parchk error */
  973.     debug(F101,"ttinl ttprty 2","",ttprty);
  974.     }
  975.     return(x);                /* Return length */
  976. }
  977. #endif /* TTXBUF */
  978.  
  979. SIGTYP (*saval)() = NULL;        /* For saving alarm handler */
  980.  
  981. VOID
  982. ttimoff() {                /* Turn off any timer interrupts */
  983.     alarm(0);
  984.     if (saval) {
  985.     signal(SIGALRM,saval);
  986.     saval = NULL;
  987.     } else {
  988.     signal(SIGALRM,SIG_IGN);    /* (was SIG_DFL) */
  989.     }
  990. }
  991.  
  992. /*  P R I N T _ M S G  --  Log an error message from VMS  */
  993.  
  994. int
  995. print_msg(s) char *s; {
  996.     long int blen = 0;
  997.     char buf[PMSG_BUF_SIZE], msg[PMSG_MSG_SIZE];
  998.     struct dsc$descriptor_s b = {
  999.     PMSG_BUF_SIZE-1,
  1000.     DSC$K_DTYPE_T,
  1001.     DSC$K_CLASS_S,NULL
  1002.     };
  1003.  
  1004.     b.dsc$a_pointer = (char *)&buf;
  1005.     if (!((vms_status = sys$getmsg(vms_status, &blen, &b, 0, 0)) & 1)) {
  1006.     fprintf(stderr,"print_msg; sys$getmsg\n");
  1007.     return(-1);
  1008.     }
  1009.     buf[blen] = '\0';
  1010.     sprintf(msg, "%s: %s\n", s, buf);
  1011.     debug(F100,s,"",0);
  1012.     ermsg(msg);
  1013.     return(0);
  1014. }
  1015.  
  1016. /*  S Y S I N I T  --  System-dependent program initialization.  */
  1017.  
  1018. #ifndef DVI$_FULLDEVNAM
  1019. #define DVI$_FULLDEVNAM 232
  1020. #endif /* DVI$_FULLDEVNAM */
  1021.  
  1022. #ifndef DVI$_STS
  1023. #define DVI$_STS 226
  1024. #endif /* DVI$_STS */
  1025.  
  1026. int
  1027. ttgwsiz() {                /* Get console window (screen) size */
  1028.     int x = -1;
  1029.     extern int tt_rows, tt_cols;
  1030.     typedef struct {            /* define an item list struct */
  1031.     short length;            /* length of buffer */
  1032.     short code;            /* item code */
  1033.     void *ptr;            /* ptr to buffer */
  1034.     void *retlen;            /* ptr to return length */
  1035.     } item_list;
  1036.     int status, iosb[2];
  1037.     item_list tt_dvi[] = {        /* Item list for GETDVI */
  1038.     {4,DVI$_DEVBUFSIZ,&tt_cols,0},
  1039.     {4,DVI$_TT_PAGE,&tt_rows,0},
  1040.     {0,0,0,0}
  1041.     };
  1042.     $DESCRIPTOR(sysin,CONDEVICE);
  1043.     status = sys$getdviw(0,0,&sysin,&tt_dvi,&iosb,0,0,0);
  1044.     if ((status & 1) == 0)
  1045.       return(-1);
  1046.     if (tt_rows < 1 || tt_cols < 1) return(0);
  1047.     return(1);
  1048. }
  1049.  
  1050. int
  1051. sysinit() {
  1052.     extern int speed;
  1053.     extern char ttname[];
  1054.     extern char *ckzsys;
  1055.     struct itmlst dviitm[] = {{64,DVI$_FULLDEVNAM,(char *)&lclnam,0},
  1056.             {sizeof(conclass),DVI$_DEVCLASS,(char *)&conclass,0},
  1057.                 {0,0,0,0}};
  1058.  
  1059.     static struct desblk {
  1060.     long int *fl;            /* Forward link.  Used by VMS only */
  1061.     void (*fncpnt)();        /* Function to call */
  1062.     unsigned char argcnt;        /* Only one arg allowed */
  1063.     unsigned char filler[3];    /* Filler.  Must be zero */
  1064.     long int *sts;            /* Address of sts (written by VMS) */
  1065.     } dclexh_ = {0,dcl_exit_h,1,{0,0,0},&dclexh_status};
  1066.  
  1067. #define GETCKXSYS
  1068. /*
  1069.   Get architecture and operating system name.
  1070. */
  1071. #ifdef GETCKXSYS
  1072.  
  1073. #if defined(__ALPHA)
  1074.  
  1075.     ckxsys = " OpenVMS Alpha";
  1076.  
  1077. #elif !(defined(__VAX) || defined (VAX) || defined (__GNUC__))
  1078. # error Unknown Hardware type, not VAX(tm) and not Alpha
  1079. #else /* VAX */
  1080.  
  1081. /* OK, we have a VAX so what is the name of the OS? */
  1082.  
  1083. #ifndef SYI$_ARCH_NAME    /* Should be in syidef.h but is not there yet */
  1084. # define SYI$_ARCH_NAME 4454
  1085. #endif /* SYI$_ARCH_NAME */
  1086.  
  1087.     struct iosb_t {
  1088.     short int status;        /* System service status */
  1089.     short int unused[3];
  1090.     } iosb;
  1091.  
  1092.     struct itmlst_t {
  1093.     short unsigned int buffer_len;    /* Buffer length */
  1094.     short unsigned int item_code;    /* Item code */
  1095.     char*buffer;            /* Where to write SYI info */
  1096.     long unsigned int *ret_len;    /* Pointer to returned length */
  1097.     long unsigned int mbz;        /* Must Be Zero */
  1098.  
  1099.     } itmlst;
  1100.  
  1101.     char arch_name[sizeof ("Alpha") - 1]; /* Architecture name */
  1102.     long unsigned int ret_len;        /* Returned length */
  1103. /*
  1104.   $getsyi of "hw_arch" will fail prior to VMS 5.5.  This failure indicates that
  1105.   the OS name is "VAX/VMS" (sic).  Use success or failure or $getsyi "hw_arch"
  1106.   rather than the more straight forward $getsyi "node_swvers" because latter
  1107.   is defined as four (4) characters and will get strange representing VMS
  1108.   10.0.
  1109. */
  1110.  
  1111. /*  Default -- Not strictly correct but traditional & familiar... */
  1112.     ckxsys = " VAX/VMS";
  1113.  
  1114.     itmlst.buffer_len = sizeof (arch_name);
  1115.     itmlst.item_code = SYI$_ARCH_NAME;
  1116.     itmlst.buffer = arch_name;
  1117.     itmlst.ret_len = &ret_len;
  1118.     itmlst.mbz = 0;
  1119.  
  1120.     if ((sys$getsyiw (0, 0, 0,
  1121.             &itmlst,
  1122.             &iosb,
  1123.             0, 0) & 1) == 1)
  1124.     if ((iosb.status & 1) == 1)
  1125.         ckxsys = " OpenVMS VAX";
  1126.  
  1127.     ckzsys = ckxsys;            /* Same deal for file module */
  1128.  
  1129. #endif /* OS Type */
  1130. #endif /* GETCKXSYS */
  1131.  
  1132. /*
  1133.  * Set up DCL Exit handler.  This allows us to reset terminal
  1134.  * and any other modifications we have done.
  1135.  */
  1136.     debug(F101,"sysinit ttychn","",ttychn);
  1137.     debug(F101,"sysinit conchn","",conchn);
  1138.     if (!CHECK_ERR("sysinit: sys$dclexh",
  1139.            sys$dclexh(&dclexh_))) {
  1140.         debug(F100,"sysinit failed to declare exit handler","",0);
  1141. #ifdef COMMENT
  1142.     return(0);
  1143. #endif /* COMMENT */
  1144.     }
  1145.     if (ttychn)                         /* if comms line already opened */
  1146.       return(0);            /* (how could it be???) */
  1147.  
  1148.     if (!conchn) {            /* Get console channel */
  1149. #ifdef CMU_TCPIP
  1150.       /* need to open console using libcmu routine to enable `select' call on
  1151.        * file descriptor zero.
  1152.        */
  1153.       cmu_stdin_open(dftty);
  1154.       conchn = cmu_get_sdc(0);
  1155. #else
  1156.       struct dsc$descriptor_s devnam =
  1157.         {sizeof(dftty)-1,DSC$K_DTYPE_T,DSC$K_CLASS_S,NULL};
  1158.       devnam.dsc$a_pointer = dftty;
  1159.       conchn = vms_assign_channel(&devnam);
  1160. #endif /* CMU_TCPIP */
  1161.     }
  1162.     congm();                /* Get and save its modes */
  1163. /*
  1164.  * Parse console terminal device name.
  1165.  */
  1166.     if (isatty(0)) {             /* So following won't fail under batch */
  1167.     CHECK_ERR("sysinit: sys$getdviw",
  1168.           sys$getdviw(0, conchn, 0, &dviitm, &wrk_iosb, 0, 0, 0));
  1169.     debug(F111,"sysinit","lclnam",lclnam);
  1170.  
  1171.     if (!CHECK_ERR("sysinit: sys$qiow",
  1172.                sys$qiow(QIOW_EFN, conchn, IO$_SENSEMODE,
  1173.                 &wrk_iosb, 0, 0,
  1174.                 &ccold, sizeof(ccold), 0, 0, 0, 0)))
  1175.       return(-1);
  1176.     ttspeed = speed = ttispd((unsigned char) wrk_iosb.size);
  1177.     conspd = ttspeed;
  1178.     debug(F111,"sysinit speed",lclnam,speed);
  1179.     strncpy(ttname,lclnam,80);
  1180.     }
  1181.  
  1182.     /* Initialize descriptor */
  1183.     tt_fulldevnam_d.dsc$b_dtype = DSC$K_DTYPE_T;
  1184.     tt_fulldevnam_d.dsc$b_class = DSC$K_CLASS_S;
  1185.  
  1186.     debug(F100,"sysinit done","",0);
  1187.     return(0);
  1188. }
  1189.  
  1190. /*
  1191.  * DCL Exit handler.  This is the cleanup handler for program.
  1192.  * Any final cleanup (closing channels etc) should be done at this
  1193.  * point.
  1194.  */
  1195. VOID
  1196. dcl_exit_h(sts) unsigned long int *sts; {
  1197.     syscleanup();
  1198.     return;
  1199. }
  1200.  
  1201. /*  S Y S C L E A N U P -- System-dependent program epilog.  */
  1202.  
  1203.  
  1204. int
  1205. syscleanup() {
  1206.     int x;
  1207.     extern zclosf();
  1208.     void con_cancel();
  1209.     debug(F101,"syscleanup entry","",ttyfd);
  1210.     con_cancel();        /* Cancel pending console i/o. */
  1211.     ttclos(ttyfd);        /* Do the cleanup no matter what... */
  1212.     zclosf(ZSYSFN);        /* Close various files and kill child procs */
  1213. #ifdef COMMENT
  1214.     /* This is a bit extreme... */
  1215.     if ((x = conres()) < 0) exit(SS$_ABORT);
  1216. #else
  1217.     conres();
  1218. #endif /* COMMENT */
  1219.     debug(F101,"syscleanup conres","",x);
  1220.     printf("\r");
  1221.     return(0);
  1222. }
  1223.  
  1224. /*  T T O P E N  --  Open a tty for exclusive access.  */
  1225.  
  1226. /*  Returns 0 on success, -1 on failure.  */
  1227. /*
  1228.   If called with lcl < 0, sets value of lcl as follows:
  1229.   0: the terminal named by ttname is the job's controlling terminal.
  1230.   1: the terminal named by ttname is not the job's controlling terminal.
  1231.   But watch out: if a line is already open, or if requested line can't
  1232.   be opened, then lcl remains (and is returned as) -1.
  1233. */
  1234. int
  1235. ttopen(ttname,lcl,modem,timo) char *ttname; int *lcl, modem, timo; {
  1236.     extern int speed;
  1237.     int s, x;
  1238.     unsigned long int no_share_priv[2], prev_privs[2];
  1239.     unsigned long int devchar, devclass, devsts;
  1240. /*    char dvibuf[65]; */
  1241.     struct dsc$descriptor_s devnam = {0,DSC$K_DTYPE_T,DSC$K_CLASS_S,0};
  1242.     struct itmlst dviitm[] = {{64,DVI$_FULLDEVNAM,(char *)&tt_fulldevnam,0},
  1243.             {sizeof(devchar),DVI$_DEVCHAR,NULL,0},
  1244.             {sizeof(devclass),DVI$_DEVCLASS,NULL,0},
  1245.             {sizeof(devsts),DVI$_STS,NULL,0},
  1246.             {0,0,0,0}};
  1247.             
  1248.     dviitm[1].adr = (char *)&devchar;
  1249.     dviitm[2].adr = (char *)&devclass;
  1250.     dviitm[3].adr = (char *)&devsts;
  1251.     
  1252. #ifdef NETCONN
  1253.     if (network && ttyfd > -1) {    /* if device already opened */
  1254.         if (strncmp(ttname,ttnmsv,80))    /* are new & old names equal? */
  1255.           ttclos(ttyfd);        /* no, close old ttname, open new */
  1256.         else                 /* else same, ignore this call, */
  1257.       return(0);            /* and return. */
  1258.     }
  1259.     if (modem < 0) {            /* modem < 0 = special code for net */
  1260.     int x;
  1261.     ttmdm = modem;
  1262.     modem = -modem;            /* Positive network type number */
  1263.     debug(F111,"ttopen net",ttname,modem);
  1264.     network = 1;            /* Because rlog_ini() uses ttoc() */
  1265.     x = netopen(ttname, lcl, modem);
  1266.     if (x > -1) {            /* Success... */
  1267.         strncpy(ttnmsv,ttname,DEVNAMLEN);
  1268.         ttnet = modem;
  1269.     } else network = 0;        /* Failed, unset network flag */
  1270.         return(x);
  1271.     }
  1272. #endif /* NETCONN */
  1273.  
  1274.     if (ttychn) return(0);        /* Close channel if open */
  1275.  
  1276.     devnam.dsc$w_length  = strlen(ttname);
  1277.     devnam.dsc$a_pointer = ttname;
  1278.     sys$getdviw(0, 0, &devnam, &dviitm, &wrk_iosb, 0, 0, 0);
  1279.     tt_fulldevnam[65] = '\0';        /* Make sure it has an end.... */
  1280.  
  1281.     if (devclass != DC$_TERM) {        /* Is it a terminal? */
  1282.     fprintf(stderr,
  1283.         "%%CKERMIT-W-NOTTERM, %s is not a terminal\n",ttname);
  1284.     return(-1);
  1285.     }
  1286.     if (!(devchar & DEV$M_AVL)) {    /* Is it available? */
  1287.     fprintf(stderr,
  1288.         "%%CKERMIT-W-NOTAVAL, %s is not available\n",tt_fulldevnam);
  1289.     return(-5);
  1290.     }
  1291.     if (!(devsts & UCB$M_ONLINE)) {    /* Is it online? */
  1292.     fprintf(stderr,
  1293.         "%%CKERMIT-W-OFFLINE, %s is not online\n",tt_fulldevnam);
  1294.     return(-5);
  1295.     }
  1296.     ttmdm = modem;            /* Make this available to other fns */
  1297.     xlocal = *lcl;            /* Make this available to other fns */
  1298.  
  1299. /*
  1300.  *  Set up the tt_fulldevnam_d descriptor for use by ttclos() later.
  1301.  */
  1302.     tt_fulldevnam_d.dsc$w_length  = strlen(tt_fulldevnam);
  1303.     tt_fulldevnam_d.dsc$a_pointer = tt_fulldevnam;
  1304.  
  1305. /*
  1306.  *  Assume the user has SHARE privilege enabled and turn it off.  This is
  1307.  *  necessary to prevent a privileged user from assigning a channel to
  1308.  *  a device already in use by another process.
  1309.  */
  1310.     no_share_priv[0] = PRV$M_SHARE;
  1311.     sys$setprv (0, &no_share_priv, 0, &prev_privs);
  1312.  
  1313.     ttychn = vms_assign_channel(&devnam); /* Get a channel for it. */
  1314.  
  1315.     sys$setprv (1, &prev_privs, 0, 0);    /* Re-enable the old privs */
  1316.  
  1317.     debug(F111,"ttopen","modem",modem);
  1318.     debug(F101," ttychn","",ttychn);
  1319.  
  1320.     if (!ttychn) return(-1);        /* If couldn't open, fail. */
  1321. /*
  1322.  * Check for maximum size of QIO, so as to not get the dreaded quota exceeded
  1323.  * status returned.  When doing a QIO that has a larger buffer than
  1324.  * MAXBUF, exceeded quota wil be returned.
  1325.  *
  1326.  * Example: MAXBUF = 2048, QIO = 1936, overhead is 112 will succeed.
  1327.  *        QIO of 1937 will fail.
  1328.  *
  1329.  * This can change for different versions of VMS.
  1330.  */
  1331.     qio_maxbuf_size = get_qio_maxbuf_size(ttychn);
  1332.  
  1333.     strncpy(ttname,tt_fulldevnam,80);    /* Copy true name back to main pgm  */
  1334.  
  1335.     strcpy(ttnmsv,ttname);        /* Open, keep copy of name locally. */
  1336.     ttxbn = ttxbp = 0;            /* Initialize input buffer */
  1337.  
  1338. /* Caller wants us to figure out if line is controlling tty */
  1339.  
  1340.     debug(F111,"ttopen ok",ttname,*lcl);
  1341.     if (*lcl < 0) {
  1342.     if (conclass == DC$_TERM)
  1343.       xlocal = (strncmp(ttname,lclnam,80) == 0) ? 0 : 1;
  1344.     else
  1345.       xlocal = 1;             /* If not a term, then we must be local */
  1346.     debug(F111,"ttyname",lclnam,xlocal);
  1347.     }
  1348.     if (!CHECK_ERR("ttopen: sys$qiow",
  1349.     sys$qiow(QIOW_EFN, ttychn, IO$_SENSEMODE, &wrk_iosb, 0, 0,
  1350.          &ttold, sizeof(ttold), 0, 0, 0, 0))) return(-1);
  1351.  
  1352.     ttspeed = speed = ttispd((unsigned char) wrk_iosb.size);
  1353.  
  1354. /* Got the line, now set the desired value for local. */
  1355.  
  1356.     if (*lcl) *lcl = xlocal;
  1357.  
  1358.     tttvt = ttold;
  1359.     ttraw = ttold;
  1360.     debug(F101,"ttopen lcl","",*lcl);
  1361.     ttpmsk = 0xff;
  1362.     return(0);
  1363. }
  1364.  
  1365. #ifdef COMMENT
  1366. /*
  1367.   Old version.
  1368. */
  1369. unsigned long int
  1370. vms_assign_channel(ttname) char *ttname;  {
  1371.     unsigned int channel = 0;
  1372.     struct dsc$descriptor_s d = {0,DSC$K_DTYPE_T,DSC$K_CLASS_S,0};
  1373.  
  1374.     d.dsc$w_length  = strlen(ttname);
  1375.     d.dsc$a_pointer = ttname;
  1376.     if (!CHECK_ERR("vms_assign_channel: sys$assign",
  1377.     sys$assign(&d, &channel, 0, 0))) return(0);
  1378.     return(channel);
  1379. }
  1380. #else
  1381. /*
  1382.   New version from Hunter Goatley.
  1383. */
  1384. unsigned short int
  1385. vms_assign_channel(ttname) struct dsc$descriptor_s *ttname; {
  1386.     unsigned short channel = 0;
  1387.  
  1388. #ifdef COMMENT
  1389. /* what's all this then ... */
  1390.     struct dsc$descriptor_s d = {0,DSC$K_DTYPE_T,DSC$K_CLASS_S,0};
  1391.     d.dsc$w_length  = strlen(ttname);
  1392.     d.dsc$a_pointer = ttname;
  1393. #endif /* COMMENT */
  1394.  
  1395.     if (!CHECK_ERR("vms_assign_channel: sys$assign",
  1396.     sys$assign(ttname, &channel, 0, 0))) return(0);
  1397.  
  1398. #ifdef NEW_STUFF_FROM_BRUCE_DAY
  1399. /*
  1400.   Which is not presently defined...
  1401.   This is supposed to allow C-Kermit to go into protocol mode on an LTA 
  1402.   device without a prior CONNECT command.
  1403. */
  1404. #ifdef IO$M_LT_CONNECT
  1405.     vms_status = sys$qiow(QIOW_EFN, channel, IO$_TTY_PORT|IO$M_LT_CONNECT,
  1406.                           &wrk_iosb, 0, 0, 0, 0, 0, 0, 0, 0);
  1407.     debug(F101, "vms_assign_channel LAT connect status","",vms_status);
  1408.     debug(F101, "vms_assign_channel LAT connect iosb","",wrk_iosb.status);
  1409. #endif /* IO$M_LT_CONNECT */
  1410. #endif /* NEW_STUFF_FROM_BRUCE_DAY */
  1411.  
  1412.     return(channel);
  1413. }
  1414. #endif /* COMMENT */
  1415.  
  1416. /*  T T C L O S  --  Close the communication device.  */
  1417.  
  1418. int
  1419. ttclos(dummy) int dummy; {
  1420.     debug(F101,"ttclos 1: ttyfd","",ttyfd);
  1421.     debug(F101,"ttclos 1: ttychn","",ttychn);
  1422.     debug(F101,"ttclos 1: network","",network);
  1423.  
  1424. #ifdef NETCONN
  1425.     if (network) {            /* Network connection. */
  1426.     netclos();            /* Close it. */
  1427.     debug(F101,"ttclos 2: network","",network);
  1428.     debug(F101,"ttclos 2: ttychn","",ttychn);
  1429.     network = 0;
  1430.     return(0);
  1431.     } else
  1432.       ck_cancio();            /* Cancel any pending i/o. */
  1433. #endif /* NETCONN */
  1434.  
  1435. /* The rest is for serial connections, in which ttychn is nonzero. */
  1436.  
  1437.     if (!ttychn) return(0);
  1438. /*
  1439.   Observations indicate that it can take 20-30 seconds for DTR to drop
  1440.   after closing the device.  Perhaps a call to tthang() should go here.
  1441. */
  1442.     ttres();                /* Reset modes. */
  1443.  
  1444. /*
  1445.   Assume it's a LAT device and try to do a LAT disconnect on it.
  1446.   If it fails, then it's not a LAT device and no harm is done.
  1447. */
  1448. #ifdef IO$M_LT_DISCON
  1449.     vms_status = sys$qiow(QIOW_EFN, ttychn, IO$_TTY_PORT|IO$M_LT_DISCON,
  1450.               &wrk_iosb, 0, 0, 0, 0, 0, 0, 0, 0);
  1451.     debug(F101, "ttclos LAT disconnect, status", "", vms_status);
  1452.     debug(F101, "ttclos LAT disconnect, iosb", "", wrk_iosb.status);
  1453. #else
  1454.     debug(F100, "ttclos LAT disconnect not supported", "", 0);
  1455. #endif /* IO$M_LT_DISCON */
  1456.     if (!CHECK_ERR("ttclos: sys$dassgn",
  1457.     sys$dassgn(ttychn))) return(-1);
  1458.     ttychn = 0;                /* Mark it as closed. */
  1459.     return(0);
  1460. }
  1461.  
  1462.  
  1463. /*  T T R E S  --  Restore terminal to its original modes.  */
  1464.  
  1465. int
  1466. ttres() {                /* Restore the tty to normal. */
  1467.     ttpmsk = 0xff;
  1468. #ifdef NETCONN
  1469.     if (network) return (0);        /* Network connection, do nothing */
  1470. #endif /* NETCONN */
  1471.  
  1472.     if (!ttychn) return(-1);        /* Not open. */
  1473.  
  1474.     tt_cancel();            /* Cancel outstanding I/O */
  1475.     msleep(250);            /* Wait for pending i/o to finish. */
  1476.     debug(F101,"ttres, ttychn","",ttychn);
  1477.     if (!CHECK_ERR("ttres: sys$qiow",
  1478.     sys$qiow(QIOW_EFN, ttychn, IO$_SETMODE, &wrk_iosb, 0, 0,
  1479.              &ttold, sizeof(ttold), 0, 0, 0, 0))) return(-1);
  1480.     return(0);
  1481. }
  1482.  
  1483. /*  T T B I N  --  Code shared by ttpkt() and ttvt()  */
  1484. /*
  1485.   Puts communication device in "binary" mode.  In VMS there's no distinction
  1486.   between device modes for terminal connection, packet operation, and dialing.
  1487. */
  1488. static int
  1489. ttbin(speed, xflow, xparity) int speed, xflow, xparity; {
  1490.     int s;
  1491.     extern int flow;            /* Global flow control variable */
  1492.  
  1493.     if (xparity > -1) {
  1494.     ttprty  = xparity;
  1495.     ttpflg  = 0;            /* Parity not sensed yet */
  1496. #ifdef COMMENT
  1497. /*
  1498.   No.  We want the mask applied for file transfer, but not for CONNECT or
  1499.   scripts, because then we lose Telnet negotiations.
  1500. */
  1501.     ttpmsk  = ttprty ? 0177 : 0377;    /* Parity stripping mask */
  1502. #endif /* COMMENT */
  1503.     debug(F101,"ttbin ttprty","",ttprty);
  1504.     }
  1505.  
  1506. #ifdef NETCONN
  1507.     if (network) return(0);        /* Nothing to do on net connections */
  1508. #endif /* NETCONN */
  1509.  
  1510.     if (!ttychn) return(-1);        /* Not open. */
  1511.  
  1512. /* The following applies only to serial ports - causes errors on network */
  1513.  
  1514.     if (xflow != FLO_DIAL && ttflow != FLO_DIAX)
  1515.       ttflow = xflow;            /* for other CKVTIO routines. */
  1516.  
  1517.     ttspeed = speed;            /* Keep local copies of arguments */
  1518.     if ((s = ttsspd(speed/10)) < 0)    /* Get internal speed code */
  1519.       s = 0;
  1520.  
  1521. /* Log original terminal settings for debugging purposes */
  1522.  
  1523.     ttraw = ttold;            /* Get a fresh copy of this */
  1524.     debug(F101, "original ttraw.basic", "", ttraw.basic);
  1525.     debug(F101, "original ttraw.extended", "", ttraw.extended);
  1526. /*
  1527.   Settings based on call parameters flow-control and parity...
  1528.   NOTE: we are using the GLOBAL copy of flow, not our parameter here.
  1529.   This is because the parameter might be FLO_DIAL or FLO_DIALX, which
  1530.   is not flow control at all.
  1531. */
  1532.     if (flow == FLO_XONX) {                /* FLOW = XON/XOFF */
  1533.     ttraw.basic |=  (TT$M_HOSTSYNC|TT$M_TTSYNC);
  1534.     } else if (flow == FLO_NONE) {            /* FLOW = NONE */
  1535.     ttraw.basic &= ~(TT$M_HOSTSYNC|TT$M_TTSYNC);
  1536.     } else if (flow == FLO_KEEP) {            /* FLOW = KEEP */
  1537. /*
  1538.  * Put flow-control paramaters back the way we found them when
  1539.  * the device was first opened.
  1540.  */
  1541.     if (ttold.basic & TT$M_HOSTSYNC)
  1542.       ttraw.basic |= TT$M_HOSTSYNC;
  1543.     else
  1544.       ttraw.basic &= ~TT$M_HOSTSYNC;
  1545.     if (ttold.basic & TT$M_TTSYNC)
  1546.       ttraw.basic |= TT$M_TTSYNC;
  1547.     else
  1548.       ttraw.basic &= ~TT$M_TTSYNC;
  1549. /*
  1550.   NOTE: VMS 7.0 supports RTS/CTS.  But how can we include that here
  1551.   portably -- distinction between compile time & run time, etc...
  1552. */
  1553.     }
  1554. /*
  1555.   EIGHTBIT setting depends on GLOBAL copy of parity variable, not our
  1556.   parameter.
  1557. */
  1558.     if (parity == 0)
  1559.       ttraw.basic  |= TT$M_EIGHTBIT;    /* Allow 8-bit data if no parity */
  1560.     else                /* Otherwise */
  1561.       ttraw.basic  &= ~TT$M_EIGHTBIT;    /* 7-bit data. */
  1562.  
  1563.     ttraw.basic |= TT$M_NOECHO;        /* Turn off echo */
  1564.     ttraw.basic |= TT$M_NOBRDCST;    /* Turn off broadcasts */
  1565.     ttraw.basic &= ~TT$M_NOTYPEAHD;    /* Enable type-ahead */
  1566.     ttraw.basic &= ~TT$M_ESCAPE;    /* Disable escape-seq processing */
  1567.     ttraw.extended &= ~TT2$M_LOCALECHO;    /* Disable local echo */
  1568.     ttraw.extended |= TT2$M_PASTHRU;    /* Enable pass-through mode */
  1569.     ttraw.extended |= TT2$M_ALTYPEAHD;    /* Use big type-ahead buffers */
  1570.  
  1571. /* Report what we did so we can check for problems */
  1572.  
  1573.     debug(F101, "ttraw.basic", "", ttraw.basic);
  1574.     debug(F101, "ttraw.extended", "", ttraw.extended);
  1575.  
  1576.     vms_status = sys$qiow(QIOW_EFN, ttychn, IO$_SETMODE, &wrk_iosb, 0, 0,
  1577.              &ttraw, sizeof(ttraw), s, 0, 0, 0);
  1578.  
  1579.     if (vms_status != SS$_NORMAL) {    /* Error queuing request */
  1580.     print_msg("ttbin: sys$qiow");
  1581.     return(-1);
  1582.     }
  1583.     if (wrk_iosb.status != SS$_NORMAL) { /* Error executing request */
  1584.     vms_status = wrk_iosb.status;
  1585.     print_msg("ttbin: sys$qiow(iosb)");
  1586.     return(-1);
  1587.     }
  1588.     debug(F100,"ttbin ok","",0);
  1589.     return(0);                /* All OK */
  1590. }
  1591.  
  1592. /*  T T P K T  --  Condition the communication device for packets. */
  1593.  
  1594. #ifdef COMMENT
  1595. #define DIALING    4        /* Flags (via flow) for modem handling */
  1596. #define CONNECT 5        /* NOT YET IMPLEMENTED IN VMS! */
  1597. #endif /* COMMENT */
  1598.  
  1599. /*  Returns 0 on success, -1 on failure.  */
  1600.  
  1601. int
  1602. ttpkt(speed,flow,parity) long speed; int flow, parity; {
  1603.     int x;
  1604.     debug(F101,"ttpkt flow","",flow);
  1605.     x = ttbin(speed,flow,parity);    /* Put device in binary mode */
  1606.     debug(F101,"ttpkt ttbin","",x);
  1607.     ttpmsk = (ttprty) ? 0x7f : 0xff;    /* Parity stripping mask. */
  1608.     return(x);
  1609. }
  1610.  
  1611. /*  T T V T  --  Condition communication device terminal connection. */
  1612.  
  1613. int
  1614. ttvt(speed,flow) long speed; int flow; {
  1615.     int x;
  1616.     debug(F101,"ttvt flow","",flow);
  1617.     if ((x = ttbin(speed,flow,-1)) > -1) /* Put device in binary mode */
  1618.       tvtflg = 1;
  1619.     debug(F101,"ttvt ttbin","",x);
  1620.     ttpmsk = 0xff;            /* Let CONNECT module handle it */
  1621.     return(x);
  1622. }
  1623.  
  1624. /* T T I S P D  -- Return binary baud rate for internal coded speed */
  1625.  
  1626. int
  1627. ttispd(ispeed) unsigned char ispeed; {
  1628.     int s;
  1629.  
  1630. #ifdef NETCONN
  1631.     if (network) return(-1);
  1632. #endif /* NETCONN */
  1633.  
  1634. /* When the line is set, grab the line speed  and save it */
  1635.  
  1636.     for (s = 0;  ttspeeds[s].dec &&
  1637.     (ttspeeds[s].dec != ispeed);  s++)
  1638.         ;
  1639.  
  1640. /* If speed is zero, then no match.  Set speed to -1 so it is undefined */
  1641.  
  1642.     return(ttspeeds[s].line ? (int) ttspeeds[s].line * 10 : -1);
  1643. }
  1644.  
  1645.  
  1646. /*  T T S S P D  --  Return the internal baud rate code for 'speed'.  */
  1647.  
  1648. int
  1649. ttsspd(cps) int cps; {
  1650.     int s;
  1651.     char msg[50];
  1652.  
  1653. #ifdef    NETCONN
  1654.     if (network) return(0);
  1655. #endif    /* NETCONN */
  1656.  
  1657.     if (cps <= 0)            /* 026 Unknown cps fails */
  1658.       return (-1);
  1659.     for (s = 0;  ttspeeds[s].line && (ttspeeds[s].line != cps);  s++) ;
  1660.     if (ttspeeds[s].line) {
  1661.         ttspeed = cps * 10L;        /* Make a copy global to this module */
  1662.     if (ttspeed == 70L)        /* ... in bits per second, not cps, */
  1663.       ttspeed = 75L;        /* because ttgspd() uses it! */
  1664.     return(ttspeeds[s].dec);
  1665.     } else {
  1666.     sprintf(msg,"Unsupported line speed - %d\n",cps*10);
  1667.     ermsg(msg);
  1668.     ermsg("Current speed not changed\n");
  1669.     return(-1);
  1670.     }
  1671. }
  1672.  
  1673.  
  1674. /* Interrupt Functions */
  1675.  
  1676.  
  1677. /*  C O N I N T  --  Console Interrupt setter  */
  1678.  
  1679. static SIGTYP (*cctrap)();
  1680.  
  1681. VOID
  1682. #ifdef CK_ANSIC
  1683. conint(SIGTYP (*f)(int), SIGTYP (*s)(int))
  1684. #else
  1685. conint(f,s) int (*f)(int), (*s)(int);
  1686. #endif /* CK_ANSIC */
  1687. /* conint */ {                /* Set an interrupt trap. */
  1688.  
  1689.     cctrap = f;                /* Make a global copy */
  1690.     debug(F101,"conint batch","",batch);
  1691.     if (batch) return;            /* Ignore signals in background. */
  1692.  
  1693. #ifdef COMMENT
  1694. /*
  1695.    Forget this whole thing. 
  1696.    The batch flag should be set in only one place: congm().
  1697. */
  1698.  
  1699. /*
  1700.   Check if invoked in background -- if so signals set to be ignored.
  1701.   But VMS has no notion of background, so no worries, right?
  1702. */
  1703.     if (!isatty(0)) {
  1704.     debug(F100,"conint isatty diagnoses batch","",0);
  1705. #ifdef COMMENT
  1706.     batch = backgrd = 1;
  1707. #else
  1708. /*
  1709.   But we still might need to know whether we are running under batch.
  1710.   In which case, the test above is probably inadequate.  According to Carl
  1711.   Friedberg <friedberg@esb.com>, "I believe this can be done unambiguously by
  1712.   checking that (1) SYS$GETJPI returns a null string as the terminal; and
  1713.   (2) the current process is NOT a subprocess (a subprocess ALWAYS has a null
  1714.   string as its terminal ID). The real test is if PCB$L_STS has the
  1715.   PCB$M_BATCH bit set.  If the current process is a subprocess, then the test
  1716.   must be repeated for the MASTER (root) process in the job tree.  It is legal
  1717.   to run Kermit in a subprocess from within a batch job... and in that case,
  1718.   it should still behave like a batch job (no terminal input; must execute a
  1719.   SET LINE command).
  1720. */
  1721.     batch = 1;
  1722.     backgrd = 0;
  1723. #endif /* COMMENT */
  1724.     return;
  1725.     }
  1726. #endif /* COMMENT */
  1727.     signal(SIGINT,f);            /* Function to trap to. */
  1728.     conif = 1;                /* Flag console interrupts on. */
  1729. }
  1730.  
  1731. /*  C O N N O I  --  Reset console terminal interrupts */
  1732.  
  1733. VOID
  1734. connoi() {                /* Console-no-interrupts */
  1735.  
  1736.     if (batch) return;            /* must ignore signals in bkgrd */
  1737.  
  1738. #ifdef COMMENT
  1739. /* wrong... */
  1740.     signal(SIGINT,SIG_DFL);
  1741. #else
  1742. /* right?.. */
  1743.     signal(SIGINT,SIG_IGN);
  1744. #endif /* COMMENT */
  1745.     conif = 0;
  1746. }
  1747.  
  1748. /*  T T O L  --  Write string s, length n, to communication device.  */
  1749.  
  1750. #ifndef IO$M_BREAKTHRU
  1751. #define IO$M_BREAKTHRU    0x0200
  1752. #endif /* IO$M_BREAKTHRU */
  1753.  
  1754. #ifndef SS$_EXQUOTA  
  1755. #define SS$_EXQUOTA 28
  1756. #endif /* SS$_EXQUOTA */
  1757.  
  1758. int
  1759. ttol(s,n) int n; CHAR *s; {
  1760.     int
  1761.       remaining,            /* Amount left to write */
  1762.       size;                /* How much to write this time */
  1763.     static int max = 0;            /* Chunk size for writing */
  1764.  
  1765. #ifdef NETCONN
  1766.     debug(F101,"ttol network","",network);
  1767.     if (network)            /* If SET HOST connection, */
  1768.     return(nettol(s,n));        /* call network package. */
  1769. #endif /* NETCONN */
  1770.  
  1771. /* It's not a SET HOST connection. */
  1772.  
  1773.     debug(F101,"ttol ttychn","",ttychn);
  1774.     if (!ttychn) return(-1);        /* Not open. */
  1775.     debug(F101,"ttol length","",n);
  1776.     debug(F101,"ttol max","",max);
  1777.    
  1778. /* Have we already calculated a chunk size? */   
  1779.    
  1780.     if (max == 0) {            /* No, try to send whole packet. */
  1781.     vms_status = sys$qiow(QIOW_EFN, ttychn, IO$_WRITEVBLK|IO$M_BREAKTHRU,
  1782.                   &wrk_iosb, 0, 0, s, n, 0, 0, 0, 0);
  1783.     if (vms_status == SS$_NORMAL) {
  1784.         debug(F101,"ttol 1 ok","",n);
  1785.         return(n);
  1786.     }
  1787. #ifdef DEBUG
  1788.     if (deblog) {            /* Failed. */
  1789.         debug(F101,"ttol 1 error, vms_status","",vms_status);    
  1790.         debug(F101,"ttol 1 iosb size","",wrk_iosb.size);
  1791.         debug(F101,"ttol 1 iosb status","",wrk_iosb.status);
  1792.     }
  1793. #endif /* DEBUG */
  1794.     if (vms_status != SS$_EXQUOTA)    /* "Quota exceeded"? */
  1795.       return(-3);            /* No, something else, give up. */
  1796. /*
  1797.   Here we should find out what MAXBUF is (not to mention BYTLM, BIOLM, and
  1798.   friends), and chop up the packet into pieces accordingly.  But reportedly
  1799.   this information, and how to use it (percent overhead, etc), is highly
  1800.   VMS-version-dependent.  So instead we just try different numbers.  Our first
  1801.   attempt keeps dividing it in half until it works, down to about 70.
  1802. */
  1803.     do {
  1804.         max = (max == 0) ? n / 2 : max / 2;
  1805.         debug(F101,"ttol 2 max","",max);
  1806.         vms_status = sys$qiow(QIOW_EFN, ttychn,
  1807.                   IO$_WRITEVBLK|IO$M_BREAKTHRU,
  1808.                   &wrk_iosb, 0, 0, s, max, 0, 0, 0, 0);
  1809.           debug(F101,"ttol 2 vms_status","",vms_status); 
  1810.         if (vms_status == SS$_NORMAL)
  1811.           break;
  1812.     } while (max > 70);        /* 70 is the minimum. */
  1813.     
  1814.     if (vms_status != SS$_NORMAL)    /* Loop exhausted, fail. */
  1815.       return(-3);
  1816.    
  1817.     } else {                /* We already calculated max. */
  1818.  
  1819.     size = (max > n) ? n : max;      /* Write 1st chunk, but not too much */
  1820.     vms_status = sys$qiow(QIOW_EFN, ttychn, IO$_WRITEVBLK|IO$M_BREAKTHRU,
  1821.                   &wrk_iosb, 0, 0, s, size, 0, 0, 0, 0);
  1822.     debug(F101,"ttol 3 vms_status","",vms_status); 
  1823.     if (vms_status != SS$_NORMAL)
  1824.       return(-3);
  1825.     if (size == n) {        /* (Not strictly necessary) */
  1826.         debug(F101,"ttol 3 done","",n);
  1827.           return(n);
  1828.     }  
  1829.     }    
  1830. /*   
  1831.   We have written the first chunk successfully, now write the remaining
  1832.   max-sized chunks, plus the (usually) less-than-max-sized last chunk.
  1833. */    
  1834.     remaining = n;
  1835.     while (1) {
  1836.     s += max;            /* Where to start */
  1837.     remaining -= max;        /* How much left to write */
  1838.     size = (remaining < max) ?    /* How much to write this time */
  1839.       remaining : max;
  1840.     if (size < 1)            /* Done? */
  1841.       break;
  1842.   
  1843.       debug(F101,"ttol 4 size","",size);
  1844.       vms_status = sys$qiow(QIOW_EFN, ttychn, IO$_WRITEVBLK|IO$M_BREAKTHRU,
  1845.                   &wrk_iosb, 0, 0, s, size, 0, 0, 0, 0);
  1846.     debug(F101,"ttol 4 vms_status","",vms_status); 
  1847.     if (vms_status != SS$_NORMAL)
  1848.       return(-3);
  1849.     }
  1850.     debug(F101,"ttol 5 done","",n);
  1851.     return(n);
  1852. }
  1853.  
  1854. /*  T T O C  --  Output a character to the communication line  */
  1855.  
  1856. int
  1857. #ifdef CK_ANSIC
  1858. ttoc(char c)
  1859. #else
  1860. ttoc(c) char c;
  1861. #endif    /* CK_ANSIC */
  1862. /* ttoc */ {
  1863. #ifdef NETCONN
  1864.     if (network) {
  1865.     return(nettoc(c));
  1866.     } else {
  1867. #endif /* NETCONN */
  1868.     debug(F101,"ttoc char","",c);
  1869.     if (!ttychn) {
  1870.         debug(F100,"ttoc ttychn not open","",0);
  1871.         return(-1);            /* Not open. */
  1872.     }    
  1873.     if (CHECK_ERR("ttoc: sys$qiow",
  1874.               sys$qiow(QIOW_EFN, ttychn, IO$_WRITEVBLK|IO$M_BREAKTHRU,
  1875.                    &wrk_iosb, 0, 0, &c, 1, 0, 0, 0, 0)))
  1876.       return(0);
  1877. #ifdef NETCONN
  1878.     }
  1879. #endif /* NETCONN */
  1880.     return(-1);
  1881. }
  1882.  
  1883. /*  T T _ C A N C E L  --  Cancel i/o on tty channel if not complete  */
  1884.  
  1885. VOID
  1886. tt_cancel() {
  1887.     int mask;
  1888. #ifdef NETCONN
  1889.     if (network) return;
  1890. #endif /* NETCONN */
  1891.     CHECK_ERR("tt_cancel: sys$cancel",sys$cancel(ttychn));
  1892.     tt_queued = 0;
  1893. }
  1894.  
  1895. /*  C O N _ C A N C E L  --  Cancel i/o on console channel if not complete  */
  1896.  
  1897. VOID
  1898. con_cancel() {
  1899.     int mask;
  1900.  
  1901.     CHECK_ERR("con_cancel: sys$cancel",sys$cancel(conchn));
  1902.     con_queued = 0;
  1903. }
  1904.  
  1905. /*  S N D B R K  --  Send a BREAK signal of the given length.  */
  1906.  
  1907. int
  1908. sndbrk(msec) int msec; {
  1909.     int long x = 0;
  1910.     int brklen;
  1911.     struct iosb_struct  tmp_ttiosb;
  1912.     struct tt_mode ttchr;
  1913. #ifndef TT$M_BREAK            /* For old VMS with no BREAK... */
  1914. /*
  1915.   Note: 110 is used instead of 50, because 50 is not supported by all
  1916.   VAX serial port controllers.
  1917. */
  1918. #define BRKSPD = 110            /* Speed for simulating BREAK */
  1919. #define BRKSYM = TT$C_BAUD_110;        /* VMS symbol for this speed */
  1920. #endif /* TT$M_BREAK */
  1921.  
  1922. #ifdef NETCONN
  1923.     if (network)             /* Send network BREAK */
  1924.       return(netbreak());        /* Length doesn't matter */
  1925. #endif /* NETCONN */
  1926.  
  1927.     if (!ttychn) return(-1);        /* SET LINE not done. */
  1928.     debug(F101,"sndbrk msec","",msec);
  1929.  
  1930.     tt_cancel();            /* Cancel I/O */
  1931.  
  1932. #ifndef TT$M_BREAK            /* VMS doesn't have BREAK function */
  1933.  
  1934. /* Send the right number of NULs at BREAK-simulation speed... */
  1935.  
  1936.     brklen = ( BRKSPD * 1000 ) / ( msec * 10 ); /* Calculate number of chars */
  1937.     if (brklen > sizeof(brkarray)) brklen = sizeof(brkarray);
  1938.     debug(F101,"sndbrk speed","",BRKSPD);
  1939.     debug(F101,"sndbrk brklen","",brklen);
  1940.     if (!CHECK_ERR("ttsndb: SENSEMODE",
  1941.     sys$qiow(QIOW_EFN, ttychn, IO$_SENSEMODE, &wrk_iosb, 0, 0,
  1942.         &ttchr, sizeof(ttchr), 0, 0, 0, 0))) return(-1);
  1943.     if (!CHECK_ERR("ttsndb: SETMODE(1)",
  1944.     sys$qiow(QIOW_EFN, ttychn, IO$_SETMODE, &tmp_ttiosb, 0, 0,
  1945.         &ttchr, sizeof(ttchr), BRKSYM, 0, 0, 0))) return(-1);
  1946.     if (!CHECK_ERR("ttsndb: writing nulls",
  1947.     sys$qiow(QIOW_EFN, ttychn, IO$_WRITEVBLK|IO$M_BREAKTHRU, &tmp_ttiosb,
  1948.          0, 0, (char *) brkarray, brklen, 0, 0, 0, 0))) return(-1);
  1949.     if (!CHECK_ERR("ttsndb: SETMODE(2)",
  1950.     sys$qiow(QIOW_EFN, ttychn, IO$_SETMODE, &tmp_ttiosb, 0, 0,
  1951.         &ttchr, sizeof(ttchr), wrk_iosb.size, 0, 0, 0))) return(-1);
  1952. #else
  1953.     if (!CHECK_ERR("ttsndb: SENSEMODE",
  1954.     sys$qiow(QIOW_EFN, ttychn, IO$_SENSEMODE, &wrk_iosb, 0, 0,
  1955.         &ttchr, sizeof(ttchr), 0, 0, 0, 0))) return(-1);
  1956.     x = TT$M_BREAK;            /* Break signal on */
  1957.     if (!CHECK_ERR("ttsndb: SETMODE(1)",
  1958.     sys$qiow(QIOW_EFN, ttychn, IO$_SETMODE, &wrk_iosb, 0, 0,
  1959.         &ttchr, sizeof(ttchr), 0, 0, x, 0))) return(-1);
  1960.     msleep(msec);            /* Sleep requested amount of time */
  1961.     x = 0;                /* Break signal off */
  1962.     if (!CHECK_ERR("ttsndb: SETMODE(2)",
  1963.     sys$qiow(QIOW_EFN, ttychn, IO$_SETMODE, &wrk_iosb, 0, 0,
  1964.         &ttchr, sizeof(ttchr), 0, 0, x, 0))) return(-1);
  1965. #endif /* TT$M_BREAK */
  1966.     return(0);
  1967. }
  1968.  
  1969. /*  T T S N D B  --  Send a BREAK signal  */
  1970.  
  1971. int
  1972. ttsndb() {
  1973.     return(sndbrk(275));
  1974. }
  1975.  
  1976. /*  T T S N D L B  --  Send a Long BREAK signal  */
  1977.  
  1978. int
  1979. ttsndlb() {
  1980.     return(sndbrk(1500));
  1981. }
  1982.  
  1983. /*  T T H A N G  --  Hang up the communications line  */
  1984. /*
  1985.   Warning: As written, this function DOES NOT WORK on terminal server
  1986.   ports.  This is a shortcoming of VMS, confirmed by the Digital Diagnostic
  1987.   Center (or whatever DDC stands for).  Someone should add code here to test
  1988.   if the ttychn device is not a real terminal, and if so to handle it some
  1989.   other way, like set the speed to zero for a sec, or close and reopen the
  1990.   device.
  1991. */
  1992. int
  1993. tthang() {
  1994.     if (!xlocal) return(0);        /* Only on local connections. */
  1995.  
  1996. #ifdef NETCONN
  1997.     if (network) {            /* Network connection. */
  1998.     int x;
  1999.     if (netclos() < 0) return(-1);    /* Close it */
  2000.         tvtflg = 0;
  2001.         x = 1;
  2002.     netopen(ttnmsv, &x, ttmdm);    /* Open it again */
  2003.         return(1);
  2004.     }
  2005. #endif /* NETCONN */
  2006.  
  2007.     if (!ttychn) return(0);        /* Not open. */
  2008.  
  2009.     tt_cancel();            /* Cancel pending i/o. */
  2010. /*
  2011.   This is NOT listed in the VMS Terminal Driver as one of the functions
  2012.   that does NOT work with LAT devices.
  2013. */
  2014.     debug(F101,"tthang 1","",gtimer());
  2015.     if (!CHECK_ERR("tthang: sys$qiow",
  2016.     sys$qiow(QIOW_EFN, ttychn, IO$_SETMODE|IO$M_HANGUP, &wrk_iosb, 0, 0,
  2017.         0, 0, 0, 0, 0, 0))) return(-1);
  2018. /*
  2019.   The following 3-second sleep is required because the sys$qiow() returns
  2020.   immediately, about 2.5 seconds before VMS brings DTR back up.  Without this
  2021.   sleep(), DIAL does not work at all if DIAL HANGUP is ON, and, worse,
  2022.   subsequent operations on the device can hang the Kermit process
  2023.   uninterruptibly.
  2024. */
  2025.     sleep(3);
  2026.     debug(F101,"tthang 2","",gtimer());
  2027.     return(1);
  2028. }
  2029.  
  2030. /*  M S L E E P  --  Millisecond version of sleep().  */
  2031.  
  2032. /*
  2033.  Handles intervals up to about 7 minutes (2**32 / 10**7 seconds)
  2034. */
  2035. int
  2036. msleep(m) int m; {
  2037.  
  2038.     struct time_struct {
  2039.     long int hi, lo;
  2040.     } t;
  2041.  
  2042.     if (m <= 0) return(0);
  2043.     t.hi = -10000 * m;  /*  Time in 100-nanosecond units  */
  2044.     t.lo = -1;
  2045.     if (!CHECK_ERR("msleep: sys$schdwk",
  2046.     sys$schdwk(0, 0, &t, 0))) return(-1);
  2047.     sys$hiber();
  2048.     debug(F101,"msleep ok","",m);
  2049.     return(0);
  2050. }
  2051.  
  2052. /*  R T I M E R --  Reset elapsed time counter  */
  2053.  
  2054. VOID
  2055. rtimer() {
  2056.     tcount = time( (TIME_T *) 0);
  2057. }
  2058.  
  2059.  
  2060. /*  G T I M E R --  Get current value of elapsed time counter in seconds  */
  2061.  
  2062. int
  2063. gtimer() {
  2064.     int x;
  2065.     x = (int) (time( (TIME_T *) 0 ) - tcount);
  2066.     return( (x < 0) ? 0 : x );
  2067. }
  2068.  
  2069. /*  Z T I M E  --  Return date/time string  */
  2070.  
  2071. VOID
  2072. ztime(s) char **s; {
  2073.     static TIME_T clock;
  2074. #ifdef COMMENT
  2075. #ifdef bogus
  2076.     static char time_string[24];
  2077.     struct dsc$descriptor_s t =
  2078.     {sizeof(time_string)-1,DSC$K_DTYPE_T,DSC$K_CLASS_S,&time_string};
  2079.  
  2080.     if (!CHECK_ERR("ztime: sys$asctim",
  2081.     sys$asctim(0, &t, 0, 0))) return(-1);
  2082.     time_string[t.dsc$w_length] = '\0';
  2083.     *s = &time_string;
  2084. #else
  2085.     char *asctime();
  2086.     struct tm *tp;
  2087.  
  2088.     time(&clock);
  2089.     tp = localtime(&clock);
  2090.     *s = asctime(tp);
  2091. #endif /* bogus */
  2092. #else /* not COMMENT */
  2093. /*
  2094.  Apparently ctime() is available in old C libraries, even though asctime()
  2095.  is not.  Let's use the same method for all versions.
  2096. */
  2097.     time(&clock);
  2098.     *s = ctime(&clock);
  2099. #endif /* COMMENT */
  2100. }
  2101.  
  2102. /*  C O N G M  --  Get console terminal modes.  */
  2103.  
  2104. /*
  2105.  Saves current console mode, and establishes variables for switching between
  2106.  current (presumably normal) mode and other modes.
  2107. */
  2108. int
  2109. congm() {
  2110.     char s[] = CONDEV_COLON;
  2111.     struct itmlst dviitm[] = { {4,DVI$_DEVCLASS,NULL,0},
  2112.             {0,0,0,0}};
  2113. #ifdef COMMENT /* old */
  2114.     struct dsc$descriptor_s
  2115.       r = {sizeof(s),DSC$K_DTYPE_T,DSC$K_CLASS_S,(char *)&s};
  2116. #else /* from ttj */
  2117.     struct dsc$descriptor_s
  2118.       devnam = {sizeof(s)-1,DSC$K_DTYPE_T,DSC$K_CLASS_S,NULL};
  2119.       devnam.dsc$a_pointer = s;
  2120. #endif /* COMMENT */
  2121.  
  2122.     dviitm[0].adr = (char *)&dviitm[0].adr;
  2123.  
  2124.     debug(F101,"congm cgmf","",cgmf);
  2125.     if (cgmf) return(-1);        /* If called already, then nop */
  2126.  
  2127.     if (!CHECK_ERR("congm: sys$getdviw",
  2128.     sys$getdviw(0, 0, &devnam, &dviitm, &wrk_iosb, 0, 0, 0))) return(-1);
  2129.     debug(F101, "congm: devclass", "", (unsigned long int) dviitm[0].adr);
  2130.     if ((unsigned long int) dviitm[0].adr != DC$_TERM) {
  2131.     batch = 1;
  2132.     }
  2133. #ifdef COMMENT                /* Let's try it anyway... */
  2134.       else {
  2135. #endif /* COMMENT */
  2136.     /*
  2137.        NOTE: Reportedly, when C-Kermit is run from a .COM file
  2138.            it complains "Sorry, terminal type not supported: vt300-80".
  2139.            Reportedly, the cure is to execute the following code always,
  2140.            not just when the if condition above is false; i.e. just get
  2141.            rid of {, } else {, and }.  But some of the following system
  2142.            calls look like they might be dangerous on non-terminals,
  2143.            so widespread testing would be needed.  Better safe than sorry.
  2144.         */
  2145.         debug(F101, "congm: conchn", "", conchn);
  2146.     if (!conchn) {            /* Get console channel */
  2147.         $DESCRIPTOR(sys_input, CONDEV_COLON);
  2148.         conchn = vms_assign_channel(&devnam);
  2149.     }
  2150.     if (!conchn)
  2151.       return(-1);
  2152.         if (!CHECK_ERR("congm: sys$qiow",
  2153.         sys$qiow(QIOW_EFN, conchn, IO$_SENSEMODE, &wrk_iosb, 0, 0,
  2154.                  &ccold, sizeof(ccold), 0, 0, 0, 0))) return(-1);
  2155.         ccraw = cccbrk = ccold;
  2156. #ifdef COMMENT
  2157.     }
  2158. #endif /* COMMENT */
  2159.     cgmf = 1;                /* Flag that we got them. */
  2160.     return(0);
  2161. }
  2162.  
  2163. /*  C O N C B --  Put console in cbreak mode.  */
  2164.  
  2165. /*  Returns 0 if ok, -1 if not  */
  2166.  
  2167. int
  2168. #ifdef CK_ANSIC
  2169. concb(char esc)
  2170. #else
  2171. concb(esc) char esc;
  2172. #endif /* CK_ANSIC */
  2173. /* concb */ {
  2174.     int x;
  2175.  
  2176.     debug(F101,"concb batch","",batch);
  2177.     if (batch) return(0);
  2178.     if (!cgmf) congm();            /* Get modes if necessary. */
  2179.     escchr = esc;            /* Make this available to other fns */
  2180.     ckxech = 1;                /* Program can echo characters */
  2181. /*
  2182.   Note: PASTHRU / PASSALL is what is preventing the Ctrl-C trap in the
  2183.   main program from working.  This business can be removed without any effect
  2184.   at all on the command parser -- everything still works: completion, ?-help,
  2185.   editing, etc.  The only problem is that Ctrl-Y is not trapped, so the
  2186.   program dies and leaves the terminal in no-echo mode.
  2187. */
  2188.     cccbrk.extended |= TT2$M_PASTHRU | TT2$M_ALTYPEAHD;
  2189.     if (parity)
  2190.       cccbrk.basic |= TT$M_NOECHO;
  2191.     else
  2192.       cccbrk.basic |= TT$M_NOECHO | TT$M_EIGHTBIT;
  2193.     cccbrk.basic &= ~TT$M_ESCAPE;    /* Disable escape-seq processing */
  2194.     cccbrk.extended &= ~TT2$M_LOCALECHO; /* and local echoing */
  2195.     if (!CHECK_ERR("concb: sys$qiow",
  2196.     sys$qiow(QIOW_EFN, conchn, IO$_SETMODE, &wrk_iosb, 0, 0,
  2197.                  &cccbrk, sizeof(cccbrk), 0, 0, 0, 0))) return(-1);
  2198.     debug(F100,"concb ok","",0);
  2199.     return(0);
  2200. }
  2201.  
  2202. /*  C O N B I N  --  Put console in binary mode  */
  2203.  
  2204. /*  Returns 0 if ok, -1 if not  */
  2205.  
  2206. int
  2207. #ifdef CK_ANSIC
  2208. conbin(char esc)
  2209. #else
  2210. conbin(esc) char esc;
  2211. #endif /* CK_ANSIC */
  2212. /* conbin */ {
  2213.  
  2214.     debug(F101,"conbin batch","",batch);
  2215.     if (batch) return(0);
  2216.     if (!cgmf) congm();            /* Get modes if necessary. */
  2217.     escchr = esc;            /* Make this available to other fns */
  2218.     ckxech = 1;                /* Program can echo characters */
  2219.     ccraw.extended |= TT2$M_PASTHRU | TT2$M_ALTYPEAHD;
  2220.     ccraw.basic &= ~TT$M_ESCAPE;    /* Disable escape-seq processing */
  2221.     ccraw.extended &= ~TT2$M_LOCALECHO;    /* and local echoing */
  2222.     if (parity)
  2223.       ccraw.basic |= TT$M_NOECHO;
  2224.     else
  2225.       ccraw.basic |= TT$M_NOECHO | TT$M_EIGHTBIT;
  2226. #ifdef COMMENT
  2227.     ccraw.basic &= ~(TT$M_HOSTSYNC | TT$M_TTSYNC);
  2228. #endif /* COMMENT */
  2229.     if (!CHECK_ERR("conbin: sys$qiow",
  2230.     sys$qiow(QIOW_EFN, conchn, IO$_SETMODE, &wrk_iosb, 0, 0,
  2231.                  &ccraw, sizeof(ccraw), 0, 0, 0, 0))) return(-1);
  2232.     return(0);
  2233. }
  2234.  
  2235.  
  2236. /*  C O N R E S  --  Restore the console terminal  */
  2237.  
  2238. int
  2239. conres() {
  2240.     debug(F101,"conres cgmf","",cgmf);
  2241.     if (!cgmf) return(0);        /* Do nothing if modes unknown */
  2242.     if (batch) return(0);
  2243.  
  2244.     msleep(250);
  2245.     ckxech = 0;                /* System should echo chars */
  2246.     if (!CHECK_ERR("conres: sys$qiow",
  2247.     sys$qiow(QIOW_EFN, conchn, IO$_SETMODE, &wrk_iosb, 0, 0,
  2248.     &ccold, sizeof(ccold), 0, 0, 0, 0))) return(-1);
  2249.     debug(F100,"conres ok","",0);
  2250.     return(0);
  2251. }
  2252.  
  2253.  
  2254. /*  C O N R E S N E --  Restore the console terminal with No Echo */
  2255.  
  2256. int
  2257. conresne() {
  2258.     debug(F101,"conresne cgmf","",cgmf);
  2259.     if (!cgmf) return(0);        /* Don't do anything if modes unk */
  2260.     if (batch) return(0);
  2261.  
  2262.     msleep(250);
  2263.     ckxech = 1;                /* Program should echo chars */
  2264.  
  2265.     cctmp = ccold;
  2266.     cctmp.basic |= TT$M_NOECHO;
  2267.     if (!CHECK_ERR("conres: sys$qiow",
  2268.     sys$qiow(QIOW_EFN, conchn, IO$_SETMODE, &wrk_iosb, 0, 0,
  2269.     &cctmp, sizeof(cctmp), 0, 0, 0, 0))) return(-1);
  2270.     debug(F100,"conresne ok","",0);
  2271.     return(0);
  2272. }
  2273.  
  2274. /*  C O N O C  --  Output a character to the console terminal  */
  2275.  
  2276. int
  2277. #ifdef CK_ANSIC
  2278. conoc(char c)
  2279. #else
  2280. conoc(c) char c;
  2281. #endif /* CK_ANSIC */
  2282. /* conoc */ {
  2283.     if (batch) putchar(c);
  2284.     else
  2285.     if (!CHECK_ERR("conoc: sys$qiow",
  2286.         sys$qiow(QIOW_EFN, conchn, IO$_WRITEVBLK|IO$M_BREAKTHRU,
  2287.              &wrk_iosb, 0, 0, &c, 1, 0, 0, 0, 0))) return(-1);
  2288.     return(1);
  2289. }
  2290.  
  2291. /*  C O N X O  --  Write x characters to the console terminal  */
  2292.  
  2293. int
  2294. conxo(x,s) char *s; int x; {
  2295.     if (batch) fprintf(stdout, "%.*s", x, s);
  2296.     else if (!CHECK_ERR("conxo: sys$qiow",
  2297.     sys$qiow(QIOW_EFN, conchn, IO$_WRITEVBLK|IO$M_BREAKTHRU,
  2298.          &wrk_iosb, 0, 0, s, x, 0, 0, 0, 0))) return(-1);
  2299.     return(0);
  2300. }
  2301.  
  2302. /*  C O N O L  --  Write a line to the console terminal  */
  2303.  
  2304. int
  2305. conol(s) char *s; {
  2306.     int len;
  2307.  
  2308.     if (batch) fputs(s, stdout);
  2309.     else {
  2310.     len = strlen(s);
  2311.     if (!CHECK_ERR("conol: sys$qiow",
  2312.         sys$qiow(QIOW_EFN, conchn, IO$_WRITEVBLK|IO$M_BREAKTHRU, &wrk_iosb,
  2313.              0, 0, s, len, 0, 0, 0, 0))) return(-1);
  2314.     }
  2315.     return(1);
  2316. }
  2317.  
  2318. /*  C O N O L A  --  Write an array of lines to console, with CRLFs added */
  2319.  
  2320. int
  2321. conola(s) char *s[]; {
  2322.     int i;
  2323.     char t[100], *cp;
  2324.  
  2325.     for (i=0 ; *s[i] ; i++) {
  2326.     strncpy(t,s[i],100);
  2327.     for (cp = t + strlen(t); --cp >= t;) {
  2328.         if (*cp != '\n' && *cp != '\r') {
  2329.         cp++;
  2330.         *cp++ = '\r'; *cp++ = '\n'; *cp++ = '\0';
  2331.         break;
  2332.         }
  2333.     }
  2334.     if (conol(t) < 0) return(-1);
  2335.     }
  2336.     return(0);
  2337. }
  2338.  
  2339. /*  C O N O L L  --  Output a string followed by CRLF  */
  2340.  
  2341. int
  2342. conoll(s) char *s; {
  2343.     int x;
  2344.     x = conol(s);
  2345.     if (x > -1)
  2346.       x = conol("\r\n");
  2347.     return(x);
  2348. }
  2349.  
  2350.  
  2351. /*  C O N C H K  --  Check if characters available at console  */
  2352.  
  2353. int
  2354. conchk() {
  2355.     struct {
  2356.     unsigned short count;
  2357.     unsigned char first;
  2358.     unsigned char reserved1;
  2359.     long reserved2;
  2360.     } t;
  2361.  
  2362.     if (batch) return(0);
  2363.     return(CHECK_ERR("conchk: sys$qiow",
  2364.     sys$qiow(QIOW_EFN, conchn, IO$_SENSEMODE|IO$M_TYPEAHDCNT, &wrk_iosb,
  2365.          0, 0, &t, sizeof(t), 0, 0, 0, 0)) ? t.count : 0);
  2366. }
  2367.  
  2368. /*  C O N I N C  --  Get a character from the console  */
  2369.  
  2370. int
  2371. coninc(timo) int timo; {        /* Timo > 0 = timeout in seconds. */
  2372.     int n = 0;
  2373.     unsigned char ch;
  2374.     int func, mask;
  2375.  
  2376.     debug(F101,"coninc timo","",timo);
  2377.     debug(F101,"coninc con_queued","",con_queued);
  2378.  
  2379.     if (batch)
  2380.       return(getchar());
  2381.  
  2382.     mask = 1 << CON_EFN;
  2383.  
  2384.     if (con_queued) {        /* If a console read was already posted... */
  2385.                 /* e.g. by contti() ... */
  2386.     if (timo > 0) {                /* If a timeout was specified... */
  2387.         struct { int hi, lo; } qtime;   /* Set a timer... */
  2388.         qtime.hi = -10*1000*1000*timo;  /* in VMS "delta-time" notation. */
  2389. /*
  2390.   If the timo value is big enough to make the delta-time overflow an integer,
  2391.   substitute something useful.
  2392. */  
  2393.         if (qtime.hi > 0)        /* Did it go positive? */
  2394.           qtime.hi = -0x7fffffff;    /* Yes, so fudge it. */
  2395.         qtime.lo = -1;
  2396.         sys$setimr(TIM_EFN, &qtime, 0, 0, 0); /* Specify event flag. */
  2397.         mask |= TIM_EFN;        /* And add it to read mask. */
  2398.     }
  2399.     sys$wflor(CON_EFN, mask);    /* Wait for SETIMR to complete. */
  2400.     sys$readef(CON_EFN, &mask);    /* Read event flags. */
  2401.     if (mask & (1 << CON_EFN)) {    /* We got a console event? */
  2402.         ch = (unsigned char) conch;    /* (see contti() about this...) */
  2403.         CHECK_ERR("coninc: coniosb.status", coniosb.status);
  2404.         con_queued = 0;
  2405.     } else {            /* We didn't */
  2406.         ch = -1;            /* So indicate that coninc() ... */
  2407.         vms_status = SS$_TIMEOUT;    /*  timed out. */
  2408.     }
  2409.     } else {                /* Console read not already posted */
  2410.     func = IO$_READVBLK | IO$M_NOFILTR;
  2411.     if (timo > 0) func |= IO$M_TIMED;
  2412.     CHECK_ERR("coninc: sys$qiow",
  2413.       sys$qiow(QIOW_EFN, conchn, func, &wrk_iosb,0,0,&ch,1,timo,0,0,0));
  2414.     }
  2415.     if (vms_status & 1) {
  2416.     if (wrk_iosb.status == SS$_TIMEOUT)
  2417.       return(-1);
  2418.     else return((ch == '\r') ? '\n' : (unsigned)ch);
  2419.     } else return(-1);
  2420. }
  2421.  
  2422.  
  2423. /*  V M S _ G E T C H A R -- get a character from the console (no echo).
  2424.  *    Since we use raw reads, we must check for ctrl/c, ctrl/y and
  2425.  *    ctrl/z ourselves.  We probably should post a "mailbox" for
  2426.  *    ctrl/c and ctrl/y so the poor user can abort a runaway Kermit.
  2427.  *    Note: this routine intends for ctrl/z (eof) to be "permanent".
  2428.  *    Currently, no kermit routine calls "clearerror".  If this
  2429.  *    changes, the following code must be rewritten.
  2430.  */
  2431.  
  2432. int
  2433. vms_getchar() {
  2434.     register unsigned int ch;
  2435.     static int ateof = 0;
  2436.  
  2437.     if (ateof)
  2438.       return (EOF);
  2439.     ch = coninc(0);
  2440.     switch (ch) {
  2441.       case ('Y' - 64):
  2442.       case ('C' - 64):
  2443. #ifndef COMMENT
  2444. /*
  2445.   Just call the same handler that signal(SIGINT,xxx) would have invoked
  2446.   if Ctrl-C had been trapped.  The pointer to the handler was saved in
  2447.   cctrap by conint().
  2448. */
  2449.     if (cctrap)
  2450.       (*cctrap)(SIGINT,0);
  2451. #else
  2452.     ttclos(ttyfd);            /* Close down other terminal    */
  2453.     conres();            /* And cleanup console modes    */
  2454.     exit(SS$_ABORT);        /* Fatal exit.            */
  2455. #endif /* COMMENT */
  2456.       case ('Z' - 64):
  2457.     ateof = 1;
  2458.     return (EOF);
  2459.  
  2460.       default:
  2461.     return (ch);
  2462.     }
  2463. }
  2464.  
  2465. /*  C O N T T I  --  Get character from console then from tty  */
  2466. /*
  2467.   This is used in conect() when NO_FORK is defined.
  2468.   src is returned with 1 if the character came from the comm. line,
  2469.   0 if it was from the console, and with -1 if there was any error.
  2470. */
  2471. #ifdef TCPIPLIB
  2472. /*
  2473.  * Network/console read posted?
  2474.  */
  2475. static int    nettty_queued    = 0;
  2476. static int    netcon_queued    = 0;
  2477. #endif /* TCPIPLIB */
  2478.  
  2479. int
  2480. contti(c, src) int *c, *src; {
  2481.  
  2482. #ifndef TCPIPLIB
  2483.     int mask = 1<<CON_EFN | 1<<TTY_EFN;
  2484.     int x; unsigned char cc;
  2485.  
  2486. #else /* TCPIPLIB */
  2487.  
  2488. #ifdef CMU_TCPIP
  2489.     int s;                    /* select status */
  2490.     fd_set exceptfds;                /* select exceptions */
  2491.     static struct timeval timeout;        /* for non-blocking select */
  2492. #endif /* CMU_TCPIP */
  2493.  
  2494. #define NET_EFN 7                /* Network event flag */
  2495.  
  2496.     int                mask;        /* Event flag mask */
  2497.  
  2498.     static CHAR            concc;        /* Console and network data */
  2499.     static CHAR            netcc;
  2500.  
  2501.     static struct iosb_struct    net_iosb;
  2502.     static struct iosb_struct    con_iosb;    /* IO status blocks */
  2503.  
  2504. /*
  2505.   Buffered network data, count, next character.  Declared in CKCNET.C ...
  2506. */
  2507.     extern CHAR            ttibuf[];
  2508.     extern int            ttibn;    
  2509.     extern int            ttibp;
  2510. #endif /* TCPIPLIB */
  2511.  
  2512.     *src = -2;
  2513.  
  2514.     debug(F101,"contti: network","",network);
  2515.     debug(F101,"contti: ttyfd","",ttyfd);
  2516.     debug(F101,"contti: ttychn","",ttychn);
  2517.  
  2518.     *src = -1;                /* Assume there was an error */
  2519.  
  2520.     if (network && ttyfd < 0)        /* Make sure we're not called */
  2521.       return(-1);            /* out of context... */
  2522.     if (!network && !ttychn)
  2523.       return(-1);
  2524.  
  2525. #ifdef TCPIPLIB
  2526.     if (network) {            /* For active network connections */
  2527.     debug(F100,"contti: network","",0);
  2528.     debug(F101,"contti: ttibn","",ttibn);
  2529.  
  2530.     if (ttibn > 0) {
  2531.         /*
  2532.          * Handle the case where data remains in our "internal" buffer.
  2533.          * We need to:
  2534.          *
  2535.          *    -- Handle the console keyboard (is a character ready?)
  2536.          *    -- Return one character from the network buffer if not
  2537.          *
  2538.          * Post a new console read if necessary
  2539.          */
  2540.             if (!netcon_queued) {
  2541. #ifdef CMU_TCPIP
  2542.             cmu_stdin_read(IO$_READVBLK, &concc, 1, 0, 0);
  2543. #else
  2544.             debug(F100,"contti: sys$qio conchn 1","",0);
  2545.                 if (!CHECK_ERR("contti: console sys$qio",
  2546.                        sys$qio(CON_EFN, conchn, IO$_READVBLK,
  2547.                            &con_iosb, 0, 0, &concc,
  2548.                            1, 0, 0, 0, 0))) {
  2549.                 debug(F100,"contti: sys$qio conchn 1 fails","",0);
  2550.                 return(*c = -1);
  2551.             }
  2552.             debug(F100,"contti: sys$qio conchn 2","",0);
  2553. #endif /* CMU_TCPIP */
  2554.                     netcon_queued = 1;
  2555.         }
  2556.         /* Console char ready? */
  2557. #ifdef CMU_TCPIP
  2558.         mask = 1;
  2559.         exceptfds = mask;
  2560.         if (select(1, &mask, 0, &exceptfds, &timeout) == 1)
  2561.           if (FD_ISSET(0,&exceptfds))
  2562.             return(*c = -1);
  2563.         netcon_queued = 0;
  2564.         *c   = (unsigned)(concc & 0xff);
  2565.         *src = 0;
  2566.         return(1);
  2567. #else
  2568.                (void) sys$readef(CON_EFN, &mask);
  2569.             if (mask & (1 << CON_EFN)) {
  2570.             netcon_queued = 0;
  2571.             if (!CHECK_ERR("contti: con_iosb.status",
  2572.                    con_iosb.status)) {
  2573.             debug(F100,"contti: con_iosb.status fails","",0);
  2574.             return(*c = -1);
  2575.             }
  2576.             *c = (unsigned)(concc & 0xff);
  2577.             *src = 0;
  2578.             return(1);
  2579.         }
  2580. #endif /* CMU_TCPIP */
  2581.         /*
  2582.          * No console data; return buffered network character
  2583.          */
  2584.         ttibn--;
  2585.         *c   = (unsigned)(ttibuf[ttibp++]);
  2586.         *src = 1;
  2587.         return(1);
  2588.     }
  2589.     /*
  2590.      * No buffered data; post network and console reads
  2591.      */
  2592.     debug(F101,"contti: nettty_queued","",nettty_queued);
  2593.         if (!nettty_queued) {
  2594.  
  2595. /* Another attempt by fdc to catch a broken connection. */
  2596.  
  2597.         int x;
  2598.         x = nettchk();
  2599.         debug(F101,"contti: nettchk","",x);
  2600.         if (x < 0) {
  2601.         return(*src = x);
  2602.         }
  2603. #ifdef CMU_TCPIP 
  2604.  
  2605. /* Network read is always posted */
  2606.  
  2607. #else
  2608.  
  2609. /*     -lt.  1992-09-14  begin */
  2610. /* All the event flag numbers should be obtained using lib$get_ef().
  2611.  * Using hard coded numbers, especially < 31 is tres dangereuse!!!
  2612.  * Be careful, one must also change the event flag cluster used by
  2613.  * sys$readef. It is *not* just a simple matter of changing a few #defines.
  2614.  *
  2615.  * At least for DEC TCP/IP Services, socket calls return a proper file
  2616.  * descriptor (fd).  OpenVMS system services require a channel
  2617.  * (from sys$assign).  The two are *not* the same.  The call vaxc$get_sdc()
  2618.  * maps from a DEC TCP/IP fd to a channel.
  2619.  *
  2620.  * This is "gag me with a spoon" code, but it gets thing up and running.
  2621.  *
  2622.  */
  2623. #ifdef DEC_TCPIP
  2624.  
  2625.         {
  2626.         static int last_ttyfd = -1;
  2627.         static short int net_chan = -1;
  2628.  
  2629.         if (ttyfd != last_ttyfd) {
  2630.             last_ttyfd = ttyfd;
  2631. #ifdef COMMENT
  2632. #ifdef __DECC
  2633.             net_chan = (short) decc$get_sdc(last_ttyfd);
  2634. #else
  2635. #ifdef VAXC
  2636.             net_chan = vaxc$get_sdc(last_ttyfd);
  2637. #else
  2638. # error CALL TO GET_SDC requires DECC or VAXC compiler!
  2639. #endif    /* VAXC */
  2640. #endif    /* DECC */
  2641. #else /* COMMENT */
  2642.             net_chan = GET_SDC(last_ttyfd);
  2643. #endif /* COMMENT */
  2644.             }
  2645.  
  2646.         if (!CHECK_ERR("contti: network sys$qio",
  2647.                    sys$qio(NET_EFN, net_chan, IO$_READVBLK,
  2648.                        &net_iosb, 0, 0,
  2649.                        &netcc, 1, 0, 0, 0, 0))) {
  2650.             debug(F100,"contti: network sys$qio net_chan fails","",0);
  2651.             return(*c = -1);
  2652.         }
  2653.         }
  2654.  
  2655. #else /* Not DEC_TCPIP */
  2656.  
  2657.             if (!CHECK_ERR("contti: network sys$qio",
  2658.                sys$qio(NET_EFN, ttyfd, IO$_READVBLK, &net_iosb,
  2659.                    0, 0, &netcc, 1, 0, 0, 0, 0))) {
  2660.         debug(F100,"contti: network sys$qio ttyfd fails","",0);
  2661.         return(*c = -1);
  2662.         }
  2663. #endif /* DEC_TCPIP */
  2664. #endif /* CMU_TCPIP */
  2665.         nettty_queued = 1;
  2666.     }
  2667.         if (!netcon_queued) {
  2668. #ifdef CMU_TCPIP
  2669.         cmu_stdin_read(IO$_READVBLK, &concc, 1, 0, 0);
  2670. #else
  2671.             if (!CHECK_ERR("contti: console sys$qio",
  2672.                sys$qio(CON_EFN, conchn, IO$_READVBLK, &con_iosb,
  2673.                    0, 0, &concc, 1, 0, 0, 0, 0))) {
  2674.         debug(F100,"contti: console sys$qio fails","",0);
  2675.         return(*c = -1);
  2676.         }
  2677. #endif /* CMU_TCPIP */
  2678.             netcon_queued = 1;
  2679.     }
  2680.     /*
  2681.      * Wait for a character
  2682.      */
  2683. #ifdef CMU_TCPIP
  2684.     exceptfds = mask = (1 | (1<<ttyfd));
  2685.     s = select(ttyfd, &mask, 0, &exceptfds, 0); /*a blocking select*/
  2686.  
  2687.     if (FD_ISSET(0,&exceptfds))
  2688.         return(-1);
  2689.  
  2690.     if (FD_ISSET(ttyfd,&exceptfds))
  2691.         return(-1);
  2692.  
  2693.     if (FD_ISSET(0,&mask)) {
  2694.         *c         = (unsigned)(concc & 0xff);
  2695.         *src       = 0;
  2696.         netcon_queued = 0;
  2697.     } else {
  2698.         if (FD_ISSET(ttyfd,&mask)) {
  2699.         s = cmu_read(ttyfd, &netcc, 1);
  2700.         if (s <= 0)
  2701.             return(-1);
  2702.         *c         = (unsigned)(netcc & 0xff);
  2703.         *src       = 1;
  2704.         nettty_queued = 0;
  2705.         }
  2706.     }
  2707. #else
  2708.         mask = (1 << CON_EFN) | (1 << NET_EFN);
  2709.  
  2710.         if (!CHECK_ERR("contti: sys$wflor", sys$wflor(CON_EFN, mask))) {
  2711.         debug(F100,"contti: sys$wflor fails", "", 0);
  2712.         return(*c = -1);
  2713.     }
  2714.         if (!CHECK_ERR("contti: sys$readef",sys$readef(CON_EFN, &mask))) {
  2715.         debug(F100,"contti: sys$readef fails", "", 0);
  2716.         return(*c = -1);
  2717.     }
  2718.         if (mask & (1 << CON_EFN)) {    /* Console */
  2719.             if (!CHECK_ERR("contti: con_iosb.status", con_iosb.status)) {
  2720.         debug(F100,"contti: con_iosb.status fails","",0);
  2721.         return(-1);
  2722.         }
  2723.             *c = (unsigned)(concc & 0xff);
  2724.         *src = 0;
  2725.             netcon_queued = 0;
  2726.  
  2727.         } else if (mask & (1 << NET_EFN)) { /* Network */
  2728.         if (!(net_iosb.status & 1)) { /* Read error */
  2729. #ifdef WINTCP
  2730. #ifdef OLD_TWG
  2731.         perror("contti: net_iosb.status");
  2732. #else
  2733.         _$set_vaxc_error(SS$_NORMAL, net_iosb.status);
  2734.         win$perror("contti: net_iosb.status");
  2735. #endif /* OLD_TWG */
  2736. #else
  2737. #ifdef MULTINET
  2738. #ifdef COMMENT
  2739. /*
  2740.   When user hangs up, this prints an unnecessary scary message,
  2741.   like "Operation would block."
  2742. */
  2743.         socket_perror("contti: net_iosb.status");
  2744. #endif /* COMMENT */
  2745. #endif /* MULTINET */
  2746. #endif /* WINTCP */
  2747.         debug(F100,"contti: network read error", "", 0);
  2748.         return(*c = -1);
  2749.         }
  2750.         debug(F101,"contti: net_iosb.size","",net_iosb.size);
  2751.         if (net_iosb.size == 0) {    /* Handle reset from remote */
  2752.         debug(F100,"contti: network reset from remote", "", 0);
  2753.         return(*c = -1);
  2754.         }
  2755.         *c = (unsigned)(netcc & 0xff);
  2756.         *src = 1;
  2757.             nettty_queued = 0;
  2758.         }
  2759. #endif /* CMU_TCPIP */
  2760.     } else                /* Not network */
  2761. #endif /* TCPIPLIB */
  2762.  
  2763. /*
  2764.   Should we worry about a network connection that's running under BATCH ?
  2765. */
  2766.     if (batch) {            /* Batch? */
  2767.     debug(F100,"contti batch","",0);
  2768.     if ((*c = getchar()) != EOF) {
  2769.         *src = 0;
  2770.     } else {
  2771.         *src = 1;
  2772.         *c = ttinc(0);
  2773.     }
  2774.     } else {                /* Interactive but not network */
  2775.  
  2776. #ifdef TTXBUF
  2777.     if (ttxbn > 0) {        /* Buffered port chars available */
  2778.  
  2779. /* Post a read on the console if one is not posted already */
  2780.  
  2781.         if (!con_queued) {
  2782.         if (!CHECK_ERR("contti: console sys$qio",
  2783.                  sys$qio(CON_EFN, conchn, IO$_READVBLK,
  2784.                      &coniosb, 0, 0,
  2785.                      &conch, 1, 0, 0, 0, 0)))
  2786.           return(-1);
  2787.         con_queued = 1;
  2788.         }
  2789.  
  2790. /* See if a console character has been read and if so, return it.  */
  2791.  
  2792.         (void) sys$readef(CON_EFN, &mask);
  2793.         if (mask & (1 << CON_EFN)) {
  2794.         con_queued = 0;
  2795.         if (!CHECK_ERR("contti: coniosb.status",
  2796.                    coniosb.status))
  2797.           return(-1);
  2798.         *c   = (unsigned)(conch & 0xff);
  2799.         *src = 0;
  2800.         return(1);
  2801.         }
  2802.  
  2803. /* No console character, so return buffered port character */
  2804.  
  2805.         *c = ttinc(0);
  2806.         *src = 1;
  2807.         return(1);
  2808.     }
  2809.  
  2810. /* No buffered port data; post both network and console reads... */
  2811.  
  2812. #endif /* TTXBUF */
  2813.  
  2814.         mask = 1<<CON_EFN | 1<<TTY_EFN;    /* Event mask */
  2815.  
  2816.     debug(F101,"contti interactive mask","",mask);
  2817.  
  2818.         if (!con_queued) {        /* Console read not queued... */
  2819.             if (!CHECK_ERR("contti: console sys$qio",
  2820.             sys$qio(CON_EFN, conchn, IO$_READVBLK, &coniosb, 0, 0,
  2821.                     &conch, 1, 0, 0, 0, 0))) return(-1);
  2822.         con_queued = 1;
  2823.         debug(F100,"contti con_queued","",0);
  2824.     }
  2825.         if (!tt_queued) {        /* Port read not queued */
  2826.             if (!CHECK_ERR("contti: tty sys$qio",
  2827.             sys$qio(TTY_EFN, ttychn, IO$_READVBLK, &ttiosb, 0, 0,
  2828.                     &ttch, 1, 0, 0, 0, 0))) return(-1);
  2829.         tt_queued = 1;
  2830.         debug(F100,"contti tt_queued","",0);
  2831.     }
  2832.  
  2833. /* Wait for one of the queued reads to complete */
  2834.  
  2835.         if (!CHECK_ERR("contti: sys$wflor",
  2836.             sys$wflor(CON_EFN, mask))) return(-1);
  2837.     debug(F100,"contti sys$wflor ok","",0);
  2838.  
  2839. /* Read the event flags to see which read was completed */
  2840.  
  2841.         if (!CHECK_ERR("contti: sys$readef",
  2842.             sys$readef(CON_EFN, &mask))) return(-1);        
  2843.     debug(F100,"contti sys$readef ok","",0);
  2844.  
  2845.  
  2846. /* Return the character with the appropriate source (src) indicator */
  2847.  
  2848.         if (!(*src = ((mask & 1<<CON_EFN) ? 0 : 1))) {
  2849.             *c = (unsigned)(conch);
  2850.             CHECK_ERR("contti: coniosb.status", coniosb.status);
  2851.             con_queued = 0;
  2852.         } else {
  2853.             *c = (ttprty ? (unsigned)(ttch & 0177) : (unsigned)ttch);
  2854.         if (ttiosb.status == SS$_HANGUP) {
  2855.         fprintf(stderr,"\n%%CKERMIT-F-HANGUP, data set hang-up");
  2856.         *src = -1;
  2857.         return(1);
  2858.         }
  2859.             CHECK_ERR("contti: ttiosb.status", ttiosb.status);
  2860.             tt_queued = 0;
  2861.         }
  2862.         if (!(vms_status & 1)) *src = -1;
  2863.     }
  2864.     debug(F101,"contti *src","",*src);
  2865.     return((*src > -1) ? 1 : 0);
  2866. }
  2867.  
  2868. /*
  2869.   C A N C I O
  2870.   Cancel pending I/O requests on console and communication device.
  2871. */
  2872.  
  2873. int
  2874. ck_cancio() {
  2875.  
  2876.     debug(F101,"ck_cancio: ttyfd","",ttyfd);
  2877.     if (network && ttyfd < 0)
  2878.       return(0);
  2879.     debug(F101,"ck_cancio: ttychn","",ttychn);
  2880.     if (!network && !ttychn)
  2881.       return(0);
  2882. #ifdef NETCONN
  2883.     if (network) {
  2884. #ifdef TCPIPLIB
  2885. #ifdef DEC_TCPIP
  2886.     short int net_chan = -1;
  2887.  
  2888.     net_chan = GET_SDC(ttyfd);
  2889.         if (nettty_queued) (void) sys$cancel(net_chan);
  2890. #else  /* DEC_TCPIP */
  2891. #ifdef CMU_TCPIP
  2892.     /* not going to do this when CMU is the network transport.
  2893.      * the sys$cancel will cause the channel to shutdown
  2894.      *
  2895.      * if (nettty_queued) (void) sys$cancel(cmu_get_sdc(ttyfd));
  2896.      */
  2897. #else  /* !CMU_TCPIP */
  2898.        if (nettty_queued) (void) sys$cancel(ttyfd);
  2899. #endif /* CMU_TCPIP */
  2900. #endif /* DEC_TCPIP */
  2901.         if (netcon_queued) (void) sys$cancel(conchn);
  2902.  
  2903.         netcon_queued = 0;
  2904.         nettty_queued = 0;
  2905.     return(0);
  2906. #else /* Not TCPIPLIB */
  2907.     return(0);
  2908. #endif /* TCPIPLIB */
  2909.     }
  2910. #endif /* NETCONN */
  2911.  
  2912.     if (!batch) {
  2913.         CHECK_ERR("ck_cancio: console sys$cancel",
  2914.             sys$cancel(conchn));
  2915.         CHECK_ERR("ck_cancio: tty sys$cancel",
  2916.             sys$cancel(ttychn));
  2917.         con_queued = 0;
  2918.         tt_queued = 0;
  2919.     }
  2920.     return(0);
  2921. }
  2922.  
  2923. /* get_qio_maxbuf_size()
  2924.  *
  2925.  * Get maximum size of QIO that can occur without getting the dreaded
  2926.  * exceeded quota status.
  2927.  */
  2928.  
  2929. #ifndef SYI$_MAXBUF
  2930. #define SYI$_MAXBUF 4175
  2931. #endif /* SYI$_MAXBUF */
  2932.  
  2933. int
  2934. get_qio_maxbuf_size(ttychn) unsigned long int ttychn; {
  2935.     unsigned char *tmpbuf;
  2936.     int unsigned long max=0;
  2937.     struct itmlst syiitm[] = { {2,SYI$_MAXBUF,NULL,0},
  2938.             {0,0,0,0}};
  2939.  
  2940.     syiitm[0].adr = (char *)&max;
  2941.     
  2942.     if (!ttychn) return(-1);
  2943.  
  2944.     if (!CHECK_ERR("get_qio_maxbuf_size: sys$getsyiw",
  2945.     sys$getsyiw(     0    /* efn */
  2946.             ,0    /* csidadr */
  2947.             ,0    /* nodename */
  2948.             ,&syiitm /* itmlst */
  2949.             ,&wrk_iosb /* iosb */
  2950.             ,0    /* astadr */
  2951.             ,0)))    /* astprm */
  2952.         exit(SS$_ABORT);        /* Fatal exit */
  2953.  
  2954.     if (!(tmpbuf = malloc(max)))
  2955.     return(0);
  2956.  
  2957.     for (; max > 0; max -= 16) {
  2958.     if (!test_qio(ttychn,max,tmpbuf)) /* (was &tmpbuf, caused crash) */
  2959.     {
  2960.         free(tmpbuf);
  2961.         return(max);
  2962.     }
  2963.     }
  2964.  
  2965.     free(tmpbuf);
  2966.     printf("\n%%CKERMIT-F-get_qio_maxbuf_size, Could not get maxbuf size\n");
  2967.     exit(SS$_ABORT);        /* Fatal exit */
  2968. }
  2969.  
  2970. int
  2971. test_qio(ttychn,max,dest)
  2972. unsigned long int ttychn;
  2973. long int max;
  2974. unsigned char *dest;
  2975. {
  2976.     static int trmmsk[2] = {0,0};
  2977.  
  2978. /*    trmmsk[1] = 1 << eol; */
  2979.  
  2980.     vms_status = sys$qiow(QIOW_EFN, ttychn, IO$_READVBLK|IO$M_TIMED,
  2981.               &wrk_iosb, 0, 0, dest, max, 0, &trmmsk, 0, 0);
  2982.     return( !(vms_status & 1) ||
  2983.     (!(wrk_iosb.status & 1)) && wrk_iosb.status != SS$_TIMEOUT);
  2984. }
  2985.  
  2986.  
  2987. /*
  2988.  * Flush tt output buffer
  2989.  */
  2990.  
  2991. int
  2992. ttfluo() {
  2993.  
  2994.     long n=0;
  2995.  
  2996. #ifdef NETCONN
  2997.     if (network) return(0);
  2998. #endif /* NETCONN */
  2999.  
  3000.     if (!ttychn) return(-1);        /* Not open. */
  3001.  
  3002.     if (!CHECK_ERR("ttfluo: sys$qiow",
  3003.     sys$qiow(QIOW_EFN, ttychn, IO$_READVBLK|IO$M_TIMED|IO$M_PURGE,
  3004.          &wrk_iosb, 0, 0, &n, 0, 0, 0, 0, 0))) {
  3005.     perror("flush failed");
  3006.     return(-1);
  3007.     }
  3008.     return(0);
  3009. }
  3010.  
  3011. /*  T T G M D M  --  Get modem signals  */
  3012. /*
  3013.  Looks for the modem signals CTS, DSR, and CTS, and returns those that are
  3014.  on in as its return value, in a bit mask as described for ttwmdm.  Returns:
  3015.  -3 Not implemented
  3016.  -2 if the line does not have modem control
  3017.  -1 on error.
  3018.  >= 0 on success, with a bit mask containing the modem signals that are on.
  3019. */
  3020. int
  3021. ttgmdm() {
  3022.     struct {
  3023.     unsigned char type;
  3024.     unsigned char spare1;
  3025.     unsigned char modem;
  3026.     unsigned char spare2;
  3027.     unsigned long filler;
  3028.     } mdminfo;
  3029.     int retval;
  3030.  
  3031. #ifdef NETCONN
  3032.     if (network) return(-2);
  3033. #endif /* NETCONN */
  3034.     vms_status = sys$qiow(QIOW_EFN, ttychn, IO$_SENSEMODE|IO$M_RD_MODEM,
  3035.               &wrk_iosb, 0, 0, &mdminfo, 0, 0, 0, 0, 0);
  3036.  
  3037.     if (vms_status != SS$_NORMAL) {
  3038.     debug(F101,"ttgmdm serious error, status","",vms_status);
  3039.     return(-1);
  3040.     }
  3041.  
  3042.     debug(F101,"ttgmdm iosb","",wrk_iosb.status);
  3043.     debug(F101,"ttgmdm type","",mdminfo.type);
  3044.     debug(F101,"ttgmdm modem","",mdminfo.modem);
  3045.  
  3046.     if (wrk_iosb.status != SS$_NORMAL) {
  3047.     debug(F101,"ttgmdm iosb error, status","",wrk_iosb.status);
  3048.     return(-1);
  3049.     }
  3050.  
  3051. #ifdef DT$_LAT
  3052.     if (mdminfo.type == DT$_LAT) {
  3053.     debug(F101,"ttgmdm LAT port, no modem control","",0);
  3054.     return(-2);
  3055.     }
  3056. #endif /* DT$_LAT */
  3057.  
  3058.     if (mdminfo.type == 0) {
  3059.     debug(F101,"ttgmdm unknown driver, modem","",mdminfo.modem);
  3060.     return(-2);
  3061.     }
  3062.  
  3063.     retval = BM_DTR | BM_RTS;        /* Not visible, set by TTDRIVER */
  3064.     if (mdminfo.modem & TT$M_DS_CTS)
  3065.     retval |= BM_CTS;
  3066.     if (mdminfo.modem & TT$M_DS_DSR)
  3067.     retval |= BM_DSR;
  3068.     if (mdminfo.modem & TT$M_DS_CARRIER)
  3069.     retval |= BM_DCD;
  3070.     if (mdminfo.modem & TT$M_DS_RING)
  3071.     retval |= BM_RNG;
  3072.     return(retval);
  3073. }
  3074.  
  3075. long
  3076. congspd() {
  3077.     return(conspd);
  3078. }
  3079.  
  3080. /*
  3081.   Return serial communication device speed.  Speed is retreived from a qiow
  3082.   initially.  It is then changed only at user request.  (Yes, but it would
  3083.   still be better to do another qiow here to actually read the speed from the
  3084.   device so we know it is what we think it should be!)
  3085. */
  3086. long
  3087. ttgspd() {
  3088.     extern int speed;
  3089. #ifdef NETCONN
  3090.     if (network) return(-1);        /* -1 if network connection */
  3091. #endif /* NETCONN */
  3092.     return(ttspeed);
  3093. }
  3094.  
  3095. /*  T T S C A R R  --  Set ttcarr variable, controlling carrier handling.
  3096.  *
  3097.  *  0 = Off: Always ignore carrier. E.g. you can connect without carrier.
  3098.  *  1 = On: Heed carrier, except during dialing. Carrier loss gives disconnect.
  3099.  *  2 = Auto: For "modem direct": The same as "Off".
  3100.  *            For real modem types: Heed carrier during connect, but ignore
  3101.  *                it anytime else.  Compatible with pre-5A C-Kermit versions.
  3102.  *
  3103.  * As you can see, this setting does not affect dialing, which always ignores
  3104.  * carrier (unless there is some special exception for some modem type).  It
  3105.  * does affect ttopen() if it is set before ttopen() is used.  This setting
  3106.  * takes effect on the next call to ttopen()/ttpkt()/ttvt().  And they are
  3107.  * (or should be) always called before any communications is tried, which
  3108.  * means that, practically speaking, the effect is immediate.
  3109.  *
  3110.  * Of course, nothing of this applies to remote mode (xlocal = 0).
  3111.  *
  3112.  * Someone has yet to uncover how to manipulate the carrier in the BSD
  3113.  * environment (or any non-termio using environment).  Until that time, this
  3114.  * will simply be a no-op for BSD.
  3115.  *
  3116.  * Note that in previous versions, the carrier was most often left unchanged
  3117.  * in ttpkt()/ttvt() unless they were called with DIALING or CONNECT.  This
  3118.  * has changed.  Now it is controlled by ttcarr in conjunction with these
  3119.  * modes.
  3120.  */
  3121. int
  3122. ttscarr(carrier) int carrier; {
  3123.  
  3124.     return(-1);
  3125. }
  3126.  
  3127. int
  3128. psuspend(x) int x; {
  3129.  
  3130.     return(-1);
  3131. }
  3132.  
  3133. int
  3134. vmsttyfd() {
  3135.     return(network ? ttyfd : ttychn);
  3136. }
  3137.  
  3138. #ifdef CK_CURSES
  3139. /*
  3140.   tgetent() support for VMS curses emulation.
  3141.   Used by all three VMS fullscreen methods.
  3142.   Called from "SET FILE DISPLAY FULLSCREEN" in ckuus7.c.
  3143. */
  3144. int isvt52 = 0;                /* VT52/VT1xx flag */
  3145.  
  3146. int
  3147. tgetent(lp, term) char *lp, *term; {
  3148.     debug(F101,"tgetent terminal type","",ccold.type);
  3149.     debug(F101,"tgetent terminal extended","",ccold.extended);
  3150.  
  3151.     if ((ccold.type == DT$_VT5X) || (ccold.type == DT$_VT55)) {
  3152.     debug(F100,"tgetent VT5x","",0);
  3153.     isvt52 = 1;
  3154.     return(1);
  3155.     }
  3156.     if ((ccold.extended & TT2$M_ANSICRT) == TT2$M_ANSICRT) {
  3157.     debug(F100,"tgetent ANSICRT","",0);
  3158.     isvt52 = 0;
  3159.     return(1);
  3160.     }
  3161.     if ((ccold.extended & TT2$M_DECCRT) == TT2$M_DECCRT) {
  3162.     debug(F100,"tgetent DECCRT","",0);
  3163.     isvt52 = 0;
  3164.     return(1);
  3165.     }
  3166.     return(0);                /* Not a supported terminal type */
  3167. }
  3168. #endif /* CK_CURSES */
  3169.