home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / old / ckermit5a188 / ckucon.c < prev    next >
C/C++ Source or Header  |  2020-01-01  |  42KB  |  1,342 lines

  1. char *connv = "CONNECT Command for UNIX, 5A(051) 8 Mar 93";
  2.  
  3. /*  C K U C O N  --  Dumb terminal connection to remote system, for UNIX  */
  4. /*
  5.   Author: Frank da Cruz (fdc@columbia.edu, FDCCU@CUVMA.BITNET),
  6.   Columbia University Center for Computing Activities.
  7.   First released January 1985.
  8.   Copyright (C) 1985, 1992, Trustees of Columbia University in the City of New
  9.   York.  Permission is granted to any individual or institution to use this
  10.   software as long as it is not sold for profit.  This copyright notice must be
  11.   retained.  This software may not be included in commercial products without
  12.   written permission of Columbia University.
  13. */
  14.  
  15. #include "ckcdeb.h"            /* Common things first */
  16.  
  17. #ifdef NEXT
  18. #undef NSIG
  19. #include <sys/wait.h>            /* For wait() */
  20. #endif /* NEXT */
  21.  
  22. #include <signal.h>            /* Signals */
  23. #include <errno.h>            /* Error numbers */
  24.  
  25. #ifdef ZILOG                /* Longjumps */
  26. #include <setret.h>
  27. #else
  28. #include <setjmp.h>
  29. #endif /* ZILOG */
  30.  
  31. /* Kermit-specific includes */
  32.  
  33. #include "ckcasc.h"            /* ASCII characters */
  34. #include "ckcker.h"            /* Kermit things */
  35. #include "ckucmd.h"            /* For xxesc() prototype */
  36. #include "ckcnet.h"            /* Network symbols */
  37. #ifndef NOCSETS
  38. #include "ckcxla.h"            /* Character set translation */
  39. #endif /* NOCSETS */
  40.  
  41. /* Internal function prototypes */
  42.  
  43. _PROTOTYP( VOID doesc, (char) );
  44. _PROTOTYP( VOID logchar, (char) );
  45. _PROTOTYP( int hconne, (void) );
  46. _PROTOTYP( VOID shomdm, (void) );
  47.  
  48. #ifndef SIGUSR1                /* User-defined signals */
  49. #define SIGUSR1 30
  50. #endif /* SIGUSR1 */
  51.  
  52. #ifndef SIGUSR2
  53. #define SIGUSR2 31
  54. #endif /* SIGUSR2 */
  55.  
  56. /* External variables */
  57.  
  58. extern int local, escape, duplex, parity, flow, seslog, sessft, debses,
  59.  mdmtyp, ttnproto, cmask, cmdmsk, network, nettype, deblog, sosi, tnlm,
  60.  xitsta, what, ttyfd, quiet, backgrd, pflag, tt_crd, tn_nlm, ttfdflg;
  61. extern long speed;
  62. extern char ttname[], sesfil[], myhost[], *ccntab[];
  63.  
  64. #ifndef NOSETKEY            /* Keyboard mapping */
  65. extern KEY *keymap;            /* Single-character key map */
  66. extern MACRO *macrotab;            /* Key macro pointer table */
  67. static MACRO kmptr = NULL;        /* Pointer to current key macro */
  68. #endif /* NOSETKEY */
  69.  
  70. /* Global variables local to this module */
  71.  
  72. static int quitnow = 0,            /* <esc-char>Q was typed */
  73.   dohangup = 0,                /* <esc-char>H was typed */
  74.   sjval = 0,                /* Setjump return value */
  75.   goterr = 0,                /* I/O error flag */
  76. #ifndef SUNX25
  77.   active = 0,                /* Lower fork active flag */
  78. #endif /* SUNX25 */
  79.   inshift = 0,                /* SO/SI shift states */
  80.   outshift = 0;
  81.  
  82. static char kbuf[10], *kbp;        /* Keyboard buffer & pointer */
  83. static PID_T parent_id = (PID_T)0;    /* Process id of keyboard fork */
  84.  
  85. static char *ibp;            /* Input buffer pointer */
  86. static int ibc = 0;            /* Input buffer count */
  87. #ifdef pdp11
  88. #define IBUFL 1536            /* Input buffer length */
  89. #else
  90. #define IBUFL 4096
  91. #endif /* pdp11 */
  92.  
  93. static char *obp;            /* Output buffer pointer */
  94. static int obc = 0;            /* Output buffer count */
  95. #ifndef OXOS
  96. #define OBUFL 1024            /* Output buffer length */
  97. #else /* OXOS */
  98. #define OBUFL IBUFL
  99. #endif /* OXOS */
  100.  
  101. #define TMPLEN 200            /* Temporary message buffer length */
  102. #ifdef DYNAMIC
  103. static char *ibuf = NULL, *obuf = NULL, *temp = NULL; /* Buffers */
  104. #else
  105. static char ibuf[IBUFL], obuf[OBUFL], temp[TMPLEN];
  106. #endif /* DYNAMIC */
  107.  
  108. /* SunLink X.25 items */
  109.  
  110. #ifdef SUNX25
  111. static char *p;                /* General purpose pointer */
  112. char x25ibuf[MAXIX25];            /* Input buffer */
  113. char x25obuf[MAXOX25];            /* Output buffer */
  114. int active = 0;                /* Lower fork active flag */
  115. int ibufl;                /* Length of input buffer */
  116. int obufl;                /* Length of output buffer */
  117. unsigned char tosend = 0;
  118. int linkid, lcn;
  119. static int dox25clr = 0;
  120. CHAR padparms[MAXPADPARMS+1];
  121. static int padpipe[2];            /* Pipe descriptor to pass PAD parms */
  122. #endif /* SUNX25 */
  123.  
  124. /* Character-set items */
  125.  
  126. #ifndef NOCSETS
  127. #ifdef CK_ANSIC /* ANSI C prototypes... */
  128. extern CHAR (*xls[MAXTCSETS+1][MAXFCSETS+1])(CHAR); /* Character set */
  129. extern CHAR (*xlr[MAXTCSETS+1][MAXFCSETS+1])(CHAR); /* translation functions */
  130. static CHAR (*sxo)(CHAR);    /* Local translation functions */
  131. static CHAR (*rxo)(CHAR);    /* for output (sending) terminal chars */
  132. static CHAR (*sxi)(CHAR);    /* and for input (receiving) terminal chars. */
  133. static CHAR (*rxi)(CHAR);
  134. #else /* Not ANSI C... */
  135. extern CHAR (*xls[MAXTCSETS+1][MAXFCSETS+1])();    /* Character set */
  136. extern CHAR (*xlr[MAXTCSETS+1][MAXFCSETS+1])();    /* translation functions. */
  137. static CHAR (*sxo)();        /* Local translation functions */
  138. static CHAR (*rxo)();        /* for output (sending) terminal chars */
  139. static CHAR (*sxi)();        /* and for input (receiving) terminal chars. */
  140. static CHAR (*rxi)();
  141. #endif /* CK_ANSIC */
  142. extern int language;        /* Current language. */
  143. static int langsv;        /* For remembering language setting. */
  144. extern struct csinfo fcsinfo[]; /* File character set info. */
  145. extern int tcsr, tcsl;        /* Terminal character sets, remote & local. */
  146. static int tcs;            /* Intermediate ("transfer") character set. */
  147.  
  148. #ifndef NOESCSEQ
  149. /*
  150.   As of edit 178, the CONNECT command will skip past ANSI escape sequences
  151.   to avoid translating the characters within them.  This allows the CONNECT
  152.   command to work correctly when connected to a remote host that uses a
  153.   7-bit ISO 646 national character set, in which characters like '[' would
  154.   normally be translated into accented characters, ruining the terminal's
  155.   interpretation (and generation) of escape sequences.
  156.  
  157.   Escape sequences of non-ANSI/ISO-compliant terminals are not handled.
  158. */
  159. #ifndef SKIPESC
  160. #define SKIPESC
  161. #endif /* SKIPESC */
  162. /*
  163.   States for the escape-sequence recognizer.
  164. */
  165. #define ES_NORMAL 0            /* Normal, not in escape sequence */
  166. #define ES_GOTESC 1            /* Current character is ESC */
  167. #define ES_ESCSEQ 2            /* Inside an escape sequence */
  168. #define ES_GOTCSI 3            /* Inside a control sequence */
  169. #define ES_STRING 4            /* Inside DCS,OSC,PM, or APC string */
  170. #define ES_TERMIN 5            /* 1st char of string terminator */
  171.  
  172. static int
  173.   skipesc = 0,                /* Skip over ANSI escape sequences */
  174.   inesc = ES_NORMAL;            /* State of sequence recognizer */
  175. /*
  176.   ANSI escape sequence handling.  Only the 7-bit form is treated, because
  177.   translation is not a problem in the 8-bit environment, in which all GL
  178.   characters are ASCII and no translation takes place.  So we don't check
  179.   for the 8-bit single-character versions of CSI, DCS, OSC, APC, or ST.
  180.   Here is the ANSI sequence recognizer state table, followed by the code
  181.   that implements it.
  182.  
  183.   Definitions:
  184.     CAN = Cancel                       01/08         Ctrl-X
  185.     SUB = Substitute                   01/10         Ctrl-Z
  186.     DCS = Device Control Sequence      01/11 05/00   ESC P
  187.     CSI = Control Sequence Introducer  01/11 05/11   ESC [
  188.     ST  = String Terminator            01/11 05/12   ESC \
  189.     OSC = Operating System Command     01/11 05/13   ESC ]
  190.     PM  = Privacy Message              01/11 05/14   ESC ^
  191.     APC = Application Program Command  01/11 05/15   ESC _
  192.  
  193.   ANSI escape sequence recognizer:
  194.  
  195.     State    Input  New State  ; Commentary
  196.  
  197.     NORMAL   (start)           ; Start in NORMAL state
  198.  
  199.     (any)    CAN    NORMAL     ; ^X cancels
  200.     (any)    SUB    NORMAL     ; ^Z cancels
  201.  
  202.     NORMAL   ESC    GOTESC     ; Begin escape sequence
  203.     NORMAL   other             ; NORMAL control or graphic character
  204.  
  205.     GOTESC   ESC               ; Start again
  206.     GOTESC   [      GOTCSI     ; CSI
  207.     GOTESC   P      STRING     ; DCS introducer, consume through ST
  208.     GOTESC   ]      STRING     ; OSC introducer, consume through ST
  209.     GOTESC   ^      STRING     ; PM  introducer, consume through ST
  210.     GOTESC   _      STRING     ; APC introducer, consume through ST
  211.     GOTESC   0..~   NORMAL     ; 03/00 through 17/14 = Final character
  212.     GOTESC   other  ESCSEQ     ; Intermediate or ignored control character
  213.  
  214.     ESCSEQ   ESC    GOTESC     ; Start again
  215.     ESCSEQ   0..~   NORMAL     ; 03/00 through 17/14 = Final character
  216.     ESCSEQ   other             ; Intermediate or ignored control character
  217.  
  218.     GOTCSI   ESC    GOTESC     ; Start again
  219.     GOTCSI   @..~   NORMAL     ; 04/00 through 17/14 = Final character
  220.     GOTCSI   other             ; Intermediate char or ignored control char
  221.  
  222.     STRING   ESC    TERMIN     ; Maybe have ST
  223.     STRING   other             ; Consume all else
  224.  
  225.     TERMIN   \      NORMAL     ; End of string
  226.     TERMIN   other  STRING     ; Still in string
  227. */
  228. /*
  229.   chkaes() -- Check ANSI Escape Sequence.
  230.   Call with EACH character in input stream.
  231.   Sets global inesc variable according to escape sequence state.
  232. */
  233. VOID
  234. #ifdef CK_ANSIC
  235. chkaes(char c)
  236. #else
  237. chkaes(c) char c;
  238. #endif /* CK_ANSIC */
  239. /* chkaes */ {
  240.  
  241.     if (c == CAN || c == SUB)        /* CAN and SUB cancel any sequence */
  242.       inesc = ES_NORMAL;
  243.     else                /* Otherwise */
  244.       switch (inesc) {            /* enter state switcher */
  245.  
  246.     case ES_NORMAL:            /* NORMAL state */
  247.       if (c == ESC)            /* Got an ESC */
  248.         inesc = ES_GOTESC;        /* Change state to GOTESC */
  249.       break;            /* Otherwise stay in NORMAL state */
  250.  
  251.     case ES_GOTESC:            /* GOTESC state */
  252.       if (c == '[')            /* Left bracket after ESC is CSI */
  253.         inesc = ES_GOTCSI;        /* Change to GOTCSI state */
  254.       else if (c > 057 && c < 0177)    /* Final character '0' thru '~' */
  255.         inesc = ES_NORMAL;        /* Back to normal */
  256.       else if (c == 'P' || (c > 0134 && c < 0140)) /* P, [, ^, or _ */
  257.         inesc = ES_STRING;        /* Switch to STRING-absorption state */
  258.       else if (c != ESC)        /* ESC in an escape sequence... */
  259.         inesc = ES_ESCSEQ;        /* starts a new escape sequence */
  260.       break;            /* Intermediate or ignored ctrl char */
  261.  
  262.     case ES_ESCSEQ:            /* ESCSEQ -- in an escape sequence */
  263.       if (c > 057 && c < 0177)    /* Final character '0' thru '~' */
  264.         inesc = ES_NORMAL;        /* Return to NORMAL state. */
  265.       else if (c == ESC)        /* ESC ... */
  266.         inesc = ES_GOTESC;        /* starts a new escape sequence */
  267.       break;            /* Intermediate or ignored ctrl char */
  268.  
  269.     case ES_GOTCSI:            /* GOTCSI -- In a control sequence */
  270.       if (c > 077 && c < 0177)    /* Final character '@' thru '~' */
  271.         inesc = ES_NORMAL;        /* Return to NORMAL. */
  272.       else if (c == ESC)        /* ESC ... */
  273.         inesc = ES_GOTESC;        /* starts over. */
  274.       break;            /* Intermediate or ignored ctrl char */
  275.  
  276.     case ES_STRING:            /* Inside a string */
  277.       if (c == ESC)            /* ESC may be 1st char of terminator */
  278.         inesc = ES_TERMIN;        /* Go see. */
  279.       break;            /* Absorb all other characters. */
  280.  
  281.     case ES_TERMIN:            /* May have a string terminator */
  282.       if (c == '\\')        /* which must be backslash */
  283.         inesc = ES_NORMAL;        /* If so, back to NORMAL */
  284.       else                /* Otherwise */
  285.         inesc = ES_STRING;        /* Back to string absorption. */
  286.       }
  287. }
  288. #endif /* NOESCSEQ */
  289. #endif /* NOCSETS */
  290.  
  291. /* Connect state parent/child communication signal handlers */
  292.  
  293. static jmp_buf con_env;         /* Environment pointer for connect errors */
  294. /*
  295.   Note: Some C compilers (e.g. Cray UNICOS) interpret the ANSI C standard
  296.   about setjmp() in a way that disallows constructions like:
  297.  
  298.     if ((var = setjmp(env)) == 0) ...
  299.  
  300.   which prevents the value returned by longjmp() from being used at all.
  301.   So the following handlers set a global variable instead.
  302. */
  303. static
  304. SIGTYP
  305. conn_int(foo) int foo; {        /* Modem read failure handler, */
  306.     signal(SIGUSR1,SIG_IGN);        /* Disarm the interrupt */
  307.     sjval = 1;                /* Set global variable */
  308.     longjmp(con_env,sjval);        /* Notifies parent process to stop */
  309. }
  310.  
  311. static
  312. SIGTYP
  313. mode_chg(foo) int foo; {
  314.     signal(SIGUSR2,mode_chg);        /* Re-arm the signal immediately. */
  315.  
  316. #ifdef SUNX25                /* X.25 read new params from pipe */
  317.     if (nettype == NET_SX25) {
  318.         read(padpipe[0],padparms,MAXPADPARMS);
  319.         debug(F100,"pad_chg","",0);
  320. /*
  321.   NOTE: we can probably skip this longjmp, just as we do in the "else" case.
  322.   But I don't (yet) have any way to test this.
  323. */
  324.     sjval = 2;            /* Set global variable. */
  325.     longjmp(con_env,sjval);
  326.     debug(F100,"mode_chg X.25","",0);
  327.     } else {
  328. #endif /* SUNX25 */
  329.     duplex = 1 - duplex;        /* Toggle duplex mode. */
  330.     debug(F101,"mode_chg duplex","",duplex);
  331. #ifdef SUNX25
  332.     }
  333. #endif /* SUNX25 */
  334. }
  335.  
  336. /*  C K C P U T C  --  C-Kermit CONNECT Put Character to Screen  */
  337. /*
  338.   Output is buffered to avoid slow screen writes on fast connections.
  339. */
  340. int
  341. ckcputf() {                /* Dump the output buffer */
  342.     int x = 0;
  343.     if (obc > 0)            /* If we have any characters, */
  344.       x = conxo(obc,obuf);        /* dump them, */
  345.     obp = obuf;                /* reset the pointer */
  346.     obc = 0;                /* and the counter. */
  347.     return(x);                /* Return conxo's return code */
  348. }
  349.  
  350. int
  351. ckcputc(c) int c; {
  352.     int x;
  353.  
  354.     *obp++ = c & 0xff;            /* Deposit the character */
  355.     obc++;                /* Count it */
  356.     if (ibc == 0 ||            /* If input buffer about empty */
  357.     obc == OBUFL) {            /* or output buffer full */
  358.     debug(F101,"CKCPUTC obc","",obc);
  359.     x = conxo(obc,obuf);        /* dump the buffer, */
  360.     obp = obuf;            /* reset the pointer */
  361.     obc = 0;            /* and the counter. */
  362.     return(x);            /* Return conxo's return code */
  363.     } else return(0);
  364. }
  365.  
  366. /*  C K C G E T C  --  C-Kermit CONNECT Get Character  */
  367. /*
  368.   Buffered read from communication device.
  369.   Returns the next character, refilling the buffer if necessary.
  370.   On error, returns ttinc's return code (see ttinc() description).
  371.   Dummy argument for compatible calling conventions with ttinc().
  372. */
  373. int
  374. ckcgetc(dummy) int dummy; {
  375.     int c, n;
  376.  
  377.     debug(F101,"CKCGETC 1 ibc","",ibc); /* Log */
  378.     if (ibc < 1) {            /* Need to refill buffer? */
  379.     ibc = 0;            /* Yes, reset count */
  380.     ibp = ibuf;            /* and buffer pointer */
  381.     debug(F100,"CKCGETC 1 calling ttinc(0)","",0); /* Log */
  382.     c = ttinc(0);            /* Read one character, blocking */
  383.     debug(F101,"CKCGETC 1 ttinc(0)","",c); /* Log */
  384.     if (c < 0) {            /* If error, return error code */
  385.         return(c);
  386.     } else {            /* Otherwise, got one character */
  387.         *ibp++ = c;            /* Advance buffer pointer */
  388.         ibc++;            /* and count. */
  389.     }
  390.  
  391.     /* Now quickly read any more that might have arrived */
  392.  
  393.     if ((n = ttchk()) > 0) {    /* Any more waiting? */
  394.         if (n > (IBUFL - ibc))    /* Get them all at once. */
  395.           n = IBUFL - ibc;        /* Don't overflow buffer */
  396.         if ((n = ttxin(n,(CHAR *)ibp)) > 0) {
  397.         ibp += n;        /* Advance pointer */
  398.         ibc += n;        /* and counter */
  399.         } else return(-1);
  400.     }
  401.     debug(F101,"CKCGETC 2 ibc","",ibc); /* Log how many */
  402.     ibp = ibuf;
  403.     }
  404.     c = *ibp++ & 0xff;            /* Get next character from buffer */
  405.     ibc--;                /* Reduce buffer count */
  406.     return(c);                /* Return the character */
  407. }
  408.  
  409. /*  C O N E C T  --  Perform terminal connection  */
  410.  
  411. int
  412. conect() {
  413.     PID_T pid;            /* Process id of child (modem reader) */
  414.     int    n;            /* General purpose counter */
  415.  
  416.     int c;            /* c is a character, but must be signed 
  417.                    integer to pass thru -1, which is the
  418.                    modem disconnection signal, and is
  419.                    different from the character 0377 */
  420.     int c2;            /* A copy of c */
  421.     int csave;            /* Another copy of c */
  422.     int tx;            /* tn_doop() return code */
  423. #ifdef SUNX25
  424.     int i;            /* Worker for X.25 code*/
  425. #endif /* SUNX25 */
  426.  
  427. #ifdef DYNAMIC
  428.     if (!(ibuf = malloc(IBUFL+1))) {    /* Allocate input line buffer */
  429.     printf("Sorry, CONNECT input buffer can't be allocated\n");
  430.     return(0);
  431.     }
  432.     if (!(obuf = malloc(OBUFL+1))) {    /* Allocate input line buffer */
  433.     printf("Sorry, CONNECT output buffer can't be allocated\n");
  434.     free(ibuf);
  435.     return(0);
  436.     }
  437.     if (!(temp = malloc(TMPLEN+1))) {    /* Allocate temporary buffer */
  438.     printf("Sorry, CONNECT temporary buffer can't be allocated\n");
  439.     free(obuf);
  440.     return(0);
  441.     }
  442. #endif /* DYNAMIC */
  443.  
  444.     if (!local) {
  445. #ifdef NETCONN
  446.     printf("Sorry, you must SET LINE or SET HOST first\n");
  447. #else
  448.     printf("Sorry, you must SET LINE first\n");
  449. #endif /* NETCONN */
  450.     return(0);
  451.     }
  452.     if (speed < 0L && network == 0 && ttfdflg == 0) {
  453.     printf("Sorry, you must SET SPEED first\n");
  454.     return(0);
  455.     }
  456. #ifdef TCPSOCKET
  457.     if (network && (nettype != NET_TCPB)
  458. #ifdef SUNX25
  459.         && (nettype != NET_SX25)
  460. #endif /* SUNX25 */
  461.     ) {
  462.     printf("Sorry, network type not supported\n");
  463.     return(0);
  464.     }
  465. #endif /* TCPSOCKET */
  466.  
  467.     if (ttyfd < 0) {            /* If communication device not open */
  468.     debug(F111,"ckucon opening",ttname,0); /* Open it now */
  469.     if (ttopen(ttname,
  470.            &local,
  471.            network ? -nettype : mdmtyp,
  472.            0
  473.            ) < 0) {
  474.         sprintf(temp,"Sorry, can't open %s",ttname);
  475.         perror(temp);
  476.         debug(F110,"ckucon open failure",temp,0);
  477.         return(0);
  478.     }
  479.     }
  480.     dohangup = 0;            /* Hangup not requested yet */
  481. #ifdef SUNX25
  482.     dox25clr = 0;            /* X.25 clear not requested yet */
  483. #endif /* SUNX25 */
  484.  
  485.     if (!quiet) {
  486. #ifdef NETCONN
  487.     if (network) {
  488.         printf("Connecting to host %s",ttname);
  489. #ifdef SUNX25
  490.         if (nettype == NET_SX25)
  491.           printf(", Link ID %d, LCN %d",linkid,lcn);
  492. #endif /* SUNX25 */
  493.     } else {
  494. #endif /* NETCONN */
  495.         printf("Connecting to %s",ttname);
  496.         if (speed > -1L) printf(", speed %ld",speed);
  497. #ifdef NETCONN
  498.     }
  499. #endif /* NETCONN */
  500.     printf(".\r\nThe escape character is Ctrl-%c (ASCII %d, %s)\r\n",
  501.            ctl(escape), escape, (escape == 127 ? "DEL" : ccntab[escape]));
  502.     printf("Type the escape character followed by C to get back,\r\n");
  503.     printf("or followed by ? to see other options.\r\n");
  504.     if (seslog) {
  505.         printf("(Session logged to %s, ",sesfil);
  506.         printf("%s)\r\n", sessft ? "binary" : "text");
  507.     }
  508.     if (debses) printf("Debugging Display...)\r\n");
  509.     fflush(stdout);
  510.     }
  511.  
  512. /* Condition console terminal and communication line */        
  513.  
  514.     if (conbin((char)escape) < 0) {
  515.     printf("Sorry, can't condition console terminal\n");
  516.     return(0);
  517.     }
  518.     debug(F101,"connect cmask","",cmask);
  519.     debug(F101,"connect cmdmsk","",cmdmsk);
  520.     goterr = 0;
  521.     if ((n = ttvt(speed,flow)) < 0) {    /* Enter "virtual terminal" mode */
  522.     debug(F101,"CONNECT ttvt","",n);
  523.     goterr = 1;            /* Error recovery... */
  524.     tthang();            /* Hang up and close the device. */
  525.     ttclos(0);
  526.     if (ttopen(ttname,        /* Open it again... */
  527.            &local,
  528.            network ? -nettype : mdmtyp,
  529.            0
  530.            ) < 0) {
  531.         sprintf(temp,"Sorry, can't reopen %s",ttname);
  532.         perror(temp);
  533.         return(0);
  534.     }
  535.     if (ttvt(speed,flow) < 0) {    /* Try virtual terminal mode again. */
  536.         conres();            /* Failure this time is fatal. */
  537.         printf("Sorry, Can't condition communication line\n");
  538.         return(0);
  539.     }
  540. #ifdef NETCONN
  541.     if (network && ttnproto == NP_TELNET)
  542.       tn_ini();            /* Just in case ttopen didn't... */
  543. #endif /* NETCONN */
  544.     }
  545.     debug(F101,"connect ttvt ok, escape","",escape);
  546.  
  547. #ifndef NOCSETS
  548. /* Set up character set translations */
  549.  
  550.     tcs = gettcs(tcsr,tcsl);        /* Get intermediate set. */
  551.  
  552.     if (tcsr == tcsl) {            /* Remote and local sets the same? */
  553.     sxo = rxo = NULL;        /* If so, no translation. */
  554.     sxi = rxi = NULL;
  555.     } else {                /* Otherwise, set up */
  556.     sxo = xls[tcs][tcsl];        /* translation function */
  557.     rxo = xlr[tcs][tcsr];        /* pointers for output functions */
  558.     sxi = xls[tcs][tcsr];        /* and for input functions. */
  559.     rxi = xlr[tcs][tcsl];
  560.     }
  561. /*
  562.   This is to prevent use of zmstuff() and zdstuff() by translation functions.
  563.   They only work with disk i/o, not with communication i/o.  Luckily Russian
  564.   translation functions don't do any stuffing...
  565. */
  566.     langsv = language;
  567. #ifndef NOCYRIL
  568.     if (language != L_RUSSIAN)
  569. #endif /* NOCYRIL */
  570.       language = L_USASCII;
  571.  
  572. #ifdef SKIPESC
  573. /*
  574.   We need to activate the "skip escape sequence" feature when:
  575.   (a) translation is elected, and
  576.   (b) the local and/or remote set is a 7-bit set other than US ASCII.
  577. */
  578.     skipesc = (tcs != TC_TRANSP) &&    /* Not transparent */
  579.       (fcsinfo[tcsl].size == 128 || fcsinfo[tcsr].size == 128) && /* 7 bits */
  580.     (fcsinfo[tcsl].code != FC_USASCII); /* But not ASCII */
  581.     inesc = ES_NORMAL;            /* Initial state of recognizer */
  582. #ifdef COMMENT
  583.     debug(F101,"tcs","",tcs);
  584.     debug(F101,"tcsl","",tcsl);
  585.     debug(F101,"tcsr","",tcsr);
  586.     debug(F101,"fcsinfo[tcsl].size","",fcsinfo[tcsl].size);
  587.     debug(F101,"fcsinfo[tcsr].size","",fcsinfo[tcsr].size);
  588. #endif /* COMMENT */
  589.     debug(F101,"skipesc","",skipesc);
  590. #endif /* SKIPESC */
  591. #endif /* NOCSETS */
  592.  
  593. /*
  594.   This is a label we jump back to when the lower fork sensed the need
  595.   to change modes.  As of 5A(178), this is used only by X.25 code
  596.   (perhaps unnecessarily? -- The X.25 code needs a lot of testing and
  597.   cleaning up...)
  598. */
  599. newfork:
  600.     debug(F100,"CONNECT newfork","",0);
  601.     parent_id = getpid();        /* Get parent id for signalling */
  602.     signal(SIGUSR1,SIG_IGN);        /* Don't kill myself */
  603. #ifdef SUNX25
  604.     pipe(padpipe);                      /* Create pipe to pass PAD parms */
  605. #endif /* SUNX25 */
  606.     pid = fork();            /* All ok, make a fork */
  607.     if (pid == (PID_T) -1) {        /* Can't create it. */
  608.     conres();            /* Reset the console. */
  609.     perror("Can't create keyboard fork");
  610.     if (!quiet) {
  611.     printf("\r\nCommunications disconnect (Back at %s)\r\n",
  612.            *myhost ?
  613.            myhost :
  614. #ifdef UNIX
  615.            "local UNIX system"
  616. #else
  617.            "local system"
  618. #endif /* UNIX */
  619.            );
  620.     }
  621.     printf("\n");
  622.     what = W_NOTHING;        /* So console modes are set right. */
  623. #ifndef NOCSETS
  624.     language = langsv;        /* Restore language */
  625. #endif /* NOCSETS */
  626.     parent_id = (PID_T) 0;        /* Clean up */
  627. #ifdef DYNAMIC
  628.     if (temp) free(temp);        /* Free allocated memory */
  629.     if (ibuf) free(ibuf);
  630.     if (obuf) free(obuf);
  631. #endif /* DYNAMIC */
  632.     return(1);
  633.     }
  634.     if (pid) {                /* Top fork reads, sends keystrokes */
  635.     what = W_CONNECT;        /* Keep track of what we're doing */
  636.     active = 1;
  637.     debug(F101,"CONNECT keyboard fork duplex","",duplex);
  638.  
  639.     /* Catch communication errors or mode changes in lower fork */
  640.  
  641.     if (setjmp(con_env) == 0) {    /* Normal entry... */
  642.         sjval = 0;            /* Initialize setjmp return code. */
  643.         signal(SIGUSR1,conn_int);    /* Routine for child process exit. */
  644.         signal(SIGUSR2,mode_chg);    /* Routine for mode change. */
  645. #ifdef SUNX25
  646.         if (network && nettype == NET_SX25) {
  647.         obufl = 0;
  648.         bzero (x25obuf,sizeof(x25obuf)) ;
  649.         }
  650. #endif /* SUNX25 */
  651.  
  652. /*
  653.   Here is the big loop that gets characters from the keyboard and sends them
  654.   out the communication device.  There are two components to the communication
  655.   path: the connection from the keyboard to C-Kermit, and from C-Kermit to
  656.   the remote computer.  The treatment of the 8th bit of keyboard characters 
  657.   is governed by SET COMMAND BYTESIZE (cmdmsk).  The treatment of the 8th bit
  658.   of characters sent to the remote is governed by SET TERMINAL BYTESIZE
  659.   (cmask).   This distinction was introduced in edit 5A(164).
  660. */
  661.         while (active) {
  662. #ifndef NOSETKEY
  663.         if (kmptr) {        /* Have current macro? */
  664.             debug(F100,"kmptr non NULL","",0);
  665.             if ((c = (CHAR) *kmptr++) == NUL) { /* Get char from it */
  666.             kmptr = NULL;    /* If no more chars,  */
  667.             debug(F100,"macro empty, continuing","",0);
  668.             continue;    /* reset pointer and continue */
  669.             }
  670.             debug(F000,"char from macro","",c);
  671.         } else            /* No macro... */
  672. #endif /* NOSETKEY */
  673.           c = congks(0);    /* Read from keyboard */
  674.  
  675.         debug(F101,"** KEYB","",c);
  676.  
  677.                 if (c == -1) {        /* If read() got an error... */
  678. #ifdef COMMENT
  679. /*
  680.  This seems to cause problems.  If read() returns -1, the signal has already
  681.  been delivered, and nothing will wake up the pause().
  682. */
  683.             pause();        /* Wait for transmitter to finish. */
  684. #else
  685. #ifdef A986
  686. /*
  687.   On Altos machines with Xenix 3.0, pressing DEL in connect mode brings us
  688.   here (reason unknown).  The console line discipline at this point has
  689.   intr = ^C.  The communications tty has intr = DEL but we get here after
  690.   pressing DEL on the keyboard, even when the remote system has been set not
  691.   to echo.  With A986 defined, we stay in the read loop and beep only if the
  692.   offending character is not DEL.
  693. */
  694.             if ((c & 127) != 127) conoc(BEL);
  695. #else
  696.             conoc(BEL);        /* Beep */
  697.             active = 0;        /* and terminate the read loop */
  698.             continue;
  699. #endif /* A986 */
  700. #endif /* COMMENT */
  701.         }
  702.         c &= cmdmsk;        /* Do any requested masking */
  703. #ifndef NOSETKEY
  704. /*
  705.   Note: kmptr is NULL if we got character c from the keyboard, and it is
  706.   not NULL if it came from a macro.  In the latter case, we must avoid
  707.   expanding it again.
  708. */
  709.         if (!kmptr && macrotab[c]) { /* Macro definition for c? */
  710.             kmptr = macrotab[c];     /* Yes, set up macro pointer */
  711.             continue;             /* and restart the loop, */
  712.         } else c = keymap[c];         /* else use single-char keymap */
  713. #endif /* NOSETKEY */
  714.         if (
  715. #ifndef NOSETKEY
  716.             !kmptr &&
  717. #endif /* NOSETKEY */
  718.             ((c & 0x7f) == escape)) { /* Escape character? */
  719.             debug(F000,"connect got escape","",c);
  720.             c = congks(0) & 0177; /* Got esc, get its arg */
  721.             /* No key mapping here */
  722.             doesc((char) c);    /* Now process it */
  723.  
  724.         } else {        /* It's not the escape character */
  725.             csave = c;        /* Save it before translation */
  726.                     /* for local echoing. */
  727. #ifndef NOCSETS
  728. #ifndef SKIPESC
  729.             /* Translate character sets */
  730.             if (sxo) c = (*sxo)(c); /* From local to intermediate. */
  731.             if (rxo) c = (*rxo)(c); /* From intermediate to remote. */
  732. #else
  733.             if (inesc == ES_NORMAL) { /* If not inside escape seq.. */
  734.             /* Translate character sets */
  735.             if (sxo) c = (*sxo)((char)c); /* Local-intermediate */
  736.             if (rxo) c = (*rxo)((char)c); /* Intermediate-remote */
  737.             }
  738.             if (skipesc) chkaes((char)c); /* Check escape seq status */
  739. #endif /* SKIPESC */
  740. #endif /* NOCSETS */
  741. /*
  742.  If Shift-In/Shift-Out is selected and we have a 7-bit connection,
  743.  handle shifting here.
  744. */
  745.             if (sosi) {             /* Shift-In/Out selected? */
  746.             if (cmask == 0177) { /* In 7-bit environment? */
  747.                 if (c & 0200) {          /* 8-bit character? */
  748.                 if (outshift == 0) { /* If not shifted, */
  749.                     ttoc(dopar(SO)); /* shift. */
  750.                     outshift = 1;
  751.                 }
  752.                 } else {
  753.                 if (outshift == 1) { /* 7-bit character */
  754.                     ttoc(dopar(SI)); /* If shifted, */
  755.                     outshift = 0;    /* unshift. */
  756.                 }
  757.                 }
  758.             }
  759.             if (c == SO) outshift = 1;   /* User typed SO */
  760.             if (c == SI) outshift = 0;   /* User typed SI */
  761.             }
  762.             c &= cmask;        /* Apply Kermit-to-host mask now. */
  763. #ifdef SUNX25
  764.                     if (network && nettype == NET_SX25) {
  765.                         if (padparms[PAD_ECHO]) {
  766.                             if (debses)
  767.                   conol(dbchr(c)) ;
  768.                             else
  769.                   if ((c != padparms[PAD_CHAR_DELETE_CHAR])   &&
  770.                   (c != padparms[PAD_BUFFER_DELETE_CHAR]) &&
  771.                   (c != padparms[PAD_BUFFER_DISPLAY_CHAR]))
  772.                                 conoc(c) ;
  773.                             if (seslog) logchar(c);
  774.                         }
  775.             if (c == CR && (padparms[PAD_LF_AFTER_CR] == 4 ||
  776.                     padparms[PAD_LF_AFTER_CR] == 5)) {
  777.                             if (debses)
  778.                   conol(dbchr(LF)) ;
  779.                             else
  780.                   conoc(LF) ;
  781.                             if (seslog) logchar(LF);
  782.                         }
  783.                         if (c == padparms[PAD_BREAK_CHARACTER])
  784.               breakact();
  785.                         else if (padparms[PAD_DATA_FORWARD_TIMEOUT]) {
  786.                             tosend = 1;
  787.                             x25obuf [obufl++] = c;
  788.                         } else if (((c == padparms[PAD_CHAR_DELETE_CHAR])  ||
  789.                     (c == padparms[PAD_BUFFER_DELETE_CHAR]) ||
  790.                     (c == padparms[PAD_BUFFER_DISPLAY_CHAR])) 
  791.                    && (padparms[PAD_EDITING]))
  792.               if (c == padparms[PAD_CHAR_DELETE_CHAR])
  793.                 if (obufl > 0) {
  794.                 conol("\b \b"); obufl--;
  795.                 } else {}
  796.               else if (c == padparms[PAD_BUFFER_DELETE_CHAR]) {
  797.                   conol ("\r\nPAD Buffer Deleted\r\n");
  798.                   obufl = 0;
  799.               }
  800.               else if (c == padparms[PAD_BUFFER_DISPLAY_CHAR]) {
  801.                   conol("\r\n");
  802.                   conol(x25obuf);
  803.                   conol("\r\n");
  804.               } else {} 
  805.                         else {
  806.                             x25obuf [obufl++] = c;
  807.                             if (obufl == MAXOX25) tosend = 1;
  808.                             else if (c == CR) tosend = 1;
  809.                         }
  810.                         if (tosend) 
  811.               if (ttol(x25obuf,obufl) < 0) {
  812.                   perror ("\r\nCan't send characters");
  813.                   active = 0;
  814.               } else {
  815.                   bzero (x25obuf,sizeof(x25obuf));
  816.                   obufl = 0;
  817.                   tosend = 0;
  818.               } else {};
  819.                     } else {
  820. #endif /* SUNX25 */ 
  821.  
  822. /* If we have a CR, handle CR/CRLF mapping... */
  823.  
  824.             if (c == '\015') {
  825.             if (tnlm    /* TERMINAL NEWLINE ON */
  826. #ifdef TNCODE                /* And for TELNET... */
  827.             || (network && ttnproto == NP_TELNET)
  828. #endif /* TNCODE */
  829.             ) {
  830.                 ttoc(dopar('\015'));    /* Send CR */
  831.                 if (duplex) conoc('\015');    /* Maybe echo CR */
  832. #ifdef TNCODE
  833.                 if (network && !tn_nlm && ttnproto == NP_TELNET)
  834.                   c = '\0';        /* Stuff NUL */
  835.                 else
  836. #endif /* TNCODE */
  837.                   c = '\012';    /* Stuff LF */
  838.                 csave = c;
  839.             }
  840.             }            /* Now process the LF or NUL... */
  841. #ifdef TNCODE
  842. /* If user types the 0xff character (TELNET IAC), it must be doubled. */
  843.             else
  844.               if (c == IAC && network && ttnproto == NP_TELNET) {
  845.                     /* Send one copy now */
  846.             ttoc((char)IAC); /* and the other one just below. */
  847.             }
  848. #endif /* TNCODE */
  849.  
  850.             /* Send the character */
  851.  
  852.             if (ttoc((char)dopar((CHAR) c)) > -1) {
  853.                 if (duplex) {    /* If half duplex, must echo */
  854.                 if (debses)
  855.                   conol(dbchr(csave)); /* the original char */
  856.                 else               /* not the translated one */
  857.                   conoc((char)csave);
  858.                 if (seslog) { /* And maybe log it too */
  859.                 c2 = csave;
  860.                 if (sessft == 0 && csave == '\r')
  861.                   c2 = '\n';
  862.                 logchar((char)c2);
  863.                 }
  864.             }
  865.                     } else {
  866.             perror("\r\nCan't send character");
  867.             active = 0;
  868.             }
  869. #ifdef SUNX25
  870.         } 
  871. #endif /* SUNX25 */
  872.         }
  873.         }
  874.     }                /* Come here on death of child */
  875.     debug(F100,"CONNECT killing port fork","",0);
  876.     kill(pid,9);            /* Done, kill inferior fork. */
  877.     wait((WAIT_T *)0);        /* Wait till gone. */
  878.     if (sjval == 1) {        /* Read error on comm device */
  879.         dohangup = 1;
  880. #ifdef NETCONN
  881.         if (network) {
  882.         ttclos(0);
  883. #ifdef SUNX25
  884.         if (nettype == NET_SX25) initpad();
  885. #endif /* SUNX25 */
  886.         }
  887. #endif /* NETCONN */
  888.     }
  889.     if (sjval == 2)            /* If it was a mode change, go back */
  890.       goto newfork;            /* and coordinate with other fork. */
  891.     conres();            /* Reset the console. */
  892.     if (quitnow) doexit(GOOD_EXIT,xitsta); /* Exit now if requested. */
  893.     if (dohangup > 0) {        /* If hangup requested, do that. */
  894. #ifndef NODIAL
  895.         if (dohangup > 1)        /* User asked for it */
  896.           if (mdmhup() < 1)        /* Maybe hang up via modem */
  897. #endif /* NODIAL */
  898.           tthang();            /* And make sure we don't hang up */
  899.         dohangup = 0;        /* again unless requested again. */
  900.     }
  901. #ifdef SUNX25
  902.     if (dox25clr) {            /* If X.25 clear requested */
  903.         x25clear();            /* do that. */
  904.         initpad();
  905.         dox25clr = 0;        /* But only once. */
  906.     }
  907. #endif /* SUNX25 */
  908.     if (!quiet)
  909.       printf("(Back at %s)", *myhost ? myhost : "local UNIX system");
  910.     printf("\n");
  911.     what = W_NOTHING;        /* So console modes set right. */
  912. #ifndef NOCSETS
  913.     language = langsv;        /* Restore language */
  914. #endif /* NOCSETS */
  915.     parent_id = (PID_T) 0;
  916. #ifdef DYNAMIC
  917.     if (temp) free(temp);        /* Free allocated memory */
  918.     if (ibuf) free(ibuf);
  919.     if (obuf) free(obuf);
  920. #endif /* DYNAMIC */
  921.     return(1);
  922.  
  923.     } else {                /* Inferior reads, prints port input */
  924.  
  925.     if (priv_can()) {        /* Cancel all privs */
  926.         printf("?setuid error - fatal\n");
  927.         doexit(BAD_EXIT,-1);
  928.     }
  929.     signal(SIGINT, SIG_IGN);    /* In case these haven't been */
  930.     signal(SIGQUIT, SIG_IGN);    /* inherited from above... */
  931.  
  932.     inshift = outshift = 0;        /* Initial SO/SI shift state. */
  933.     sleep(1);            /* Wait for parent's handler setup.  */
  934.     ibp = ibuf;            /* Initialize input buffering */
  935.     ibc = 0;            /* And output buffering. */
  936.     obp = obuf;
  937.     obc = 0;
  938.     debug(F100,"CONNECT starting port fork","",0);
  939.     while (1) {            /* Fresh read, wait for a character. */
  940. #ifdef SUNX25
  941.         if (network && (nettype == NET_SX25)) {
  942.         bzero(x25ibuf,sizeof(x25ibuf)) ;
  943.         if ((ibufl = ttxin(MAXIX25,x25ibuf)) < 0) {
  944.             if (ibufl == -2) {  /* PAD parms changes */
  945.             write(padpipe[1],padparms,MAXPADPARMS);
  946.             kill(parent_id,SIGUSR2);
  947.             } else {
  948.             if (!quiet)
  949.               printf("\r\nCommunications disconnect ");
  950.             kill(parent_id,SIGUSR1);
  951.             }
  952.             pause();
  953.         }
  954.         if (debses) {        /* Debugging output */
  955.             p = x25ibuf ;
  956.                         while (ibufl--) { c = *p++; conol(dbchr(c)); }
  957.         } else {
  958.             if (sosi
  959. #ifndef NOCSETS
  960.             || tcsl != tcsr
  961. #endif /* NOCSETS */
  962.             ) { /* Character at a time */
  963.             for (i = 1; i < ibufl; i++) {
  964.                 c = x25ibuf[i] & cmask;
  965.                 if (sosi) { /* Handle SI/SO */
  966.                 if (c == SO) {
  967.                     inshift = 1;
  968.                     continue;
  969.                 } else if (c == SI) {
  970.                     inshift = 0;
  971.                     continue;
  972.                 }
  973.                 if (inshift)
  974.                   c |= 0200;
  975.                 }
  976. #ifndef NOCSETS
  977. #ifndef SKIPESC
  978.             /* Translate character sets */
  979.             if (sxo) c = (*sxo)(c); /* From local to intermediate. */
  980.             if (rxo) c = (*rxo)(c); /* From intermediate to remote. */
  981.  
  982. #else /* Skipping escape sequences... */
  983.  
  984.             if (inesc == ES_NORMAL) { /* If not inside escape seq.. */
  985.             /* Translate character sets */
  986.             if (sxo) c = (*sxo)(c); /* Local to intermediate. */
  987.             if (rxo) c = (*rxo)(c); /* Intermediate to remote. */
  988.             }
  989.             if (skipesc) chkaes(c); /* Check escape sequence status */
  990. #endif /* SKIPESC */
  991. #endif /* NOCSETS */
  992.                 c &= cmdmsk; /* Apply command mask. */
  993.                 conoc(c);    /* Output to screen */
  994.                 logchar(c);  /* and session log */
  995.             }
  996.             } else {         /* All at once */
  997.             for (i = 1; i < ibufl; i++)
  998.               x25ibuf[i] &= (cmask & cmdmsk);
  999.             conxo(ibufl,x25ibuf);
  1000.             if (seslog) zsoutx(ZSFILE,x25ibuf,ibufl);
  1001.             }
  1002.         }
  1003.         continue;
  1004.  
  1005.         } else {            /* Not X.25... */
  1006. #endif /* SUNX25 */
  1007. /*
  1008.   Get the next communication line character from our internal buffer.
  1009.   If the buffer is empty, refill it.
  1010. */
  1011.         c = ckcgetc(0);        /* Get next character */
  1012.         /* debug(F101,"CONNECT c","",c); */
  1013.         if (c < 0) {
  1014.             if (!quiet) {    /* Failed... */
  1015.             printf("\r\nCommunications disconnect ");
  1016.             if ( c == -3
  1017. #ifdef UTEK
  1018. /* This happens on UTEK if there's no carrier */
  1019.                 && errno != EWOULDBLOCK
  1020. #endif /* UTEK */
  1021.                 )
  1022.               perror("\r\nCan't read character");
  1023.             }
  1024. #ifdef NOSETBUF
  1025.             fflush(stdout);
  1026. #endif /* NOSETBUF */
  1027.             tthang();        /* Hang up the connection */
  1028.             kill(parent_id,SIGUSR1); /* Notify parent */
  1029.             for (;;) pause();    /* and wait to be killed */
  1030.         }
  1031.         debug(F101,"** PORT","",c);
  1032. #ifdef TNCODE
  1033.         /* Handle TELNET negotiations here */    
  1034.         if (c == IAC && network && ttnproto == NP_TELNET) {
  1035.             ckcputf();        /* Dump output buffer */
  1036.             if ((tx = tn_doop((CHAR)(c & 0xff),duplex,ckcgetc)) == 0) {
  1037.             continue;
  1038.             } else if (tx == -1) { /* I/O error */
  1039.             if (!quiet)
  1040.               printf("\r\nCommunications disconnect ");
  1041. #ifdef NOSETBUF
  1042.             fflush(stdout);
  1043. #endif /* NOSETBUF */
  1044.             kill(parent_id,SIGUSR1); /* Notify parent. */
  1045.             for (;;) pause(); /* Wait to be killed. */
  1046.             } else if ((tx == 1) && (!duplex)) { /* ECHO change */
  1047.             kill(parent_id,SIGUSR2); /* Tell the parent fork */
  1048.             duplex = 1;
  1049.             } else if ((tx == 2) && (duplex)) { /* ECHO change */
  1050.             kill(parent_id,SIGUSR2); 
  1051.             duplex = 0;
  1052.             } else if (tx == 3) { /* Quoted IAC */
  1053.             c = 255;
  1054.             } else continue;    /* Negotiation OK, get next char. */
  1055.         }
  1056. #endif /* TNCODE */
  1057.         if (debses) {        /* Output character to screen */
  1058.             char *s;        /* Debugging display... */
  1059.             s = dbchr(c);
  1060.             while (*s)
  1061.               ckcputc(*s++);
  1062.         } else {        /* Regular display ... */
  1063.             c &= cmask;        /* Apply Kermit-to-remote mask */
  1064.             if (sosi) {        /* Handle SI/SO */
  1065.             if (c == SO) {    /* Shift Out */
  1066.                 inshift = 1;
  1067.                 continue;
  1068.             } else if (c == SI) { /* Shift In */
  1069.                 inshift = 0;
  1070.                 continue;
  1071.             }
  1072.             if (inshift) c |= 0200; 
  1073.             }
  1074. #ifndef NOCSETS
  1075. #ifndef SKIPESC
  1076.             /* Translate character sets */
  1077.             if (sxi) c = (*sxi)((CHAR)c);
  1078.             if (rxi) c = (*rxi)((CHAR)c);
  1079. #else
  1080.             if (inesc == ES_NORMAL) {
  1081.             /* Translate character sets */
  1082.             if (sxi) c = (*sxi)((CHAR)c);
  1083.             if (rxi) c = (*rxi)((CHAR)c);
  1084.             }
  1085.             /* Adjust escape sequence status */
  1086.             if (skipesc) chkaes((char)c);
  1087. #endif /* SKIPESC */
  1088. #endif /* NOCSETS */
  1089.             c &= cmdmsk;    /* Apply command mask. */
  1090.             if (c == CR && tt_crd) { /* SET TERM CR-DISPLAY CRLF ? */
  1091.             ckcputc(c);         /* Yes, output CR */
  1092.             if (seslog) logchar((char)c);
  1093.             c = LF;             /* and insert a linefeed */
  1094.             }
  1095.             ckcputc(c);        /* Output character to screen */
  1096.             if (seslog) logchar((char)c); /* Do session log */
  1097.         }
  1098. #ifdef SUNX25
  1099.         }   
  1100. #endif /* SUNX25 */    
  1101.     }
  1102.     }
  1103. }
  1104.  
  1105.  
  1106. /*  H C O N N E  --  Give help message for connect.  */
  1107.  
  1108. int
  1109. hconne() {
  1110.     int c;
  1111.     static char *hlpmsg[] = {
  1112. "\r\n  ? for this message",
  1113. "\r\n  0 (zero) to send a null",
  1114. "\r\n  B to send a BREAK",
  1115. #ifdef CK_LBRK
  1116. "\r\n  L to send a Long BREAK",
  1117. #endif /* CK_LBRK */
  1118. #ifdef NETCONN
  1119. "\r\n  I to send a network interrupt packet",
  1120. #ifdef TCPSOCKET
  1121. "\r\n  A to send Are You There?",
  1122. #endif /* TCPSOCKET */
  1123. #ifdef SUNX25
  1124. "\r\n  R to reset X.25 virtual circuit",
  1125. #endif /* SUNX25 */
  1126. #endif /* NETCONN */
  1127. "\r\n  H to hangup and close the connection",
  1128. "\r\n  Q to hangup and quit Kermit",
  1129. "\r\n  S for status",
  1130. "\r\n  ! to push to local shell",
  1131. "\r\n  Z to suspend",
  1132. "\r\n  \\ backslash code:",
  1133. "\r\n    \\nnn  decimal character code",
  1134. "\r\n    \\Onnn octal character code",
  1135. "\r\n    \\Xhh  hexadecimal character code",
  1136. "\r\n    terminate with carriage return.",
  1137. "\r\n Type the escape character again to send the escape character, or",
  1138. "\r\n press the space-bar to resume the CONNECT command.\r\n\r\n",
  1139. "" };
  1140.     conol("\r\nPress C to return to ");
  1141.     conol(*myhost ? myhost : "the C-Kermit prompt");
  1142.     conol(", or:");
  1143.     conola(hlpmsg);            /* Print the help message. */
  1144.     conol("Command>");            /* Prompt for command. */
  1145.     c = congks(0) & 0177;        /* Get character, strip any parity. */
  1146.     /* No key mapping or translation here */
  1147.     if (c != CMDQ)
  1148.       conoll("");
  1149.     return(c);                /* Return it. */
  1150. }
  1151.  
  1152.  
  1153. /*  D O E S C  --  Process an escape character argument  */
  1154.  
  1155. VOID
  1156. #ifdef CK_ANSIC
  1157. doesc(char c)
  1158. #else
  1159. doesc(c) char c;
  1160. #endif /* CK_ANSIC */
  1161. /* doesc */ {
  1162.     CHAR d;
  1163.   
  1164.     while (1) {
  1165.     if (c == escape) {        /* Send escape character */
  1166.         d = dopar((CHAR) c); ttoc((char) d); return;
  1167.         } else                /* Or else look it up below. */
  1168.         if (isupper(c)) c = tolower(c);
  1169.  
  1170.     switch(c) {
  1171.  
  1172.     case 'c':            /* Escape back to prompt */
  1173.     case '\03':
  1174.         active = 0; conol("\r\n"); return;
  1175.  
  1176.     case 'b':            /* Send a BREAK signal */
  1177.     case '\02':
  1178.         ttsndb(); return;
  1179.  
  1180. #ifdef NETCONN
  1181.     case 'i':            /* Send Interrupt */
  1182.     case '\011':
  1183. #ifdef TCPSOCKET
  1184. #ifndef IP
  1185. #define IP 244
  1186. #endif /* IP */
  1187.         if (network && ttnproto == NP_TELNET) { /* TELNET */
  1188.         temp[0] = IAC;        /* I Am a Command */
  1189.         temp[1] = IP;        /* Interrupt Process */
  1190.         temp[2] = NUL;
  1191.         ttol((CHAR *)temp,2);
  1192.         } else 
  1193. #endif /* TCPSOCKET */
  1194. #ifdef SUNX25
  1195.             if (network && (nettype == NET_SX25)) { /* X.25 */
  1196.         (VOID) x25intr(0);                /* X.25 interrupt packet */
  1197.         conol("\r\n");
  1198.         } else
  1199. #endif /* SUNX25 */
  1200.           conoc(BEL);
  1201.         return;
  1202.  
  1203. #ifdef TCPSOCKET
  1204.     case 'a':            /* "Are You There?" */
  1205.     case '\01':
  1206. #ifndef AYT
  1207. #define AYT 246
  1208. #endif /* AYT */
  1209.         if (network && ttnproto == NP_TELNET) {
  1210.         temp[0] = IAC;        /* I Am a Command */
  1211.         temp[1] = AYT;        /* Are You There? */
  1212.         temp[2] = NUL;
  1213.         ttol((CHAR *)temp,2);
  1214.         } else conoc(BEL);
  1215.         return;
  1216. #endif /* TCPSOCKET */
  1217. #endif /* NETCONN */
  1218.  
  1219. #ifdef CK_LBRK
  1220.     case 'l':            /* Send a Long BREAK signal */
  1221.         ttsndlb(); return;
  1222. #endif /* CK_LBRK */
  1223.  
  1224.     case 'h':            /* Hangup */
  1225.      /*    case '\010': */            /* No, too dangerous */
  1226. #ifdef SUNX25
  1227.             if (network && (nettype == NET_SX25)) dox25clr = 1;
  1228.             else
  1229. #endif /* SUNX25 */
  1230.         dohangup = 2; active = 0; conol("\r\nHanging up "); return;
  1231.  
  1232. #ifdef SUNX25
  1233.         case 'r':                       /* Reset the X.25 virtual circuit */
  1234.         case '\022':
  1235.             if (network && (nettype == NET_SX25)) (VOID) x25reset();
  1236.             conol("\r\n"); return;
  1237. #endif /* SUNX25 */
  1238.  
  1239.     case 'q':            /* Quit */
  1240.         quitnow = 1; active = 0; conol("\r\n"); return;
  1241.  
  1242.     case 's':            /* Status */
  1243.         sprintf(temp,
  1244.             "\r\nConnected %s %s", network ? "to" : "through", ttname);
  1245.         conol(temp);
  1246. #ifdef SUNX25
  1247.             if (network && (nettype == NET_SX25)) {
  1248.                 sprintf(temp,", Link ID %d, LCN %d",linkid,lcn); conol(temp);
  1249.         }
  1250. #endif /* SUNX25 */
  1251.         if (speed >= 0L) {
  1252.         sprintf(temp,", speed %ld", speed);
  1253.         conoll(temp);
  1254.         } else conoll("");
  1255.         sprintf(temp,
  1256.             "Terminal bytesize: %d, Command bytesize: %d, Parity: ",
  1257.             (cmask  == 0177) ? 7 : 8,
  1258.             (cmdmsk == 0177) ? 7 : 8 );
  1259.         conol(temp);
  1260.  
  1261.         switch (parity) {
  1262.           case  0:  conoll("none");  break;
  1263.           case 'e': conoll("even");  break;
  1264.           case 'o': conoll("odd");   break;
  1265.           case 's': conoll("space"); break;
  1266.           case 'm': conoll("mark");  break;
  1267.         }
  1268.         sprintf(temp,"Terminal echo: %s", duplex ? "local" : "remote");
  1269.         conoll(temp);
  1270.         if (seslog) {
  1271.         conol("Logging to: "); conoll(sesfil);
  1272.             }
  1273.         if (!network) shomdm();
  1274.         return;
  1275.  
  1276.     case '?':            /* Help */
  1277.         c = hconne(); continue;
  1278.  
  1279.     case '0':            /* Send a null */
  1280.         c = '\0'; d = dopar((CHAR) c); ttoc((char) d); return;
  1281.  
  1282. #ifndef NOPUSH
  1283.     case 'z': case '\032':        /* Suspend */
  1284.         stptrap(0); return;
  1285.  
  1286.     case '@':            /* Start inferior command processor */
  1287.     case '!':
  1288.         conres();            /* Put console back to normal */
  1289.         zshcmd("");            /* Fork a shell. */
  1290.         if (conbin((char)escape) < 0) {
  1291.         printf("Error resuming CONNECT session\n");
  1292.         active = 0;
  1293.         }
  1294.         return;
  1295. #endif /* NOPUSH */
  1296.  
  1297.     case SP:            /* Space, ignore */
  1298.         return;
  1299.  
  1300.     default:            /* Other */
  1301.         if (c == CMDQ) {        /* Backslash escape */
  1302.         int x;
  1303.         kbp = kbuf;
  1304.         *kbp++ = c;
  1305.         while (((c = (congks(0) & cmdmsk)) != '\r') && (c != '\n'))
  1306.           *kbp++ = c;
  1307.         *kbp = NUL; kbp = kbuf;
  1308.         x = xxesc(&kbp);    /* Interpret it */
  1309.         if (x >= 0) {        /* No key mapping here */
  1310.             c = dopar((CHAR) x);
  1311.             ttoc((char) c);
  1312.             return;
  1313.         } else {        /* Invalid backslash code. */
  1314.             conoc(BEL);
  1315.             return;
  1316.         }
  1317.         }
  1318.         conoc(BEL); return;     /* Invalid esc arg, beep */
  1319.         }
  1320.     }
  1321. }
  1322.  
  1323. VOID
  1324. #ifdef CK_ANSIC
  1325. logchar(char c)
  1326. #else
  1327. logchar(c) char c;
  1328. #endif /* CK_ANSIC */
  1329. /* logchar */ {            /* Log character c to session log */
  1330.     if (seslog) 
  1331.       if ((sessft != 0) ||
  1332.       (c != '\r' &&
  1333.        c != '\0' &&
  1334.        c != XON &&
  1335.        c != XOFF))
  1336.     if (zchout(ZSFILE,c) < 0) {
  1337.         conoll("");
  1338.         conoll("ERROR WRITING SESSION LOG, LOG CLOSED!");
  1339.         seslog = 0;
  1340.     }
  1341. }
  1342.