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

📄 ucdomap.c

📁 基于rtos开发的浏览器!
💻 C
📖 第 1 页 / 共 4 页
字号:
	isdefault = 1;    } else {	isdefault = UCInfo[UChndl_out].replacedesc.isdefault;	trydefault = UCInfo[UChndl_out].replacedesc.trydefault;    }    if (!isdefault) {	ut = UCInfo[UChndl_out].unitable;	if (ut != UC_current_unitable) {	    rc = UC_con_set_unimap(UChndl_out, 1);	    if (rc < 0) {		return rc;	    }	}	rc = conv_uni_to_pc(unicode, 0);	if (rc >= 0)	    return rc;    }    if (isdefault || trydefault) {	rc = conv_uni_to_pc(unicode, 1);	if (rc >= 0)	    return rc;    }    if (!isdefault && (rc == -4)) {	rc = conv_uni_to_pc(0xfffd, 0);    }    if ((isdefault || trydefault) && (rc == -4)) {	rc = conv_uni_to_pc(0xfffd, 1);    }    return rc;}/* *  Returns string length, or negative value for error. */PUBLIC int UCTransUniCharStr ARGS5(	char *, 	outbuf,	int,		buflen,	long,		unicode,	int,		charset_out,	int,		chk_single_flag){    int rc = -14, src = 0, ignore_err;    int UChndl_out;    int isdefault, trydefault = 0;    struct unimapdesc_str * repl;    u16 * ut;    if (buflen < 2)	return -13;    if ((UChndl_out = LYCharSet_UC[charset_out].UChndl) < 0) {	if ((UChndl_out = default_UChndl) < 0)	    return -12;	isdefault = 1;    } else {	isdefault = UCInfo[UChndl_out].replacedesc.isdefault;	trydefault = UCInfo[UChndl_out].replacedesc.trydefault;    }    if (chk_single_flag) {	if (!isdefault) {	    ut = UCInfo[UChndl_out].unitable;	    if (ut != UC_current_unitable) {		src = UC_con_set_unimap(UChndl_out, 1);		if (src < 0) {		    return src;		}	    }	}	src = conv_uni_to_pc(unicode, isdefault);	if (src >= 32) {	    outbuf[0] = src; outbuf[1] = '\0';	    return 1;	}    }    repl = &(UCInfo[UChndl_out].replacedesc);    if (!isdefault) {	if (repl != UC_current_unitable_str)  {	    con_clear_unimap_str(0);	    ignore_err = UC_con_set_unimap_str(repl->entry_ct, repl->entries, 0);	    UC_current_unitable_str = repl;	}	rc = conv_uni_to_str(outbuf, buflen, unicode, 0);	if (rc >= 0)	    return (strlen(outbuf));    }    if (trydefault && chk_single_flag) {	src = conv_uni_to_pc(unicode, 1);	if (src >= 32) {	    outbuf[0] = src; outbuf[1] = '\0';	    return 1;	}    }    if (isdefault || trydefault) {	rc = conv_uni_to_str(outbuf, buflen, unicode, 1);	if (rc >= 0)	    return (strlen(outbuf));    }    if (rc == -4) {	if (!isdefault)	    rc = conv_uni_to_str(outbuf, buflen, 0xfffd, 0);	if ((rc == -4) && (isdefault || trydefault))	    rc = conv_uni_to_str(outbuf, buflen, 0xfffd, 1);	if (rc >= 0)	    return (strlen(outbuf));    }    if (chk_single_flag && src == -4) {	if (!isdefault)	    rc = conv_uni_to_pc(0xfffd, 0);	if ((rc == -4) && (isdefault || trydefault))	    rc = conv_uni_to_pc(0xfffd, 1);	if (rc >= 32) {	    outbuf[0] = rc; outbuf[1] = '\0';	    return 1;	}	return rc;    }    return -4;}PRIVATE int UC_lastautoGN = 0;PRIVATE int UC_MapGN ARGS2(	int,		UChndl,	int,		update_flag){    int i, Gn, found, lasthndl;    found = 0;    Gn = -1;    for (i = 0; i < 4 && Gn < 0; i++) {	if (UC_GNhandles[i] < 0) {	    Gn = i;	} else if (UC_GNhandles[i] == UChndl) {	    Gn = i;	    found = 1;	}    }    if (found)	return Gn;    if (Gn >= 0) {	UCInfo[UChndl].GN = Gn;	UC_GNhandles[Gn] = UChndl;    } else {	if (UC_lastautoGN == GRAF_MAP) {	    Gn = IBMPC_MAP;	} else {	    Gn = GRAF_MAP;	}	UC_lastautoGN = Gn;	lasthndl = UC_GNhandles[Gn];	UCInfo[lasthndl].GN = -1;	UCInfo[UChndl].GN = Gn;	UC_GNhandles[Gn] = UChndl;    }    if (TRACE) {	fprintf(stderr,		"UC_MapGN: Using %d <- %d (%s)\n",		Gn, UChndl, UCInfo[UChndl].MIMEname);    }    UC_con_set_trans(UChndl,Gn,update_flag);    return Gn;}PUBLIC int UCTransChar ARGS3(	char,		ch_in,	int,		charset_in,	int,		charset_out){    int unicode, Gn;    int rc = -4;    int UChndl_in, UChndl_out;    int isdefault, trydefault = 0;    u16 * ut;    int upd = 0;#ifndef UC_NO_SHORTCUTS    if (charset_in == charset_out)	return (unsigned char)ch_in;#endif /* UC_NO_SHORTCUTS */    if (charset_in < 0)	return -11;    if ((UChndl_in = LYCharSet_UC[charset_in].UChndl) < 0)	return -11;    if ((UChndl_out = LYCharSet_UC[charset_out].UChndl) < 0) {	if ((UChndl_out = default_UChndl) < 0)	    return -12;	isdefault = 1;    } else {	isdefault = UCInfo[UChndl_out].replacedesc.isdefault;	trydefault = UCInfo[UChndl_out].replacedesc.trydefault;    }    if (!UCInfo[UChndl_in].num_uni)	return -11;    if ((Gn = UCInfo[UChndl_in].GN) < 0) {	Gn = UC_MapGN(UChndl_in,0);	upd = 1;    }    ut = UCInfo[UChndl_out].unitable;    if (!isdefault) {	if (ut == UC_current_unitable) {	    if (upd) {		set_inverse_transl(Gn);	    }	} else {	    rc = UC_con_set_unimap(UChndl_out, 1);	    if (rc > 0) {		set_inverse_transl(Gn);	    } else if (rc < 0) {		return rc;	    }	}    }    UC_translate = set_translate(Gn);    unicode = UC_translate[(unsigned char)ch_in];    if (!isdefault) {	rc = conv_uni_to_pc(unicode, 0);	if (rc >= 0)	    return rc;    }    if ((rc == -4) && (isdefault || trydefault)) {	rc = conv_uni_to_pc(unicode, 1);    }    if ((rc == -4) && !isdefault) {	rc = conv_uni_to_pc(0xfffd, 0);    }    if ((rc == -4) && (isdefault || trydefault)) {	rc = conv_uni_to_pc(0xfffd, 1);    }    return rc;}PUBLIC long int UCTransToUni ARGS2(	char,		ch_in,	int,		charset_in){  int unicode, Gn;  unsigned char ch_iu;  int UChndl_in;  ch_iu = (unsigned char)ch_in;#ifndef UC_NO_SHORTCUTS    if (charset_in == 0)	return ch_iu;    if ((unsigned char)ch_in < 128 && (unsigned char)ch_in >= 32)	return ch_iu;#endif /* UC_NO_SHORTCUTS */    if (charset_in < 0)	return -11;    if ((unsigned char)ch_in < 32 &&	LYCharSet_UC[charset_in].enc != UCT_ENC_8BIT_C0)	/*	 *  Don't translate C0 chars except for specific charsets.	 */	return ch_iu;    if ((UChndl_in = LYCharSet_UC[charset_in].UChndl) < 0)	return -11;    if (!UCInfo[UChndl_in].num_uni)	return -11;    if ((Gn = UCInfo[UChndl_in].GN) < 0) {	Gn = UC_MapGN(UChndl_in,1);    }  UC_translate = set_translate(Gn);  unicode = UC_translate[(unsigned char)ch_in];  return unicode;}PUBLIC int UCReverseTransChar ARGS3(	char,		ch_out,	int,		charset_in,	int,		charset_out){    int Gn;    int rc;    int UChndl_in, UChndl_out;    int isdefault;    int i_ch = (unsigned char)ch_out;    u16 * ut;#ifndef UC_NO_SHORTCUTS    if (charset_in == charset_out)	return ch_out;#endif /* UC_NO_SHORTCUTS */    if (charset_in < 0)	return -11;    if ((UChndl_in = LYCharSet_UC[charset_in].UChndl) < 0)	return -11;    if (!UCInfo[UChndl_in].num_uni)	return -11;    if (charset_out < 0)	return -12;    if ((UChndl_out = LYCharSet_UC[charset_out].UChndl) < 0) {	if ((UChndl_out = default_UChndl) < 0)	    return -12;	isdefault = 1;    } else {	isdefault = UCInfo[UChndl_out].replacedesc.isdefault;    }    if (!isdefault) {	/*	 *  Try to use the inverse table if charset_out is not equivalent	 *  to using just the default table.  If it is, it should have	 *  just ASCII chars and trying to back-translate those should	 *  not give anything but themselves. - kw	 */	ut = UCInfo[UChndl_out].unitable;	if (ut == UC_current_unitable) {	    if ((Gn = UCInfo[UChndl_in].GN) >= 0) {		UC_translate = set_translate(Gn);		rc = inv_translate[i_ch];		if (rc >= 32) {		    return rc;		}	    } else {		Gn = UC_MapGN(UChndl_in,1);		UC_translate = set_translate(Gn);		rc = inv_translate[i_ch];		if (rc >= 32) {		    return rc;		}	    }	}    }    return UCTransChar(ch_out, charset_out, charset_in);}/* *  Returns string length, or negative value for error. */PUBLIC int UCTransCharStr ARGS6(	char *, 	outbuf,	int,		buflen,	char,		ch_in,	int,		charset_in,	int,		charset_out,	int,		chk_single_flag){    int unicode, Gn;    int rc = -14, src = 0, ignore_err;    int UChndl_in, UChndl_out;    int isdefault, trydefault = 0;    struct unimapdesc_str * repl;    u16 * ut;    int upd = 0;    if (buflen < 2)	return -13;#ifndef UC_NO_SHORTCUTS    if (chk_single_flag && charset_in == charset_out) {	outbuf[0] = ch_in;	outbuf[1] = '\0';	return 1;    }#endif /* UC_NO_SHORTCUTS */    if (charset_in < 0)	return -11;    if ((UChndl_in = LYCharSet_UC[charset_in].UChndl) < 0)	return -11;    if (!UCInfo[UChndl_in].num_uni)	return -11;    if ((UChndl_out = LYCharSet_UC[charset_out].UChndl) < 0) {	if ((UChndl_out = default_UChndl) < 0)	    return -12;	isdefault = 1;    } else {	isdefault = UCInfo[UChndl_out].replacedesc.isdefault;	trydefault = UCInfo[UChndl_out].replacedesc.trydefault;    }    if ((Gn = UCInfo[UChndl_in].GN) < 0) {	Gn = UC_MapGN(UChndl_in, !chk_single_flag);	upd = chk_single_flag;    }    UC_translate = set_translate(Gn);    unicode = UC_translate[(unsigned char)ch_in];    if (chk_single_flag) {	if (!isdefault) {	    ut = UCInfo[UChndl_out].unitable;	    if (ut == UC_current_unitable) {		if (upd) set_inverse_transl(Gn);	    } else {		src = UC_con_set_unimap(UChndl_out, 1);		if (src > 0) {		    set_inverse_transl(Gn);		} else if (src < 0) {		    return src;		}	    }	}	src = conv_uni_to_pc(unicode, isdefault);	if (src >= 32) {	    outbuf[0] = src; outbuf[1] = '\0';	    return 1;	}    }    repl = &(UCInfo[UChndl_out].replacedesc);    if (!isdefault) {	if (repl != UC_current_unitable_str) {	    con_clear_unimap_str(0);	    ignore_err = UC_con_set_unimap_str(repl->entry_ct, repl->entries, 0);	    UC_current_unitable_str = repl;	}	rc = conv_uni_to_str(outbuf, buflen, unicode, 0);	if (rc >= 0)	    return (strlen(outbuf));    }    if (trydefault && chk_single_flag) {	src = conv_uni_to_pc(unicode, 1);	if (src >= 32) {	    outbuf[0] = src; outbuf[1] = '\0';	    return 1;	}    }    if (isdefault || trydefault) {	rc = conv_uni_to_str(outbuf, buflen, unicode, 1);	if (rc >= 0)	    return (strlen(outbuf));    }    if (rc == -4) {	if (!isdefault)	    rc = conv_uni_to_str(outbuf, buflen, 0xfffd, 0);	if ((rc == -4) && (isdefault || trydefault))	    rc = conv_uni_to_str(outbuf, buflen, 0xfffd, 1);	if (rc >= 0)	    return (strlen(outbuf));    }    if (chk_single_flag && src == -4) {	if (!isdefault)	    rc = conv_uni_to_pc(0xfffd, 0);	if ((rc == -4) && (isdefault || trydefault))	    rc = conv_uni_to_pc(0xfffd, 1);	if (rc >= 32) {	    outbuf[0] = rc; outbuf[1] = '\0';	    return 1;	} else if (rc <= 0) {	    outbuf[0] = '\0';	    return rc;	}	return rc;    }    return -4;}PRIVATE int UC_FindGN_byMIME ARGS1(	CONST char *,	UC_MIMEcharset){  int i;    for (i = 0; i < 4; i++) {	if (!strcmp(UC_MIMEcharset,UC_GNsetMIMEnames[i])) {      return i;	}    }  return -1;}PUBLIC int UCGetRawUniMode_byLYhndl ARGS1(	int,		i){    if (i < 0)	return 0;  return LYCharSet_UC[i].enc;}/* *  Currently the charset name has to match exactly -- not substring *  matching as was done before (see HTMIME.c, HTML.c). */PUBLIC int UCGetLYhndl_byMIME ARGS1(	CONST char *,	UC_MIMEcharset){  int i;  int LYhndl = -1;    if (!UC_MIMEcharset || !(*UC_MIMEcharset))	return -1;    for (i = 0;	 (i < MAXCHARSETS && i < LYNumCharsets &&	  LYchar_set_names[i] && LYhndl < 0); i++) {	if (LYCharSet_UC[i].MIMEname &&	    !strcmp(UC_MIMEcharset, LYCharSet_UC[i].MIMEname)) {	    LYhndl = i;	}    }    if (LYhndl < 0) {	/*	 *  Not yet found, try synonyms. - FM	 */	if (!strcmp(UC_MIMEcharset, "unicode-1-1-utf-8") ||	    !strcmp(UC_MIMEcharset, "utf8")) {	    /*	     *	Treat these as synonyms for the IANA registered name. - FM	     */	    return UCGetLYhndl_byMIME("utf-8");	}	if (!strncmp(UC_MIMEcharset, "iso-2022-jp", 11) ||	    !strcmp(UC_MIMEcharset, "x-euc-jp")) {	    return UCGetLYhndl_byMIME("euc-jp");	}	if (!strcmp(UC_MIMEcharset, "x-shift-jis")) {	    return UCGetLYhndl_byMIME("shift_jis");	}	if (!strcmp(UC_MIMEcharset, "iso-2022-kr")) {	    return UCGetLYhndl_byMIME("euc-kr");	}	if (!strcmp(UC_MIMEcharset, "gb2312") ||	    !strncmp(UC_MIMEcharset, "cn-gb", 5) ||	    !strcmp(UC_MIMEcharset, "iso-2022-cn")) {	    return UCGetLYhndl_byMIME("euc-cn");	}

⌨️ 快捷键说明

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