mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
added documentation pages from Dave Korn's old web site
This commit is contained in:
parent
82a89f64a9
commit
a30e7b7fa9
20 changed files with 2777 additions and 0 deletions
129
docs/ksh/scripts/cgi-lib.ksh.txt
Normal file
129
docs/ksh/scripts/cgi-lib.ksh.txt
Normal file
|
@ -0,0 +1,129 @@
|
|||
typeset -A COOKIE HEADER
|
||||
typeset Cgi _CGI_c _CGI_multipart
|
||||
|
||||
function cgi_header
|
||||
{
|
||||
typeset h
|
||||
for h in "${!HEADER[@]}"
|
||||
do printf '%s: %s\n' "$h" "${HEADER[$h]}"
|
||||
done
|
||||
print
|
||||
}
|
||||
|
||||
function cgi_url
|
||||
{
|
||||
if [[ $SERVER_PORT != 80 ]]
|
||||
then print "http://$SERVER_NAME:$SERVER_PORT$SCRIPT_NAME"
|
||||
else print "http://$SERVER_NAME$SCRIPT_NAME"
|
||||
fi
|
||||
}
|
||||
|
||||
function cgi_parse
|
||||
{
|
||||
if [[ $REQUEST_METHOD == POST ]]
|
||||
then if [[ $CONTENT_TYPE == multipart/form-data* ]]
|
||||
then _CGI_multipart=${TMPDIR-/tmp}/cgi-form-$$
|
||||
trap 'rm -rf "$_CGI_multipart"' EXIT
|
||||
mkdir $_CGI_multipart
|
||||
unset -f Cgi.set
|
||||
typeset -A Cgi.file
|
||||
typeset i b v
|
||||
pax --nosummary --read --edit ",.*/,," --edit ",^,$_CGI_multipart/,"
|
||||
for i in $_CGI_multipart/*
|
||||
do b=${i##*/}
|
||||
if [[ $b == +([a-z]) ]]
|
||||
then v=$(<$i)
|
||||
eval Cgi.$b='$v'
|
||||
else Cgi.file[$b]=$i
|
||||
fi
|
||||
done
|
||||
else Cgi=$(<&0) # Read from stdin
|
||||
fi
|
||||
else Cgi="$QUERY_STRING"
|
||||
fi
|
||||
cgi_cookie "$HTTP_COOKIE"
|
||||
HEADER["Content-type"]="text/html"
|
||||
}
|
||||
|
||||
function cgi_cookie
|
||||
{
|
||||
typeset cookie=$1 name val c IFS=';'
|
||||
set -- $cookie
|
||||
for c
|
||||
do
|
||||
IFS='='
|
||||
set -- $c
|
||||
name=${1##' '} val=${2##' '} # trim white space
|
||||
name=${name%%' '} val=${val%%' '}
|
||||
COOKIE[$name]=$val
|
||||
done
|
||||
}
|
||||
|
||||
function cgi_setcookie # name value
|
||||
{
|
||||
HEADER["Set-Cookie"]="$1=$2; path=$SCRIPT_NAME"
|
||||
}
|
||||
|
||||
## Cgi variable disciplines
|
||||
|
||||
function Cgi.set
|
||||
{
|
||||
set -f
|
||||
typeset i j n val IFS='&'
|
||||
set -- ${.sh.value}
|
||||
for i
|
||||
do n=${i%%=*}
|
||||
[[ $n == [[:alpha:]_]*([[:alnum:]_]) ]] || continue
|
||||
val=${i#$n=}
|
||||
val=${val//+/ }
|
||||
val=${val//@([\'\\])/'\'\1}
|
||||
eval j=\${#${.sh.name}.${n}[@]} \
|
||||
"${.sh.name}.${n}[j]=\$'${val//'%'@(??)/'\x'\1"'\$'"}'"
|
||||
done
|
||||
}
|
||||
|
||||
function cgi_C_init
|
||||
{
|
||||
integer i
|
||||
for ((i=1; i < 256; i++))
|
||||
do if (( i!=16#22 && i!=16#27 && i!=16#5C && i!=16#5B && i!=16#5D ))
|
||||
then printf $'_CGI_c[$\'\\\\x%.2X\']=%%%.2X\n' $i $i
|
||||
fi
|
||||
done
|
||||
print
|
||||
}
|
||||
|
||||
function cgi_encode
|
||||
{
|
||||
typeset v=$1
|
||||
var=${v//' '/+}
|
||||
cbrace='}'
|
||||
eval var=${var//@([!a-zA-Z0-9_+])/\${_CGI_c[\\\1]$cbrace}
|
||||
print -r -- "$var"
|
||||
}
|
||||
|
||||
function Cgi.get
|
||||
{
|
||||
typeset i val name vname
|
||||
if [[ ! ${_CGI_c[\\]} ]]
|
||||
then val='"'
|
||||
_CGI_c[""]=%00
|
||||
_CGI_c[$var]=%22
|
||||
_CGI_c[\']=%27
|
||||
_CGI_c[\]]=%5B
|
||||
_CGI_c[\[]=%5D
|
||||
_CGI_c[\\]=%5C
|
||||
eval $(cgi_C_init)
|
||||
unset -f cgi_C_init
|
||||
fi
|
||||
vname=${.sh.name} # .sh.name contains variable name
|
||||
.sh.value= # .sh.value stores value
|
||||
for i in ${!Cgi.@}
|
||||
do
|
||||
name=${i#$vname.}
|
||||
nameref v=${i}
|
||||
val=$(cgi_encode "$v")
|
||||
.sh.value="${.sh.value}${.sh.value:+&}$name=$val"
|
||||
done
|
||||
}
|
||||
|
17
docs/ksh/scripts/dump-cgi.ksh.txt
Normal file
17
docs/ksh/scripts/dump-cgi.ksh.txt
Normal file
|
@ -0,0 +1,17 @@
|
|||
#!/bin/ksh
|
||||
|
||||
. ./cgi-lib.ksh
|
||||
|
||||
cgi_parse
|
||||
cgi_header
|
||||
|
||||
print "<html>"
|
||||
print "<pre>"
|
||||
print -r "Url: $(cgi_url)"
|
||||
for i in ${!Cgi.*}
|
||||
do
|
||||
nameref val=$i
|
||||
print -r "$i = $val"
|
||||
done
|
||||
print "</pre>"
|
||||
print "</html>"
|
66
docs/ksh/scripts/env.txt
Normal file
66
docs/ksh/scripts/env.txt
Normal file
|
@ -0,0 +1,66 @@
|
|||
#! /usr/bin/ksh
|
||||
# shell version of env command
|
||||
case $(getopts '[-]' opt '--???man' 2>&1) in
|
||||
version=[0-9]*)
|
||||
usage=$'[-?@(#)env (AT&T Labs Research) 1999-05-20\n]
|
||||
[-author?David Korn <dgkorn@gmail.com>]
|
||||
[-license?http://www.research.att.com/sw/tools/reuse]
|
||||
[+NAME?env - set environment for command invocation]
|
||||
[+DESCRIPTION?\benv\b modifies the current environment according
|
||||
to the \aname\a\b=\b\avalue\a arguments, and then
|
||||
invokes \acommand\a with the modified environment.]
|
||||
[+?If \acommand\a is not specified, the resulting environment
|
||||
is written to standard output quoted as required for
|
||||
reading by the \bsh\b.]
|
||||
[i:ignore-environment?Invoke \acommand\a with the exact environment
|
||||
specified by the \aname\a\b=\b\avalue\a arguments; inherited
|
||||
environment variables are ignored. As an obsolete feature,
|
||||
\b-\b by itself can be specified instead of \b-i\b.]
|
||||
[u:unset]:[name?Unset the environment variable \aname\a if it was
|
||||
in the environment. This option can be repeated to unset
|
||||
additional variables.]
|
||||
|
||||
[name=value]... [command ...]
|
||||
|
||||
[+EXIT STATUS?If \acommand\a is invoked, the exit status of \benv\b
|
||||
will be that of \acommand\a. Otherwise, it will be one of
|
||||
the following:]{
|
||||
[+0?\benv\b completed successfully.]
|
||||
[+126?\acommand\a was found but could not be invoked.]
|
||||
[+127?\acommand\a could not be found.]
|
||||
}
|
||||
[+SEE ALSO?\bsh\b(1), \bexport\b(1)]
|
||||
'
|
||||
;;
|
||||
*)
|
||||
usage='iu:[name] [name=value]... [command ...]'
|
||||
;;
|
||||
esac
|
||||
clear=
|
||||
while getopts "$usage" var
|
||||
do case $var in
|
||||
i) clear=1;;
|
||||
u) command unset $OPTARG 2> /dev/null;;
|
||||
esac
|
||||
done
|
||||
#[[ $var == "" ]] || exit 1
|
||||
shift $((OPTIND-1))
|
||||
if [[ $1 == - ]] # obsolete form
|
||||
then clear=1
|
||||
shift
|
||||
fi
|
||||
if [[ $clear == 1 ]]
|
||||
then typeset +x $(typeset +x)
|
||||
fi
|
||||
while true
|
||||
do case $1 in
|
||||
*=*) export "$1";;
|
||||
*) break;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
if (( $# >0 ))
|
||||
then exec "$@"
|
||||
else export
|
||||
exit 0
|
||||
fi
|
2
docs/ksh/scripts/line.txt
Normal file
2
docs/ksh/scripts/line.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
#! /bin/ksh
|
||||
read -r && print -r -- "$REPLY"
|
2
docs/ksh/scripts/which.txt
Normal file
2
docs/ksh/scripts/which.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
#! /bin/ksh
|
||||
whence -p "$@"
|
Loading…
Add table
Add a link
Reference in a new issue