Previous | Contents | Index |
While in a Sheerpower Code Area, you can embed any other code or script, including an .HTM or .HTML file, by using the %INCLUDE directive. Sheerpower will recognize the HTML code and output it all to the browser. This makes it trivial to embed large blocks of HTML within your program. To include an HTML file:
%include "@sample_page.html" |
If the file type is .SPSRC, .SPINC or .SPRUN, then the entire include file is assumed to be code. Otherwise it is assumed to be script.
See Section 3.9.4,%INCLUDE for more on the %INCLUDE directive in Sheerpower.
19.4.3 CGI Environment Symbols - GETSYMBOL$ Function
variable_name$ = getsymbol$('cgi_symbol') |
Example 19-6 GETSYMBOL$ Function |
---|
// get the CGI symbol value of "password" and store it into // the variable mypassword$ [[%spcode]] mypassword$ = getsymbol$('password') print 'My Password is:'; mypassword$ [[/%spcode]] |
CGI Symbol Names are case sensitive. |
Standard CGI environment symbols must be prefixed with "env:". For example:
[[%spcode]] myip$ = getsymbol$('env:REMOTE_ADDR') print 'My IP address is:'; myip$ [[/%spcode]] |
For a list of CGI environment symbols supported, see Section 18.3.8, Summary of CGI Environment Variables.
If embedded code inside a Sheerpower script area starts with a $ (dollar sign) then what follows the $ is treated as a CGI symbol lookup. The result of that lookup is then sent to the browser. For example, to send the HTML to the browser the value of CITY (where CITY was received from a browser form submit action):
The city was: [[$CITY]] |
CGI Symbol Names are case sensitive. |
19.5 High Performance PERSIST Tags
[[%persist]] ... ... [[/%persist]] |
[[%persist]] [[%spscript]] <html> <head> <title>Search Form</title> </head> <body onload="document.forms[0].city.select()"> <h2>Search for a city</h2> [[/%spscript]] counter++ print '<h2>Counter: '; counter;'</h2>' process$ = getsymbol$('process') select case process$ case '' display_form case 'show_results' display_form do_show_results case else print 'Unknown process: '; process$ end select print '</body>' print '</html>' [[/%persist]] |
The [[%persist]] and [[/%persist]] tags will provide your program with a higher performance.
For high performance, a script can remain running longer than initially required using the [[%persist]] and [[/%persist]] tags.
To use the tags, place the [[%persist]] tag at the beginning of the main logic area, and the [[/%persist]] at the end of the main logic area.
The process included within the tags "goes away" after 10 seconds of inactivity.
In addition to the [[%persist]] tag, find any code that you want to run just once per persistance and surround it with the [[%once]] and [[/%once]] tags. Good candidates are:
routine do_show_results [[%once]] open structure client: name 'c:\sheerpower\samples\client' [[/%once]] |
19.6 Location of Sheerpower Scripting Programs
Sheerpower scripting programs must be located in the following directory:
Sheerpower\sphandlers\scripts\sp4gl |
The scripting programs are not stored directly in the wwwroot folder purposely to increase security. They are parallel to it. The actual location of the program when it runs is:
wwwroot\..\scripts\sp4gl\ |
If you move wwwroot to a different location, then the location of the scripting program moves as well. For example, if you change wwwroot as follows:
spins_webserver -wwwroot d:\mystuff\ |
Then the new location that the scripting program should reside is:
d:\scripts\sp4gl |
And the parallel location the program will run from is:
d:\wwwroot\..\scripts\sp4gl |
See Section 17.1.4, Specify Any Root Folder on how to change the location of wwwroot in SPINS Webserver.
19.6.1 How to Invoke a Sheerpower Script Program in the Browser
To invoke a Sheerpower script program in your browser:
\sheerpower\sphandlers\spins_webserver.exe |
http://localhost/test.spsrc |
Routines written in other languages can be called and run from a Sheerpower program.
Callable routines are stored in libraries. The LIBRARY statement tells Sheerpower what library a routine is located in. The LIBRARY statement must be used to specify where routines are located when they are called in a program.
The CALL statement calls routines and executes them. Any routine in a shared Windows library can be called and executed. The CALL and LIBRARY statements make programs more powerful, more versatile, and provide more programming options.
Sheerpower can also run other programs from within Sheerpower using the PASS instruction. See Section 10.8, Pass Commands to the Operating System. |
LIBRARY 'libr_name' |
The LIBRARY statement is used to specify the libraries that will be used in a program.
The LIBRARY statement specifies libraries from which to CALL routines. The routines can be written in any Windows language that supports the standard calling interface (FORTRAN, BASIC, COBOL, etc.).
libr_name is the file specification of a library. The library can be one of the Windows supplied libraries, or a user-defined library. A library must be named with the LIBRARY statement before a routine is called from it. The library name must be a string constant in quotes.
CALL routine_name(arg [BY pass_mech], arg...) |
Example 20-1 LIBRARY and CALL Statements |
---|
library 'msvcrt.dll' a$ = space$(40) text$ = 'Hello there!' call 'strcpy' (a$, text$) print a$ end Hello there! |
The CALL statement is used to call and execute library routines. These routines can perform procedures so the programmer does not have to write the code from scratch.
The library to which the routine belongs must have been specified in a LIBRARY statement.
routine_name is the name of the routine being called. Some routines take arguments. arg is an argument that passes data to the routine or retrieves data from the routine. If more than one argument is passed, separate the arguments with commas:
CALL routine_name(arg, arg, arg...) |
Previous | Next | Contents | Index |