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: HelpXlate.c /main/1 1996/08/22 09:16:03 rswiston $ */
24 /****************************************************************************
25 $FILEBEG$: HelpXlate.c
27 $COMPONENT$: DtXlate service
28 $1LINER$: Implements a translation service using tables and regex search
30 (c) Copyright 1993, 1994 Hewlett-Packard Company
31 (c) Copyright 1993, 1994 International Business Machines Corp.
32 (c) Copyright 1993, 1994 Sun Microsystems, Inc.
33 (c) Copyright 1993, 1994 Unix System Labs, Inc., a subsidiary of Novell, Inc.
35 ****************************************************************************
36 ************************************<+>*************************************/
41 #include <sys/param.h> /* MAXPATHLEN */
45 #include <X11/Intrinsic.h>
47 /*=================================================================
48 $SHAREDBEG$: This header appears in all appropriate DtXlate topics
49 =======================================================$SKIP$======*/
51 #include "HelpXlate.h"
55 static char MyPlatform[_DtPLATFORM_MAX_LEN+1];
56 static _DtXlateDb MyDb = NULL;
60 static const char *DfltStdCharset = "ISO-8859-1";
61 static const char *DfltStdLang = "C";
63 /*========================================================*/
64 /*================== Private routines ====================*/
65 /*========================================================*/
66 /******************************************************************************
67 * Function: static int OpenLcxDb ()
76 * Purpose: Opens the Ce-private Lcx database
78 *****************************************************************************/
84 static short MyProcess = False;
85 static short MyFirst = True;
88 * wait 30 sec. until another thread or enter is done modifying the table
90 while (MyProcess == True)
92 /* if time out, return */
93 if (time(&time2) == (time_t)-1)
98 else if (time2 - time1 >= (time_t)30)
102 _DtHelpProcessLock();
106 if (_DtLcxOpenAllDbs(&MyDb) == 0 &&
107 _DtXlateGetXlateEnv(MyDb,MyPlatform,&ExecVer,&CompVer) != 0)
109 _DtLcxCloseDb(&MyDb);
115 _DtHelpProcessUnlock();
117 return (MyDb == NULL ? -1 : 0 );
120 /******************************************************************************
121 * Function: int _DtHelpCeXlateStdToOpLocale ( char *operation, char *stdLoc
123 * char *dflt_opLocale, char **ret_opLocale
127 * operation operation whose locale value will be retrieved
128 * stdLocale standard locale value
129 * dflt_opLocale operation-specific locale-value
130 * This is the default value used in error case
131 * ret_opLocale operation-specific locale-value placed here
132 * Caller must free this string.
136 * Purpose: Gets an operation-specific locale string given the standard string
138 *****************************************************************************/
140 _DtHelpCeXlateStdToOpLocale (
146 int result = OpenLcxDb();
148 _DtHelpProcessLock();
151 (void) _DtLcxXlateStdToOp(MyDb, MyPlatform, CompVer,
152 operation, stdLocale, NULL, NULL, NULL, ret_opLocale);
154 _DtHelpProcessUnlock();
156 /* if translation fails, use a default value */
157 if (ret_opLocale && (result != 0 || *ret_opLocale == NULL))
159 if (dflt_opLocale) *ret_opLocale = strdup(dflt_opLocale);
160 else if (stdLocale) *ret_opLocale = strdup(stdLocale);
165 /******************************************************************************
166 * Function: int _DtHelpCeXlateOpToStdLocale (char *operation, char *opLocale
168 * char **ret_stdLocale, char **ret_stdLang, char **ret_
172 * operation Operation associated with the locale value
173 * opLocale An operation-specific locale string
174 * ret_locale Returns the std locale
175 * Caller must free this string.
176 * ret_stdLang Returns the std language & territory string.
177 * Caller must free this string.
178 * ret_stdSet Returns the std code set string.
179 * Caller must free this string.
183 * Purpose: Gets the standard locale given an operation and its locale
185 *****************************************************************************/
187 _DtHelpCeXlateOpToStdLocale (
190 char **ret_stdLocale,
194 int result = OpenLcxDb();
196 _DtHelpProcessLock();
199 (void) _DtLcxXlateOpToStd(MyDb, MyPlatform, CompVer,
201 ret_stdLocale, ret_stdLang, ret_stdSet, NULL);
203 _DtHelpProcessUnlock();
205 /* if failed, give default values */
206 if (ret_stdLocale != NULL && (result != 0 || *ret_stdLocale == NULL))
208 *ret_stdLocale = malloc(
209 strlen(DfltStdLang)+strlen(DfltStdCharset)+3);
210 sprintf(*ret_stdLocale,"%s.%s",DfltStdLang,DfltStdCharset);
212 if (ret_stdLang != NULL && (result != 0 || *ret_stdLang == NULL))
213 *ret_stdLang = strdup(DfltStdLang);
214 if (ret_stdSet != NULL && (result != 0 || *ret_stdSet == NULL))
215 *ret_stdSet = strdup(DfltStdCharset);
218 /******************************************************************************
219 * Function: int _DtHelpCeGetMbLen (char *lang, char *char_set)
222 * lang Represents the language. A NULL value
224 * char_set Represents the character set. A NULL
225 * value value defaults to "ISO-8859-1"
227 * Return Value: Returns the MB_CUR_MAX for the combination
232 * Purpose: To determine the maximum number of bytes required to display
233 * a character if/when the environment is set to 'lang.charset'
235 *****************************************************************************/
244 lang = (char *)DfltStdLang;
246 if (char_set == NULL)
247 char_set = (char *)DfltStdCharset;
249 _DtHelpProcessLock();
250 if (OpenLcxDb() == 0)
252 /* if translation is present, lang.charset are a multibyte locale */
253 if (_DtLcxXlateStdToOp(MyDb, MyPlatform, CompVer, DtLCX_OPER_MULTIBYTE,
254 NULL, lang, char_set, NULL, NULL) == 0)
257 _DtHelpProcessUnlock();