⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ckucon.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 3 页
字号:
char *connv = "CONNECT Command for UNIX, 5A(047) 23 Nov 92";/*  C K U C O N  --  Dumb terminal connection to remote system, for UNIX  *//*  Author: Frank da Cruz (fdc@columbia.edu, FDCCU@CUVMA.BITNET),  Columbia University Center for Computing Activities.  First released January 1985.  Copyright (C) 1985, 1992, Trustees of Columbia University in the City of New  York.  Permission is granted to any individual or institution to use this  software as long as it is not sold for profit.  This copyright notice must be  retained.  This software may not be included in commercial products without  written permission of Columbia University.*/#include "ckcdeb.h"			/* Common things first */#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 *//* 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 doesc, (char) );_PROTOTYP( VOID logchar, (char) );_PROTOTYP( int hconne, (void) );_PROTOTYP( VOID shomdm, (void) );#ifndef SIGUSR1				/* User-defined signals */#define SIGUSR1 30#endif /* SIGUSR1 */#ifndef SIGUSR2#define SIGUSR2 31#endif /* SIGUSR2 *//* External variables */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;extern long speed;extern char ttname[], sesfil[], myhost[], *ccntab[];#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 */  dohangup = 0,				/* <esc-char>H was typed */  sjval = 0,				/* Setjump return value */  goterr = 0,				/* I/O error flag */#ifndef SUNX25  active = 0,				/* Lower fork active flag */#endif /* SUNX25 */  inshift = 0,				/* SO/SI shift states */  outshift = 0;static char kbuf[10], *kbp;		/* Keyboard buffer & pointer */static PID_T parent_id = (PID_T)0;	/* Process id of keyboard fork */static char *ibp;			/* Input buffer pointer */static int ibc = 0;			/* Input buffer count */#ifdef pdp11#define IBUFL 1536			/* Input buffer length */#else#define IBUFL 4096#endif /* pdp11 */static char *obp;			/* Output buffer pointer */static int obc = 0;			/* Output buffer count */#define OBUFL 1024			/* Output buffer length */#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 *//* 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;CHAR padparms[MAXPADPARMS+1];static int padpipe[2];			/* Pipe descriptor to pass PAD parms */#endif /* SUNX25 *//* 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. */#ifndef NOESCSEQ/*  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.  Escape sequences of non-ANSI/ISO-compliant terminals are not handled.*/#ifndef SKIPESC#define SKIPESC#endif /* SKIPESC *//*  States for the escape-sequence recognizer.*/#define ES_NORMAL 0			/* Normal, not in 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  skipesc = 0,				/* Skip over ANSI escape sequences */  inesc = ES_NORMAL;			/* State of sequence 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.*/VOID#ifdef CK_ANSICchkaes(char c)#elsechkaes(c) char c;#endif /* CK_ANSIC *//* chkaes */ {    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 > 057 && c < 0177)	/* Final character '0' thru '~' */	    inesc = ES_NORMAL;		/* Back to normal */	  else if (c == 'P' || (c > 0134 && c < 0140)) /* P, [, ^, or _ */	    inesc = ES_STRING;		/* Switch to STRING-absorption state */	  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. */	  break;			/* Absorb all other characters. */	case ES_TERMIN:			/* May have a string terminator */	  if (c == '\\')		/* which must be backslash */	    inesc = ES_NORMAL;		/* If so, back to NORMAL */	  else				/* Otherwise */	    inesc = ES_STRING;		/* Back to string absorption. */      }}#endif /* NOESCSEQ */#endif /* NOCSETS *//* Connect state parent/child communication signal handlers */static jmp_buf con_env;		 /* Environment pointer for connect errors *//*  Note: Some C compilers (e.g. Cray UNICOS) interpret the ANSI C standard  about setjmp() in a way that disallows constructions like:    if ((var = setjmp(env)) == 0) ...  which prevents the value returned by longjmp() from being used at all.  So the following handlers set a global variable instead.*/staticSIGTYPconn_int(foo) int foo; {		/* Modem read failure handler, */    signal(SIGUSR1,SIG_IGN);		/* Disarm the interrupt */    sjval = 1;				/* Set global variable */    longjmp(con_env,sjval);		/* Notifies parent process to stop */}staticSIGTYPmode_chg(foo) int foo; {    signal(SIGUSR2,mode_chg);		/* Re-arm the signal immediately. */#ifdef SUNX25				/* X.25 read new params from pipe */    if (nettype == NET_SX25) {        read(padpipe[0],padparms,MAXPADPARMS);        debug(F100,"pad_chg","",0);/*  NOTE: we can probably skip this longjmp, just as we do in the "else" case.  But I don't (yet) have any way to test this.*/	sjval = 2;			/* Set global variable. */	longjmp(con_env,sjval);	debug(F100,"mode_chg X.25","",0);    } else {#endif /* SUNX25 */	duplex = 1 - duplex;		/* Toggle duplex mode. */	debug(F101,"mode_chg duplex","",duplex);#ifdef SUNX25    }#endif /* SUNX25 */}/*  C K C P U T C  --  C-Kermit CONNECT Put Character to Screen  *//*  Output is buffered to avoid slow screen writes on fast connections.*/intckcputf() {				/* Dump the output buffer */    int x = 0;    if (obc > 0)			/* If we have any characters, */      x = conxo(obc,obuf);		/* dump them, */    obp = obuf;				/* reset the pointer */    obc = 0;				/* and the counter. */    return(x);				/* Return conxo's return code */}intckcputc(c) int c; {    int x;    *obp++ = c & 0xff;			/* Deposit the character */    obc++;				/* Count it */    if (ibc == 0 ||			/* If input buffer about empty */	obc == OBUFL) {			/* or output buffer full */	debug(F101,"CKCPUTC obc","",obc);	x = conxo(obc,obuf);		/* dump the buffer, */	obp = obuf;			/* reset the pointer */	obc = 0;			/* and the counter. */	return(x);			/* Return conxo's return code */    } else return(0);}/*  C K C G E T C  --  C-Kermit CONNECT Get Character  *//*  Buffered read from communication device.  Returns the next character, refilling the buffer if necessary.  On error, returns ttinc's return code (see ttinc() description).  Dummy argument for compatible calling conventions with ttinc().*/intckcgetc(dummy) int dummy; {    int c, n;    debug(F101,"CKCGETC 1 ibc","",ibc); /* Log */    if (ibc < 1) {			/* Need to refill buffer? */	ibc = 0;			/* Yes, reset count */	ibp = ibuf;			/* and buffer pointer */	debug(F100,"CKCGETC 1 calling ttinc(0)","",0); /* Log */	c = ttinc(0);			/* Read one character, blocking */	debug(F101,"CKCGETC 1 ttinc(0)","",c); /* Log */	if (c < 0) {			/* If error, return error code */	    return(c);	} else {			/* Otherwise, got one character */	    *ibp++ = c;			/* Advance buffer pointer */	    ibc++;			/* and count. */	}	/* Now quickly read any more that might have arrived */	if ((n = ttchk()) > 0) {	/* Any more waiting? */	    if (n > (IBUFL - ibc))	/* Get them all at once. */	      n = IBUFL - ibc;		/* Don't overflow buffer */	    if ((n = ttxin(n,(CHAR *)ibp)) > 0) {		ibp += n;		/* Advance pointer */		ibc += n;		/* and counter */	    } else return(-1);	}	debug(F101,"CKCGETC 2 ibc","",ibc); /* Log how many */	ibp = ibuf;    }    c = *ibp++ & 0xff;			/* Get next character from buffer */    ibc--;				/* Reduce buffer count */    return(c);				/* Return the character */}/*  C O N E C T  --  Perform terminal connection  */intconect() {    PID_T pid;			/* Process id of child (modem reader) */    int	n;			/* General purpose counter */    int c;			/* c is a character, but must be signed 				   integer to pass thru -1, which is the				   modem disconnection signal, and is				   different from the character 0377 */    int c2;			/* A copy of c */    int csave;			/* Another copy of c */    int tx;			/* tn_doop() return code */#ifdef SUNX25    int i;			/* Worker for X.25 code*/#endif /* SUNX25 */#ifdef DYNAMIC    if (!(ibuf = malloc(IBUFL+1))) {    /* Allocate input line buffer */	printf("Sorry, CONNECT input buffer can't be allocated\n");	return(0);    }    if (!(obuf = malloc(OBUFL+1))) {    /* Allocate input line buffer */	printf("Sorry, CONNECT output buffer can't be allocated\n");	free(ibuf);	return(0);    }    if (!(temp = malloc(TMPLEN+1))) {    /* Allocate temporary buffer */	printf("Sorry, CONNECT temporary buffer can't be allocated\n");	free(obuf);	return(0);    }#endif /* DYNAMIC */    if (!local) {#ifdef NETCONN	printf("Sorry, you must SET LINE or SET HOST first\n");#else	printf("Sorry, you must SET LINE first\n");#endif /* NETCONN */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -