📄 ckucns.c
字号:
/* debug(F000,"kbdread","send()",ch); */ printf("\r\ngot: %c rc = %d\r\n",ch,rc); } else msleep(100); } debug(F110,"kbdread","terminating",0); return(rc);}#endif /* BEBOX */static int printbar = 0;#define OUTXBUFSIZ 15static CHAR inxbuf[OUTXBUFSIZ+1]; /* Host-to-screen expansion buffer */static int inxcount = 0; /* and count */static CHAR outxbuf[OUTXBUFSIZ+1]; /* Keyboard-to-host expansion buf */static int outxcount = 0; /* and count */intconect() { int rc = 0; /* Return code: 0 = fail, 1 = OK */ int i, x = 0; register int c, c2, csave; /* Characters */#ifdef TNCODE int tx; /* For Telnet negotiations */#endif /* TNCODE */ int apcrc = 0; /* For APC and transparent print */ int n, kbin, scrnout; /* select() items... */ fd_set in, out, err; /* File descriptor sets */ int gotnet = 0; /* Flag for net ready to read */ int gotkbd = 0; /* Flag for keyboard ready to read */ int oldprt = 0; /* Used with printing */ int msgflg = 0; char cbuf[2]; /* Ditto */#ifdef BEBOX int tid = 0; /* Thread ID */ int pair[2]; /* Socket Pair */ CHAR ch; CHAR buf[64];#endif /* BEBOX */#ifdef BEBOX { /* Create a socket pair to be used for the keyboard input */ if (socketpair(pair)) { debug(F110,"conect","unable to create socket pair",0); return(-1); } debug(F111,"connect","socket pair[0]",pair[0]); debug(F111,"connect","socket pair[1]",pair[1]); /* Assign one end of the socket to kbin */ kbin = pair[0]; tid = spawn_thread(kbdread, "Kbd to Socket Pair", B_NORMAL_PRIORITY, (void *)pair[1] ); resume_thread(tid); debug(F110,"connect","tid",tid); }#else /* BEBOX */ kbin = fileno(stdin); /* stdin file descriptor */#endif /* BEBOX */ scrnout = fileno(stdout); /* stdout file descriptor */#ifdef CK_TRIGGER makestr(&triggerval,NULL); /* Reset trigger */#endif /* CK_TRIGGER */#ifdef XPRINT escbufc = 0; /* Reset esc-sequence buffer */ escbuf[0] = NUL;#endif /* XPRINT */ cbuf[1] = NUL; ttimoff(); /* Turn off any timer interrupts */ if (!local) { /* Be sure we're not in remote mode */#ifdef NETCONN printf("Sorry, you must SET LINE or SET HOST first\n");#else printf("Sorry, you must SET LINE first\n");#endif /* NETCONN */ return(0); } if (speed < 0L && network == 0 && ttfdflg == 0) { printf("Sorry, you must SET SPEED first\n"); return(0); }#ifdef TCPSOCKET if (network && !ttpipe && (nettype != NET_TCPB && nettype != NET_PTY)) { printf("Sorry, network type not supported\n"); return(0); }#endif /* TCPSOCKET */#ifdef DYNAMIC if (!ibuf) { if (!(ibuf = malloc(IBUFL+1))) { /* Allocate input line buffer */ printf("Sorry, CONNECT input buffer can't be allocated\n"); return(0); } else { ibp = ibuf; ibc = 0; } } if (!obuf) { if (!(obuf = malloc(OBUFL+1))) { /* Allocate output line buffer */ printf("Sorry, CONNECT output buffer can't be allocated\n"); return(0); } else { obp = obuf; obc = 0; } } if (!kbuf) { if (!(kbuf = malloc(KBUFL+1))) { /* Allocate keyboard input buffer */ printf("Sorry, CONNECT keyboard buffer can't be allocated\n"); return(0); } } if (!temp) { if (!(temp = malloc(TMPLEN+1))) { /* Allocate temporary buffer */ printf("Sorry, CONNECT temporary buffer can't be allocated\n"); return(0); } }#else obp = obuf; obc = 0;#endif /* DYNAMIC */ kbp = kbuf; /* Always clear these. */ *kbp = NUL; /* No need to preserve them between */ kbc = 0; /* CONNECT sessions. */#ifdef DEBUG if (deblog) { debug(F101,"CONNECT conect entry ttyfd","",ttyfd); debug(F101,"CONNECT conect entry ibc","",ibc); debug(F101,"CONNECT conect entry obc","",obc); debug(F101,"CONNECT conect entry kbc","",kbc);#ifdef CK_TRIGGER debug(F110,"CONNECT conect trigger",tt_trigger[0],0);#endif /* CK_TRIGGER */ if (ttyfd > -1) { n = ttchk(); debug(F101,"CONNECT conect entry ttchk","",n); } }#endif /* DEBUG */ if (ttyfd < 0) { /* If communication device not open */#ifdef TTLEBUF int n = le_inbuf(); debug(F111,"CONNECT le_inbuf()","ttyfd < 0",n); if (n > 0) { while (n--) { CHAR ch; le_getchar(&ch); conoc(ch); } return(0); }#endif /* TTLEBUF */ debug(F101,"CONNECT ttnproto","",ttnproto); debug(F111,"CONNECT opening",ttname,0); /* Open it now */ if (ttopen(ttname, &local, network ? -nettype : mdmtyp, 0 ) < 0) { sprintf(temp,"Sorry, can't open %s",ttname); perror(temp); debug(F110,"CONNECT open failure",ttname,0); return(0); }#ifdef IKS_OPTION /* If peer is in Kermit server mode, return now. */ if (TELOPT_SB(TELOPT_KERMIT).kermit.u_start) return(0);#endif /* IKS_OPTION */ } dohangup = 0; /* Hangup not requested yet */ msgflg = !quiet#ifdef CK_APC && !apcactive#endif /* CK_APC */ ; if (msgflg) {#ifdef NETCONN if (network) {#ifdef CK_ENCRYPTION extern int me_encrypt, u_encrypt; if (ck_tn_encrypting() && ck_tn_decrypting()) printf("SECURE connection to host %s",ttname); else#endif /* CK_ENCRYPTION */ if (ttpipe || ttpty) printf("Connecting via command \"%s\"",ttname); else printf("Connecting to host %s",ttname); } else {#endif /* NETCONN */ printf("Connecting to %s",ttname); if (speed > -1L) printf(", speed %ld",speed);#ifdef NETCONN }#endif /* NETCONN */ if (tt_escape) { printf(".\r\nThe escape character is Ctrl-%c (ASCII %d, %s)\r\n", ctl(escape), escape, (escape == 127 ? "DEL" : ccntab[escape])); printf("Type the escape character followed by C to get back,\r\n"); printf("or followed by ? to see other options.\r\n"); } else { printf(".\r\n\nESCAPE CHARACTER IS DISABLED\r\n\n"); } if (seslog) { printf("(Session logged to %s, ",sesfil); printf("%s)\r\n", sessft ? "binary" : "text"); } if (debses) printf("Debugging Display...)\r\n"); }/* Condition console terminal and communication line */ if (conbin((char)escape) < 0) { printf("Sorry, can't condition console terminal\n"); fflush(stdout); return(0); } debug(F101,"CONNECT cmask","",cmask); debug(F101,"CONNECT cmdmsk","",cmdmsk); debug(F101,"CONNECT speed before ttvt","",speed); if ((n = ttvt(speed,flow)) < 0) { /* Enter "virtual terminal" mode */ if (!network) { debug(F101,"CONNECT ttvt","",n); tthang(); /* Hang up and close the device. */ ttclos(0); if (ttopen(ttname, /* Open it again... */ &local, network ? -nettype : mdmtyp, 0 ) < 0) { sprintf(temp,"Sorry, can't reopen %s",ttname); perror(temp); return(0); }#ifdef IKS_OPTION if (TELOPT_SB(TELOPT_KERMIT).kermit.u_start) return(0);#endif /* IKS_OPTION */ if (ttvt(speed,flow) < 0) { /* Try virtual terminal mode again. */ conres(); /* Failure this time is fatal. */ printf("Sorry, Can't condition communication line\n"); return(0); } } } debug(F101,"CONNECT ttvt ok, escape","",escape); /* Despite ttvt() this is still needed in HP-UX */ /* because of the HP-9000 <RESET> key.*/ signal(SIGINT, SIG_IGN); signal(SIGQUIT, SIG_IGN); debug(F101,"CONNECT carrier-watch","",carrier); if (!network && (carrier != CAR_OFF)) { int x; x = ttgmdm(); debug(F100,"CONNECT ttgmdm","",x); if ((x > -1) && !(x & BM_DCD)) {#ifndef NOICP extern int hints;#endif /* NOICP */ debug(F100,"CONNECT ttgmdm CD test fails","",x); conres(); printf("?Carrier required but not detected.\n");#ifndef NOICP if (!hints) return(0); printf("***********************************\n"); printf(" Hint: To CONNECT to a serial device that\n"); printf(" is not presenting the Carrier Detect signal,\n"); printf(" first tell C-Kermit to:\n\n"); printf(" SET CARRIER-WATCH OFF\n\n"); printf("***********************************\n\n");#endif /* NOICP */ return(0); } debug(F100,"CONNECT ttgmdm ok","",0); } /* Now we are connected. */ if (msgflg || printbar) printf("----------------------------------------------------\r\n"); fflush(stdout);#ifndef NOCSETS/* Set up character set translations */ unicode = 0; /* Assume Unicode won't be involved */ tcs = 0; /* "Transfer" or "Other" charset */ sxo = rxo = NULL; /* Initialize byte-to-byte functions */ sxi = rxi = NULL; if (tcsr != tcsl) { /* Remote and local sets differ... */#ifdef UNICODE if (tcsr == FC_UTF8 || /* Remote charset is UTF-8 */ tcsl == FC_UTF8) { /* or local one is. */ xuf = xl_ufc[tcsl]; /* Incoming Unicode to local */ if (xuf) { tcs = (tcsr == FC_UTF8) ? tcsl : tcsr; /* The "other" set */ xfu = xl_fcu[tcs]; /* Local byte to remote Unicode */ if (xfu) unicode = (tcsr == FC_UTF8) ? 1 : 2; } tcssize = fcsinfo[tcs].size; /* Size of other character set. */ } else {#endif /* UNICODE */ tcs = gettcs(tcsr,tcsl); /* Get intermediate set. */ sxo = xls[tcs][tcsl]; /* translation function */ rxo = xlr[tcs][tcsr]; /* pointers for output functions */ sxi = xls[tcs][tcsr]; /* and for input functions. */ rxi = xlr[tcs][tcsl];#ifdef UNICODE }#endif /* UNICODE */ }/* This is to prevent use of zmstuff() and zdstuff() by translation functions. They only work with disk i/o, not with communication i/o. Luckily Russian translation functions don't do any stuffing...*/ langsv = language;#ifndef NOCYRIL if (language != L_RUSSIAN)#endif /* NOCYRIL */ language = L_USASCII;#ifdef COMMENT#ifdef DEBUG if (deblog) { debug(F101,"CONNECT tcs","",tcs); debug(F101,"CONNECT tcsl","",tcsl); debug(F101,"CONNECT tcsr","",tcsr); debug(F101,"CONNECT fcsinfo[tcsl].size","",fcsinfo[tcsl].size); debug(F101,"CONNECT fcsinfo[tcsr].size","",fcsinfo[tcsr].size); debug(F101,"CONNECT unicode","",unicode); }#endif /* DEBUG */#endif /* COMMENT */#ifdef CK_XYZ#ifndef XYZ_INTERNAL { extern int binary; /* See about ZMODEM autodownloads */ char * s; s = binary ? ptab[PROTO_Z].p_b_rcmd : ptab[PROTO_Z].p_t_rcmd; if (!s) s = ""; zmdlok = (*s != NUL); /* OK if we have external commands */ }#endif /* XYZ_INTERNAL */#endif /* CK_XYZ */#ifndef NOESCSEQ/* We need to activate the escape-sequence recognition feature when: (a) translation is elected, AND (b) the local and/or remote set is a 7-bit set other than US ASCII. Or: SET TERMINAL APC is not OFF (handled in the next statement).*/ escseq = (tcs != TC_TRANSP) && /* Not transparent */ (fcsinfo[tcsl].size == 128 || fcsinfo[tcsr].size == 128) && /* 7 bits */ (fcsinfo[tcsl].code != FC_USASCII); /* But not ASCII */#endif /* NOESCSEQ */#endif /* NOCSETS */#ifndef NOESCSEQ#ifdef CK_APC escseq = escseq || (apcstatus != APC_OFF); apcactive = 0; /* An APC command is not active */ apclength = 0; /* ... */#endif /* CK_APC */#ifdef XPRINT escseq |= tt_print;#endif /* XPRINT */ inesc[0] = ES_NORMAL; /* Initial state of recognizer */ inesc[1] = ES_NORMAL; debug(F101,"CONNECT escseq","",escseq);#endif /* NOESCSEQ */ if (ttyfd > -1) { /* (just in case...) */ what = W_CONNECT; /* Keep track of what we're doing */ FD_ZERO(&in); /* Clear select() structs */ FD_ZERO(&out); FD_ZERO(&err); active = 1; } while (active) { /* Big loop... */ debug(F100,"CONNECT top of loop","",0); gotkbd = 0; gotnet = ttpeek(); /* Something sitting in ckutio buf */ debug(F101,"CONNECT ttpeek","",gotnet); if (#ifndef NOSETKEY !kmptr /* Check for key macro active */#else 1#endif /* NOSETKEY */ ) { if (obc) { /* No key macro - set up for select */ FD_SET(ttyfd, &out); /* Have stuff to send to net */ } else { FD_SET(kbin, &in); /* Need to read stuff from keyboard */ }#ifdef BEBOX if (!(ibc || gotnet > 0)) FD_SET(ttyfd, &in); /* Need to read stuff from net */#else /* BEBOX */ if (ibc || gotnet > 0) { FD_SET(scrnout, &out); /* Have stuff to put on screen */ } else { FD_SET(ttyfd, &in); /* Need to read stuff from net */ }#endif /* BEBOX */ FD_SET(ttyfd, &err);#ifdef CK_FORWARD_X fwdx_init_fd_set(&in);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -