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 libraries 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: Helpos.c /main/13 1998/07/30 12:08:32 mgreess $ */
24 /************************************<+>*************************************
25 ****************************************************************************
29 ** Project: Rivers Project
31 ** Description: All system/os dependent calls are placed in here.
34 ** WARNING: Do NOT put any Xt or Xm dependencies in this code.
36 ** (c) Copyright 1987, 1988, 1989, 1990, 1991, 1992 Hewlett-Packard Company
38 ** (c) Copyright 1993, 1994 Hewlett-Packard Company
39 ** (c) Copyright 1993, 1994 International Business Machines Corp.
40 ** (c) Copyright 1993, 1994 Sun Microsystems, Inc.
41 ** (c) Copyright 1993, 1994 Novell, Inc.
42 ****************************************************************************
43 ************************************<+>*************************************/
46 #include <sys/param.h>
50 #define X_INCLUDE_PWD_H
51 #define XOS_USE_XT_LOCKING
52 #include <X11/Xos_r.h>
54 #ifndef _SUN_OS /* don't need the nl_types.h file */
55 # include <nl_types.h>
56 #endif /* ! _SUN_OS */
58 #include <X11/Intrinsic.h>
59 #include <X11/Shell.h>
64 #include <Dt/DtNlUtils.h>
72 static const int NL_CAT_LOCALE = 0;
77 /* Global Message Catalog file names */
78 static char *CatFileName=NULL;
82 /*****************************************************************************
83 * Function: Boolean _DtHelpOSGetHomeDirName(
86 * Parameters: Output string, size of output string
88 * Return Value: String.
93 *****************************************************************************/
94 void _DtHelpOSGetHomeDirName(
98 /* outptr is allocated outside this function, just filled here. */
99 /* this solution leads to less change in the current (mwm) code */
102 static char *ptr = NULL;
103 _Xgetpwparams pwd_buf;
104 struct passwd * pwd_ret;
106 _DtHelpProcessLock();
108 if((ptr = (char *)getenv("HOME")) == NULL) {
109 if((ptr = (char *)getenv("USER")) != NULL)
110 pwd_ret = _XGetpwnam(ptr, pwd_buf);
113 pwd_ret = _XGetpwuid(uid, pwd_buf);
116 ptr = pwd_ret->pw_dir;
123 strncpy(outptr, ptr, len);
124 outptr[len-1] = '\0'; /* Make sure it is Null terminated */
128 _DtHelpProcessUnlock();
136 /*****************************************************************************
137 * Function: _DtHelpGetUserSearchPath(
142 * Return Value: String, owned by caller.
146 * Gets the user search path for use
147 * when searching for a volume.
148 * Takes path from the environment,
149 * or uses the default path.
151 *****************************************************************************/
152 String _DtHelpGetUserSearchPath(void)
155 char homedir[MAXPATHLEN];
157 extern char * _DtCliSrvGetDtUserSession(); /* in libCliSrv */
159 localPath = (char *)getenv (DtUSER_FILE_SEARCH_ENV);
160 if (localPath == NULL)
164 /* Use our default path */
165 _DtHelpOSGetHomeDirName(homedir, sizeof(homedir));
166 session = _DtCliSrvGetDtUserSession();
168 path = calloc(1, 3*strlen(session) + 6*strlen(homedir) +
169 strlen(DtDEFAULT_USER_PATH_FORMAT));
170 sprintf(path, DtDEFAULT_USER_PATH_FORMAT,
171 homedir, session, homedir, session, homedir, session,
172 homedir, homedir, homedir);
174 /* homedir is a local array */
176 /* Return our expanded default path */
181 /* Make a local copy for us */
182 localPath = strdup(localPath);
184 /* Just Use our local path */
192 /*****************************************************************************
193 * Function: _DtHelpGetSystemSearchPath(
198 * Return Value: String, owned by caller.
202 * Gets the system search path for use
203 * when searching for a volume.
204 * Takes path from the environment,
205 * or uses the default path.
207 *****************************************************************************/
208 String _DtHelpGetSystemSearchPath(void)
212 /* try to retrieve env var value */
213 path = getenv(DtSYS_FILE_SEARCH_ENV);
215 /* if fail, use default */
217 path = DtDEFAULT_SYSTEM_PATH;
225 /*****************************************************************************
226 * Function: void DtHelpSetCatalogName(char *catFile);
229 * Parameters: catFile Specifies the name of the message catalog file
235 * Description: This function will set the name of the message catalog file
236 * within the Dt help system environment.
238 * The new name must be of the format <name>.cat and the file
239 * must be installed such that the NLS search path can find it.
241 * If this function is not called then the default value of
242 * Dt.cat will be used.
245 *****************************************************************************/
246 void DtHelpSetCatalogName(
251 _DtHelpProcessLock();
252 /* Setup our Message Catalog file names */
255 /* Setup the short and long versions */
257 CatFileName = strdup("DtHelp.cat");
259 CatFileName = strdup("DtHelp");
266 /* If we have a full path, just use it */
268 CatFileName = strdup(catFile);
271 /* We don't have a full path, and the ultirx os needs the
272 * ".cat" extention so let's make sure its there.
274 if (strcmp(&catFile[strlen(catFile) -4], ".cat") == 0)
275 CatFileName = strdup(catFile);
278 /* Create our CatFileName with the extention */
279 CatFileName = malloc (strlen(catFile) + 5);
280 /* +5, 1 for NULL, 4 for ".cat" */
281 strcpy(CatFileName, catFile);
282 strcat(CatFileName, ".cat");
289 /* If we have a full path, just use it */
291 CatFileName = strdup(catFile);
294 /* hp-ux os does not work with the ".cat" extention, so
295 * if one exists, remove it.
298 if (strcmp(&catFile[strlen(catFile) -4], ".cat") != 0)
299 CatFileName = strdup(catFile);
302 /* Create our CatFileName with out the extention */
303 len = strlen(catFile) -4;
304 CatFileName = malloc(len +1);
305 strncpy (CatFileName, catFile, len);
306 CatFileName[len]= '\0';
311 _DtHelpProcessUnlock();
316 #ifndef NO_MESSAGE_CATALOG
317 /*****************************************************************************
318 * Function: Boolean _DtHelpGetMessage(
323 * Return Value: char *
326 * Description: This function will retreive the requested message from the
327 * cache proper cache creek message catalog file.
329 *****************************************************************************/
330 char *_DtHelpGetMessage(
339 static int first = 1;
340 static nl_catd nlmsg_fd;
342 _DtHelpProcessLock();
346 /* Setup our default message catalog names if none have been set! */
347 if (CatFileName == NULL)
349 /* Setup the short and long versions */
351 CatFileName = strdup("DtHelp.cat");
353 CatFileName = strdup("DtHelp");
357 loc = _DtHelpGetLocale();
358 if (!loc || !(strcmp (loc, "C")))
360 * If LANG is not set or if LANG=C, then there
361 * is no need to open the message catalog - just
362 * return the built-in string "s".
364 nlmsg_fd = (nl_catd) -1;
366 nlmsg_fd = catopen(CatFileName, NL_CAT_LOCALE);
371 msg=catgets(nlmsg_fd,set,n,s);
372 _DtHelpProcessUnlock();
379 /*****************************************************************************
380 * Function: char * _DtHelpGetLocale(
385 * Return Value: char *
388 * Description: Returns the value of LC_MESSAGES from the environ.
389 * If that is NULL, returns the value of LANG form the environ.
390 * If that is NULL, returns NULL.
392 *****************************************************************************/
393 char *_DtHelpGetLocale(void)
397 loc = setlocale(LC_MESSAGES, NULL);
398 if (NULL == loc || '\0' == loc[0]) loc = getenv("LANG");
399 if (NULL == loc || '\0' == loc[0]) return NULL;
401 loc = strdup(loc); /* getenv() returns ptr to private memory */