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) || \
687 * The assumption here is that the use of strrstr is
688 * to determine if "dp->d_name" ends in ".cat".
691 if ((int) strlen(filename) >= (int) strlen(suffix))
693 strcmp(filename + (strlen(filename) - strlen (suffix)), suffix);
695 return (pch == NULL);
697 return (strrstr(filename, suffix) != NULL);
701 /***************************************************************************
705 * Scan a directory structure to see if it contains an installed language.
706 * If so, the name of the language is appended to a global list of languages.
708 * Scan method and scan directory will vary by platform.
710 ***************************************************************************/
714 ScanNLSDir(char *dirname)
718 * Search installed locale names for AIX 3.2.5
724 /* Search valid locales which are locale database files in
726 * File name is "??_??" which can be used as LANG variable.
728 if((dirp = opendir(dirname)) != NULL)
730 while((dp = readdir(dirp)) != NULL)
732 if(strlen(dp->d_name) == 5 && dp->d_name[2] == '_')
734 if((int) strlen(languageList) + 7 < LANGLISTSIZE )
736 strcat(languageList, " ");
737 strcat(languageList, dp->d_name);
747 #define LOCALE "locale.inf"
748 #define LOCALEOLD "locale.def"
749 #define COLLATE8 "collate8"
750 #define MAILX "mailx"
752 #define MSGCAT ".cat"
757 * Scan for installed locales on HP platform.
760 /***************************************************************************
761 * Scan supplied NLS directory structure to see if it contains an
762 * installed language. If so, the name of the language is appended
763 * to a global list of languages.
765 * This routine is recursively called as a directory structure is
768 *************************************************************************/
777 * Scan input directory, looking for a LOCALE file. If a sub-directory
778 * is found, recurse down into it...
780 if ( (dirp = opendir(dirname)) != NULL )
782 while ( (dp = readdir(dirp)) != NULL )
785 * ignore files that are known not to be candidates...
787 if ( MatchesFileSuffix(dp->d_name, MSGCAT) ||
788 (strcmp (dp->d_name, COLLATE8) == 0 ) ||
789 (strcmp (dp->d_name, MAILX) == 0 ) ||
790 (strcmp (dp->d_name, ELM) == 0 ) ||
791 (strcmp (dp->d_name, DOT) == 0 ) ||
792 (strcmp (dp->d_name, DOTDOT) == 0 ) )
797 * check to see if this is the locale file...
799 if ( (strcmp(dp->d_name, LOCALEOLD) == 0 ) ||
800 (strcmp(dp->d_name, LOCALE) == 0 ) )
805 * Convert directory name to language name...
807 if ( (p = strstr(dirname, DEF_NLS_DIR)) != NULL )
809 p += strlen(DEF_NLS_DIR);
814 while ( (p = strchr(s,'/')) != NULL )
818 * append to global list of languages...
820 if ((int) (strlen(languageList)+strlen(s)+2) < LANGLISTSIZE)
822 strcat(languageList, " ");
823 strcat(languageList, s);
831 * if this file is a directory, scan it also...
833 strcpy(buf, dirname);
835 strcat(buf, dp->d_name);
837 if (stat(buf, &statb) == 0 && S_ISDIR(statb.st_mode))
845 #elif defined(__osf__)
847 #if defined(__osf__obsoleted)
848 #define LANGUAGE_LIST_CMD "/bin/locale -a"
850 * Scan for installed locales on DEC platform
854 char locale[MAXPATHLEN];
856 if (NULL == (f = popen(LANGUAGE_LIST_CMD, "r")))
859 while (NULL != fgets(locale, sizeof(locale), f))
861 if (locale[0] != '.' &&
862 LANGLISTSIZE > (int) (strlen(languageList) + strlen(locale) + 2))
864 int len = strlen(locale);
866 if ('\n' == locale[len-1])
867 locale[len-1] = '\0';
868 strcat(languageList, " ");
869 strcat(languageList, locale);
881 char **ignore = NULL;
885 const char *delim = " \t";
890 * Convert the string of locale patterns to an array. It will
891 * be easier to loop through when we start matching locales.
894 if (!(str = strdup(ignoreLocales)))
897 for (p = strtok(str, delim); p; p = strtok(NULL, delim)) {
898 if (num_ignore >= max_ignore) {
900 if (!(ignore = realloc(ignore, max_ignore * sizeof(char *)))) {
906 ignore[num_ignore++] = p;
910 * Assume that each file of the form ??_??* is a locale. If
911 * the locale doesn't match any of the ignore patterns, add it
912 * to the language list with a space separator.
914 * Seed the list with C and POSIX. They're built into libc
915 * and don't have locale files. Checking ignoreLocales for them
916 * isn't worth the effort.
919 strcpy(languageList, "C POSIX");
920 listlen = strlen(languageList);
922 if (dirp = opendir(dirname)) {
923 while (entp = readdir(dirp)) {
924 int namelen = strlen(entp->d_name);
925 if (namelen >= 5 && entp->d_name[2] == '_') {
927 for (i = 0; i < num_ignore; i++) {
928 if (!fnmatch(ignore[i], entp->d_name, 0)) {
937 /* 1 for space-separator, 1 for null-terminator */
938 if (listlen + 1 + namelen + 1 > LANGLISTSIZE)
941 languageList[listlen++] = ' ';
943 strcpy(&languageList[listlen], entp->d_name);
948 languageList[listlen++] = '\0';
955 #endif /* __osf__obsoleted__ */
959 * Scan for installed locales on Sun platform.
965 char path1[MAXPATHLEN], path2[MAXPATHLEN];
966 struct stat stat1, stat2;
967 int retval1, retval2;
970 * To determin the fully installed locale list, check several locations.
972 if((dirp = opendir(DEF_X11_NLS_SHARE_DIR)) != NULL)
974 while((dp = readdir(dirp)) != NULL)
976 filename = dp->d_name;
978 if ( filename[0] != '.' &&
979 (int)(strlen(languageList) +
980 strlen(filename) + 2) < LANGLISTSIZE)
982 (void) sprintf(path1, "%s/%s", DEF_X11_NLS_LIB_DIR, filename);
983 (void) sprintf(path2, "%s/%s", dirname, filename);
984 retval1 = stat(path1, &stat1);
985 retval2 = stat(path2, &stat2);
987 if ( retval1==0 && retval2==0 &&
988 S_ISDIR(stat1.st_mode) && S_ISDIR(stat2.st_mode) )
990 strcat(languageList, " ");
991 strcat(languageList, filename);
999 #elif defined(__uxp__) || defined(USL)
1001 #define LC_COLLATE "LC_COLLATE"
1002 #define LC_CTYPE "LC_CTYPE"
1003 #define LC_MESSAGES "LC_MESSAGES"
1004 #define LC_MONETARY "LC_MONETARY"
1005 #define LC_NUMERIC "LC_NUMERIC"
1006 #define LC_TIME "LC_TIME"
1009 * Scan for installed locales on Fujitsu and Novell/SCO platforms.
1012 DIR *nls_dirp, *locale_dirp;
1015 char locale_path[MAXPATHLEN];
1016 struct stat locale_stat;
1020 * To determin the fully installed locale list, check several locations.
1022 if((nls_dirp = opendir(dirname)) != NULL)
1024 while((dp = readdir(nls_dirp)) != NULL)
1028 locale = dp->d_name;
1031 * A locale is indicated by a directory which has one or more
1032 * of the following subdirectories:
1040 (void) sprintf(locale_path, "%s/%s", dirname, locale);
1041 retval = stat(locale_path, &locale_stat);
1042 if ( (0 != retval) || (! S_ISDIR(locale_stat.st_mode)) )
1045 if (NULL == (locale_dirp = opendir(locale_path)) )
1049 while (NULL != (dp = readdir(locale_dirp)) &&
1052 if ((0 == strcmp(dp->d_name, LC_COLLATE)) ||
1053 (0 == strcmp(dp->d_name, LC_CTYPE)) ||
1054 (0 == strcmp(dp->d_name, LC_MESSAGES)) ||
1055 (0 == strcmp(dp->d_name, LC_MONETARY)) ||
1056 (0 == strcmp(dp->d_name, LC_NUMERIC)) ||
1057 (0 == strcmp(dp->d_name, LC_TIME)) )
1061 closedir(locale_dirp);
1064 LANGLISTSIZE > (int) (strlen(languageList)+strlen(locale)+2) )
1066 strcat(languageList, " ");
1067 strcat(languageList, locale);
1075 #else /* !_AIX && !hpV4 && !__osf__ !sun && !USL && !__uxp__ */
1077 * Scan for installed locales on generic platform
1083 char locale_path[MAXPATHLEN];
1084 struct stat locale_stat;
1088 * To determin the fully installed locale list, check several locations.
1090 if(NULL != (dirp = opendir(dirname)))
1092 while((dp = readdir(dirp)) != NULL)
1094 locale = dp->d_name;
1096 if ( (strcmp(dp->d_name, ".") == 0) ||
1097 (strcmp(dp->d_name, "..") == 0) )
1100 if (locale[0] != '.' &&
1101 LANGLISTSIZE > (int) (strlen(languageList)+strlen(locale)+2));
1103 (void) sprintf(locale_path, "%s/%s", dirname, locale);
1104 retval = stat(locale_path, &locale_stat);
1106 if (0 == retval && S_ISDIR(locale_stat.st_mode))
1108 strcat(languageList, " ");
1109 strcat(languageList, locale);
1119 #endif /* ENABLE_DYNAMIC_LANGLIST */
1122 #define ENVFILE "/etc/environment"
1124 /* Refer to the LANG environment variable, first.
1125 * Or, search a line which includes "LANG=XX_XX" in /etc/environment.
1126 * If succeeded, set the value to d->language.
1129 SetDefaultLanguage(struct display *d)
1137 if((lang = getenv( "LANG" )) == NULL ) {
1138 if((file = fopen(ENVFILE, "r")) != NULL) {
1139 while(fgets(lineBuf, sizeof(lineBuf) - 1, file)) {
1140 n = strlen(lineBuf);
1141 if(n > 1 && lineBuf[0] != '#') {
1142 if(lineBuf[n - 1] == '\n')
1143 lineBuf[n - 1] = '\0';
1144 if((p = strstr(lineBuf, "LANG=")) != NULL) {
1146 if(strlen(p) == 5 && p[2] == '_') {
1156 if(lang != NULL && strlen(lang) > 0) {
1158 * If LANG is set for hft, we need to change it for X.
1159 * Currently there are four hft LANG variables.
1161 d->language = (char *)malloc(strlen(lang)+1);
1162 if(strcmp(lang, "En_JP") == 0)
1163 strcpy(d->language, "Ja_JP");
1164 else if(strcmp(lang, "en_JP") == 0)
1165 strcpy(d->language, "ja_JP");
1166 else if(strcmp(lang, "en_KR") == 0)
1167 strcpy(d->language, "ko_KR");
1168 else if(strcmp(lang, "en_TW") == 0)
1169 strcpy(d->language, "zh_TW");
1171 strcpy(d->language, lang);
1178 setLang( struct display *d, char **env , char *langptr)
1180 char langlist[LANGLISTSIZE];
1182 char *element = NULL;
1183 int set_def_lang = FALSE;
1186 if (NULL != langptr)
1187 Debug("setLang(): langlist = %s\n", langptr);
1189 Debug("setLang(): langlist = NULL\n");
1192 strcpy(langlist, langptr);
1194 strcpy(langlist, getEnv(env, "LANGLIST"));
1196 if (langlist && (int) strlen(langlist) > 0) {
1197 element = strtok(langlist, DELIM);
1199 set_def_lang = FALSE;
1200 if (strcmp(element,d->language) == 0){
1201 env = setEnv(env, "LANG", d->language);
1205 set_def_lang = TRUE;
1207 s += strlen(element) +1;
1208 element = strtok(langlist+s, DELIM);
1211 set_def_lang = TRUE;
1214 env = setEnv(env, "LANG", "C");
1215 d->language = strdup("C");
1220 static char localHostbuf[256];
1221 static int gotLocalHostname;
1226 if (!gotLocalHostname)
1228 XmuGetHostname (localHostbuf, sizeof (localHostbuf) - 1);
1229 gotLocalHostname = 1;
1231 return localHostbuf;