📄 ckucns.c
字号:
signal(SIGINT, SIG_IGN); signal(SIGQUIT, SIG_IGN); debug(F101,"CONNECT carrier-watch","",carrier); if ((!network #ifdef TN_COMPORT || istncomport()#endif /* TN_COMPORT */ ) && (carrier != CAR_OFF)) { int x; x = ttgmdm(); debug(F100,"CONNECT ttgmdm","",x); if ((x > -1) && !(x & BM_DCD)) {#ifndef NOHINTS extern int hints;#endif /* NOHINTS */ debug(F100,"CONNECT ttgmdm CD test fails","",x); conres(); printf("?Carrier required but not detected.\n");#ifndef NOHINTS cx_status = CSX_CARRIER; 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 /* NOHINTS */ 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 || tcsl == FC_UTF8) { 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_ON); 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 */ active = 1; }#ifdef CKLEARN if (learning) { /* Learned script active... */ learnbp = 0; /* INPUT buffer pointer */ learnbc = 0; /* INPUT buffer count */ learnst = 0; /* State (0 = neutral, none) */ learnt1 = (ULONG) time(0); }#endif /* CKLEARN */#ifdef CKTIDLE idlelimit = tt_idlelimit;#endif /* CKTIDLE */ while (active) { /* Big loop... */ debug(F100,"CONNECT top of loop","",0); FD_ZERO(&in); /* Clear select() structs */ FD_ZERO(&out); FD_ZERO(&err); 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);#endif /* CK_FORWARD_X */ /* Wait till the first one of the above is ready for i/o */ /* or TERM IDLE-SEND is active and we time out. */ errno = 0;#ifdef CKTIDLE /* This really could be moved out of the loop... */ if (idlelimit) { /* Idle timeout set */ struct timeval tv; if (idlelimit > 0) { /* Positive = sec */ tv.tv_sec = (long) idlelimit; tv.tv_usec = 0L; } else { /* Negative = millisec */ long u = (0 - idlelimit); tv.tv_sec = u / 1000L; tv.tv_usec = ((u % 1000L) * 1000L); }#ifdef INTSELECT c = select(FD_SETSIZE,(int *)&in,(int *)&out,(int *)&err, &tv);#else c = select(FD_SETSIZE, &in, &out, &err, &tv);#endif /* INTSELECT */ } else#endif /* CKTIDLE */#ifdef INTSELECT c = select(FD_SETSIZE, (int *)&in, (int *)&out, (int *)&err, 0);#else c = select(FD_SETSIZE, &in, &out, &err, 0);#endif /* INTSELECT */ if (c < 1) {#ifdef CKTIDLE if (c == 0) { /* Timeout */ debug(F101,"CONNECT select() timeout","",tt_idleact); switch (tt_idleact) { case IDLE_HANG: { /* Hang up */ int x = 0;#ifndef NODIAL if (dialmhu) x = mdmhup(); if (x < 1)#endif /* NODIAL */ tthang(); /* fall thru deliberately... */ } case IDLE_RET: /* Return to command mode */ cx_status = CSX_IDLE; active = 0; continue; case IDLE_OUT: /* OUTPUT a string */ if (tt_idlestr) { int len = strlen(tt_idlestr); if (len > 0) ttol((CHAR *)tt_idlestr,len); else ttoc(NUL); /* No string, send a NUL */ } else ttoc(NUL); /* No string, send a NUL */ continue; case IDLE_EXIT: /* Exit from Kermit */ doexit(GOOD_EXIT,xitsta);#ifdef TNCODE case IDLE_TAYT: /* Send Telnet Are You There? */ if (network && IS_TELNET()) { tnopt[0] = (CHAR) IAC; tnopt[1] = (CHAR) TN_AYT; tnopt[2] = NUL; if (ttol((CHAR *)tnopt,2) < 0) active = 0; } continue; case IDLE_TNOP: /* Send Telnet NOP */ if (network && IS_TELNET()) { tnopt[0] = (CHAR) IAC; tnopt[1] = (CHAR) TN_NOP; tnopt[2] = NUL; if (ttol((CHAR *)tnopt,2) < 0) active = 0; } continue;#endif /* TNCODE */ } }#endif /* CKTIDLE */ debug(F101,"CONNECT select() errno","",errno); /* A too-big first arg to select() gets EBADF */#ifdef EINTR if (c == -1) { if (errno == EINTR) { continue; } }#endif /* EINTR */ sleep(1); continue; }#ifndef BEBOX#ifdef DEBUG if (FD_ISSET(scrnout, &out)) { debug(F100,"CONNECT SELECT scrnout","",0); }#endif /* DEBUG */#endif /* BEBOX */#ifdef CK_FORWARD_X fwdx_check_sockets(&in);#endif /* CK_FORWARD_X */ if (FD_ISSET(ttyfd, &in)) { /* Read from net? */ debug(F110,"CONNECT SELECT ttyfd","in",0); FD_CLR(ttyfd, &in); gotnet = 1; /* Net is ready */ } if (FD_ISSET(kbin, &in)) { /* Read from keyboard? */ debug(F100,"CONNECT SELECT kbin","",0); FD_CLR(kbin, &in); gotkbd = 1; /* Keyboard is ready */ } if (FD_ISSET(ttyfd, &err)) { debug(F110,"CONNECT SELECT ttyfd","err",0); FD_CLR(ttyfd, &err);#ifdef NETPTY#ifdef HAVE_PTYTRAP /* Special handling for HP-UX pty i/o */ if (ttpty) { if (pty_trap_handler(ttyfd) > 0) { ttclos(0); goto conret1; } continue; }#endif /* HAVE_PTYTRAP */#endif /* NETPTY */ gotnet = 1; /* Net is ready (don't set if pty) */ } }#ifdef DEBUG if (deblog) { debug(F101,"CONNECT gotkbd","",gotkbd); debug(F101,"CONNECT kbc","",kbc);#ifndef NOSETKEY debug(F101,"CONNECT kmptr","",kmptr);#endif /* NOSETKEY */ }#endif /* DEBUG */ while (gotkbd || kbc > 0 /* If we have keyboard chars */#ifndef NOSETKEY || kmptr#endif /* NOSETKEY */ ) {#ifndef NOSETKEY if (kmptr) { /* Have current macro? */ debug(F100,"CONNECT kmptr non NULL","",0); if ((c = (CHAR) *kmptr++) == NUL) { /* Get char from it */ debug(F100,"CONNECT macro empty, continuing","",0); kmptr = NULL; /* If no more chars, */ continue; /* Reset pointer and continue */ } debug(F000,"CONNECT char from macro","",c); } else { /* No macro... */#endif /* NOSETKEY */#ifdef BEBOX { int rc = 0; if ((rc = recv(kbin,buf,1,0)) > 0) c = buf[0]; else c = -1; debug(F111,"recv","rc",rc); printf("\r\nrecv: %c rc=%d\r\n",buf[0],rc); }#else /* BEBOX */ c = CONGKS(); /* Yes, read from keyboard */#endif /* BEBOX */ gotkbd = 0; /* Turn off select() result flag */#ifndef NOSETKEY }#endif /* NOSETKEY */ if (c == -1) {#ifdef EINTR if (errno == EINTR) continue;#endif /* EINTR */ cx_status = CSX_IOERROR; conoc(BEL); goto conret0; } c &= cmdmsk; /* Do any requested masking */#ifndef NOSETKEY/* Note: kmptr is NULL if we got character c from the keyboard, and it is not NULL if it came from a macro. In the latter case, we must avoid expanding it again.*/ if (!kmptr && macrotab[c]) { /* Macro definition for c? */ debug(F000,"CONNECT macro key",macrotab[c],c); kmptr = macrotab[c]; /* Yes, set up macro pointer */ continue; /* and restart the loop, */ } else c = keymap[c]; /* else use single-char keymap */#endif /* NOSETKEY */ if (#ifndef NOSETKEY !kmptr &&#endif /* NOSETKEY */ (tt_escape && ((c & 0xff) == escape))) { /* Escape char? */ debug(F000,"CONNECT got escape","",c);#ifdef BEBOX if (recv(kbin,buf,1,0)>=0) c = buf[0]; else c = -1;#else /* BEBOX */ c = CONGKS() & 0x7f; /* Read argument */#endif /* BEBOX */ doesc((char) c); /* Handle it */ continue; /* Back to loop */ } csave = c; /* Save it before translation */ /* for local echoing. */#ifdef CKLEARN crflag = (c == CR); /* Remember if it was CR. */#endif /* CKLEARN */#ifndef NOCSETS if (inesc[1] == ES_NORMAL) { /* If not inside escape seq.. */ /* Translate character sets */#ifdef UNICODE int x; if (unicode == 1) { /* Remote is UTF-8 */ outxcount = b_to_u((CHAR)c,outxbuf,OUTXBUFSIZ,tcssize); outxbuf[outxcount] = NUL; } else if (unicode == 2) { /* Local is UTF-8 */ x = u_to_b((CHAR)c); if (x < 0) continue; outxbuf[0] = (unsigned)(x & 0xff); outxcount = 1; outxbuf[outxcount] = NUL; } else {#endif /* UNICODE */ if (sxo) c = (*sxo)((char)c); /* Local-intermediate */ if (rxo) c = (*rxo)((char)c); /* Intermediate-remote */ outxbuf[0] = c; outxcount = 1; outxbuf[outxcount] = NUL;#ifdef UNICODE }#endif /* UNICODE */ } else { outxbuf[0] = c; outxcount = 1; outxbuf[outxcount] = NUL; } if (escseq)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -