---
 wmsun/wmgeneral/wmgeneral.c | 200 ++++++++++++++++++++++++++++++++++++--------
 wmsun/wmgeneral/wmgeneral.h |  43 +++++++++-
 2 files changed, 205 insertions(+), 38 deletions(-)

diff --git a/wmsun/wmgeneral/wmgeneral.c b/wmsun/wmgeneral/wmgeneral.c
index a4f13c1..f707e7f 100644
--- a/wmsun/wmgeneral/wmgeneral.c
+++ b/wmsun/wmgeneral/wmgeneral.c
@@ -1,19 +1,56 @@
 /*
-       Best viewed with vim5, using ts=4
-
        wmgeneral was taken from wmppp.
 
        It has a lot of routines which most of the wm* programs use.
 
        ------------------------------------------------------------
 
-       Author: Martijn Pieterse (piete...@xs4all.nl)
+       Copyright (C) 1998 Martijn Pieterse (piete...@xs4all.nl)
+
+       This program is free software; you can redistribute it and/or
+       modify it under the terms of the GNU General Public License
+       as published by the Free Software Foundation; either version 2
+       of the License, or (at your option) any later version.
+
+       This program is distributed in the hope that it will be useful,
+       but WITHOUT ANY WARRANTY; without even the implied warranty of
+       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+       GNU General Public License for more details.
+
+       You should have received a copy of the GNU General Public License
+       along with this program; if not, write to the Free Software
+       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+       02110-1301, USA.
 
        ---
        CHANGES:
        ---
+       10/10/2003 (Simon Law, sfl...@debian.org)
+               * changed the parse_rcfile function to use getline instead of
+                 fgets.
+       10/14/2000 (Chris Gray, cg...@tribsoft.com)
+               * Removed a bug from parse_rcfile.  An extra
+                 newline would cause a segfault.
+       14/09/1998 (Dave Clark, cla...@skyia.com)
+               * Updated createXBMfromXPM routine
+               * Now supports >256 colors
+       11/09/1998 (Martijn Pieterse, piete...@xs4all.nl)
+               * Removed a bug from parse_rcfile. You could
+                 not use "start" in a command if a label was
+                 also start.
+               * Changed the needed geometry string.
+                 We don't use window size, and don't support
+                 negative positions.
+       03/09/1998 (Martijn Pieterse, piete...@xs4all.nl)
+               * Added parse_rcfile2
+       02/09/1998 (Martijn Pieterse, piete...@xs4all.nl)
+               * Added -geometry support (untested)
+       28/08/1998 (Martijn Pieterse, piete...@xs4all.nl)
+               * Added createXBMfromXPM routine
+               * Saves a lot of work with changing xpm's.
        02/05/1998 (Martijn Pieterse, piete...@xs4all.nl)
-               * changed the read_rc_file to parse_rcfile, as suggester by 
Marcelo E. Magallon
+               * changed the read_rc_file to parse_rcfile, as suggested by
+                 Marcelo E. Magallon
                * debugged the parse_rc file.
        30/04/1998 (Martijn Pieterse, piete...@xs4all.nl)
                * Ripped similar code from all the wm* programs,
@@ -21,18 +58,17 @@
 
 */
 
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <ctype.h>
-#include <stdarg.h>
-
-#include <X11/Xlib.h>
-#include <X11/xpm.h>
-#include <X11/extensions/shape.h>
-
+#define _POSIX_C_SOURCE 200809L
 #include "wmgeneral.h"
+#include <X11/Xlib.h>                   /* for XCopyArea, etc */
+#include <X11/Xutil.h>                  /* for XSizeHints, XWMHints, etc */
+#include <X11/extensions/shape.h>       /* for XShapeCombineMask */
+#include <X11/extensions/shapeconst.h>  /* for ShapeBounding, ShapeSet */
+#include <X11/xpm.h>                    /* for XpmAttributes, Pixel, etc */
+#include <stddef.h>                     /* for size_t */
+#include <stdio.h>                      /* for fprintf, stderr, NULL, etc */
+#include <stdlib.h>                     /* for exit, free */
+#include <string.h>                     /* for strcmp, strdup, strcspn, etc */
 
   /*****************/
  /* X11 Variables */
@@ -45,7 +81,6 @@ int                   d_depth;
 XSizeHints     mysizehints;
 XWMHints       mywmhints;
 Pixel          back_pix, fore_pix;
-char           *Geometry = "";
 Window         iconwin, win;
 GC                     NormalGC;
 XpmIcon                wmgen;
@@ -63,7 +98,6 @@ typedef struct {
        int             right;
 } MOUSE_REGION;
 
-#define MAX_MOUSE_REGION (8)
 MOUSE_REGION   mouse_region[MAX_MOUSE_REGION];
 
   /***********************/
@@ -77,27 +111,70 @@ void AddMouseRegion(int, int, int, int, int);
 int CheckMouseRegion(int, int);
 
 
/*******************************************************************************\
-|* read_rc_file                                                                
                                                                   *|
+|* parse_rcfile                                                                
                                                                   *|
 
\*******************************************************************************/
 
 void parse_rcfile(const char *filename, rckeys *keys) {
 
        char    *p;
-       char    temp[128];
-       char    *tokens = " :\t\n";
        FILE    *fp;
-       int             i,key;
 
        fp = fopen(filename, "r");
        if (fp) {
+               char temp[128];
+
                while (fgets(temp, 128, fp)) {
+                       char *q;
+                       char *tokens = " :\t\n";
+                       int key;
+
+                       key = 0;
+                       q = strdup(temp);
+                       q = strtok(q, tokens);
+                       if(!q)
+                               continue;
+                       while (key >= 0 && keys[key].label) {
+                               if ((!strcmp(q, keys[key].label))) {
+                                       int i;
+
+                                       p = strstr(temp, keys[key].label);
+                                       p += strlen(keys[key].label);
+                                       p += strspn(p, tokens);
+                                       if ((i = strcspn(p, "#\n"))) p[i] = 
'\0';
+                                       *keys[key].var = strdup(p);
+                                       key = -1;
+                               } else key++;
+                       }
+               }
+               fclose(fp);
+       }
+}
+
+/*******************************************************************************\
+|* parse_rcfile2                                                               
                                                           *|
+\*******************************************************************************/
+
+void parse_rcfile2(const char *filename, rckeys2 *keys) {
+
+       char    *p;
+       char    *line = NULL;
+       size_t  line_size = 0;
+       FILE    *fp;
+
+       fp = fopen(filename, "r");
+       if (fp) {
+               while (getline(&line, &line_size, fp) >= 0) {
+                       int key;
+
                        key = 0;
                        while (key >= 0 && keys[key].label) {
-                               if ((p = strstr(temp, keys[key].label))) {
+                               if ((p = strstr(line, keys[key].label))) {
+                                       char *tokens = " :\t\n";
+                                       int i;
+
                                        p += strlen(keys[key].label);
                                        p += strspn(p, tokens);
                                        if ((i = strcspn(p, "#\n"))) p[i] = 0;
-                                       free(*keys[key].var);
                                        *keys[key].var = strdup(p);
                                        key = -1;
                                } else key++;
@@ -124,7 +201,7 @@ static void GetXPM(XpmIcon *wmgen, char *pixmap_bytes[]) {
 
        err = XpmCreatePixmapFromData(display, Root, pixmap_bytes, 
&(wmgen->pixmap),
                                        &(wmgen->mask), &(wmgen->attributes));
-       
+
        if (err != XpmSuccess) {
                fprintf(stderr, "Not enough free colorcells.\n");
                exit(1);
@@ -171,9 +248,9 @@ static int flush_expose(Window w) {
 
\*******************************************************************************/
 
 void RedrawWindow(void) {
-       
+
        flush_expose(iconwin);
-       XCopyArea(display, wmgen.pixmap, iconwin, NormalGC, 
+       XCopyArea(display, wmgen.pixmap, iconwin, NormalGC,
                                0,0, wmgen.attributes.width, 
wmgen.attributes.height, 0,0);
        flush_expose(win);
        XCopyArea(display, wmgen.pixmap, win, NormalGC,
@@ -185,9 +262,9 @@ void RedrawWindow(void) {
 
\*******************************************************************************/
 
 void RedrawWindowXY(int x, int y) {
-       
+
        flush_expose(iconwin);
-       XCopyArea(display, wmgen.pixmap, iconwin, NormalGC, 
+       XCopyArea(display, wmgen.pixmap, iconwin, NormalGC,
                                x,y, wmgen.attributes.width, 
wmgen.attributes.height, 0,0);
        flush_expose(win);
        XCopyArea(display, wmgen.pixmap, win, NormalGC,
@@ -233,6 +310,55 @@ int CheckMouseRegion(int x, int y) {
 }
 
 
/*******************************************************************************\
+|* createXBMfromXPM                                                            
                                                           *|
+\*******************************************************************************/
+void createXBMfromXPM(char *xbm, char **xpm, int sx, int sy) {
+
+       int     i,j,k;
+       int     width, height, numcol, depth;
+       int     zero=0;
+       int     curpixel;
+
+       sscanf(*xpm, "%10d %10d %10d %10d", &width, &height, &numcol, &depth);
+
+
+       for (k=0; k!=depth; k++)
+       {
+               zero <<=8;
+               zero |= xpm[1][k];
+       }
+
+       for (i=numcol+1; i < numcol+sy+1; i++) {
+               unsigned char bwrite;
+               int bcount;
+
+               bcount = 0;
+               bwrite = 0;
+               for (j=0; j<sx*depth; j+=depth) {
+                       bwrite >>= 1;
+
+                       curpixel=0;
+                       for (k=0; k!=depth; k++)
+                       {
+                               curpixel <<=8;
+                               curpixel |= xpm[i][j+k];
+                       }
+
+                       if ( curpixel != zero ) {
+                               bwrite += 128;
+                       }
+                       bcount++;
+                       if (bcount == 8) {
+                               *xbm = bwrite;
+                               xbm++;
+                               bcount = 0;
+                               bwrite = 0;
+                       }
+               }
+       }
+}
+
+/*******************************************************************************\
 |* copyXPMArea                                                                 
                                                           *|
 
\*******************************************************************************/
 
@@ -276,17 +402,20 @@ void openXwindow(int argc, char *argv[], char 
*pixmap_bytes[], char *pixmask_bit
        XGCValues               gcv;
        unsigned long   gcm;
 
+       char                    *geometry = NULL;
 
        int                             dummy=0;
        int                             i;
 
        for (i=1; argv[i]; i++) {
-               if (!strcmp(argv[i], "-display")) 
-                       display_name = argv[i+1];
+               if (!strcmp(argv[i], "-display"))
+                       display_name = argv[++i];
+               else if (!strcmp(argv[i], "-geometry"))
+                       geometry = argv[++i];
        }
 
        if (!(display = XOpenDisplay(display_name))) {
-               fprintf(stderr, "%s: can't open display %s\n", 
+               fprintf(stderr, "%s: can't open display %s\n",
                                                wname, 
XDisplayName(display_name));
                exit(1);
        }
@@ -306,15 +435,15 @@ void openXwindow(int argc, char *argv[], char 
*pixmap_bytes[], char *pixmask_bit
        back_pix = GetColor("white");
        fore_pix = GetColor("black");
 
-       XWMGeometry(display, screen, Geometry, NULL, borderwidth, &mysizehints,
+       XWMGeometry(display, screen, geometry, NULL, borderwidth, &mysizehints,
                                &mysizehints.x, 
&mysizehints.y,&mysizehints.width,&mysizehints.height, &dummy);
 
        mysizehints.width = 64;
        mysizehints.height = 64;
-               
+
        win = XCreateSimpleWindow(display, Root, mysizehints.x, mysizehints.y,
                                mysizehints.width, mysizehints.height, 
borderwidth, fore_pix, back_pix);
-       
+
        iconwin = XCreateSimpleWindow(display, win, mysizehints.x, 
mysizehints.y,
                                mysizehints.width, mysizehints.height, 
borderwidth, fore_pix, back_pix);
 
@@ -335,7 +464,7 @@ void openXwindow(int argc, char *argv[], char 
*pixmap_bytes[], char *pixmask_bit
        XSetWMName(display, win, &name);
 
        /* Create GC for drawing */
-       
+
        gcm = GCForeground | GCBackground | GCGraphicsExposures;
        gcv.foreground = fore_pix;
        gcv.background = back_pix;
@@ -362,5 +491,4 @@ void openXwindow(int argc, char *argv[], char 
*pixmap_bytes[], char *pixmask_bit
 
        XSetCommand(display, win, argv, argc);
        XMapWindow(display, win);
-
 }
diff --git a/wmsun/wmgeneral/wmgeneral.h b/wmsun/wmgeneral/wmgeneral.h
index 55b37dd..c3454c5 100644
--- a/wmsun/wmgeneral/wmgeneral.h
+++ b/wmsun/wmgeneral/wmgeneral.h
@@ -1,23 +1,61 @@
+/*
+       wmgeneral was taken from wmppp.
+
+       It has a lot of routines which most of the wm* programs use.
+
+       ------------------------------------------------------------
+
+       Copyright (C) 1998 Martijn Pieterse (piete...@xs4all.nl)
+
+       This program is free software; you can redistribute it and/or
+       modify it under the terms of the GNU General Public License
+       as published by the Free Software Foundation; either version 2
+       of the License, or (at your option) any later version.
+
+       This program is distributed in the hope that it will be useful,
+       but WITHOUT ANY WARRANTY; without even the implied warranty of
+       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+       GNU General Public License for more details.
+
+       You should have received a copy of the GNU General Public License
+       along with this program; if not, write to the Free Software
+       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+       02110-1301, USA.
+
+*/
+
 #ifndef WMGENERAL_H_INCLUDED
 #define WMGENERAL_H_INCLUDED
 
+#include <X11/X.h>                      /* for Pixmap */
+#include <X11/Xlib.h>                   /* for Display */
+#include <X11/xpm.h>                    /* for XpmAttributes */
+
   /***********/
  /* Defines */
 /***********/
 
-#define MAX_MOUSE_REGION (8)
+#define MAX_MOUSE_REGION (16)
 
   /************/
  /* Typedefs */
 /************/
 
+struct _rckeys {
+       const char      *label;
+       char            **var;
+};
+
 typedef struct _rckeys rckeys;
 
-struct _rckeys {
+struct _rckeys2 {
+       const char      *family;
        const char      *label;
        char            **var;
 };
 
+typedef struct _rckeys2 rckeys2;
+
 typedef struct {
        Pixmap                  pixmap;
        Pixmap                  mask;
@@ -41,6 +79,7 @@ void openXwindow(int argc, char *argv[], char **, char *, 
int, int);
 void RedrawWindow(void);
 void RedrawWindowXY(int x, int y);
 
+void createXBMfromXPM(char *, char **, int, int);
 void copyXPMArea(int, int, int, int, int, int);
 void copyXBMArea(int, int, int, int, int, int);
 void setMaskXY(int, int);
-- 
2.1.4


-- 
To unsubscribe, send mail to wmaker-dev-unsubscr...@lists.windowmaker.org.

Reply via email to