1 /* $XConsortium: i18nxlate.c /main/5 1995/11/09 13:00:30 rswiston $ */
3 * (c) Copyright 1993, 1994 Hewlett-Packard Company
4 * (c) Copyright 1993, 1994 International Business Machines Corp.
5 * (c) Copyright 1993, 1994 Novell, Inc.
6 * (c) Copyright 1993, 1994 Sun Microsystems, Inc.
15 #include <LocaleXlate.h> /* under DtHelp, for Operation constants */
26 * Wrapper functions taken from libHelp/CEUtil.c
28 * We took these functions and renamed them because
29 * 1. Originally these are called _DtHelpCeXlate* and thus they are private
30 * to libHelp and not exported to outside of libHelp.
31 * 2. When these functions are moved to another library, then users of these
32 * functions would only need to link with a different library. The caller
33 * doesn't have to modify code.
36 static const char *DfltStdCharset = "ISO-8859-1";
37 static const char *DfltStdLang = "C";
39 static char MyPlatform[_DtPLATFORM_MAX_LEN+1];
40 static _DtXlateDb MyDb = NULL;
41 char MyProcess = False;
47 /******************************************************************************
48 * Function: static int OpenLcxDb ()
57 * Purpose: Opens the Ce-private Lcx database
59 *****************************************************************************/
67 * wait 30 sec. until another thread or enter is done modifying the table
69 while (MyProcess == True)
71 /* if time out, return */
72 if (time(&time2) == (time_t)-1)
77 else if (time2 - time1 >= (time_t)30)
84 if (_DtLcxOpenAllDbs(&MyDb) == 0 &&
85 _DtXlateGetXlateEnv(MyDb,MyPlatform,&ExecVer,&CompVer) != 0)
94 return (MyDb == NULL ? -1 : 0 );
97 /******************************************************************************
98 * Function: int DtI18NXlateOpToStdLocale (char *operation, char *opLocale,
99 * char **ret_stdLocale, char **ret_stdLang, char **ret_stdSet)
102 * operation Operation associated with the locale value
103 * opLocale An operation-specific locale string
104 * ret_locale Returns the std locale
105 * Caller must free this string.
106 * ret_stdLang Returns the std language & territory string.
107 * Caller must free this string.
108 * ret_stdSet Returns the std code set string.
109 * Caller must free this string.
113 * Purpose: Gets the standard locale given an operation and its locale
115 *****************************************************************************/
117 _DtI18NXlateOpToStdLocale (
120 char **ret_stdLocale,
128 (void) _DtLcxXlateOpToStd(MyDb, MyPlatform, CompVer,
130 ret_stdLocale, ret_stdLang, ret_stdSet, NULL);
133 /* if failed, give default values */
134 if (ret_stdLocale != NULL && *ret_stdLocale == NULL)
136 *ret_stdLocale = (char *)malloc(strlen(DfltStdLang)+strlen(DfltStdCharset)+3);
137 sprintf(*ret_stdLocale,"%s.%s",DfltStdLang,DfltStdCharset);
139 if (ret_stdLang != NULL && *ret_stdLang == NULL)
140 *ret_stdLang = (char *)strdup(DfltStdLang);
141 if (ret_stdSet != NULL && *ret_stdSet == NULL)
142 *ret_stdSet = (char *)strdup(DfltStdCharset);
145 /******************************************************************************
146 * Function: int DtI18NXlateStdToOpLocale ( char *operation, char *stdLocale,
147 * char *dflt_opLocale, char **ret_opLocale)
150 * operation operation whose locale value will be retrieved
151 * stdLocale standard locale value
152 * dflt_opLocale operation-specific locale-value
153 * This is the default value used in error case
154 * ret_opLocale operation-specific locale-value placed here
155 * Caller must free this string.
159 * Purpose: Gets an operation-specific locale string given the standard string
161 *****************************************************************************/
163 _DtI18NXlateStdToOpLocale (
173 (void) _DtLcxXlateStdToOp(MyDb, MyPlatform, CompVer,
174 operation, stdLocale, NULL, NULL, NULL, ret_opLocale);
177 /* if translation fails, use a default value */
178 if (ret_opLocale && *ret_opLocale == NULL)
180 if (dflt_opLocale) *ret_opLocale = (char *)strdup(dflt_opLocale);
181 else if (stdLocale) *ret_opLocale = (char *)strdup(stdLocale);