[hackers] [wmii] New wmiirc/wmiiloop model that mawk shouldn't choke on.

From: Kris Maglione <jg_AT_suckless.org>
Date: Wed Mar 07 16:42:59 2007

changeset: 2007:994e2bcc192d
tag: tip
user: Kris Maglione <jg_AT_suckless.org>
date: Wed Mar 07 10:38:31 2007 -0500
summary: New wmiirc/wmiiloop model that mawk shouldn't choke on.

diff -r 4dd58e211466 -r 994e2bcc192d rc/wmiirc
--- a/rc/wmiirc Tue Mar 06 16:15:08 2007 -0500
+++ b/rc/wmiirc Wed Mar 07 10:38:31 2007 -0500
@@ -38,19 +38,23 @@ EOF
 EOF
 
 # Event processing
-{
-cat <<'EOF'
 # Status Bar Info
 status() {
         echo -n $(uptime | sed 's/.*://; s/,//g') '|' $(date)
 }
 
+IFS=''
+eval $({
+cat <<'EOF'
 # Events
 Event Start
         case "$1" in
         wmiirc)
- exit;;
- exac
+ exit;
+ esac
+Event Key
+ fn=$(echo $@ | sed 's/[^a-zA-Z_0-9]/_/g')
+ Key_$fn $@
 Event CreateTag
         echo "$WMII_NORMCOLORS" "$@" | wmiir create "/lbar/$@"
 Event DestroyTag
@@ -143,8 +147,9 @@ Key $MODKEY-Shift-$i
         wmiir xwrite /client/sel/tags "\$(echo \$key | sed 's/.*-//')"
 EOF
 done
-
-cat <<'EOF'
+} | wmiiloop)
+unset IFS
+
 # Functions
 proglist() {
         paths=$(echo "$@" | sed 'y/:/ /')
@@ -183,7 +188,6 @@ PROGS_FILE="$WMII_NS_DIR/.proglist"
 PROGS_FILE="$WMII_NS_DIR/.proglist"
 Action status &
 proglist $PATH >$PROGS_FILE &
-EOF
 
 xsetroot -solid "$WMII_BACKGROUND" &
 
@@ -215,4 +219,9 @@ done
 # Stop any running instances of wmiirc
 echo Start wmiirc | wmiir write /event || exit 1
 
-} | wmiiloop | sh
+wmiir read /event |
+while read event; do
+ set -- $event
+ event=$1; shift
+ Event_$event $@ 2>/dev/null
+done
\ No newline at end of file
diff -r 4dd58e211466 -r 994e2bcc192d wmii9rc
--- a/wmii9rc Tue Mar 06 16:15:08 2007 -0500
+++ b/wmii9rc Wed Mar 07 10:38:31 2007 -0500
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/sh -f
 RC=""
 for i in "$PLAN9" /usr/local/plan9 /usr/local/9 /opt/plan9 /opt/9 /usr/plan9 /usr/9; do
         if [ -d "$i" -a -x "$i/bin/rc" ]; then
diff -r 4dd58e211466 -r 994e2bcc192d wmiiloop
--- a/wmiiloop Tue Mar 06 16:15:08 2007 -0500
+++ b/wmiiloop Wed Mar 07 10:38:31 2007 -0500
@@ -1,32 +1,19 @@
 #!AWKPATH -f
-/^#/ && $2 !~ /^Events|Actions|Key$/ || !begin, \
-/^#/ && $2 ~ /^(Events|Actions|Key)$/ {
- begin = 1
- print
- next
-}
-
 BEGIN {
         arg[1] = "Nop"
         writekeys = "wmiir write /keys"
- readevent = "wmiir read /event"
- print "ACTIONS=\"\""
+ print "IFS=''"
 }
 
 function addevent() {
- if(arg[1] == "Key") {
- keys[arg[2]] = body
- }
- else if(arg[1] == "Event") {
- events[arg[2]] = body
- }
- else if(arg[1] == "Action") {
- action = arg[2];
- actions[action] = body
- gsub("\"", "\\\"", action)
- print "ACTIONS=\"$ACTIONS " action "\""
- print "Action_" action "() {" actions[action] "\n}"
- }
+ if(arg[1] == Key)
+ keys[arg[1]] = 1;
+
+ var = arg[1] "s"
+ print var "=\"$" var "\n" arg[1] "\""
+
+ gsub("[^a-zA-Z_0-9]", "_", arg[2]);
+ print arg[1] "_" arg[2] "() {" body "\n}"
 }
 
 /^(Event|Key|Action)[ \t]/ {
@@ -39,24 +26,8 @@ function addevent() {
 }
 
 END {
+ addevent()
         for(key in keys)
                 print key | writekeys
- close(writekeys)
- while(readevent | getline) {
- split($0, arg)
- sub("^[a-zA-Z]+[ \t]+", "")
- print "set -f"
- if(arg[1] == "Key") {
- sub("^[^ \t]+", "")
- print "key=\"" arg[2] "\""
- body = keys[arg[2]]
- }
- else {
- print "event=\"" arg[1] "\""
- body = events[arg[1]]
- }
- print "set -- " $0
- print body
- fflush()
- }
+ close(writekeys);
 }
Received on Wed Mar 07 2007 - 16:42:59 UTC

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