webviewer.tcl File Reference

Go to the source code of this file.

Functions/Subroutines

autoproxy::init ret webview (type url)
ret parser (type outvar, type tag, type end, type attr, type text)
ret fetchurl (type url)
ret Display (type msg)
ret Error (type msg)

Variables

package require htmlparse
package require http
package require autoproxy

Function Documentation

ret Display ( type  msg  ) 

Definition at line 103 of file webviewer.tcl.

Referenced by TextInitialize().

00103                         {
00104     if {[string length [package provide Tk]] > 0} {
00105         toplevel .dlg -class Dialog
00106         wm title .dlg "webview output."
00107         text .dlg.txt -yscrollcommand {.dlg.sb set}
00108         scrollbar .dlg.sb -command {.dlg.txt yview}
00109         button .dlg.b -command {destroy .dlg} -text Exit -underline 1
00110         .dlg.txt insert 0.0 $msg
00111         bind .dlg <Control-F2> {console show}
00112         bind .dlg <Escape> {.dlg.b invoke}
00113         grid .dlg.txt .dlg.sb -sticky news
00114         grid .dlg.b  - -sticky e -pady {3 0} -ipadx 4
00115         grid rowconfigure .dlg 0 -weight 1
00116         grid columnconfigure .dlg 0 -weight 1
00117         tkwait window .dlg
00118     } else {
00119         puts $msg
00120     }
00121 }

Here is the caller graph for this function:

ret Error ( type  msg  ) 

Definition at line 123 of file webviewer.tcl.

Referenced by fetchurl(), and rdate().

00123                       {
00124     if {[string length [package provide Tk]] > 0} {
00125         tk_messageBox -title "webviewer error" -icon error -message $msg
00126     } else {
00127         puts stderr $msg
00128     }
00129     exit 1
00130 }

Here is the caller graph for this function:

ret fetchurl ( type  url  ) 

Definition at line 67 of file webviewer.tcl.

References Error(), error(), and state.

Referenced by webview().

00067                          {
00068     set html ""
00069     set err ""
00070     set tok [http::geturl $url -timeout 30000]
00071     if {[string equal [http::status $tok] "ok"]} {
00072         if {[http::ncode $tok] >= 500} {
00073             set err "server error: [http::code $tok]"
00074         } elseif {[http::ncode $tok] >= 400} {
00075             set err "authentication error: [http::code $tok]"
00076         } elseif {[http::ncode $tok] >= 300} {
00077             upvar \#0 $tok state
00078             array set meta $state(meta)
00079             if {[info exists meta(Location)]} {
00080                 return [fetchurl $meta(Location)]
00081             } else {
00082                 set err [http::code $tok]
00083             }
00084         } else {
00085             set html [http::data $tok]
00086         }
00087     } else {
00088         set err [http::error $tok]
00089     }
00090     http::cleanup $tok
00091 
00092     if {[string length $err] > 0} {
00093         Error $err
00094     }
00095     return $html
00096 }

Here is the call graph for this function:

Here is the caller graph for this function:

ret parser ( type  outvar,
type  tag,
type  end,
type  attr,
type  text 
)

Definition at line 45 of file webviewer.tcl.

References h, and p().

Referenced by webview().

00045                                                                         {
00046     upvar \#0 $outvar out
00047     set tag [string tolower $tag]
00048     set end [string length $end]
00049     if {$end == 0} {
00050         if {[string equal "hmstart" $tag]} {
00051             set out ""
00052         } elseif {[regexp {h(\d+)} $tag -> level]} {
00053             append out "\n\n" [string repeat * $level] " " $text
00054         } elseif {[lsearch -exact {p pre td} $tag] != -1} {
00055             append out "\n" $text
00056         } elseif {[lsearch -exact {a span i b} $tag] != -1} { 
00057             append out $text
00058         }
00059     }
00060 }

Here is the call graph for this function:

Here is the caller graph for this function:

autoproxy::init ret webview ( type  url  ) 

Definition at line 28 of file webviewer.tcl.

References error(), fetchurl(), htmlparse, and parser().

00028                         {
00029     set html [fetchurl $url]
00030     if {[string length $html] > 0} {
00031         variable parsed ""
00032         htmlparse::parse -cmd [list parser [namespace current]::parsed] $html
00033         set parsed [htmlparse::mapEscapes $parsed]
00034         set parsed [regsub -all -line "\n{2,}" $parsed "\n\n"]
00035         Display $parsed
00036     } else {
00037         Error "error: no data available from \"$url\""
00038     }
00039 }

Here is the call graph for this function:


Variable Documentation

package require autoproxy

Definition at line 18 of file webviewer.tcl.

package require htmlparse

Definition at line 16 of file webviewer.tcl.

Referenced by webview().

package require http

Definition at line 17 of file webviewer.tcl.


Generated on 21 Sep 2010 for Gui by  doxygen 1.6.1