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.

This commit is contained in:
Uriel 2008-09-26 10:35:12 +02:00
parent ff35f9ebf6
commit 1f376ad60a
3 changed files with 51 additions and 52 deletions

41
bin/cgilib.rc Normal file
View file

@ -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
}