Please enable JavaScript to view this site.

A-Shell Reference

The CGI script launching A-Shell must provide a command file to log the session in and run a program capable of retrieving the request and responding to it.  The Linux and Windows examples in the prior topics used a command file CGITST (e.g. CMD:CGITST.CMD or CMD:CGITST.DO) that might contain something like the following:

:R

log bas:

run cgitst

 

Finally, our program CGITST.BAS might look something like this:

program CGITST,1.0(100)

!---------------------------------------------------------------------

! Sample program used within a CGI script

! Note that we are expecting the form parameters to have been passed 

! to us in stdin (using the POST method). We'll pick them up with

! cgiutl. The output page templateis stored in cgitst.htm in the 

! current directory; it contains "variables" for the form parameters, 

! which we substitute in using cgiutl. 

!---------------------------------------------------------------------

 

++include ashinc:ashell.def

 

map1 PARAMETERS               ! parameters we expect to be passed by form

map2 NAME,S,60

map2 ZIP,S,5

map2 AGE,S,10            ! e.g. "11-30"

map2 COMMENTS,S,500

map1 CGIUTL'PARMS

map2 STATUS,F

 

! test if we are in cgi mode (-cgi switch used)

xcall CGIUTL,CGIOP_STATUS,STATUS

if STATUS = 0 print "Not running in CGI mode" : end

! retrieve parameters

xcall CGIUTL,CGIOP_GETPAR,"name",NAME,STATUS

xcall CGIUTL,CGIOP_GETPAR,"zip",ZIP,STATUS

xcall CGIUTL,CGIOP_GETPA2,"age",AGE,STATUS

xcall CGIUTL,CGIOP_GETPA2,"comments",COMMENTS,STATUS

! now build new web page just displaying these parameters

! (using the template file CGITST.HTM)

xcall CGIUTL,CGIOP_MRGOUT,"cgitst.htm", STATUS, &

"$NAME="+NAME, &

"$ZIP="+ZIP, &

"$AGE="+AGE, &

"$COMMENTS="+COMMENTS

! finally, just end

end

 

The template file for the output web page might look like the following. Note that we don’t have to use this template approach. We can also use the CGIUTL opcode CGIOP_STDOUT (4) to build the web page from scratch. But this approach allows you to design your web page in another tool, then just modify it to specify suitable fill-in variable names for the data you want to merge in.

content-type: text/html

 

<HTML>

<HEAD>

<TITLE> Sample CGI-generated web page </TITLE>

</HEAD>

<BODY>

<H1> Here is the information you passed in the previous form: </H1>

<P></P>

<P>Name = $NAME</P>

<P>Zip = $ZIP</P>

<P>Age = $AGE</P>

<P>Comments = $COMMENTS</P>

</BODY>

</HTML>

The above sample program doesn’t do anything useful, other than just read in the data input into the form, parse it out, and then display that data on a new web page. However, it should be easy to extend this technique to do something useful.

See FastCGI for details about ASB support for the fast variation.