I've long been frustrated that twm has no option for preprocessing
config files, so as to allow includes, automatic variations based on
location, and such. At one time, I thought it would make sense to use
the C preprocessor, but I've come up with a much simpler solution: If
the config file is executable, run it and use the output instead of
using the file itself. This allows users to generate their config files
using whatever dynamic methods they like without any impact on existing
configurations.
I've attached a patch. I tried to keep the patch consistent in
programming style. I did not update any documentation or make this a
configuration option, as I'm not up to speed on autoconf, though the
ability to use popen() probably should be checked in the configuration
script.
--- twm-1.0.6/src/parse.c 2010-10-06 23:33:57.000000000 -0400
+++ twm-1.0.6-pc/src/parse.c 2011-06-07 13:20:29.000009000 -0400
@@ -59,6 +59,9 @@
***********************************************************************/
#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
#include <X11/Xos.h>
#include <X11/Xmu/CharSet.h>
#include "twm.h"
@@ -162,6 +165,7 @@
int homelen = 0;
char *cp = NULL;
char tmpfilename[257];
+ int using_pipe = 0;
/*
* If filename given, try it, else try ~/.twmrc.# then ~/.twmrc. Then
@@ -197,7 +201,18 @@
break;
}
- if (cp) twmrc = fopen (cp, "r");
+ if (cp) {
+ struct stat buf;
+ if (stat(cp,&buf) < 0 ) {
+ buf.st_mode = 0; /* Don't use garbage */
+ }
+ if (buf.st_mode & S_IXUSR) {
+ twmrc = popen (cp, "r");
+ using_pipe = 1;
+ } else {
+ twmrc = fopen (cp, "r");
+ }
+ }
}
if (twmrc) {
@@ -209,12 +224,20 @@
ProgramName, filename, cp);
}
status = doparse (twmFileInput, "file", cp);
- fclose (twmrc);
+ if ( using_pipe ) {
+ pclose (twmrc);
+ } else {
+ fclose (twmrc);
+ }
return status;
} else {
- if (filename) {
+ if ( using_pipe && filename ) {
+ fprintf (stderr,
+ "%s: unable to execute twmrc file %s, using built-in defaults instead\n",
+ ProgramName, filename);
+ } else if (filename) {
fprintf (stderr,
- "%s: unable to open twmrc file %s, using built-in defaults instead\n",
+ "%s: unable to open twmrc file %s, using built-in defaults instead\n",
ProgramName, filename);
}
return ParseStringList (defTwmrc);
_______________________________________________
[email protected]: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel