On Sun, 29 Jul 2001, after playing in traffic, nicolas delon yelped:
>
> I wrote a patch that expands the two forms of ~ expansion:
> - ~/ : a simple getenv("HOME")
> - ~jeff/ : a getpwname
>
> and when blackbox rewrites .blackboxrc it takes the '~' form.
> I have coded it with a class, so i have replace the '~'
> expansion old code in Screen.cc by the new code
> (for the menu file).
>
> here is the patch, I have posted it in blackbox.thelinuxcommunity.org
> too.
Hmm... interesting idea with the class and all, and it's more functional
than my old patch. However, I got bored, so I fixed my patch, it can now do
the ~/ and ~<user> expansion, and will rewrite the unexpanded version,
provided that it wasn't changed during operation (styles).
I don't feel the need, but replacing the ~ code in Screen.cc *should* be an
easy task. (*should* as in I haven't read Screen.cc, and don't want to
anyway as it works for me)
(...and I finally fixed my MUA to not encode attachments... only a few code
repairs...)
--gile
--
"i think when somebody goes to a software site and sees TITS, they are
obligated to click" -dingo
--- ../../src/blackbox.cc Sun Jun 25 01:56:48 2000
+++ blackbox.cc Sun Jul 29 01:34:26 2001
@@ -120,6 +120,10 @@
}
#endif // HAVE_BASENAME
+#include <pwd.h>
+
+static char * real_menu_file = NULL;
+static char * real_style_file = NULL;
// X event scanner for enter/leave notifies - adapted from twm
typedef struct scanargs {
@@ -1019,7 +1023,11 @@
load_rc();
- sprintf(rc_string, "session.menuFile: %s", resource.menu_file);
+ if (real_menu_file != NULL) {
+ sprintf(rc_string, "session.menuFile: %s", real_menu_file);
+ } else {
+ sprintf(rc_string, "session.menuFile: %s", resource.menu_file);
+ }
XrmPutLineResource(&new_blackboxrc, rc_string);
sprintf(rc_string, "session.colorsPerChannel: %d",
@@ -1234,6 +1242,68 @@
}
+char * mc_expand (char * str)
+{
+ struct passwd * pw;
+ char * ret;
+ char user[24];
+ int c;
+ int n;
+ if (str[0] != '~')
+ {
+ return bstrdup(str);
+ }
+ if (str[1] != '/')
+ {
+ c = 1;
+ while (str[c] != '/')
+ {
+ user[c - 1] = str[c];
+ c++;
+ }
+ user[c - 1] = '\0';
+ pw = getpwnam(user);
+ } else {
+ c = 1;
+ pw = getpwuid(getuid());
+ }
+ ret = (char *) malloc(strlen(pw->pw_dir) + (strlen(str) - c) + 1);
+ strcpy(ret, pw->pw_dir);
+ n = strlen(ret);
+ while (str[c] != '\0')
+ {
+ ret[n] = str[c];
+ n++;
+ c++;
+ }
+ return ret;
+}
+
+char * set_real_file (char * str, int f)
+{
+ char * tmp;
+ tmp = mc_expand(str);
+ if (!strcmp(str, tmp))
+ {
+ return str;
+ }
+ switch (f)
+ {
+ case 1:
+ real_menu_file = str;
+ break;
+ case 2:
+ real_style_file = str;
+ break;
+ default:
+ real_menu_file = NULL;
+ real_style_file = NULL;
+ break;
+ }
+ return tmp;
+}
+
+
void Blackbox::load_rc(void) {
XrmDatabase database = (XrmDatabase) 0;
@@ -1259,7 +1329,7 @@
if (XrmGetResource(database, "session.menuFile", "Session.MenuFile",
&value_type, &value))
- resource.menu_file = bstrdup(value.addr);
+ resource.menu_file = set_real_file(bstrdup(value.addr), 1);
else
resource.menu_file = bstrdup(DEFAULTMENU);
@@ -1279,7 +1349,7 @@
if (XrmGetResource(database, "session.styleFile", "Session.StyleFile",
&value_type, &value))
- resource.style_file = bstrdup(value.addr);
+ resource.style_file = set_real_file(bstrdup(value.addr), 2);
else
resource.style_file = bstrdup(DEFAULTSTYLE);
@@ -1674,7 +1744,11 @@
} else
dbfile = bstrdup(rc_file);
- sprintf(style, "session.styleFile: %s", resource.style_file);
+ if ((real_style_file != NULL) && (!strcmp(resource.style_file,
+mc_expand(real_style_file)))) {
+ sprintf(style, "session.styleFile: %s", real_style_file);
+ } else {
+ sprintf(style, "session.styleFile: %s", resource.style_file);
+ }
XrmPutLineResource(&new_blackboxrc, style);
XrmDatabase old_blackboxrc = XrmGetFileDatabase(dbfile);