zoukankan      html  css  js  c++  java
  • 关于catopen函数

    关于catopen函数:

    参考网址:http://pubs.opengroup.org/onlinepubs/009695399/functions/catopen.html

    1)编辑消息文件

    [root@Master catlogTest]# vi msg1.euc

      1 Hello msg1.euc 1

      2 Hello msg2.euc 2

      3 Hello msg3.euc 3

      4 Hello msg4.euc 4

    [root@Master catlogTest]# vi msg1.sjis

           1 Hello msg1.sjis 1

           2 Hello msg2.sjis 2

           3 Hello msg3.sjis 3

           4 Hello msg4.sjis 4

    2)用gencat生成cat文件

    [root@Master catlogTest]# gencat msg1.euc.cat msg1.euc

    [root@Master catlogTest]# ls

    msg1.euc  msg1.euc.cat  msg1.sjis

    [root@Master catlogTest]# gencat msg2.sjis.cat msg1.sjis

    [root@Master catlogTest]# ls

    msg1.euc  msg1.euc.cat  msg1.sjis  msg2.sjis.cat

    3)使用catopen等函数调用消息

    #include <stdio.h>

     #include <locale.h>

     #include <nl_types.h>

     int main()

     {

        nl_catd catid = NULL;

        char *fstr;

        char *s1;

        

        setlocale(LC_ALL,"");

       

         catid = catopen("/root/honglihua/catlogTest/msg1.euc.cat",NL_CAT_LOCALE);

         if((int)catid == -1)

          {

                fprintf(stdout,":Can't open message catlog");

                 return -1;

           }

        

         fstr = (char *)catgets(catid,1,1,"default string");

         fprintf(stdout,"%s ",fstr);

        

         catclose(catid);

        

         return 0;

              }

    编译:

    [root@Master catlogTest]# gcc -o catopenTest catopenTest.c

    执行:

    [root@Master catlogTest]# ./catopenTest

    Hello msg1.euc 1

    如果

    fstr = (char *)catgets(catid,1,2,"default string");

    执行结果为:

    [root@Master catlogTest]# ./catopenTest

    Hello msg2.euc 2

    如果catopen第一个参数不带路径,则可以设置NLSPATH环境变量如下:
    setenv NLSPATH /usr/lib/locale/%L/LC_MESSAGES/%N
    (%L会被$LANG代替;%N会被catopen中的hello代替)
    在调用:
    catopen("hello", NL_CAT_LOCALE)时,
    会去/usr/lib/locale/en_US/LC_MESSAGES/hello
    这个路径寻找消息文件

    补充:

    经过测试,得出当catopen的满足如下条件值时, %L会按照LC_ALL > LC_MESSAGES > LANG的优先值顺序进行替换。

    1)catopen的第一个参数不为路径

    2)catopen的第二个参数为NL_CAT_LOCALE(如果第二个参数为0,%L会被$LANG代替)

    3)设置了环境变量NLSPATH,且该变量所指的路径中使用%L

  • 相关阅读:
    ps photoshop cc 2015 Extract Assets(生成器)切图大法
    获取免费代理推荐
    nodejs http代理请求
    nodejs 发起http请求
    AHK GUI开发示例
    为【桌面右键菜单
    NPM 模块收集
    nodejs Commander 命令行神器简单示例
    如何用nodejs 开发一个命令行交互工具
    利用 T-sql 的从句 for xml path('') 实现多行合并到一行, 并带有分隔符
  • 原文地址:https://www.cnblogs.com/honglihua8688/p/3709020.html
Copyright © 2011-2022 走看看