global SaveLine Sep space spat set SaveLine {} set Sep { } set space { } set spat {^([ ]+)} # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # proc xcpt {} { global in Src Script scripts if {$in(comment)} { if [regsub {.*-->} $Src {} Src] { incr in(comment) -1 incr in(except) -1 } else { set Src {} } } elseif {$in(SCRIPT)} { if [regexp -nocase {(.*)} $Src {} i Src] { if {$i != {}} {append Script($scripts) $i} incr in(SCRIPT) -1 incr in(except) -1 } else { append Script($scripts) $Src set Src {} } } } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # # Interpret a chunk of text as HTML and append its formatted value to the # window. We normally get just one line at a time here. We strip off chunk # one at a time, and feed them to various routines for processing. We # distinguish mainly between three types of text chunks: # 1. White space. # 2. HTML tags. # 3. Other text. # proc docLine {w x} { global V me Cols SP Rows LC wantNL in white SaveLine scripts Script space spat Src global curD Txt TxtLen TxtMaxw if {$V>1} {set id "$me/docLine"} set Src "$SaveLine$x" set SaveLine {} if {$V>2} {puts "$id: ============================================================="} if {$V>4} {puts "$id: Src=\"$Src\""} if {$curD != $w} { if {$V>1} {puts "$id: Changing w={$w} to curD={$curD}"} set w $curD } if {$in(PRE) > 0} { if {$V>4} {puts "$id: PREformatted line."} if {$wantNL($curD) < 1} { if {$V>4} {puts "$id: $curD insert end newline (PREformatted line)"} $curD insert end \n set wantNL($curD) 0; # Note that we've inserted the newline. set LC "\n" } } else { HSP $curD $space } if {!$in(H)} { if [regexp -nocase {^} $Src] { if {$V>4} {puts "$id: Found tag"} set in(H) 1 } elseif [regexp -nocase {^} $Src] { if {$V>4} {puts "$id: Found <TITLE> tag"} set in(H) 1 } elseif [regexp -nocase {^<!--} $Src] { if {$V>4} {puts "$id: Found <!-- tag"} set in(H) 1 } elseif [regexp -nocase {^<!DOCTYPE} $Src] { if {$V>4} {puts "$id: Found <!DOCTYPE ...> tag"} set in(H) 1 } else { if {$V>4} {puts "$id: $w insert end \"$Src\""} $w insert end $Src\n incr TxtLen($w) [string length $Src] incr TxtMaxw($w) [font measure [FontName $w] $Src] if {$V>2} {puts "$id: $w now contains TxtLen=$TxtLen($w) chars of text."} return } } if {$in(except)} {xcpt} # # Chop off initial chunks of the current source line one at a time, # and decide how to display them. while {$Src != {}} { if {$V>4} {puts "$id: ==== Src=\"$Src\""} if [regexp $spat $Src i] { if {$V>4} {puts "$id: SPACES {$i} LC={$LC}"} if {$in(PRE) > 0} { if {$V>4} {puts "$id: SPACES preformatted."} Htxt $i set LC [string range $i end end] } elseif {$in(SCRIPT) > 0} { if {$V>4} {puts "$id: SCRIPT line \"$Src\""} append Script($scripts) $Src } elseif {$SP($curD) != {}} { if {$V>4} {puts "$id: SPACES converted to single space."} HSP $curD $space } else { if {$V>4} {puts "$id: SPACES ignored."} HSP $curD $space } set Src [string trimleft $Src] continue } if {$V>7} {puts "$id: Not white space."} if [regexp {^([^<& ]+)(.*)} $Src {} i Src] { if {$V>4} {puts "$id: TEXT i=\"$i\" Src=\"$Src\""} if {$in(PRE) > 0} { } elseif {$in(SCRIPT) > 0} { } else { regsub -all {[ ]+} $i { } i } if {$V>4} {puts "$id: TEXT i=\"$i\""} Htxt $i continue } if {$V>7} {puts "$id: Not text."} if [regexp {^<!--} $Src] { if {$V>4} {puts "$id: COMMENT ..."} incr in(comment) incr in(except) if [regsub {^<!--.*-->} $Src {} Src] { if {$V>4} {puts "$id: COMMENT deleted."} incr in(comment) -1 incr in(except) -1 } else { if {$V>4} {puts "$id: COMMENT not complete on this line ..."} set Src {} } continue } if {$V>7} {puts "$id: Not comment."} if [regexp {^<!--} $Src] { if {$V>1} {puts "$id: DOCTYPE ..."} if [regsub {^<!DOCTYPE.*>} $Src {} Src] { if {$V>1} {puts "$id: DOCTYPE deleted."} } else { if {$V>1} {puts "$id: DOCTYPE incomplete."} Htxt $Src set Src {} } continue } if {$V>7} {puts "$id: Not DOCTYPE."} if [regexp {^<[^>]*$} $Src SaveLine] { if {$V>4} {puts "$id: CONT incomplete HTML tag \"$SaveLine\""} set Src {} append SaveLine { } if {$V>4} {puts "$id: Save \"$SaveLine\""} continue } if {$V>7} {puts "$id: Not incomplete tag."} if [regexp {^&#([0-9]+);(.*)$} $Src {} i Src] { if {$V>4} {puts "$id: CHR i=\"$i\" Src=\"$Src\""} Htxt [Chr $i] continue } if {$V>7} {puts "$id: Not &XX; escape."} if [regexp {^&([A-Za-z0-9]+);(.*)$} $Src {} i Src] { if {$V>4} {puts "$id: CHR i=\"$i\" Src=\"$Src\""} Htxt [Chr $i] continue } if {$V>7} {puts "$id: Not &symb; escape."} if [regexp {^<([^>]+)>(.*)$} $Src {} i Src] { if {$V>4} {puts "$id: TAG i=\"$i\" Src=\"$Src\""} Tag $w [string trim $i] continue } if {$V>7} {puts "$id: Not complete tag."} if [regexp {^\ (.*)$} $Src {} Src] { if {$V>4} {puts "$id: CHR nbsp Src=\"$Src\""} Htxt { } # incr TxtLen($w) [string length $Src] if {$V>2} {puts "$id: $w now contains TxtLen=$TxtLen($w) chars of HTML text."} set LC { } continue } if {$V>7} {puts "$id: Not   escape."} if [regexp {^(&[^;]+;)(.*)$} $Src {} i Src] { if {$V>4} {puts "$id: chr i=\"$i\" Src=\"$Src\""} continue } if {$V>7} {puts "$id: Not &...; escape."} if [regexp {^(.)(.*)$} $Src {} i Src] { if {$V>4} {puts "$id: one i=\"$i\" Src=\"$Src\""} continue } if {$V>7} {puts "$id: Not single character."} if {$V>0} {puts "$id: NO PATTERN MATCHED!!!"} if {$V>0} {puts "$id: Discard Src=\"$Src\""} Src = {} } }