1 /* $XConsortium: HelpXlate.c /main/1 1996/08/22 09:16:03 rswiston $ */
2 /****************************************************************************
5 $COMPONENT$: DtXlate service
6 $1LINER$: Implements a translation service using tables and regex search
8 (c) Copyright 1993, 1994 Hewlett-Packard Company
9 (c) Copyright 1993, 1994 International Business Machines Corp.
10 (c) Copyright 1993, 1994 Sun Microsystems, Inc.
11 (c) Copyright 1993, 1994 Unix System Labs, Inc., a subsidiary of Novell, Inc.
13 ****************************************************************************
14 ************************************<+>*************************************/
19 #include <sys/param.h> /* MAXPATHLEN */
22 #include <X11/Intrinsic.h>
24 /*=================================================================
25 $SHAREDBEG$: This header appears in all appropriate DtXlate topics
26 =======================================================$SKIP$======*/
28 #include "HelpXlate.h"
32 static char MyPlatform[_DtPLATFORM_MAX_LEN+1];
33 static _DtXlateDb MyDb = NULL;
37 static const char *DfltStdCharset = "ISO-8859-1";
38 static const char *DfltStdLang = "C";
40 /*========================================================*/
41 /*================== Private routines ====================*/
42 /*========================================================*/
43 /******************************************************************************
44 * Function: static int OpenLcxDb ()
53 * Purpose: Opens the Ce-private Lcx database
55 *****************************************************************************/
61 static short MyProcess = False;
62 static short MyFirst = True;
65 * wait 30 sec. until another thread or enter is done modifying the table
67 while (MyProcess == True)
69 /* if time out, return */
70 if (time(&time2) == (time_t)-1)
75 else if (time2 - time1 >= (time_t)30)
83 if (_DtLcxOpenAllDbs(&MyDb) == 0 &&
84 _DtXlateGetXlateEnv(MyDb,MyPlatform,&ExecVer,&CompVer) != 0)
92 _DtHelpProcessUnlock();
94 return (MyDb == NULL ? -1 : 0 );
97 /******************************************************************************
98 * Function: int _DtHelpCeXlateStdToOpLocale ( char *operation, char *stdLoc
100 * char *dflt_opLocale, char **ret_opLocale
104 * operation operation whose locale value will be retrieved
105 * stdLocale standard locale value
106 * dflt_opLocale operation-specific locale-value
107 * This is the default value used in error case
108 * ret_opLocale operation-specific locale-value placed here
109 * Caller must free this string.
113 * Purpose: Gets an operation-specific locale string given the standard string
115 *****************************************************************************/
117 _DtHelpCeXlateStdToOpLocale (
123 int result = OpenLcxDb();
125 _DtHelpProcessLock();
128 (void) _DtLcxXlateStdToOp(MyDb, MyPlatform, CompVer,
129 operation, stdLocale, NULL, NULL, NULL, ret_opLocale);
131 _DtHelpProcessUnlock();
133 /* if translation fails, use a default value */
134 if (ret_opLocale && (result != 0 || *ret_opLocale == NULL))
136 if (dflt_opLocale) *ret_opLocale = strdup(dflt_opLocale);
137 else if (stdLocale) *ret_opLocale = strdup(stdLocale);
142 /******************************************************************************
143 * Function: int _DtHelpCeXlateOpToStdLocale (char *operation, char *opLocale
145 * char **ret_stdLocale, char **ret_stdLang, char **ret_
149 * operation Operation associated with the locale value
150 * opLocale An operation-specific locale string
151 * ret_locale Returns the std locale
152 * Caller must free this string.
153 * ret_stdLang Returns the std language & territory string.
154 * Caller must free this string.
155 * ret_stdSet Returns the std code set string.
156 * Caller must free this string.
160 * Purpose: Gets the standard locale given an operation and its locale
162 *****************************************************************************/
164 _DtHelpCeXlateOpToStdLocale (
167 char **ret_stdLocale,
171 int result = OpenLcxDb();
173 _DtHelpProcessLock();
176 (void) _DtLcxXlateOpToStd(MyDb, MyPlatform, CompVer,
178 ret_stdLocale, ret_stdLang, ret_stdSet, NULL);
180 _DtHelpProcessUnlock();
182 /* if failed, give default values */
183 if (ret_stdLocale != NULL && (result != 0 || *ret_stdLocale == NULL))
185 *ret_stdLocale = malloc(
186 strlen(DfltStdLang)+strlen(DfltStdCharset)+3);
187 sprintf(*ret_stdLocale,"%s.%s",DfltStdLang,DfltStdCharset);
189 if (ret_stdLang != NULL && (result != 0 || *ret_stdLang == NULL))
190 *ret_stdLang = strdup(DfltStdLang);
191 if (ret_stdSet != NULL && (result != 0 || *ret_stdSet == NULL))
192 *ret_stdSet = strdup(DfltStdCharset);
195 /******************************************************************************
196 * Function: int _DtHelpCeGetMbLen (char *lang, char *char_set)
199 * lang Represents the language. A NULL value
201 * char_set Represents the character set. A NULL
202 * value value defaults to "ISO-8859-1"
204 * Return Value: Returns the MB_CUR_MAX for the combination
209 * Purpose: To determine the maximum number of bytes required to display
210 * a character if/when the environment is set to 'lang.charset'
212 *****************************************************************************/
221 lang = (char *)DfltStdLang;
223 if (char_set == NULL)
224 char_set = (char *)DfltStdCharset;
226 _DtHelpProcessLock();
227 if (OpenLcxDb() == 0)
229 /* if translation is present, lang.charset are a multibyte locale */
230 if (_DtLcxXlateStdToOp(MyDb, MyPlatform, CompVer, DtLCX_OPER_MULTIBYTE,
231 NULL, lang, char_set, NULL, NULL) == 0)
234 _DtHelpProcessUnlock();