コード例 #1
0
// creates a table-based multibyte locale
const char* create_locale ()
{
    char cm_fname [1024];
    if (rw_snprintf (cm_fname, sizeof cm_fname, "%s%c%s",
                     locale_root, _RWSTD_PATH_SEP, "charmap") < 0)
        return 0;

    static const char charmap[] = {
        "<code_set_name> test_charmap\n"
        "<comment_char> %\n"
        "<escape_char> /\n"
        "<mb_cur_min> 1\n"
        "<mb_cur_max> 9\n"
        "CHARMAP\n"
        "<U0000>   /x30                                   0 \n"
        "<U0001>   /x31                                   1 \n"
        "<U0002>   /x32/x32                               22 \n"
        "<U0003>   /x33/x33/x33                           333 \n"
        "<U0004>   /x34/x34/x34/x34                       4444 \n"
        "<U0005>   /x35/x35/x35/x35/x35                   55555 \n"
        "<U0006>   /x36/x36/x36/x36/x36/x36               666666 \n"
        "<U0007>   /x37/x37/x37/x37/x37/x37/x37           7777777 \n"
        "<U0008>   /x38/x38/x38/x38/x38/x38/x38/x38       88888888 \n"
        "<U0009>   /x39/x39/x39/x39/x39/x39/x39/x39/x39   999999999 \n"
        "<U0010>   /x41 A \n"
        "<U0011>   /x42 B \n"
        "<U0012>   /x43 C \n"
        "END CHARMAP\n"
    };

    if (std::size_t (-1) == rw_fwrite (cm_fname, charmap))
        return 0;

    char src_fname [1024];
    if (rw_snprintf (src_fname, sizeof src_fname, "%s%c%s",
                     locale_root, _RWSTD_PATH_SEP, "source") < 0)
        return 0;

    if (std::size_t (-1) == rw_fwrite (src_fname, "LC_CTYPE\nEND LC_CTYPE\n"))
        return 0;

    // invoke localedef to create the named locale
    // silence the following warnings:
    // 701: no compatible locale found
    // 702: member of portable character set <x> not found
    //      in the character map
    // 706: iconv_open() failed
    const char* const locname =
        rw_localedef ("-w701 -w702 -w706",
                      src_fname, cm_fname, "mb_cur_max-9");

    return locname;
}
コード例 #2
0
ファイル: 0.locale.cpp プロジェクト: Flameeyes/stdcxx
static int
test_localedef ()
{
    // the root of the locale directory (RWSTD_LOCALE_ROOT)
    static const char* const locale_root = rw_set_locale_root ();

    static int inx;

    const int id = inx++;

    // create a temporary locale definition file
    char srcfname [1024];
    if (rw_snprintf (srcfname, sizeof srcfname, "%s%c%s.%d",
                     locale_root, _RWSTD_PATH_SEP, "locale", id) < 0)
        return -1;

    // create a temporary character map file
    char cmfname [1024];
    if (rw_snprintf (cmfname, sizeof cmfname, "%s%c%s.%d.src",
                     locale_root, _RWSTD_PATH_SEP, "charmap", id) < 0)
        return -1;

    rw_fwrite (srcfname, "LC_CTYPE\nEND LC_CTYPE\n");
    rw_fwrite (cmfname, "CHARMAP\nEND CHARMAP\n");

    const char opts[]    = "-w";
    char locname[40];
    rw_snprintf (locname, sizeof locname, "%s.%d", "locale", id);

    // try to create the locale
    const char* const ret =
        rw_localedef (opts, srcfname, cmfname, locname);

    const char* const topdir = std::getenv ("TOPDIR");

    rw_assert (0 != ret, 0, __LINE__,
               "rw_localedef(%s, %#s, %#s, %#s) failed with TOPDIR=%#s",
               opts, srcfname, cmfname, locname, topdir);

    // remove temporary files
    std::remove (cmfname);
    std::remove (srcfname);

    return 0;
}