Whatīs PasHyPer?

PasHyPer is a Pascal Hypertext Preprocessor.
The preprocessor works reading a HTML page and finding for pascal programs into this page.
On found a pascal program, the preprocessor compiles and run the script. All this is made in side server.

Why Pascal

Pascal is a very popular programming language because itīs clean, easy and readable. Why pascal is out of web as script language? I donīt know! If you like pascal, join us. Help us to build a Pascal Hypertext Preprocessor.

About PasHyPer Now

PasHyPer was compiled with FPC - FreePascal Compiler.

PasHyPer supports a subset of standard pascal and is missing several wanted improvements.
Reserved Words are the same of standard pascal, but not yet supports set, downto, array, record, type and signs as [].

PasHyPer supports the types integer, real, string, boolean and char.
The string type is a pointer to bytes managed by itself PasHyPer. The size of string is 1024 bytes for now. May be the max size of a WORD.

PasHyPer can run a enough set of functions and procedures of standard pascal and some functions to connection with MySQL database.
PasHyPer have a unique cgi function (cgi_getenv) that retrieves all the values of pages server.

PasHyPer manage uploads files, but need the programmer to pointer the directory of uploaded files with chdir procedure.
The size of uploaded files is limited to space in disk or space quote.

PasHyPer not yet with work typed files. Only text files is available for read/write.

PasHyPer not writes to files. This is a decision not a limitation (except downloaded files).

PasHyPer just supports comments in Borland way ({comment...}) and slashes (//comment).

PasHyPer supports just two directive (for now): $INCLUDE and $DEFINE.

PasHyPer file include is limited to 36KB for now. Because this limit, you must write small libraries. This turns PasHyPer faster and usefull with economic memory.

PasHyPer chdir procedure is virtual. It changes to a directory into directory root declared into pashyper.ini (see config file bellow). If you declare as directory root in pashyper.ini the string /home/carlos/pashyper/site01 and changes the directory with chdir to /home/carlos/pashyper/anotherdirectory will generate a error. The same with assign a file. So, if you must refere to file or directory into think root directory as "/". An alias can override the path to directory root.

PasHyPer handle date like FPC and Delphi/Kylix: it's a real value. The time part of datetime type is not implemented. This is the fractional part of a real. The date values may be different of FPC/Delphi values.

PasHyPer and Apache

PasHyPer, for now, don't have a module to Apache. But some integration may be using the file httpd.conf. To do this, you need put into file httpd.conf four lines:

ScriptAlias /pas/ "<pashyper directory>" (ex: "c:/pashyper/")
AddType application/x-httpd-pas .pas .pp
AddHandler application/x-httpd-pas .pas .pp
Action application/x-httpd-pas "/pas/pashyper[.exe]"

If you not yet setup the CGI directory, then put the following lines into httpd.conf:

<Directory "pashyperdirectory">
    AllowOverride All
    Options ExecCGI FollowSymlinks Includes
    Order allow,deny
    Allow from all
    Require All Granted

You need find CGI directory in httpd.conf file and replace it with lines below.

Pashyper and IIS

PasHyPer, for now, don't have module to IIS. To integrate PasHyPer with IIS, take the steps in IIS manager interface:

Or you can write command lines as:

appcmd set config /section:handlers /+[name='pascal_script',path='*.pp',verb='GET,HEAD,POST',scriptProcessor='"C:\path\pashyper.exe"', modules='CgiModule', resourceType='Either'];

appcmd set config /section:handlers /accessPolicy:Read,Script,Execute

PasHyPer Config File

The pashyper.ini file must be placed into PasHyPer directory. If you use MySQL, you must write the config file. The pashyper.ini is a plain text file, with sections, keys and values, in format:

# Line commented is started by a "#" or a ";"

The sections possible for now are root, aliases and mysql. The keys are: directory, in root section to indicate a directory as "/" directory; path in mysql section to indicate mysql client library path (without file name); lib in mysql section to pointer to mysql client library file (just the file name).

In aliases section you can put aliases that will be replaced by the indicated value. For example, if you put into file healthplan01=/home/mydocs/health/plans/01/page.htm, when PasHyPer found healthplan01 as parameter to filename* it will replace by the indicated value. For now, just full string is translated (i.e., no compare is made with substring). The aliases, for now, overrides the root directory declared into root section. To disable the aliases (global processor), write in root section ignorealiases=yes (1, si, sim, true)



    #overrides path

* The parameter filename is used in following way:


to indicate to pashyper how file it process. The extension assumed as default is .htm, but the file may be a image, a video, a text, etc. In this case you must indicate the file extension (pashyper selects media type based on file extension). PasHyPer accept wildcards in aliases section. If you write kc*=c:\pashyper\site01\index.htm, all word that start with kc in filename parameter will translated to c:\pashyper\site01\index.htm.

To do

PasHyPer need debugging all internal functions, procedures and operators. This is made with little codes for each case.

PasHyPer need little libraries that provides facilities to programmer. This is made using the $include clause.

a) utf-8 routines to writes output and read input.

b) url encode and decode routines don't works properly in linux. AllocMem may be crashes when running under linux. Trying don't use ansistring but pchar.

c) md5 and base64 encrypt routines to work natively.

d) images and other binary files can be served by PasHyPer. But if you use pashyper to output very images per page, the performance is down. For now, references as http://.../pashyper?filename=<a_image_file> must be not used or skippep.

d) ssl security is not implemented.

e) implement support to arrays and pointers.

f) case not supports construction as case myfunc(parameters) of. The construction for now is case variable of.

Rules to Write Scripts

A script is a program. So, as in pascal standard, you need write a program to PasHyPer recognize it as a script. Into html files, PasHyPer will recognize just code fragment placed into tags <pas> and </pas>. Example:


But, if you need use variables, you will write this fragments as a procedure, declaring variables and a code block, as in:

var i:integer;
  for i:=1 to 1000 do write('XX ');

For now, you cannot write pascal tags into html tags as in:
<input ... <pas> ... </pas> ... />.

You can write several procedures and functions into script section:

<script type="text/pascal">
procedure abba;

procedure baab;

function faaf:integer;

function affa:boolean;

{$include somefilepascal.inc}
//you can call this functions and procedures into body of html.

For build calling of functions and procedure, PasHyPer work only as a script, it not work as code peace into html file. So, the logical structure of a program is the logical structure of a program:

program dosomething;
var i:integer;

{$include someincludefile}

function foo_bar(s:string):boolean;
  foo_bar:=length(s) > 0;

procedure baboo(i:integer);
  writeln('<tr><td>', i, '</td></tr>');

begin {program}
  if foo_bar('***********') then
  writeln('<tr><td>', some thing, '</td></tr>');


You can help this project if you like Pascal Language and know Pascal Language. You can debug it, write examples code, write documentation, translating text, coding short libraries, etc. Just if you know and like Pascal Language.

Set of Types, Functions and Procedures of Pashyper

Pashyper presents the set of types, functions and procedures below, for now:

integerNumeric type that receive a integer number.
charCharacter type that receive only a character.
booleanLogical type that receive special values TRUE or FALSE
realNumeric type that receive a point floating value.
stringA chain of characters. You cannot access strings as an array of char.
fileHandle a text file, for now. You cannot access typed file (see directives).
arrayArray declaration of any basic type, except file
writewrites one or more values in output stream (without CRLF).
writelnwrites one or more values in output stream (within CRLF).
readreads a value from input stream not staying CRLF.
readlnreads a value from input stream staying CRLF.
assignassigns a name to a file handle.
resetopen a file for read only.
rewritecreates a file for write. If file exists, it will be override.
closecloses a opened file.
deletedeletes a specified peace of a string.
insertinserts a specified string into another string.
valcomputes a value numeric that a string presents.
exitexits of a specified point of a procedure or function.
incincrements a integer number of a specified increment. If not specified the increment, it will 1.
decdecrements a integer number of a specified decrement. If not specified the decrement, it will 1.
randomizeinitializes the random number generator.
strputs in a variable of type string the representation of numeric value.
chdirchanges the current directory to another specified. Work just into root directory of pashyper.
runerrorsimulates an error specified. NOT IMPLEMENTED.
swapswaps two values of two variables. NOT IMPLEMENTED.
movemove a value of a variable to another variable. NOT IMPLEMENTED.
getdatereturns current date into four variables: year, month, day and day of week.
gettimereturns current time into three variables: hour, minutes, seconds.
packtimepacks date and time into a variable real. TIME NOT IMPLEMENTED.
unpacktimeunpacks a real value into six variables: year, month, day, hour, minutes and seconds.
haltstops the program at point where is called.
cgi_headerwrites a value in output stream (as writeln). Checks the presence of "content-type".
sql_connectconnects mysql database server.
sql_queryexecutes a query into mysql server and return the result.
sql_freereleases the query result returned by sql_open.
sql_closecloses the connection with mysql server.
sql_nextmove data pointer of a query result to next record.
sql_execexecutes a query into mysql server that not return result.
unloadlibnot util, yet. Unloads a dynamic library.
cgi_session_setassign a value to a field of current session.
cgi_session_clearclear current session.
cgi_session_sqlsave all current record of mysql into current session.
gph_barcodecreates a bitmap file with a bar code determined. Supports 16 bar code types.
eofreturns True if end of file was founded.
ordreturns the ordinal value numeric of parameter.
oddreturns True if the parameter is odd.
truncreturns a integer truncated value of parameter.
predreturns the predecessor of parameter.
succreturns the successor of parameter.
chrreturns a character correspondent to parameter.
copyreturns a substring of string parameter.
lengthreturns the length of a string.
posreturns the position of a string into another.
upcasereturns up case value of parameter.
locasereturns low case value of parameter.
absreturns the absolute value of parameter.
arctanreturns the arch witch tangent is the parameter.
cosreturns the cosine of parameter.
expreturns the exponential of parameter.
fracreturns the fractional part of a number.
intreturns the integer part of a number.
lnreturns the logarithm of parameter.
powerreturns the power of a number by another.
randomreturns a random number between 0 and parameter.
roundreturns the parameter rounded.
sinreturns the sine of parameter.
sqrreturns the square of a number.
sqrtreturns the square root of a number.
addrreturns the address of a variable. NOT IMPLEMENTED.
offsreturns the offset of a variable. NOT IMPLEMENTED.
sizeofreturns the size of a variable (type). NOT IMPLEMENTED
getdirreturns the current directory.
pireturns pi (π) value.
ioresultreturns last input/output error value.
formatdatereturns a string that represents a date in a human comprehensive format.
cgi_getenvreturns a value of environment variable.
cgi_queryreturns a value of a field of query_string
cgi_cookiereturns a value of a cookie.
cgi_md5_stringreturns a value of md5 encrypt algorithm of a string
cgi_md5_filereturns a value of md5 encrypt algorithm of a file
cgi_sha1_stringreturns a value of sha1 encrypt algorithm of a string
cgi_sha1_bufferreturns a value of sha1 encrypt algorithm of a string
cgi_sha1_filereturns a value of sha1 encrypt algorithm of a file
sql_eofreturns True if the pointer to result of mysql reached end.
sql_asintreturns the integer value of a field in data set of mysql.
sql_asstrreturns the string value of a field in data set of mysql.
sql_asboolreturns the boolean value of a field in data set of mysql.
sql_asrealreturns the floating value of a field in data set of mysql.
sql_astextreturns the long text value of a field in data set of mysql.
sql_asdatereturns the date value of a field in data set of mysql.
sql_datestreturns the date field value as a string value of a field in data set of mysql.
sql_rowsreturns the number of records into a data set of mysql.
sql_escapereturns a string ready to be saved into mysql database.
loadlibLoad a DLL - not implemented.
cgi_session_getreturns the value of field session specified.
cgi_temp_namereturns a temporary filename. The directory is the parameter.

PasHyPer Directives

For now, PasHyPer supports just two directives:

Compiling Pashyper - Directives

When compiling and linking the PasHyPer preprocessor, you can turn on or off the following directives:

{$DEFINE DTEQFPC}if ON, the date values are equal fpc date values else it's Pashyper values.
{$DEFINE USEMYSQL}if ON, Pashyper load mysql library.
{$DEFINE STRING256}if ON, Pashyper will use strings with 256 characters of length.
{$DEFINE TYPEDFILE}if ON, typed file will be accessible.
{$DEFINE FILEHANDLEW32}if ON, pashyper modifies free pascal output handle. Works only on MS-Windows(1).
{$DEFINE NOIOREDIRECT}if ON, pashyper output not will be into a temporary file but directly to console(2).
{$DEFINE USELOGS}if ON, pashyper will produce log file about url accesses.
{$DEFINE PT_DATENAMES}if ON then names of date and double numbers will be converted to Portuguese of Brazil.
{$DEFINE BIGWRITE}if ON then pashyper will process all text HTML making a unique program. Very fast.
{$DEFINE ADDRESSNOROT}if ON then address manager routines will be ignored.
{$DEFINE LISTLINKEDLIST}if ON then will be used a linked list as TLIST; else will be used a TLIST KOL based.
{$DEFINE USESMD5}if ON then will be used MD5 algorithm of cryptography.
{$DEFINE USESSHA1}if ON then will be used SHA1 algorithm of cryptography.
{$DEFINE BARCODE}if ON then will be used bar code module to creation of.
For PASHYPER Internal Debug
{$DEFINE DBG_HP}if ON, an internal debug is executed over preprocessor unit, writing a log file.
{$DEFINE DBG_INT}if ON then the compiler and interpreter will be debugged.
{$DEFINE DBG_SCR}if ON then the script manager will be debugged.
{$DEFINE DBG_MAC}if ON then the virtual machine will be debugged.
{$DEFINE DBG_CMP}if ON then the compiler will be debugged.
{$DEFINE DBG_SES}if ON, an internal debug is executed over session unit, writing a log file.
{$DEFINE DBG_LIT}if ON then the literal memory manager will be debugged.
{$DEFINE DBG_URL}if ON then the url converter will be debugged.
{$DEFINE DBG_DTT}if ON then the datetime manager will be debugged.
{$DEFINE DBG_PIO}if ON, an internal debug is executed over input/output unit, writing a log file.
{$DEFINE DBG_SLF}if ON, Pashyper starts GDB debug when running. Compile with -g option.
{$DEFINE DBG_BWT}if ON then the unit bigwriter will be debugged.
{$DEFINE DBG_MD5}if ON then the unit MD5 of cryptography will be debugged.
{$DEFINE DBG_SHA}if ON then unit SHA1 of cryptography will be debugged.
{$DEFINE DBG_SEC}if ON then unit of security will be debugged.
{$DEFINE DBG_BAR}if ON then unit of bar code will be debugged.
{$DEFINE SIMULATEGET}if ON, an execution of pashyper simulates a GET method. Parameters settings is in envar unit.
(1) Dependent of NOIOREDIRECT OFF.
(2) This is need to PasHyPer run under a folder without write permission.

Đ 2008 Carlos Alberto de Oliveira - carlosnatal@yahoo.com.br