File: getLcidString.c

package info (click to toggle)
scilab 6.0.1-10%2Bdeb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 365,292 kB
  • sloc: xml: 827,376; cpp: 273,125; ansic: 216,672; java: 190,706; fortran: 90,783; ml: 24,107; tcl: 16,853; sh: 13,608; makefile: 9,556; lex: 1,615; perl: 1,566; yacc: 1,263; php: 690; cs: 614
file content (93 lines) | stat: -rw-r--r-- 2,750 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 * Copyright (C) 2010 - DIGITEO - Allan CORNET
 *
 * Copyright (C) 2012 - 2016 - Scilab Enterprises
 *
 * This file is hereby licensed under the terms of the GNU GPL v2.0,
 * pursuant to article 5.3.4 of the CeCILL v.2.1.
 * This file was originally licensed under the terms of the CeCILL v2.1,
 * and continues to be available under such terms.
 * For more information, see the COPYING file which you should have received
 * along with this program.
 *
 */
/*--------------------------------------------------------------------------*/
#include <string.h>
#include <stdio.h>
#ifdef _MSC_VER
#include <Windows.h>
#include "LocaleNameToLCID_Windows.h"
#endif
#include "os_string.h"
#include "getLcidString.h"
#include "sci_malloc.h"
#include "charEncoding.h"
#include "machine.h" /* bsiz */
/*--------------------------------------------------------------------------*/
#define DEFAULT_EN_LCID "0x0409"
/*--------------------------------------------------------------------------*/
#ifdef _MSC_VER
/* replaces '_' by '-' windows local format and convert to wide string */
static wchar_t *getWindowsLocaleFormat(const char *pStrLocale);
#endif
/*--------------------------------------------------------------------------*/
char *getLcidString(const char *pStrLocale)
{
    char *pStrLCID = NULL;

    if (pStrLocale == NULL)
    {
        return os_strdup(DEFAULT_EN_LCID);
    }
#ifdef _MSC_VER
    if ((strcmp(pStrLocale, "") == 0) || (strcmp(pStrLocale, "C") == 0))
    {
        return os_strdup(DEFAULT_EN_LCID);
    }
    else
    {
        wchar_t *wLocale = getWindowsLocaleFormat(pStrLocale);
        LCID lcid = dllLocaleNameToLCID(wLocale, 0);

        if (lcid == 0)
        {
            pStrLCID = os_strdup(DEFAULT_EN_LCID);
        }
        else
        {
            pStrLCID = (char *)MALLOC(sizeof(char) * bsiz);
            if (pStrLCID)
            {
                sprintf(pStrLCID, "0x0%x", lcid);
            }
        }
    }
#else
    /* this routines not used on others platforms */
    pStrLCID = os_strdup(DEFAULT_EN_LCID);
#endif
    return pStrLCID;
}
/*--------------------------------------------------------------------------*/
#ifdef _MSC_VER
static wchar_t *getWindowsLocaleFormat(const char *pStrLocale)
{
    wchar_t *Locale = NULL;
    if (pStrLocale)
    {
        wchar_t *pwStrLocale = to_wide_string(pStrLocale);
        if (pwStrLocale)
        {
            wchar_t *pos = wcschr(pwStrLocale, L'_');
            if (pos)
            {
                *pos = L'-';
            }
            Locale = pwStrLocale;
        }
    }
    return Locale;
}
#endif
/*--------------------------------------------------------------------------*/