iconv VS2008移植工程

  • c6_584024
    了解作者
  • 2.3MB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-06-05 03:19
    上传日期
libconv在windows系统的移植,编译,测试工程代码 确实有需要的请下载使用。以下是测试代码 #include <stdlib.h> //include <sys/ipc.h> #include <stdio.h> #include <string.h> //#include <fcntl.h> //include <unistd.h> #include <iconv.h> int code_convert(char *from_charset,char *to_charset,char *inbuf,int inlen,char *outbuf,int outlen) { iconv_t cd; char **pin = &inbuf; char **pout = &outbuf; size_t iconv_ret; cd = iconv_open(to_charset,from_charset); if (cd==(iconv_t)-1) { perror("iconv_open():"); exit(0); } memset(outbuf,0,outlen); iconv_ret = iconv(cd,pin,&inlen,pout,&outlen); if (iconv_ret == (size_t)-1) { perror("iconv():"); exit(0); } iconv_close(cd); return 0; } int u2g(char *inbuf,int inlen,char *outbuf,int outlen) //UNICODE码转为GB2312码 { return code_convert("utf-8","gb2312",inbuf,inlen,outbuf,outlen); } int g2u(char *inbuf,size_t inlen,char *outbuf,size_t outlen) //GB2312码转为UNICODE码 { return code_convert("gb2312","utf-8",inbuf,inlen,outbuf,outlen); } /* 这是一个iconv的测试例程: “纵海杯”东南大学第三届嵌入式系统设计邀请赛 */ int main(void) { unsigned char in_utf8[] = {0x20,0xe8,0xbf,0x99,0xe6,0x98,0xaf,0xe4,0xb8,0x80,0xe4,0xb8,0xaa,0x69,0x63,0x6f, 0x6e,0x76,0xe7,0x9a,0x84,0xe6,0xb5,0x8b,0xe8,0xaf,0x95,0xe4,0xbe,0x8b,0xe7,0xa8, 0x8b,0xef,0xbc,0x9a,0x0a,0xe2,0x80,0x9c,0xe7,0xba,0xb5,0xe6,0xb5,0xb7,0xe6,0x9d, 0xaf,0xe2,0x80,0x9d,0xe4,0xb8,0x9c,0xe5,0x8d,0x97,0xe5,0xa4,0xa7,0xe5,0xad,0xa6, 0xe7,0xac,0xac,0xe4,0xb8,0x89,0xe5,0xb1,0x8a,0xe5,0xb5,0x8c,0xe5,0x85,0xa5,0xe5, 0xbc,0x8f,0xe7,0xb3,0xbb,0xe7,0xbb,0x9f,0xe8,0xae,0xbe,0xe8,0xae,0xa1,0xe9,0x82, 0x80,0xe8,0xaf,0xb7,0xe8,0xb5,0x9b,0x00}; //UTF-8编码 char in_gb2312[] =" 这是一个iconv的测试例程:\n\ “纵海杯”东南大学第三届嵌入式系统设计邀请赛"; //GB2312编码 char out[256]; int rc; printf("\r\n------iconv test------\r\n"); printf("\r\n---Start UTF8 to GB2312 convert...\r\n"); rc = u2g(in_utf8,strlen(in_utf8),out,256); printf("%s\n",out); rc = strcmp(in_gb2312,out); if(rc==0) { printf("---End UTF8 to GB2312 convert OK\r\n"); } else { printf("---End UTF8 to GB2312 convert FAIL\r\n"); } printf("\r\n---Start GB2312 to UTF8 convert...\n"); rc = g2u(in_gb2312,strlen(in_gb2312),out,256); printf("%s\n",out); rc = strcmp(in_utf8,out); if(rc==0) { printf("---End GB2312 to UTF8 convert OK\r\n"); } else { printf("---End GB2312 to UTF8 convert FAIL\r\n"); } printf("\r\n------iconv test over------\r\n"); system("pause");; }
iconv.rar
  • iconv-1.11.1
  • std_h
  • unistd.h
    43B
  • stdbool.h
    1.5KB
  • stdint.h
    180B
  • src-1.11.1
  • iso8859_5.h
    3.5KB
  • mac_roman.h
    6.9KB
  • cp1251.h
    5KB
  • sjis.h
    4.1KB
  • ucs4.h
    2.2KB
  • aliases_aix.h
    614B
  • canonical_aix.h
    551B
  • atarist.h
    6.7KB
  • canonical_local.h
    122B
  • iso8859_4.h
    4.6KB
  • encodings_dos.def
    4.9KB
  • iso8859_14.h
    5.3KB
  • mac_cyrillic.h
    5.6KB
  • relocatable.c
    12.7KB
  • gb2312.h
    154.5KB
  • cp855.h
    5.3KB
  • gentranslit.c
    8KB
  • armscii_8.h
    4.2KB
  • cp936.h
    3.5KB
  • cns11643_3.h
    56KB
  • genflags.c
    3.5KB
  • iso8859_6.h
    3.4KB
  • cns11643_inv.h
    934.8KB
  • converters.h
    7.2KB
  • tds565.h
    4KB
  • iconv.c
    19.3KB
  • utf32be.h
    1.6KB
  • tcvn.h
    11KB
  • ucs2internal.h
    1.5KB
  • vietcomb.h
    12.2KB
  • aliases_dos.h
    1.5KB
  • cp866.h
    5.1KB
  • koi8_ru.h
    7.2KB
  • isoir165ext.h
    45KB
  • mac_centraleurope.h
    5.8KB
  • config.h.msvc
    2.3KB
  • utf8.h
    4KB
  • riscos1.h
    3.4KB
  • iso8859_10.h
    4.3KB
  • canonical_osf1.h
    124B
  • koi8_u.h
    7.2KB
  • cns11643_7.h
    57.1KB
  • iso2022_jp3.h
    15.2KB
  • mac_arabic.h
    5.4KB
  • aliases2.h
    1.1KB
  • cns11643_4a.h
    26.9KB
  • jisx0213.h
    275.2KB
  • cp860.h
    6.4KB
  • iso8859_3.h
    4.6KB
  • cp1257.h
    5.5KB
  • iso8859_2.h
    4.6KB
  • localcharset.h
    1.4KB
  • java.h
    3.9KB
  • cjk_variants.h
    247.9KB
  • cp863.h
    6.7KB
  • ucs2swapped.h
    1.8KB
  • cp862.h
    6.5KB
  • johab.h
    4.3KB
  • cp858.h
    1.6KB
  • jisx0201.h
    1.7KB
  • shift_jisx0213.h
    9.6KB
  • config.h_vms
    2.3KB
  • mac_croatian.h
    7KB
  • pt154.h
    4.8KB
  • tis620.h
    1.5KB
  • utf16.h
    3.5KB
  • utf7.h
    10KB
  • iso2022_jp.h
    5.1KB
  • cp1250.h
    5.5KB
  • isoir165.h
    5.6KB
  • cp869.h
    5.5KB
  • cp1161.h
    2.7KB
  • cp1133.h
    3.6KB
  • iso2022_jp1.h
    6.3KB
  • iso2022_cn.h
    8.1KB
  • cns11643_6.h
    55.9KB
  • koi8_t.h
    5.9KB
  • mac_romania.h
    7KB
  • encodings_osf1.def
    1.2KB
  • cp775.h
    6.2KB
  • ucs4le.h
    1.4KB
  • config.h
    2.4KB
  • config.h.in
    2.3KB
  • big5hkscs1999.h
    5.6KB
  • hz.h
    3.6KB
  • gb18030uni.h
    11.9KB
  • uhc_1.h
    82.4KB
  • cns11643_4b.h
    39.2KB
  • hp_roman8.h
    4.3KB
  • johab_hangul.h
    10KB
  • cns11643_15.h
    62.8KB
  • iso2022_cnext.h
    15.8KB
  • cp852.h
    6.3KB
  • iso8859_13.h
    4.4KB
内容介绍
/* * Copyright (C) 1999-2006 Free Software Foundation, Inc. * This file is part of the GNU LIBICONV Library. * * The GNU LIBICONV Library is free software; you can redistribute it * and/or modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * The GNU LIBICONV Library is distributed in the hope that it will be * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with the GNU LIBICONV Library; see the file COPYING.LIB. * If not, write to the Free Software Foundation, Inc., 51 Franklin Street, * Fifth Floor, Boston, MA 02110-1301, USA. */ #include <iconv.h> #include <stdlib.h> #include <string.h> #include "config.h" #include "localcharset.h" #if ENABLE_EXTRA /* * Consider all system dependent encodings, for any system, * and the extra encodings. */ #define USE_AIX #define USE_OSF1 #define USE_DOS #define USE_EXTRA #else /* * Consider those system dependent encodings that are needed for the * current system. */ #ifdef _AIX #define USE_AIX #endif #if defined(__osf__) || defined(VMS) #define USE_OSF1 #endif #if defined(__DJGPP__) || (defined(_WIN32) && (defined(_MSC_VER) || defined(__MINGW32__))) #define USE_DOS #endif #endif /* * Data type for general conversion loop. */ struct loop_funcs { size_t (*loop_convert) (iconv_t icd, const char* * inbuf, size_t *inbytesleft, char* * outbuf, size_t *outbytesleft); size_t (*loop_reset) (iconv_t icd, char* * outbuf, size_t *outbytesleft); }; /* * Converters. */ #include "converters.h" /* * Transliteration tables. */ #include "cjk_variants.h" #include "translit.h" /* * Table of all supported encodings. */ struct encoding { struct mbtowc_funcs ifuncs; /* conversion multibyte -> unicode */ struct wctomb_funcs ofuncs; /* conversion unicode -> multibyte */ int oflags; /* flags for unicode -> multibyte conversion */ }; enum { #define DEFENCODING(xxx_names,xxx,xxx_ifuncs1,xxx_ifuncs2,xxx_ofuncs1,xxx_ofuncs2) \ ei_##xxx , #include "encodings.def" #ifdef USE_AIX #include "encodings_aix.def" #endif #ifdef USE_OSF1 #include "encodings_osf1.def" #endif #ifdef USE_DOS #include "encodings_dos.def" #endif #ifdef USE_EXTRA #include "encodings_extra.def" #endif #include "encodings_local.def" #undef DEFENCODING ei_for_broken_compilers_that_dont_like_trailing_commas }; #include "flags.h" static struct encoding const all_encodings[] = { #define DEFENCODING(xxx_names,xxx,xxx_ifuncs1,xxx_ifuncs2,xxx_ofuncs1,xxx_ofuncs2) \ { xxx_ifuncs1,xxx_ifuncs2, xxx_ofuncs1,xxx_ofuncs2, ei_##xxx##_oflags }, #include "encodings.def" #ifdef USE_AIX #include "encodings_aix.def" #endif #ifdef USE_OSF1 #include "encodings_osf1.def" #endif #ifdef USE_DOS #include "encodings_dos.def" #endif #ifdef USE_EXTRA #include "encodings_extra.def" #endif #undef DEFENCODING #define DEFENCODING(xxx_names,xxx,xxx_ifuncs1,xxx_ifuncs2,xxx_ofuncs1,xxx_ofuncs2) \ { xxx_ifuncs1,xxx_ifuncs2, xxx_ofuncs1,xxx_ofuncs2, 0 }, #include "encodings_local.def" #undef DEFENCODING }; /* * Conversion loops. */ #include "loops.h" /* * Alias lookup function. * Defines * struct alias { int name; unsigned int encoding_index; }; * const struct alias * aliases_lookup (const char *str, unsigned int len); * #define MAX_WORD_LENGTH ... */ #include "aliases.h" /* * System dependent alias lookup function. * Defines * const struct alias * aliases2_lookup (const char *str); */ #if defined(USE_AIX) || defined(USE_OSF1) || defined(USE_DOS) || defined(USE_EXTRA) /* || ... */ struct stringpool2_t { #define S(tag,name,encoding_index) char stringpool_##tag[sizeof(name)]; #include "aliases2.h" #undef S }; static const struct stringpool2_t stringpool2_contents = { #define S(tag,name,encoding_index) name, #include "aliases2.h" #undef S }; #define stringpool2 ((const char *) &stringpool2_contents) static const struct alias sysdep_aliases[] = { #define S(tag,name,encoding_index) { (int)(long)&((struct stringpool2_t *)0)->stringpool_##tag, encoding_index }, #include "aliases2.h" #undef S }; #ifdef __GNUC__ __inline #endif const struct alias * aliases2_lookup (register const char *str) { const struct alias * ptr; unsigned int count; for (ptr = sysdep_aliases, count = sizeof(sysdep_aliases)/sizeof(sysdep_aliases[0]); count > 0; ptr++, count--) if (!strcmp(str, stringpool2 + ptr->name)) return ptr; return NULL; } #else #define aliases2_lookup(str) NULL #define stringpool2 NULL #endif #if 0 /* Like !strcasecmp, except that the both strings can be assumed to be ASCII and the first string can be assumed to be in uppercase. */ static int strequal (const char* str1, const char* str2) { unsigned char c1; unsigned char c2; for (;;) { c1 = * (unsigned char *) str1++; c2 = * (unsigned char *) str2++; if (c1 == 0) break; if (c2 >= 'a' && c2 <= 'z') c2 -= 'a'-'A'; if (c1 != c2) break; } return (c1 == c2); } #endif iconv_t iconv_open (const char* tocode, const char* fromcode) { struct conv_struct * cd; char buf[MAX_WORD_LENGTH+10+1]; const char* cp; char* bp; const struct alias * ap; unsigned int count; unsigned int from_index; int from_wchar; unsigned int to_index; int to_wchar; int transliterate = 0; int discard_ilseq = 0; /* Before calling aliases_lookup, convert the input string to upper case, * and check whether it's entirely ASCII (we call gperf with option "-7" * to achieve a smaller table) and non-empty. If it's not entirely ASCII, * or if it's too long, it is not a valid encoding name. */ for (to_wchar = 0;;) { /* Search tocode in the table. */ for (cp = tocode, bp = buf, count = MAX_WORD_LENGTH+10+1; ; cp++, bp++) { unsigned char c = * (unsigned char *) cp; if (c >= 0x80) goto invalid; if (c >= 'a' && c <= 'z') c -= 'a'-'A'; *bp = c; if (c == '\0') break; if (--count == 0) goto invalid; } for (;;) { if (bp-buf >= 10 && memcmp(bp-10,"//TRANSLIT",10)==0) { bp -= 10; *bp = '\0'; transliterate = 1; continue; } if (bp-buf >= 8 && memcmp(bp-8,"//IGNORE",8)==0) { bp -= 8; *bp = '\0'; discard_ilseq = 1; continue; } break; } if (buf[0] == '\0') { tocode = locale_charset(); /* Avoid an endless loop that could occur when using an older version of localcharset.c. */ if (tocode[0] == '\0') goto invalid; continue; } ap = aliases_lookup(buf,bp-buf); if (ap == NULL) { ap = aliases2_lookup(buf); if (ap == NULL) goto invalid; } if (ap->encoding_index == ei_local_char) { tocode = locale_charset(); /* Avoid an endless loop that could occur when using an older version of localcharset.c. */ if (tocode[0] == '\0') goto invalid; continue; } if (ap->encoding_index == ei_local_wchar_t) { #if __STDC_ISO_10646__ if (sizeof(wchar_t) == 4) { to_index = ei_ucs4internal; break; } if (sizeof(wchar_t) == 2) { to_index = ei_ucs2internal; break; } if (sizeof(wchar_t) == 1) { to_index = ei_iso8859_1; break; } #endif #if HAVE_MBRTOWC to_wchar = 1; tocode = locale_charset(); continue; #endif goto invalid; } to_index = ap->encoding_index; break; } for (from_wchar = 0;;) { /* Search fromcode in the table. */ for (cp = fromcode, bp = buf, count = MAX_WORD_LENGTH+10+1; ; cp++, bp++)
评论
    相关推荐