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

📄 ckucns.c

📁 C-Kermit源码。是使用串口/Modem和网络通讯的程序
💻 C
📖 第 1 页 / 共 5 页
字号:
	    escbuf[escbufc] = NUL;	    debug(F111,"ESCBUF 1",escbuf,escbufc);	} else {			/* Buffer overrun */	    if (printing && escbufc)	/* Print what's there so far */	      zsoutx(ZMFILE,escbuf,escbufc);	    escbufc = 1;		/* clear it out */	    escbuf[0] = c;		/* and start off fresh buffer */	    escbuf[1] = NUL;		/* with this character. */	}    }#endif /* XPRINT */    if (c == CAN || c == SUB) {		/* CAN and SUB cancel any sequence */#ifdef XPRINT	if (!src) {	    if (printing && escbufc > 1)	      zsoutx(ZMFILE,escbuf,escbufc-1);	    escbufc = 0;		/* Clear buffer */	    escbuf[0] = NUL;	}#endif /* XPRINT */	inesc[src] = ES_NORMAL;    } else				/* Otherwise */      switch (inesc[src]) {		/* enter state switcher */	case ES_NORMAL:			/* NORMAL state */	  if (c == ESC) {		/* Got an ESC */	      inesc[src] = ES_GOTESC;	/* Change state to GOTESC */#ifdef XPRINT	      if (!src) {		  escbufc = 1;		/* Clear escape sequence buffer */		  escbuf[0] = c;	/* and deposit the ESC */		  escbuf[1] = NUL;		  debug(F111,"ESCBUF 2",escbuf,escbufc);	      }#endif /* XPRINT */	  }	  break;			/* Otherwise stay in NORMAL state */	case ES_GOTESC:			/* GOTESC state - prev char was ESC*/	  if (c == '[') {		/* Left bracket after ESC is CSI */	      inesc[src] = ES_GOTCSI;	/* Change to GOTCSI state */	  } else if (c == 'P' || (c > 0134 && c < 0140)) { /* P, ], ^, or _ */	      inesc[src] = ES_STRING;	/* Switch to STRING-absorption state */#ifdef XPRINT	      debug(F111,"ESCBUF STRING",escbuf,escbufc);#endif /* XPRINT */#ifdef CK_APC	      /* If APC not disabled */	      if (!src && c == '_' && apcstatus != APC_OFF) {		  debug(F100,"CONNECT APC begin","",0);		  apcactive = APC_REMOTE; /* 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[src] = ES_NORMAL;	/* Back to normal */#ifdef XPRINT	      if (!src) {		  if (printing & escbufc > 1) {		      /* Dump esc seq buf to printer */		      zsoutx(ZMFILE,escbuf,escbufc-1);		      debug(F111,"ESCBUF PRINT 1",escbuf,escbufc);		  }		  escbufc = 0;		/* Clear parameter buffer */		  escbuf[0] = NUL;	      }#endif /* XPRINT */	  } else if (c != ESC) {	/* ESC in an escape sequence... */	      inesc[src] = 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[src] = ES_NORMAL;	/* Return to NORMAL state. */#ifdef XPRINT	      if (!src) {		  if (printing && escbufc > 1) {		      zsoutx(ZMFILE,escbuf,escbufc-1);		      debug(F111,"ESCBUF PRINT 2",escbuf,escbufc);		  }		  escbufc = 0;		/* Clear escseq buffer */		  escbuf[0] = NUL;	      }#endif /* XPRINT */	  } else if (c == ESC) {	/* ESC ... */	      inesc[src] = 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 '~' */#ifdef XPRINT	      if (!src && tt_print) {	/* Printer enabled? */		  if (c == 'i') {	/* Final char is "i"? */		      char * p = (char *) (escbuf + escbufc - 4);		      if (!strncmp(p, "\033[5i", 4)) /* Yes, turn printer on */			printon();		      else if (!strncmp(p, "\033[4i", 4)) { /* Or off... */			  printoff();	/* Turn off printer. */			  conxo(escbufc,escbuf); /* Display this sequence. */		      } else if (printing && escbufc > 1) {			  zsoutx(ZMFILE,escbuf,escbufc-1);			  debug(F111,"ESCBUF PRINT 3",escbuf,escbufc);		      }		  } else if (printing && escbufc > 1) {		      zsoutx(ZMFILE,escbuf,escbufc-1);		      debug(F111,"ESCBUF PRINT 4",escbuf,escbufc);		  }	      }	      if (!src) {		  escbufc = 0;		/* Clear esc sequence buffer */		  escbuf[0] = NUL;	      }#endif /* XPRINT */	      inesc[src] = ES_NORMAL;	/* Return to NORMAL. */	  } else if (c == ESC) {	/* ESC ... */	      inesc[src] = ES_GOTESC;	/* starts over. */	  }	  break;	case ES_STRING:			/* Inside a string */	  if (c == ESC)			/* ESC may be 1st char of terminator */	    inesc[src] = ES_TERMIN;	/* Go see. */#ifdef CK_APC	  else if (apcactive) {		/* If in APC */	      if (apclength < apcbuflen) { /* and there is room... */		  apcbuf[apclength++] = c; /* deposit this character. */	      } else {			/* Buffer overrun */		  apcactive = 0;	/* Discard what we got */		  apclength = 0;	/* and go back to normal */		  apcbuf[0] = 0;	/* Not pretty, but what else */		  inesc[src] = ES_NORMAL; /* can we do?  (ST might not come) */	      }	  }#endif /* CK_APC */	  break;			/* Absorb all other characters. */	case ES_TERMIN:			/* Maybe a string terminator */	  if (c == '\\') {		/* which must be backslash */	      inesc[src] = ES_NORMAL;	/* If so, back to NORMAL */#ifdef XPRINT	      if (!src) {		  if (printing && escbufc > 1) { /* If printing... */		      /* Print esc seq buffer */		      zsoutx(ZMFILE,escbuf,escbufc-1);		      debug(F111,"ESCBUF PRINT 5",escbuf,escbufc);		  }		  escbufc = 0;		/* Clear escseq buffer */		  escbuf[0] = NUL;	      }#endif /* XPRINT */#ifdef CK_APC	      if (!src && apcactive) {	/* If it was an APC string, */		  debug(F101,"CONNECT APC terminated","",c);		  apcbuf[apclength] = NUL; /* terminate it and then ... */		  return(1);	      }#endif /* CK_APC */	  } else {			/* It's not a backslash so... */	      inesc[src] = ES_STRING;	/* back to string absorption. */#ifdef CK_APC	      if (apcactive) {		/* In APC string */		  if (apclength+1 < apcbuflen) { /* If enough room */		      apcbuf[apclength++] = ESC; /* deposit the Esc */		      apcbuf[apclength++] = c;   /* and this character too. */		  } else {		/* Buffer overrun */		      apcactive = 0;		      apclength = 0;		      apcbuf[0] = 0;		      inesc[src] = ES_NORMAL;		  }	      }#endif /* CK_APC */	  }      }	/* switch() */    debug(F111,"chkaes exit inesc",ckitoa(src),inesc[src]);    return(0);}#endif /* NOESCSEQ *//*  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.*/static 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 */}/*  NOTE: This is probably the right place for character-set translation,  rather than down below in the mainline code.  ckcputc() would act like  xpnbyte() in ckcfns.c, and ckcgetc() would act like xgnbyte().  This  would shield the rest of the code from all the complexities of many-to-one  and one-to-many conversions, and would allow handling of Kanji and other  CJK sets along with UTF-8 and the rest.*/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,"CONNECT 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()  so a pointer to this function can be passed to tn_doop().*/intckcgetc(dummy) int dummy; {    int c, n;#ifdef CK_SSL    extern int ssl_active_flag, tls_active_flag;#endif /* CK_SSL */#ifdef CK_ENCRYPTION    /* No buffering for possibly encrypted connections */    if (network && ttnproto == NP_TELNET && TELOPT_ME(TELOPT_AUTHENTICATION))      return(ttinc(0));#endif /* CK_ENCRYPTION */#ifdef CK_SSL    if (ssl_active_flag || tls_active_flag)        return(ttinc(0));#endif /* CK_SSL */    if (ibc < 1) {			/* Need to refill buffer? */	ibc = 0;			/* Yes, reset count */	ibp = ibuf;			/* and buffer pointer */	c = ttinc(0);			/* Read one character, blocking */	if (c < 0) {			/* If error, return error code */	    return(c);	} else {			/* Otherwise, got one character */	    *ibp++ = c;			/* Advance buffer pointer */	    ibc++;			/* and count. */	}	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) {#ifdef CK_ENCRYPTION		  if (TELOPT_U(TELOPT_ENCRYPTION))                    ck_tn_decrypt(ibp,n);#endif /* CK_ENCRYPTION */		  ibc += n;		/* Advance counter */              }	} else if (n < 0) {		/* Error? */	    return(n);			/* Return the error code */	}	ibp = ibuf;			/* Point to beginning of buffer */    }    c = *ibp++ & 0xff;			/* Get next character from buffer */    ibc--;				/* Reduce buffer count */    /* debug(F000,"CKCGETC","",c); */    return(c);				/* Return the character */}/*   Keyboard handling, buffered for speed, which is needed when C-Kermit is   in CONNECT mode between two other computers that are transferring data.*/static char *kbp;			/* Keyboard input buffer pointer */static int kbc;				/* Keyboard input buffer count */#ifdef CK_SMALL				/* Keyboard input buffer length */#define KBUFL 32			/* Small for PDP-11 UNIX */#else#define KBUFL 257			/* Regular kernel size for others */#endif /* CK_SMALL */#ifdef DYNAMICstatic char *kbuf = NULL;#elsestatic char kbuf[KBUFL];#endif /* DYNAMIC *//* Macro for reading keystrokes. */#define CONGKS() (((--kbc)>=0) ? ((int)(*kbp++) & 0377) : kbget())/*  Note that we call read() directly here, normally a no-no, but in this case  we know it's UNIX and we're only doing what coninc(0) would have done,  except we're reading a block of characters rather than just one.  There is,  at present, no conxin() analog to ttxin() for chunk reads, and instituting  one would only add function-call overhead as it would only be a wrapper for  a read() call anyway.  Another note: We stick in this read() till the user types something.  But we know they already did, since select() said so.  Therefore something  would need to be mighty wrong before we get in trouble here.*/static int				/* Keyboard buffer filler */kbget() {#ifdef EINTR    int tries = 10;			/* If read() is interrupted, */    int ok = 0;    while (tries-- > 0) {		/* try a few times... */#endif /* EINTR */	kbc = conchk();			/* How many chars waiting? */	debug(F101,"kbget kbc","",kbc);	if (kbc < 1)	  kbc = 1;			/* If none or dunno, wait for one. */	else if (kbc > KBUFL)		/* If too many, */	  kbc = KBUFL;			/* only read this many. */	if ((kbc = read(0, kbuf, kbc)) < 1) { /* Now read it/them. */	    debug(F101,"CONNECT kbget errno","",errno);	/* Got an error. */#ifdef EINTR	    if (errno == EINTR)		/* Interrupted system call. */	      continue;			/* Try again, up to limit. */	    else			/* Something else. */#endif /* EINTR */	      return(-1);		/* Pass along read() error. */	}#ifdef EINTR	else { ok = 1; break; }    }    if (!ok) return(-1);#endif /* EINTR */    kbp = kbuf;				/* Adjust buffer pointer, */    kbc--;				/* count, */    return((int)(*kbp++) & 0377);	/* and return first character. */}#ifdef BEBOX/* * CreateSocketPair -- * *	This procedure creates a connected socket pair * * Results: *	0 if OK, the error if not OK. * * Side effects: *	None */intsocketpair(int *pair) {    int servsock;    int val;    struct sockaddr_in serv_addr, cli_addr;    extern char myipaddr[];    debug(F110,"socketpair",myipaddr,0);    if (myipaddr[0] == 0)      getlocalipaddr();    servsock = socket(AF_INET, SOCK_STREAM, 0);    if (servsock == 0) {	return h_errno;    }    debug(F111,"socketpair","socket",servsock);    memset(&serv_addr, 0, sizeof(serv_addr));    serv_addr.sin_family = AF_INET;    serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);    serv_addr.sin_port = htons(0);    val = sizeof(serv_addr);    if (bind(servsock, (struct sockaddr *) &serv_addr, val) < 0) {	closesocket(servsock);	return h_errno;    }    debug(F111,"socketpair","bind",0);    listen(servsock, 1);    debug(F111,"socketpair","listen",0);    if (getsockname(servsock, (struct sockaddr *) &serv_addr, &val) < 0) {	closesocket(servsock);	return h_errno;    }    debug(F111,"socketpair","getsockname",0);    pair[0] = socket(AF_INET, SOCK_STREAM, 0);    if (pair[0] == 0) {	closesocket(servsock);	return h_errno;    }    debug(F111,"socketpair","socket",pair[0]);    memset(&cli_addr, 0, sizeof(cli_addr));    cli_addr.sin_family = AF_INET;    cli_addr.sin_addr.s_addr = inet_addr(myipaddr[0]?myipaddr:"127.0.0.1");    cli_addr.sin_port = serv_addr.sin_port;    if (connect(pair[0],(struct sockaddr *) &cli_addr, sizeof(cli_addr)) < 0) {	closesocket(pair[0]);	closesocket(servsock);	return h_errno;    }    debug(F111,"socketpair","connect",0);    pair[1] = accept(servsock, (struct sockaddr *) &serv_addr, &val);    if (pair[1] == 0) {	closesocket(pair[0]);	closesocket(servsock);	return h_errno;    }    debug(F111,"socketpair","accept",pair[1]);    closesocket(servsock);    debug(F111,"socketpair","closesocket",0);    return 0;}longkbdread(void * param) {    int sock = (int) param;    char ch;    int rc = 0;    debug(F111,"kbdread","sock",sock);    while (rc >= 0) {	rc = read(fileno(stdin), &ch, 1); /* Read a character. */	if (rc > 0) {	    rc = send(sock,&ch,1,0);

⌨️ 快捷键说明

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