home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / ckc190.zip / ckdcon.c < prev    next >
C/C++ Source or Header  |  1994-09-18  |  47KB  |  1,123 lines

  1. char *connv = "CONNECT Command for DG AOS/VS, 5A(046) 15 Sep 94";
  2.  
  3. /*  C K D C O N  --  Dumb terminal connection to remote system, for AOS/VS */
  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, copy, or
  10.  redistribute this software so long as it is not sold for profit, provided this
  11.  copyright notice is retained. 
  12. */
  13.  
  14. /* This module brought up to 5A by Eugenia Harris at Data General. */
  15.  
  16. #nolist
  17. #include "ckcdeb.h"                     /* Common things first */
  18. #include <signal.h>                     /* Signals */
  19. #include <errno.h>                      /* Error numbers */
  20. #include <setjmp.h>
  21.  
  22. /* Kermit-specific includes */
  23.  
  24. #include "ckcasc.h"                     /* ASCII characters */
  25. #include "ckcker.h"                     /* Kermit things */
  26. #include "ckucmd.h"                     /* For xxesc() prototype */
  27. #include "ckcnet.h"                     /* Network symbols */
  28. #ifndef NOCSETS
  29. #include "ckcxla.h"                     /* Character set translation */
  30. #endif /* NOCSETS */
  31.  
  32. #ifdef datageneral
  33. #include <sgtty.h>
  34. #include <multitask.h>
  35. #include <packets:normal_io.h>
  36. #list
  37.  
  38. extern short idel_tbl[7] = {0x4,0,0,0,0,0,0};   /* delimiter table -- */
  39.                                                 /* defaults to CR only*/
  40. /* Globals and defines for DG multi-tasking connect command */
  41. void readfromcommline();                        /* listener sub-task */
  42. extern int ttyfd,ttyfdout;
  43. #define TASKID      17                  /* task id of readfromcommline task */
  44. #define TASKPRI   200                 /* priority of readfromcommline (was 2) */
  45. #define STACK       02000               /* default stack size (was 0) */
  46. #define MAXINBUF    2048
  47. static int inbufsize = MAXINBUF;
  48. extern long times();
  49. #endif /* datageneral */
  50.  
  51. /* Internal function prototypes */
  52.  
  53. _PROTOTYP( VOID doesc, (char) );
  54. _PROTOTYP( VOID logchar, (char) );
  55. _PROTOTYP( int hconne, (void) );
  56.  
  57. #ifndef SIGUSR1                         /* User-defined signals */
  58. #define SIGUSR1 30
  59. #endif /* SIGUSR1 */
  60.  
  61. #ifndef SIGUSR2
  62. #define SIGUSR2 31
  63. #endif /* SIGUSR2 */
  64.  
  65. /* External variables */
  66.  
  67. extern int local, escape, duplex, parity, flow, seslog, sessft, debses,
  68.  mdmtyp, ttnproto, cmask, cmdmsk, network, nettype, deblog, sosi, tnlm,
  69.  xitsta, what, ttyfd, quiet, backgrd, tt_crd, tn_nlm;
  70. extern long speed;
  71. extern char ttname[], sesfil[], myhost[],*ccntab[];
  72.  
  73. #ifndef NOSETKEY                        /* Keyboard mapping */
  74. extern KEY *keymap;                     /* Single-character key map */
  75. extern MACRO *macrotab;                 /* Key macro pointer table */
  76. static MACRO kmptr = NULL;              /* Pointer to current key macro */
  77. #endif /* NOSETKEY */
  78.  
  79. /* Global variables local to this module */
  80.  
  81. static int quitnow = 0,                 /* <esc-char>Q was typed */
  82.   dohangup = 0,                         /* <esc-char>H was typed */
  83.   sjval = 0,                            /* Setjump return value */
  84.   goterr = 0,                           /* I/O error flag */
  85.   active = 0,                           /* Lower fork active flag */
  86.   inshift = 0;                          /* SO/SI shift state */
  87.   outshift = 0;
  88.  
  89. static char kbuf[10], *kbp;             /* Keyboard buffer & pointer */
  90. static PID_T parent_id = (PID_T)0;      /* Process id of main task */
  91.  
  92. static char *ibp;                       /* Input buffer pointer */
  93. static int ibc = 0;                     /* Input buffer count */
  94. #define IBUFL 4096                      /* Input buffer length */
  95.  
  96. static char *obp;                       /* Output buffer pointer */
  97. static int obc = 0;                     /* Output buffer count */
  98. #define OBUFL 1024                      /* Output buffer length */
  99.  
  100. #define TMPLEN 200                      /* Temp buffer length */
  101.  
  102. #ifdef DYNAMIC
  103. static char *ibuf, *obuf, *temp;        /* Input, output, & temp buffers */
  104. #else
  105. static char ibuf[IBUFL], obuf[OBUFL], temp[TMPLEN];
  106. #endif /* DYNAMIC */
  107.  
  108. /* Character-set items */
  109.  
  110. #ifndef NOCSETS
  111. #ifdef CK_ANSIC /* ANSI C prototypes... */
  112. extern CHAR (*xls[MAXTCSETS+1][MAXFCSETS+1])(CHAR); /* Character set */
  113. extern CHAR (*xlr[MAXTCSETS+1][MAXFCSETS+1])(CHAR); /* translation functions */
  114. static CHAR (*sxo)(CHAR);       /* Local translation functions */
  115. static CHAR (*rxo)(CHAR);       /* for output (sending) terminal chars */
  116. static CHAR (*sxi)(CHAR);       /* and for input (receiving) terminal chars. */
  117. static CHAR (*rxi)(CHAR);
  118. #else /* Not ANSI C... */
  119. extern CHAR (*xls[MAXTCSETS+1][MAXFCSETS+1])(); /* Character set */
  120. extern CHAR (*xlr[MAXTCSETS+1][MAXFCSETS+1])(); /* translation functions. */
  121. static CHAR (*sxo)();           /* Local translation functions */
  122. static CHAR (*rxo)();           /* for output (sending) terminal chars */
  123. static CHAR (*sxi)();           /* and for input (receiving) terminal chars. */
  124. static CHAR (*rxi)();
  125. #endif /* CK_ANSIC */
  126. extern int language;            /* Current language. */
  127. static int langsv;              /* For remembering language setting. */
  128. extern struct csinfo fcsinfo[]; /* File character set info. */
  129. extern int tcsr, tcsl;          /* Terminal character sets, remote & local. */
  130. static int tcs;                 /* Intermediate ("transfer") character set. */
  131.  
  132. #ifndef NOESCSEQ
  133. /*
  134.   As of edit 178, the CONNECT command will skip past ANSI escape sequences
  135.   to avoid translating the characters within them.  This allows the CONNECT
  136.   command to work correctly when connected to a remote host that uses a
  137.   7-bit ISO 646 national character set, in which characters like '[' would
  138.   normally be translated into accented characters, ruining the terminal's
  139.   interpretation (and generation) of escape sequences.
  140.  
  141.   Escape sequences of non-ANSI/ISO-compliant terminals are not handled.
  142. */
  143. #ifndef SKIPESC
  144. #define SKIPESC
  145. #endif /* SKIPESC */
  146. /*
  147.   States for the escape-sequence recognizer.
  148. */
  149. #define ES_NORMAL 0                     /* Normal, not in escape sequence */
  150. #define ES_GOTESC 1                     /* Current character is ESC */
  151. #define ES_ESCSEQ 2                     /* Inside an escape sequence */
  152. #define ES_GOTCSI 3                     /* Inside a control sequence */
  153. #define ES_STRING 4                     /* Inside DCS,OSC,PM, or APC string */
  154. #define ES_TERMIN 5                     /* 1st char of string terminator */
  155.  
  156. static int
  157.   skipesc = 0,                          /* Skip over ANSI escape sequences */
  158.   inesc = ES_NORMAL;                    /* State of sequence recognizer */
  159. /*
  160.   ANSI escape sequence handling.  Only the 7-bit form is treated, because
  161.   translation is not a problem in the 8-bit environment, in which all GL
  162.   characters are ASCII and no translation takes place.  So we don't check
  163.   for the 8-bit single-character versions of CSI, DCS, OSC, APC, or ST.
  164.   Here is the ANSI sequence recognizer state table, followed by the code
  165.   that implements it.
  166.  
  167.   Definitions:
  168.     CAN = Cancel                       01/08         Ctrl-X
  169.     SUB = Substitute                   01/10         Ctrl-Z
  170.     DCS = Device Control Sequence      01/11 05/00   ESC P
  171.     CSI = Control Sequence Introducer  01/11 05/11   ESC [
  172.     ST  = String Terminator            01/11 05/12   ESC \
  173.     OSC = Operating System Command     01/11 05/13   ESC ]
  174.     PM  = Privacy Message              01/11 05/14   ESC ^
  175.     APC = Application Program Command  01/11 05/15   ESC _
  176.  
  177.   ANSI escape sequence recognizer:
  178.  
  179.     State    Input  New State  ; Commentary
  180.  
  181.     NORMAL   (start)           ; Start in NORMAL state
  182.  
  183.     (any)    CAN    NORMAL     ; ^X cancels
  184.     (any)    SUB    NORMAL     ; ^Z cancels
  185.  
  186.     NORMAL   ESC    GOTESC     ; Begin escape sequence
  187.     NORMAL   other             ; NORMAL control or graphic character
  188.  
  189.     GOTESC   ESC               ; Start again
  190.     GOTESC   [      GOTCSI     ; CSI
  191.     GOTESC   P      STRING     ; DCS introducer, consume through ST
  192.     GOTESC   ]      STRING     ; OSC introducer, consume through ST
  193.     GOTESC   ^      STRING     ; PM  introducer, consume through ST
  194.     GOTESC   _      STRING     ; APC introducer, consume through ST
  195.     GOTESC   0..~   NORMAL     ; 03/00 through 17/14 = Final character
  196.     GOTESC   other  ESCSEQ     ; Intermediate or ignored control character
  197.  
  198.     ESCSEQ   ESC    GOTESC     ; Start again
  199.     ESCSEQ   0..~   NORMAL     ; 03/00 through 17/14 = Final character
  200.     ESCSEQ   other             ; Intermediate or ignored control character
  201.  
  202.     GOTCSI   ESC    GOTESC     ; Start again
  203.     GOTCSI   @..~   NORMAL     ; 04/00 through 17/14 = Final character
  204.     GOTCSI   other             ; Intermediate char or ignored control char
  205.  
  206.     STRING   ESC    TERMIN     ; Maybe have ST
  207.     STRING   other             ; Consume all else
  208.  
  209.     TERMIN   \      NORMAL     ; End of string
  210.     TERMIN   other  STRING     ; Still in string
  211. */
  212. /*
  213.   chkaes() -- Check ANSI Escape Sequence.
  214.   Call with EACH character in input stream.
  215.   Sets global inesc variable according to escape sequence state.
  216. */
  217. VOID
  218. #ifdef CK_ANSIC
  219. chkaes(char c)
  220. #else
  221. chkaes(c) char c;
  222. #endif /* CK_ANSIC */
  223. /* chkaes */ {
  224.  
  225.     if (c == CAN || c == SUB)           /* CAN and SUB cancel any sequence */
  226.       inesc = ES_NORMAL;
  227.     else                                /* Otherwise */
  228.       switch (inesc) {                  /* enter state switcher */
  229.  
  230.         case ES_NORMAL:                 /* NORMAL state */
  231.           if (c == ESC)                 /* Got an ESC */
  232.             inesc = ES_GOTESC;          /* Change state to GOTESC */
  233.           break;                        /* Otherwise stay in NORMAL state */
  234.  
  235.         case ES_GOTESC:                 /* GOTESC state */
  236.           if (c == '[')                 /* Left bracket after ESC is CSI */
  237.             inesc = ES_GOTCSI;          /* Change to GOTCSI state */
  238.           else if (c > 057 && c < 0177) /* Final character '0' thru '~' */
  239.             inesc = ES_NORMAL;          /* Back to normal */
  240.           else if (c == 'P' || (c > 0134 && c < 0140)) /* P, [, ^, or _ */
  241.             inesc = ES_STRING;          /* Switch to STRING-absorption state */
  242.           else if (c != ESC)            /* ESC in an escape sequence... */
  243.             inesc = ES_ESCSEQ;          /* starts a new escape sequence */
  244.           break;                        /* Intermediate or ignored ctrl char */
  245.  
  246.         case ES_ESCSEQ:                 /* ESCSEQ -- in an escape sequence */
  247.           if (c > 057 && c < 0177)      /* Final character '0' thru '~' */
  248.             inesc = ES_NORMAL;          /* Return to NORMAL state. */
  249.           else if (c == ESC)            /* ESC ... */
  250.             inesc = ES_GOTESC;          /* starts a new escape sequence */
  251.           break;                        /* Intermediate or ignored ctrl char */
  252.  
  253.         case ES_GOTCSI:                 /* GOTCSI -- In a control sequence */
  254.           if (c > 077 && c < 0177)      /* Final character '@' thru '~' */
  255.             inesc = ES_NORMAL;          /* Return to NORMAL. */
  256.           else if (c == ESC)            /* ESC ... */
  257.             inesc = ES_GOTESC;          /* starts over. */
  258.           break;                        /* Intermediate or ignored ctrl char */
  259.  
  260.         case ES_STRING:                 /* Inside a string */
  261.           if (c == ESC)                 /* ESC may be 1st char of terminator */
  262.             inesc = ES_TERMIN;          /* Go see. */
  263.           break;                        /* Absorb all other characters. */
  264.  
  265.         case ES_TERMIN:                 /* May have a string terminator */
  266.           if (c == '\\')                /* which must be backslash */
  267.             inesc = ES_NORMAL;          /* If so, back to NORMAL */
  268.           else                          /* Otherwise */
  269.             inesc = ES_STRING;          /* Back to string absorption. */
  270.       }
  271. }
  272. #endif /* NOESCSEQ */
  273. #endif /* NOCSETS */
  274.  
  275. /* Connect state parent/child communication signal handlers */
  276.  
  277. static jmp_buf con_env;          /* Environment pointer for connect errors */
  278. /*
  279.   Note: Some C compilers (e.g. Cray UNICOS) interpret the ANSI C standard
  280.   about setjmp() in a way that disallows constructions like:
  281.  
  282.     if ((var = setjmp(env)) == 0) ...
  283.  
  284.   which prevents the value returned by longjmp() from being used at all.
  285.   So the following handlers set a global variable instead.
  286. */
  287. static
  288. SIGTYP
  289. conn_int(foo) int foo; {                /* Modem read failure handler, */
  290.     signal(SIGUSR1,SIG_IGN);            /* Disarm the interrupt */
  291.     sjval = 1;                          /* Set global variable */
  292.     longjmp(con_env,sjval);             /* Notifies parent process to stop */
  293. }
  294.  
  295. static
  296. SIGTYP
  297. mode_chg(foo) int foo; {
  298.  
  299.     signal(SIGUSR2,mode_chg);       /* Re-arm the signal. */
  300.     duplex = 1 - duplex;            /* Toggle duplex mode. */
  301.     debug(F101,"mode_chg duplex","",duplex);
  302. }
  303.  
  304. /*  C K C P U T F  --  C-Kermit CONNECT Put Character to Screen  */
  305. /*
  306.   Output is buffered to avoid slow screen writes on fast connections.
  307. */
  308. int
  309. ckcputf() {                             /* Dump the output buffer */
  310.     int x = 0;
  311.     if (obc > 0)                        /* If we have any characters, */
  312.       x = conxo(obc,obuf);              /* dump them, */
  313.     obp = obuf;                         /* reset the pointer */
  314.     obc = 0;                            /* and the counter. */
  315.     return(x);                          /* Return conxo's return code */
  316. }
  317.  
  318. /*  C K C P U T C  --  C-Kermit CONNECT Put Character to Screen  */
  319. /*
  320.   Output is buffered to avoid slow screen writes on fast connections.
  321. */
  322. int
  323. ckcputc(c) int c; {
  324.     int x;
  325.  
  326.     *obp++ = c & 0xff;                  /* Deposit the character */
  327.     obc++;                              /* Count it */
  328.     if (ibc == 0 ||                     /* If input buffer empty */
  329.         obc == OBUFL) {                 /* or output buffer full */
  330.         debug(F101,"CKCPUTC obc","",obc);
  331.         x = conxo(obc,obuf);            /* dump the buffer, */
  332.         obp = obuf;                     /* reset the pointer */
  333.         obc = 0;                        /* and the counter. */
  334.         return(x);                      /* Return conxo's return code */
  335.     } else return(0);
  336. }
  337.  
  338. /*  C K C G E T C  --  C-Kermit CONNECT Get Character  */
  339. /*
  340.   Buffered read from communication device.
  341.   Returns the next character, refilling the buffer if necessary.
  342.   On error, returns ttinc's return code (see ttinc() description).
  343.   Dummy argument for compatible calling conventions with ttinc().
  344. */
  345. int
  346. ckcgetc(dummy) int dummy; {
  347.     int c, n;
  348.  
  349.     debug(F101,"CKCGETC 1 ibc","",ibc); /* Log */
  350.     if (ibc < 1) {                      /* Need to refill buffer? */
  351.         ibc = 0;                        /* Yes, reset count */
  352.         ibp = ibuf;                     /* and buffer pointer */
  353.         debug(F100,"CKCGETC 1 calling ttinc(0)","",0); /* Log */
  354.         c = ttinc(0);                   /* Read one character, blocking */
  355.         debug(F101,"CKCGETC 1 ttinc(0)","",c); /* Log */
  356.         if (c < 0) {                    /* If error, return error code */
  357.             return(c);
  358.         } else {                        /* Otherwise, got one character */
  359.             *ibp++ = c;                 /* Advance buffer pointer */
  360.             ibc++;                      /* and count. */
  361.         }
  362.  
  363.         /* Now quickly read any more that might have arrived */
  364.  
  365.         if ((n = ttchk()) > 0) {        /* Any more waiting? */
  366.             if (n > (IBUFL - ibc))      /* Get them all at once. */
  367.               n = IBUFL - ibc;          /* Don't overflow buffer */
  368.             if ((n = ttxin(n,(CHAR *)ibp)) > 0) {
  369.                 ibp += n;               /* Advance pointer */
  370.                 ibc += n;               /* and counter */
  371.             } else return (-1);
  372.         }
  373.         debug(F101,"CKCGETC 2 ibc","",ibc); /* Log how many */
  374.         ibp = ibuf;
  375.     }
  376.     c = *ibp++ & 0xff;                  /* Get next character from buffer */
  377.     ibc--;                              /* Reduce buffer count */
  378.     return(c);                          /* Return the character */
  379. }
  380.  
  381. /*  C O N E C T  --  Perform terminal connection  */
  382.  
  383. int
  384. conect() {
  385.     PID_T pid;                  /* Process id of child (modem reader) */
  386.     int n;                      /* General purpose counter */
  387.     int c;                      /* c is a character, but must be signed 
  388.                                    integer to pass thru -1, which is the
  389.                                    modem disconnection signal, and is
  390.                                    different from the character 0377 */
  391.     int c2;                     /* A copy of c */
  392.     int csave;                  /* Another copy of c */
  393.     int num;                    /* Another counter - used with dgncinb() */
  394.     char ch;                    /* Ditto here */
  395.  
  396. #ifdef DYNAMIC
  397.     if (!(ibuf = malloc(IBUFL+1))) {    /* Allocate input line buffer */
  398.         printf("Sorry, CONNECT input buffer can't be allocated\n");
  399.         return(0);
  400.     }
  401.     if (!(obuf = malloc(OBUFL+1))) {    /* Allocate input line buffer */
  402.         printf("Sorry, CONNECT output buffer can't be allocated\n");
  403.         free(ibuf); ibuf = 0;
  404.         return(0);
  405.     }
  406.     if (!(temp = malloc(TMPLEN+1))) {    /* Allocate temporary buffer */
  407.         printf("Sorry, CONNECT temporary buffer can't be allocated\n");
  408.         free(ibuf); ibuf = 0;
  409.         free(obuf); obuf = 0;
  410.         return(0);
  411.     }
  412. #endif /* DYNAMIC */
  413.  
  414.     if (!local) {
  415. #ifdef NETCONN
  416.         printf("Sorry, you must SET LINE or SET HOST first\n");
  417. #else
  418.         printf("Sorry, you must SET LINE first\n");
  419. #endif /* NETCONN */
  420.         return(0);
  421.     }
  422.     if (backgrd) {
  423.         printf(
  424. "\r\nSorry, Kermit's CONNECT command can be used only in the foreground\r\n");
  425.         return(0);
  426.     }
  427.     if (speed < 0L && network == 0) {
  428.         printf("Sorry, you must SET SPEED first\n");
  429.         return(0);
  430.     }
  431. #ifdef TCPSOCKET
  432.     if (network && (nettype != NET_TCPB)) {
  433.         printf("Sorry, network type not supported\n");
  434.         return(0);
  435.     }
  436. #endif /* TCPSOCKET */
  437.  
  438.  
  439.     if (ttyfd < 0) {                    /* If communication device not open */
  440.         debug(F111,"ckdcon opening",ttname,0); /* Open it now */
  441.         if (ttopen(ttname,&local,mdmtyp,0) < 0) {
  442.             sprintf(temp,"Sorry, can't open %s",ttname);
  443.             perror(temp);
  444.             debug(F110,"ckdcon open failure",temp,0);
  445. #ifdef DYNAMIC
  446.             if (ibuf) free(ibuf); ibuf = 0;
  447.             if (obuf) free(obuf); obuf = 0;
  448.             if (temp) free(temp); temp = 0;
  449. #endif /* DYNAMIC */
  450.             return(0);
  451.         }
  452.     }
  453.     dohangup = 0;                       /* Hangup not requested yet */
  454.     if (!quiet) {
  455. #ifdef NETCONN
  456.         if (network) {
  457.             printf("Connecting to host %s",ttname);
  458.         } else {
  459. #endif /* NETCONN */
  460.             printf("Connecting to %s",ttname);
  461.             if (speed > -1L) printf(", speed %ld",speed);
  462. #ifdef NETCONN
  463.         }
  464. #endif /* NETCONN */
  465.         printf(".\r\nThe escape character is %s (ASCII %d).\r\n",
  466.                dbchr(escape),escape);
  467.         printf("Type the escape character followed by C to get back,\r\n");
  468.         printf("or followed by ? to see other options.\r\n");
  469.         if (seslog) {
  470.             printf("(Session logged to %s, ",sesfil);
  471.             printf("%s)\r\n", sessft ? "binary" : "text");
  472.         }
  473.         if (debses) printf("Debugging Display...)\r\n");
  474.     }
  475.  
  476. /* Condition console terminal and communication line */     
  477.  
  478.     if (conbin(escape) < 0) {
  479.         printf("Sorry, can't condition console terminal\n");
  480. #ifdef DYNAMIC
  481.             if (ibuf) free(ibuf); ibuf = 0;
  482.             if (obuf) free(obuf); obuf = 0;
  483.             if (temp) free(temp); temp = 0;
  484. #endif /* DYNAMIC */
  485.         return(0);
  486.     }
  487.     debug(F101,"connect cmask","",cmask);
  488.     debug(F101,"connect cmdmsk","",cmdmsk);
  489.     goterr = 0;
  490.     if ((n = ttvt(speed,flow)) < 0) {   /* Enter "virtual terminal" mode */
  491.         debug(F101,"CONNECT ttvt","",n);
  492.         goterr = 1;                     /* Error recovery... */
  493.         tthang();                       /* Hang up and close the device. */
  494.         ttclos(0);
  495.         if (ttopen(ttname,&local,mdmtyp,0) < 0) { /* Open it again... */
  496.             sprintf(temp,"Sorry, can't reopen %s",ttname);
  497.             perror(temp);
  498. #ifdef DYNAMIC
  499.             if (ibuf) free(ibuf); ibuf = 0;
  500.             if (obuf) free(obuf); obuf = 0;
  501.             if (temp) free(temp); temp = 0;
  502. #endif /* DYNAMIC */
  503.             return(0);
  504.         }
  505.         if (ttvt(speed,flow) < 0) {     /* Try virtual terminal mode again. */
  506.             conres();                   /* Failure this time is fatal. */
  507.             printf("Sorry, Can't condition communication line\n");
  508. #ifdef DYNAMIC
  509.             if (ibuf) free(ibuf); ibuf = 0;
  510.             if (obuf) free(obuf); obuf = 0;
  511.             if (temp) free(temp); temp = 0;
  512. #endif /* DYNAMIC */
  513.             return(0);
  514.         }
  515.     }
  516.     debug(F101,"connect ttvt ok, escape","",escape);
  517.  
  518. #ifndef NOCSETS
  519. /* Set up character set translations */
  520.  
  521.     tcs = gettcs(tcsr,tcsl);
  522.  
  523.     if (tcsr == tcsl) {                 /* Remote and local sets the same? */
  524.         sxo = rxo = NULL;               /* If so, no translation. */
  525.         sxi = rxi = NULL;
  526.     } else {                            /* Otherwise, set up */
  527.         sxo = xls[tcs][tcsl];           /* translation function */
  528.         rxo = xlr[tcs][tcsr];           /* pointers for output functions */
  529.         sxi = xls[tcs][tcsr];           /* and for input functions. */
  530.         rxi = xlr[tcs][tcsl];
  531.     }
  532. /*
  533.   This is to prevent use of zmstuff() and zdstuff() by translation functions.
  534.   They only work with disk i/o, not with communication i/o.  Luckily Russian
  535.   translation functions don't do any stuffing...
  536. */
  537.     langsv = language;
  538. #ifndef NOCYRIL
  539.     if (language != L_RUSSIAN)
  540. #endif /* NOCYRIL */
  541.       language = L_USASCII;
  542.  
  543. #ifdef SKIPESC
  544. /*
  545.   We need to activate the "skip escape sequence" feature when:
  546.   (a) translation is elected, and
  547.   (b) the local and/or remote set is 7-bit set other than US ASCII.
  548. */
  549.     skipesc = (tcs != TC_TRANSP) &&     /* Not transparent */
  550.       (fcsinfo[tcsl].size == 128 || fcsinfo[tcsr].size == 128) && /* 7 bits */
  551.         (fcsinfo[tcsl].code != FC_USASCII); /* But not ASCII */
  552.     inesc = ES_NORMAL;                  /* Initial state of recognizer */
  553. #ifdef COMMENT
  554.     debug(F101,"tcs","",tcs);
  555.     debug(F101,"tcsl","",tcsl);
  556.     debug(F101,"tcsr","",tcsr);
  557.     debug(F101,"fcsinfo[tcsl].size","",fcsinfo[tcsl].size);
  558.     debug(F101,"fcsinfo[tcsr].size","",fcsinfo[tcsr].size);
  559. #endif /* COMMENT */
  560.     debug(F101,"skipesc","",skipesc);
  561. #endif /* SKIPESC */
  562. #endif /* NOCSETS */
  563.  
  564. /*
  565.   This is a label we jump back to when the lower fork senses the need
  566.   to change modes.
  567. */
  568. newfork:
  569.  
  570.     debug(F100,"CONNECT starting readfromcommline task","",0);
  571.     parent_id = getpid();               /* Get pid for signalling */
  572.     signal(SIGUSR1,SIG_IGN);            /* Don't kill myself */
  573.  
  574. /* ENH - DG specifics inserted here - we do an mtask instead of a vfork */
  575. /* of the code that listens to the comm line and writes to the console  */
  576. /* -- that task is called readfromcommline */
  577.  
  578. /* ENH - commented next because timeouts should be handled with signals now */
  579. /*  setto(channel(ttyfdout),60); */     /* Set output timeouts to 60 seconds */
  580. /*  setto(channel(ttyfd),2);     */     /* Set input timeouts to 2 seconds */
  581.     mfinit(stdout,1);                   /* Protect output to terminal screen */
  582.     if (mtask(readfromcommline, STACK, TASKID, TASKPRI) != 0) {
  583.         conres();                       /* Reset the console. */
  584.         perror("Can't create readfromcommline fork");
  585.         if (!quiet) {
  586.         printf("\r\nCommunications disconnect (Back at %s)\r\n",
  587.                *myhost ? myhost : "local MV system");
  588.         }
  589.         printf("\n");
  590.         what = W_NOTHING;               /* So console modes are set right. */
  591. #ifndef NOCSETS
  592.         language = langsv;              /* Restore language */
  593. #endif /* NOCSETS */
  594.         parent_id = (PID_T) 0;          /* Clean up */
  595. #ifdef DYNAMIC
  596.             if (ibuf) free(ibuf); ibuf = 0;
  597.             if (obuf) free(obuf); obuf = 0;
  598.             if (temp) free(temp); temp = 0;
  599. #endif /* DYNAMIC */
  600.         return(1);
  601.     } else {       /* otherwise start reading from the keyboard (or script) */
  602.  
  603.         what = W_CONNECT;               /* Keep track of what we're doing */
  604.         active = 1;
  605.         debug(F101,"CONNECT mtask succeeded, duplex:","",duplex);
  606.  
  607.         /* Catch communication errors or mode changes in lower fork */
  608.  
  609.         if (setjmp(con_env) == 0) {     /* Normal entry... */
  610.             sjval = 0;                  /* Initialize setjmp return code. */
  611.             signal(SIGUSR1,conn_int);   /* Routine for child process exit. */
  612.             signal(SIGUSR2,mode_chg);   /* Routine for mode change. */
  613.         }
  614.  
  615. /*
  616.   Here is the big loop that gets characters from the keyboard and sends them
  617.   out the communication device.  There are two components to the communication
  618.   path: the connection from the keyboard to C-Kermit, and from C-Kermit to
  619.   the remote computer.  The treatment of the 8th bit of keyboard characters
  620.   is governed by SET COMMAND BYTESIZE (cmdmsk).  The treatment of the 8th bit
  621.   of characters sent to the remote is governed by SET TERMINAL BYTESIZE
  622.   (cmask).   This distinction was introduced in edit 5A(164).
  623. */
  624.             while (active) {
  625. #ifndef NOSETKEY
  626.                 if (kmptr) {            /* Have current macro? */
  627.                     debug(F100,"kmptr non NULL","",0);
  628.                     if ((c = (CHAR) *kmptr++) == NUL) { /* Get char from it */
  629.                         kmptr = NULL;   /* If no more chars,  */
  630.                         debug(F100,"macro empty, continuing","",0);
  631.                         continue;       /* reset pointer and continue */
  632.                     }
  633.                     debug(F000,"char from macro","",c);
  634.                 } else                  /* No macro... */
  635. #endif /* NOSETKEY */
  636.                 setto(channel(0),2);    /* Set device timeout to 2 secs */
  637.                 while (active) {        /* Make sure connection still there */
  638.                     /* terrible kludge calling dgncinb() directly -- we do
  639.                        it so we can set the device timeout and thus prevent
  640.                        this read from hanging forever when the remote has
  641.                        disconnected -- all so that we'll pop back to the
  642.                        prompt when the disconnect occurs
  643.                     */
  644.                     num = dgncinb(0,&ch,1); /* Get one keyboard char */
  645.                     if (num != 1) {
  646.                         if ((num == 0) || (num == -2)) /* Keep trying on */
  647.                             continue;                  /* timeout or none */
  648.                         else {                         /* Otherwise it's a*/
  649.                             c == -1;                   /* VS error or EOF */
  650.                             break;                     /* dealt w/ in a sec */
  651.                         }
  652.                     } else {
  653.                         c = ch & 0377;  /* Got a good one */
  654.                         break;          /* Get out of here */
  655.                     }
  656.                 }
  657.                 resto(channel(0));      /* Undo the device timeout */
  658.                 if (!active)            /* If remote disconnected */
  659.                     break;              /* Get out */
  660.                 if (c == -1) {          /* If read() got an error... */
  661.                     conoc(BEL);         /* Beep */
  662.                     break;              /* and terminate the read loop */
  663.                 }
  664.                 /* debug(F111,"** KEYB",dbchr(c),c); */
  665.                 c &= cmdmsk;            /* Do any requested masking */
  666. #ifndef NOSETKEY
  667. /*
  668.   Note: kmptr is NULL if we got character c from the keyboard, and it is
  669.   not NULL if it came from a macro.  In the latter case, we must avoid
  670.   expanding it again.
  671. */
  672.                 if (!kmptr && macrotab[c]) { /* Macro definition for c? */
  673.                     kmptr = macrotab[c];     /* Yes, set up macro pointer */
  674.                     continue;                /* and restart the loop, */
  675.                 } else c = keymap[c];        /* else use single-char keymap */
  676. #endif /* NOSETKEY */
  677.                 if (
  678.  
  679. #ifndef NOSETKEY
  680.                     !kmptr &&
  681. #endif /* NOSETKEY */
  682.                     ((c & 0x7f) == escape)) { /* Escape character? */
  683.                     debug(F000,"connect got escape","",c);
  684.                     c = congks(0) & 0177; /* Got esc, get its arg */
  685.                     /* No key mapping here */
  686.                     doesc(c);           /* Now process it */
  687.  
  688.                 } else {                /* It's not the escape character */
  689.                     csave = c;          /* Save it before translation */
  690.                                         /* for local echoing. */
  691. #ifndef NOCSETS
  692. #ifndef SKIPESC
  693.                     /* Translate character sets */
  694.                     if (sxo) c = (*sxo)(c); /* From local to intermediate. */
  695.                     if (rxo) c = (*rxo)(c); /* From intermediate to remote. */
  696. #else
  697.                     if (inesc == ES_NORMAL) { /* If not inside escape seq.. */
  698.                         /* Translate character sets */
  699.                         if (sxo) c = (*sxo)(c); /* Local to intermediate. */
  700.                         if (rxo) c = (*rxo)(c); /* Intermediate to remote. */
  701.                     }
  702.                     if (skipesc) chkaes(c); /* Check escape sequence status */
  703. #endif /* SKIPESC */
  704. #endif /* NOCSETS */
  705. /*
  706.  If Shift-In/Shift-Out is selected and we have a 7-bit connection,
  707.  handle shifting here.
  708. */
  709.                     if (sosi) {                    /* Shift-In/Out selected? */
  710.                         if (cmask == 0177) {       /* In 7-bit environment? */
  711.                             if (c & 0200) {        /* 8-bit character? */
  712.                                 if (outshift == 0) {    /* If not shifted, */
  713.                                     ttoc(dopar(SO));    /* shift. */
  714.                                     outshift = 1;
  715.                                 }
  716.                             } else {
  717.                                 if (outshift == 1) {    /* 7-bit character */
  718.                                     ttoc(dopar(SI));    /* If shifted, */
  719.                                     outshift = 0;       /* unshift. */
  720.                                 }
  721.                             }
  722.                         }
  723.                         if (c == SO) outshift = 1; /* User typed SO */
  724.                         if (c == SI) outshift = 0; /* User typed SI */
  725.                     }
  726.                     c &= cmask;         /* Apply Kermit-to-host mask now. */
  727.             if (c == '\015') {        /* Carriage Return */
  728.             int stuff = -1;
  729.             if (tnlm) {        /* TERMINAL NEWLINE ON */
  730.                 stuff = LF;     /* Stuff LF */
  731. #ifdef TNCODE
  732.             } else if (network &&    /* TELNET NEWLINE ON/OFF/RAW */
  733.                    (ttnproto == NP_TELNET) &&
  734.                    (tn_nlm != TNL_CR)) {
  735.                 stuff = (tn_nlm == TNL_CRLF) ? LF : NUL;
  736. #endif /* TNCODE */
  737.             }
  738.             if (stuff > -1) {
  739.                 ttoc(dopar('\015'));    /* Send CR */
  740.                 if (duplex) conoc('\015');    /* Maybe echo CR */
  741.                 c = stuff;            /* Char to stuff */
  742.                 csave = c;
  743.             }
  744.             }
  745. #ifdef TNCODE
  746. /* If user types the 0xff character (TELNET IAC), it must be doubled. */
  747.                     else
  748.                      if (dopar(c) == IAC && network && ttnproto == NP_TELNET) {
  749.                                         /* Send one copy now */
  750.                         ttoc(IAC);      /* and the other one just below. */
  751.                     }
  752. #endif /* TNCODE */
  753.                     /* Send the character */
  754.  
  755.                     if (ttoc(dopar(c)) > -1) {
  756.                         if (duplex) {   /* If half duplex, must echo */
  757.                             if (debses)
  758.                               conol(dbchr(csave)); /* the original char */
  759.                             else                   /* not the translated one */
  760.                               conoc(csave);
  761.                             if (seslog) { /* And maybe log it too */
  762.                                 c2 = csave;
  763.                                 if (sessft == 0 && csave == '\r')
  764.                                   c2 = '\n';
  765.                                 logchar(c2);
  766.                             }
  767.                         }
  768.                     } else if (active){  /* UNIX doesn't check for active */
  769.                         perror("\r\nCan't send character");
  770.                         break;           /* UNIX clears active flag instead */
  771.                     }
  772.                 }
  773.             } 
  774.         midkill(TASKID);                /* kill comm line reader task */
  775.         if (sjval == 1) {               /* Read error on comm device */
  776.             dohangup = 1;
  777. #ifdef NETCONN
  778.             if (network) {
  779.                 ttclos(0);
  780.             }
  781. #endif /* NETCONN */
  782.         }
  783.         if (sjval == 2)                 /* If it was a mode change, go back */
  784.           goto newfork;                 /* and coordinate with other fork. */
  785.         conres();                       /* Reset the console. */
  786.         if (quitnow) doexit(GOOD_EXIT,xitsta); /* Exit now if requested. */
  787.         if (dohangup > 0) {
  788. #ifndef NODIAL
  789.             if (dohangup > 1)           /* If hangup requested, do that. */
  790.                 if (mdmhup() < 1)       /* Try via modem first */
  791. #endif /* NODIAL */
  792.                 tthang();               /* And make sure we don't hang up */
  793.             dohangup = 0;               /* again unless requested again. */
  794.         }
  795.         mfinit(stdout,0);               /* Un-protect output to screen */
  796.         what = W_NOTHING;               /* So console modes set right. */
  797. #ifndef NOCSETS
  798.         language = langsv;              /* Restore language */
  799. #endif /* NOCSETS */
  800.         parent_id = (PID_T) 0;
  801. #ifdef DYNAMIC
  802.             if (ibuf) free(ibuf); ibuf = 0;
  803.             if (obuf) free(obuf); obuf = 0;
  804.             if (temp) free(temp); temp = 0;
  805. #endif /* DYNAMIC */
  806.         return(1);
  807.     } /* else */
  808. }
  809.  
  810. void
  811. readfromcommline() {
  812.     int c;
  813.     int i;
  814.     int n;
  815.     int tx,x;                     /* variables needed for tn_doop code */
  816.  
  817.         if (priv_can()) {               /* Cancel all privs */
  818.             printf("?setuid error - fatal\n");
  819.             doexit(BAD_EXIT,-1);
  820.         }
  821.         signal(SIGINT, SIG_IGN);        /* In case these haven't been */
  822.         signal(SIGQUIT, SIG_IGN);       /* inherited from above... */
  823.  
  824.         inshift = outshift = 0;         /* Initial shift state. */
  825.         sleep(1);                       /* Wait for parent's handler setup.  */
  826.         ibp = ibuf;                     /* Initialize input buffering */
  827.         ibc = 0;                        /* And output buffering. */
  828.         obp = obuf;
  829.         obc = 0;
  830.         debug(F100,"CONNECT starting port task (readfromcommline)","",0);
  831.         while (active)  {            /* Fresh read, wait for a character. */
  832. /*
  833.   Get the next communication line character from our internal buffer.
  834.   If the buffer is empty, refill it.
  835. */
  836.                 c = ckcgetc(0);         /* Get next character */
  837.                 /* debug(F101,"CONNECT c","",c); */
  838.                 if (c < 0) {
  839.                     active = 0;         /* deviation from unix code */
  840.                     if (!quiet) {       /* Failed... */
  841.                      printf("\r\nCommunications disconnect (Back at %s)\r\n",
  842.                              *myhost ? myhost : "local MV system");
  843.                     if ( c == -3)
  844.                            perror("\r\nCan't read character");
  845.                     }
  846. #ifndef NODIAL
  847.                     if (mdmhup() < 1)
  848. #endif /* NODIAL */
  849.                       tthang();           /* Hang up our side. */
  850.                     sjval = 1;            /* Notify parent - kludge */
  851.                     for (;;) pause();     /* Wait to be killed */
  852.                 }
  853.                 debug(F111,"** PORT",dbchr(c),c);
  854. #ifdef TNCODE
  855.                 /* Handle TELNET negotiations here */
  856.                 if (c == IAC && network && ttnproto == NP_TELNET) {
  857.                     debug(F111,"got IAC from port",dbchr(c),c);
  858.                     ckcputf();          /* Dump output buffer */
  859.                     tx = tn_doop((c & 0xff),duplex,ckcgetc);
  860.                     debug(F111,"tn_doop returns ","",tx);
  861.                     if (tx == 0)
  862.                         continue;
  863.                     else if (tx == -1) {                /* I/O error */
  864.                         if (active && !quiet)
  865.                       printf("\r\nCommunications disconnect (Back at %s)\r\n",
  866.                              *myhost ? myhost : "local MV system");
  867.                         active = 0;
  868.                         sjval = 1;          /* Notify parent - kludge */
  869.                         for (;;) pause();   /* Wait to be killed. */
  870.                     } else if ((tx == 1) && (!duplex)) { /* ECHO change */
  871.                         if (parent_id)
  872.                             kill(parent_id,SIGUSR2);    /* Tell the parent */
  873.                         duplex = 1;
  874.             continue;
  875.                     } else if ((tx == 2) && (duplex)) { /* ECHO change */
  876.                         if (parent_id)
  877.                             kill(parent_id,SIGUSR2);
  878.                         duplex = 0;
  879.             continue;
  880.                     } else if (tx == 3) { /* Quoted IAC */
  881.                         c = 255;
  882.                     } else continue;    /* Negotiation OK, get next char. */
  883.                 }
  884. #endif /* TNCODE */
  885.                 if (debses) {           /* Output character to screen */
  886.                     char *s;            /* Debugging display... */
  887.                     s = dbchr(c);
  888.                     while (*s)
  889.                       ckcputc(*s++);
  890.                 } else {                /* or regular display ... */
  891.                     c &= cmask;         /* Apply Kermit-to-remote mask */
  892.                     if (sosi) {         /* Handle SI/SO */
  893.                         if (c == SO) {  /* Shift Out */
  894.                             inshift = 1;
  895.                             continue;
  896.                         } else if (c == SI) { /* Shift In */
  897.                             inshift = 0;
  898.                             continue;
  899.                         }
  900.                         if (inshift) c |= 0200;
  901.                     }
  902. #ifndef NOCSETS
  903. #ifndef SKIPESC
  904.                     /* Translate character sets */
  905.                     if (sxi) c = (*sxi)(c);
  906.                     if (rxi) c = (*rxi)(c);
  907. #else
  908.                     if (inesc == ES_NORMAL) {
  909.                         /* Translate character sets */
  910.                         if (sxi) c = (*sxi)(c);
  911.                         if (rxi) c = (*rxi)(c);
  912.                     }
  913.                     if (skipesc) chkaes(c); /* Adjust escape sequence status */
  914. #endif /* SKIPESC */
  915. #endif /* NOCSETS */
  916.                     c &= cmdmsk;                /* Apply command mask. */
  917.                     if (c == CR && tt_crd) { /* SET TERM CR-DISPLAY CRLF ? */
  918.                         ckcputc(c);          /* Yes, output CR */
  919.                         if (seslog) logchar(c);
  920.                         c = LF;              /* and insert a linefeed */
  921.                     }
  922.                     ckcputc(c);                 /* Output to screen */
  923.                     if (seslog) logchar(c);     /* Take care of session log */
  924.                 }
  925.         }
  926.  
  927.  
  928.  
  929. /*  H C O N N E  --  Give help message for connect.  */
  930.  
  931. int
  932. hconne() {
  933.     int c;
  934.     static char *hlpmsg[] = {
  935. "\r\n  ? for this message",
  936. "\r\n  0 (zero) to send a null",
  937. "\r\n  B to send a BREAK",
  938. #ifdef NETCONN
  939. "\r\n  I to send a network interrupt packet",
  940. #ifdef TCPSOCKET
  941. "\r\n  A to send Are You There?",
  942. #endif /* TCPSOCKET */
  943. #endif /* NETCONN */
  944. "\r\n  H to hangup and close the connection",
  945. "\r\n  Q to hangup and quit Kermit",
  946. "\r\n  S for status",
  947. "\r\n  ! to push to local shell",
  948. "\r\n  \\ backslash code:",
  949. "\r\n    \\nnn decimal character code",
  950. "\r\n    \\Onnn octal character code",
  951. "\r\n    \\Xhh  hexadecimal character code",
  952. "\r\n    terminate with carriage return.",
  953. "\r\n type the escape character twice to send the escape character",
  954. "\r\n space-bar to resume the CONNECT command\r\n\r\n",
  955. "" };
  956.     conol("\r\nPress C to return to ");
  957.     conol(*myhost ? myhost : "the C-Kermit prompt");
  958.     conol(", or:");
  959.     conola(hlpmsg);                     /* Print the help message. */
  960.     conol("Command>");                  /* Prompt for command. */
  961.     c = congks(0) & 0177;               /* Get character, strip any parity. */
  962.     /* No key mapping or translation here */
  963.     if (c != CMDQ)
  964.       conoll("");
  965.     return(c);                          /* Return it. */
  966. }
  967.  
  968.  
  969. /*  D O E S C  --  Process an escape character argument  */
  970.  
  971. VOID
  972. #ifdef CK_ANSIC
  973. doesc(char c)
  974. #else
  975. doesc(c) char c;
  976. #endif /* CK_ANSIC */
  977. /* doesc */ {
  978.     CHAR d, buf[3];
  979.   
  980.     while (1) {
  981.         if (c == escape) {              /* Send escape character */
  982.             d = dopar(c); ttoc(d); return;
  983.         } else                          /* Or else look it up below. */
  984.             if (isupper(c)) c = tolower(c);
  985.  
  986.         switch(c) {
  987.  
  988.         case 'c':                       /* Close connection */
  989.         case '\03':
  990.             active = 0; conol("\r\n"); return;
  991.  
  992.         case 'b':                       /* Send a BREAK signal */
  993.         case '\02':
  994.             ttsndb(); return;
  995.  
  996. #ifdef NETCONN
  997.         case 'i':                       /* Send Interrupt */
  998.         case '\011':
  999. #ifdef TCPSOCKET
  1000. #ifndef IP
  1001. #define IP 244
  1002. #endif /* IP */
  1003.             if (network && ttnproto == NP_TELNET) { /* TELNET */
  1004.                 buf[0] = (CHAR) IAC;    /* I Am a Command */
  1005.                 buf[1] = (CHAR) IP;     /* Interrupt Process */
  1006.                 ttol(buf,2);
  1007.             } else
  1008. #endif /* TCPSOCKET */
  1009.               conoc(BEL);
  1010.             return;
  1011. #ifdef TCPSOCKET
  1012.         case 'a':                       /* "Are You There?" */
  1013.         case '\01':
  1014. #ifndef AYT
  1015. #define AYT 246
  1016. #endif /* AYT */
  1017.             if (network && ttnproto == NP_TELNET) {
  1018.                 buf[0] = (CHAR) IAC;    /* I Am a Command */
  1019.                 buf[1] = (CHAR) AYT;    /* Are You There? */
  1020.                 ttol(buf,2);
  1021.             } else conoc(BEL);
  1022.             return;
  1023. #endif /* TCPSOCKET */
  1024. #endif /* NETCONN */
  1025.  
  1026.         case 'h':                       /* Hangup */
  1027.     /*  case '\010':  */        /* Too dangerous */
  1028.             dohangup = 2; active = 0; conol("\r\nHanging up "); return;
  1029.  
  1030.         case 'q':
  1031.             quitnow = 1; active = 0; conol("\r\n"); return;
  1032.  
  1033.         case 's':                       /* Status */
  1034.             sprintf(temp,
  1035.                     "\r\nConnected %s %s", network ? "to" : "through", ttname);
  1036.             conol(temp);
  1037.             if (speed >= 0L) {
  1038.                 sprintf(temp,", speed %ld",speed); conol(temp);
  1039.             }
  1040.             sprintf(temp,", %d terminal bits",(cmask == 0177) ? 7 : 8);
  1041.             conol(temp);
  1042.             if (parity) {
  1043.                 conol(", ");
  1044.                 switch (parity) {
  1045.                     case 'e': conol("even");  break;
  1046.                     case 'o': conol("odd");   break;
  1047.                     case 's': conol("space"); break;
  1048.                     case 'm': conol("mark");  break;
  1049.                 }
  1050.                 conol(" parity");
  1051.             }
  1052.             if (seslog) {
  1053.                 conol(", logging to "); conol(sesfil);
  1054.             }
  1055.             conoll("");
  1056.             if (!network) shomdm();
  1057.             return;
  1058.  
  1059.         case '?':                       /* Help */
  1060.             c = hconne(); continue;
  1061.  
  1062.         case '0':                       /* Send a null */
  1063.             c = '\0'; d = dopar(c); ttoc(d); return;
  1064.  
  1065. #ifndef NOPUSH
  1066.         case '@':                       /* Start inferior command processor */
  1067.         case '!':
  1068.             conres();                   /* Put console back to normal */
  1069.             zshcmd("");                 /* Fork a shell. */
  1070.             if (conbin(escape) < 0) {
  1071.                 printf("Error resuming CONNECT session\n");
  1072.                 active = 0;
  1073.             }
  1074.             return;
  1075. #endif /* NOPUSH */
  1076.  
  1077.         case SP:                        /* Space, ignore */
  1078.             return;
  1079.  
  1080.         default:                        /* Other */
  1081.             if (c == CMDQ) {            /* Backslash escape */
  1082.                 int x;
  1083.                 kbp = kbuf;
  1084.                 *kbp++ = c;
  1085.                 while (((c = (congks(0) & cmdmsk)) != '\r') && (c != '\n'))
  1086.                   *kbp++ = c;
  1087.                 *kbp = NUL; kbp = kbuf;
  1088.                 x = xxesc(&kbp);        /* Interpret it */
  1089.                 if (x >= 0) {           /* No key mapping here */
  1090.                     c = dopar(x);
  1091.                     ttoc(c);
  1092.                     return;
  1093.                 } else {                /* Invalid backslash code. */
  1094.                     conoc(BEL);
  1095.                     return;
  1096.                 }
  1097.             }
  1098.             conoc(BEL); return;         /* Invalid esc arg, beep */
  1099.         }
  1100.     }
  1101. }
  1102.  
  1103. VOID
  1104. #ifdef CK_ANSIC
  1105. logchar(char c)
  1106. #else
  1107. logchar(c) char c;
  1108. #endif /* CK_ANSIC */
  1109. /* logchar */ {                 /* Log character c to session log */
  1110.     if (seslog) 
  1111.       if ((sessft != 0) ||
  1112.           (c != '\r' &&
  1113.            c != '\0' &&
  1114.            c != XON &&
  1115.            c != XOFF))
  1116.         if (zchout(ZSFILE,c) < 0) {
  1117.             conoll("");
  1118.             conoll("ERROR WRITING SESSION LOG, LOG CLOSED!");
  1119.             seslog = 0;
  1120.         }
  1121. }
  1122.