File: convert_examples.tcl.in

package info (click to toggle)
libapache2-mod-rivet 2.3.3-1
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 5,156 kB
  • ctags: 1,093
  • sloc: xml: 7,696; tcl: 6,939; ansic: 5,682; sh: 4,862; makefile: 199; sql: 91; lisp: 78
file content (55 lines) | stat: -rw-r--r-- 1,482 bytes parent folder | download | duplicates (2)
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
# 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: convert_examples.tcl.in 1399019 2012-10-16 22:11:31Z mxmanghi $
#

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 "$example needs rebuild"
        
        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
    }

}