ppC++(acronym for "ppC++ preprocessed C++"), is an HTML-preprocessed
C/C++ programming language. This preprocessor lets you write server-side
programs in C++ inside your HTML code and brings new additional features
which make web programming easier.
ppC++ was developed for those, who
need high performance, stability and harmony in simple HTML enviroment.
For those, who know C or C++ and have some skills in HTML, doesn't wish to
learn new interpreter languages like Perl, PHP or ASP and wants to start
creating dynamic web-pages immediately. If you are C/C++ programmer, you
would start to develop a full-featured dynamic server pages of full value
and ease of HTML tags in a few hours. The main goal of ppC++ is to bring
classic C/C++ adopted in simple and rapid development of dynamic
web pages.
ppC++ lets you use powerfull, stable and fast C++ in simple
web scripts and hides a lot of routine cgi programming.
How does it work? Here is an example:
As you see, it looks like a regular HTML page, but you can find
one line written in C++ between special tags.
Now save this file somwhere in your cgi-bin directory
as, for example, "hello.ppc" and run it from
ppC++ web compiler or simply
type the script's path and name in your browser address
line(only in UNIX) - it will create
standalone cgi executable binary file "hello.ppc.cgi" in the
same directory that outputs to client browser:
Now
"hello.ppc.cgi" is the independent compiled cgi-programm
and doesn't require neither its "ppc" source, nor ppC++ compiler.
And you don't have to worry if someone could download your original
"hello.ppc"
source code - if client will request it, web-server will treat
ppc-source as an executable and will return 500 server error.
·2.2 Installation
First you need to install web-server.
Apache >2.0 is the only server now that
supports ppC++(if somebody could cross it to other servers,
please let me know). If you don't know what is
web server and how to configure it, download one of easy-to-install
distributions of server, like
XAMPP(windows/linux).
When you have configured and started your server,
go to download page.
·3.1 Functions, classes and global variables
Functions, classes and global variables can be declared anywhere,
for example in
addittional standard C++ header files, the same or the other ppc scripts,
and this constructions will be accessable anywhere in the script.
The simplest way is to write functions or classes in one file:
As it seen from example, the function can be declared after it
was called.
OK, the function works, but doesn't it look a
little cumbersome in this HTML enviroment? In this case ppC++ lets
you write much more grace code:
The same story about classes/structs:
To use global
variables or class/srtuct objects(those,
which must be accessible to functions or classes) you have to define
it with special keyword: global (it is sacrifice for
main()-function absence):
The variable must be defined as a global, for
example this will not work:
And of course you can use standard C/C++ library fuctions/classes -
simply by including their header files:
Preprocessor lets you include your own native C/C++ files:
·3.2 Control Structures The control structures(like while, for, if-else) are exactly
the same as in C/C++, but also could be optimized for HTML.
For example to get this result
in your browser window, you can write:
but ppC++ can offer another method for writing more "HTMLable" code:
·3.3 HTTP request variables(GET and POST)
Now we can write dynamic HTML pages, but how to make our pages
interactive? To use HTTP request variables, which can be sent to server via
"<form>" or URL HTTP request string.
When the following form is submitted
or "script.ppc.cgi?var1=value1&var2=value2" is requested,
ppC++ will create the variables "var1" and "var2" as members
of ppc - special pseudo class object, which hides and encapsulates
all the cgi routine work:
If it is submitted, in script.ppcppc.get("var1") will return value and
ppc.post("var1") will return another_value.
In this case ppc.var1 has priority to POST method.
Remember, the type of all the HTTP request variables from "ppc"
return "string" type
, though it is actually
not string object - the string's common functions and properties are not
accessible here.
·3.4 Cookies
All the cookie manipulations can be made via "cookie" pseudo-class object.
cookie.set("name=value; EXPIRES=date; PATH=path; DOMAIN=domain_name; SECURE")
will send the cookie to a browser.
Afterwards (in the following pages) you can get the cookie as a variable -
member of a "cookie".
The following page sets the cookie "foo" and offers the link to
the second page:
"Page2.ppc" shows the cookie value. If it is absent, an empty string
will be shown:
"Page3.ppc" also has an acces to cookie.foo:
To erease the cookie value, simply write
cookie.set("foo=") and
client browser will remove this variable.
Remember, the type of all the variables from "cookie"
return "string" type
, though it is actually
not string object - the string's common functions and properties are not
accessible here.
But if you will try to compile "second_file.ppc" alone, you
get a fatal error: variable "a" undeclared.
Included ppc files also can contain functions, structs and classes
in addition to main code, which
runs immediately. You can even include the same ppc file more than
once without expecting name conflicts:
For example if this file called "script.ppc",
<;=ppc.SCRIPT;> will return
"script.ppc.cgi"(Windows) or "script.ppc"(UNIX).
Let's check it:<br>
<;if(ppc.SCRIPT == "script.ppc"){;>
Yes! This file is "<;=ppc.SCRIPT;>"!
<;}else{;>
No, this file is "<;=ppc.SCRIPT;>", not "script.ppc"...
<;};>
Returns a string in which all non-alphanumeric characters except -_.
have been replaced with a percent (%) sign followed by two hex digits.
It is encoded the same way that the posted data from a WWW form is
encoded.
<;
= ppc.urlencode("x = a * b"); // will print "x%20%3D%20a%20%2A%20b".
// if I will try to send "x = a * b" through HTTP request string - it may
// be parsed wrong, because of spaces and non-alphanumeric characters.
// If i send it encoded, the content will be saved:
;><br>
<a href='<;=ppc.SCRIPT;>?variable=x = a * b' >
send a variable(unsafe).
</a><br>
<a href='<;=ppc.SCRIPT;>?variable=<;=ppc.urlencode("x = a * b");>'>
send a variable(safe).
</a><br>
<;if(ppc.variable != ""){;>
expression: <;=ppc.variable;>
<;};>
· name - name of cookie.
· value - value of cookie.
· EXPIRES=date - the cookie will live until date.
By default cookie dies in the moment of browser closing.
· PATH=path - the path of cookies visibility.
· DOMAIN=domain_name - domain of cookies visibility.
· SECURE - shows if the cookie is sent via secure shell.