Changeset 57

Show
Ignore:
Timestamp:
03/01/08 19:57:01 (10 months ago)
Author:
scott
Message:

Bug fixes for awkbot

  • Fixes for inserting quotes passed through mysql_quote(). double quotes and backslashes proved to be problematic
  • Syntax hilighting! Cleaned up the output of awkpaste is now hilighted.
Location:
trunk/awkbot/src
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/awkbot/src/awkpaste.awk

    r56 r57  
    33#import <cgi-lib.awk> 
    44#import <config.awk> 
     5#import <tempfile.awk> 
    56#import <awkbot_db_mysql.awk> 
    67 
    78BEGIN { 
    89    cgi_params(query) 
    9     cgi_headers("text/plain") 
     10    cgi_headers("text/html") 
    1011 
    1112    config_load("etc/awkbot.conf") 
     
    1920        subject = paste["subject"] 
    2021        content = paste["content"] 
     22        link    = sprintf("%s?id=%d", config("paste.cgi"), id) 
    2123 
    22         gsub(/\\n/, "\n", content) 
     24        gsub(/\r\\n/, "\n", content) 
     25        gsub(/\\\t/,  "\t", content) 
     26        gsub(/\\\\/,  "\\", content) # Outcoming escapes 
    2327    } 
    2428    else { 
     
    3236        # This has synchronization issues...but what the hell, this is awk 
    3337        id      = awkbot_db_paste_last() 
     38        link    = sprintf("%s?id=%d", config("paste.cgi"), id) 
    3439     
    3540        if (id) { 
    36             printf("say %s %s pasted %s at %s?id=%s\n",    \ 
     41            printf("say %s %s pasted %s at %s\n",    \ 
    3742                    config("paste.channel"), nick, subject,\ 
    38                     config("paste.cgi"), id) >> stream 
     43                    link) >> stream 
    3944     
    4045            close(stream) 
     
    4247    } 
    4348 
     49    workfile = tempfile("paste") 
     50    template = workfile ".html" 
    4451 
    45     print "Id:", id 
    46     print "Nick:", nick 
    47     print "Subject:", subject 
    48     print content 
     52    print content > workfile 
     53    close(workfile) 
     54 
     55    system("vim -i NONE -c \"syn on\" -c \"set syntax=awk\" -c \"set nu\"" \ 
     56            " -c TOhtml -c wq -c q " workfile " &> /dev/null") 
     57 
     58    while (getline content < template) { 
     59        print content 
     60 
     61        # Ghetto little thing to inject a title 
     62        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/>" 
     67        } 
     68    } 
     69    close(template) 
     70 
     71#   print "Id:", id 
     72#   print "Nick:", nick 
     73#   print "Subject:", subject 
     74#   print content 
     75 
     76    system("rm " workfile) 
     77    system("rm " template) 
    4978} 
  • trunk/awkbot/src/mysql.awk

    r39 r57  
    111111 
    112112function mysql_quote (string,   result) { 
    113     result = gensub("([^\\\\])'", "\\1\\\\'", "g", string) 
     113    gsub(/\\/, "\\\\", string) 
     114    result = gensub(/(['\''"])/, "\\\\\\1", "g", string) 
    114115    return "'" result "'" 
    115116}