Changeset 62

Show
Ignore:
Timestamp:
03/09/08 05:39:44 (10 months ago)
Author:
scott
Message:

Added Raw Source view

  • As per xmb's suggestion, added a "plain text" view to pastes, and a link at the bottom to reach them.
  • This gets rid of the copy/paste problem of not using a numbered list for the line numbering.
Files:
1 modified

Legend:

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

    r61 r62  
    99BEGIN { 
    1010    cgi_params(query) 
    11     cgi_headers("text/html") 
    12  
    1311    config_load("etc/awkbot.conf") 
    1412    awkbot_db_init() 
     
    4644        } 
    4745    } 
    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) 
    5461 
    5562#ifdef VIM 
    56     TEMPLATE_FILE 
     63        TEMPLATE_FILE 
    5764 
    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") 
    6067 
    61     while (getline content < template) { 
     68        while (getline content < template) { 
    6269#else 
    6370#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" 
    6772 
    68     while (hilight |& getline content) { 
     73        print content |& hilight 
     74        close(hilight, "to") 
     75 
     76        while (hilight |& getline content) { 
    6977#else 
    70     TEMPLATE_FILE 
     78        TEMPLATE_FILE 
    7179 
    72     system("highlight -I -l -k monospace -S awk -o " template " " workfile) 
     80        system("highlight -I -l -k monospace -S awk -o " template " " workfile) 
    7381 
    74     while (getline content < template) { 
     82        while (getline content < template) { 
    7583#endif 
    7684#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            } 
    80102        } 
    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) 
    96106 
    97107#ifdef VIM 
    98     CLEANUP_FILE 
     108        CLEANUP_FILE 
    99109#else 
    100110#ifndef GAWK 
    101     CLEANUP_FILE 
     111        CLEANUP_FILE 
    102112#else 
    103     close(hilight, "from") 
     113        close(hilight, "from") 
    104114#endif 
    105115#endif 
     116    } 
    106117}