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

📄 ckcfns.c

📁 C-Kermit源码。是使用串口/Modem和网络通讯的程序
💻 C
📖 第 1 页 / 共 5 页
字号:
		if ((rc = pnbyte((ucsorder ? 0xbd : 0xff),fn)) < 0)		  return(rc);		if ((rc = pnbyte((ucsorder ? 0xff : 0xbd),fn)) < 0)		  return(rc);	    }	    if ((count = ucs2_to_utf8(uc.x_short,&buf)) < 1)	      return(-1);	    debug(F011,"xpnbyte buf",buf,count);	    for (i = 0; i < count; i++)	      if ((rc = pnbyte(buf[i],fn)) < 0)		return(rc);	    if (utferror)	      count += 2;	    return(count);	} else {			/* Translate UCS-2 to byte */	    if (uc.x_short == 0x2028 || uc.x_short == 0x2029) {		if (utferror)		  pnbyte(UNK,fn);		if (feol)		  return(pnbyte((CHAR)feol,fn));		if ((rc = pnbyte((CHAR)CR,fn)) < 0)		  return(rc);		if ((rc = pnbyte((CHAR)LF,fn)) < 0)		  return(rc);		else		  return(utferror ? 3 : 2);	    } else if (xuf) {		/* UCS-to-FCS function */		int x = 0;		if (utferror)		  pnbyte(UNK,fn);		if ((rc = (*xuf)(uc.x_short)) < 0) /* These can fail... */		  ch = UNK;		else		  ch = (unsigned)((unsigned)rc & 0xffff);		x = pnbyte(ch,fn);		if (x < 0)		  return(x);		else if (utferror)		  x++;		return(x);#ifdef KANJI/*  Also see the non-Unicode Kanji section further down in this function. */	    } else if (fcsinfo[fcs].alphabet == AL_JAPAN) {		/* Translate UCS-2 to Japanese set */		debug(F001,"xpnbyte uc","",uc.x_short);		sj.x_short = un_to_sj(uc.x_short); /* First to Shift-JIS */		debug(F001,"xpnbyte sj","",sj.x_short);		switch (fcs) {		/* File character set */		  case FC_SHJIS:	/* Shift-JIS -- just output it */		    if (sj.x_char[byteorder]) /* But not high byte if zero */		      if ((rc = pnbyte((CHAR)sj.x_char[byteorder],fn)) < 0)			return(rc);		    if ((rc = pnbyte((CHAR)sj.x_char[1-byteorder],fn)) < 0)		      return(rc);		    return(2);		  case FC_JEUC:		/* EUC-JP */		    eu.x_short = sj_to_eu(sj.x_short); /* Shift-JIS to EUC */		    debug(F001,"xpnbyte eu","",eu.x_short);		    if (eu.x_short == 0xffff) { /* Bad */			if ((rc = pnbyte(UNK,fn)) < 0)			  return(rc);			return(1);		    } else {		/* Good */			int count = 0;	/* Write high byte if not zero */			if (eu.x_char[byteorder]) {			    if ((rc=pnbyte((CHAR)eu.x_char[byteorder],fn)) < 0)			      return(rc);			    count++;			}			/* Always write low byte */			if ((rc = pnbyte((CHAR)eu.x_char[1-byteorder],fn)) < 0)			  return(rc);			count++;			return(count);		    }		    break;		  case FC_JIS7:		/* JIS-7 */		  case FC_JDEC:		/* DEC Kanji */		    eu.x_short = sj_to_eu(sj.x_short); /* Shift-JIS to EUC */		    if (eu.x_short == 0xffff) { /* Bad */			debug(F001,"xpnbyte bad eu","",eu.x_short);			if ((rc = pnbyte(UNK,fn)) < 0)			  return(rc);			return(1);		    } else {		/* Good */			int i;			/* ^^^ Use another name - 'a' hides parameter */			/* It's OK as is but causes compiler warnings */			char a = eu.x_char[1-byteorder]; /* Low byte */			debug(F001,"xpnbyte eu","",eu.x_short);			if (eu.x_char[byteorder] == 0) { /* Roman */			    switch (jstate) {			      case 1:	/* Current state is Katakana */				jbuf[0] = 0x0f;	/* SI */				jbuf[1] = a;				jx = 2;				break;			      case 2:	/* Current state is Kanji */				jbuf[0] = 0x1b;	/* ESC */				jbuf[1] = 0x28;	/* ( */				jbuf[2] = 0x4a;	/* J */				jbuf[3] = a;				jx = 4;				break;			      default:	/* Current state is Roman */				jbuf[0] = a;				jx = 1;				break;			    }			    jstate = 0;	/* New state is Roman */			} else if (eu.x_char[byteorder] == 0x8e) { /* Kana */			    jx = 0;			    switch (jstate) {			      case 2:		   /* from Kanji */				jbuf[jx++] = 0x1b; /* ESC */				jbuf[jx++] = 0x28; /* ( */				jbuf[jx++] = 0x4a; /* J */			      case 0:		   /* from Roman */				jbuf[jx++] = 0x0e; /* SO */			      default:		   /* State is already Kana*/				jbuf[jx++] = (a & 0x7f); /* and the char */				break;			    }			    jstate = 1;	/* New state is Katakana */			} else {	/* Kanji */			    jx = 0;			    switch (jstate) {			      case 1:	/* Current state is Katakana */				jbuf[jx++] = 0x0f; /* SI  */			      case 0:	/* Current state is Roman */				jbuf[jx++] = 0x1b; /* ESC */				jbuf[jx++] = 0x24; /* $   */				jbuf[jx++] = 0x42; /* B   */			      default:	/* Current state is already Kanji */				jbuf[jx++] = eu.x_char[byteorder] & 0x7f;				jbuf[jx++] = eu.x_char[1-byteorder] & 0x7f;				break;			    }			    jstate = 2;	/* Set state to Kanji */			}			for (i = 0; i < jx; i++) /* Output the result */			  if ((rc = pnbyte(jbuf[i],fn)) < 0)			    return(rc);			return(jx);	/* Return its length */		    }		}#endif /* KANJI */	    } else {			/* No translation function */		int count = 0;		if (utferror) {		    if ((rc = pnbyte((ucsorder ? 0xfd : 0xff),fn)) < 0)		      return(rc);		    if ((rc = pnbyte((ucsorder ? 0xff : 0xfd),fn)) < 0)		      return(rc);		    count += 2;		}		if ((rc = pnbyte(uc.x_char[swapping],fn)) < 0)		  return(rc);		if ((rc = pnbyte(uc.x_char[1-swapping],fn)) < 0)		  return(rc);		count += 2;		return(count);	    }	}    } else {				/* Byte to Unicode */	if (xtu) {			/* TCS-to-UCS function */	    if (((tcsinfo[tcs].size > 128) && (uc.x_short & 0x80)) ||		tcsinfo[tcs].size <= 128)	      uc.x_short = (*xtu)(uc.x_short);	}	if (fcs == FC_UCS2) {		/* And FCS is UCS-2 */	    /* Write out the bytes in the appropriate byte order */	    if (offc == 0 && ucsbom) {	/* Beginning of file? */		if ((rc = pnbyte((ucsorder ? 0xff : 0xfe),fn)) < 0) /* BOM */		  return(rc);		if ((rc = pnbyte((ucsorder ? 0xfe : 0xff),fn)) < 0)		  return(rc);	    }	    if ((rc = pnbyte(uc.x_char[swapping],fn)) < 0)	      return(rc);	    if ((rc = pnbyte(uc.x_char[1-swapping],fn)) < 0)	      return(rc);	    return(2);	} else if (fcs == FC_UTF8) {	/* Convert to UTF-8 */	    CHAR * buf = NULL;	    int i, count;	    if ((count = ucs2_to_utf8(uc.x_short,&buf)) < 1)	      return(-1);	    for (i = 0; i < count; i++)	      if ((rc = pnbyte(buf[i],fn)) < 0)		return(rc);	    return(count);	} else {	    debug(F100,"xpnbyte impossible combination","",0);	    return(-1);	}    }#else#ifdef KANJI/*  This almost, but not quite, duplicates the Kanji section above.  There is no doubt a way to combine the sections more elegantly,  but probably only at the expense of additional execution overhead.  As matters stand, be careful to reflect any changes in this section  to the other Kanji section above.*/    if (tcs == TC_JEUC) {		/* Incoming Japanese EUC */	int count = 0;	switch (fcs) {			/* File character set */	  case FC_SHJIS:		/* Shift-JIS -- just output it */	    if (sj.x_char[byteorder])	/* But not high byte if zero */	      if ((rc = pnbyte((CHAR)sj.x_char[byteorder],fn)) < 0)		return(rc);	    count++;	    if ((rc = pnbyte((CHAR)sj.x_char[1-byteorder],fn)) < 0)	      return(rc);	    count++;	    return(count);	  case FC_JEUC:			/* EUC-JP */	    eu.x_short = sj_to_eu(sj.x_short); /* Shift-JIS to EUC */	    debug(F001,"xpnbyte FC_JEUC eu","",eu.x_short);	    if (eu.x_short == 0xffff) { /* Bad */		if ((rc = pnbyte(UNK,fn)) < 0)		  return(rc);		return(1);	    } else {			/* Good */		int count = 0;		/* Write high byte if not zero */		if (eu.x_char[byteorder]) {		    if ((rc = pnbyte((CHAR)eu.x_char[byteorder],fn)) < 0)		      return(rc);		    count++;		}		/* Always write low byte */		if ((rc = pnbyte((CHAR)eu.x_char[1-byteorder],fn)) < 0)		  return(rc);		count++;		return(count);	    }	    break;	  case FC_JIS7:			/* JIS-7 */	  case FC_JDEC:			/* DEC Kanji */	    eu.x_short = sj_to_eu(sj.x_short); /* Shift-JIS to EUC */	    if (eu.x_short == 0xffff) { /* Bad */		debug(F001,"xpnbyte FC_JIS7 bad eu","",eu.x_short);		if ((rc = pnbyte(UNK,fn)) < 0)		  return(rc);		return(1);	    } else {			/* Good */		int i;		char a = eu.x_char[1-byteorder]; /* Low byte */		debug(F001,"xpnbyte FC_JIS7 eu","",eu.x_short);		if (eu.x_char[byteorder] == 0) { /* Roman */		    switch (jstate) {		      case 1:		/* Current state is Katakana */			jbuf[0] = 0x0f;	/* SI */			jbuf[1] = a;			jx = 2;			break;		      case 2:		/* Current state is Kanji */			jbuf[0] = 0x1b;	/* ESC */			jbuf[1] = 0x28;	/* ( */			jbuf[2] = 0x4a;	/* J */			jbuf[3] = a;			jx = 4;			break;		      default:		/* Current state is Roman */			jbuf[0] = a;			jx = 1;			break;		    }		    jstate = 0;		/* New state is Roman */		} else if (eu.x_char[byteorder] == 0x8e) { /* Kana */		    jx = 0;		    switch (jstate) {		      case 2:		   /* from Kanji */			jbuf[jx++] = 0x1b; /* ESC */			jbuf[jx++] = 0x28; /* ( */			jbuf[jx++] = 0x4a; /* J */		      case 0:		   /* from Roman */			jbuf[jx++] = 0x0e; /* SO */		      default:		   /* State is already Kana*/			jbuf[jx++] = (a & 0x7f); /* and the char */			break;		    }		    jstate = 1;		/* New state is Katakana */		} else {		/* Kanji */		    jx = 0;		    switch (jstate) {		      case 1:		/* Current state is Katakana */			jbuf[jx++] = 0x0f; /* SI  */		      case 0:		/* Current state is Roman */			jbuf[jx++] = 0x1b; /* ESC */			jbuf[jx++] = 0x24; /* $   */			jbuf[jx++] = 0x42; /* B   */		      default:		/* Current state is already Kanji */			jbuf[jx++] = eu.x_char[byteorder] & 0x7f;			jbuf[jx++] = eu.x_char[1-byteorder] & 0x7f;			break;		    }		    jstate = 2;		/* Set state to Kanji */		}		for (i = 0; i < jx; i++) /* Output the result */		  if ((rc = pnbyte(jbuf[i],fn)) < 0)		    return(rc);		return(jx);		/* Return its length */	    }	  default:	    if (sj.x_short < 0x80)	      return(sj.x_short);	    else	      return('?');	}    }#endif /* KANJI */#endif /* UNICODE */    debug(F100,"xpnbyte BAD FALLTHRU","",0);    return(-1);}#ifndef NOXFER/*  D E C O D E  --  Kermit Data-packet decoder  */int#ifdef CK_ANSICdecode(CHAR *buf, int (*fn)(char), int xlate)#elsedecode(buf,fn,xlate) register CHAR *buf; register int (*fn)(); int xlate;#endif /* CK_ANSIC *//* decode */ {    register unsigned int a, a7, a8, b8; /* Various copies of current char */    int t;				/* Int version of character */    int ssflg;				/* Character was single-shifted */    int ccpflg;				/* For Ctrl-unprefixing stats */    int len;    long z;    CHAR c;/*  Catch the case in which we are asked to decode into a file that is not open,  for example, if the user interrupted the transfer, but the other Kermit  keeps sending.*/    if ((cxseen || czseen || discard) && (fn == putfil))      return(0);#ifdef COMMENT#ifdef CKTUNING    if (binary && !parity)      return(bdecode(buf,fn));#endif /* CKTUNING */#endif /* COMMENT */    debug(F100,"DECODE","",0);    xdbuf = buf;			/* Make global copy of pointer. */    rpt = 0;				/* Initialize repeat count. */    len = rln;				/* Number of bytes in data field */    while (len > 0) {			/* Loop for each byte */        a = *xdbuf++ & 0xff;		/* Get next character */	len--;	if (a == rptq && rptflg) {	/* Got a repeat prefix? */	    rpt = xunchar(*xdbuf++ & 0xFF); /* Yes, get the repeat count, */	    rptn += rpt;	    a = *xdbuf++ & 0xFF;	/* and get the prefixed character. */	    len -= 2;	}	b8 = lsstate ? 0200 : 0;	/* 8th-bit value from SHIFT-STATE */	if (ebqflg && a == ebq) {	/* Have 8th-bit prefix? */	    b8 ^= 0200;			/* Yes, invert the 8th bit's value, */	    ssflg = 1;			/* remember we did this, */	    a = *xdbuf++ & 0xFF;	/* and get the prefixed character. */	    len--;	} else ssflg = 0;	ccpflg = 0;	if (a == ctlq) {		/* If control prefix, */	    a  = *xdbuf++ & 0xFF;	/* get its operand */	    len--;	    a7 = a & 0x7F;		/* and its low 7 bits. */	    if ((a7 >= 0100 && a7 <= 0137) || a7 == '?') { /* Controllify */		a = ctl(a);		/* if in control range. */		a7 = a & 0x7F;		ccpflg = 1;		/* Note that we did this */		ccp++;			/* Count for stats */	    }	} else a7 = a & 0x7f;		/* Not control quote */	if (a7 < 32 || a7 == 127) {	/* Control character? */	    if (!ccpflg) ccu++;		/* A bare one, count it */	    if (lscapu) {		/* If doing locking shifts... */		if (lsstate)		/* If SHIFTED */		  a8 = (a & ~b8) & 0xFF; /* Invert meaning of 8th bit */		else			/* otherwise */		  a8 = a | b8;		/* OR in 8th bit */		/* If we're not in a quoted sequence */		if (!lsquote && (!lsstate || !ssflg)) {		    if (a8 == DLE) {	/* Check for DLE quote */			lsquote = 1;	/* prefixed by single shift! */			continue;		    } else if (a8 == SO) { /* Check for Shift-Out */			lsstate = 1;	/* SHIFT-STATE = SHIFTED */			continue;		    } else if (a8 == SI) { /* or Shift-In */			lsstate = 0;	/* SHIFT-STATE = UNSHIFTED */			continue;		    }		} else lsquote = 0;	    }	}	a |= b8;			/* OR in the 8th bit */	if (rpt == 0) rpt = 1;		/* If no repeats, then one */#ifndef NOCSETS	if (!binary) {			/* If in text mode, */	    if (tcharset != TC_UCS2) {		if (feol && a == CR)	/* Convert CRLF to newline char */		  continue;		if (feol && a == LF)		  a = feol;	    }	    if (xlatype == XLA_BYTE)	/* Byte-for-byte - do it now */	      if (xlate && rx) a = (*rx)((CHAR) a);    	}#endif /* NOCSETS */	/* (PWP) Decoding speedup via buffered output and a macro... */	if (fn == putfil) {	    for (; rpt > 0; rpt--) {	/* Output the char RPT times */

⌨️ 快捷键说明

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