#!/usr/bin/tclsh
#generate tcl/tk version of manual page
puts "proc FillManualPage \{ w \} \{"
puts "\$w.text tag configure bold -font \{Courier 12 bold\}"
puts "\$w.text tag configure underline -underline on"
set input [ open "| man -l tkalbum.1 -Tascii" ]
puts "\$w.text insert end \{"
set counter 0
while { ! [ eof $input ] } {
    set line  [ gets $input ]
    if { [ string first "\b" $line ] == -1 } {
	puts "$line"
    } else {
	set ix [ string first "\b" $line ] 
	while { $ix != -1 } {
	    puts "[string range $line 0 [ expr $ix - 2 ]]\}"
	    set line [ string range $line [ expr $ix - 1 ] end ]
	    set word ""
	    if { [ string index $line 0 ] == "\_" } {
		while { [ string index $line 0 ] == "\_"  && \
			    [ string index $line 1 ] == "\b" } {
		    append word [ string index $line 2 ]
		    set line [ string range $line 3 end ]
		}
		puts "\$w.text  insert end \{$word\} underline"
	    } else {
		while { [ string index $line 1 ] == "\b" } {
		    append word [ string index $line 2 ]
		    set line [ string range $line 3 end ]
		}
		puts "\$w.text  insert end \{$word\} bold"
	    }
	    puts -nonewline "\$w.text insert end \{"
	    set ix [ string first "\b" $line ] 
	}
	puts "$line"
    }
    incr counter
}
puts "\}\}"
exit

