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

📄 ckcfns.c

📁 KERMIT工具 这在办公室下载不了,很多人都没有载不到.
💻 C
📖 第 1 页 / 共 5 页
字号:
		} else if (a == 0x8e) {	/* SS2 -- Katakana prefix */		    eu.x_char[byteorder] = (CHAR) a; /* Save it */		    bn++;		    kana = 1;		    kanji = 0;		    return(0);		} else {		    bad++;		}	    }	    break;	  case 1:			/* Byte 1 */	    bn = 0;	    if (kanji) {		eu.x_char[1-byteorder] = (CHAR) a;		sj.x_short = eu_to_sj(eu.x_short);		break;	    } else if (kana) {		sj.x_short = (CHAR) (a | 0x80);		break;	    } else {			/* (shouldn't happen) */		bad++;	    }	}	/* Come here with one Shift-JIS character */#ifdef UNICODE	if (bad) {	    uc.x_short = 0xfffd;	} else {	    uc.x_short = sj_to_un(sj.x_short); /* Convert to Unicode */	}	haveuc = 1;#endif /* UNICODE */    } else#endif /* KANJI */#ifdef UNICODE	uc.x_short = (unsigned)a & 0xff; /* Latin-1 or whatever... */    /* Come here with uc = the character to be translated. */    /* If (haveuc) it's UCS-2 in native order, otherwise it's a byte. */    debug(F101,"xpnbyte haveuc","",haveuc);    if (haveuc) {			/* If we have a Unicode... */	debug(F001,"xpnbyte uc.x_short","[A]",uc.x_short);	debug(F101,"xpnbyte feol","",feol);	if (what & W_XFER) {		/* If transferring a file */	    if (feol && uc.x_short == CR) { /* handle eol conversion. */		return(0);	    } else if (feol && uc.x_short == LF) {		uc.x_short = feol;	    }	}	debug(F001,"xpnbyte uc.x_short","[B]",uc.x_short);	if (fcs == FC_UCS2) {		/* And FCS is UCS-2 */	    /* Write out the bytes in the appropriate byte order */	    int count = 0;#ifndef IKSDONLY#ifdef OS2            extern int k95stdout,wherex[],wherey[];			extern unsigned char colorcmd;            union {                USHORT ucs2;                UCHAR  bytes[2];            } output;#endif /* OS2 */#endif /* IKSDONLY */	    if (offc == 0L && ucsbom) {	/* Beginning of file? */#ifndef IKSDONLY#ifdef OS2                if (fn == NULL && !k95stdout && !inserver) {		    offc++;#ifdef COMMENT		    /* Don't print the BOM to the display */                    output.bytes[0] = (!ucsorder ? 0xff : 0xfe);                    output.bytes[1] = (!ucsorder ? 0xfe : 0xff);                    VscrnWrtUCS2StrAtt(VCMD,                                       &output.ucs2,                                       1,                                       wherey[VCMD],                                       wherex[VCMD],                                       &colorcmd                                       );#endif /* COMMENT */                } else #endif /* OS2 */#endif /* IKSDONLY */                {		    if ((rc = pnbyte((ucsorder ? 0xff : 0xfe),fn)) < 0)		      return(rc);	/* BOM */		    if ((rc = pnbyte((ucsorder ? 0xfe : 0xff),fn)) < 0)		      return(rc);		}		count += 2;	    }	    if (utferror) {#ifndef IKSDONLY#ifdef OS2                if (fn == NULL && !k95stdout && !inserver) {                    offc++;                    output.bytes[0] = (!ucsorder ? 0xfd : 0xff);                    output.bytes[1] = (!ucsorder ? 0xff : 0xfd);                    VscrnWrtUCS2StrAtt(VCMD,                                       &output.ucs2,                                       1,                                       wherey[VCMD],                                       wherex[VCMD],                                       &colorcmd                                       );                } else #endif /* OS2 */#endif /* IKSDONLY */		{		    if ((rc = pnbyte((ucsorder ? 0xfd : 0xff),fn)) < 0)		      return(rc);		    if ((rc = pnbyte((ucsorder ? 0xff : 0xfd),fn)) < 0)		      return(rc);		}		count += 2;	    }#ifndef IKSDONLY#ifdef OS2            if (fn == NULL && !k95stdout && !inserver) {                offc++;                output.bytes[0] = uc.x_char[1-swapping];                output.bytes[1] = uc.x_char[swapping];                VscrnWrtUCS2StrAtt(VCMD,                                   &output.ucs2,                                   1,                                   wherey[VCMD],                                   wherex[VCMD],                                   &colorcmd                                   );            } else #endif /* OS2 */#endif /* IKSDONLY */            {		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 if (fcs == FC_UTF8) {	/* Convert to UTF-8 */	    CHAR * buf = NULL;	    int i, count;	    if (utferror) {		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 */

⌨️ 快捷键说明

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