免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 6925 | 回复: 18
打印 上一主题 下一主题

[其它] ARM9 开发板上 不能locale ,还有怎么查支持的字符集 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-09-23 19:36 |只看该作者 |倒序浏览
RT,请教各位大神

论坛徽章:
0
2 [报告]
发表于 2013-09-23 19:37 |只看该作者
或者怎么安装 locale

论坛徽章:
5
摩羯座
日期:2014-07-22 09:03:552015元宵节徽章
日期:2015-03-06 15:50:392015亚冠之大阪钢巴
日期:2015-06-12 16:01:352015年中国系统架构师大会
日期:2015-06-29 16:11:2815-16赛季CBA联赛之四川
日期:2018-12-17 14:10:21
3 [报告]
发表于 2013-09-23 20:18 |只看该作者
本帖最后由 T-Bagwell 于 2013-09-23 20:23 编辑

这个比较好弄
不过没有必要用locale,最好还是用iconv好些

安装locale的话,你需要找到你的arm-linux-的toolchains里面,有对应的locale的库
使用nfs将对应的目录挂到你的板子上,然后localedef安装就可以了

不过最好还是用iconv来做,比locale小很多,而且还方便

论坛徽章:
0
4 [报告]
发表于 2013-09-23 20:55 |只看该作者
对 我的函数里用的也是iconv 可是出现iconv_open error: Invalid argument

我认为是板子里没有我要的字符集,所以我要用locale 命令看下里有没有我要的字符集

或者版主你有没有其它办法看板子支持的字符集

谢谢版主回复 3# T-Bagwell


   

论坛徽章:
5
摩羯座
日期:2014-07-22 09:03:552015元宵节徽章
日期:2015-03-06 15:50:392015亚冠之大阪钢巴
日期:2015-06-12 16:01:352015年中国系统架构师大会
日期:2015-06-29 16:11:2815-16赛季CBA联赛之四川
日期:2018-12-17 14:10:21
5 [报告]
发表于 2013-09-23 21:22 |只看该作者
iconv -l就可以看的

论坛徽章:
0
6 [报告]
发表于 2013-09-23 21:47 |只看该作者
好的 为什么我用iconv 从GBK到UTF-8 出现 Invalid argument

从GBK到UNICODE也出现Invalid argument

而从GBK到UTF-16却可以

iconv 对这些都支持啊回复 5# T-Bagwell


   

论坛徽章:
5
摩羯座
日期:2014-07-22 09:03:552015元宵节徽章
日期:2015-03-06 15:50:392015亚冠之大阪钢巴
日期:2015-06-12 16:01:352015年中国系统架构师大会
日期:2015-06-29 16:11:2815-16赛季CBA联赛之四川
日期:2018-12-17 14:10:21
7 [报告]
发表于 2013-09-23 22:02 |只看该作者
回复 6# tjf258


    有可能确实是你传递参数的问题了

论坛徽章:
0
8 [报告]
发表于 2013-09-23 22:05 |只看该作者
那得从哪开始解决啊回复 7# T-Bagwell


   

论坛徽章:
5
摩羯座
日期:2014-07-22 09:03:552015元宵节徽章
日期:2015-03-06 15:50:392015亚冠之大阪钢巴
日期:2015-06-12 16:01:352015年中国系统架构师大会
日期:2015-06-29 16:11:2815-16赛季CBA联赛之四川
日期:2018-12-17 14:10:21
9 [报告]
发表于 2013-09-23 22:08 |只看该作者
回复 8# tjf258
  1.      #include <stdio.h>
  2.      #include <errno.h>
  3.      #include <string.h>
  4.      #include <iconv.h>
  5.      #include <stdlib.h>


  6.      /*
  7.       * For state-dependent encodings, changes the state of the conversion
  8.       * descriptor to initial shift state.  Also, outputs the byte sequence
  9.       * to change the state to initial state.
  10.       * This code is assuming the iconv call for initializing the state
  11.       * won't fail due to lack of space in the output buffer.
  12.       */
  13.      #define INIT_SHIFT_STATE(cd, fptr, ileft, tptr, oleft) \
  14.          { \
  15.              fptr = NULL; \
  16.              ileft = 0; \
  17.              tptr = to; \
  18.              oleft = BUFSIZ; \
  19.              (void) iconv(cd, &fptr, &ileft, &tptr, &oleft); \
  20.              (void) fwrite(to, 1, BUFSIZ - oleft, stdout); \
  21.          }

  22.      int
  23.      main(int argc, char **argv)
  24.      {
  25.          iconv_t cd;
  26.          char    from[BUFSIZ], to[BUFSIZ];
  27.          char    *from_code, *to_code;
  28.          char    *tptr;
  29.          const char  *fptr;
  30.          size_t  ileft, oleft, num, ret;

  31.          if (argc != 3) {
  32.              (void) fprintf(stderr,
  33.                  "Usage: %s from_codeset to_codeset\\n", argv[0]);
  34.              return (1);
  35.          }

  36.          from_code = argv[1];
  37.          to_code = argv[2];

  38.          cd = iconv_open((const char *)to_code, (const char *)from_code);
  39.          if (cd == (iconv_t)-1) {
  40.              /*
  41.               * iconv_open failed
  42.               */
  43.              (void) fprintf(stderr,
  44.                  "iconv_open(%s, %s) failed\\n", to_code, from_code);
  45.              return (1);
  46.          }

  47.          ileft = 0;
  48.          while ((ileft +=
  49.              (num = fread(from + ileft, 1, BUFSIZ - ileft, stdin))) >; 0) {
  50.              if (num == 0) {
  51.                  /*


  52.                   * Input buffer still contains incomplete character
  53.                   * or sequence.  However, no more input character.
  54.                   */

  55.                  /*
  56.                   * Initializes the conversion descriptor and outputs
  57.                   * the sequence to change the state to initial state.
  58.                   */
  59.                  INIT_SHIFT_STATE(cd, fptr, ileft, tptr, oleft);
  60.                  (void) iconv_close(cd);

  61.                  (void) fprintf(stderr, "Conversion error\\n");
  62.                  return (1);
  63.              }

  64.              fptr = from;
  65.              for (;;) {
  66.                  tptr = to;
  67.                  oleft = BUFSIZ;

  68.                  ret = iconv(cd, &fptr, &ileft, &tptr, &oleft);
  69.                  if (ret != (size_t)-1) {
  70.                      /*
  71.                       * iconv succeeded
  72.                       */

  73.                      /*
  74.                       * Outputs converted characters
  75.                       */
  76.                      (void) fwrite(to, 1, BUFSIZ - oleft, stdout);
  77.                      break;
  78.                  }

  79.                  /*
  80.                   * iconv failed
  81.                   */
  82.                  if (errno == EINVAL) {
  83.                      /*
  84.                     * Incomplete character or shift sequence
  85.                       */

  86.                      /*
  87.                       * Outputs converted characters
  88.                       */
  89.                      (void) fwrite(to, 1, BUFSIZ - oleft, stdout);
  90.                      /*
  91.                       * Copies remaining characters in input buffer
  92.                       * to the top of the input buffer.
  93.                       */
  94.                      (void) memmove(from, fptr, ileft);
  95.                      /*
  96.                       * Tries to fill input buffer from stdin

  97.                       */
  98.                      break;
  99.                  } else if (errno == E2BIG) {
  100.                      /*
  101.                       * Lack of space in output buffer
  102.                       */

  103.                      /*
  104.                       * Outputs converted characters
  105.                       */
  106.                      (void) fwrite(to, 1, BUFSIZ - oleft, stdout);
  107.                      /*
  108.                       * Tries to convert remaining characters in
  109.                       * input buffer with emptied output buffer
  110.                       */
  111.                      continue;
  112.                  } else if (errno == EILSEQ) {
  113.                      /*
  114.                       * Illegal character or shift sequence
  115.                       */

  116.                      /*
  117.                       * Outputs converted characters
  118.                       */
  119.                      (void) fwrite(to, 1, BUFSIZ - oleft, stdout);
  120.                      /*
  121.                       * Initializes the conversion descriptor and
  122.                       * outputs the sequence to change the state to
  123.                       * initial state.
  124.                       */
  125.                      INIT_SHIFT_STATE(cd, fptr, ileft, tptr, oleft);
  126.                      (void) iconv_close(cd);

  127.                      (void) fprintf(stderr,
  128.                       "Illegal character or sequence\\n");
  129.                      return (1);
  130.                  } else if (errno == EBADF) {
  131.                      /*
  132.                       * Invalid conversion descriptor.
  133.                       * Actually, this shouldn't happen here.
  134.                       */
  135.                      (void) fprintf(stderr, "Conversion error\\n");
  136.                      return (1);
  137.                  } else {
  138.                      /*
  139.                       * This errno is not defined
  140.                       */
  141.                      (void) fprintf(stderr, "iconv error\\n");
  142.                      return (1);
  143.                  }
  144.              }
  145.          }


  146.          /*
  147.           * Initializes the conversion descriptor and outputs
  148.           * the sequence to change the state to initial state.
  149.           */
  150.          INIT_SHIFT_STATE(cd, fptr, ileft, tptr, oleft);

  151.          (void) iconv_close(cd);
  152.          return (0);
  153.      }
复制代码

论坛徽章:
0
10 [报告]
发表于 2013-09-24 18:19 |只看该作者
百度了下
iconv_open() 函数
如下值得一提的错误可能发生:
EINVAL
实现不支持

发现竟然不能支持字符从 fromcode 到 tocode 的转换。
可奇怪的是我iconv -l
有UCS-2,
  UCS-2BE, UCS-2LE, UCS-4, UCS-4BE, UCS-4LE, UCS2, UCS4, UHC, UJIS, UK,
  UNICODE, UNICODEBIG, UNICODELITTLE, US-ASCII, US, UTF-7, UTF-8, UTF-16,
  UTF-16BE, UTF-16LE, UTF-32, UTF-32BE, UTF-32LE, UTF7, UTF8, UTF16,

这会是什么问题呢

回复 9# T-Bagwell


   
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP