shithub: werc

Download patch

ref: c070f51c5c0417f32e2cf9aadf6a679106f2a501
parent: 49cdebe34d1abac84eff7e9ff4d7bd029943f7d0
author: uriel <uriel@engel.se.cat-v.org>
date: Fri Feb 6 17:09:32 EST 2009

Convert fltr_cache into a function. Enable output buffering which had been commented out for unknwon reasons.

--- /dev/null
+++ b/bin/fltr_cache.rc
@@ -1,0 +1,35 @@
+#!/usr/bin/env rc
+
+fn fltr_cache {
+    a=()
+    tmpf=()
+
+    proc=$1
+    shift
+
+    if(~ $#* 0) {
+        tmpf=/tmp/fmttmp.$pid
+        f=$tmpf
+        score=`{{tee $tmpf || exit 1} | sha1sum}
+    }
+    if not {
+        f=$1
+        if(~ $f */) {
+            score=`{du -an $f | sha1sum || exit 1} # XXX using -n(bytes) instead of -t(lastmod) because sitemap proc touches files in tree.
+            a=$f
+            f=/dev/null
+        }
+        if not
+            score=`{sha1sum $f || exit 1}
+    }
+    cachedir=/tmp/fltr_cache/$score
+    mkdir -p $cachedir >[2]/dev/null
+
+    if(test -s $cachedir/$proc)
+        cat $cachedir/$proc
+    if not
+        if($proc $a < $f | tee $cachedir/$pid)
+            mv $cachedir/$pid $cachedir/$proc
+
+    rm $tmpf $cachedir/$pid >[2]/dev/null &
+}
--- a/bin/fproc_cache.rc
+++ /dev/null
@@ -1,34 +1,0 @@
-#!/usr/bin/env rc
-#. 9.rc # Not really needed when calling from werc, only would be needed if you use fproc_cache.rc standalone
-
-a=()
-tmpf=()
-
-proc=$1
-shift
-
-if(~ $#* 0) {
-    tmpf=/tmp/fmttmp.$pid
-    f=$tmpf
-    score=`{{tee $tmpf || exit 1} | sha1sum}
-}
-if not {
-    f=$1
-    if(~ $f */) {
-        score=`{du -an $f | sha1sum || exit 1} # XXX using -n(bytes) instead of -t(lastmod) because sitemap proc touches files in tree.
-        a=$f
-        f=/dev/null
-    }
-    if not
-        score=`{sha1sum $f || exit 1}
-}
-cachedir=/tmp/fproc_cache/$score
-mkdir -p $cachedir >[2]/dev/null
-
-if(test -s $cachedir/$proc)
-    cat $cachedir/$proc
-if not
-    if($proc $a < $f | tee $cachedir/$pid)
-        mv $cachedir/$pid $cachedir/$proc
-
-rm $tmpf $cachedir/$pid >[2]/dev/null &
--- a/bin/werc.rc
+++ b/bin/werc.rc
@@ -3,6 +3,7 @@
 . ./werclib.rc
 . ./wercconf.rc
 . ./corehandlers.rc
+. ./fltr_cache.rc
 cd ..
 
 forbidden_uri_chars='[^a-zA-Z0-9_+\-\/\.]'
@@ -105,7 +106,7 @@
     if(! ~ $#debug 0)
         dprint $"SERVER_NAME^$"REQUEST_URI - $"HTTP_USER_AGENT - $"REQUEST_METHOD - $"handler_body_main - $"master_template
 
-    template $headers $master_template #| awk_buffer
+    template $headers $master_template | awk_buffer
     echo $res_tail
 }
 
--- a/etc/initrc
+++ b/etc/initrc
@@ -9,17 +9,17 @@
 
 # Location of your Plan 9 from User Space installation (usually /usr/local/plan9)
 plan9port=$PLAN9
+#plan9port=/usr/local/plan9
 
 # Path, make sure the plan9port /bin directory is included before /bin
 # Keep '.' in path! It is needed.
 path=($plan9port/bin/ . ./bin/ ./bin/contrib/ /bin/ /usr/bin/)
 
-# Set this to your favorite markdown formatter, eg., markdown.pl (fproc_cache
-# is a wrapper around a script it takes as an argument, in the default
-# configuration markdown.pl, that caches output)
-# Note that some werc components assume a markdown-like formatter, but all
-# major functionality should should be formatter agnostic.
-formatter=(fproc_cache.rc markdown.pl)
+# Set this to your favorite markdown formatter, eg., markdown.pl (fltr_cache
+# takes as an argument a filter, in the default configuration markdown.pl, that
+# caches output) Note that some werc components assume a markdown-like
+# formatter, but all major functionality should should be formatter agnostic.
+formatter=(fltr_cache markdown.pl)
 
 # Enable debugging, to disable set to ()
 debug=true
--- a/lib/sitemap.tpl
+++ b/lib/sitemap.tpl
@@ -56,7 +56,7 @@
     echo '</ul>'
 }
 
-fproc_cache.rc listDir $sitedir/
+fltr_cache listDir $sitedir/
 #listDir $sitedir/
 
 if(test -s $tmpfile)