Skip to main content

SIMPOL Server Pages

A SIMPOL server page is a file with the extension smz, the contents of which is HTML but which also includes blocks of SIMPOL source code. The blocks of source code are inside server page comment blocks (in between <% and %> tags), so if we launch the HTML viewer component of the SIMPOL IDE, we will see just the HTML page as if it did not contain any SIMPOL source code.

A project with smz files is a CGI project. This means that the final SIMPOL program is intended to be executed on the server side as a CGI, ISAPI or Fast-CGI program. Typically, a CGI program is called from a web server, for example the Apache web server. The entry point of a CGI or ISAPI program is the main() function, but in this case, the function has only one argument: function main(cgicall cgi). cgi is a cgicall object, and it contains all of the information the web server received from a browser call.

Building a CGI project adds another process to the normal build. First, the smz files are compiled into sma or smu files, and then the normal build follows. When a SIMPOL server page is compiled into SIMPOL source code, the SIMPOL source code in the server page block comments are passed through without change and the HTML is converted into string arguments of cgi.output() statements.

Here is an example of the process followed when building a CGI project:

  1. Project's main server page files: MySPFile1.smz, MySPFile2.smz

  2. MySPFile1.smz — includes —> MySPFile1a.txt

  3. MySPFile1.smz — compiles to —> MySPFile1.sma

  4. MySPFile2.smz — compiles to —> MySPFile2.sma

  5. Project's main source code files: MyFile1.sma, MyFile2.sma

  6. MyFile1.sma — includes —> MyFile1a.sma, MyFile1b.sma and MySPFile1.sma

  7. MyFile2.sma — includes —> MyFile2a.sma and MySPFile2.sma

  8. MyFile1.sma — compiles to —> MyFile1.smp

  9. MyFile2.sma — compiles to —> MyFile2.sml

  10. MyFile1.smp + MyFile2.sml — link to —> MyFile1.smp

 

The following is an example of SIMPOL server page code:

Example 3.1. SIMPOL Server Page Code

<%'-------------------------- begin code --------------------------
function ShowHelloOrNothing(cgicall cgi, integer i)
'--------------------------  end code  --------------------------%>
<HTML>
	<HEAD><META http-equiv="pragma" 
	  content="no-cache"></HEAD>
	<TITLE>SIMPOL Hello Page</TITLE>
<%'-------------------------- begin code --------------------------
	if(i == 1)
'--------------------------  end code  --------------------------%>
		<BODY>Hello</BODY>
<%'-------------------------- begin code --------------------------
	end if
'--------------------------  end code  --------------------------%>
</HTML>
<%'-------------------------- begin code --------------------------
end function

 

Results after compiling the server page:

Example 3.2. Compiled SIMPOL Server Page

'-------------------------- begin code --------------------------
function ShowHelloOrNothing(CGICall cgi, integer i)
'--------------------------  end code  --------------------------
	cgi.output("<HTML>" + "{0D}{0A}", 1)
	cgi.output("	<HEAD><META http-equiv=""pragma""" + "{0D}{0A}", 1)
	cgi.output("    content=""no-cache""></HEAD>" + "{0D}{0A}", 1)
	cgi.output("	<TITLE>SIMPOL Hello Page</TITLE>" + "{0D}{0A}", 1)
'-------------------------- begin code --------------------------
	if(i == 1)
'--------------------------  end code  --------------------------
	cgi.output("		<BODY>Hello</BODY>" + "{0D}{0A}", 1)
'-------------------------- begin code --------------------------
	end if
'--------------------------  end code  --------------------------
	cgi.output("</HTML>" + "{0D}{0A}", 1)
'-------------------------- begin code --------------------------
end function
'--------------------------  end code  --------------------------

 

The advantage of doing this, is that we can create HTML in a dynamic way using the power of the SIMPOL programming language and we can also visualize the HTML in the HTML viewer that is part of the IDE whenever we need it. So it is very easy to embed HTML (what a final user will see in his browser) in a SIMPOL CGI-style program.

The way that SIMPOL server pages work is different to that of ASP, JSP, or PHP. In each of these cases, the source code is also embedded into the HTML but unlike with SIMPOL these mixed-mode pages are then interpreted by the web server (which must be especially designed to be aware of them) and then the code portions are passed to the language interpreters for execution. With SIMPOL server pages, the design style is similar but the results are compiled rather than interpreted, which is faster and also does not require any special capabilities on the part of the web server.

A CGI project can contain any number of server pages. The server pages follow the same pattern as SIMPOL source code files when including files. Each main server page is the root node of a tree of other included files. The Superbase NG IDE manages the file time-dependencies when a build is done, as in the case of source code SIMPOL files.

The Superbase NG IDE provides a way to compile SIMPOL server pages into SIMPOL source code, and a way to regenerate a SIMPOL server page after manipulating the associated (compiled) SIMPOL source code; this allows the programmer to use the color coding capabilities of the IDE for the HTML source when working on the server page and then after compiling, it is possible to work on the SIMPOL program source in the resulting compiled page. After the changes are done to the compiled source, the option to regenerate the server page from the right mouse button popup menu should be used to send the changes back to the server page source code.

[Tip] Tip

It is always a good idea to propogate the changes back to the server page source right after making them, since the server page is the reference source code in the project. If you forget, during the next build you will be prompted that the code has changed. If you say okay, your changes will be lost as the compilation of the server page overwrites them. Also, only change code in the blocks between the begin code and end code comments. If you change anything else, it won't successfully regenerate the server page!