Changeset 58
- Timestamp:
- 03/02/08 00:27:44 (10 months ago)
- Location:
- trunk/awkbot
- Files:
-
- 1 added
- 4 modified
-
htdocs/index.xhtml (modified) (2 diffs)
-
src/awkpaste.awk (modified) (4 diffs)
-
src/cgi-lib.awk (modified) (1 diff)
-
src/config.h (added)
-
src/mysql.awk (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/awkbot/htdocs/index.xhtml
r56 r58 6 6 <title>AWK Paste!</title> 7 7 </head> 8 <style type="text/css"> 9 label { 10 display: block; 11 } 12 </style> 8 13 9 14 <body> 10 15 <h1>AWK Paste</h1> 16 <p>Link will be relayed to <a href="irc://irc.freenode.net/awk">#awk</a></p> 11 17 <form action="/cgi/paste.cgi" method="post"> 12 18 <fieldset> 13 19 <div> 14 20 <label for="description">Description</label> 15 <input type="text" name="description" size="30"/> 16 </div> 17 <div> 18 <label for="name">Your name</label> 19 <input type="text" name="name" size="30"/> 21 <input type="text" name="description" size="80"/> 20 22 </div> 21 23 <div> … … 24 26 </div> 25 27 <div> 26 <input type="submit" name="submit" value="Paste it!"/> 28 <label for="name">Nick</label> 29 <input type="text" name="name" size="30"/> 30 <input type="submit" value="Paste!"/> 27 31 </div> 28 32 </fieldset> -
trunk/awkbot/src/awkpaste.awk
r57 r58 5 5 #import <tempfile.awk> 6 6 #import <awkbot_db_mysql.awk> 7 #include "config.h" 7 8 8 9 BEGIN { … … 23 24 24 25 gsub(/\r\\n/, "\n", content) 25 gsub(/\\\t/, "\t", content)26 26 gsub(/\\\\/, "\\", content) # Outcoming escapes 27 27 } … … 47 47 } 48 48 49 #ifdef GAWK 50 hilight = "highlight -I -l -S awk" 51 print content |& hilight 52 close(hilight, "to") 53 54 while (hilight |& getline content) { 55 #else 49 56 workfile = tempfile("paste") 50 57 template = workfile ".html" … … 53 60 close(workfile) 54 61 62 #ifdef VIM 55 63 system("vim -i NONE -c \"syn on\" -c \"set syntax=awk\" -c \"set nu\"" \ 56 64 " -c TOhtml -c wq -c q " workfile " &> /dev/null") 65 #else 66 system("highlight -I -l -S awk -o " template " " workfile) 67 #endif 68 while (getline content < template) { 69 #endif 70 if (content ~ /<\/body>/) { 71 printf "<a href=\"%s\">Create a new Paste</a>\r\n", \ 72 config("paste.form") 73 } 57 74 58 while (getline content < template) {59 75 print content 60 76 61 77 # Ghetto little thing to inject a title 78 # works in both gawk and vim... 62 79 if (content ~ /<body/) { 63 print "<h1>AWK Paste:", "<a href=\"" link "\" />" id "</a></h1>"64 print "<p><b>Nick:", nick, "<br />"65 print "Subject:", subject, "<br />"66 print "</b></p><hr />"80 print "<h1>AWK Paste:", "<a href=\"" link "\">" id "</a></h1>" 81 print "<p><b>Nick:", nick, "<br>" 82 print "Subject:", subject, "<br>" 83 print "</b></p><hr>" 67 84 } 68 85 } 69 close( template)86 close(hilight, "from") 70 87 71 # print "Id:", id 72 # print "Nick:", nick 73 # print "Subject:", subject 74 # print content 75 88 #ifndef GAWK 76 89 system("rm " workfile) 77 90 system("rm " template) 91 #endif 78 92 } -
trunk/awkbot/src/cgi-lib.awk
r56 r58 17 17 len = length(string) 18 18 19 while ((i = index(string, "%")) && i + 2 < len) {19 while ((i = index(string, "%")) && i + 2 <= len) { 20 20 result = result substr(string, 1, i - 1) 21 21 result = result chr(dec( substr(string, i + 1, 2) )) -
trunk/awkbot/src/mysql.awk
r57 r58 46 46 47 47 print query | call 48 print query >> "/tmp/debug.log" 48 49 49 50 close(call) … … 51 52 if (getline input < mysql[resource]) { 52 53 for (i = split(input, key, "\t"); i > 0; i--) 53 mysql[resource, i] = gensub(/\\t/, "\t", "g", key[i])54 mysql[resource, i] = key[i] 54 55 } 55 56 … … 61 62 fields = split(input, row, "\t") 62 63 for (i = 1; i <= fields; i++) 63 row[mysql[resource, i]] = gensub(/\\t/, "\t", "g", row[i])64 row[mysql[resource, i]] = row[i] 64 65 } 65 66 … … 112 113 function mysql_quote (string, result) { 113 114 gsub(/\\/, "\\\\", string) 114 result = gensub(/(['\''"])/, "\\\\\\1", "g", string) 115 return "'" result "'" 115 gsub(/'/, "\\\'", string) 116 117 return "'" string "'" 116 118 }