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