2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: i18nxlate.c /main/5 1995/11/09 13:00:30 rswiston $ */
25 * (c) Copyright 1993, 1994 Hewlett-Packard Company
26 * (c) Copyright 1993, 1994 International Business Machines Corp.
27 * (c) Copyright 1993, 1994 Novell, Inc.
28 * (c) Copyright 1993, 1994 Sun Microsystems, Inc.
37 #include <LocaleXlate.h> /* under DtHelp, for Operation constants */
48 * Wrapper functions taken from libHelp/CEUtil.c
50 * We took these functions and renamed them because
51 * 1. Originally these are called _DtHelpCeXlate* and thus they are private
52 * to libHelp and not exported to outside of libHelp.
53 * 2. When these functions are moved to another library, then users of these
54 * functions would only need to link with a different library. The caller
55 * doesn't have to modify code.
58 static const char *DfltStdCharset = "ISO-8859-1";
59 static const char *DfltStdLang = "C";
61 static char MyPlatform[_DtPLATFORM_MAX_LEN+1];
62 static _DtXlateDb MyDb = NULL;
63 char MyProcess = False;
69 /******************************************************************************
70 * Function: static int OpenLcxDb ()
79 * Purpose: Opens the Ce-private Lcx database
81 *****************************************************************************/
89 * wait 30 sec. until another thread or enter is done modifying the table
91 while (MyProcess == True)
93 /* if time out, return */
94 if (time(&time2) == (time_t)-1)
99 else if (time2 - time1 >= (time_t)30)
106 if (_DtLcxOpenAllDbs(&MyDb) == 0 &&
107 _DtXlateGetXlateEnv(MyDb,MyPlatform,&ExecVer,&CompVer) != 0)
109 _DtLcxCloseDb(&MyDb);
116 return (MyDb == NULL ? -1 : 0 );
119 /******************************************************************************
120 * Function: int DtI18NXlateOpToStdLocale (char *operation, char *opLocale,
121 * char **ret_stdLocale, char **ret_stdLang, char **ret_stdSet)
124 * operation Operation associated with the locale value
125 * opLocale An operation-specific locale string
126 * ret_locale Returns the std locale
127 * Caller must free this string.
128 * ret_stdLang Returns the std language & territory string.
129 * Caller must free this string.
130 * ret_stdSet Returns the std code set string.
131 * Caller must free this string.
135 * Purpose: Gets the standard locale given an operation and its locale
137 *****************************************************************************/
139 _DtI18NXlateOpToStdLocale (
142 char **ret_stdLocale,
150 (void) _DtLcxXlateOpToStd(MyDb, MyPlatform, CompVer,
152 ret_stdLocale, ret_stdLang, ret_stdSet, NULL);
155 /* if failed, give default values */
156 if (ret_stdLocale != NULL && *ret_stdLocale == NULL)
158 *ret_stdLocale = (char *)malloc(strlen(DfltStdLang)+strlen(DfltStdCharset)+3);
159 sprintf(*ret_stdLocale,"%s.%s",DfltStdLang,DfltStdCharset);
161 if (ret_stdLang != NULL && *ret_stdLang == NULL)
162 *ret_stdLang = (char *)strdup(DfltStdLang);
163 if (ret_stdSet != NULL && *ret_stdSet == NULL)
164 *ret_stdSet = (char *)strdup(DfltStdCharset);
167 /******************************************************************************
168 * Function: int DtI18NXlateStdToOpLocale ( char *operation, char *stdLocale,
169 * char *dflt_opLocale, char **ret_opLocale)
172 * operation operation whose locale value will be retrieved
173 * stdLocale standard locale value
174 * dflt_opLocale operation-specific locale-value
175 * This is the default value used in error case
176 * ret_opLocale operation-specific locale-value placed here
177 * Caller must free this string.
181 * Purpose: Gets an operation-specific locale string given the standard string
183 *****************************************************************************/
185 _DtI18NXlateStdToOpLocale (
195 (void) _DtLcxXlateStdToOp(MyDb, MyPlatform, CompVer,
196 operation, stdLocale, NULL, NULL, NULL, ret_opLocale);
199 /* if translation fails, use a default value */
200 if (ret_opLocale && *ret_opLocale == NULL)
202 if (dflt_opLocale) *ret_opLocale = (char *)strdup(dflt_opLocale);
203 else if (stdLocale) *ret_opLocale = (char *)strdup(stdLocale);