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 /* (c) Copyright 1997 The Open Group */
25 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
26 * (c) Copyright 1993, 1994 International Business Machines Corp. *
27 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
28 * (c) Copyright 1993, 1994 Novell, Inc. *
31 * xdm - display manager daemon
33 * $TOG: util.c /main/15 1998/04/06 13:22:20 mgreess $
35 * Copyright 1988 Massachusetts Institute of Technology
37 * Permission to use, copy, modify, and distribute this software and its
38 * documentation for any purpose and without fee is hereby granted, provided
39 * that the above copyright notice appear in all copies and that both that
40 * copyright notice and this permission notice appear in supporting
41 * documentation, and that the name of M.I.T. not be used in advertising or
42 * publicity pertaining to distribution of the software without specific,
43 * written prior permission. M.I.T. makes no representations about the
44 * suitability of this software for any purpose. It is provided "as is"
45 * without express or implied warranty.
47 * Author: Keith Packard, MIT X Consortium
53 * various utility routines
63 # include <sys/signal.h>
72 nl_catd nl_fd = (nl_catd)-1; /* message catalog file descriptor */
74 #if !defined(NL_CAT_LOCALE)
75 #define NL_CAT_LOCALE 0
78 #if !defined (ENABLE_DYNAMIC_LANGLIST)
79 #define LANGLISTSIZE 2048
80 char languageList[LANGLISTSIZE]; /* global list of languages */
81 #endif /* ENABLE_DYNAMIC_LANGLIST */
83 /***************************************************************************
85 * Local procedure declarations
87 ***************************************************************************/
89 static char * makeEnv(
93 static SIGVAL MakeLangAbort(
96 static int MatchesFileSuffix(
100 static void ScanNLSDir(
103 /******** End Local Function Declarations ********/
106 /***************************************************************************
110 * read a string from the message catalog
111 ***************************************************************************/
114 ReadCatalog( int set_num, int msg_num, char *def_str )
116 static Bool alreadyopen = False;
119 if (alreadyopen == False)
121 char *curNlsPath, *newNlsPath;
127 * Desktop message catalogs are in DT directory, so append desktop
128 * search paths to current NLSPATH.
130 #define NLS_PATH_STRING CDE_INSTALLATION_TOP "/nls/msg/%L/%N.cat:" \
131 CDE_INSTALLATION_TOP "/lib/nls/msg/%L/%N.cat:" \
132 CDE_INSTALLATION_TOP "/lib/nls/msg/%l/%t/%c/%N.cat:" \
133 CDE_INSTALLATION_TOP "/lib/nls/msg/%l/%c/%N.cat"
135 curNlsPath = getenv("NLSPATH");
136 if (curNlsPath && strlen(curNlsPath) == 0)
144 * <length of NLS_PATH_STRING>
147 newNlsPathLen = 7 + 1 + strlen(NLS_PATH_STRING) + 1;
149 if (curNlsPath != NULL)
153 * <length of curNlsPath>
155 newNlsPathLen += (1 + strlen(curNlsPath));
158 newNlsPath = malloc(newNlsPathLen); /* placed in environ, do not free */
160 if (curNlsPath != NULL)
162 sprintf(newNlsPath, "NLSPATH=%s:%s", curNlsPath, NLS_PATH_STRING);
166 sprintf(newNlsPath, "NLSPATH=%s", NLS_PATH_STRING);
170 * Store new NLSPATH in environment. Note this memory cannot be freed
175 * Open message catalog. Note, if invalid descriptor returned (ie
176 * msg catalog could not be opened), subsequent call to catgets() using
177 * that descriptor will return 'def_str'.
179 nl_fd = catopen("dtlogin", NL_CAT_LOCALE);
182 s = catgets(nl_fd,set_num,msg_num,def_str);
184 return((unsigned char *)s);
191 Debug (" %s\n", *e++);
195 makeEnv( char *name, char *value )
199 result = malloc ((unsigned) (strlen (name) + strlen (value) + 2));
202 ReadCatalog(MC_LOG_SET,MC_LOG_MAKEENV,MC_DEF_LOG_MAKEENV));
206 if (value && *value) {
207 sprintf (result, "%s=%s", name, value);
210 sprintf (result, "%s", name);
217 getEnv( char **e, char *name )
219 int l = strlen (name);
222 if ((int) strlen (*e) > l &&
223 !strncmp (*e, name, l) &&
233 setEnv( char **e, char *name, char *value )
241 newe = makeEnv (name, value);
243 LogOutOfMem(ReadCatalog(MC_LOG_SET,MC_LOG_SETENV,MC_DEF_LOG_SETENV));
247 for (old = e; *old; old++)
248 if ((int) strlen (*old) > l &&
249 !strncmp (*old, name, l) &&
260 realloc((char *) e, (unsigned) ((envsize + 2) * sizeof (char *)));
263 new = (char **) malloc (2 * sizeof (char *));
266 LogOutOfMem(ReadCatalog(MC_LOG_SET,MC_LOG_SETENV,MC_DEF_LOG_SETENV));
282 for (e = env; *e; e++)
288 # define isblank(c) ((c) == ' ' || c == '\t')
291 parseArgs( char **argv, char *string )
298 while (argv && argv[i])
301 argv = (char **) malloc (sizeof (char *));
303 LogOutOfMem(ReadCatalog(
304 MC_LOG_SET,MC_LOG_PARSEARGS,MC_DEF_LOG_PARSEARGS));
310 if (!*string || isblank (*string)) {
311 if (word != string) {
312 argv = (char **) realloc ((char *) argv,
313 (unsigned) ((i + 2) * sizeof (char *)));
314 save = malloc ((unsigned) (string - word + 1));
315 if (!argv || !save) {
316 LogOutOfMem(ReadCatalog(MC_LOG_SET,
318 MC_DEF_LOG_PARSEARGS));
320 free ((char *) argv);
325 argv[i] = strncpy (save, word, string-word);
326 argv[i][string-word] = '\0';
343 * On i386/i486 platforms setprrp() functions causes the mouse not
344 * to work. Since in the daemon mode the parent daemon has already
345 * executed a setpgrp it is a process and session leader. Since it
346 * has also gotten rid of the controlling terminal there is no great
347 * harm in not making the sub-daemons as leaders.
353 #if defined (SYSV) || defined (SVR4) || defined(linux)
354 #if !defined (USL) && !defined(__uxp__)
358 setpgrp (0, getpid ());
363 (void) signal (SIGCHLD, SIG_DFL);
365 (void) signal (SIGTERM, SIG_DFL);
366 (void) signal (SIGPIPE, SIG_DFL);
367 (void) signal (SIGALRM, SIG_DFL);
368 (void) signal (SIGHUP, SIG_DFL);
373 parseEnv( char **e, char *string )
376 char *s1, *s2, *t1, *t2;
378 s1 = s2 = strdup(string);
380 while ((t1 = strtok(s1," \t")) != NULL ) {
381 if ( (t2 = strchr(t1,'=')) != NULL ) {
383 e = setEnv(e, t1, t2);
396 /*************************************<->*************************************
398 * Cursor GetHourGlass ()
403 * Builds and returns the appropriate Hourglass cursor
416 * None. (None doesn't count as a comment)
418 *************************************<->***********************************/
420 #define time32_width 32
421 #define time32_height 32
422 #define time32_x_hot 15
423 #define time32_y_hot 15
424 static unsigned char time32_bits[] = {
425 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, 0x7f, 0xfe, 0xff, 0xff, 0x7f,
426 0x8c, 0x00, 0x00, 0x31, 0x4c, 0x00, 0x00, 0x32, 0x4c, 0x00, 0x00, 0x32,
427 0x4c, 0x00, 0x00, 0x32, 0x4c, 0x00, 0x00, 0x32, 0x4c, 0x00, 0x00, 0x32,
428 0x8c, 0x00, 0x00, 0x31, 0x0c, 0x7f, 0xfe, 0x30, 0x0c, 0xfe, 0x7f, 0x30,
429 0x0c, 0xfc, 0x3f, 0x30, 0x0c, 0xf8, 0x1f, 0x30, 0x0c, 0xe0, 0x07, 0x30,
430 0x0c, 0x80, 0x01, 0x30, 0x0c, 0x80, 0x01, 0x30, 0x0c, 0x60, 0x06, 0x30,
431 0x0c, 0x18, 0x18, 0x30, 0x0c, 0x04, 0x20, 0x30, 0x0c, 0x02, 0x40, 0x30,
432 0x0c, 0x01, 0x80, 0x30, 0x8c, 0x00, 0x00, 0x31, 0x4c, 0x80, 0x01, 0x32,
433 0x4c, 0xc0, 0x03, 0x32, 0x4c, 0xf0, 0x1f, 0x32, 0x4c, 0xff, 0xff, 0x32,
434 0xcc, 0xff, 0xff, 0x33, 0x8c, 0xff, 0xff, 0x31, 0xfe, 0xff, 0xff, 0x7f,
435 0xfe, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00};
437 #define time32m_width 32
438 #define time32m_height 32
439 static unsigned char time32m_bits[] = {
440 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
441 0xcf, 0x00, 0x00, 0xf3, 0x6e, 0x00, 0x00, 0x76, 0x6e, 0x00, 0x00, 0x76,
442 0x6e, 0x00, 0x00, 0x76, 0x6e, 0x00, 0x00, 0x76, 0x6e, 0x00, 0x00, 0x76,
443 0xce, 0x00, 0x00, 0x73, 0x8e, 0x7f, 0xfe, 0x71, 0x0e, 0xff, 0xff, 0x70,
444 0x0e, 0xfe, 0x7f, 0x70, 0x0e, 0xfc, 0x3f, 0x70, 0x0e, 0xf8, 0x1f, 0x70,
445 0x0e, 0xe0, 0x07, 0x70, 0x0e, 0xe0, 0x07, 0x70, 0x0e, 0x78, 0x1e, 0x70,
446 0x0e, 0x1c, 0x38, 0x70, 0x0e, 0x06, 0x60, 0x70, 0x0e, 0x03, 0xc0, 0x70,
447 0x8e, 0x01, 0x80, 0x71, 0xce, 0x00, 0x00, 0x73, 0x6e, 0x80, 0x01, 0x76,
448 0x6e, 0xc0, 0x03, 0x76, 0x6e, 0xf0, 0x1f, 0x76, 0x6e, 0xff, 0xff, 0x76,
449 0xee, 0xff, 0xff, 0x77, 0xcf, 0xff, 0xff, 0xf3, 0xff, 0xff, 0xff, 0xff,
450 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
453 #define time16_x_hot 7
454 #define time16_y_hot 7
455 #define time16_width 16
456 #define time16_height 16
457 static unsigned char time16_bits[] = {
458 0x00, 0x00, 0xfe, 0x7f, 0x14, 0x28, 0x14, 0x28, 0x14, 0x28, 0x24, 0x24,
459 0x44, 0x22, 0x84, 0x21, 0x84, 0x21, 0x44, 0x22, 0x24, 0x24, 0x14, 0x28,
460 0x94, 0x29, 0xd4, 0x2b, 0xfe, 0x7f, 0x00, 0x00};
462 #define time16m_width 16
463 #define time16m_height 16
464 static unsigned char time16m_bits[] = {
465 0xff, 0xff, 0xff, 0xff, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f,
466 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f,
467 0xfe, 0x7f, 0xfe, 0x7f, 0xff, 0xff, 0xff, 0xff};
470 Cursor GetHourGlass (Display *dpy)
476 unsigned int xHotspot;
477 unsigned int yHotspot;
482 unsigned int cHeight;
483 int useLargeCursors = 0;
486 if (XQueryBestCursor (dpy, DefaultRootWindow(dpy),
487 32, 32, &cWidth, &cHeight))
489 if ((cWidth >= 32) && (cHeight >= 32))
497 width = time32_width;
498 height = time32_height;
499 bits = (char *)time32_bits;
500 maskBits = (char *)time32m_bits;
501 xHotspot = time32_x_hot;
502 yHotspot = time32_y_hot;
506 width = time16_width;
507 height = time16_height;
508 bits = (char *)time16_bits;
509 maskBits = (char *)time16m_bits;
510 xHotspot = time16_x_hot;
511 yHotspot = time16_y_hot;
514 pixmap = XCreateBitmapFromData (dpy,
515 DefaultRootWindow(dpy), bits,
518 maskPixmap = XCreateBitmapFromData (dpy,
519 DefaultRootWindow(dpy), maskBits,
522 xcolors[0].pixel = BlackPixelOfScreen(DefaultScreenOfDisplay(dpy));
523 xcolors[1].pixel = WhitePixelOfScreen(DefaultScreenOfDisplay(dpy));
526 DefaultColormapOfScreen(DefaultScreenOfDisplay
529 waitCursor = XCreatePixmapCursor (dpy, pixmap, maskPixmap,
530 &(xcolors[0]), &(xcolors[1]),
532 XFreePixmap (dpy, pixmap);
533 XFreePixmap (dpy, maskPixmap);
541 /*************************************<->*************************************
543 * void SetHourGlassCursor
548 * sets the window cursor to an hourglass
562 * None. (None doesn't count as a comment)
564 *************************************<->***********************************/
567 SetHourGlassCursor( Display *dpy, Window w )
571 XUndefineCursor(dpy, w);
573 cursor = GetHourGlass(dpy);
575 XDefineCursor(dpy, w, cursor);
576 XFreeCursor(dpy, cursor);
580 #if !defined (ENABLE_DYNAMIC_LANGLIST)
581 /***************************************************************************
585 * Generate the list of languages installed on the host.
586 * Result is stored the global array "languageList"
588 ***************************************************************************/
590 #define DELIM " \t" /* delimiters in language list */
592 static jmp_buf langJump;
595 MakeLangAbort( int arg )
598 longjmp (langJump, 1);
606 char *lang[500]; /* sort list for languages */
607 int nlang; /* total number of languages */
612 * build language list from set of languages installed on the host...
613 * Wrap a timer around it so it doesn't hang things up too long.
614 * langListTimeout resource by default is 30 seconds to scan NLS dir.
620 signal (SIGALRM, MakeLangAbort);
621 alarm ((unsigned) langListTimeout);
623 if (!setjmp (langJump)) {
624 ScanNLSDir(DEF_NLS_DIR);
627 LogError(ReadCatalog(MC_LOG_SET,MC_LOG_NO_SCAN,MC_DEF_LOG_NO_SCAN),
628 DEF_NLS_DIR, langListTimeout);
632 signal (SIGALRM, SIG_DFL);
636 * sort the list to eliminate duplicates and replace in global array...
639 p = savelist = strdup(languageList);
642 while ( (s = strtok(p, DELIM)) != NULL ) {
651 for (i = nlang; i > 0 && strcmp(s,lang[i-1]) < 0; i--);
653 if (i==0 || strcmp(s,lang[i-1]) != 0 ) {
654 for (j = nlang; j > i; j--)
668 for ( i = 0; i < nlang; i++) {
679 MatchesFileSuffix(char *filename, char *suffix)
682 #if defined(_AIX) || defined(SVR4) || defined (__osf__) || defined(linux)
686 * The assumption here is that the use of strrstr is
687 * to determine if "dp->d_name" ends in ".cat".
690 if ((int) strlen(filename) >= (int) strlen(suffix))
692 strcmp(filename + (strlen(filename) - strlen (suffix)), suffix);
694 return (pch == NULL);
696 return (strrstr(filename, suffix) != NULL);
700 /***************************************************************************
704 * Scan a directory structure to see if it contains an installed language.
705 * If so, the name of the language is appended to a global list of languages.
707 * Scan method and scan directory will vary by platform.
709 ***************************************************************************/
713 ScanNLSDir(char *dirname)
717 * Search installed locale names for AIX 3.2.5
723 /* Search valid locales which are locale database files in
725 * File name is "??_??" which can be used as LANG variable.
727 if((dirp = opendir(dirname)) != NULL)
729 while((dp = readdir(dirp)) != NULL)
731 if(strlen(dp->d_name) == 5 && dp->d_name[2] == '_')
733 if((int) strlen(languageList) + 7 < LANGLISTSIZE )
735 strcat(languageList, " ");
736 strcat(languageList, dp->d_name);
746 #define LOCALE "locale.inf"
747 #define LOCALEOLD "locale.def"
748 #define COLLATE8 "collate8"
749 #define MAILX "mailx"
751 #define MSGCAT ".cat"
756 * Scan for installed locales on HP platform.
759 /***************************************************************************
760 * Scan supplied NLS directory structure to see if it contains an
761 * installed language. If so, the name of the language is appended
762 * to a global list of languages.
764 * This routine is recursively called as a directory structure is
767 *************************************************************************/
776 * Scan input directory, looking for a LOCALE file. If a sub-directory
777 * is found, recurse down into it...
779 if ( (dirp = opendir(dirname)) != NULL )
781 while ( (dp = readdir(dirp)) != NULL )
784 * ignore files that are known not to be candidates...
786 if ( MatchesFileSuffix(dp->d_name, MSGCAT) ||
787 (strcmp (dp->d_name, COLLATE8) == 0 ) ||
788 (strcmp (dp->d_name, MAILX) == 0 ) ||
789 (strcmp (dp->d_name, ELM) == 0 ) ||
790 (strcmp (dp->d_name, DOT) == 0 ) ||
791 (strcmp (dp->d_name, DOTDOT) == 0 ) )
796 * check to see if this is the locale file...
798 if ( (strcmp(dp->d_name, LOCALEOLD) == 0 ) ||
799 (strcmp(dp->d_name, LOCALE) == 0 ) )
804 * Convert directory name to language name...
806 if ( (p = strstr(dirname, DEF_NLS_DIR)) != NULL )
808 p += strlen(DEF_NLS_DIR);
813 while ( (p = strchr(s,'/')) != NULL )
817 * append to global list of languages...
819 if ((int) (strlen(languageList)+strlen(s)+2) < LANGLISTSIZE)
821 strcat(languageList, " ");
822 strcat(languageList, s);
830 * if this file is a directory, scan it also...
832 strcpy(buf, dirname);
834 strcat(buf, dp->d_name);
836 if (stat(buf, &statb) == 0 && S_ISDIR(statb.st_mode))
844 #elif defined(__osf__)
846 #if defined(__osf__obsoleted)
847 #define LANGUAGE_LIST_CMD "/bin/locale -a"
849 * Scan for installed locales on DEC platform
853 char locale[MAXPATHLEN];
855 if (NULL == (f = popen(LANGUAGE_LIST_CMD, "r")))
858 while (NULL != fgets(locale, sizeof(locale), f))
860 if (locale[0] != '.' &&
861 LANGLISTSIZE > (int) (strlen(languageList) + strlen(locale) + 2))
863 int len = strlen(locale);
865 if ('\n' == locale[len-1])
866 locale[len-1] = '\0';
867 strcat(languageList, " ");
868 strcat(languageList, locale);
880 char **ignore = NULL;
884 const char *delim = " \t";
889 * Convert the string of locale patterns to an array. It will
890 * be easier to loop through when we start matching locales.
893 if (!(str = strdup(ignoreLocales)))
896 for (p = strtok(str, delim); p; p = strtok(NULL, delim)) {
897 if (num_ignore >= max_ignore) {
899 if (!(ignore = realloc(ignore, max_ignore * sizeof(char *)))) {
905 ignore[num_ignore++] = p;
909 * Assume that each file of the form ??_??* is a locale. If
910 * the locale doesn't match any of the ignore patterns, add it
911 * to the language list with a space separator.
913 * Seed the list with C and POSIX. They're built into libc
914 * and don't have locale files. Checking ignoreLocales for them
915 * isn't worth the effort.
918 strcpy(languageList, "C POSIX");
919 listlen = strlen(languageList);
921 if (dirp = opendir(dirname)) {
922 while (entp = readdir(dirp)) {
923 int namelen = strlen(entp->d_name);
924 if (namelen >= 5 && entp->d_name[2] == '_') {
926 for (i = 0; i < num_ignore; i++) {
927 if (!fnmatch(ignore[i], entp->d_name, 0)) {
936 /* 1 for space-separator, 1 for null-terminator */
937 if (listlen + 1 + namelen + 1 > LANGLISTSIZE)
940 languageList[listlen++] = ' ';
942 strcpy(&languageList[listlen], entp->d_name);
947 languageList[listlen++] = '\0';
954 #endif /* __osf__obsoleted__ */
958 * Scan for installed locales on Sun platform.
964 char path1[MAXPATHLEN], path2[MAXPATHLEN];
965 struct stat stat1, stat2;
966 int retval1, retval2;
969 * To determin the fully installed locale list, check several locations.
971 if((dirp = opendir(DEF_X11_NLS_SHARE_DIR)) != NULL)
973 while((dp = readdir(dirp)) != NULL)
975 filename = dp->d_name;
977 if ( filename[0] != '.' &&
978 (int)(strlen(languageList) +
979 strlen(filename) + 2) < LANGLISTSIZE)
981 (void) sprintf(path1, "%s/%s", DEF_X11_NLS_LIB_DIR, filename);
982 (void) sprintf(path2, "%s/%s", dirname, filename);
983 retval1 = stat(path1, &stat1);
984 retval2 = stat(path2, &stat2);
986 if ( retval1==0 && retval2==0 &&
987 S_ISDIR(stat1.st_mode) && S_ISDIR(stat2.st_mode) )
989 strcat(languageList, " ");
990 strcat(languageList, filename);
998 #elif defined(__uxp__) || defined(USL)
1000 #define LC_COLLATE "LC_COLLATE"
1001 #define LC_CTYPE "LC_CTYPE"
1002 #define LC_MESSAGES "LC_MESSAGES"
1003 #define LC_MONETARY "LC_MONETARY"
1004 #define LC_NUMERIC "LC_NUMERIC"
1005 #define LC_TIME "LC_TIME"
1008 * Scan for installed locales on Fujitsu and Novell/SCO platforms.
1011 DIR *nls_dirp, *locale_dirp;
1014 char locale_path[MAXPATHLEN];
1015 struct stat locale_stat;
1019 * To determin the fully installed locale list, check several locations.
1021 if((nls_dirp = opendir(dirname)) != NULL)
1023 while((dp = readdir(nls_dirp)) != NULL)
1027 locale = dp->d_name;
1030 * A locale is indicated by a directory which has one or more
1031 * of the following subdirectories:
1039 (void) sprintf(locale_path, "%s/%s", dirname, locale);
1040 retval = stat(locale_path, &locale_stat);
1041 if ( (0 != retval) || (! S_ISDIR(locale_stat.st_mode)) )
1044 if (NULL == (locale_dirp = opendir(locale_path)) )
1048 while (NULL != (dp = readdir(locale_dirp)) &&
1051 if ((0 == strcmp(dp->d_name, LC_COLLATE)) ||
1052 (0 == strcmp(dp->d_name, LC_CTYPE)) ||
1053 (0 == strcmp(dp->d_name, LC_MESSAGES)) ||
1054 (0 == strcmp(dp->d_name, LC_MONETARY)) ||
1055 (0 == strcmp(dp->d_name, LC_NUMERIC)) ||
1056 (0 == strcmp(dp->d_name, LC_TIME)) )
1060 closedir(locale_dirp);
1063 LANGLISTSIZE > (int) (strlen(languageList)+strlen(locale)+2) )
1065 strcat(languageList, " ");
1066 strcat(languageList, locale);
1074 #else /* !_AIX && !hpV4 && !__osf__ !sun && !USL && !__uxp__ */
1076 * Scan for installed locales on generic platform
1082 char locale_path[MAXPATHLEN];
1083 struct stat locale_stat;
1087 * To determin the fully installed locale list, check several locations.
1089 if(NULL != (dirp = opendir(dirname)))
1091 while((dp = readdir(dirp)) != NULL)
1093 locale = dp->d_name;
1095 if (locale[0] != '.' &&
1096 LANGLISTSIZE > (int) (strlen(languageList)+strlen(locale)+2));
1098 (void) sprintf(locale_path, "%s/%s", dirname, locale);
1099 retval = stat(locale_path, &locale_stat);
1101 if (0 == retval && S_ISDIR(locale_stat.st_mode))
1103 strcat(languageList, " ");
1104 strcat(languageList, locale);
1114 #endif /* ENABLE_DYNAMIC_LANGLIST */
1117 #define ENVFILE "/etc/environment"
1119 /* Refer to the LANG environment variable, first.
1120 * Or, search a line which includes "LANG=XX_XX" in /etc/environment.
1121 * If succeeded, set the value to d->language.
1124 SetDefaultLanguage(struct display *d)
1132 if((lang = getenv( "LANG" )) == NULL ) {
1133 if((file = fopen(ENVFILE, "r")) != NULL) {
1134 while(fgets(lineBuf, sizeof(lineBuf) - 1, file)) {
1135 n = strlen(lineBuf);
1136 if(n > 1 && lineBuf[0] != '#') {
1137 if(lineBuf[n - 1] == '\n')
1138 lineBuf[n - 1] = '\0';
1139 if((p = strstr(lineBuf, "LANG=")) != NULL) {
1141 if(strlen(p) == 5 && p[2] == '_') {
1151 if(lang != NULL && strlen(lang) > 0) {
1153 * If LANG is set for hft, we need to change it for X.
1154 * Currently there are four hft LANG variables.
1156 d->language = (char *)malloc(strlen(lang)+1);
1157 if(strcmp(lang, "En_JP") == 0)
1158 strcpy(d->language, "Ja_JP");
1159 else if(strcmp(lang, "en_JP") == 0)
1160 strcpy(d->language, "ja_JP");
1161 else if(strcmp(lang, "en_KR") == 0)
1162 strcpy(d->language, "ko_KR");
1163 else if(strcmp(lang, "en_TW") == 0)
1164 strcpy(d->language, "zh_TW");
1166 strcpy(d->language, lang);
1173 setLang( struct display *d, char **env , char *langptr)
1175 char langlist[LANGLISTSIZE];
1177 char *element = NULL;
1178 int set_def_lang = FALSE;
1181 if (NULL != langptr)
1182 Debug("setLang(): langlist = %s\n", langptr);
1184 Debug("setLang(): langlist = NULL\n");
1187 strcpy(langlist, langptr);
1189 strcpy(langlist, getEnv(env, "LANGLIST"));
1191 if (langlist && (int) strlen(langlist) > 0) {
1192 element = strtok(langlist, DELIM);
1194 set_def_lang = FALSE;
1195 if (strcmp(element,d->language) == 0){
1196 env = setEnv(env, "LANG", d->language);
1200 set_def_lang = TRUE;
1202 s += strlen(element) +1;
1203 element = strtok(langlist+s, DELIM);
1206 set_def_lang = TRUE;
1209 env = setEnv(env, "LANG", "C");
1210 d->language = strdup("C");
1215 static char localHostbuf[256];
1216 static int gotLocalHostname;
1221 if (!gotLocalHostname)
1223 XmuGetHostname (localHostbuf, sizeof (localHostbuf) - 1);
1224 gotLocalHostname = 1;
1226 return localHostbuf;