diff options
author | Matthieu Herrb <matthieu@cvs.openbsd.org> | 2006-11-26 10:53:58 +0000 |
---|---|---|
committer | Matthieu Herrb <matthieu@cvs.openbsd.org> | 2006-11-26 10:53:58 +0000 |
commit | 1cb4778bcef21ea9015cfccdb99abb7a0e035d74 (patch) | |
tree | f164009397f9d3d5634c6f8a94b1542f793d9692 /app/fvwm/modules/FvwmM4 | |
parent | 841f8331c93ff96bd798e9a74ba10fab155da5c5 (diff) |
Importing from XF4, plus BSD make infrastructure
Diffstat (limited to 'app/fvwm/modules/FvwmM4')
-rw-r--r-- | app/fvwm/modules/FvwmM4/FvwmM4.1 | 155 | ||||
-rw-r--r-- | app/fvwm/modules/FvwmM4/FvwmM4.c | 471 | ||||
-rw-r--r-- | app/fvwm/modules/FvwmM4/FvwmM4.h | 12 | ||||
-rw-r--r-- | app/fvwm/modules/FvwmM4/Imakefile | 11 | ||||
-rw-r--r-- | app/fvwm/modules/FvwmM4/Makefile | 17 |
5 files changed, 666 insertions, 0 deletions
diff --git a/app/fvwm/modules/FvwmM4/FvwmM4.1 b/app/fvwm/modules/FvwmM4/FvwmM4.1 new file mode 100644 index 000000000..eda325e10 --- /dev/null +++ b/app/fvwm/modules/FvwmM4/FvwmM4.1 @@ -0,0 +1,155 @@ +.\" $OpenBSD: FvwmM4.1,v 1.1.1.1 2006/11/26 10:53:52 matthieu Exp $ +.\" t +.\" @(#)FvwmM4.1 1/28/94 +.de EX \"Begin example +.ne 5 +.if n .sp 1 +.if t .sp .5 +.nf +.in +.5i +.. +.de EE +.fi +.in -.5i +.if n .sp 1 +.if t .sp .5 +.. +.TH FvwmM4 1 12/12/94 2.0 +.UC +.SH NAME +FvwmM4 \- the FVWM M4 pre-processor +.SH SYNOPSIS +FvwmM4 is spawned by fvwm, so no command line invocation will work. + +.SH DESCRIPTION +When called, this module will attempt to have M4 pre-process the file +specified in its invocation, and then have fvwm read the resulting file. + +.SH INVOCATION +FvwmM4 can be invoked by inserting the line 'FvwmM4' in +the .fvwmrc file. It can also be called from a menu or mouse binding. +If the user wants his entire .fvwmrc file pre-processed with FvwmM4, +then fvwm should be invoked as: + +.EX +fvwm2 -cmd "FvwmM4 .fvwmrc" +.EE + +Note that the argument to the option "-cmd" should be enclosed +in quotes, and no other quoting should be used. For example, a +typical invocation might be: + +.EX +fvwm2 -cmd "FvwmM4 -m4-squote { -m4-equote } .fvwmrc" +.EE + +Some options can be specified on the command line: +.IP -m4-prefix +I think this makes all the m4 directives require the prefix "m4_". + +.TP +-m4opt \fIoption\fP +Lets you pass an option to the m4 program. Not really needed as any +unknown options will be passed on automatically. + +.TP +-m4-squote \fIcharacter\fP +Lets you change the m4 start-of-quote character to \fIcharacter\fP. + +.TP +-m4-equote \fIcharacter\fP +Lets you change the m4 end-of-quote character to \fIcharacter\fP. + +.TP +-m4prog \fIname\fP +Instead of invoking "m4", fvwm will invoke \fIname\fP. + +.TP +-outfile \fIfilename\fP +Instead of creating a random unique name for the temporary file for +the preprocessed rc file, this option will let you specify the name of +the temporary file it will create. + +.IP -debug +Causes the temporary file create by m4 to +be retained. This file is usually called "/tmp/fvwmrcXXXXXXXXXX" + + +.SH CONFIGURATION OPTIONS +FvwmM4 defines some values for use in the pre-processor file: + +.IP TWM_TYPE +Always set to "fvwm". +.IP SERVERHOST +The name of the machine running the X Server. +.IP CLIENTHOST +The name of the machine running fvwm. +.IP HOSTNAME +The hostname of the machine running fvwm. Generally the same as CLIENTHOST. +.IP OSTYPE +The operating system for CLIENTHOST. +.IP USER +The name of the person running fvwm. +.IP VERSION +The X11 version. +.IP REVISION +The X11 revision number. +.IP VENDOR +The X server vendor. +.IP RELEASE +The X server release number. +.IP WIDTH +The screen width in pixels. +.IP HEIGHT +The screen height in pixels. +.IP X_RESOLUTION +Some distance/pixel measurement for the horizontal direction, I think. +.IP Y_RESOLUTION +Some distance/pixel measurement for the vertical direction, I think. +.IP PLANES +Number of color planes for the X server display +.IP BITS_PER_RGB +Number of bits in each rgb triplet. +.IP CLASS +The X11 visual class, ie PsuedoColor. +.IP COLOR +Yes or No, Yes if the display class is neither StaticGrey or GreyScale. +.IP FVWM_VERSION +The fvwm version number, ie 2.0 +.IP OPTIONS +Some combination of SHAPE, XPM, NO_SAVEUNDERS, and M4, as defined in +configure.h at compile time. +.IP FVWM_MODULEDIR +The directory where fvwm looks for .fvwmrc and modules by default, as +determined at compile time. + +.SH EXAMPLE PROLOG + +.EX +define(TWM_TYPE,``fvwm'')dnl +define(SERVERHOST,``spx20'')dnl +define(CLIENTHOST,``grumpy'')dnl +define(HOSTNAME,``grumpy'')dnl +define(OSTYPE,``SunOS'')dnl +define(USER,``nation'')dnl +define(HOME,``/local/homes/dsp/nation'')dnl +define(VERSION,``11'')dnl +define(REVISION,``0'')dnl +define(VENDOR,``HDS human designed systems, inc. (2.1.2-D)'')dnl +define(RELEASE,``4'')dnl +define(WIDTH,``1280'')dnl +define(HEIGHT,``1024'')dnl +define(X_RESOLUTION,``3938'')dnl +define(Y_RESOLUTION,``3938'')dnl +define(PLANES,``8'')dnl +define(BITS_PER_RGB,``8'')dnl +define(CLASS,``PseudoColor'')dnl +define(COLOR,``Yes'')dnl +define(FVWM_VERSION,``1.24l'')dnl +define(OPTIONS,``SHAPE XPM M4 '')dnl +define(FVWM_MODULEDIR,``/local/homes/dsp/nation/modules'')dnl +.EE + +.SH AUTHOR +FvwmM4 is the result of a random bit mutation on a hard disk, +presumably a result of a cosmic-ray or some such thing. diff --git a/app/fvwm/modules/FvwmM4/FvwmM4.c b/app/fvwm/modules/FvwmM4/FvwmM4.c new file mode 100644 index 000000000..474fd41a7 --- /dev/null +++ b/app/fvwm/modules/FvwmM4/FvwmM4.c @@ -0,0 +1,471 @@ +/* This module, and the entire FvwmM4 program, and the concept for + * interfacing this module to the Window Manager, are all original work + * by Robert Nation + * + * Copyright 1994, Robert Nation + * No guarantees or warantees or anything + * are provided or implied in any way whatsoever. Use this program at your + * own risk. Permission to use this program for any purpose is given, + * as long as the copyright is kept intact. */ + +#define TRUE 1 +#define FALSE 0 + +#include "config.h" + +#include <stdio.h> +#include <signal.h> +#include <fcntl.h> +#include <string.h> +#include <sys/wait.h> +#include <sys/time.h> +#include <unistd.h> +#include <ctype.h> +#include <stdlib.h> +#include <pwd.h> +#include <sys/param.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <netdb.h> + +#include <X11/Xlib.h> +#include <X11/Xutil.h> +#include <X11/Xproto.h> +#include <X11/Xatom.h> +#include <X11/Intrinsic.h> + +#include "../../fvwm/module.h" + +#include "FvwmM4.h" +#include "../../libs/fvwmlib.h" +#include <X11/StringDefs.h> +#include <X11/Shell.h> +#define Resolution(pixels, mm) ((((pixels) * 100000 / (mm)) + 50) / 100) + +char *MyName; +int fd[2]; + +int ScreenWidth, ScreenHeight; +int Mscreen; + +long Vx, Vy; +static char *MkDef(char *name, char *def); +static char *MkNum(char *name,int def); +static char *m4_defs(Display *display, const char *host, char *m4_options, char *config_file); +#define MAXHOSTNAME 255 +#define EXTRA 50 + +int m4_enable; /* use m4? */ +int m4_prefix; /* Do GNU m4 prefixing (-P) */ +char m4_options[BUFSIZ]; /* Command line options to m4 */ +char m4_outfile[BUFSIZ] = ""; /* The output filename for m4 */ +char *m4_prog = "m4"; /* Name of the m4 program */ +int m4_default_quotes; /* Use default m4 quotes */ +char *m4_startquote = "`"; /* Left quote characters for m4 */ +char *m4_endquote = "'"; /* Right quote characters for m4 */ + +/*********************************************************************** + * + * Procedure: + + * main - start of module + * + ***********************************************************************/ +int main(int argc, char **argv) +{ + Display *dpy; /* which display are we talking to */ + char *temp, *s; + char *display_name = NULL; + char *filename = NULL; + char *tmp_file, read_string[80],delete_string[80]; + int i,m4_debug = 0; + + m4_enable = TRUE; + m4_prefix = FALSE; + strcpy(m4_options,""); + m4_default_quotes = 1; + + /* Record the program name for error messages */ + temp = argv[0]; + + s=strrchr(argv[0], '/'); + if (s != NULL) + temp = s + 1; + + MyName = safemalloc(strlen(temp)+2); + strcpy(MyName,"*"); + strcat(MyName, temp); + + if(argc < 6) + { + fprintf(stderr,"%s Version %s should only be executed by fvwm!\n",MyName, + VERSION); + fprintf(stderr,"Wanted argc == 6. Got %d\n",argc); + exit(1); + } + + /* Open the X display */ + if (!(dpy = XOpenDisplay(display_name))) + { + fprintf(stderr,"%s: can't open display %s", MyName, + XDisplayName(display_name)); + exit (1); + } + + + Mscreen= DefaultScreen(dpy); + ScreenHeight = DisplayHeight(dpy,Mscreen); + ScreenWidth = DisplayWidth(dpy,Mscreen); + + /* We should exit if our fvwm pipes die */ + signal (SIGPIPE, DeadPipe); + + fd[0] = atoi(argv[1]); + fd[1] = atoi(argv[2]); + + for(i=6;i<argc;i++) + { + if(strcasecmp(argv[i],"-m4-prefix") == 0) + { + m4_prefix = TRUE; + } + else if(strcasecmp(argv[i],"-m4opt") == 0) + { + /* leaving this in just in case-- any option starting with '-' + will get passed on to m4 anyway */ + strlcat(m4_options, argv[++i],sizeof(m4_options)); + strlcat(m4_options, " ", sizeof(m4_options)); + } + else if(strcasecmp(argv[i],"-m4-squote") == 0) + { + m4_startquote = argv[++i]; + m4_default_quotes = 0; + } + else if(strcasecmp(argv[i],"-m4-equote") == 0) + { + m4_endquote = argv[++i]; + m4_default_quotes = 0; + } + else if (strcasecmp(argv[i], "-m4prog") == 0) + { + m4_prog = argv[++i]; + } + else if(strcasecmp(argv[i], "-outfile") == 0) + { + strlcpy(m4_outfile,argv[++i],sizeof(m4_outfile)); + } + else if(strcasecmp(argv[i], "-debug") == 0) + { + m4_debug = 1; + } + else if (strncasecmp(argv[i],"-",1) == 0) + { + /* pass on any other arguments starting with '-' to m4 */ + strlcat(m4_options, argv[i],sizeof(m4_options)); + strlcat(m4_options, " ",sizeof(m4_options)); + } + else + filename = argv[i]; + } + + for(i=0;i<strlen(filename);i++) + if((filename[i] == '\n')||(filename[i] == '\r')) + { + filename[i] = 0; + } + + if (!(dpy = XOpenDisplay(display_name))) + { + fprintf(stderr,"FvwmM4: can't open display %s", + XDisplayName(display_name)); + exit (1); + } + + tmp_file = m4_defs(dpy, display_name,m4_options, filename); + + snprintf(read_string,sizeof(read_string),"read %s\n",tmp_file); + SendInfo(fd,read_string,0); + + /* For a debugging version, we may wish to omit this part. */ + /* I'll let some m4 advocates clean this up */ + if(!m4_debug) + { + snprintf(delete_string,sizeof(delete_string),"exec rm %s\n",tmp_file); + SendInfo(fd,delete_string,0); + } + return 0; +} + + + + +static char *m4_defs(Display *display, const char *host, char *m4_options, char *config_file) +{ + Screen *screen; + Visual *visual; + char client[MAXHOSTNAME], server[MAXHOSTNAME], *colon; + char ostype[BUFSIZ]; + char options[BUFSIZ]; + static char tmp_name[BUFSIZ]; + struct hostent *hostname; + char *vc; /* Visual Class */ + FILE *tmpf; + int fd; + struct passwd *pwent; + /* Generate a temporary filename. Honor the TMPDIR environment variable, + if set. Hope nobody deletes this file! */ + + if (strlen(m4_outfile) == 0) { + if ((vc=getenv("TMPDIR"))) { + strlcpy(tmp_name, vc, sizeof(tmp_name)); + } else { + strlcpy(tmp_name, "/tmp",sizeof(tmp_name)); + } + strlcat(tmp_name, "/fvwmrcXXXXXXXXXX",sizeof(tmp_name)); + mktemp(tmp_name); + } else { + strlcpy(tmp_name,m4_outfile,sizeof(tmp_name)); + } + + if (*tmp_name == '\0') + { + perror("mktemp failed in m4_defs"); + exit(0377); + } + + /* + ** check to make sure it doesn't exist already, to prevent security hole + */ + if ((fd = open(tmp_name, O_WRONLY|O_EXCL|O_CREAT, 0600)) < 0) + { + perror("exclusive open for output file failed in m4_defs"); + exit(0377); + } + close(fd); + + /* + * Create the appropriate command line to run m4, and + * open a pipe to the command. + */ + + if(m4_prefix) + sprintf(options, "%s --prefix-builtins %s > %s\n", + m4_prog, + m4_options, tmp_name); + else + sprintf(options, "%s %s > %s\n", + m4_prog, + m4_options, tmp_name); + tmpf = popen(options, "w"); + if (tmpf == NULL) { + perror("Cannot open pipe to m4"); + exit(0377); + } + + gethostname(client,MAXHOSTNAME); + + getostype (ostype, sizeof ostype); + + /* Change the quoting characters, if specified */ + + if (!m4_default_quotes) + { + fprintf(tmpf, "%schangequote(%s, %s)%sdnl\n", + (m4_prefix) ? "m4_" : "", + m4_startquote, m4_endquote, + (m4_prefix) ? "m4_" : ""); + } + + hostname = gethostbyname(client); + strlcpy(server, XDisplayName(host),sizeof(server)); + colon = strchr(server, ':'); + if (colon != NULL) *colon = '\0'; + if ((server[0] == '\0') || (!strcmp(server, "unix"))) + strlcpy(server, client, sizeof(server)); /* must be connected to :0 or unix:0 */ + + /* TWM_TYPE is fvwm, for completeness */ + + fputs(MkDef("TWM_TYPE", "fvwm"), tmpf); + + /* The machine running the X server */ + fputs(MkDef("SERVERHOST", server), tmpf); + /* The machine running the window manager process */ + fputs(MkDef("CLIENTHOST", client), tmpf); + if (hostname) + fputs(MkDef("HOSTNAME", (char *)hostname->h_name), tmpf); + else + fputs(MkDef("HOSTNAME", (char *)client), tmpf); + + fputs(MkDef("OSTYPE", ostype), tmpf); + + pwent=getpwuid(geteuid()); + fputs(MkDef("USER", pwent->pw_name), tmpf); + + fputs(MkDef("HOME", getenv("HOME")), tmpf); + fputs(MkNum("VERSION", ProtocolVersion(display)), tmpf); + fputs(MkNum("REVISION", ProtocolRevision(display)), tmpf); + fputs(MkDef("VENDOR", ServerVendor(display)), tmpf); + fputs(MkNum("RELEASE", VendorRelease(display)), tmpf); + screen = ScreenOfDisplay(display, Mscreen); + visual = DefaultVisualOfScreen(screen); + fputs(MkNum("WIDTH", DisplayWidth(display,Mscreen)), tmpf); + fputs(MkNum("HEIGHT", DisplayHeight(display,Mscreen)), tmpf); + + fputs(MkNum("X_RESOLUTION",Resolution(screen->width,screen->mwidth)),tmpf); + fputs(MkNum("Y_RESOLUTION",Resolution(screen->height,screen->mheight)),tmpf); + fputs(MkNum("PLANES",DisplayPlanes(display, Mscreen)), tmpf); + + fputs(MkNum("BITS_PER_RGB", visual->bits_per_rgb), tmpf); + fputs(MkNum("SCREEN", Mscreen), tmpf); + + switch(visual->class) + { + case(StaticGray): + vc = "StaticGray"; + break; + case(GrayScale): + vc = "GrayScale"; + break; + case(StaticColor): + vc = "StaticColor"; + break; + case(PseudoColor): + vc = "PseudoColor"; + break; + case(TrueColor): + vc = "TrueColor"; + break; + case(DirectColor): + vc = "DirectColor"; + break; + default: + vc = "NonStandard"; + break; + } + + fputs(MkDef("CLASS", vc), tmpf); + if (visual->class != StaticGray && visual->class != GrayScale) + fputs(MkDef("COLOR", "Yes"), tmpf); + else + fputs(MkDef("COLOR", "No"), tmpf); + fputs(MkDef("FVWM_VERSION", VERSION), tmpf); + + /* Add options together */ + *options = '\0'; +#ifdef SHAPE + strcat(options, "SHAPE "); +#endif +#ifdef XPM + strcat(options, "XPM "); +#endif + + strcat(options, "M4 "); + +#ifdef NO_SAVEUNDERS + strcat(options, "NO_SAVEUNDERS "); +#endif + + fputs(MkDef("OPTIONS", options), tmpf); + + fputs(MkDef("FVWM_MODULEDIR", FVWM_MODULEDIR), tmpf); + fputs(MkDef("FVWM_CONFIGDIR", FVWM_CONFIGDIR), tmpf); + + /* + * At this point, we've sent the definitions to m4. Just include + * the fvwmrc file now. + */ + + fprintf(tmpf, "%sinclude(%s%s%s)\n", + (m4_prefix) ? "m4_": "", + m4_startquote, + config_file, + m4_endquote); + + pclose(tmpf); + return(tmp_name); +} + + + + + +/*********************************************************************** + * + * Procedure: + * SIGPIPE handler - SIGPIPE means fvwm is dying + * + ***********************************************************************/ +void DeadPipe(int nonsense) +{ + exit(0); +} + + + +static char *MkDef(char *name, char *def) +{ + static char *cp = NULL; + static int maxsize = 0; + int n; + + /* The char * storage only lasts for 1 call... */ + + /* Get space to hold everything, if needed */ + + n = EXTRA + strlen(name) + strlen(def); + if (n > maxsize) { + maxsize = n; + if (cp == NULL) { + cp = malloc(n); + } else { + cp = realloc(cp, n); + } + } + + if (cp == NULL) { + perror("MkDef can't allocate enough space for a macro definition"); + exit(0377); + } + + /* Create the macro definition, using the appropriate prefix, if any */ + + if (m4_prefix) + { + strcpy(cp, "m4_define("); + } + else + strcpy(cp, "define("); + + strcat(cp, name); + + /* Tack on "," and 2 sets of starting quotes */ + strcat(cp, ","); + strcat(cp, m4_startquote); + strcat(cp, m4_startquote); + + /* The definition itself */ + strcat(cp, def); + + /* Add 2 sets of closing quotes */ + strcat(cp, m4_endquote); + strcat(cp, m4_endquote); + + /* End the definition, appropriately */ + strcat(cp, ")"); + if (m4_prefix) + { + strcat(cp, "m4_"); + } + + strcat(cp, "dnl\n"); + + return(cp); +} + +static char *MkNum(char *name,int def) +{ + char num[20]; + + sprintf(num, "%d", def); + return(MkDef(name, num)); +} diff --git a/app/fvwm/modules/FvwmM4/FvwmM4.h b/app/fvwm/modules/FvwmM4/FvwmM4.h new file mode 100644 index 000000000..26c263163 --- /dev/null +++ b/app/fvwm/modules/FvwmM4/FvwmM4.h @@ -0,0 +1,12 @@ +#include "fvwmlib.h" + +/************************************************************************* + * + * Subroutine Prototypes + * + *************************************************************************/ +void DeadPipe(int nonsense); + + + + diff --git a/app/fvwm/modules/FvwmM4/Imakefile b/app/fvwm/modules/FvwmM4/Imakefile new file mode 100644 index 000000000..0412a8769 --- /dev/null +++ b/app/fvwm/modules/FvwmM4/Imakefile @@ -0,0 +1,11 @@ +# $OpenBSD: Imakefile,v 1.1.1.1 2006/11/26 10:53:52 matthieu Exp $ + +FVWMTOP=../.. +#include "../../Fvwm.tmpl" + +FvwmSimpleModuleTarget(FvwmM4) + +PATH_DEFINES= -DFVWM_MODULEDIR=\"$(FVWMLIBDIR)\" \ + -DFVWM_CONFIGDIR=\"$(FVWMLIBDIR)\" \ + +SpecialObjectRule(FvwmM4.o, FvwmM4.c, $(PATH_DEFINES)) diff --git a/app/fvwm/modules/FvwmM4/Makefile b/app/fvwm/modules/FvwmM4/Makefile new file mode 100644 index 000000000..20055037d --- /dev/null +++ b/app/fvwm/modules/FvwmM4/Makefile @@ -0,0 +1,17 @@ +# $Xenocara: Makefile,v 1.1 2006/04/17 20:16:24 matthieu Exp $ + +.include "../Makefile.inc" + +.PATH: ${DIST}/modules/FvwmM4 + +PROG= FvwmM4 +SRCS= FvwmM4.c + +CPPFLAGS+= -DFVWM_MODULEDIR=\"$(FVWMLIBDIR)\" \ + -DFVWM_CONFIGDIR=\"$(FVWMLIBDIR)\" \ + +LDADD+= -lX11 +BINDIR= ${FVWMLIBDIR} + +.include <bsd.prog.mk> +.include <bsd.xorg.mk> |