File: tree.tcl

package info (click to toggle)
tk-html3 3.0~fossil20110109-6
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 6,644 kB
  • ctags: 5,882
  • sloc: ansic: 48,994; tcl: 26,030; sh: 1,190; yacc: 161; makefile: 24
file content (41 lines) | stat: -rw-r--r-- 821 bytes parent folder | download | duplicates (5)
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

set auto_path [concat . $auto_path]
package require Tkhtml

# Procedure to return the contents of a file-system entry
proc readFile {fname} {
  set ret {}
  catch {
    set fd [open $fname]
    set ret [read $fd]
    close $fd
  }
  return $ret
}

proc print_tree {node {indent 0}} {
  if {[$node tag]=="text"} {
    if {[regexp {^ *$} [$node text]]==0} {
      puts -nonewline [string repeat " " $indent]
      puts [$node text]
    }
  } else {
    puts -nonewline [string repeat " " $indent]
    puts "<[$node tag]>"
    for {set i 0} {$i < [$node nChildren]} {incr i} {
      print_tree [$node child $i] [expr $indent+2]
    }
    puts -nonewline [string repeat " " $indent]
    puts "</[$node tag]>"
  }
}

html .h
.h parse [readFile [lindex $argv 0]]
.h tree build
set root [.h tree root]
print_tree $root

exit