swerc

anselm's simpler werc fork
git clone git://git.suckless.org/swerc
Log | Files | Refs | README

commit 366a11678582f7c430670ca7495aa7ebe67db120
parent 865996d60002b54db31605f20a1da7565bce4917
Author: uriel@engel.se.cat-v.org <unknown>
Date:   Fri, 26 Sep 2008 10:35:12 +0200

Further cleanup and code reorganization, move generic cgi related functions to cgilib.rc, start to add code to be used for handing comments and wiki editing.
Diffstat:
Abin/cgilib.rc | 41+++++++++++++++++++++++++++++++++++++++++
Mbin/controller.rc | 60+++++++++---------------------------------------------------
Mlib/feeds/rss20.tpl | 2+-
3 files changed, 51 insertions(+), 52 deletions(-)

diff --git a/bin/cgilib.rc b/bin/cgilib.rc @@ -0,0 +1,41 @@ +# Useful functions + +fn dprint { echo $* >[1=2] } + +fn perm_redirect { + echo 'Status: 301 Moved Permanantly +Location: '^$1^' + +' + exit +} + +fn setvars { + ifs='& +' for(pair in `{cat}) { + pair = `{echo -n $pair | sed 's/=/\&/'} \ + ifs=() \ + if(~ $pair(1) $*) + eval $pair(1)'=`{urldecode $pair(2)}' + } +} + +# Is this really useful? +fn awk_buffer { + awk '{ + buf = buf $0"\n" + if(length(buf) > 8192) { + printf "%s", buf + buf = "" + } + } + END{ printf "%s", buf }' +} + +fn template { template.awk $* | rc $rcargs } + +# .rec parsing +fn parse_rec { + sed 's/% *//; /^$/q' < $1 + sed -n '/^$/,$p' < $1 +} diff --git a/bin/controller.rc b/bin/controller.rc @@ -1,23 +1,10 @@ #!/usr/local/plan9/bin/rc +. cgilib.rc cd .. - forbidden_uri_chars='[^a-zA-Z0-9_+\-\/\.]' response_format=html -# Useful functions -fn dprint { - echo $* >[1=2] -} - -fn perm_redirect { - echo 'Status: 301 Moved Permanantly -Location: '^$1^' - -' - exit -} - fn get_lib_file { wantedfile = $1 if (test -f $sitedir/_werc/lib/$wantedfile) @@ -133,13 +120,9 @@ fn set_handler { handler_args = $* } -fn md_handler { - cat $* | $formatter -} +fn md_handler { cat $* | $formatter } -fn tpl_handler { - template.awk $1 | rc $rcargs -} +fn tpl_handler { template $1 } fn html_handler { cat $1 | /bin/sed '0,/<[Bb][Oo][Dd][Yy][^>]*>/d; /<\/[Bb][Oo][Dd][Yy]>/,$d' @@ -161,9 +144,7 @@ fn dir_listing_handler { echo '</ul>' } -fn 404_handler { - template.awk `{get_lib_file 404.tpl } | rc $rcargs -} +fn 404_handler { template `{get_lib_file 404.tpl } } fn blog_dir_handler { blogDirs = $* @@ -320,7 +301,7 @@ for (i in ('' $args)) { } if (test -f $fpath/_config) - . $fpath/_config + . $fpath/_config # DEPRECATED if (test -f $fpath/_werc/config) . $fpath/_werc/config @@ -335,9 +316,9 @@ if (~ $#redirectPermanent 1) if not if (~ $#redirectPermanent 2 && {echo $SERVER_NAME^$REQUEST_URI|grep -s $redirectPermanent(1) }) { # Experimental regexp sub-based redirect, probably should find a nicer interface # For now only used at sites/harmful.cat-v.org/software/OO_programming/_config - to=`{echo $SERVER_NAME^$REQUEST_URI|sed 's|'^$redirectPermanent(1)^'|'^$redirectPermanent(2)^'|'} + to=`{echo $SERVER_NAME^$REQUEST_URI|sed 's@'^$redirectPermanent(1)^'@'^$redirectPermanent(2)^'@'} if(! ~ $to $REQUEST_URI) - perm_redirect $to + perm_redirect $to } # Set Page title @@ -348,13 +329,10 @@ if not body=$sitedir/$body -rssuri=$uri - if (test -d $body) { if(! ~ $body */) perm_redirect $REQUEST_URI^'/' body=$body/index - rssuri=$rssuri/ } select_handler @@ -367,30 +345,10 @@ if(~ $master_template 0) { master_template=$sitedir/_default.tpl } -# Is this really useful? -fn postfil_awk_buf { - awk '{ - buf = buf $0"\n" - if(length(buf) > 8192) { - printf "%s", buf - buf = "" - } - } - END{ printf "%s", buf }' -} - -post_filter=postfil_awk_buf - -# This probably should merge with tpl_handler -fn template { - if(~ $#post_filter 0) - template.awk | rc $rcargs - if not - template.awk | rc $rcargs | $post_filter -} if(~ $response_format html) { - cat $headers $master_template | template + # Is awk_buffer really useful? + template $headers $master_template | awk_buffer echo '</body></html>' } if not if (~ $response_format raw) { diff --git a/lib/feeds/rss20.tpl b/lib/feeds/rss20.tpl @@ -34,8 +34,8 @@ fn statpost { <description>%($blogDesc%)</description> <language>en-us</language> <generator>Tom Duff's rc, and Kris Maglione's clever hackery</generator> - <webMaster>uriel99+rss@gmail.com (Uriel)</webMaster> %{ + # <webMaster>uriel99+rss@gmail.com (Uriel)</webMaster> for(f in `{sortedBlogPostList $blogDirs}) { statpost $f # Hack to aproximate the last build date