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 */
44 #include <X11/Intrinsic.h>
46 /*=================================================================
47 $SHAREDBEG$: This header appears in all appropriate DtXlate topics
48 =======================================================$SKIP$======*/
50 #include "HelpXlate.h"
54 static char MyPlatform[_DtPLATFORM_MAX_LEN+1];
55 static _DtXlateDb MyDb = NULL;
59 static const char *DfltStdCharset = "ISO-8859-1";
60 static const char *DfltStdLang = "C";
62 /*========================================================*/
63 /*================== Private routines ====================*/
64 /*========================================================*/
65 /******************************************************************************
66 * Function: static int OpenLcxDb ()
75 * Purpose: Opens the Ce-private Lcx database
77 *****************************************************************************/
83 static short MyProcess = False;
84 static short MyFirst = True;
87 * wait 30 sec. until another thread or enter is done modifying the table
89 while (MyProcess == True)
91 /* if time out, return */
92 if (time(&time2) == (time_t)-1)
97 else if (time2 - time1 >= (time_t)30)
101 _DtHelpProcessLock();
105 if (_DtLcxOpenAllDbs(&MyDb) == 0 &&
106 _DtXlateGetXlateEnv(MyDb,MyPlatform,&ExecVer,&CompVer) != 0)
108 _DtLcxCloseDb(&MyDb);
114 _DtHelpProcessUnlock();
116 return (MyDb == NULL ? -1 : 0 );
119 /******************************************************************************
120 * Function: int _DtHelpCeXlateStdToOpLocale ( char *operation, char *stdLoc
122 * char *dflt_opLocale, char **ret_opLocale
126 * operation operation whose locale value will be retrieved
127 * stdLocale standard locale value
128 * dflt_opLocale operation-specific locale-value
129 * This is the default value used in error case
130 * ret_opLocale operation-specific locale-value placed here
131 * Caller must free this string.
135 * Purpose: Gets an operation-specific locale string given the standard string
137 *****************************************************************************/
139 _DtHelpCeXlateStdToOpLocale (
145 int result = OpenLcxDb();
147 _DtHelpProcessLock();
150 (void) _DtLcxXlateStdToOp(MyDb, MyPlatform, CompVer,
151 operation, stdLocale, NULL, NULL, NULL, ret_opLocale);
153 _DtHelpProcessUnlock();
155 /* if translation fails, use a default value */
156 if (ret_opLocale && (result != 0 || *ret_opLocale == NULL))
158 if (dflt_opLocale) *ret_opLocale = strdup(dflt_opLocale);
159 else if (stdLocale) *ret_opLocale = strdup(stdLocale);
164 /******************************************************************************
165 * Function: int _DtHelpCeXlateOpToStdLocale (char *operation, char *opLocale
167 * char **ret_stdLocale, char **ret_stdLang, char **ret_
171 * operation Operation associated with the locale value
172 * opLocale An operation-specific locale string
173 * ret_locale Returns the std locale
174 * Caller must free this string.
175 * ret_stdLang Returns the std language & territory string.
176 * Caller must free this string.
177 * ret_stdSet Returns the std code set string.
178 * Caller must free this string.
182 * Purpose: Gets the standard locale given an operation and its locale
184 *****************************************************************************/
186 _DtHelpCeXlateOpToStdLocale (
189 char **ret_stdLocale,
193 int result = OpenLcxDb();
195 _DtHelpProcessLock();
198 (void) _DtLcxXlateOpToStd(MyDb, MyPlatform, CompVer,
200 ret_stdLocale, ret_stdLang, ret_stdSet, NULL);
202 _DtHelpProcessUnlock();
204 /* if failed, give default values */
205 if (ret_stdLocale != NULL && (result != 0 || *ret_stdLocale == NULL))
207 *ret_stdLocale = malloc(
208 strlen(DfltStdLang)+strlen(DfltStdCharset)+3);
209 sprintf(*ret_stdLocale,"%s.%s",DfltStdLang,DfltStdCharset);
211 if (ret_stdLang != NULL && (result != 0 || *ret_stdLang == NULL))
212 *ret_stdLang = strdup(DfltStdLang);
213 if (ret_stdSet != NULL && (result != 0 || *ret_stdSet == NULL))
214 *ret_stdSet = strdup(DfltStdCharset);
217 /******************************************************************************
218 * Function: int _DtHelpCeGetMbLen (char *lang, char *char_set)
221 * lang Represents the language. A NULL value
223 * char_set Represents the character set. A NULL
224 * value value defaults to "ISO-8859-1"
226 * Return Value: Returns the MB_CUR_MAX for the combination
231 * Purpose: To determine the maximum number of bytes required to display
232 * a character if/when the environment is set to 'lang.charset'
234 *****************************************************************************/
243 lang = (char *)DfltStdLang;
245 if (char_set == NULL)
246 char_set = (char *)DfltStdCharset;
248 _DtHelpProcessLock();
249 if (OpenLcxDb() == 0)
251 /* if translation is present, lang.charset are a multibyte locale */
252 if (_DtLcxXlateStdToOp(MyDb, MyPlatform, CompVer, DtLCX_OPER_MULTIBYTE,
253 NULL, lang, char_set, NULL, NULL) == 0)
256 _DtHelpProcessUnlock();