Changeset 62
- Timestamp:
- 03/09/08 05:39:44 (10 months ago)
- Files:
-
- 1 modified
-
trunk/awkbot/src/awkpaste.awk (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/awkbot/src/awkpaste.awk
r61 r62 9 9 BEGIN { 10 10 cgi_params(query) 11 cgi_headers("text/html")12 13 11 config_load("etc/awkbot.conf") 14 12 awkbot_db_init() … … 46 44 } 47 45 } 48 #define TEMPLATE_FILE \ 49 workfile = tempfile("paste"); \ 50 template = workfile ".html"; \ 51 \ 52 print content > workfile; \ 53 close(workfile) 46 47 if (query["view"] == "text") { 48 cgi_headers("text/plain") 49 print content 50 exit 51 } 52 else { 53 cgi_headers("text/html") 54 55 #define TEMPLATE_FILE \ 56 workfile = tempfile("paste"); \ 57 template = workfile ".html"; \ 58 \ 59 print content > workfile; \ 60 close(workfile) 54 61 55 62 #ifdef VIM 56 TEMPLATE_FILE63 TEMPLATE_FILE 57 64 58 system("vim -i NONE -c \"syn on\" -c \"set syntax=awk\" -c \"set nu\"" \59 " -c TOhtml -c wq -c q " workfile " &> /dev/null")65 system("vim -i NONE -c \"syn on\" -c \"set syntax=awk\" " \ 66 " -c \"set nu\" -c TOhtml -c wq -c q " workfile " &> /dev/null") 60 67 61 while (getline content < template) {68 while (getline content < template) { 62 69 #else 63 70 #ifdef GAWK 64 hilight = "highlight -I -l -k monospace -S awk" 65 print content |& hilight 66 close(hilight, "to") 71 hilight = "highlight -I -l -k monospace -S awk" 67 72 68 while (hilight |& getline content) { 73 print content |& hilight 74 close(hilight, "to") 75 76 while (hilight |& getline content) { 69 77 #else 70 TEMPLATE_FILE78 TEMPLATE_FILE 71 79 72 system("highlight -I -l -k monospace -S awk -o " template " " workfile)80 system("highlight -I -l -k monospace -S awk -o " template " " workfile) 73 81 74 while (getline content < template) {82 while (getline content < template) { 75 83 #endif 76 84 #endif 77 if (content ~ /<\/body>/) { 78 printf "<a href=\"%s\">Create a new Paste</a>\r\n", \ 79 config("paste.form") 85 if (content ~ /<\/body>/) { 86 printf "<a href=\"%s?id=%s&view=text\">Plain Text</a>",\ 87 config("paste.cgi"), id 88 printf " | <a href=\"%s\">Create a new Paste</a>\r\n", \ 89 config("paste.form") 90 } 91 92 print content 93 94 # Ghetto little thing to inject a title 95 # works in both gawk and vim... 96 if (content ~ /<body/) { 97 print "<h1>AWK Paste:", "<a href=\"" link "\">" id "</a></h1>" 98 print "<p><b>Nick:", nick, "<br>" 99 print "Subject:", subject, "<br>" 100 print "</b></p><hr>" 101 } 80 102 } 81 82 print content 83 84 # Ghetto little thing to inject a title 85 # works in both gawk and vim... 86 if (content ~ /<body/) { 87 print "<h1>AWK Paste:", "<a href=\"" link "\">" id "</a></h1>" 88 print "<p><b>Nick:", nick, "<br>" 89 print "Subject:", subject, "<br>" 90 print "</b></p><hr>" 91 } 92 } 93 #define CLEANUP_FILE \ 94 system("rm " workfile); \ 95 system("rm " template) 103 #define CLEANUP_FILE \ 104 system("rm " workfile); \ 105 system("rm " template) 96 106 97 107 #ifdef VIM 98 CLEANUP_FILE108 CLEANUP_FILE 99 109 #else 100 110 #ifndef GAWK 101 CLEANUP_FILE111 CLEANUP_FILE 102 112 #else 103 close(hilight, "from")113 close(hilight, "from") 104 114 #endif 105 115 #endif 116 } 106 117 }