so sorry to send another fix for my patch to mwmparse.y, but i forgot
to care for the case if MWM_DDIR is not defind (for OS/2 ?).
plus, change for MAX_PATH_LEN to be defined as PATH_MAX in <limits.h>.
this is against the original mwmparse.y in 0.93.14.
--- ./mwmparse.y-0.93.14 Fri Aug 3 04:45:28 2001
+++ mwmparse.y Sun Oct 28 09:31:54 2001
@@ -30,24 +30,43 @@
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
+#include <limits.h>
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
+
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
+
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
+
#ifdef HAVE_PWD_H
#include <pwd.h>
#endif
+
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
+
+#ifdef PATH_MAX /* defined in <limits.h> */
+# define MAX_PATH_LEN PATH_MAX
+#else
+# define MAX_PATH_LEN 2048 /* this is OS dependent, but this should catch most */
+#endif
+
+
#include <X11/Xfuncs.h>
+
#ifdef __EMX__
#include <X11/Xlibint.h> /* for __XOS2RedirRoot() */
+# ifdef MWM_DDIR
+# undef MWM_DDIR
+# define MWM_DDIR (char*)__XOS2RedirRoot("/XFree86/lib/X11/mwm")
+# endif
#endif
#include <Xm/Xm.h>
@@ -56,11 +75,6 @@
#include "mwm.h"
-/*
- * this is OS dependent, but this should catch most
- */
-#define MAX_PATH_LEN 2048
-
extern int yydebug;
extern int yylex(void);
@@ -1122,98 +1136,97 @@
/*
* find the config file
*/
+/*
+ * The "Motif User's Guide [1]" didn't mention what to do if; a. configFile
+ * is NOT defined, b. configFile IS defined but it does not refer to a proper file
+ * (mulformed or unreadable), c. configFile does begin with "~" but not "~/".
+ * The code below deals with these cases for conveniences.
+ *
+ * [1]
+(http://w3.pppl.gov/misc/motif/MotifUserGuide/en_US/Understanding_the_Resource_Description_File.html)
+ */
+
static Boolean
-find_config_file2(const char *the_file) {
- if (verbose)
- printf("Checking for config file '%s'\n", the_file);
- if (access(the_file, R_OK) == 0)
- return True;
- return False;
-}
-
-
-static Boolean
-find_config_file3(char *buf, const char *cfile) {
- char *lang, *ptr;
-
- /* Shall overrun check be done for each strcat()??? */
- strcat(buf, "/");
-
- lang = getenv("LANG");
- if (!lang)
- lang = "";
-
- ptr = buf + strlen(buf);
-
- if (strlen(lang) != 0) {
- strcat(buf, lang);
- strcat(buf, "/");
- strcat(buf, cfile);
- if (find_config_file2(buf)) {
- return True;
- }
- }
-
- strcpy(ptr, cfile);
- if (find_config_file2(buf)) {
- return True;
- }
- return False;
-}
-
+find_config_file(char *buf)
+{
+ char *head = NULL;
+ char *middle = NULL;
+ char *ptr;
+ char tmpbuf[MAX_PATH_LEN];
+ struct stat *st;
-static Boolean
-find_config_file(char *buf, const char *cfile) {
- char *home;
+#if defined(HAVE_SYS_TYPES_H) && defined(HAVE_PWD_H)
+ struct passwd *passwd;
+#endif
- home = getenv("HOME");
+ ptr = Mwm.config_file;
- if (!home)
- home = getcwd(NULL, MAX_PATH_LEN);
+ if(strlen(Mwm.config_file) > MAX_PATH_LEN)
+ return False;
- switch (*cfile) {
+ switch (Mwm.config_file[0])
+ {
case '/':
- if (find_config_file2(cfile)) {
- strcpy(buf, cfile);
- return True;
- }
+ head = "";
+ ptr = Mwm.config_file;
break;
case '~':
- if (*(cfile+1) == '/') {
- strcpy(buf, home);
- strcat(buf, "/");
- strcat(buf, cfile+2);
- if (find_config_file2(buf)) {
- return True;
- }
+ ptr++;
+ if (Mwm.config_file[1] == '/')
+ { /* ~ => $HOME */
+ head = getenv("HOME");
+ middle = getenv("LANG");
}
- else {
- /* XXX function not implemented yet */
- if (verbose)
- printf("~user notation is not implemented.\n");
+ else
+#if defined(HAVE_SYS_TYPES_H) && defined(HAVE_PWD_H)
+ { /* ~hoge => hoge's home */
+ int idx;
+
+ idx = strcspn(ptr, "/");
+ if(*(ptr + idx) == '\0')
+ head = NULL;
+ else
+ {
+ strncpy(tmpbuf, ptr, idx);
+ if( (passwd = getpwnam(tmpbuf)) ) {
+ head = strcpy(tmpbuf, passwd->pw_dir);
+ ptr += idx;
+ }
+ else
+ head = NULL; /* no such user "hoge" */
+ }
}
break;
- default: /* check for home dir */
- strcpy(buf, home);
- if (find_config_file3(buf, cfile))
- return True;
- } /* switch (*cfile) */
-
- strcpy(buf, home);
- if (find_config_file3(buf, HOME_MWMRC))
- return True;
-#ifndef __EMX__
- strcpy(buf, MWM_DDIR);
#else
- strcpy(buf, (char*)__XOS2RedirRoot("/XFree86/lib/X11/mwm"));
+ ; /* no <pwd.h>, no ~hoge */
+ head = NULL;
+ break;
#endif
- if (find_config_file3(buf, SYSTEM_MWMRC))
- return True;
- return False;
+ default:
+ /* search for the current dir */
+ head = getcwd(buf, MAX_PATH_LEN);
+ break;
+
+ } /* switch (Mwm.config_file[0]) */
+
+
+ if(!head || strlen(head) + strlen(ptr) > MAX_PATH_LEN)
+ sprintf(buf, "%s/%s", MWM_DDIR, SYSTEM_MWMRC); /* should be ok */
+ else
+ {
+ sprintf(buf, "%s%s", head, ptr);
+ if(middle && strlen(head) + 1 + strlen(middle) + strlen(ptr) <= MAX_PATH_LEN)
+ {
+ sprintf(tmpbuf, "%s%s%s%s", head, "/", middle, ptr);
+ if(stat(tmpbuf, st) == 0)
+ strcpy(buf, tmpbuf);
+ }
+ }
+ return True;
}
+
char
mwm_getc(void) {
char c;
@@ -1300,7 +1313,7 @@
#endif
ptr = Mwm.config_file;
- if (!find_config_file(buf, Mwm.config_file)) {
+ if (!find_config_file(buf)) {
yyerror("Cannot find configuration file. "
"Using builtin defaults.\n");