Make your own free website on Tripod.com
-->

kshWeb cgiparse
CGI Forms Parser

 

kshWeb Home | ksh Applications, Tools, Utilities | Obtain Korn Shell | Shell News Groups | Publications | Links
Korn Shell Jobs | Tip-O-The-Day | Visitor Supplied Scripts | GuestBook | Registration and Download | MicroEMACS

FREE On-Line
Business Card File
Data Entry System
FREE On-Line
Korn Shell Books Free E-mail
YourName@ UnixGuru.zzn.com
YourName@ UnixWizard.zzn.com
YourName@ MCSE.zzn.com
... and many others!!!

Cut and paste the following script into a file called "cgiparse.ksh" on your system. Or click on cgiparse.ksh to download a file containing the function.

#!/bin/ksh
################################################################
####    
####    Korn Shell function to parse CGI form variables and 
####    values.  Processes a standard input stream and provides 
####    as output the processed stream, one variable/value pair 
####    per line. Also evaluates the variable/value pair so
####    that subsequent commands can reference the CGI specified 
####    variables.
####
####    This function assumes "bc" and "awk" commands can be 
####    located via the PATH environment variable.
####    
####    Load this file into your current environment as follows:
####    
####    . ./cgiparse.sh
####    
####    Thats "dot-space-dot-slash-cgiparse-dot-sh"
####
####    You will then be able to issue the command "cgiparse"
####    from your current environment to retrieve one character.
####
####    SYNTAX: cgiparse [-v] < STDIN
####        OR
####            echo "UNPARSED CGI STRING" | cgiparse
####
####    -v    Verbose mode. Echoes each variable/value pair to STDOUT
####
####
####    AUTHOR: Dana French
####    EMAIL: dfrench@mtxia.com
####
################################################################
cgiparse()
{
VFLAG="0"
[[ "_${1}" = "_-v" ]] && VFLAG="1"
CGI_TMP1=`sed -e "s/\&/	/g;s/%\(..\)/\\\`print \\\'ibase=16\\\; \1\\\' \\\| bc \\\| awk \\\'\\\{printf\\\(\\\\\"%c\\\\\",\\\$1\\\)\\\}\\\'\\\`/g"`

if [[ "_${CGI_TMP1}" != "_" ]]
then
  for i in `eval echo "\"${CGI_TMP1}\""`
  do
    CGI_TMP2=`print "${i}" | sed -e "s/\"/\'/g;s/,/ /g;s/+/ /g"`
    CGI_VAR="${CGI_TMP2%%=*}"
    CGI_VAL="${CGI_TMP2#*=}"
    eval ${CGI_VAR}="\"\${CGI_VAL}\""
    [[ ${VFLAG} -eq 1 ]] && print "${CGI_VAR}=\"${CGI_VAL}\""
  done
fi    
}
################################################################

#
# uncomment the following command to test the cgiparse function
#
# print 'EXCLAMATION=%21&POUND=%23&DOLLAR=%24&PERCENT=%25&ERSAND=%26&SINGLE=%27&OPEN_PAREN=%28&CLOSE_PAREN=%29&ATSIGN=%40&GRAVE=%60&EOD=' | cgiparse -v
################################################################

kshWeb Home | ksh Applications, Tools, Utilities | Obtain Korn Shell | Shell News Groups | Publications | Links
Korn Shell Jobs | Tip-O-The-Day | Visitor Supplied Scripts | GuestBook | Registration and Download | MicroEMACS

FREE On-Line
Business Card File
Data Entry System
FREE On-Line
Korn Shell Books Free E-mail
YourName@ UnixGuru.zzn.com
YourName@ UnixWizard.zzn.com
YourName@ MCSE.zzn.com
... and many others!!!

 

For Information regarding this page, contact Dana French ( dfrench@mtxia.com )