werc/bin/cgilib.rc

45 lines
803 B
Plaintext

# Useful functions
fn dprint { echo $* >[1=2] }
fn perm_redirect {
echo 'Status: 301 Moved Permanantly
Location: '^$1^'
'
exit
}
fn get_post_args {
ifs='&
' for(pair in `{cat}) {
pair = `{echo -n $pair | sed 's/=/\&/'} \
ifs=() \
if(~ $pair(1) $*)
$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 {
for(i in `{sed 's/% *//; /^$/q' < $1}) {
v = `{echo $i | sed 's/^/rec_/; s/=.*//;'}
$v = `{echo $i | sed
}
rec_data = `{sed -n '/^$/,$p' < $1}
}