Skip to content
Browse files

Fixed a variety of bugs.

 * src/config.awk:
   * RSTART was used without match()
   * matching close tag assertion was disabled
   * split for directive block now strips whitespace correctly.
 * src/awkpaste.awk:
   * implemented language support
 * src/socket.awk:
   * turned off debug.
   * mkfifo only happens internally when we're creating our own tempfile.
 * bin/awkbot:
   * bootstrap now does mkfifo
 * cgi-bin/paste.cgi:
   * Removed antiquated comments.



git-svn-id: http://svn.blisted.org/awkbot/trunk@219 ebfa9934-6f10-0410-9599-894cdf3d53f0
  • Loading branch information...
1 parent b308dd2 commit 4cda7040dc3a7d5efb5062926c35b67da1e6c2ba scott committed May 15, 2011
Showing with 75 additions and 59 deletions.
  1. +7 −4 bin/awkbot
  2. +1 −2 cgi-bin/paste.cgi
  3. +6 −6 etc/awkbot.conf
  4. +13 −9 src/awkbot.awk
  5. +6 −5 src/awkbot_db_mysql.awk
  6. +10 −10 src/awkpaste.awk
  7. +24 −15 src/config.awk
  8. +8 −8 src/socket.awk
View
11 bin/awkbot
@@ -8,8 +8,8 @@ cpp -I /usr/share/awk -I src src/awkbot-boot.awk 2> /dev/null > $bootstrap
livedata=`awk -f $bootstrap /dev/null`
status=$?
-if [ $status -ne 1 ]
-then echo "Generated script ($bootstrap) exited prematurely, please inspect"
+if [ $status -ne 0 ]
+then echo "Bootstrap script ($bootstrap) exited prematurely, please inspect"
exit 1
fi
@@ -21,12 +21,15 @@ cpp -I /usr/share/awk/ -I src src/awkbot.awk 2> /dev/null > $awkbot
# Give our continuous input through a pipe to tail. tail -f never exits.
# Note, that this means awkbot never exits unless killed from the outside.
+rm $livedata
+mkfifo $livedata
chmod 666 $livedata
-tail -f $livedata | awk -f $awkbot
+
+cat $livedata | awk -f $awkbot
status=$?
-if [ $status -ne 1 ]
+if [ $status -ne 0 ]
then echo "Generated script ($awkbot) exited prematurely, please inspect"
exit 1
fi
View
3 cgi-bin/paste.cgi
@@ -7,8 +7,7 @@ cd ..
awkpaste=`tempfile`
cpp -I /usr/share/awk/ -I src src/awkpaste.awk 2> /dev/null > $awkpaste
-# Give our continuous input through a pipe to tail. tail -f never exits.
-# Note, that this means awkbot never exits unless killed from the outside.
+# Now that it's assembled, run it
awk -f $awkpaste
# Clean up our mess
View
12 etc/awkbot.conf
@@ -1,18 +1,18 @@
-debug 1
+
# IRC Stuff
<irc>
- nickname awktest
- altnick awktest-
- username awktest
- realname AWK IRC bot: Testing
+ nickname awkbot
+ altnick awkbot-
+ username awkbot
+ realname AWK IRC bot
# server irc.isprime.com:6667
server irc.freenode.net:6667
# port 6667
# channel awk perl pike
# channel c++
channel awk
# channel blacksun
- debug 1
+# debug 1
startup PRIVMSG NickServ :identify darwin
</irc>
View
22 src/awkbot.awk
@@ -90,19 +90,21 @@ $1 == "quit" {
# TODO [20091211 18:14] Is this still necessary?
# Nasty hack to clean up every few records
-NR % 10000 == 0 {
- print "DEBUG: Truncating file.."
- printf "" > irc["tempfile"]
- fflush(irc["tempfile"])
- close(irc["tempfile"])
-}
+# I think this shit now that I'm using a fifo
+#NR % 10000 == 0 {
+# print "DEBUG: Truncating file.."
+# printf "" > irc["tempfile"]
+# fflush(irc["tempfile"])
+# close(irc["tempfile"])
+#}
$1 == "say" {
_msg = $3
+
for (i = 4; i <= NF; i++) {
_msg = _msg " " $i
}
- print "Saying " _msg " to " $2
+
irc_privmsg($2, _msg)
}
@@ -148,14 +150,16 @@ func calc (expr ,result,bc) {
}
function irc_handler_privmsg (nick, host, recipient, message, arg \
- ,direct,target,address,action,c_msg,argc,t,q,a,s) {
+ ,direct,target,address,action,c_msg,argc,t,q,a,s)
+{
if (recipient ~ /^#/) target = recipient
else target = nick
# A special case...
if (substr(arg[1], 0, length(irc["nickname"])) == irc["nickname"] &&
- arg[1] !~ irc["nickname"] "\\+\\+") {
+ arg[1] !~ irc["nickname"] "\\+\\+")
+ {
direct = 1
shift(arg)
View
11 src/awkbot_db_mysql.awk
@@ -75,7 +75,7 @@ function awkbot_db_forget (question) {
function awkbot_db_status_running (running) {
mysql_finish(mysql_query("UPDATE status SET running = " \
- running ? 1 : 0))
+ (running ? 1 : 0)))
if (! running) {
mysql_finish(mysql_query("UPDATE status SET livefeed = NULL"))
@@ -89,7 +89,7 @@ function awkbot_db_status_running (running) {
function awkbot_db_status_connected (connected) {
mysql_finish(mysql_query("UPDATE status SET connected = " \
- connected ? 1 : 0))
+ (connected ? 1 : 0)))
}
function awkbot_db_status_livefeed (filename ,rv,row) {
@@ -125,10 +125,11 @@ function awkbot_db_info (keyword ,result,rv,row) {
return result
}
-function awkbot_db_paste_add (nick, description, content) {
- mysql_finish(mysql_query("INSERT INTO paste (nick, subject, content) " \
- " VALUES (" mysql_quote(nick) "," \
+function awkbot_db_paste_add (nick, description, language, content) {
+ mysql_finish(mysql_query("INSERT INTO paste (nick, subject, language, "\
+ "content) VALUES (" mysql_quote(nick) "," \
mysql_quote(description) "," \
+ mysql_quote(language) "," \
mysql_quote(content) ")"))
}
View
20 src/awkpaste.awk
@@ -19,11 +19,6 @@ BEGIN {
language = paste["language"]
content = paste["content"]
link = sprintf("%s?id=%d", config("paste.cgi"), id)
-
-# This should be dealt with in mysql.awk
-# gsub(/\\r\\n|\\n/, "\n", content) # CRLF to LF
-# gsub(/\\t/, "\t", context) # Outcoming tabs.
-# gsub(/\\\\/, "\\", content) # Outcoming escapes
}
else {
print "Location: /404.html"
@@ -34,9 +29,10 @@ BEGIN {
else {
stream = awkbot_db_status_livefeed()
- nick = query["name"]
- subject = query["description"]
- content = query["content"]
+ nick = query["name"]
+ subject = query["description"]
+ content = query["content"]
+ language = query["language"]
errmsg = ""
@@ -64,7 +60,7 @@ BEGIN {
exit 1
}
- awkbot_db_paste_add(nick, subject, content)
+ awkbot_db_paste_add(nick, subject, language, content)
# This has synchronization issues...but what the hell, this is awk
id = awkbot_db_paste_last()
link = sprintf("%s?id=%d", config("paste.cgi"), id)
@@ -75,6 +71,10 @@ BEGIN {
link) >> stream
close(stream)
+
+ print "Location:", link
+ print ORS
+ exit 1
}
}
@@ -102,7 +102,7 @@ BEGIN {
while (getline content < template) {
#else
#ifdef GAWK
- hilight = "highlight -I -l -k monospace -S awk"
+ hilight = "highlight -I -l -k monospace -S " language
print content |& hilight
close(hilight, "to")
View
39 src/config.awk
@@ -13,12 +13,12 @@ function config_load (filename) {
}
# Recurse over new levels
-function config_parse (config_data,level,filename ,l,t,s,current,closing) {
- if (config_data["debug"])
+function config_parse (config_data,level,filename ,l,t,s,current,closing) {
+ if (config_data["debug"])
printf "config_parse(ARRAY, %s, %s)\n", level, filename
while ( getline < filename ) {
- # Strip coments
+
sub(/^[\t ]*#.*$/, "")
if (config_data["debug"]) {
@@ -27,14 +27,13 @@ function config_parse (config_data,level,filename ,l,t,s,current,closing) {
}
if (/<[^\/][^>]*>/) {
- # 3 arg match equil
- # match($0, /<([^\/][^>]*)>/, l)
+ match($0, /<[^\/][^>]*>/)
s = substr($0, RSTART + 1, RLENGTH - 2)
if (config_data["debug"]) print "Opening: ", s > "/dev/stderr"
if (level) config_parse(config_data, level SUBSEP s, filename)
- else config_parse(config_data, s, filename)
+ else config_parse(config_data, s, filename)
}
else if (/<[\/][^>]*>/) {
match($0, /<[\/]([^>]*)>/)
@@ -43,7 +42,7 @@ function config_parse (config_data,level,filename ,l,t,s,current,closing) {
t = split(s, l, SUBSEP)
closing = l[t]
- t = split(s, l, SUBSEP)
+ t = split(level, l, SUBSEP)
current = l[t]
if (config_data["debug"])
@@ -52,17 +51,27 @@ function config_parse (config_data,level,filename ,l,t,s,current,closing) {
assert((current == closing), "Inconsistent open/close tags")
return
}
- else {
+ else if (match($0, /([^ ][^ ]*)[ ][ ]*([^ ].*)/)) {
+
+ split(substr($0, RSTART), l, /[ ][ ]*/)
- if (match($0, /([^ ][^ ]*)[ ]*(..*)/)) {
- # Using split rather than 3 argument match, for mawk.
- split($0, l, /[ ][ ]*/)
+ l[2] = substr($0, RSTART + length(l[1]))
- if (config_data["debug"])
- print level SUBSEP l[1], "=", l[2] > "/dev/stderr"
+ sub(/^[ ][ ]*/, "", l[2])
+
+ if (level) {
+ if (config_data["debug"]) {
+ print level "." l[1], "=", l[2] > "/dev/stderr"
+ }
+
+ config_data[level, l[1]] = l[2]
+ }
+ else {
+ if (config_data["debug"]) {
+ print l[1], "=", l[2] > "/dev/stderr"
+ }
- if (level) config_data[level, l[1]] = l[2]
- else config_data[l[1]] = l[2]
+ config_data[l[1]] = l[2]
}
}
}
View
16 src/socket.awk
@@ -45,16 +45,17 @@ BEGIN {
func socket_init (socket, tempfile, writeonly) {
if (!tempfile) {
tempfile = tempfile("tcp_socket")
+
+ if (socket_use_fifo) {
+ # If we're in fifo mode, unlink the file and make it a fifo.
+ system("unlink " tempfile)
+ system("mkfifo " tempfile)
+ }
+
}
socket["tempfile"] = tempfile
- if (socket_use_fifo) {
- # If we're in fifo mode, unlink the file and make it a fifo.
- system("unlink " tempfile)
- system("mkfifo " tempfile)
- }
-
if (!writeonly) {
# Allocate tempfile and tail by starting it
print >> tempfile
@@ -69,8 +70,7 @@ func socket_init (socket, tempfile, writeonly) {
# @param port integer TCP port number
func socket_connect (socket,host,port) {
socket["output"] = socket_catalyst " " host " " port " > " \
- socket["tempfile"] " 2>&1"
- print "DEBUG: using " socket["output"]
+ socket["tempfile"]
# Send zero bytes - just kick it off.
socket_write(socket)

0 comments on commit 4cda704

Please sign in to comment.
Something went wrong with that request. Please try again.