File: helpdoc.tcl

package info (click to toggle)
espresso 5.1%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 146,004 kB
  • ctags: 17,245
  • sloc: f90: 253,041; sh: 51,271; ansic: 27,494; tcl: 15,570; xml: 14,508; makefile: 2,958; perl: 2,035; fortran: 1,924; python: 337; cpp: 200; awk: 57
file content (226 lines) | stat: -rw-r--r-- 5,385 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
set dir [file dirname [info script]]
lappend auto_path $dir [file join $dir .. .. GUI Guib lib]

package require tclu 0.9
package require struct::tree  2.1
package require struct::stack 1.3
package require textutil

namespace eval ::helpdoc {
    variable dir [file dirname [info script]]

    # schema-related variables

    variable attrArr; # stores all about attributes
    variable elemArr; # stores all about elements
    variable defineArr; # stores all about define's

    variable elemList ""
    variable itemList ""

    variable state    
    array set state {
	depth       0
	rootVisited 0
	rootElem    ""
    }

    variable stackArr    
    array set stackArr [subst {
	repetition  [::struct::stack]
	optional    [::struct::stack]
	interleave  [::struct::stack]
	currentElem [::struct::stack]
    }]

    $stackArr(repetition)  push 1; # decimal-digit | + | * | ? (meaning integer-number of times, one-or-more, zero-or-more, zero-or-one)
    $stackArr(optional)    push 0
    $stackArr(interleave)  push 0
    $stackArr(currentElem) push ""

    # stack & tree for parsing input definitions

    variable tree  ""
    variable stack [::struct::stack]

    # output-related

    variable indentNum 3
    variable txtDepth 0
    variable fid
    variable head
    variable rbd_var 
    variable rbd_stack 
    variable rbd_info
    variable robodoc  [auto_execok robodoc]
    variable xsltproc [auto_execok xsltproc]

    # TXT variables
    variable vargroup 0
    variable dimensiongroup 0
    variable colgroup 0
    variable rowgroup 0
}

namespace eval ::helpdoc::tag {}
namespace eval ::helpdoc::schema {}
source [file join $::helpdoc::dir readSchema.tcl]

proc ::helpdoc::openOutputs {file} {
    variable fid 
    variable head

    set head [file rootname $file]

    set fid(xml) [open $head.xml w]
    set fid(txt) [open $head.txt w]

    # currently disabled
    #set fid(rbd) [open $head.rbd w]
    
    puts $fid(xml) {<?xml version="1.0" encoding="ISO-8859-1"?>}
    puts $fid(xml) {<?xml-stylesheet type="text/xsl" href="input_xx.xsl"?>}
    puts $fid(xml) {<!-- FILE AUTOMATICALLY CREATED: DO NOT EDIT, CHANGES WILL BE LOST -->
    }

    puts $fid(txt) "*** FILE AUTOMATICALLY CREATED: DO NOT EDIT, CHANGES WILL BE LOST ***\n"
    
    #puts $fid(rbd) "# *** FILE AUTOMATICALLY CREATED: DO NOT EDIT, CHANGES WILL BE LOST ***\n"
}

proc ::helpdoc::writeOutputs {} {
    variable tree 
    variable head 
    variable fid
    variable robodoc 
    variable xsltproc 
    variable rbd_info

    #$tree destroy
    
    puts ""
    foreach fmt [array names fid] {
	puts "File $head.$fmt has been written."
	close $fid($fmt)
    }
    
    # run XSLTPROC

    if { $xsltproc != "" } {
	catch [list exec $xsltproc $head.xml > $head.html]    
	puts "File $head.html has been written."
    }
    
    # run ROBODOC 

    if { 0 } {
	# currently disbabled

	if { $robodoc != "" } {
	    if { ! [file isdirectory $head.d] } {
		file mkdir $head.d
	    } else {
		foreach file [glob -nocomplain $head.d/*.html] {
		    file delete $file
		}
	    }
	    if { ! [file isdirectory $head.robodoc] } {
		file mkdir $head.robodoc
	    }
	    
	    file copy -force $head.rbd $head.robodoc/
	    
	    catch {exec $robodoc --doc $head.d/ --src $head.robodoc/ --documenttitle "Description of $rbd_info(program) input file"}
	    
	    if { [file exists $head.d/toc_index.html] } {
		file copy -force $head.d/toc_index.html $head.d/index.html
		puts "File $head.d/index.html has been written."
	    }	
	}
    }
}


proc ::helpdoc::readSchema {} {
    puts "\n***\n*** Parsing the helpdoc.schema\n***\n"
    namespace eval schema { ::source [file join $basedir helpdoc.schema] }

    puts "\n\n***\n*** Assigning ref's\n***\n"
    assignRefs_
    
    puts "\n\n***\n*** Creating tags commands\n***\n"
    createTagCmds_
}



proc ::helpdoc::print_xml {tree node action} {
    variable fid
    
    set depth [$tree depth $node]

    set tag        [$tree get $node tag]
    set attributes [getFromTree $tree $node attributes]
    set content    [getFromTree $tree $node text]
       
    xml_tag_${action} $tag $attributes $content $depth
}

proc ::helpdoc::print_txt {tree node action} {
    variable fid
    
    set depth [$tree depth $node]

    set tag        [$tree get $node tag]
    set attributes [getFromTree $tree $node attributes]
    set content    [getFromTree $tree $node text]

    

    txt_tag_${action} $tree $node $tag $attributes $content [expr $depth - 1]

    # currently disabled:

    # robodoc
    #rbd_tag_${action} $tag $attributes $content $depth
}



proc ::helpdoc::process {fileList} {
    variable tree
    variable vargroup 
    variable dimensiongroup 
    variable mode

    # first read the schema (and load tag's commands)
    readSchema 

    #puts "tag commands: [info procs ::helpdoc::tag::*]"

    foreach file $fileList {

	set vargroup 0
	set dimensiongroup 0
	
	if { [file exists $file] } {	
	    
	    openOutputs $file	

	    puts "\n\n***\n*** Parsing definition file: $file\n***\n"
	    namespace eval tag [list source $file]	    
	    
	    set mode default

	    $tree walkproc root -order both print_xml
	    $tree walkproc root -order both print_txt
	    writeOutputs

	    $tree destroy
	    unset mode
	} else {
	    puts stderr "file [file join [pwd] $file] does not exists : aborting ..."	    
	    exit 1
	}
    }
}