home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2000 June
/
PCWorld_2000-06_cd.bin
/
Software
/
Servis
/
Sambar43
/
_SETUP.1
/
PBCgi.bas
< prev
next >
Wrap
BASIC Source File
|
1998-07-08
|
4KB
|
106 lines
' This program is for PowerBasic Console Compiler and was converted from
' the Delphi program named CGITEST which was by Dave Wedwick,
' Phoenix Transit System, June, 1997
' Converted on June 1998 by David Martin, Ivy League Software
' This tests the win-cgi capabilities of a web server.
' The win-cgi programs receive three command line parameters. These are
' filenames for interacting with the server.
' The first parameter is the name of an INI file (doesn't have to be an
' .INI file extension) containing information needed to process the request.
' The second parameter is the name of a file containing data that was POSTed
' by a form.
' The third parameter is the file to where output needs to go to return data
' to the web server.
' This program simply reads the data from the file identified by the first
' command line parameter and writes it to the file identified by the third
' parameter. Some HTML formatting is included in the output. Include this
' program in HTML Forms to see the results of submitting the form, etc.
FUNCTION PBMain ()
' If launched by the web server, there will be (at least) three
' command line parameters. If there aren't, assume that this is
' being launched by the command line and show a usage message.
CommandLine$ = COMMAND$
IF PARSECOUNT ( CommandLine$ , ANY ", " ) < 3 THEN
' This is for when someone runs it from the command line
CLS
STDOUT "This is a Win-CGI Test Program..."
STDOUT
STDOUT "This program tests the cgi-win capabilities of a web server."
STDOUT
STDOUT "To test, copy this executable to the cgi-win area of the web"
STDOUT "server and reference it via the web browser."
STDOUT
STDOUT "Example: HTTP:\\www.myserver.com\cgi-win\pbcgi.exe"
IF NOT CommandLine$ = "" THEN
STDOUT
STDOUT "The COMMAND$ was: ";
STDOUT CommandLine$
STDOUT "Which has" ;
STDOUT LTRIM$(STRING$(PARSECOUNT ( CommandLine$ , ANY ", " ),2)) ;
STDOUT "parameters"
END IF
ELSE
gIniFile$ = PARSE$( CommandLine$ , ANY ", " , 1 )
gInputFile$ = PARSE$( CommandLine$ , ANY ", " , 2 )
gOutputFile$ = PARSE$( CommandLine$ , ANY ", " , 3 )
' Open the third parameter for writing (output)
gOutputNum% = FREEFILE
OPEN gOutputFile$ FOR BINARY AS #gOutputNum%
' Required header used by the server for processing
PUT$ #gOutputNum% , "HTTP/1.0 200 OK" + CHR$(13,10)
PUT$ #gOutputNum% , "Content-type: text/html" + CHR$(13,10) + CHR$(13,10)
' Useing builtin commands is easy
PUT$ #gOutputNum% , "The date & time at the server is " + DATE$ + " at " + TIME$
' Show what the three filenames are
PUT$ #gOutputNum% , "<H4>INI file is: " + gIniFile$ + _
"<br>Input file is: " + gInputFile$ + _
"<br>Output file is: " + gOutputFile$ + "</H4>"
' Read INI file and write it back out to the Output file
gIniNum% = FREEFILE
OPEN gIniFile$ FOR BINARY AS #gIniNum%
PUT$ #gOutputNum% , "<HR><H1>Contents of INI file:</H1>"
PUT$ #gOutputNum% , "<PRE>" + CHR$(13,10)
WHILE NOT EOF(gIniNum%)
GET$ #gIniNum% , 4000 , TheLineIn$
PUT$ #gOutputNum% , TheLineIn$ + CHR$(13,10)
WEND
PUT$ #gOutputNum% , "</PRE>" + CHR$(13,10)
CLOSE #gIniNum%
' Read Input file and write it back out to the Output file
gInputNum% = FREEFILE
OPEN gInputFile$ FOR BINARY AS #gInputNum%
PUT$ #gOutputNum% , "<BR><HR><H1>Contents of INPUT file:</H1>"
PUT$ #gOutputNum% , "<PRE>" + CHR$(13,10)
WHILE NOT EOF(gInputNum%)
GET$ #gInputNum% , 4000 , TheLineIn$
PUT$ #gOutputNum% , TheLineIn$ + CHR$(13,10)
WEND
PUT$ #gOutputNum% , "</PRE>" + CHR$(13,10)
CLOSE #gInputNum%
PUT$ #gOutputNum% , "<HR>"
CLOSE #gOutputNum%
' We're done. When this .EXE finishes, the web server
' then processes the output file for the client.
END IF
END FUNCTION