[hackers] [wmii] Write /ctl before the second sourcing of rc.wmii.local

From: Kris Maglione <jg_AT_suckless.org>
Date: Sat Mar 31 23:23:16 2007

changeset: 2052:7bc9a58ae0a4
tag: tip
user: Kris Maglione <jg_AT_suckless.org>
date: Sat Mar 31 17:22:30 2007 -0400
summary: Write /ctl before the second sourcing of rc.wmii.local

diff -r c5aa6015b0f1 -r 7bc9a58ae0a4 cmd/wmii/draw.c
--- a/cmd/wmii/draw.c Sat Mar 31 00:19:12 2007 -0400
+++ b/cmd/wmii/draw.c Sat Mar 31 17:22:30 2007 -0400
@@ -1,6 +1,7 @@
 /* Copyright ©2004-2006 Anselm R. Garbe <garbeam at gmail dot com>
  * See LICENSE file for license details.
  */
+#include <ctype.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
@@ -34,12 +35,9 @@ loadfont(Blitz *blitz, BlitzFont *font)
         font->set = XCreateFontSet(blitz->dpy, fontname, &missing, &n, &def);
         if(missing) {
                 fprintf(stderr, "%s: missing fontset%s for '%s':", argv0,
- n > 1 ? "s": "",
- fontname);
+ (n > 1 ? "s":""), fontname);
                 for(i = 0; i < n; i++)
- fprintf(stderr, "%s %s",
- i ? ",": "",
- missing[i]);
+ fprintf(stderr, "%s %s", (i ? ",":""), missing[i]);
                 fprintf(stderr, "\n");
                 XFreeStringList(missing);
         }
@@ -59,10 +57,10 @@ loadfont(Blitz *blitz, BlitzFont *font)
                         XFreeFont(blitz->dpy, font->xfont);
                 font->xfont = nil;
                 font->xfont = XLoadQueryFont(blitz->dpy, fontname);
- if (!font->xfont) {
- if(!strncmp(fontname, BLITZ_FONT, sizeof(BLITZ_FONT)))
- fatal("cannot load font: %s",
- BLITZ_FONT);
+ fprintf(stderr, "%s: cannot load font: %s\n", argv0, fontname);
+ if(!font->xfont) {
+ if(!strcmp(fontname, BLITZ_FONT))
+ fatal("cannot load font: %s", BLITZ_FONT);
                         free(font->fontstr);
                         font->fontstr = estrdup(BLITZ_FONT);
                         loadfont(blitz, font);
@@ -129,9 +127,8 @@ draw_label(BlitzBrush *b, char *text) {
                         buf[len - 1] = '.';
         }
 
- if(b->font->set) {
+ if(b->font->set)
                 XmbTextExtents(b->font->set, text, len, &r, nil);
- }
 
         switch (b->align) {
         case EAST:
@@ -219,15 +216,24 @@ loadcolor(Blitz *blitz, BlitzColor *c) {
 
 char *
 parse_colors(char **buf, int *buflen, BlitzColor *col) {
- uint i;
- if(*buflen < 23 || 3 != sscanf(*buf, "#%06x #%06x #%06x", &i,&i,&i))
+ static regex_t reg;
+ static Bool compiled;
+
+ if(!compiled) {
+ compiled = 1;
+ regcomp(&reg, "^#[0-9a-f]{6} #[0-9a-f]{6} #[0-9a-f]{6}",
+ REG_EXTENDED|REG_NOSUB|REG_ICASE);
+ }
+
+ if(*buflen < 23 || regexec(&reg, *buf, 0, 0, 0))
                 return "bad value";
- (*buflen) -= 23;
- bcopy(*buf, col->colstr, 23);
+
+ memcpy(col->colstr, *buf, 23);
         loadcolor(&blz, col);
 
- (*buf) += 23;
- if(**buf == '\n' || **buf == ' ') {
+ *buf += 23;
+ *buflen -= 23;
+ if(isspace(**buf)) {
                 (*buf)++;
                 (*buflen)--;
         }
diff -r c5aa6015b0f1 -r 7bc9a58ae0a4 cmd/wmii/rule.c
--- a/cmd/wmii/rule.c Sat Mar 31 00:19:12 2007 -0400
+++ b/cmd/wmii/rule.c Sat Mar 31 17:22:30 2007 -0400
@@ -3,6 +3,7 @@
  * See LICENSE file for license details.
  */
 
+#include <assert.h>
 #include <string.h>
 #include <stdlib.h>
 #include <util.h>
@@ -33,9 +34,11 @@ trim(char *str, const char *chars) {
 
 void
 update_rules(Rule **rule, const char *data) {
- int mode = IGNORE;
+ int state = IGNORE;
         Rule *rul;
- char *p, *r = nil, *v = nil, regex[256], value[256];
+ char regex[256], value[256];
+ char *r, *v;
+ const char *p;
 
         if(!data || !strlen(data))
                 return;
@@ -44,28 +47,26 @@ update_rules(Rule **rule, const char *da
                 regfree(&rul->regex);
                 free(rul);
         }
- for(p = (char *)data; *p; p++)
- switch(mode) {
+ for(p = data; *p; p++)
+ switch(state) {
                 case IGNORE:
                         if(*p == '/') {
- mode = REGEX;
                                 r = regex;
+ state = REGEX;
                         }
                         else if(*p == '>') {
- mode = VALUE;
                                 value[0] = 0;
                                 v = value;
+ state = VALUE;
                         }
                         break;
                 case REGEX:
                         if(*p == '/') {
- mode = IGNORE;
                                 *r = 0;
+ state = IGNORE;
                         }
- else {
- *r = *p;
- r++;
- }
+ else
+ *r++ = *p;
                         break;
                 case VALUE:
                         if(*p == '\n' || *p == 0) {
@@ -77,12 +78,12 @@ update_rules(Rule **rule, const char *da
                                         rule = &(*rule)->next;
                                 }
                                 else free(*rule);
- mode = IGNORE;
+ state = IGNORE;
                         }
- else {
- *v = *p;
- v++;
- }
+ else
+ *v++ = *p;
                         break;
+ default: /* can't happen */
+ assert(!"invalid state");
                 }
 }
diff -r c5aa6015b0f1 -r 7bc9a58ae0a4 rc/rc.wmii.rc
--- a/rc/rc.wmii.rc Sat Mar 31 00:19:12 2007 -0400
+++ b/rc/rc.wmii.rc Sat Mar 31 17:22:30 2007 -0400
@@ -196,9 +196,6 @@ fn run_command {
         }
 }
 
-# Source Overrides
-. <{awk '/^# Overrides/, 0' $local </dev/null}
-
 # WM Configuration
 wmiir write /ctl <<!
 grabmod $MODKEY
@@ -207,6 +204,9 @@ focuscolors $WMII_FOCUSCOLORS
 focuscolors $WMII_FOCUSCOLORS
 normcolors $WMII_NORMCOLORS
 !
+
+# Source Overrides
+. <{awk '/^# Overrides/, 0' $local </dev/null}
 
 # Misc Setup
 xsetroot -solid $WMII_BACKGROUND
Received on Sat Mar 31 2007 - 23:23:16 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 15:56:31 UTC