From dick@csci.csusb.edu  Mon Apr  3 18:10:55 2000
Received: from silicon.csci.csusb.edu (silicon.csci.csusb.edu [139.182.38.1])
	by swi.psy.uva.nl (8.9.3/8.9.3) with ESMTP id SAA11675
	for <prolog@swi.psy.uva.nl>; Mon, 3 Apr 2000 18:10:54 +0200 (MET DST)
From: dick@csci.csusb.edu
Received: from blaze.csci.csusb.edu (blaze.csci.csusb.edu [139.182.38.10])
	by silicon.csci.csusb.edu (8.9.1/8.9.1) with ESMTP id JAA22564;
	Mon, 3 Apr 2000 09:07:50 -0700 (PDT)
	(envelope-from dick@csci.csusb.edu)
Received: by csci.csusb.edu id IAA23308; Mon, 3 Apr 2000 08:05:16 -0800 (8.9.1 Berkeley Sendmail)
Date: Mon, 3 Apr 2000 08:05:16 -0800
Message-Id: <200004031605.IAA23308@csci.csusb.edu>
To: lains@caramail.com, prolog@swi.psy.uva.nl
Subject: Re:  CGI with SWI-Prolog
Cc: dick@csci.csusb.edu

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

