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 /* (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(const char *filename, const char *suffix);
98 static void ScanNLSDir(
101 /******** End Local Function Declarations ********/
104 /***************************************************************************
108 * read a string from the message catalog
109 ***************************************************************************/
112 ReadCatalog( int set_num, int msg_num, char *def_str )
114 static Bool alreadyopen = False;
117 if (alreadyopen == False)
119 char *curNlsPath, *newNlsPath;
125 * Desktop message catalogs are in DT directory, so append desktop
126 * search paths to current NLSPATH.
128 #define NLS_PATH_STRING CDE_INSTALLATION_TOP "/nls/msg/%L/%N.cat:" \
129 CDE_INSTALLATION_TOP "/lib/nls/msg/%L/%N.cat:" \
130 CDE_INSTALLATION_TOP "/lib/nls/msg/%l/%t/%c/%N.cat:" \
131 CDE_INSTALLATION_TOP "/lib/nls/msg/%l/%c/%N.cat"
133 curNlsPath = getenv("NLSPATH");
134 if (curNlsPath && strlen(curNlsPath) == 0)
142 * <length of NLS_PATH_STRING>
145 newNlsPathLen = 7 + 1 + strlen(NLS_PATH_STRING) + 1;
147 if (curNlsPath != NULL)
151 * <length of curNlsPath>
153 newNlsPathLen += (1 + strlen(curNlsPath));
156 newNlsPath = malloc(newNlsPathLen); /* placed in environ, do not free */
158 if (curNlsPath != NULL)
160 sprintf(newNlsPath, "NLSPATH=%s:%s", curNlsPath, NLS_PATH_STRING);
164 sprintf(newNlsPath, "NLSPATH=%s", NLS_PATH_STRING);
168 * Store new NLSPATH in environment. Note this memory cannot be freed
173 * Open message catalog. Note, if invalid descriptor returned (ie
174 * msg catalog could not be opened), subsequent call to catgets() using
175 * that descriptor will return 'def_str'.
177 nl_fd = catopen("dtlogin", NL_CAT_LOCALE);
180 s = catgets(nl_fd,set_num,msg_num,def_str);
182 return((unsigned char *)s);
189 Debug (" %s\n", *e++);
193 makeEnv( char *name, char *value )
197 result = malloc ((unsigned) (strlen (name) + strlen (value) + 2));
200 ReadCatalog(MC_LOG_SET,MC_LOG_MAKEENV,MC_DEF_LOG_MAKEENV));
205 sprintf (result, "%s=%s", name, value);
208 sprintf (result, "%s", name);
215 getEnv( char **e, char *name )
217 int l = strlen (name);
220 if ((int) strlen (*e) > l &&
221 !strncmp (*e, name, l) &&
231 setEnv( char **e, char *name, char *value )
239 newe = makeEnv (name, value);
241 LogOutOfMem(ReadCatalog(MC_LOG_SET,MC_LOG_SETENV,MC_DEF_LOG_SETENV));
245 for (old = e; *old; old++)
246 if ((int) strlen (*old) > l &&
247 !strncmp (*old, name, l) &&
258 realloc((char *) e, (unsigned) ((envsize + 2) * sizeof (char *)));
261 new = (char **) malloc (2 * sizeof (char *));
264 LogOutOfMem(ReadCatalog(MC_LOG_SET,MC_LOG_SETENV,MC_DEF_LOG_SETENV));
280 for (e = env; *e; e++)
286 # define isblank(c) ((c) == ' ' || c == '\t')
289 parseArgs( char **argv, char *string )
296 while (argv && argv[i])
299 argv = (char **) malloc (sizeof (char *));
301 LogOutOfMem(ReadCatalog(
302 MC_LOG_SET,MC_LOG_PARSEARGS,MC_DEF_LOG_PARSEARGS));
308 if (!*string || isblank (*string)) {
309 if (word != string) {
310 argv = (char **) realloc ((char *) argv,
311 (unsigned) ((i + 2) * sizeof (char *)));
312 save = malloc ((unsigned) (string - word + 1));
313 if (!argv || !save) {
314 LogOutOfMem(ReadCatalog(MC_LOG_SET,
316 MC_DEF_LOG_PARSEARGS));
318 free ((char *) argv);
323 argv[i] = strncpy (save, word, string-word);
324 argv[i][string-word] = '\0';
341 * On i386/i486 platforms setprrp() functions causes the mouse not
342 * to work. Since in the daemon mode the parent daemon has already
343 * executed a setpgrp it is a process and session leader. Since it
344 * has also gotten rid of the controlling terminal there is no great
345 * harm in not making the sub-daemons as leaders.
351 #if defined (SYSV) || defined (SVR4) || defined(linux)
352 #if !defined (USL) && !defined(__uxp__)
356 setpgrp (0, getpid ());
361 (void) signal (SIGCHLD, SIG_DFL);
363 (void) signal (SIGTERM, SIG_DFL);
364 (void) signal (SIGPIPE, SIG_DFL);
365 (void) signal (SIGALRM, SIG_DFL);
366 (void) signal (SIGHUP, SIG_DFL);
371 parseEnv( char **e, char *string )
374 char *s1, *s2, *t1, *t2;
376 s1 = s2 = strdup(string);
378 while ((t1 = strtok(s1," \t")) != NULL ) {
379 if ( (t2 = strchr(t1,'=')) != NULL ) {
381 e = setEnv(e, t1, t2);
394 /*************************************<->*************************************
396 * Cursor GetHourGlass ()
401 * Builds and returns the appropriate Hourglass cursor
414 * None. (None doesn't count as a comment)
416 *************************************<->***********************************/
418 #define time32_width 32
419 #define time32_height 32
420 #define time32_x_hot 15
421 #define time32_y_hot 15
422 static unsigned char time32_bits[] = {
423 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, 0x7f, 0xfe, 0xff, 0xff, 0x7f,
424 0x8c, 0x00, 0x00, 0x31, 0x4c, 0x00, 0x00, 0x32, 0x4c, 0x00, 0x00, 0x32,
425 0x4c, 0x00, 0x00, 0x32, 0x4c, 0x00, 0x00, 0x32, 0x4c, 0x00, 0x00, 0x32,
426 0x8c, 0x00, 0x00, 0x31, 0x0c, 0x7f, 0xfe, 0x30, 0x0c, 0xfe, 0x7f, 0x30,
427 0x0c, 0xfc, 0x3f, 0x30, 0x0c, 0xf8, 0x1f, 0x30, 0x0c, 0xe0, 0x07, 0x30,
428 0x0c, 0x80, 0x01, 0x30, 0x0c, 0x80, 0x01, 0x30, 0x0c, 0x60, 0x06, 0x30,
429 0x0c, 0x18, 0x18, 0x30, 0x0c, 0x04, 0x20, 0x30, 0x0c, 0x02, 0x40, 0x30,
430 0x0c, 0x01, 0x80, 0x30, 0x8c, 0x00, 0x00, 0x31, 0x4c, 0x80, 0x01, 0x32,
431 0x4c, 0xc0, 0x03, 0x32, 0x4c, 0xf0, 0x1f, 0x32, 0x4c, 0xff, 0xff, 0x32,
432 0xcc, 0xff, 0xff, 0x33, 0x8c, 0xff, 0xff, 0x31, 0xfe, 0xff, 0xff, 0x7f,
433 0xfe, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00};
435 #define time32m_width 32
436 #define time32m_height 32
437 static unsigned char time32m_bits[] = {
438 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
439 0xcf, 0x00, 0x00, 0xf3, 0x6e, 0x00, 0x00, 0x76, 0x6e, 0x00, 0x00, 0x76,
440 0x6e, 0x00, 0x00, 0x76, 0x6e, 0x00, 0x00, 0x76, 0x6e, 0x00, 0x00, 0x76,
441 0xce, 0x00, 0x00, 0x73, 0x8e, 0x7f, 0xfe, 0x71, 0x0e, 0xff, 0xff, 0x70,
442 0x0e, 0xfe, 0x7f, 0x70, 0x0e, 0xfc, 0x3f, 0x70, 0x0e, 0xf8, 0x1f, 0x70,
443 0x0e, 0xe0, 0x07, 0x70, 0x0e, 0xe0, 0x07, 0x70, 0x0e, 0x78, 0x1e, 0x70,
444 0x0e, 0x1c, 0x38, 0x70, 0x0e, 0x06, 0x60, 0x70, 0x0e, 0x03, 0xc0, 0x70,
445 0x8e, 0x01, 0x80, 0x71, 0xce, 0x00, 0x00, 0x73, 0x6e, 0x80, 0x01, 0x76,
446 0x6e, 0xc0, 0x03, 0x76, 0x6e, 0xf0, 0x1f, 0x76, 0x6e, 0xff, 0xff, 0x76,
447 0xee, 0xff, 0xff, 0x77, 0xcf, 0xff, 0xff, 0xf3, 0xff, 0xff, 0xff, 0xff,
448 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
451 #define time16_x_hot 7
452 #define time16_y_hot 7
453 #define time16_width 16
454 #define time16_height 16
455 static unsigned char time16_bits[] = {
456 0x00, 0x00, 0xfe, 0x7f, 0x14, 0x28, 0x14, 0x28, 0x14, 0x28, 0x24, 0x24,
457 0x44, 0x22, 0x84, 0x21, 0x84, 0x21, 0x44, 0x22, 0x24, 0x24, 0x14, 0x28,
458 0x94, 0x29, 0xd4, 0x2b, 0xfe, 0x7f, 0x00, 0x00};
460 #define time16m_width 16
461 #define time16m_height 16
462 static unsigned char time16m_bits[] = {
463 0xff, 0xff, 0xff, 0xff, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f,
464 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f,
465 0xfe, 0x7f, 0xfe, 0x7f, 0xff, 0xff, 0xff, 0xff};
468 Cursor GetHourGlass (Display *dpy)
474 unsigned int xHotspot;
475 unsigned int yHotspot;
480 unsigned int cHeight;
481 int useLargeCursors = 0;
484 if (XQueryBestCursor (dpy, DefaultRootWindow(dpy),
485 32, 32, &cWidth, &cHeight))
487 if ((cWidth >= 32) && (cHeight >= 32))
495 width = time32_width;
496 height = time32_height;
497 bits = (char *)time32_bits;
498 maskBits = (char *)time32m_bits;
499 xHotspot = time32_x_hot;
500 yHotspot = time32_y_hot;
504 width = time16_width;
505 height = time16_height;
506 bits = (char *)time16_bits;
507 maskBits = (char *)time16m_bits;
508 xHotspot = time16_x_hot;
509 yHotspot = time16_y_hot;
512 pixmap = XCreateBitmapFromData (dpy,
513 DefaultRootWindow(dpy), bits,
516 maskPixmap = XCreateBitmapFromData (dpy,
517 DefaultRootWindow(dpy), maskBits,
520 xcolors[0].pixel = BlackPixelOfScreen(DefaultScreenOfDisplay(dpy));
521 xcolors[1].pixel = WhitePixelOfScreen(DefaultScreenOfDisplay(dpy));
524 DefaultColormapOfScreen(DefaultScreenOfDisplay
527 waitCursor = XCreatePixmapCursor (dpy, pixmap, maskPixmap,
528 &(xcolors[0]), &(xcolors[1]),
530 XFreePixmap (dpy, pixmap);
531 XFreePixmap (dpy, maskPixmap);
539 /*************************************<->*************************************
541 * void SetHourGlassCursor
546 * sets the window cursor to an hourglass
560 * None. (None doesn't count as a comment)
562 *************************************<->***********************************/
565 SetHourGlassCursor( Display *dpy, Window w )
569 XUndefineCursor(dpy, w);
571 cursor = GetHourGlass(dpy);
573 XDefineCursor(dpy, w, cursor);
574 XFreeCursor(dpy, cursor);
578 #if !defined (ENABLE_DYNAMIC_LANGLIST)
579 /***************************************************************************
583 * Generate the list of languages installed on the host.
584 * Result is stored the global array "languageList"
586 ***************************************************************************/
588 #define DELIM " \t" /* delimiters in language list */
590 static jmp_buf langJump;
593 MakeLangAbort( int arg )
596 longjmp (langJump, 1);
604 char *lang[500]; /* sort list for languages */
605 int nlang; /* total number of languages */
610 * build language list from set of languages installed on the host...
611 * Wrap a timer around it so it doesn't hang things up too long.
612 * langListTimeout resource by default is 30 seconds to scan NLS dir.
618 signal (SIGALRM, MakeLangAbort);
619 alarm ((unsigned) langListTimeout);
621 if (!setjmp (langJump)) {
622 ScanNLSDir(DEF_NLS_DIR);
625 LogError(ReadCatalog(MC_LOG_SET,MC_LOG_NO_SCAN,MC_DEF_LOG_NO_SCAN),
626 DEF_NLS_DIR, langListTimeout);
630 signal (SIGALRM, SIG_DFL);
634 * sort the list to eliminate duplicates and replace in global array...
637 p = savelist = strdup(languageList);
640 while ( (s = strtok(p, DELIM)) != NULL ) {
649 for (i = nlang; i > 0 && strcmp(s,lang[i-1]) < 0; i--);
651 if (i==0 || strcmp(s,lang[i-1]) != 0 ) {
652 for (j = nlang; j > i; j--)
666 for ( i = 0; i < nlang; i++) {
677 MatchesFileSuffix(const char *filename, const char *suffix)
680 #if defined(_AIX) || defined(SVR4) || defined (__osf__) || defined(linux) || \
685 * The assumption here is that the use of strrstr is
686 * to determine if "dp->d_name" ends in ".cat".
688 if (strlen(filename) >= strlen(suffix)) {
689 different = strcmp(filename + (strlen(filename) - strlen (suffix)), suffix);
692 return (different == 0);
694 return (strrstr(filename, suffix) != NULL);
698 /***************************************************************************
702 * Scan a directory structure to see if it contains an installed language.
703 * If so, the name of the language is appended to a global list of languages.
705 * Scan method and scan directory will vary by platform.
707 ***************************************************************************/
711 ScanNLSDir(char *dirname)
715 * Search installed locale names for AIX 3.2.5
721 /* Search valid locales which are locale database files in
723 * File name is "??_??" which can be used as LANG variable.
725 if((dirp = opendir(dirname)) != NULL)
727 while((dp = readdir(dirp)) != NULL)
729 if(strlen(dp->d_name) == 5 && dp->d_name[2] == '_')
731 if((int) strlen(languageList) + 7 < LANGLISTSIZE )
733 strcat(languageList, " ");
734 strcat(languageList, dp->d_name);
744 #define LOCALE "locale.inf"
745 #define LOCALEOLD "locale.def"
746 #define COLLATE8 "collate8"
747 #define MAILX "mailx"
749 #define MSGCAT ".cat"
754 * Scan for installed locales on HP platform.
757 /***************************************************************************
758 * Scan supplied NLS directory structure to see if it contains an
759 * installed language. If so, the name of the language is appended
760 * to a global list of languages.
762 * This routine is recursively called as a directory structure is
765 *************************************************************************/
774 * Scan input directory, looking for a LOCALE file. If a sub-directory
775 * is found, recurse down into it...
777 if ( (dirp = opendir(dirname)) != NULL )
779 while ( (dp = readdir(dirp)) != NULL )
782 * ignore files that are known not to be candidates...
784 if ( MatchesFileSuffix(dp->d_name, MSGCAT) ||
785 (strcmp (dp->d_name, COLLATE8) == 0 ) ||
786 (strcmp (dp->d_name, MAILX) == 0 ) ||
787 (strcmp (dp->d_name, ELM) == 0 ) ||
788 (strcmp (dp->d_name, DOT) == 0 ) ||
789 (strcmp (dp->d_name, DOTDOT) == 0 ) )
794 * check to see if this is the locale file...
796 if ( (strcmp(dp->d_name, LOCALEOLD) == 0 ) ||
797 (strcmp(dp->d_name, LOCALE) == 0 ) )
802 * Convert directory name to language name...
804 if ( (p = strstr(dirname, DEF_NLS_DIR)) != NULL )
806 p += strlen(DEF_NLS_DIR);
811 while ( (p = strchr(s,'/')) != NULL )
815 * append to global list of languages...
817 if ((int) (strlen(languageList)+strlen(s)+2) < LANGLISTSIZE)
819 strcat(languageList, " ");
820 strcat(languageList, s);
828 * if this file is a directory, scan it also...
830 strcpy(buf, dirname);
832 strcat(buf, dp->d_name);
834 if (stat(buf, &statb) == 0 && S_ISDIR(statb.st_mode))
842 #elif defined(__osf__)
844 #if defined(__osf__obsoleted)
845 #define LANGUAGE_LIST_CMD "/bin/locale -a"
847 * Scan for installed locales on DEC platform
851 char locale[MAXPATHLEN];
853 if (NULL == (f = popen(LANGUAGE_LIST_CMD, "r")))
856 while (NULL != fgets(locale, sizeof(locale), f))
858 if (locale[0] != '.' &&
859 LANGLISTSIZE > (int) (strlen(languageList) + strlen(locale) + 2))
861 int len = strlen(locale);
863 if ('\n' == locale[len-1])
864 locale[len-1] = '\0';
865 strcat(languageList, " ");
866 strcat(languageList, locale);
878 char **ignore = NULL;
882 const char *delim = " \t";
887 * Convert the string of locale patterns to an array. It will
888 * be easier to loop through when we start matching locales.
891 if (!(str = strdup(ignoreLocales)))
894 for (p = strtok(str, delim); p; p = strtok(NULL, delim)) {
895 if (num_ignore >= max_ignore) {
897 if (!(ignore = realloc(ignore, max_ignore * sizeof(char *)))) {
903 ignore[num_ignore++] = p;
907 * Assume that each file of the form ??_??* is a locale. If
908 * the locale doesn't match any of the ignore patterns, add it
909 * to the language list with a space separator.
911 * Seed the list with C and POSIX. They're built into libc
912 * and don't have locale files. Checking ignoreLocales for them
913 * isn't worth the effort.
916 strcpy(languageList, "C POSIX");
917 listlen = strlen(languageList);
919 if (dirp = opendir(dirname)) {
920 while (entp = readdir(dirp)) {
921 int namelen = strlen(entp->d_name);
922 if (namelen >= 5 && entp->d_name[2] == '_') {
924 for (i = 0; i < num_ignore; i++) {
925 if (!fnmatch(ignore[i], entp->d_name, 0)) {
934 /* 1 for space-separator, 1 for null-terminator */
935 if (listlen + 1 + namelen + 1 > LANGLISTSIZE)
938 languageList[listlen++] = ' ';
940 strcpy(&languageList[listlen], entp->d_name);
945 languageList[listlen++] = '\0';
952 #endif /* __osf__obsoleted__ */
954 #elif defined(__uxp__) || defined(USL)
956 #define LC_COLLATE "LC_COLLATE"
957 #define LC_CTYPE "LC_CTYPE"
958 #define LC_MESSAGES "LC_MESSAGES"
959 #define LC_MONETARY "LC_MONETARY"
960 #define LC_NUMERIC "LC_NUMERIC"
961 #define LC_TIME "LC_TIME"
964 * Scan for installed locales on Fujitsu and Novell/SCO platforms.
967 DIR *nls_dirp, *locale_dirp;
970 char locale_path[MAXPATHLEN];
971 struct stat locale_stat;
975 * To determin the fully installed locale list, check several locations.
977 if((nls_dirp = opendir(dirname)) != NULL)
979 while((dp = readdir(nls_dirp)) != NULL)
986 * A locale is indicated by a directory which has one or more
987 * of the following subdirectories:
995 (void) sprintf(locale_path, "%s/%s", dirname, locale);
996 retval = stat(locale_path, &locale_stat);
997 if ( (0 != retval) || (! S_ISDIR(locale_stat.st_mode)) )
1000 if (NULL == (locale_dirp = opendir(locale_path)) )
1004 while (NULL != (dp = readdir(locale_dirp)) &&
1007 if ((0 == strcmp(dp->d_name, LC_COLLATE)) ||
1008 (0 == strcmp(dp->d_name, LC_CTYPE)) ||
1009 (0 == strcmp(dp->d_name, LC_MESSAGES)) ||
1010 (0 == strcmp(dp->d_name, LC_MONETARY)) ||
1011 (0 == strcmp(dp->d_name, LC_NUMERIC)) ||
1012 (0 == strcmp(dp->d_name, LC_TIME)) )
1016 closedir(locale_dirp);
1019 LANGLISTSIZE > (int) (strlen(languageList)+strlen(locale)+2) )
1021 strcat(languageList, " ");
1022 strcat(languageList, locale);
1030 #else /* !_AIX && !hpV4 && !__osf__ !sun && !USL && !__uxp__ */
1032 * Scan for installed locales on generic platform
1038 char locale_path[MAXPATHLEN];
1039 struct stat locale_stat;
1043 * To determin the fully installed locale list, check several locations.
1045 if(NULL != (dirp = opendir(dirname)))
1047 while((dp = readdir(dirp)) != NULL)
1049 locale = dp->d_name;
1051 if ( (strcmp(dp->d_name, ".") == 0) ||
1052 (strcmp(dp->d_name, "..") == 0) )
1055 if (locale[0] != '.' &&
1056 LANGLISTSIZE > (int) (strlen(languageList)+strlen(locale)+2));
1058 (void) sprintf(locale_path, "%s/%s", dirname, locale);
1059 retval = stat(locale_path, &locale_stat);
1061 if (0 == retval && S_ISDIR(locale_stat.st_mode))
1063 strcat(languageList, " ");
1064 strcat(languageList, locale);
1074 #endif /* ENABLE_DYNAMIC_LANGLIST */
1077 #define ENVFILE "/etc/environment"
1079 /* Refer to the LANG environment variable, first.
1080 * Or, search a line which includes "LANG=XX_XX" in /etc/environment.
1081 * If succeeded, set the value to d->language.
1084 SetDefaultLanguage(struct display *d)
1092 if((lang = getenv( "LANG" )) == NULL ) {
1093 if((file = fopen(ENVFILE, "r")) != NULL) {
1094 while(fgets(lineBuf, sizeof(lineBuf) - 1, file)) {
1095 n = strlen(lineBuf);
1096 if(n > 1 && lineBuf[0] != '#') {
1097 if(lineBuf[n - 1] == '\n')
1098 lineBuf[n - 1] = '\0';
1099 if((p = strstr(lineBuf, "LANG=")) != NULL) {
1101 if(strlen(p) == 5 && p[2] == '_') {
1111 if(lang != NULL && strlen(lang) > 0) {
1113 * If LANG is set for hft, we need to change it for X.
1114 * Currently there are four hft LANG variables.
1116 d->language = (char *)malloc(strlen(lang)+1);
1117 if(strcmp(lang, "En_JP") == 0)
1118 strcpy(d->language, "Ja_JP");
1119 else if(strcmp(lang, "en_JP") == 0)
1120 strcpy(d->language, "ja_JP");
1121 else if(strcmp(lang, "en_KR") == 0)
1122 strcpy(d->language, "ko_KR");
1123 else if(strcmp(lang, "en_TW") == 0)
1124 strcpy(d->language, "zh_TW");
1126 strcpy(d->language, lang);
1133 setLang( struct display *d, char **env , char *langptr)
1135 char langlist[LANGLISTSIZE];
1137 char *element = NULL;
1138 int set_def_lang = FALSE;
1141 if (NULL != langptr)
1142 Debug("setLang(): langlist = %s\n", langptr);
1144 Debug("setLang(): langlist = NULL\n");
1147 snprintf(langlist, sizeof(langlist), "%s", langptr);
1149 snprintf(langlist, sizeof(langlist), "%s", getEnv(env, "LANGLIST"));
1151 if (strlen(langlist) > 0) {
1152 element = strtok(langlist, DELIM);
1154 set_def_lang = FALSE;
1155 if (strcmp(element,d->language) == 0){
1156 env = setEnv(env, "LANG", d->language);
1160 set_def_lang = TRUE;
1162 s += strlen(element) +1;
1163 element = strtok(langlist+s, DELIM);
1166 set_def_lang = TRUE;
1169 env = setEnv(env, "LANG", "C");
1170 d->language = strdup("C");
1175 static char localHostbuf[256];
1176 static int gotLocalHostname;
1181 if (!gotLocalHostname)
1183 XmuGetHostname (localHostbuf, sizeof (localHostbuf) - 1);
1184 gotLocalHostname = 1;
1186 return localHostbuf;