Subject: Re: CGI with SWI-Prolog

From: [email-masked]
Date: Mon, 3 Apr 2000 08:05:16 -0800

If you are server runs UNIX you could use the tools I
through together for handling posted data and URL-unencoding.
If your not UNIX-ready skip the rest of this message:-)

I haven't tried them with Prolog and they treat each http
request with no memory of previous ones.  Use FTP or a browser
to got to
	ftp://www.csci.csusb.edu/dick/tools/
	http://www.csci.csusb.edu/dick/tools/

The C program 'unpost.c' grabs posted data and outputs
it as standard output (with terminator!)when used like this:
	unpost $CONTENT_LENGTH

The script 'urlunencode' uses the UNIX sed program to remove
URL encoding from standard input and produces the unencoded text
on standard output.

The C program `url2lf.c` stops some programs from being broken
by long streams of characters with no end of lines.  When compiled
it spots URL-encoded end-of-lines (harder than you might think...)
and puts in end-of-lines in their place.  Again the program - in K&R
C (!) when compiled takes URL-encoded data on standard input
and produces code with URL-endoced newlines replaced by real newlines
on standard output.

A typical CGI of mine looks like:
echo Content-type: text/html
echo
if [ x"$REQUEST_METHOD" = xPOST ]
then
        /u/faculty/dick/bin/unpost $CONTENT_LENGTH  |
        tr '&' '
' |
        /u/faculty/dick/bin/url2lf |
        /u/faculty/dick/bin/urlunencode |
        (
	   #whatever
	)
else
        echo REQUEST_METHOD must be POST.
fi

Hope this helps,
dick