Version 2 of THP

Updated 2005-11-26 00:08:44

CAU 25-Nov-2005: I finally got around to putting this page together. Something I've been meaning to do for at least 6 months.

THP is a way of embedding Tcl into HTML.

The requirements were quite straight forward. Some features are fairly obvious, others less so:

  • PHP, ASP and the like all allow the web developer to embed code directly into the markup language. I wanted to be able this with my preferred scripting language - Tcl.
  • I wanted to ensure that only complete commands were executed so simply using eval was out.
  • I wanted to be able to embed bits of HTML inside the code directly such as
 <%tcl while {$i<10} { %><B>Repeated line</B><BR><%tcl } %>
  • I wanted to be able to include other files by preparsing them (or pre-interpreting).
  • I wished to make the code as neat and fast as I could without making it unreadable (not sure if I've achieved either, you be the judge).
  • The code should be platform, server and client independent.
  • Using THP must be very easy.

Why THP? Well, it's a play on the PHP name - (T)cl (H)ypertext (P)reprocessor

I've been using THP now for a little while, tweaking where necessary, and think that it generally fits what it was supposed to do.

THP has been tested on:

  • Linux with Apache using both the standard interpreter (tclsh) and tclkit.
  • Windows XP/Server2003 with Tclhttpd using and IIS using tclsh and tclkit.
  • Windows XP/Server2003 with IIS and THP wrapped as a starpack.

I had some fun putting the starpack version together and figuring out IIS for the first time. Getting THP working with Tclhttpd outside of the cgi-bin directory was a challenge too, but it works a treat! ...more details to follow.

THP evaluates everything in an interp before returning any resulting HTML to the client. I've aliased the "puts" command to give more control (THP can be used in debug mode on the command line using filenames as arguments) and it removes the need to use "puts -nonewline" frequently. There's also an "include" command which is more flexible than "source" or "open" to include the contents of anthother script or text file at that point in the markup.

THP also reads a file named .thprc (or thp.ini on windows platforms) and interprets this before anything else, allowing the developer to set variables or redirects quite easily.

Check out a description and example at [L1 ]


See also: