File: example.tcl

package info (click to toggle)
libapache2-mod-rivet 3.2.0-1
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 5,868 kB
  • sloc: xml: 8,496; tcl: 7,212; ansic: 6,959; sh: 5,030; makefile: 261; sql: 91; lisp: 78
file content (47 lines) | stat: -rw-r--r-- 994 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# we have complete access to the interpreter here, so it is best to
# run per-page code in a namespace, just like we do with .rvt pages.

proc getcode { filename } {
    set fl [ open $filename r ]
    set sourcecode [ read $fl ]
    close $fl
    regsub -all "&" "$sourcecode" "\\&" sourcecode
    regsub -all "<" "$sourcecode" "\\&lt;" sourcecode
    regsub -all ">" "$sourcecode" "\\&gt;" sourcecode
    return $sourcecode
}

if { ! [ info exists header ] } {
    set header {
	<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
	<html>
	<head>
	<title>.tcl example</title>
	</head>
	<body bgcolor="#ffffff">
    }
}

if { ! [ info exists footer ] } {
    set footer {
	</body>
	</html>
    }
}

namespace eval request {
    hgetvars
    puts $header
    puts {
	<p>This is an example of a .tcl file being processed in Rivet</p>
	<p>Here is the source code:</p>
	<hr>
	<pre>
    }
    puts [ getcode $ENVS(SCRIPT_FILENAME) ]
    puts {
	</pre>
	<hr>
    }
    puts $footer
}