wmii/wmiiloop

64 lines
1.1 KiB
Plaintext

#!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=\"\""
}
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\n" action "\""
print "Action_" action "() {" actions[action] "\n}"
}
}
/^(Event|Key|Action)[ \t]/ {
addevent()
split($0, arg)
body = ""
}
/^[ \t]/ {
body = body"\n"$0
}
END {
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 "set +f"
print body
fflush()
}
}