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 /* $TOG: userinit.c /main/6 1998/04/20 12:55:18 mgreess $ */
26 #include "variables.h"
27 #include <Dt/DtNlUtils.h>
28 #include <Dt/EnvControlP.h>
32 #include <X11/Intrinsic.h>
33 #include <X11/IntrinsicP.h>
34 #include <X11/CoreP.h>
35 #include <X11/StringDefs.h>
36 #include <Xm/XmStrDefs.h>
41 #include <Xm/Protocols.h>
52 #include "xmwidgets.h"
58 * LocaleChanged is defined in ksh93/src/cmd/ksh93/sh/init.c
61 extern void LocaleChanged (
68 static Namdisc_t localeDisc = { 0, LocaleChanged, NULL, NULL, NULL, NULL, NULL, NULL };
69 static Namfun_t localeFun = {NULL, NULL };
71 extern char *savedNlsPath; /* in ./ksh93/src/cmd/ksh93/sh/init.c */
81 if(value != (char *)NULL)
83 buf = malloc(strlen(name) + strlen(value) + 2);
88 free(buf); /* I hope it's legal to free this! */
93 * This is a hook for an additional initialization routine
94 * A function of this name is called in main after sh_init().
103 lockedFds = LockKshFileDescriptors();
104 (void) XtSetLanguageProc((XtAppContext)NULL, (XtLanguageProc)NULL,
106 setlocale(LC_ALL, "");
108 _DtEnvControl(DT_ENV_SET);
109 localeFun.disc = &localeDisc;
110 nv_stack(LANGNOD, &localeFun);
111 UnlockKshFileDescriptors(lockedFds);
114 * Save the current setting of NLSPATH. The user/script may want to
115 * set its own NLSPATH to access its message catalog, so we need to
116 * remember where to find our own catalog(s). This saved path is used
117 * in ksh93/src/cmd/ksh93/sh/init.c: _DtGetMessage(). We don't mess
118 * with the user/script's setting of LANG as we want to track changes
121 savedNlsPath = strdup(getenv("NLSPATH"));
124 * Sync the libc environment (set up by DtEnvControl) with our internal
125 * hash table environment.
132 * The following routines are used to query a CDE database to determine
133 * if the current character encoding requires special care in the ksh
134 * parser. They are used in updateShSpecialParse(). These are copied
135 * from the DtHelp code.
137 #include <XlationSvc.h>
138 #include <LocaleXlate.h>
140 static const char *DfltStdCharset = "ISO-8859-1";
141 static const char *DfltStdLang = "C";
143 static char MyPlatform[_DtPLATFORM_MAX_LEN+1];
146 /******************************************************************************
147 * Function: static _DtXlateDb OpenLcxDb ()
151 * Return Value: NULL: error, else a _DtXlateDb
155 * Purpose: Opens the Ce-private Lcx database
157 *****************************************************************************/
161 static _DtXlateDb MyDb;
162 static Boolean MyFirst = True;
163 static Boolean MyProcess = False;
169 * wait up to 30 sec. until another thread or enter is done
170 * modifying the table.
172 while (MyProcess == True)
174 /* if time out, return */
175 if (time(&time2) == (time_t)-1)
176 return (_DtXlateDb)NULL;
180 else if (time2 - time1 >= (time_t)30)
181 return (_DtXlateDb)NULL;
187 if (_DtLcxOpenAllDbs(&MyDb) == 0 &&
188 _DtXlateGetXlateEnv(MyDb,MyPlatform,&ExecVer,&CompVer) != 0)
190 _DtLcxCloseDb(&MyDb);
200 /******************************************************************************
201 * Function: static void XlateOpToStdLocale(char *operation, char *opLocale,
202 * char **ret_stdLocale,
203 * char **ret_stdLang,
207 * operation Operation associated with the locale value
208 * opLocale An operation-specific locale string
209 * ret_locale Returns the std locale
210 * Caller must free this string.
211 * ret_stdLang Returns the std language & territory string.
212 * Caller must free this string.
213 * ret_stdSet Returns the std code set string.
214 * Caller must free this string.
218 * Purpose: Gets the standard locale given an operation and its locale
220 *****************************************************************************/
225 char **ret_stdLocale,
235 (void) _DtLcxXlateOpToStd(MyDb, MyPlatform, CompVer,
237 ret_stdLocale, ret_stdLang, ret_stdSet, NULL);
240 /* if failed, give default values */
241 if (ret_stdLocale != NULL && *ret_stdLocale == NULL)
243 *ret_stdLocale = malloc(strlen(DfltStdLang)+strlen(DfltStdCharset)+3);
244 sprintf(*ret_stdLocale,"%s.%s",DfltStdLang,DfltStdCharset);
246 if (ret_stdLang != NULL && *ret_stdLang == NULL)
247 *ret_stdLang = strdup(DfltStdLang);
248 if (ret_stdSet != NULL && *ret_stdSet == NULL)
249 *ret_stdSet = strdup(DfltStdCharset);
253 /******************************************************************************
254 * Function: static void XlateStdToOpLocale(char *operation,
255 * char *stdLocale, char *dflt_opLocale,
256 * char **ret_opLocale)
259 * operation operation whose locale value will be retrieved
260 * stdLocale standard locale value
261 * dflt_opLocale operation-specific locale-value
262 * This is the default value used in error case
263 * ret_opLocale operation-specific locale-value placed here
264 * Caller must free this string.
268 * Purpose: Gets an operation-specific locale string given the standard string
270 *****************************************************************************/
283 (void) _DtLcxXlateStdToOp(MyDb, MyPlatform, CompVer,
284 operation, stdLocale, NULL, NULL, NULL, ret_opLocale);
287 extern int shSpecialParse; /* in ksh93/src/cmd/ksh93/sh/lex.c */
290 * updateShellSpecialParse uses the libXvh database to determine if the
291 * current character encoding requires special care in the ksh parser.
292 * It sets or clears a global flag (shSpecialParse) based on the value
293 * from the database. This flag is declared and inspected in sh_lex() in
294 * ksh93/src/cmd/ksh93/sh/lex.c. This routine is stubbed in the
295 * file .../sh/userinit.c to allow ksh93 to compile & run, albeit
296 * without any knowledge of when to do special parsing.
300 updateShSpecialParse( void )
302 char *locale = (char *)NULL, *parseVal = (char *)NULL;
305 lockedFds = LockKshFileDescriptors();
307 XlateOpToStdLocale(DtLCX_OPER_SETLOCALE, setlocale(LC_CTYPE,NULL),
308 &locale, NULL, NULL);
309 XlateStdToOpLocale("dtkshSpecialParse", locale, NULL, &parseVal);
312 UnlockKshFileDescriptors(lockedFds);
314 if(parseVal != (char *)NULL)