📄 ckucon.c
字号:
return(0); } if (speed < 0L && network == 0) { printf("Sorry, you must SET SPEED first\n"); return(0); }#ifdef TCPSOCKET if (network && (nettype != NET_TCPB)#ifdef SUNX25 && (nettype != NET_SX25)#endif /* SUNX25 */ ) { printf("Sorry, network type not supported\n"); return(0); }#endif /* TCPSOCKET */ if (ttyfd < 0) { /* If communication device not open */ debug(F111,"ckucon 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,"ckucon open failure",temp,0); return(0); } } dohangup = 0; /* Hangup not requested yet */#ifdef SUNX25 dox25clr = 0; /* X.25 clear not requested yet */#endif /* SUNX25 */ if (!quiet) {#ifdef NETCONN if (network) { printf("Connecting to host %s",ttname);#ifdef SUNX25 if (nettype == NET_SX25) printf(", Link ID %d, LCN %d",linkid,lcn);#endif /* SUNX25 */ } else {#endif /* NETCONN */ printf("Connecting to %s",ttname); if (speed > -1L) printf(", speed %ld",speed);#ifdef NETCONN }#endif /* NETCONN */ 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"); if (seslog) { printf("(Session logged to %s, ",sesfil); printf("%s)\r\n", sessft ? "binary" : "text"); } if (debses) printf("Debugging Display...)\r\n"); fflush(stdout); }/* Condition console terminal and communication line */ if (conbin((char)escape) < 0) { printf("Sorry, can't condition console terminal\n"); return(0); } debug(F101,"connect cmask","",cmask); debug(F101,"connect cmdmsk","",cmdmsk); goterr = 0; if ((n = ttvt(speed,flow)) < 0) { /* Enter "virtual terminal" mode */ debug(F101,"CONNECT ttvt","",n); goterr = 1; /* Error recovery... */ 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); } 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); }#ifdef NETCONN if (network && ttnproto == NP_TELNET) tn_ini(); /* Just in case ttopen didn't... */#endif /* NETCONN */ } debug(F101,"connect ttvt ok, escape","",escape);#ifndef NOCSETS/* Set up character set translations */ tcs = gettcs(tcsr,tcsl); /* Get intermediate set. */ if (tcsr == tcsl) { /* Remote and local sets the same? */ sxo = rxo = NULL; /* If so, no translation. */ sxi = rxi = NULL; } else { /* Otherwise, set up */ 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]; }/* 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 SKIPESC/* We need to activate the "skip escape sequence" feature when: (a) translation is elected, and (b) the local and/or remote set is a 7-bit set other than US ASCII.*/ skipesc = (tcs != TC_TRANSP) && /* Not transparent */ (fcsinfo[tcsl].size == 128 || fcsinfo[tcsr].size == 128) && /* 7 bits */ (fcsinfo[tcsl].code != FC_USASCII); /* But not ASCII */ inesc = ES_NORMAL; /* Initial state of recognizer */#ifdef COMMENT debug(F101,"tcs","",tcs); debug(F101,"tcsl","",tcsl); debug(F101,"tcsr","",tcsr); debug(F101,"fcsinfo[tcsl].size","",fcsinfo[tcsl].size); debug(F101,"fcsinfo[tcsr].size","",fcsinfo[tcsr].size);#endif /* COMMENT */ debug(F101,"skipesc","",skipesc);#endif /* SKIPESC */#endif /* NOCSETS *//* This is a label we jump back to when the lower fork sensed the need to change modes. As of 5A(178), this is used only by X.25 code (perhaps unnecessarily? -- The X.25 code needs a lot of testing and cleaning up...)*/newfork: debug(F100,"CONNECT newfork","",0); parent_id = getpid(); /* Get parent id for signalling */ signal(SIGUSR1,SIG_IGN); /* Don't kill myself */#ifdef SUNX25 pipe(padpipe); /* Create pipe to pass PAD parms */#endif /* SUNX25 */ pid = fork(); /* All ok, make a fork */ if (pid == (PID_T) -1) { /* Can't create it. */ conres(); /* Reset the console. */ perror("Can't create keyboard fork"); if (!quiet) { printf("\r\nCommunications disconnect (Back at %s)\r\n", *myhost ? myhost :#ifdef UNIX "local UNIX system"#else "local system"#endif /* UNIX */ ); } printf("\n"); what = W_NOTHING; /* So console modes are set right. */#ifndef NOCSETS language = langsv; /* Restore language */#endif /* NOCSETS */ parent_id = (PID_T) 0; /* Clean up */#ifdef DYNAMIC if (temp) free(temp); /* Free allocated memory */ if (ibuf) free(ibuf); if (obuf) free(obuf);#endif /* DYNAMIC */ return(1); } if (pid) { /* Top fork reads, sends keystrokes */ what = W_CONNECT; /* Keep track of what we're doing */ active = 1; debug(F101,"CONNECT keyboard fork duplex","",duplex); /* Catch communication errors or mode changes in lower fork */ if (setjmp(con_env) == 0) { /* Normal entry... */ sjval = 0; /* Initialize setjmp return code. */ signal(SIGUSR1,conn_int); /* Routine for child process exit. */ signal(SIGUSR2,mode_chg); /* Routine for mode change. */#ifdef SUNX25 if (network && nettype == NET_SX25) { obufl = 0; bzero (x25obuf,sizeof(x25obuf)) ; }#endif /* SUNX25 *//* Here is the big loop that gets characters from the keyboard and sends them out the communication device. There are two components to the communication path: the connection from the keyboard to C-Kermit, and from C-Kermit to the remote computer. The treatment of the 8th bit of keyboard characters is governed by SET COMMAND BYTESIZE (cmdmsk). The treatment of the 8th bit of characters sent to the remote is governed by SET TERMINAL BYTESIZE (cmask). This distinction was introduced in edit 5A(164).*/ while (active) {#ifndef NOSETKEY if (kmptr) { /* Have current macro? */ debug(F100,"kmptr non NULL","",0); if ((c = (CHAR) *kmptr++) == NUL) { /* Get char from it */ kmptr = NULL; /* If no more chars, */ debug(F100,"macro empty, continuing","",0); continue; /* reset pointer and continue */ } debug(F000,"char from macro","",c); } else /* No macro... */#endif /* NOSETKEY */ c = congks(0); /* Read from keyboard */ debug(F111,"** KEYB",dbchr(c),c); if (c == -1) { /* If read() got an error... */#ifdef COMMENT/* This seems to cause problems. If read() returns -1, the signal has already been delivered, and nothing will wake up the pause().*/ pause(); /* Wait for transmitter to finish. */#else#ifdef A986/* On Altos machines with Xenix 3.0, pressing DEL in connect mode brings us here (reason unknown). The console line discipline at this point has intr = ^C. The communications tty has intr = DEL but we get here after pressing DEL on the keyboard, even when the remote system has been set not to echo. With A986 defined, we stay in the read loop and beep only if the offending character is not DEL.*/ if ((c & 127) != 127) conoc(BEL);#else conoc(BEL); /* Beep */ active = 0; /* and terminate the read loop */ continue;#endif /* A986 */#endif /* COMMENT */ } 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? */ 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 */ ((c & 0x7f) == escape)) { /* Escape character? */ debug(F000,"connect got escape","",c); c = congks(0) & 0177; /* Got esc, get its arg */ /* No key mapping here */ doesc((char) c); /* Now process it */ } else { /* It's not the escape character */ csave = c; /* Save it before translation */ /* for local echoing. */#ifndef NOCSETS#ifndef SKIPESC /* Translate character sets */ if (sxo) c = (*sxo)(c); /* From local to intermediate. */ if (rxo) c = (*rxo)(c); /* From intermediate to remote. */#else if (inesc == ES_NORMAL) { /* If not inside escape seq.. */ /* Translate character sets */ if (sxo) c = (*sxo)((char)c); /* Local-intermediate */ if (rxo) c = (*rxo)((char)c); /* Intermediate-remote */ } if (skipesc) chkaes((char)c); /* Check escape seq status */#endif /* SKIPESC */#endif /* NOCSETS *//* If Shift-In/Shift-Out is selected and we have a 7-bit connection, handle shifting here.*/ if (sosi) { /* Shift-In/Out selected? */ if (cmask == 0177) { /* In 7-bit environment? */ if (c & 0200) { /* 8-bit character? */ if (outshift == 0) { /* If not shifted, */ ttoc(dopar(SO)); /* shift. */ outshift = 1; } } else { if (outshift == 1) { /* 7-bit character */ ttoc(dopar(SI)); /* If shifted, */ outshift = 0; /* unshift. */ } } } if (c == SO) outshift = 1; /* User typed SO */ if (c == SI) outshift = 0; /* User typed SI */ } c &= cmask; /* Apply Kermit-to-host mask now. */#ifdef SUNX25 if (network && nettype == NET_SX25) { if (padparms[PAD_ECHO]) { if (debses) conol(dbchr(c)) ; else if ((c != padparms[PAD_CHAR_DELETE_CHAR]) && (c != padparms[PAD_BUFFER_DELETE_CHAR]) && (c != padparms[PAD_BUFFER_DISPLAY_CHAR])) conoc(c) ; if (seslog) logchar(c); } if (c == CR && (padparms[PAD_LF_AFTER_CR] == 4 || padparms[PAD_LF_AFTER_CR] == 5)) { if (debses) conol(dbchr(LF)) ; else conoc(LF) ; if (seslog) logchar(LF); } if (c == padparms[PAD_BREAK_CHARACTER]) breakact(); else if (padparms[PAD_DATA_FORWARD_TIMEOUT]) { tosend = 1; x25obuf [obufl++] = c; } else if (((c == padparms[PAD_CHAR_DELETE_CHAR]) || (c == padparms[PAD_BUFFER_DELETE_CHAR]) || (c == padparms[PAD_BUFFER_DISPLAY_CHAR])) && (padparms[PAD_EDITING])) if (c == padparms[PAD_CHAR_DELETE_CHAR]) if (obufl > 0) { conol("\b \b"); obufl--; } else {} else if (c == padparms[PAD_BUFFER_DELETE_CHAR]) { conol ("\r\nPAD Buffer Deleted\r\n"); obufl = 0; } else if (c == padparms[PAD_BUFFER_DISPLAY_CHAR]) { conol("\r\n"); conol(x25obuf); conol("\r\n"); } else {} else { x25obuf [obufl++] = c; if (obufl == MAXOX25) tosend = 1; else if (c == CR) tosend = 1; } if (tosend) if (ttol(x25obuf,obufl) < 0) { perror ("\r\nCan't send characters"); active = 0; } else { bzero (x25obuf,sizeof(x25obuf)); obufl = 0; tosend = 0; } else {}; } else {#endif /* SUNX25 */ /* If we have a CR, handle CR/CRLF mapping... */ if (c == '\015') { if (tnlm /* TERMINAL NEWLINE ON */#ifdef TNCODE /* And for TELNET... */ || (network && ttnproto == NP_TELNET)#endif /* TNCODE */ ) { ttoc(dopar('\015')); /* Send CR */ if (duplex) conoc('\015'); /* Maybe echo CR */#ifdef TNCODE if (network && !tn_nlm && ttnproto == NP_TELNET) c = '\0'; /* Stuff NUL */ else#endif /* TNCODE */ c = '\012'; /* Stuff LF */ csave = c; } } /* Now process the LF or NUL... */#ifdef TNCODE/* If user types the 0xff character (TELNET IAC), it must be doubled. */ else if (c == IAC && network && ttnproto == NP_TELNET) { /* Send one copy now */ ttoc((char)IAC); /* and the other one just below. */ }#endif /* TNCODE */ /* Send the character */ if (ttoc((char)dopar((CHAR) c)) > -1) { if (duplex) { /* If half duplex, must echo */ if (debses) conol(dbchr(csave)); /* the original char */ else /* not the translated one */ conoc((char)csave); if (seslog) { /* And maybe log it too */ c2 = csave; if (sessft == 0 && csave == '\r') c2 = '\n'; logchar((char)c2); } } } else { perror("\r\nCan't send character"); active = 0; }#ifdef SUNX25 } #endif /* SUNX25 */ } } } /* Come here on death of child */ debug(F100,"CONNECT killing port fork","",0); kill(pid,9); /* Done, kill inferior fork. */ wait((WAIT_T *)0); /* Wait till gone. */ if (sjval == 1) { /* Read error on comm device */ dohangup = 1;#ifdef NETCONN if (network) { ttclos(0);#ifdef SUNX25 if (nettype == NET_SX25) initpad();#endif /* SUNX25 */ }#endif /* NETCONN */ } if (sjval == 2) /* If it was a mode change, go back */ goto newfork; /* and coordinate with other fork. */ conres(); /* Reset the console. */ if (quitnow) doexit(GOOD_EXIT,xitsta); /* Exit now if requested. */ if (dohangup > 0) { /* If hangup requested, do that. */#ifndef NODIAL
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -