Changeset 58

Show
Ignore:
Timestamp:
03/02/08 00:27:44 (10 months ago)
Author:
scott
Message:

Last changes to awkpaste

  • Moved to highlight(1), it's faster
  • Added GNU-awk co-process optimization, started actually using CPP.
  • Added config.h to define how rendering is done in awkpaste.
  • Fixed some issues with mysql.awk, particularly around fetching escaped tabular data and made it more portable by ditching gensub.
  • Fixed a decoding bug in cgi-lib.awk
Location:
trunk/awkbot
Files:
1 added
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/awkbot/htdocs/index.xhtml

    r56 r58  
    66    <title>AWK Paste!</title> 
    77  </head> 
     8<style type="text/css"> 
     9label { 
     10    display: block; 
     11} 
     12</style> 
    813 
    914  <body> 
    1015    <h1>AWK Paste</h1> 
     16    <p>Link will be relayed to <a href="irc://irc.freenode.net/awk">#awk</a></p> 
    1117    <form action="/cgi/paste.cgi" method="post"> 
    1218      <fieldset> 
    1319        <div> 
    1420          <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"/> 
    2022        </div> 
    2123        <div> 
     
    2426        </div> 
    2527        <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!"/> 
    2731        </div> 
    2832      </fieldset> 
  • trunk/awkbot/src/awkpaste.awk

    r57 r58  
    55#import <tempfile.awk> 
    66#import <awkbot_db_mysql.awk> 
     7#include "config.h" 
    78 
    89BEGIN { 
     
    2324 
    2425        gsub(/\r\\n/, "\n", content) 
    25         gsub(/\\\t/,  "\t", content) 
    2626        gsub(/\\\\/,  "\\", content) # Outcoming escapes 
    2727    } 
     
    4747    } 
    4848 
     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 
    4956    workfile = tempfile("paste") 
    5057    template = workfile ".html" 
     
    5360    close(workfile) 
    5461 
     62#ifdef VIM 
    5563    system("vim -i NONE -c \"syn on\" -c \"set syntax=awk\" -c \"set nu\"" \ 
    5664            " -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        } 
    5774 
    58     while (getline content < template) { 
    5975        print content 
    6076 
    6177        # Ghetto little thing to inject a title 
     78        # works in both gawk and vim...  
    6279        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>" 
    6784        } 
    6885    } 
    69     close(template) 
     86    close(hilight, "from") 
    7087 
    71 #   print "Id:", id 
    72 #   print "Nick:", nick 
    73 #   print "Subject:", subject 
    74 #   print content 
    75  
     88#ifndef GAWK 
    7689    system("rm " workfile) 
    7790    system("rm " template) 
     91#endif 
    7892} 
  • trunk/awkbot/src/cgi-lib.awk

    r56 r58  
    1717    len = length(string) 
    1818 
    19     while ((i = index(string, "%")) && i + 2 < len) { 
     19    while ((i = index(string, "%")) && i + 2 <= len) { 
    2020        result = result substr(string, 1, i - 1) 
    2121        result = result chr(dec( substr(string, i + 1, 2) )) 
  • trunk/awkbot/src/mysql.awk

    r57 r58  
    4646 
    4747    print query | call 
     48    print query >> "/tmp/debug.log" 
    4849 
    4950    close(call) 
     
    5152    if (getline input < mysql[resource]) { 
    5253        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] 
    5455    } 
    5556 
     
    6162        fields = split(input, row, "\t") 
    6263        for (i = 1; i <= fields; i++) 
    63             row[mysql[resource, i]] = gensub(/\\t/, "\t", "g", row[i]) 
     64            row[mysql[resource, i]] = row[i] 
    6465    } 
    6566 
     
    112113function mysql_quote (string,   result) { 
    113114    gsub(/\\/, "\\\\", string) 
    114     result = gensub(/(['\''"])/, "\\\\\\1", "g", string) 
    115     return "'" result "'" 
     115    gsub(/'/, "\\\'", string) 
     116 
     117    return "'" string "'" 
    116118}