📄 ckucon.c
字号:
#include "ckcsym.h"#ifdef NOLOCALchar *connv = "";#elsechar *connv = "CONNECT Command for UNIX, 6.0.083, 6 Sep 96";/* C K U C O N -- Terminal connection to remote system, for UNIX *//* Author: Frank da Cruz <fdc@columbia.edu>, Columbia University Academic Information Systems, New York City. Copyright (C) 1985, 1996, Trustees of Columbia University in the City of New York. The C-Kermit software may not be, in whole or in part, licensed or sold for profit as a software product itself, nor may it be included in or distributed with commercial products or otherwise distributed by commercial concerns to their clients or customers without written permission of the Office of Kermit Development and Distribution, Columbia University. This copyright notice must not be removed, altered, or obscured. Special thanks to Eduard Vopicka, Prague University of Economics, Czech Republic, for valuable contributions to this module in July 1994, and to Neal P. Murphy of the Motorola Cellular Infrastructure Group for rearranging the code to allow operation on the BeBox, yet still work in regular UNIX.*/#include "ckcdeb.h" /* Common things first */#ifdef BEBOXstatic double time_started = 0.0;#include <kernel/OS.h>_PROTOTYP( static long concld, (void *) );#else_PROTOTYP( static VOID concld, (void) );#endif /* BEBOX */#ifdef NEXT#undef NSIG#include <sys/wait.h> /* For wait() */#endif /* NEXT */#include <signal.h> /* Signals */#include <errno.h> /* Error numbers */#ifdef ZILOG /* Longjumps */#include <setret.h>#else#include <setjmp.h>#endif /* ZILOG */#include "ckcsig.h"/* Kermit-specific includes */#include "ckcasc.h" /* ASCII characters */#include "ckcker.h" /* Kermit things */#include "ckucmd.h" /* For xxesc() prototype */#include "ckcnet.h" /* Network symbols */#ifndef NOCSETS#include "ckcxla.h" /* Character set translation */#endif /* NOCSETS *//* Internal function prototypes */_PROTOTYP( VOID ttflux, (void) );_PROTOTYP( VOID doesc, (char) );_PROTOTYP( static VOID logchar, (char) );_PROTOTYP( int hconne, (void) );_PROTOTYP( VOID shomdm, (void) );_PROTOTYP( static int kbget, (void) );_PROTOTYP( static int pipemsg, (int) );_PROTOTYP( static VOID ck_sndmsg, (void) );_PROTOTYP( static int ckcputf, (void) );_PROTOTYP( static VOID ck_sndmsg, (void) );/* For inter-fork signaling. Normally we use SIGUSR1, except on SCO, where we use SIGUSR2 because SIGUSR1 is used by the system. You can define CK_FORK_SIG to be whatever other signal you might want to use at compile time. We don't use SIGUSR2 everywhere because in some systems, like UnixWare, the default action for SIGUSR2 is to kill the process that gets it.*/#ifndef CK_FORK_SIG#ifndef SIGUSR1 /* User-defined signals */#define SIGUSR1 30#endif /* SIGUSR1 */#ifndef SIGUSR2#define SIGUSR2 31#endif /* SIGUSR2 */#ifdef M_UNIX#define CK_FORK_SIG SIGUSR2 /* SCO - use SIGUSR2 */#else#define CK_FORK_SIG SIGUSR1 /* Others - use SIGUSR1 */#endif /* M_UNIX */#endif /* CK_FORK_SIG *//* External variables */extern struct ck_p ptab[];extern int local, escape, duplex, parity, flow, seslog, sessft, debses, mdmtyp, ttnproto, cmask, cmdmsk, network, nettype, deblog, sosi, tnlm, xitsta, what, ttyfd, quiet, backgrd, pflag, tt_crd, tn_nlm, ttfdflg, tt_escape, justone;extern long speed;extern char ttname[], sesfil[], myhost[], *ccntab[];#ifdef TNCODEextern int tn_b_nlm, me_binary, u_binary;#endif /* TNCODE */extern int nopush;#ifdef CK_APCextern int apcactive; /* Application Program Command (APC) */extern int apcstatus; /* items ... */static int apclength = 0; #ifdef DCMDBUFextern char *apcbuf;#elseextern char apcbuf[];#endif /* DCMDBUF */static int apcbuflen = APCBUFLEN - 2;extern int autodl, protocol; /* Auto download */#endif /* CK_APC */#ifdef CK_XYZ#ifdef XYZ_INTERNALstatic int zmdlok = 1; /* Zmodem autodownloads available */#elsestatic int zmdlok = 0; /* Depends on external protocol def */#endif /* XYZ_INTERNAL */#elsestatic int zmdlok = 0; /* Not available at all */#endif /* CK_XYZ */#ifndef NOSETKEY /* Keyboard mapping */extern KEY *keymap; /* Single-character key map */extern MACRO *macrotab; /* Key macro pointer table */static MACRO kmptr = NULL; /* Pointer to current key macro */#endif /* NOSETKEY *//* Global variables local to this module */static int quitnow = 0, /* <esc-char>Q was typed */ jbset = 0, /* Flag whether jmp buf is set. */ dohangup = 0, /* <esc-char>H was typed */ sjval, /* Setjump return value */ goterr = 0, /* Fork/pipe creation error flag */#ifndef SUNX25 active = 0, /* Lower fork active flag */#endif /* SUNX25 */ inshift = 0, /* SO/SI shift states */ outshift = 0;static PID_T parent_id = (PID_T)0; /* Process ID of keyboard fork */static char ecbuf[10], *ecbp; /* Escape char buffer & pointer */#ifdef pdp11#define IBUFL 1536 /* Input buffer length */#else#define IBUFL 4096#endif /* pdp11 */static int obc = 0; /* Output buffer count */#ifndef OXOS#define OBUFL 1024 /* Output buffer length */#else#define OBUFL IBUFL#endif /* OXOS */#define TMPLEN 200 /* Temporary message buffer length */#ifdef DYNAMICstatic char *ibuf = NULL, *obuf = NULL, *temp = NULL; /* Buffers */#elsestatic char ibuf[IBUFL], obuf[OBUFL], temp[TMPLEN];#endif /* DYNAMIC */#ifdef DYNAMICstatic char *ibp; /* Input buffer pointer */#elsestatic char *ibp = ibuf; /* Input buffer pointer */#endif /*DYNAMIC */static int ibc = 0; /* Input buffer count */#ifdef DYNAMICstatic char *obp; /* Output buffer pointer */#elsestatic char *obp = obuf; /* Output buffer pointer */#endif /* DYNAMIC *//* SunLink X.25 items */#ifdef SUNX25static char *p; /* General purpose pointer */char x25ibuf[MAXIX25]; /* Input buffer */char x25obuf[MAXOX25]; /* Output buffer */int active = 0; /* Lower fork active flag */int ibufl; /* Length of input buffer */int obufl; /* Length of output buffer */unsigned char tosend = 0;int linkid, lcn;static int dox25clr = 0;extern CHAR padparms[];#endif /* SUNX25 */static int xpipe[2] = {-1, -1}; /* Pipe descriptor for child-parent messages */static PID_T pid; /* Process ID of child *//* Character-set items */#ifndef NOCSETS#ifdef CK_ANSIC /* ANSI C prototypes... */extern CHAR (*xls[MAXTCSETS+1][MAXFCSETS+1])(CHAR); /* Character set */extern CHAR (*xlr[MAXTCSETS+1][MAXFCSETS+1])(CHAR); /* translation functions */static CHAR (*sxo)(CHAR); /* Local translation functions */static CHAR (*rxo)(CHAR); /* for output (sending) terminal chars */static CHAR (*sxi)(CHAR); /* and for input (receiving) terminal chars. */static CHAR (*rxi)(CHAR);#else /* Not ANSI C... */extern CHAR (*xls[MAXTCSETS+1][MAXFCSETS+1])(); /* Character set */extern CHAR (*xlr[MAXTCSETS+1][MAXFCSETS+1])(); /* translation functions. */static CHAR (*sxo)(); /* Local translation functions */static CHAR (*rxo)(); /* for output (sending) terminal chars */static CHAR (*sxi)(); /* and for input (receiving) terminal chars. */static CHAR (*rxi)();#endif /* CK_ANSIC */extern int language; /* Current language. */static int langsv; /* For remembering language setting. */extern struct csinfo fcsinfo[]; /* File character set info. */extern int tcsr, tcsl; /* Terminal character sets, remote & local. */static int tcs; /* Intermediate ("transfer") character set. */#endif /* NOCSETS *//* We do not need to parse and recognize escape sequences if we are being built without character-set support AND without APC support.*/#ifdef NOCSETS /* No character sets */#ifndef CK_APC /* No APC */#ifndef NOESCSEQ#define NOESCSEQ /* So no escape sequence recognizer */#endif /* NOESCSEQ */#endif /* CK_APC */#endif /* NOCSETS *//* Child process events / messages*/#define CEV_NO 0 /* No event */#define CEV_HUP 1 /* Communications hangup */#define CEV_PAD 2 /* X.25 - change PAD parameters */#define CEV_DUP 3 /* Toggle duplex */#define CEV_APC 4 /* Execute APC */#ifdef TNCODE#define CEV_MEBIN 5 /* Change of me_binary */#define CEV_UBIN 6 /* Change of u_binary */#endif /* TNCODE */#define CEV_ADL 7 /* Autodownload */#define CEV_AUL 8 /* Autoupload */#ifdef NOESCSEQ#define chkaes(x) 0#else/* As of edit 178, the CONNECT command will skip past ANSI escape sequences to avoid translating the characters within them. This allows the CONNECT command to work correctly when connected to a remote host that uses a 7-bit ISO 646 national character set, in which characters like '[' would normally be translated into accented characters, ruining the terminal's interpretation (and generation) of escape sequences. As of edit 190, the CONNECT command responds to APC escape sequences (ESC _ text ESC \) if the user SETs TERMINAL APC ON or UNCHECKED, and the program was built with CK_APC defined. Non-ANSI/ISO-compliant escape sequences are not handled.*//* States for the escape-sequence recognizer.*/#define ES_NORMAL 0 /* Normal, not in an escape sequence */#define ES_GOTESC 1 /* Current character is ESC */#define ES_ESCSEQ 2 /* Inside an escape sequence */#define ES_GOTCSI 3 /* Inside a control sequence */#define ES_STRING 4 /* Inside DCS,OSC,PM, or APC string */#define ES_TERMIN 5 /* 1st char of string terminator */static int escseq = 0, /* 1 = Recognizer is active */ inesc = ES_NORMAL, /* State of sequence recognizer */ oldesc = -1; /* Previous state of recognizer *//* ANSI escape sequence handling. Only the 7-bit form is treated, because translation is not a problem in the 8-bit environment, in which all GL characters are ASCII and no translation takes place. So we don't check for the 8-bit single-character versions of CSI, DCS, OSC, APC, or ST. Here is the ANSI sequence recognizer state table, followed by the code that implements it. Definitions: CAN = Cancel 01/08 Ctrl-X SUB = Substitute 01/10 Ctrl-Z DCS = Device Control Sequence 01/11 05/00 ESC P CSI = Control Sequence Introducer 01/11 05/11 ESC [ ST = String Terminator 01/11 05/12 ESC \ OSC = Operating System Command 01/11 05/13 ESC ] PM = Privacy Message 01/11 05/14 ESC ^ APC = Application Program Command 01/11 05/15 ESC _ ANSI escape sequence recognizer: State Input New State ; Commentary NORMAL (start) ; Start in NORMAL state (any) CAN NORMAL ; ^X cancels (any) SUB NORMAL ; ^Z cancels NORMAL ESC GOTESC ; Begin escape sequence NORMAL other ; NORMAL control or graphic character GOTESC ESC ; Start again GOTESC [ GOTCSI ; CSI GOTESC P STRING ; DCS introducer, consume through ST GOTESC ] STRING ; OSC introducer, consume through ST GOTESC ^ STRING ; PM introducer, consume through ST GOTESC _ STRING ; APC introducer, consume through ST GOTESC 0..~ NORMAL ; 03/00 through 17/14 = Final character GOTESC other ESCSEQ ; Intermediate or ignored control character ESCSEQ ESC GOTESC ; Start again ESCSEQ 0..~ NORMAL ; 03/00 through 17/14 = Final character ESCSEQ other ; Intermediate or ignored control character GOTCSI ESC GOTESC ; Start again GOTCSI @..~ NORMAL ; 04/00 through 17/14 = Final character GOTCSI other ; Intermediate char or ignored control char STRING ESC TERMIN ; Maybe have ST STRING other ; Consume all else TERMIN \ NORMAL ; End of string TERMIN other STRING ; Still in string*//* chkaes() -- Check ANSI Escape Sequence. Call with EACH character in input stream. Sets global inesc variable according to escape sequence state. Returns 0 normally, 1 if an APC sequence is to be executed.*/int#ifdef CK_ANSICchkaes(char c)#elsechkaes(c) char c;#endif /* CK_ANSIC *//* chkaes */ { oldesc = inesc; /* Remember previous state */ if (c == CAN || c == SUB) /* CAN and SUB cancel any sequence */ inesc = ES_NORMAL; else /* Otherwise */ switch (inesc) { /* enter state switcher */ case ES_NORMAL: /* NORMAL state */ if (c == ESC) /* Got an ESC */ inesc = ES_GOTESC; /* Change state to GOTESC */ break; /* Otherwise stay in NORMAL state */ case ES_GOTESC: /* GOTESC state */ if (c == '[') /* Left bracket after ESC is CSI */ inesc = ES_GOTCSI; /* Change to GOTCSI state */ else if (c == 'P' || (c > 0134 && c < 0140)) { /* P, [, ^, or _ */ inesc = ES_STRING; /* Switch to STRING-absorption state */#ifdef CK_APC if (c == '_' && pid == 0 && /* APC handled in child only */ apcstatus != APC_OFF) { /* and only if not disabled. */ debug(F100,"APC begin","",0); apcactive = 1; /* Set APC-Active flag */ apclength = 0; /* and reset APC buffer pointer */ }#endif /* CK_APC */ } else if (c > 057 && c < 0177) /* Final character '0' thru '~' */ inesc = ES_NORMAL; /* Back to normal */ else if (c != ESC) /* ESC in an escape sequence... */ inesc = ES_ESCSEQ; /* starts a new escape sequence */ break; /* Intermediate or ignored ctrl char */ case ES_ESCSEQ: /* ESCSEQ -- in an escape sequence */ if (c > 057 && c < 0177) /* Final character '0' thru '~' */ inesc = ES_NORMAL; /* Return to NORMAL state. */ else if (c == ESC) /* ESC ... */ inesc = ES_GOTESC; /* starts a new escape sequence */ break; /* Intermediate or ignored ctrl char */ case ES_GOTCSI: /* GOTCSI -- In a control sequence */ if (c > 077 && c < 0177) /* Final character '@' thru '~' */ inesc = ES_NORMAL; /* Return to NORMAL. */ else if (c == ESC) /* ESC ... */ inesc = ES_GOTESC; /* starts over. */ break; /* Intermediate or ignored ctrl char */ case ES_STRING: /* Inside a string */ if (c == ESC) /* ESC may be 1st char of terminator */ inesc = ES_TERMIN; /* Go see. */#ifdef CK_APC else if (apcactive && (apclength < apcbuflen)) /* If in APC, */ apcbuf[apclength++] = c; /* deposit this character. */ else { /* Buffer overrun */ apcactive = 0; /* Discard what we got */ apclength = 0; /* and go back to normal */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -