home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / ckv206.zip / ckvcon.c < prev    next >
C/C++ Source or Header  |  2002-10-30  |  55KB  |  1,729 lines

  1. #ifndef VMS
  2.       ERROR -- CKVCON.C is used only on the OpenVMS(tm) Operating System
  3. #else  /* VMS */
  4. #ifdef MULTINET
  5. #define MULTINET_OLD_STYLE
  6. #endif /* MULTINET */
  7. #endif /* VMS */
  8. #define CONN_OS_ARCH_STRING \
  9.         "CONNECT Command 8.0.058 11 Sep 2002"
  10. #ifdef __ALPHA
  11.          /* do nothing */
  12. #else
  13. # ifdef VAX
  14. # else
  15. #ifndef __GNUC__
  16.       ERROR -- CKVCON.C unknown architecture, neither VAX(tm) nor Alpha
  17. # endif /* __GNUC__ */
  18. # endif /* VAX */
  19. #endif /* __ALPHA */
  20.  
  21. char *connv = CONN_OS_ARCH_STRING;
  22.  
  23. /*  C K V C O N  --  Terminal session to remote system, for VMS  */
  24. /*
  25.   Author: Frank da Cruz <fdc@columbia.edu>,
  26.   Columbia University Academic Information Systems, New York City.
  27.  
  28.   Copyright (C) 1985, 2002,
  29.     Trustees of Columbia University in the City of New York.
  30.     All rights reserved.  See the C-Kermit COPYING.TXT file or the
  31.     copyright text in the ckcmai.c module for disclaimer and permissions.
  32. */
  33. /*
  34.  * Originally adapted from the UNIX C-Kermit CONNECT module by S. Rubenstein
  35.  * for systems without fork(), circa 1985.  This version of conect() uses
  36.  * contti(&c, &src) to return when a character is available from either the
  37.  * console or the communications connection -- kind of like select().
  38.  *
  39.  * Edit Date       By   What
  40.  *
  41.  * 010 06-Mar-1989 mab    General cleanup
  42.  * 011 23-Mar-1989 mab    Clean up doesc() code.  Add malloc() in place of
  43.  *             static buffer space.  Also increase buffer space.
  44.  * 012 27-Sep-1989 mab    Add XON sequence.
  45.  * 013 30-Mar-1991 fdc  Add so/si, character set translation.
  46.  * 014 06-Apr-1991 fdc  Adapted for TGV MultiNet TCP/IP connections.
  47.  * 015 21-Jun-1991 tmk  Cleaned up typo in session logging display.
  48.  * 016 28-Nov-1991 fdc  "Back at <hostname>", disallow CONNECT in background
  49.  * 017 25-Dec-1991 fdc  Added support for NOPUSH, added "Hanging up" message
  50.  * 018 11-Jan-1992 fdc  Added support for key mapping
  51.  * 019 27-Jan-1992 fdc  Added support for ANSI escape sequence recognition
  52.  * 020 00-May-1992 fdc  Rewrote conect() to used buffered i/o.
  53.  * 021 10-Jun-1992 fdc  Added support for Wollongong WIN/TCP from Ray Hunter.
  54.  *                      Fix messed-up help message.
  55.  * 022 20-Jun-1992 fdc  Fixed handling of CR on TELNET sessions.
  56.  * 023 28-Jun-1992 fdc  Cosmetic cleanup of "Connecting..." message.
  57.  * 024 12-Jul-1992 fdc  Added mdmhup() feature (see ckudia.c).
  58.  * 025 29-Jul-1992 fdc  Grouped TELNET IP and AYT into single writes.
  59.  * 026 13-Aug-1992 fdc  Added support for SET TELNET NEWLINE-MODE.
  60.  * 027 05-Sep-1992 lt   Added architecture ifdefs for OpenVMS, Alpha, at top.
  61.  * 028 08-Sep-1992 fdc  Separated input and output SO/SO shift states.
  62.  * 029 11-Oct-1992 fdc  Reduce modem-vs-net confusion in ttopen() calls.
  63.  * 030 27-Oct-1993 fdc  Correct a typo in network protocol-checking code.
  64.  * 031 23-Oct-1993 fdc  Reset i/o buffer pointers upon new connection.
  65.  * 032 14-Feb-1994 fdc  Some minor cleanups.
  66.  * 033  9-Mar-1994 fdc  Fixed failure to display quoted TELNET IAC (255).
  67.  * 034  2-Jul-1994 fdc  Add initial APC support.
  68.  * 035  9-Jul-1994 fdc  Fix APC support.
  69.  * 036 15-Sep-1994 fdc  Add support for SET TELNET NEWLINE RAW.
  70.  * 037 24-Mar-1996 fdc  Add support for nopush and autodownload.
  71.  * 038 11-May-1996 fdc  Add support for SET TERM ESC { ENABLED, DISABLED }
  72.  * 039  5-Jun-1996 fdc  Change H to mean Help rather than Hangup, U = hangUp.
  73.  * 040  6-Jun-1996 fdc  Add Autoupload.
  74.  * 041  6-Sep-1996 fdc  Try to handle parity better.
  75.  * 042  1-Sep-1997 fdc  Add triggers.
  76.  * 043 21-Sep-1997 fdc  Don't send NAK any more if autodownload detected.
  77.  * 044  1-Jan-1998 fdc  Enforce SET CARRIER-WATCH.
  78.  * 045  8-Feb-1998 fdc  In ckcgetc() allow contti() to return nothing.
  79.  * 046 27-Dec-1998 fdc  Remove obsolete references to me_binary.
  80.  * 047  8-Feb-1999 fdc  Allow for -2 and -3 returns from tn_doop().
  81.  * 048 22-Jul-1999 fdc  Fix <escchar>S bug (print buffer sbuf[] too small)
  82.  *                      and added more info to status display.
  83.  * 049 24-Aug-1999 fdc  Add Unicode (UTF-8) support.
  84.  * 050 24-Oct-1999 fdc  Correct #ifdefs for NOCSETS case.
  85.  * 051 30-Oct-1999 fdc  Fix broken escape sequence recognizer.
  86.  * 052  4-Nov-1999 fdc  Keep autodownload trigger to ourselves.
  87.  * 053 15-Nov-1999 fdc  Fix broken escape sequence recognizer again.
  88.  * 054 24-Nov-2000 fdc  Add learned scripts (search for CKLEARN).
  89.  * 055  7-Dec-2000  mb  Fix Multinet/DECC header file conflict.
  90.  * 056  5-May-2001 fdc  Use logchar() for session logging.
  91.  * 057 27-Jun-2001 fdc  Set cx_status to indicate CONNECT status, fix ^\u.
  92.  * 058 11-Sep-2002 fdc  Fix remote charset to local UTF-8 translation.
  93.  */
  94. #include "ckcdeb.h"
  95. #include "ckcasc.h"
  96. #include "ckcker.h"
  97. #include "ckucmd.h"
  98. #include "ckcnet.h"
  99. #include "ckvvms.h"
  100. #ifndef NOCSETS
  101. #include "ckcxla.h"            /* Character set translation */
  102. #endif /* NOCSETS */
  103. #include <stdio.h>
  104. #include <ctype.h>
  105. #include <signal.h>
  106. #include <setjmp.h>
  107.  
  108. #ifdef CKLEARN
  109. #include <time.h>
  110. #endif /* CKLEARN */
  111.  
  112. static int src;                /* Where input character came from */
  113.  
  114. extern long speed;
  115.  
  116. extern int local, escape, duplex, parity, flow, seslog, mdmtyp, batch;
  117. extern int cmask, cmdmsk, debses, sosi, ttyfd, what, quiet, tnlm, hints,
  118.  tt_crd, tn_nlm, tt_escape, itsatty;
  119. extern char ttname[], sesfil[], myhost[];
  120. #ifdef TNCODE
  121. extern int tn_b_nlm;
  122. #endif /* TNCODE */
  123.  
  124. #ifdef CKLEARN
  125. extern FILE * learnfp;
  126. extern int learning;
  127. static ULONG learnt1;
  128. static char learnbuf[LEARNBUFSIZ] = { NUL, NUL };
  129. static int  learnbc = 0;
  130. static int  learnbp = 0;
  131. static int  learnst = 0;
  132. #endif /* CKLEARN */
  133.  
  134. #ifdef CK_TRIGGER
  135. extern char * tt_trigger[], * triggerval;
  136. #endif /* CK_TRIGGER */
  137.  
  138. extern int nopush;            /* Runtime NOPUSH */
  139. extern int cx_status;            /* CONNECT status code */
  140.  
  141. #ifndef NOICP                /* Keyboard mapping */
  142. #ifndef NOSETKEY
  143. extern KEY *keymap;            /* Single-character key map */
  144. extern MACRO *macrotab;            /* Key macro pointer table */
  145. static MACRO kmptr = NULL;        /* Pointer to current key macro */
  146. #endif /* NOSETKEY */
  147. #endif /* NOICP */
  148.  
  149. extern int carrier;            /* CARRIER-WATCH selection */
  150.  
  151. /* Network support */
  152. extern int ttnproto,            /* Virtual terminal protocol */
  153.   network,                /* Network connection active */
  154.   nettype;                /* Network type */
  155.  
  156. static int unicode = 0;
  157.  
  158. #ifndef NOCSETS
  159. #ifdef CK_ANSIC
  160. extern CHAR (*xls[MAXTCSETS+1][MAXFCSETS+1])(CHAR); /* Character set */
  161. extern CHAR (*xlr[MAXTCSETS+1][MAXFCSETS+1])(CHAR); /* translation functions */
  162. static CHAR (*sxo)(CHAR);    /* Local translation functions */
  163. static CHAR (*rxo)(CHAR);    /* for output (sending) terminal chars */
  164. static CHAR (*sxi)(CHAR);    /* and for input (receiving) terminal chars. */
  165. static CHAR (*rxi)(CHAR);
  166. #else
  167. extern CHAR (*xls[MAXTCSETS+1][MAXFCSETS+1])();    /* Character set */
  168. extern CHAR (*xlr[MAXTCSETS+1][MAXFCSETS+1])();    /* translation functions. */
  169. static CHAR (*sxo)();        /* Local translation functions */
  170. static CHAR (*rxo)();        /* for output (sending) terminal chars */
  171. static CHAR (*sxi)();        /* and for input (receiving) terminal chars. */
  172. static CHAR (*rxi)();
  173. #endif /* CK_ANSIC */
  174. extern int language;        /* Current language. */
  175. static int langsv;        /* Remember language */
  176. extern struct csinfo fcsinfo[]; /* File character set info */
  177. extern int tcsr, tcsl;        /* Terminal character sets, remote & local. */
  178. static int tcs;            /* Intermediate (xfer) char set */
  179. static int tcssize = 0;        /* Size of tcs */
  180. #ifdef UNICODE                /* UTF-8 support */
  181. #ifdef CK_ANSIC
  182. extern int (*xl_ufc[MAXFCSETS+1])(USHORT);  /* Unicode to FCS */
  183. extern USHORT (*xl_fcu[MAXFCSETS+1])(CHAR); /* FCS to Unicode */
  184. extern int (*xuf)(USHORT);        /* Translation function UCS to FCS */
  185. extern USHORT (*xfu)(CHAR);        /* Translation function FCS to UCS */
  186. #else
  187. extern int (*xl_ufc[MAXFCSETS+1])();
  188. extern USHORT (*xl_fcu[MAXFCSETS+1])();
  189. extern int (*xuf)();
  190. extern USHORT (*xfu)();
  191. #endif /* CK_ANSIC */
  192. #endif /* UNICODE */
  193. #endif /* NOCSETS */
  194.  
  195. _PROTOTYP( VOID doesc, (unsigned char) );
  196.  
  197. #ifndef NOSHOW
  198. _PROTOTYP( VOID shomdm, (void) );
  199. #endif /* NOSHOW */
  200.  
  201. /* Internal prototypes */
  202. _PROTOTYP( static int ckcputf, (void) );
  203. _PROTOTYP( int conresne, (void) );
  204. _PROTOTYP( int contti, (int *, int*) );
  205.  
  206. #ifdef CK_TRIGGER
  207. _PROTOTYP( int autoexitchk, (CHAR) );
  208. #endif /* CK_TRIGGER */
  209.  
  210. #ifdef CK_APC
  211. extern int apcactive;            /* Application Program Command (APC) */
  212. extern int apcstatus;            /* items ... */
  213. static int apclength = 0;
  214. #ifdef DCMDBUF
  215. extern char *apcbuf;
  216. #else
  217. extern char apcbuf[];
  218. #endif /* DCMDBUF */
  219. static int apcbuflen = APCBUFLEN - 2;
  220. extern int autodl, protocol;        /* Autodownload */
  221. #endif /* CK_APC */
  222.  
  223. int i, active;                /* Variables global to this module */
  224. static char *p;
  225.  
  226. #define OUTXBUFSIZ 15
  227. static CHAR inxbuf[OUTXBUFSIZ+1];    /* Host-to-screen expansion buffer */
  228. static int inxcount = 0;        /* and count */
  229. static CHAR outxbuf[OUTXBUFSIZ+1];    /* Keyboard-to-host expansion buf */
  230. static int outxcount = 0;        /* and count */
  231.  
  232. static int escseq = 0;            /* 1 = Recognizer is active */
  233. static int inesc[2] = { 0, 0 };        /* State of sequence recognizer */
  234. static int oldesc[2] = { -1, -1 };    /* Previous state of recognizer */
  235.  
  236. #ifndef NOESCSEQ
  237. /*
  238.   As of edit 178, the CONNECT command skips past ANSI escape sequences to
  239.   avoid translating the characters within them.  This allows the CONNECT
  240.   command to work correctly with a host that uses a 7-bit ISO 646 national
  241.   character set, in which characters like '[' would normally be translated
  242.   into accented characters, ruining the terminal's interpretation (and
  243.   generation) of escape sequences.
  244.  
  245.   As of edit 190, the CONNECT command responds to APC escape sequences
  246.   (ESC _ text ESC \) if the user SETs TERMINAL APC ON or UNCHECKED, and the
  247.   program was built with CK_APC defined.
  248.  
  249.   Non-ANSI/ISO-compliant escape sequences are not handled.
  250. */
  251.  
  252. /* States for the escape-sequence recognizer. */
  253.  
  254. #define ES_NORMAL 0            /* Normal, not in an escape sequence */
  255. #define ES_GOTESC 1            /* Current character is ESC */
  256. #define ES_ESCSEQ 2            /* Inside an escape sequence */
  257. #define ES_GOTCSI 3            /* Inside a control sequence */
  258. #define ES_STRING 4            /* Inside DCS,OSC,PM, or APC string */
  259. #define ES_TERMIN 5            /* 1st char of string terminator */
  260.  
  261. /*
  262.   ANSI escape sequence handling.  Only the 7-bit form is treated, because
  263.   translation is not a problem in the 8-bit environment, in which all GL
  264.   characters are ASCII and no translation takes place.  So we don't check
  265.   for the 8-bit single-character versions of CSI, DCS, OSC, APC, or ST.
  266.   Here is the ANSI sequence recognizer state table, followed by the code
  267.   that implements it.
  268.  
  269.   Definitions:
  270.     CAN = Cancel                       01/08         Ctrl-X
  271.     SUB = Substitute                   01/10         Ctrl-Z
  272.     DCS = Device Control Sequence      01/11 05/00   ESC P
  273.     CSI = Control Sequence Introducer  01/11 05/11   ESC [
  274.     ST  = String Terminator            01/11 05/12   ESC \
  275.     OSC = Operating System Command     01/11 05/13   ESC ]
  276.     PM  = Privacy Message              01/11 05/14   ESC ^
  277.     APC = Application Program Command  01/11 05/15   ESC _
  278.  
  279.   ANSI escape sequence recognizer:
  280.  
  281.     State    Input  New State  ; Commentary
  282.  
  283.     NORMAL   (start)           ; Start in NORMAL state
  284.  
  285.     (any)    CAN    NORMAL     ; ^X cancels
  286.     (any)    SUB    NORMAL     ; ^Z cancels
  287.  
  288.     NORMAL   ESC    GOTESC     ; Begin escape sequence
  289.     NORMAL   other             ; NORMAL control or graphic character
  290.  
  291.     GOTESC   ESC               ; Start again
  292.     GOTESC   [      GOTCSI     ; CSI
  293.     GOTESC   P      STRING     ; DCS introducer, consume through ST
  294.     GOTESC   ]      STRING     ; OSC introducer, consume through ST
  295.     GOTESC   ^      STRING     ; PM  introducer, consume through ST
  296.     GOTESC   _      STRING     ; APC introducer, consume through ST
  297.     GOTESC   0..~   NORMAL     ; 03/00 through 17/14 = Final character
  298.     GOTESC   other  ESCSEQ     ; Intermediate or ignored control character
  299.  
  300.     ESCSEQ   ESC    GOTESC     ; Start again
  301.     ESCSEQ   0..~   NORMAL     ; 03/00 through 17/14 = Final character
  302.     ESCSEQ   other             ; Intermediate or ignored control character
  303.  
  304.     GOTCSI   ESC    GOTESC     ; Start again
  305.     GOTCSI   @..~   NORMAL     ; 04/00 through 17/14 = Final character
  306.     GOTCSI   other             ; Intermediate char or ignored control char
  307.  
  308.     STRING   ESC    TERMIN     ; Maybe have ST
  309.     STRING   other             ; Consume all else
  310.  
  311.     TERMIN   \      NORMAL     ; End of string
  312.     TERMIN   other  STRING     ; Still in string
  313. */
  314. /*
  315.   C H K A E S  --  Check ANSI Escape Sequence.
  316.  
  317.   Call with EACH character in input stream.
  318.   src = 0 means c is incoming from remote; 1 = char from keyboard.
  319.   Sets global inesc[src] variable according to escape sequence state.
  320.   Returns 0 normally, 1 if an APC sequence is to be executed.
  321.   Handles transparent printing internally.
  322. */
  323. int
  324. #ifdef CK_ANSIC
  325. chkaes(char c, int src)
  326. #else
  327. chkaes(c,src) char c; int src;
  328. #endif /* CK_ANSIC */
  329. /* chkaes */ {
  330.  
  331.     debug(F111,"chkaes entry inesc",ckitoa(src),inesc[src]);
  332.     debug(F101,"chkaes c","",c);
  333.  
  334.     if (src < 0 || src > 1)        /* Don't allow bad args. */
  335.       return(0);
  336.  
  337.     oldesc[src] = inesc[src];        /* Remember previous state */
  338.  
  339. #ifdef XPRINT
  340.     if (inesc[src] && !src) {        /* Save up escape seq for printing  */
  341.     if (!c) return(0);        /* Ignore NULs */
  342.     if (escbufc < ESCBUFLEN) {
  343.         escbuf[escbufc++] = c;
  344.         escbuf[escbufc] = NUL;
  345.         debug(F111,"ESCBUF 1",escbuf,escbufc);
  346.     } else {            /* Buffer overrun */
  347.         if (printing && escbufc)    /* Print what's there so far */
  348.           zsoutx(ZMFILE,escbuf,escbufc);
  349.         escbufc = 1;        /* clear it out */
  350.         escbuf[0] = c;        /* and start off fresh buffer */
  351.         escbuf[1] = NUL;        /* with this character. */
  352.     }
  353.     }
  354. #endif /* XPRINT */
  355.  
  356.     if (c == CAN || c == SUB) {        /* CAN and SUB cancel any sequence */
  357. #ifdef XPRINT
  358.     if (!src) {
  359.         if (printing && escbufc > 1)
  360.           zsoutx(ZMFILE,escbuf,escbufc-1);
  361.         escbufc = 0;        /* Clear buffer */
  362.         escbuf[0] = NUL;
  363.     }
  364. #endif /* XPRINT */
  365.     inesc[src] = ES_NORMAL;
  366.     } else                /* Otherwise */
  367.  
  368.       switch (inesc[src]) {        /* enter state switcher */
  369.     case ES_NORMAL:            /* NORMAL state */
  370.       if (c == ESC) {        /* Got an ESC */
  371.           inesc[src] = ES_GOTESC;    /* Change state to GOTESC */
  372. #ifdef XPRINT
  373.           if (!src) {
  374.           escbufc = 1;        /* Clear escape sequence buffer */
  375.           escbuf[0] = c;    /* and deposit the ESC */
  376.           escbuf[1] = NUL;
  377.           debug(F111,"ESCBUF 2",escbuf,escbufc);
  378.           }
  379. #endif /* XPRINT */
  380.       }
  381.       break;            /* Otherwise stay in NORMAL state */
  382.  
  383.     case ES_GOTESC:            /* GOTESC state - prev char was ESC*/
  384.       if (c == '[') {        /* Left bracket after ESC is CSI */
  385.           inesc[src] = ES_GOTCSI;    /* Change to GOTCSI state */
  386.       } else if (c == 'P' || (c > 0134 && c < 0140)) { /* P, ], ^, or _ */
  387.           inesc[src] = ES_STRING;    /* Switch to STRING-absorption state */
  388. #ifdef XPRINT
  389.           debug(F111,"ESCBUF STRING",escbuf,escbufc);
  390. #endif /* XPRINT */
  391. #ifdef CK_APC
  392.           /* If APC not disabled */
  393.           if (!src && c == '_' && apcstatus != APC_OFF) {
  394.           debug(F100,"CONNECT APC begin","",0);
  395.           apcactive = APC_REMOTE; /* Set APC-Active flag */
  396.           apclength = 0;    /* and reset APC buffer pointer */
  397.           }
  398. #endif /* CK_APC */
  399.       } else if (c > 057 && c < 0177) { /* Final character '0' thru '~' */
  400.           inesc[src] = ES_NORMAL;    /* Back to normal */
  401. #ifdef XPRINT
  402.           if (!src) {
  403.           if (printing & escbufc > 1) {
  404.               /* Dump esc seq buf to printer */
  405.               zsoutx(ZMFILE,escbuf,escbufc-1);
  406.               debug(F111,"ESCBUF PRINT 1",escbuf,escbufc);
  407.           }
  408.           escbufc = 0;        /* Clear parameter buffer */
  409.           escbuf[0] = NUL;
  410.           }
  411. #endif /* XPRINT */
  412.       } else if (c != ESC) {    /* ESC in an escape sequence... */
  413.           inesc[src] = ES_ESCSEQ;    /* starts a new escape sequence */
  414.       }
  415.       break;            /* Intermediate or ignored ctrl char */
  416.  
  417.     case ES_ESCSEQ:            /* ESCSEQ -- in an escape sequence */
  418.       if (c > 057 && c < 0177) {    /* Final character '0' thru '~' */
  419.           inesc[src] = ES_NORMAL;    /* Return to NORMAL state. */
  420. #ifdef XPRINT
  421.           if (!src) {
  422.           if (printing && escbufc > 1) {
  423.               zsoutx(ZMFILE,escbuf,escbufc-1);
  424.               debug(F111,"ESCBUF PRINT 2",escbuf,escbufc);
  425.           }
  426.           escbufc = 0;        /* Clear escseq buffer */
  427.           escbuf[0] = NUL;
  428.           }
  429. #endif /* XPRINT */
  430.       } else if (c == ESC) {    /* ESC ... */
  431.           inesc[src] = ES_GOTESC;    /* starts a new escape sequence */
  432.       }
  433.       break;            /* Intermediate or ignored ctrl char */
  434.  
  435.     case ES_GOTCSI:            /* GOTCSI -- In a control sequence */
  436.       if (c > 077 && c < 0177) {    /* Final character '@' thru '~' */
  437. #ifdef XPRINT
  438.           if (!src && tt_print) {    /* Printer enabled? */
  439.           if (c == 'i') {    /* Final char is "i"? */
  440.               char * p = (char *) (escbuf + escbufc - 4);
  441.               if (!strncmp(p, "\033[5i", 4)) /* Yes, turn printer on */
  442.             printon();
  443.               else if (!strncmp(p, "\033[4i", 4)) { /* Or off... */
  444.               int i;
  445.               printoff();    /* Turn off printer. */
  446.               for (i = 0; i < escbufc; i++)    /* And output the */
  447.                 ckcputc(escbuf[i]);         /* sequence. */
  448.               } else if (printing && escbufc > 1) {
  449.               zsoutx(ZMFILE,escbuf,escbufc-1);
  450.               debug(F111,"ESCBUF PRINT 3",escbuf,escbufc);
  451.               }
  452.           } else if (printing && escbufc > 1) {
  453.               zsoutx(ZMFILE,escbuf,escbufc-1);
  454.               debug(F111,"ESCBUF PRINT 4",escbuf,escbufc);
  455.           }
  456.           }
  457.           if (!src) {
  458.           escbufc = 0;        /* Clear esc sequence buffer */
  459.           escbuf[0] = NUL;
  460.           }
  461. #endif /* XPRINT */
  462.           inesc[src] = ES_NORMAL;    /* Return to NORMAL. */
  463.       } else if (c == ESC) {    /* ESC ... */
  464.           inesc[src] = ES_GOTESC;    /* starts over. */
  465.       }
  466.       break;
  467.  
  468.     case ES_STRING:            /* Inside a string */
  469.       if (c == ESC)            /* ESC may be 1st char of terminator */
  470.         inesc[src] = ES_TERMIN;    /* Go see. */
  471. #ifdef CK_APC
  472.       else if (apcactive) {        /* If in APC */
  473.           if (apclength < apcbuflen) { /* and there is room... */
  474.           apcbuf[apclength++] = c; /* deposit this character. */
  475.           } else {            /* Buffer overrun */
  476.           apcactive = 0;    /* Discard what we got */
  477.           apclength = 0;    /* and go back to normal */
  478.           apcbuf[0] = 0;    /* Not pretty, but what else */
  479.           inesc[src] = ES_NORMAL; /* can we do?  (ST might not come) */
  480.           }
  481.       }
  482. #endif /* CK_APC */
  483.       break;            /* Absorb all other characters. */
  484.  
  485.     case ES_TERMIN:            /* Maybe a string terminator */
  486.       if (c == '\\') {        /* which must be backslash */
  487.           inesc[src] = ES_NORMAL;    /* If so, back to NORMAL */
  488. #ifdef XPRINT
  489.           if (!src) {
  490.           if (printing && escbufc > 1) { /* If printing... */
  491.               /* Print esc seq buffer */
  492.               zsoutx(ZMFILE,escbuf,escbufc-1);
  493.               debug(F111,"ESCBUF PRINT 5",escbuf,escbufc);
  494.           }
  495.           escbufc = 0;        /* Clear escseq buffer */
  496.           escbuf[0] = NUL;
  497.           }
  498. #endif /* XPRINT */
  499. #ifdef CK_APC
  500.           if (!src && apcactive) {    /* If it was an APC string, */
  501.           debug(F101,"CONNECT APC terminated","",c);
  502.           apcbuf[apclength] = NUL; /* terminate it and then ... */
  503.           return(1);
  504.           }
  505. #endif /* CK_APC */
  506.       } else {            /* It's not a backslash so... */
  507.           inesc[src] = ES_STRING;    /* back to string absorption. */
  508. #ifdef CK_APC
  509.           if (apcactive) {        /* In APC string */
  510.           if (apclength+1 < apcbuflen) { /* If enough room */
  511.               apcbuf[apclength++] = ESC; /* deposit the Esc */
  512.               apcbuf[apclength++] = c;   /* and this character too. */
  513.           } else {        /* Buffer overrun */
  514.               apcactive = 0;
  515.               apclength = 0;
  516.               apcbuf[0] = 0;
  517.               inesc[src] = ES_NORMAL;
  518.           }
  519.           }
  520. #endif /* CK_APC */
  521.       }
  522.       }    /* switch() */
  523.     debug(F111,"chkaes exit inesc",ckitoa(src),inesc[src]);
  524.     return(0);
  525. }
  526. #endif /* NOESCSEQ */
  527.  
  528. static char *ibp;            /* Input buffer pointer */
  529. static int ibc;                /* Input buffer count */
  530. #define IBUFL 1024            /* Input buffer length */
  531.  
  532. static char *obp;            /* Output buffer pointer */
  533. static int obc;                /* Output buffer count */
  534. #define OBUFL 1024            /* Output buffer length */
  535.  
  536. #ifdef DYNAMIC
  537. static char *ibuf = NULL, *obuf = NULL;    /* Line and temp buffers */
  538. #else
  539. static char ibuf[IBUFL], obuf[OBUFL];
  540. #endif /* DYNAMIC */
  541.  
  542. char kbuf[10], *kbp;            /* Keyboard buffer */
  543.  
  544. #ifdef CKLEARN
  545. static VOID
  546. learnchar(c) int c; {            /* Learned script keyboard character */
  547.     int cc;
  548.     char xbuf[8];
  549.  
  550.     if (!learning || !learnfp)
  551.       return;
  552.  
  553.     switch (learnst) {            /* Learn state... */
  554.       case 0:                /* Neutral */
  555.       case 1:                /* Net */
  556.     if (learnbc > 0) {        /* Have net characters? */
  557.         char buf[LEARNBUFSIZ];
  558.         int i, j, n;
  559.         ULONG t;
  560.  
  561.         t = (ULONG) time(0);    /* Calculate INPUT timeout */
  562.         j = t - learnt1;
  563.         j += (j / 4) > 0 ? (j / 4) : 1; /* Add some slop */
  564.         if (j < 2) j = 2;            /* 2 seconds minimum */
  565.  
  566.         fputs("\nINPUT ",learnfp);    /* Give INPUT command for them */
  567.         fputs(ckitoa(j),learnfp);
  568.         fputs(" {",learnfp);
  569.         learnt1 = t;
  570.  
  571.         n = LEARNBUFSIZ;
  572.         if (learnbc < LEARNBUFSIZ) {  /* Circular buffer */
  573.         n = learnbc;          /*  hasn't wrapped yet. */
  574.         learnbp = 0;
  575.         }
  576.         j = 0;            /* Copy to linear buffer */
  577.         for (i = 0; i < n; i++) {    /* Number of chars in circular buf */
  578.  
  579.         cc = learnbuf[(learnbp + i) % LEARNBUFSIZ];
  580.  
  581.         /* Later account for prompts that end with a newline? */
  582.  
  583.         if (cc == CR && j > 0) {
  584.             if (buf[j-1] != LF)
  585.               j = 0;
  586.         }
  587.         buf[j++] = cc;
  588.         }
  589.         for (i = 0; i < j; i++) {    /* Now copy out the buffer */
  590.         cc = buf[i];        /* interpreting control chars */
  591.         if (cc == 0) {        /* We don't INPUT NULs */
  592.             continue;
  593.         } else if (cc < SP ||    /* Controls need quoting */
  594.                cc > 126 && cc < 160) {
  595.             ckmakmsg(xbuf,8,"\\{",ckitoa((int)cc),"}",NULL);
  596.             fputs(xbuf,learnfp);
  597.         } else {        /* Plain character */
  598.             putc(cc,learnfp);
  599.         }
  600.         }                  
  601.         fputs("}\nIF FAIL STOP 1 INPUT timeout",learnfp);
  602.         learnbc = 0;
  603.     }
  604.     learnbp = 0;
  605.     fputs("\nPAUSE 1\nOUTPUT ",learnfp); /* Emit OUTPUT and fall thru */
  606.  
  607.       case 2:                /* Already in Keyboard state */
  608.     if (c == 0) {
  609.         fputs("\\N",learnfp);
  610.     } else if (c == -7) {
  611.         fputs("\\B",learnfp);
  612.     } else if (c == -8) {
  613.         fputs("\\L",learnfp);
  614.     } else if (c < SP || c > 126 && c < 160) {
  615.         ckmakmsg(xbuf,8,"\\{",ckitoa((int)c),"}",NULL);
  616.         fputs(xbuf,learnfp);
  617.     } else {
  618.         putc(c,learnfp);
  619.     }
  620.     }
  621. }
  622. #endif /* CKLEARN */
  623.  
  624. /*  C O N E C T  --  Perform terminal connection  */
  625.  
  626. int inshift, outshift;            /* SO/SI shift states */
  627.  
  628. /*  C K C P U T C  --  C-Kermit CONNECT Put Character to Screen  */
  629. /*
  630.   Output is buffered to avoid slow screen writes on fast connections.
  631. */
  632. int
  633. ckcputf() {                /* Dump the output buffer */
  634.     int x;
  635.     if (obc > 0)            /* If we have any characters, */
  636.       x = conxo(obc,obuf);        /* dump them, */
  637.     obp = obuf;                /* reset the pointer */
  638.     obc = 0;                /* and the counter. */
  639.     return(x);                /* Return conxo's return code */
  640. }
  641.  
  642. int
  643. ckcputc(c) int c; {
  644.     int x;
  645.  
  646.     *obp++ = c & 0xff;            /* Deposit the character */
  647.     obc++;                /* Count it */
  648.     if (ibc == 0 ||            /* If input buffer empty */
  649.     obc == OBUFL) {            /* or output buffer full */
  650.     x = conxo(obc,obuf);        /* dump the buffer, */
  651.     obp = obuf;            /* reset the pointer */
  652.     obc = 0;            /* and the counter. */
  653.     return(x);            /* Return conxo's return code */
  654.     } else return(0);
  655. }
  656.  
  657. /*  C K C G E T C  --  C-Kermit CONNECT Get Character  */
  658. /*
  659.   Buffered read from communication device.
  660.   Returns the next character, refilling the buffer if necessary.
  661.   On error, returns ttinc's return code (see ttinc() description).
  662.   Dummy argument for compatible calling conventions with ttinc().
  663.   NOTE: We don't have a macro for this because we have to pass
  664.   a pointer to this function as an argument to tn_doop().
  665. */
  666. int
  667. ckcgetc(dummy) int dummy; {
  668.     int c, i, n;
  669.  
  670.     if (ibc > 0) {            /* Have buffered port characters */
  671.     src = 1;            /* Say source is port */
  672.     c = *ibp++ & 0xff;        /* Get next character */
  673.     ibc--;                /* Reduce input buffer count */
  674. #ifdef COMMENT
  675. /* This makes the debug log really big. */
  676.     debug(F101,"CKCGETC buffered port char","",c);
  677. #endif /* COMMENT */
  678.     return(c);            /* Return buffered port character */
  679.     } else {                /* Need to refill buffer */
  680.     for (i = 10; i >= 0; i--) {    /* Try 10 times... */
  681.         contti(&c, &src);        /* to read one character */
  682.         if (src == -1) {        /* Connection dropped */
  683.         return(src);        /* Have to give up */
  684.         } else if (src == -2) {    /* HANGUP with CARRIER-WATCH OFF */
  685.         msleep(i*10);        /* and no character arrived */
  686.         debug(F101,"CKCGETC -2 countdown","",i);
  687.         continue;        /* Try so many times */
  688.         } else
  689.           break;
  690.     }
  691.     if (src < 0) {            /* Give up after too many tries */
  692.         debug(F100,"CKCGETC -2 gives up","",0);
  693.         return(-1);
  694.     }
  695.     if (src == 0) {            /* Got a character from the keyboard */
  696.         debug(F101,"CKCGETC keyboard char","",c);
  697.         return(c);
  698.     } else {            /* Got a port character */
  699.         ibp = ibuf;            /* Reset buffer pointer */
  700.         *ibp++ = c;            /* Deposit the character */
  701.         ibc++;            /* and count it */
  702. /*
  703.   Quickly read any more characters that might have arrived.  Ignore any errors
  704.   here; we need to return all the characters that arrived.  When we run out,
  705.   contti() will catch the error and return it.
  706. */
  707.         if ((n = ttchk()) > 0) {    /* Any more characters waiting? */
  708.         if (n > (IBUFL - ibc))    /* Get them all at once. */
  709.           n = IBUFL - ibc;    /* Don't overflow the buffer */
  710.         if ((n = ttxin(n,(CHAR *)ibp)) > 0) /* Read waiting chars */
  711.           ibc += n;        /* Advance counter */
  712.         }
  713.         ibp = ibuf;            /* Reset buffer pointer again */
  714.         c = *ibp++ & 0xff;        /* Get first character from buffer */
  715.         ibc--;            /* Reduce buffer count */
  716.         debug(F101,"CKCGETC port char","",c);
  717.         return(c);            /* Return the character */
  718.     }
  719.     }
  720. }
  721.  
  722. int
  723. conect() {
  724.     int c;            /* c is a character, but must be signed
  725.                    integer to pass thru -1, which is the
  726.                    modem disconnection signal, and is
  727.                    different from the character 0377 */
  728.     int c2, csave;        /* Copies of c */
  729.     char errmsg[50], *erp, *cp;
  730.     int n, x;                /* Workers */
  731.     int msgflg = 0;            /* Whether to print messages */
  732.     int apcrc;
  733.     int rc = 0;
  734. #ifdef CKLEARN
  735.     int crflag = 0;
  736. #endif /* CKLEARN */
  737.  
  738. #ifdef CK_TRIGGER
  739.     int ix;
  740. #endif /* CK_TRIGGER */
  741.  
  742.     cx_status = CSX_INTERNAL;
  743.     debok = 1;
  744.  
  745.     if (!local) {
  746. #ifdef NETCONN
  747.     printf("Sorry, you must SET LINE or SET HOST first\n");
  748. #else
  749.     printf("Sorry, you must SET LINE first\n");
  750. #endif /* NETCONN */
  751.     return(-2);
  752.     }
  753.     if (batch) {
  754.     printf("\n\
  755. Sorry, Kermit's CONNECT command requires a real terminal;\n");
  756.     printf("It can't be used in a batch job.\n");
  757.     printf("Use INPUT and OUTPUT commands instead.\n");
  758.     return(0);
  759.     } else if (!itsatty) {
  760.     printf("\n\
  761. Sorry, Kermit's CONNECT command can be used only on a real terminal.\n");
  762.     printf(
  763. "If you have started Kermit from a DCL command procedure, it needs:\n\n");
  764.     printf("$ DEFINE /USER SYS$INPUT SYS$COMMAND\n\n");
  765.     printf("before starting Kermit.\n\n");
  766.     return(0);
  767.     }
  768. #ifdef TCPSOCKET
  769.     if (network && (nettype != NET_TCPB)) {
  770.     printf("Sorry, network type not supported yet\n");
  771.     return(0);
  772.     }
  773. #endif /* TCPSOCKET */
  774.  
  775.     debug(F101,"ckvcon network","",network);
  776.     debug(F101,"ckvcon speed","",speed);
  777.     debug(F101,"ckvcon ttyfd","",ttyfd);
  778.     debug(F110,"ckvcon host",ttname,0);
  779. #ifdef CK_TRIGGER
  780.     debug(F110,"ckvcon trigger",tt_trigger[0],0);
  781. #endif /* CK_TRIGGER */
  782.  
  783.     if (speed < 0 && network == 0) {
  784.     printf("Sorry, you must SET SPEED first\n");
  785.     return(-2);
  786.     }
  787.     if ((escape < 0) || (escape > 0177)) {
  788.     printf("Your escape character is not ASCII - %d\n",escape);
  789.     return(-2);
  790.     }
  791.     if (ttyfd < 0) {            /* If communication device not open */
  792.     debug(F111,"ckvcon opening",ttname,0); /* Open it now. */
  793.     if (ttopen(ttname,
  794.            &local,
  795.            network ? -nettype : mdmtyp,
  796.            0
  797.            ) < 0) {
  798.         erp = errmsg;
  799.         sprintf(erp,"Sorry, can't open %s",ttname);
  800.         perror(errmsg);
  801.         debug(F110,"ckvcon open failure",errmsg,0);
  802.         return(-2);
  803.     }
  804. #ifdef IKS_OPTION
  805.     /* If peer is in Kermit server mode, return now. */
  806.     if (TELOPT_SB(TELOPT_KERMIT).kermit.u_start) {
  807.         cx_status = CSX_IKSD;
  808.         return(0);
  809.     }
  810. #endif /* IKS_OPTION */
  811.     }
  812.     msgflg = !quiet
  813. #ifdef CK_APC
  814.       && !apcactive
  815. #endif /* CK_APC */
  816.     ;
  817.  
  818.     if (msgflg) {
  819. #ifdef NETCONN
  820.     if (network) {
  821.         printf("\nConnecting to host %s",ttname);
  822.     } else {
  823. #endif /* NETCONN */
  824.         printf("\nConnecting to %s",ttname);
  825.         if (speed > -1L) printf(", speed %ld",speed);
  826. #ifdef NETCONN
  827.     }
  828. #endif /* NETCONN */
  829.     if (tt_escape) {
  830.         printf("\r\n");
  831.         shoesc(escape);
  832.         printf("Type the escape character followed by C to get back,\r\n");
  833.         printf("or followed by ? to see other options.\r\n");
  834.     } else {
  835.         printf(".\r\n\nESCAPE CHARACTER IS DISABLED\r\n\n");
  836.     }
  837.     if (seslog) {
  838.         extern int slogts, sessft;
  839.         char * s = "";
  840.         switch (sessft) {
  841.           case XYFT_D:
  842.         s = "debug"; break;
  843.           case XYFT_T:
  844.         s = slogts ? "timestamped-text" : "text"; break;
  845.           default:
  846.         s = "binary";
  847.         }
  848.         printf("Session Log: %s, %s\r\n",sesfil,s);
  849.     }
  850.     if (debses) printf("Debugging Display...)\r\n");
  851.         printf("----------------------------------------------------\r\n");
  852.     printf("\r\n");
  853.     }
  854.  
  855. /* Condition console terminal and communication line */
  856.  
  857.     rc = 0;
  858.     if (conbin(escape) < 0) {
  859.     printf("Sorry, can't condition console terminal\n");
  860.         printf("----------------------------------------------------\r\n");
  861.     goto conret0;
  862.     }
  863.     debug(F101,"ckvcon flow","",flow);
  864.     if (ttvt(speed,flow) < 0) {
  865.     /* tthang(); */ /* Closing it should be quite enough! */
  866.     ttclos(0);
  867.     if (ttopen(ttname,        /* Open it again... */
  868.            &local,
  869.            network ? -nettype : mdmtyp,
  870.            0
  871.            ) < 0) {
  872.         erp = errmsg;
  873.         sprintf(erp,"Sorry, can't reopen %s",ttname);
  874.         perror(errmsg);
  875.         goto conret0;
  876.     }
  877. #ifdef IKS_OPTION
  878.     if (TELOPT_SB(TELOPT_KERMIT).kermit.u_start) {
  879.         cx_status = CSX_IKSD;
  880.         goto conret0;
  881.     }
  882. #endif /* IKS_OPTION */
  883.     if (ttvt(speed,flow) < 0) {    /* Try virtual terminal mode again. */
  884.         conres();            /* Failure this time is fatal. */
  885.         printf("Sorry, Can't condition communication line\n");
  886.         goto conret0;
  887.     }
  888.     }
  889.     debug(F101,"CONNECT ttvt ok, escape","",escape);
  890.  
  891.     debug(F101,"CONNECT carrier-watch","",carrier);
  892.     if (!network && (carrier != CAR_OFF)) {
  893.     int x;
  894.     x = ttgmdm();
  895.     debug(F100,"CONNECT ttgmdm","",x);
  896.     if ((x > -1) && !(x & BM_DCD)) {
  897.         debug(F100,"CONNECT ttgmdm CD test fails","",x);
  898.         conres();
  899.         printf("?Carrier required but not detected.\n");
  900.         rc = 0;
  901.         if (hints) {
  902.         printf("***********************************\n");
  903.         printf(" Hint: To CONNECT to a serial device that\n");
  904.         printf(" is not presenting the Carrier Detect signal,\n");
  905.         printf(" first tell C-Kermit to:\n\n");
  906.         printf("   SET CARRIER-WATCH OFF\n\n");
  907.         printf("***********************************\n\n");
  908.         }
  909.         cx_status = CSX_CARRIER;
  910.         goto conret0;
  911.     }
  912.     debug(F100,"CONNECT ttgmdm ok","",0);
  913.     }
  914.  
  915. #ifdef CK_APC
  916.     apcactive = 0;
  917.     apclength = 0;
  918. #endif /* CK_APC */
  919.  
  920. #ifndef NOCSETS
  921. /* Set up character set translations */
  922.  
  923.     unicode = 0;            /* Assume Unicode won't be involved */
  924.     tcs = 0;                /* "Transfer" or "Other" charset */
  925.     sxo = rxo = NULL;            /* Initialize byte-to-byte functions */
  926.     sxi = rxi = NULL;
  927.     if (tcsr != tcsl) {            /* Remote and local sets differ... */
  928. #ifdef UNICODE
  929.     if (tcsr == FC_UTF8 ||        /* Remote charset is UTF-8 */
  930.         tcsl == FC_UTF8) {        /* or local one is. */
  931.         xuf = xl_ufc[tcsl];        /* Incoming Unicode to local */
  932.         if (xuf || tcsl == FC_UTF8) {
  933.         tcs = (tcsr == FC_UTF8) ? tcsl : tcsr; /* The "other" set */
  934.         xfu = xl_fcu[tcs];    /* Local byte to remote Unicode */
  935.         if (xfu)
  936.           unicode = (tcsr == FC_UTF8) ? 1 : 2;
  937.         }
  938.         tcssize = fcsinfo[tcs].size; /* Size of other character set. */
  939.     } else {
  940. #endif /* UNICODE */
  941.         tcs = gettcs(tcsr,tcsl);    /* Get intermediate set. */
  942.         sxo = xls[tcs][tcsl];    /* translation function */
  943.         rxo = xlr[tcs][tcsr];    /* pointers for output functions */
  944.         sxi = xls[tcs][tcsr];    /* and for input functions. */
  945.         rxi = xlr[tcs][tcsl];
  946. #ifdef UNICODE
  947.     }
  948. #endif /* UNICODE */
  949.     }
  950. /*
  951.   This is to prevent use of zmstuff() and zdstuff() by translation functions.
  952.   They only work with disk i/o, not with communication i/o.  Luckily Russian
  953.   translation functions don't do any stuffing...
  954. */
  955.     langsv = language;
  956. #ifndef NOCYRIL
  957.     if (language != L_RUSSIAN)
  958. #endif /* NOCYRIL */
  959.       language = L_USASCII;
  960.  
  961. #ifndef NOESCSEQ
  962. /*
  963.   We need to activate escape-sequence recognition when:
  964.   (a) translation is elected, and:
  965.   (b) the local and/or remote set is 7-bit set other than US or UK ASCII, or:
  966.   (c) TERMINAL APC is not OFF.
  967. */
  968.     escseq = (tcs != TC_TRANSP) &&    /* Not transparent */
  969.       (fcsinfo[tcsl].size == 128 || fcsinfo[tcsr].size == 128) && /* 7 bits */
  970.     (fcsinfo[tcsl].code != FC_USASCII) && /* Not US ASCII */
  971.     (fcsinfo[tcsl].code != FC_UKASCII);   /* Not UK ASCII */
  972. #ifdef COMMENT
  973.     debug(F101,"tcs","",tcs);
  974.     debug(F101,"tcsl","",tcsl);
  975.     debug(F101,"tcsr","",tcsr);
  976.     debug(F101,"fcsinfo[tcsl].size","",fcsinfo[tcsl].size);
  977.     debug(F101,"fcsinfo[tcsr].size","",fcsinfo[tcsr].size);
  978. #endif /* COMMENT */
  979. #endif /* NOESCSEQ */
  980. #endif /* NOCSETS */
  981.  
  982. #ifndef NOESCSEQ
  983. #ifdef CK_APC
  984.     escseq = escseq || (apcstatus != APC_OFF);
  985.     apcactive = 0;            /* An APC command is not active */
  986.     apclength = 0;            /* ... */
  987. #endif /* CK_APC */
  988.     inesc[0] = ES_NORMAL;        /* Initial state of recognizer */
  989.     inesc[1] = ES_NORMAL;
  990.     debug(F101,"CONNECT escseq","",escseq);
  991. #endif /* NOESCSEQ */
  992.  
  993.     rc = 0;
  994. #ifdef DYNAMIC
  995.     if (!ibuf) {
  996.     if (!(ibuf = malloc(IBUFL+1))) { /* Allocate input line buffer */
  997.         printf("Sorry, CONNECT input buffer can't be allocated\n");
  998.         goto conret0;
  999.     } else {
  1000.         ibp = ibuf;
  1001.         ibc = 0;
  1002.     }
  1003.     }
  1004.     if (!obuf) {
  1005.     if (!(obuf = malloc(OBUFL+1))) {    /* Allocate output line buffer */
  1006.         printf("Sorry, CONNECT output buffer can't be allocated\n");
  1007.         goto conret0;
  1008.     } else {
  1009.         obp = obuf;
  1010.         obc = 0;
  1011.     }
  1012.     }
  1013. #else
  1014.     ibp = ibuf;
  1015.     ibc = 0;
  1016.     obp = obuf;
  1017.     obc = 0;
  1018. #endif /* DYNAMIC */
  1019.  
  1020. #ifdef CKLEARN
  1021.     if (learning) {            /* Learned script active... */
  1022.     learnbp = 0;            /* INPUT buffer pointer */
  1023.     learnbc = 0;            /* INPUT buffer count */
  1024.     learnst = 0;            /* State (0 = neutral, none) */
  1025.     learnt1 = (ULONG) time(0);
  1026.     }
  1027. #endif /* CKLEARN */
  1028.  
  1029.     inshift = outshift = 0;        /* Initial SI/SO states */
  1030.     active = 1;
  1031.  
  1032.     debug(F100,"CONNECT starting contti loop","",0);
  1033.     do {                /* Top of big loop */
  1034. #ifndef NOSETKEY
  1035. /*
  1036.   Before reading anything from the keyboard, continue expanding the current
  1037.   active keyboard macro, if any.
  1038. */
  1039.     if (kmptr) {            /* Have active macro */
  1040.         src = 0;            /* Pretend char came from keyboard */
  1041.         if ((c = (CHAR) *kmptr++) == NUL) { /* but get it from the macro */
  1042.         kmptr = NULL;        /* If no more chars in macro,  */
  1043.         continue;        /* reset pointer and continue. */
  1044.         }
  1045.     } else                 /* OTHERWISE... */
  1046. #endif /* NOSETKEY */
  1047. /*
  1048.   contti() samples the keyboard and the communication device, in that order,
  1049.   in what amounts to a busy loop, and does not return until it has something
  1050.   from one or the other.  This drives the VAX crazy, and also gives poor
  1051.   performance: input is character-at a time, and the keyboard buffer is
  1052.   checked at least once for every character that comes in from the remote.
  1053.   Somebody who knows something about VMS, PLEASE FIND A BETTER WAY.
  1054.  
  1055.   We want a version of contti() that does what select() does in BSD, and we
  1056.   also want it to be buffered internally, so it doesn't have to call the
  1057.   operating system for every single input character.  And most of all we don't
  1058.   want it to run a busy loop all the time.  No doubt this involves ASTs,
  1059.   things of which I know nothing.    - fdc
  1060. */
  1061.     c = ckcgetc(0);            /* Calls contti()... */
  1062.     debug(F000,"CKCGETC","",c);
  1063. /*
  1064.   Get here with a character in c, and:
  1065.  
  1066.   src = -1 Communication error
  1067.          1 Character from comm line
  1068.          0 Character from console
  1069. */
  1070.     if (src < 0) {            /* Comm line hangup or other error */
  1071.         ckcputf();            /* flush screen-output buffer */
  1072.         if (msgflg)
  1073.           printf("\r\nCommunications disconnect ");
  1074.         ttclos(0);            /* Close our end of the connection */
  1075.         if (cx_status != CSX_USERDISC)
  1076.           cx_status = CSX_HOSTDISC;
  1077.         active = 0;
  1078.  
  1079.     } else if (!src) {        /* Character from console */
  1080.         c &= cmdmsk;        /* Do requested masking */
  1081. #ifndef NOICP
  1082. #ifndef NOSETKEY
  1083. /*
  1084.   Note: kmptr is NULL if we got character c from the keyboard, and it is
  1085.   not NULL if it came from a macro.  In the latter case, we must avoid
  1086.   expanding it again.
  1087. */
  1088.         if (!kmptr && macrotab[c]) { /* If a macro is assigned to it */
  1089.         kmptr = macrotab[c];    /* set up the pointer */
  1090.         continue;        /* and do this again. */
  1091.         } else c = keymap[c];    /* Else use single-char keymap */
  1092. #endif /* NOSETKEY */
  1093. #endif /* NOICP */
  1094.         csave = c;
  1095. #ifdef CKLEARN
  1096.         crflag = (c == CR);        /* Remember if it was CR. */
  1097. #endif /* CKLEARN */
  1098.  
  1099.         if (
  1100. #ifndef NOICP
  1101. #ifndef NOSETKEY
  1102.             !kmptr &&
  1103. #endif /* NOSETKEY */
  1104. #endif /* NOICP */
  1105.         (tt_escape && (c & 0xff) == escape)) { /* Escape character? */
  1106.         conresne();        /* Restore to normal attributes */
  1107.         c = coninc(0) & 0177;
  1108.         doesc(c);
  1109.         conbin(escape);
  1110.         } else {            /* Ordinary character */
  1111. #ifndef NOCSETS
  1112.         if (inesc[1] == ES_NORMAL) { /* If not inside escape seq.. */
  1113. #ifdef UNICODE                /* Translate character sets */
  1114.             int x;
  1115.             CHAR ch;
  1116.             ch = c;
  1117.             if (unicode == 1) {    /* Remote is UTF-8 */
  1118.             outxcount = b_to_u(ch,outxbuf,OUTXBUFSIZ,tcssize);
  1119.             outxbuf[outxcount] = NUL;
  1120.             } else if (unicode == 2) { /* Local is UTF-8 */
  1121.             x = u_to_b(ch);    /* So translate to remote byte */
  1122.             if (x < 0)
  1123.               continue;
  1124.             outxbuf[0] = (unsigned)(x & 0xff);
  1125.             outxcount = 1;
  1126.             outxbuf[outxcount] = NUL;
  1127.             } else {
  1128. #endif /* UNICODE */
  1129.             if (sxo) c = (*sxo)((char)c); /* Local-intermediate */
  1130.             if (rxo) c = (*rxo)((char)c); /* Intermediate-remote */
  1131.             outxbuf[0] = c;
  1132.             outxcount = 1;
  1133.             outxbuf[outxcount] = NUL;
  1134. #ifdef UNICODE
  1135.             }
  1136. #endif /* UNICODE */
  1137.         } else {
  1138.             outxbuf[0] = c;
  1139.             outxcount = 1;
  1140.             outxbuf[outxcount] = NUL;
  1141.         }
  1142.         if (escseq)
  1143.           apcrc = chkaes((char)c,1);
  1144. #else  /* NOCSETS */
  1145.         outxbuf[0] = c;
  1146.         outxcount = 1;
  1147.         outxbuf[outxcount] = NUL;
  1148. #endif /* NOCSETS */
  1149.  
  1150.         for (i = 0; i < outxcount; i++) {
  1151.             c = outxbuf[i];
  1152. /*
  1153.   If Shift-In/Shift-Out is selected and we have a 7-bit connection,
  1154.   handle shifting here.
  1155. */
  1156.             if (sosi) {             /* Shift-In/Out selected? */
  1157.             if (cmask == 0177) { /* In 7-bit environment? */
  1158.                 if (c & 0200) { /* 8-bit character? */
  1159.                 if (outshift == 0) { /* If not shifted, */
  1160.                     if (ttoc(dopar(SO)) < 0) { /* shift. */
  1161.                     ckcputf();
  1162.                     cx_status = CSX_INTERNAL;
  1163.                     active = 0;
  1164.                     continue;
  1165.                     }
  1166.                     outshift = 1;
  1167.                 }
  1168.                 } else {
  1169.                 if (outshift == 1) { /* 7-bit character */
  1170.                     if (ttoc(dopar(SI)) < 0) {
  1171.                     ckcputf();
  1172.                     cx_status = CSX_INTERNAL;
  1173.                     active = 0;
  1174.                     continue;
  1175.                     }
  1176.                     outshift = 0; /* unshift. */
  1177.                 }
  1178.                 }
  1179.             }
  1180.             if (c == SO) outshift = 1; /* User typed SO */
  1181.             if (c == SI) outshift = 0; /* User typed SI */
  1182.             }
  1183.             c &= cmask;        /* Apply Kermit-to-host mask now. */
  1184.             if (c == '\015') {    /* Carriage Return */
  1185.             int stuff = -1;
  1186.             if (tnlm) {    /* TERMINAL NEWLINE ON */
  1187.                 stuff = LF;    /* Stuff LF */
  1188. #ifdef TNCODE
  1189.             } else if (network &&    /* TELNET NEWLINE ON/OFF/RAW */
  1190.                    (ttnproto == NP_TELNET)) {
  1191.                 switch(!TELOPT_ME(TELOPT_BINARY) ?
  1192.                    tn_nlm :
  1193.                    tn_b_nlm
  1194.                    ) {
  1195.                   case TNL_CRLF:
  1196.                 stuff = LF;
  1197.                 break;
  1198.                   case TNL_CRNUL:
  1199.                 stuff = NUL;
  1200.                 break;
  1201.                 }
  1202. #endif /* TNCODE */
  1203.             }
  1204.             if (stuff > -1) {
  1205.                 ttoc(dopar('\015')); /* Send CR */
  1206.                 if (duplex) conoc('\015'); /* Maybe echo CR */
  1207.                 c = stuff;    /* Char to stuff */
  1208.                 csave = c;
  1209.             }
  1210.             }
  1211. #ifdef TNCODE
  1212. /* If user types the 0xff character (TELNET IAC), it must be doubled. */
  1213.             else
  1214.               if (dopar(c) == IAC &&
  1215.               network &&
  1216.               ttnproto == NP_TELNET
  1217.               ) {        /* Send one copy now */
  1218.               ttoc(IAC);    /* and the other one just below. */
  1219.               }
  1220. #endif /* TNCODE */
  1221.             if (ttoc(dopar(c)) < 0) { /* Now send the character. */
  1222.             ckcputf();
  1223.             cx_status = CSX_INTERNAL;
  1224.             active = 0;
  1225.             continue;
  1226.             }
  1227. #ifdef CKLEARN
  1228.             if (learning) {    /* Learned script active */
  1229.             if (crflag) {
  1230.                 learnchar(CR);
  1231.                 learnst = 0;
  1232.             } else {
  1233.                 learnchar(c);
  1234.                 learnst = 2; /* Change state to keyboard */
  1235.             }
  1236.             }
  1237. #endif /* CKLEARN */
  1238.             if (duplex) {    /* Half duplex? */
  1239.             if (debses)    /* Yes, echo locally */
  1240.               conol(dbchr(csave)); /* in appropriate mode */
  1241.             else
  1242.               conoc(csave);
  1243.             if (seslog) logchar(c); /* And maybe log it. */
  1244.             }
  1245.         } /* for... */
  1246.         }
  1247.     } else {
  1248. /*
  1249.   Character from communications device or network connection...
  1250. */
  1251. #ifdef TNCODE
  1252.         /* Handle telnet options */
  1253.         if (network && ttnproto == NP_TELNET && ((c & 0xff) == IAC)) {
  1254.         ckcputf();        /* Dump output buffer */
  1255.         if ((x = tn_doop(c & 0xff, duplex, ckcgetc)) == -1 && msgflg)
  1256.           printf("\r\nCommunications disconnect ");
  1257.         if (x == -2 && msgflg)
  1258.           printf("\r\nConnection closed by peer ");
  1259.         if (x == -3 && msgflg)
  1260.           printf("\r\nConnection closed due to Telnet policy ");
  1261.         if (x == 1) duplex = 1;    /* Change duplex if necessary. */
  1262.         if (x == 2) duplex = 0;
  1263.         if (x == 3)        /* Quoted IAC */
  1264.           c = parity ? 127 : 255;
  1265. #ifdef IKS_OPTION
  1266.                 else if (x == 4) {    /* IKS State Change */
  1267.                     if (TELOPT_SB(TELOPT_KERMIT).kermit.u_start &&
  1268.             !tcp_incoming
  1269.             ) {
  1270.             cx_status = CSX_IKSD;
  1271.             active = 0;
  1272.             break;
  1273.                     }
  1274.                 }
  1275. #endif /* IKS_OPTION */
  1276.         else
  1277.           continue;
  1278.         } else if (parity)        /* NOW strip parity */
  1279.           c &= 0x7f;
  1280.  
  1281. #ifdef CKLEARN
  1282.         if (learning && learnst != 2) {
  1283.         learnbuf[learnbp++] = c;
  1284.         if (learnbp >= LEARNBUFSIZ)
  1285.           learnbp = 0;
  1286.         learnbc++;
  1287.         learnst = 1;
  1288.         }
  1289. #endif /* CKLEARN */
  1290.  
  1291. #endif /* TNCODE */
  1292.         if (debses) {        /* Output character to screen */
  1293.         char *s;        /* Debugging display... */
  1294.         s = dbchr(c);
  1295.         while (*s)
  1296.           ckcputc(*s++);
  1297.         } else {            /* or regular... */
  1298.         int k;
  1299.         c &= cmask;        /* Do first masking */
  1300. #ifdef CK_APC
  1301.         if (autodl && (k = kstart((CHAR)c))) { /* Saw S/I packet? */
  1302.             extern CHAR mystch, seol;
  1303.             extern int justone;
  1304.             CHAR buf[6];
  1305.             int ksign = 0;
  1306.             if (k < 0) {
  1307.             ksign = 1;
  1308.             k = 0 - k;
  1309.             justone = 1;
  1310.             } else {
  1311.             justone = 0;
  1312.             }
  1313.             if (k == PROTO_K
  1314. #ifdef CK_XYZ
  1315.             || k == PROTO_Z
  1316. #endif /* CK_XYZ */
  1317.             ) {
  1318.             /* Damage the packet so that it doesn't trigger */
  1319.             /* autodownload detection downstream. */
  1320.             if (k == PROTO_K) {
  1321.                 extern CHAR ksbuf[];
  1322.                 int i, len = strlen((char*)ksbuf);
  1323.                 for (i = 0; i < len; i++)
  1324.                   ckcputc(BS);
  1325.             }
  1326. #ifdef CK_XYZ
  1327.             else {
  1328.                 int i;
  1329.                 for (i = 0; i < 3; i++)
  1330.                   ckcputc(CAN);
  1331.             }
  1332. #endif /* CK_XYZ */
  1333.             }
  1334.             switch (protocol) { /* Stuff RECEIVE into APC buffer */
  1335.               case PROTO_K:
  1336.             strcpy(apcbuf, ksign ? "server" : "receive");
  1337.             break;
  1338. #ifdef CK_XYZ
  1339.               case PROTO_G:
  1340.             strcpy(apcbuf,
  1341.                    "set proto kermit, receive, set proto g");
  1342.             break;
  1343.               case PROTO_X:
  1344.             strcpy(apcbuf,
  1345.                    "set proto kermit, receive, set proto x");
  1346.             break;
  1347.               case PROTO_Y:
  1348.             strcpy(apcbuf,
  1349.                    "set proto kermit, receive, set proto y");
  1350.             break;
  1351.               case PROTO_Z:
  1352.             strcpy(apcbuf,
  1353.                    "set proto kermit, receive, set proto z");
  1354.             break;
  1355. #endif /* CK_XYZ */
  1356.             }
  1357.             apclength = strlen(apcbuf) ;
  1358.             debug(F110,"autodownload",apcbuf,0);
  1359.             apcactive = APC_LOCAL;
  1360.             ckcputf();        /* flush screen-output buffer and... */
  1361. #ifdef COMMENT
  1362.             printf("\r\n");    /* prevent CR-overstriking and...    */
  1363. #endif /* COMMENT */
  1364.             cx_status = CSX_APC;
  1365.             active = 0;        /* exit from the terminal emulator.. */
  1366.             break;
  1367.         }
  1368. #endif /* CK_APC */
  1369.         if (sosi) {        /* Handle SI/SO */
  1370.             if (c == SO) {    /* Shift Out */
  1371.             inshift = 1;
  1372.             continue;
  1373.             } else if (c == SI) { /* Shift In */
  1374.             inshift = 0;
  1375.             continue;
  1376.             }
  1377.             if (inshift) c |= 0200;
  1378.         }
  1379.         inxbuf[0] = c;        /* In case there is no translation */
  1380.         inxcount = 1;
  1381. #ifndef NOCSETS
  1382.         if (inesc[0] == ES_NORMAL) { /* If not in an escape sequence */
  1383. #ifdef UNICODE
  1384.             if (unicode == 1) {    /* Remote is UTF-8 */
  1385.             int x;
  1386.             x = u_to_b((CHAR)c);
  1387.             if (x == -1)
  1388.               continue;
  1389.             else if (x == -2) { /* LS or PS */
  1390.                 inxbuf[0] = CR;
  1391.                 inxbuf[1] = LF;
  1392.                 inxcount = 2;
  1393.             } else {
  1394.                 inxbuf[0] = (unsigned)(x & 0xff);
  1395.             }
  1396.             c = inxbuf[0];
  1397.             } else if (unicode == 2) { /* Local is UTF-8 */
  1398.             inxcount = b_to_u((CHAR)c,inxbuf,OUTXBUFSIZ,tcssize);
  1399.             c = inxbuf[0];
  1400.             } else {
  1401. #endif /* UNICODE */
  1402.             if (sxi) c = (*sxi)((CHAR)c);
  1403.             if (rxi) c = (*rxi)((CHAR)c);
  1404.             inxbuf[0] = c;
  1405. #ifdef UNICODE
  1406.             }
  1407. #endif /* UNICODE */
  1408.         }
  1409. #endif /* NOCSETS */
  1410.  
  1411. #ifndef NOESCSEQ
  1412.         if (escseq)        /* If handling escape sequences */
  1413.           chkaes((char)c,0);    /* update our state */
  1414. #ifdef CK_APC
  1415. /*
  1416.   If we are handling APCs, we have several possibilities at this point:
  1417.    1. Ordinary character to be written to the screen.
  1418.    2. An Esc; we can't write it because it might be the beginning of an APC.
  1419.    3. The character following an Esc, in which case we write Esc, then char,
  1420.       but only if we have not just entered an APC sequence.
  1421. */
  1422.         if (escseq && apcstatus != APC_OFF) {
  1423.             if (inesc[0] == ES_GOTESC) { /* Don't write ESC yet */
  1424.             debug(F100,"XXX SKIPPING ESC","",0);
  1425.             continue;
  1426.             } else if (oldesc[0] == ES_GOTESC && !apcactive) {
  1427.             debug(F100,"XXX WRITING ESC","",0);
  1428.             ckcputc(ESC);    /* Write saved ESC */
  1429.             if (seslog) logchar(ESC); /* And maybe log it. */
  1430.             }
  1431.         }
  1432. #endif /* CK_APC */
  1433. #endif /* NOESCSEQ */
  1434.  
  1435.         for (i = 0; i < inxcount; i++) { /* Loop thru */
  1436.             c = inxbuf[i];    /* input expansion buffer... */
  1437.             if (
  1438. #ifdef CK_APC
  1439.             !apcactive
  1440. #else
  1441.             1
  1442. #endif /* CK_APC */
  1443.             ) {
  1444.             c &= cmdmsk;    /* Apply mask */
  1445.             if (c == CR && tt_crd) { /* SET TERM CR-DISPLA CRLF? */
  1446.                 ckcputc(c);    /* Yes, output CR */
  1447.                 if (seslog) logchar(c);
  1448.                 c = LF;    /* and insert a linefeed */
  1449.             }
  1450.             ckcputc(c);    /* Put it on the screen. */
  1451.             }
  1452.             if (seslog) logchar(c); /* If logging, log it. */
  1453. #ifdef CK_TRIGGER
  1454.             /* Check for trigger string */
  1455.             if (tt_trigger[0]) if ((ix = autoexitchk((CHAR)c)) > -1) {
  1456.             int n;
  1457.             ckcputf();    /* Flush screen-output buffer */
  1458.             if (triggerval)    /* Make a copy of the trigger */
  1459.               free(triggerval);
  1460.             triggerval = NULL;
  1461.             n = strlen(tt_trigger[ix]);
  1462.             if (triggerval = (char *)malloc(n+1))
  1463.               strcpy(triggerval,tt_trigger[ix]);
  1464.             debug(F110,"CONNECT triggerval",triggerval,0);
  1465.             cx_status = CSX_TRIGGER;
  1466.             active = 0;
  1467.             }
  1468. #endif /* CK_TRIGGER */
  1469.         } /* for... */
  1470.         }
  1471.     }
  1472.     } while (active);
  1473.     rc = 1;
  1474.  
  1475.   conret0:
  1476.     ck_cancio();
  1477.     conres();
  1478.  
  1479. #ifdef CKLEARN
  1480.     if (learning && learnfp)
  1481.       fputs("\n",learnfp);
  1482. #endif /* CKLEARN */
  1483.  
  1484.     if (msgflg
  1485. #ifdef CK_APC
  1486.     && !apcactive
  1487. #endif /* CK_APC */
  1488.     )
  1489.       printf("(Back at %s)", *myhost ? myhost : "local VMS system");
  1490.     what = W_NOTHING;
  1491. #ifdef CK_APC
  1492.     if (!apcactive)
  1493. #endif /* CK_APC */
  1494.       printf("\n");
  1495. #ifndef NOCSETS
  1496.     language = langsv;            /* Restore language */
  1497. #endif /* NOCSETS */
  1498.     if (msgflg) {
  1499. #ifdef CK_APC
  1500.     if (apcactive == APC_LOCAL)
  1501.       printf("\n");
  1502. #endif /* CK_APC */
  1503.     printf("----------------------------------------------------\r\n");
  1504.     }
  1505.     return(rc);
  1506. }
  1507.  
  1508. /*  H C O N N E  --  Give help message for connect.  */
  1509.  
  1510. VOID
  1511. hconne() {
  1512.     int c;
  1513.     static char *hlpmsg[] = {
  1514. "\n",
  1515. "  C to return to C-Kermit prompt,   U to hangup and close the connection,\n",
  1516. "  B to send a BREAK,                L to send a Long BREAK,\n",
  1517. #ifdef TNCODE
  1518. "  A to send TELNET Are You There,   I to send TELNET Interrupt,\n",
  1519. #endif /* TNCODE */
  1520. "  0 (zero) to send a null,          X to send an XON,\n",
  1521. #ifdef NOPUSH
  1522. "  S for status of connection,       ? for this message, or:\n",
  1523. #else
  1524. "  @ to enter DCL,                   S for status of connection,\n",
  1525. "  ? for this message, or:\n",
  1526. #endif /* NOPUSH */
  1527. "  \\ to begin a backslash escape:\n",
  1528. "    \\nnn  (decimal character code)\n",
  1529. "    \\Onnn (octal character code)\n",
  1530. "    \\Xhh  (hexadecimal character code)\n",
  1531. "    Terminate with carriage return.\n\n",
  1532. " Type the escape character again to send the escape character, or\n",
  1533. " press the space-bar to resume the CONNECT command.\n",
  1534. "----------------------------------------------------\n\n",
  1535. "" };
  1536. /*
  1537.   Need to save term characteristics/ allow disable binary mode
  1538.   print message, get text and then restore previous state.
  1539. */
  1540.     conoll("\r\n----------------------------------------------------");
  1541.     conol("\r\nPress C to return to ");
  1542.     conol(*myhost ? myhost : "the C-Kermit prompt");
  1543.     conoll(", or:");
  1544.     conola(hlpmsg);            /* Print the help message. */
  1545.     conol("Command>");            /* Prompt for command. */
  1546.     c = coninc(0) & 0x7f;
  1547.     conoc(c);                /* Echo it. */
  1548.     if (c != CMDQ)
  1549.       conoll("");
  1550.     conoll("----------------------------------------------------");
  1551.     doesc(c);
  1552. }
  1553.  
  1554. /*  D O E S C  --  Process an escape character argument  */
  1555.  
  1556. VOID
  1557. #ifdef CK_ANSIC
  1558. doesc(register unsigned char c)
  1559. #else
  1560. doesc(c) register unsigned char c;
  1561. #endif /* CK_ANSIC */
  1562. /* doesc() */ {
  1563.     int d;
  1564.     char temp[1024];
  1565.  
  1566.     c &= 0177;                /* Mask off 8th bit */
  1567.  
  1568.     if (c == escape) {            /* If it's the escape character, */
  1569.         d = dopar(c);            /* just send it. */
  1570.         ttoc(d);
  1571.     return;
  1572.     }
  1573.     if (isupper(c)) c = tolower(c);    /* Convert to lowercase letter. */
  1574.     if (iscntrl(c)) c += 'a' - '\001';
  1575.  
  1576.     switch (c) {            /* Take requested action. */
  1577.       case 'b':
  1578. #ifdef CKLEARN
  1579.     learnchar(-7);
  1580. #endif /* CKLEARN */
  1581.     ttsndb();            /* Send a BREAK signal */
  1582.     break;
  1583. #ifdef TNCODE
  1584.       case 'i':                /* Send TELNET interrupt */
  1585. #ifndef IP
  1586. #define IP 244
  1587. #endif /* IP */
  1588.     if (network && ttnproto == NP_TELNET) { /* TELNET */
  1589.         CHAR temp[3];
  1590.         temp[0] = IAC;        /* I Am a Command */
  1591.         temp[1] = IP;        /* Interrupt Process */
  1592.         temp[2] = NUL;
  1593.         ttol((CHAR *)temp,2);
  1594.     } else conoc(BEL);
  1595.     break;
  1596.       case 'a':                /* "Are You There?" */
  1597.       case '\01':
  1598. #ifndef AYT
  1599. #define AYT 246
  1600. #endif /* AYT */
  1601.     if (network && ttnproto == NP_TELNET) {
  1602.         CHAR temp[3];
  1603.         temp[0] = IAC;        /* I Am a Command */
  1604.         temp[1] = AYT;        /* Are You There? */
  1605.         temp[2] = NUL;
  1606.         ttol((CHAR *)temp,2);
  1607.     } else conoc(BEL);
  1608. #endif /* TNCODE */
  1609.     break;
  1610.       case 'c':                /* Return to prompt */
  1611.     cx_status = CSX_ESCAPE;
  1612.     active = 0;
  1613.     conol("\r\n");
  1614.     break;
  1615.       case 'u':                /* Hang up the connection */
  1616.     cx_status = CSX_USERDISC;
  1617.     if (network)
  1618.       netclos();
  1619. #ifndef NODIAL
  1620.     else if (mdmhup() < 1)        /* Try via modem first, otherwise */
  1621.       tthang();            /* the old-fashioned way. */
  1622. #endif /* NODIAL */
  1623.     conol("\r\nHanging up ");
  1624.     break;
  1625.       case 'l':                /* Send a Long BREAK signal */
  1626. #ifdef CKLEARN
  1627.     learnchar(-8);
  1628. #endif /* CKLEARN */
  1629.     ttsndlb();
  1630.     break;
  1631.       case 's':                /* Status */
  1632.     conoll("");
  1633.     conoll("----------------------------------------------------");
  1634. #ifdef NETCMD
  1635.     if (ttpipe)
  1636.       sprintf(temp, " Pipe: \"%s\"", ttname);
  1637.     else
  1638. #endif /* NETCMD */
  1639.       sprintf(temp, " %s: %s", (network ? "Host" : "Device"), ttname);
  1640.     conoll(temp);
  1641.     if (!network && speed >= 0L) {
  1642.         sprintf(temp,"Speed %ld", speed);
  1643.         conoll(temp);
  1644.     }
  1645.     sprintf(temp," Terminal echo: %s", duplex ? "local" : "remote");
  1646.     conoll(temp);
  1647.     sprintf(temp," Terminal bytesize: %d", (cmask  == 0177) ? 7 : 8);
  1648.     conoll(temp);
  1649.     sprintf(temp," Command bytesize: %d", (cmdmsk == 0177) ? 7 : 8 );
  1650.     conoll(temp);
  1651.     sprintf(temp," Parity: %s", parnam(parity));
  1652.     conoll(temp);
  1653. #ifdef CK_APC
  1654.     sprintf(temp," Autodownload: %s", autodl ? "on" : "off");
  1655.     conoll(temp);
  1656. #endif /* CK_APC */
  1657.     sprintf(temp," Session log: %s", *sesfil ? sesfil : "(none)");
  1658.     conoll(temp);
  1659. #ifndef NOSHOW
  1660.         if (!network) shomdm();
  1661. #endif /* NOSHOW */
  1662. #ifdef CKLOGDIAL
  1663.         {
  1664.         long z;
  1665.         z = dologshow(0);
  1666.         if (z > -1L) {
  1667.             sprintf(temp," Elapsed time: %s",hhmmss(z));
  1668.             conoll(temp);
  1669.         }
  1670.         }
  1671. #endif /* CKLOGDIAL */
  1672.         conoll("----------------------------------------------------");
  1673.         return;
  1674.       case '!':
  1675.       case '@':
  1676. #ifndef NOPUSH
  1677.     if (!nopush) {
  1678.         conres();            /* Put console back to normal */
  1679.         zshcmd("");            /* Start DCL. */
  1680.         if (conbin(escape) < 0) {
  1681.         printf("Error returning to remote session\n");
  1682.         active = 0;
  1683.         }
  1684.     } else
  1685.       conoc(BEL);
  1686. #else
  1687.     conoc(BEL);
  1688. #endif /* NOPUSH */
  1689.     return;
  1690.  
  1691.       case 'x':                /* XON */
  1692. /*
  1693.   NOTE: Here we should also issue QIO's to clear XOFF deadlock.
  1694. */
  1695.     ttoc(dopar(XON));
  1696.     break;
  1697.       case 'h':                /* Help */
  1698.       case '?':                /* Give Help */
  1699.     hconne();
  1700.     break;
  1701.       case '0':                /* Send a NULL */
  1702.     c = '\0';
  1703.     d = dopar(c);
  1704.     ttoc(d);
  1705.     break;
  1706.       case SP:                /* Ignore space */
  1707.     break;
  1708.       default:
  1709.     if (c == CMDQ) {        /* Backslash escape */
  1710.         int x;
  1711.         kbp = kbuf;
  1712.         *kbp++ = c;
  1713.         while (((c = (coninc(0) & cmdmsk)) != '\r') && (c != '\n'))
  1714.           *kbp++ = c;
  1715.         *kbp = NUL; kbp = kbuf;
  1716.         x = xxesc(&kbp);
  1717.         if (x >= 0) {
  1718.         c = dopar(x);
  1719.         ttoc(c);
  1720.         return;
  1721.         } else {
  1722.         conoc(BEL);
  1723.         return;
  1724.         }
  1725.     }
  1726.     conoc(BEL); return;        /* Invalid esc arg, beep */
  1727.     }
  1728. }
  1729.