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 ************************************<+>*************************************/
45 #include <sys/param.h>
50 #if defined(HAVE_CONFIG_H)
51 # include <autotools_config.h>
53 #if defined(HAVE_LOCALE_H)
57 #define X_INCLUDE_PWD_H
58 #define XOS_USE_XT_LOCKING
59 #include <X11/Xos_r.h>
61 #ifndef _SUN_OS /* don't need the nl_types.h file */
62 # include <nl_types.h>
63 #endif /* ! _SUN_OS */
65 #include <X11/Intrinsic.h>
66 #include <X11/Shell.h>
71 #include <Dt/DtNlUtils.h>
79 static const int NL_CAT_LOCALE = 0;
84 /* Global Message Catalog file names */
85 static char *CatFileName=NULL;
89 /*****************************************************************************
90 * Function: Boolean _DtHelpOSGetHomeDirName(
93 * Parameters: Output string, size of output string
95 * Return Value: String.
100 *****************************************************************************/
101 void _DtHelpOSGetHomeDirName(
105 /* outptr is allocated outside this function, just filled here. */
106 /* this solution leads to less change in the current (mwm) code */
109 static char *ptr = NULL;
110 _Xgetpwparams pwd_buf;
111 struct passwd * pwd_ret;
113 _DtHelpProcessLock();
115 if((ptr = (char *)getenv("HOME")) == NULL) {
116 if((ptr = (char *)getenv("USER")) != NULL)
117 pwd_ret = _XGetpwnam(ptr, pwd_buf);
120 pwd_ret = _XGetpwuid(uid, pwd_buf);
123 ptr = pwd_ret->pw_dir;
130 strncpy(outptr, ptr, len);
131 outptr[len-1] = '\0'; /* Make sure it is Null terminated */
135 _DtHelpProcessUnlock();
143 /*****************************************************************************
144 * Function: _DtHelpGetUserSearchPath(
149 * Return Value: String, owned by caller.
153 * Gets the user search path for use
154 * when searching for a volume.
155 * Takes path from the environment,
156 * or uses the default path.
158 *****************************************************************************/
159 String _DtHelpGetUserSearchPath(void)
162 char homedir[MAXPATHLEN];
164 extern char * _DtCliSrvGetDtUserSession(); /* in libCliSrv */
166 localPath = (char *)getenv (DtUSER_FILE_SEARCH_ENV);
167 if (localPath == NULL)
171 /* Use our default path */
172 _DtHelpOSGetHomeDirName(homedir, sizeof(homedir));
173 session = _DtCliSrvGetDtUserSession();
175 path = calloc(1, 3*strlen(session) + 6*strlen(homedir) +
176 strlen(DtDEFAULT_USER_PATH_FORMAT));
177 sprintf(path, DtDEFAULT_USER_PATH_FORMAT,
178 homedir, session, homedir, session, homedir, session,
179 homedir, homedir, homedir);
181 /* homedir is a local array */
183 /* Return our expanded default path */
188 /* Make a local copy for us */
189 localPath = strdup(localPath);
191 /* Just Use our local path */
199 /*****************************************************************************
200 * Function: _DtHelpGetSystemSearchPath(
205 * Return Value: String, owned by caller.
209 * Gets the system search path for use
210 * when searching for a volume.
211 * Takes path from the environment,
212 * or uses the default path.
214 *****************************************************************************/
215 String _DtHelpGetSystemSearchPath(void)
219 /* try to retrieve env var value */
220 path = getenv(DtSYS_FILE_SEARCH_ENV);
222 /* if fail, use default */
224 path = DtDEFAULT_SYSTEM_PATH;
232 /*****************************************************************************
233 * Function: void DtHelpSetCatalogName(char *catFile);
236 * Parameters: catFile Specifies the name of the message catalog file
242 * Description: This function will set the name of the message catalog file
243 * within the Dt help system environment.
245 * The new name must be of the format <name>.cat and the file
246 * must be installed such that the NLS search path can find it.
248 * If this function is not called then the default value of
249 * Dt.cat will be used.
252 *****************************************************************************/
253 void DtHelpSetCatalogName(
258 _DtHelpProcessLock();
259 /* Setup our Message Catalog file names */
262 /* Setup the short and long versions */
263 CatFileName = strdup("DtHelp");
268 /* If we have a full path, just use it */
270 CatFileName = strdup(catFile);
273 /* hp-ux os does not work with the ".cat" extention, so
274 * if one exists, remove it.
277 if (strcmp(&catFile[strlen(catFile) -4], ".cat") != 0)
278 CatFileName = strdup(catFile);
281 /* Create our CatFileName with out the extention */
282 len = strlen(catFile) -4;
283 CatFileName = malloc(len +1);
284 strncpy (CatFileName, catFile, len);
285 CatFileName[len]= '\0';
289 _DtHelpProcessUnlock();
294 #ifndef NO_MESSAGE_CATALOG
295 /*****************************************************************************
296 * Function: Boolean _DtHelpGetMessage(
301 * Return Value: char *
304 * Description: This function will retreive the requested message from the
305 * cache proper cache creek message catalog file.
307 *****************************************************************************/
308 char *_DtHelpGetMessage(
317 static int first = 1;
318 static nl_catd nlmsg_fd;
320 _DtHelpProcessLock();
324 /* Setup our default message catalog names if none have been set! */
325 if (CatFileName == NULL)
327 /* Setup the short and long versions */
328 CatFileName = strdup("DtHelp");
331 loc = _DtHelpGetLocale();
332 if (!loc || !(strcmp (loc, "C")))
334 * If LANG is not set or if LANG=C, then there
335 * is no need to open the message catalog - just
336 * return the built-in string "s".
338 nlmsg_fd = (nl_catd) -1;
340 nlmsg_fd = catopen(CatFileName, NL_CAT_LOCALE);
345 msg=catgets(nlmsg_fd,set,n,s);
346 _DtHelpProcessUnlock();
353 /*****************************************************************************
354 * Function: char * _DtHelpGetLocale(
359 * Return Value: char *
362 * Description: Returns the value of LC_MESSAGES from the environ.
363 * If that is NULL, returns the value of LANG form the environ.
364 * If that is NULL, returns NULL.
366 *****************************************************************************/
367 char *_DtHelpGetLocale(void)
371 loc = setlocale(LC_MESSAGES, NULL);
372 if (NULL == loc || '\0' == loc[0]) loc = getenv("LANG");
373 if (NULL == loc || '\0' == loc[0]) return NULL;
375 loc = strdup(loc); /* getenv() returns ptr to private memory */