ref: c078d804a64b2d8ccc210a27bcaead96f26dfeca
parent: a00a90f46d874496ed00d25da978a69b3de786ce
author: uriel <[email protected]>
date: Fri Sep 26 06:35:12 EDT 2008
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.
--- /dev/null
+++ b/bin/cgilib.rc
@@ -1,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
+}
--- 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 @@
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 @@
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 @@
}
if (test -f $fpath/_config)
- . $fpath/_config
+ . $fpath/_config # DEPRECATED
if (test -f $fpath/_werc/config)
. $fpath/_werc/config
@@ -335,9 +316,9 @@
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 @@
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 @@
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) {
--- a/lib/feeds/rss20.tpl
+++ b/lib/feeds/rss20.tpl
@@ -34,8 +34,8 @@
<description>%($blogDesc%)</description>
<language>en-us</language>
<generator>Tom Duff's rc, and Kris Maglione's clever hackery</generator>
- <webMaster>[email protected] (Uriel)</webMaster>
%{
+ # <webMaster>[email protected] (Uriel)</webMaster>
for(f in `{sortedBlogPostList $blogDirs}) {
statpost $f
# Hack to aproximate the last build date