File: convert_examples.tcl.in

package info (click to toggle)
libapache2-mod-rivet 3.2.2-1
  • links: PTS
  • area: main
  • in suites: bookworm
  • size: 6,296 kB
  • sloc: xml: 8,554; tcl: 7,568; ansic: 7,094; sh: 5,017; makefile: 195; sql: 91; lisp: 78
file content (56 lines) | stat: -rw-r--r-- 1,458 bytes parent folder | download | duplicates (4)
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
48
49
50
51
52
53
54
55
56
# convert_examples.tcl --
#
#
# reads the examples dir, checks if a file has been already converted
# in <target-dir> and compares their mtimes. If the file in
# <source-dir> is more recent the target dir is recreated.

# The script uses Rivet's escape_sgml_chars to convert examples code
# into text suitable to be inclued and displayed in XML/XHTML 
# documentation

# NOTICE: This script requires Rivet, its scripts and
# libraries to be in the auto_path.

# usage:
#
# tclsh ./convert_examples
#
# $Id$
#

lappend auto_path @RIVET_TCL_TARGET@
lappend auto_path [file join @RIVET_TCL_TARGET@ rivet-tcl]

package require rivetlib

set source_dir examples
set target_dir examples-sgml

if {![info exists source_examples]} {
	set source_examples [glob [file join $source_dir *.*]]
	puts "escaping $source_examples to SGML compatible form"
}

foreach example $source_examples {

    set exam_name [file tail $example]
    set example_sgml [file join $target_dir $exam_name]

    set example_sgml_exists [file exists $example_sgml]

    if {!$example_sgml_exists || \
        ([file mtime $example] > [file mtime $example_sgml])} { 

        puts -nonewline "$example needs to be escaped..."
        
        set example_text [string trim [::rivet::read_file $example]]

        set example_sgml_fid [open $example_sgml w+]
        puts $example_sgml_fid [::rivet::escape_sgml_chars $example_text]
        close $example_sgml_fid
        puts "done"
    }

}