| •1 |
#!/usr/bin/wish -f |
| 2 |
|
| 3 |
# |
| 4 |
# dns_browse |
| 5 |
# Copyright (C) 1997 by John Heidemann |
| 6 |
# $Id: dns_browse,v 1.25 2002/05/13 16:43:24 johnh Exp $ |
| 7 |
# |
| 8 |
# This program is free software; you can redistribute it and/or |
| 9 |
# modify it under the terms of the GNU General Public License |
| 10 |
# as published by the Free Software Foundation; either version 2 |
| 11 |
# of the License, or any later version. |
| 12 |
# |
| 13 |
# This program is distributed in the hope that it will be useful, |
| 14 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
# GNU General Public License for more details. |
| 17 |
# |
| 18 |
# You should have received a copy of the GNU General Public License |
| 19 |
# along with this program; if not, write to the Free Software |
| 20 |
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 21 |
# |
| 22 |
|
| •23 |
global dns_tree types |
| 24 |
set dns_tree "dns_tree" |
| 25 |
set prog "dns_browse" |
| 26 |
set maximal_types {A CNAME HINFO LOC MX NS PTR TXT} |
| 27 |
set default_types {A CNAME NS TXT} |
| 28 |
set user_types {} |
| 29 |
set required_types {i iz m mx} |
| 30 |
set www_hosts_only 0 |
| 31 |
|
| 32 |
proc usage {} { |
| •33 |
global prog dns_tree |
| 34 |
puts stderr "usage: $prog \[-t TYPE ...\] starting_domain_name" |
| 35 |
puts stderr {options: |
| 36 |
-t TYPE show only records of these TYPE (repeat for multiple types) |
| 37 |
(the ``all'' type does everything I know about) |
| 38 |
-w match only web hosts |
| 39 |
} |
| •40 |
puts stderr "Requires $dns_tree to be in the path." |
| 41 |
exit 1 |
| 42 |
} |
| 43 |
|
| 44 |
# toggle_window is from nam-1 |
| 45 |
proc toggle_window w { |
| 46 |
if ![winfo exists $w] { build$w $w } |
| 47 |
global created$w |
| 48 |
if ![info exists created$w] { |
| 49 |
set created$w 1 |
| 50 |
wm transient $w . |
| 51 |
update idletasks |
| 52 |
set x [winfo rootx .] |
| 53 |
set y [winfo rooty .] |
| 54 |
incr y [winfo height .] |
| 55 |
incr y -[winfo reqheight $w] |
| 56 |
incr y -20 |
| 57 |
# adjust for virtual desktops |
| 58 |
incr x [winfo vrootx .] |
| 59 |
incr y [winfo vrooty .] |
| 60 |
if { $y < 0 } { set y 0 } |
| 61 |
if { $x < 0 } { |
| 62 |
set x 0 |
| 63 |
} else { |
| 64 |
set right [expr [winfo screenwidth .] - \ |
| 65 |
[winfo reqwidth $w]] |
| 66 |
if { $x > $right } { |
| 67 |
set x $right |
| 68 |
} |
| 69 |
} |
| 70 |
wm geometry $w +$x+$y |
| 71 |
wm deiconify $w |
| 72 |
} elseif [winfo ismapped $w] { |
| 73 |
wm withdraw $w |
| 74 |
} else { |
| 75 |
wm deiconify $w |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
# |
| 80 |
# formatted_text is stolen from dontspace |
| 81 |
# <http://www.isi.edu/~johnh/SOFTWARE/JACOBY/> |
| 82 |
# (with permission :-) |
| 83 |
# |
| 84 |
proc formatted_text {w text} { |
| 85 |
# NEEDSWORK: font selection should be configurable. |
| 86 |
# |
| 87 |
# If you use this code elsewhere, please follow two conscious |
| 88 |
# style choices. First, wide things are hard to read |
| 89 |
# (50 chars is about the most reasonable---consider newspaper |
| 90 |
# columns). Second, we allow the user to resize the window. |
| 91 |
# (The user should always have control, even to do stupid things.) |
| 92 |
# |
| 93 |
frame $w.f |
| 94 |
|
| 95 |
set wt $w.f.t |
| 96 |
text $wt \ |
| 97 |
-relief raised -bd 2 -yscrollcommand "$w.f.s set" \ |
| 98 |
-setgrid true -wrap word \ |
| 99 |
-width 60 -padx 4 -pady 4 \ |
| •100 |
-font -*-Times-Medium-R-*-14-* |
| 101 |
set defFg [lindex [$wt configure -foreground] 4] |
| 102 |
set defBg [lindex [$wt configure -background] 4] |
| •103 |
$wt tag configure italic -font -*-Times-Medium-I-Normal-*-14-* |
| 104 |
$wt tag configure computer -font -*-Courier-Medium-R-Normal-*-12-* |
| 105 |
$wt tag configure big -font -*-Times-Bold-R-Normal-*-18-* |
| 106 |
$wt tag configure reverse -foreground $defBg -background $defFg |
| 107 |
pack $wt -side left -expand 1 -fill both |
| 108 |
|
| 109 |
set ws $w.f.s |
| 110 |
scrollbar $ws -relief flat -command "$w.f.t yview" |
| 111 |
pack $ws -side right -expand yes -fill both |
| 112 |
|
| 113 |
pack $w.f |
| 114 |
|
| 115 |
# |
| 116 |
# Scan the text for tags. |
| 117 |
# |
| 118 |
$wt mark set insert 0.0 |
| 119 |
set t $text |
| 120 |
while { [regexp -indices {<([^@>]*)>} $t match inds] == 1 } { |
| 121 |
set start [lindex $inds 0] |
| 122 |
set end [lindex $inds 1] |
| 123 |
|
| 124 |
set keyword [string range $t $start $end] |
| 125 |
# puts stderr "tag $keyword found at $inds" |
| 126 |
|
| 127 |
# insert the left hand text into the thing |
| 128 |
set oldend [$wt index end] |
| 129 |
$wt insert end [string range $t 0 [expr $start-2]] |
| 130 |
formatted_text_purge_all_tags $wt $oldend insert |
| 131 |
|
| 132 |
# check for begin/end tag |
| 133 |
if { [string range $keyword 0 0] == "/" } { |
| 134 |
# end region |
| 135 |
set keyword [string trimleft $keyword "/"] |
| 136 |
if { [info exists tags($keyword)] == 0 } { |
| 137 |
error "end tag $keyword without beginning" |
| 138 |
} |
| 139 |
$wt tag add $keyword $tags($keyword) insert |
| 140 |
# puts stdout "tag $keyword added from $tags($keyword) to [$wt index insert]" |
| 141 |
unset tags($keyword) |
| 142 |
} else { |
| 143 |
if { [info exists tags($keyword)] == 1 } { |
| 144 |
error "nesting of begin tag $keyword" |
| 145 |
} |
| 146 |
set tags($keyword) [$wt index insert] |
| 147 |
# puts stdout "tag $keyword begins at [$wt index insert]" |
| 148 |
} |
| 149 |
|
| 150 |
# continue with the rest |
| 151 |
set t [string range $t [expr $end+2] end] |
| 152 |
} |
| 153 |
set oldend [$wt index end] |
| 154 |
$wt insert end $t |
| 155 |
formatted_text_purge_all_tags $wt $oldend insert |
| 156 |
# |
| 157 |
# Disable the text so the user can't mess with it. |
| 158 |
# |
| 159 |
$wt configure -state disabled |
| 160 |
} |
| 161 |
proc formatted_text_purge_all_tags {w start end} { |
| 162 |
# remote any bogus tags |
| 163 |
# puts stderr "Active tags at $start are [$w tag names $start]" |
| 164 |
foreach tag [$w tag names $start] { |
| 165 |
$w tag remove $tag $start $end |
| 166 |
} |
| 167 |
} |
| 168 |
|
| 169 |
proc build_formatted_text {w t} { |
| 170 |
global prog |
| 171 |
if [winfo exists $w] { return } |
| 172 |
toplevel $w |
| 173 |
bind $w <Enter> "focus $w" |
| 174 |
wm withdraw $w |
| 175 |
wm iconname $w "$prog: about" |
| 176 |
wm title $w "$prog: about" |
| 177 |
|
| 178 |
frame $w.frame -borderwidth 2 -relief raised |
| 179 |
formatted_text $w.frame $t |
| 180 |
|
| 181 |
button $w.frame.ok -text " Dismiss " -borderwidth 2 -relief raised \ |
| 182 |
-command "wm withdraw $w" |
| 183 |
pack $w.frame.ok -pady 6 -padx 6 -anchor e |
| 184 |
|
| 185 |
pack $w.frame -expand 1 -fill both |
| 186 |
} |
| 187 |
|
| 188 |
proc build.help w { |
| 189 |
build_formatted_text $w { |
| 190 |
<big>dns_browse help</big> |
| 191 |
|
| 192 |
The main pane shows a DNS hierarchy with indentation. |
| 193 |
|
| 194 |
+/- in the first column indicates a level which can be expanded or contracted. |
| 195 |
+? in the second column indicates a level that can be expanded but hasn't been tried yet. |
| 196 |
|
| 197 |
Button-1 expands or contracts a level of the hierarchy. |
| 198 |
Button-2 opens a new window showing only the clicked-on item and its children. |
| 199 |
Button-3 prints out some debugging information (but you're not supposed to know that :-). |
| 200 |
|
| 201 |
Multiple zones can be downloaded in parallel, but an in-progress zone cannot be contracted. |
| 202 |
|
| 203 |
Record types: |
| 204 |
lower-case records are internal: i)informational, e)rror messages, iz) internal ``zones'' (hierarchy levels), m)essages. |
| 205 |
|
| 206 |
Plans: clicking on www A/CNAMEs links should invoke a real web browser. |
| 207 |
|
| 208 |
Known bugs: dns_tree (invoked to expand sub-levels) can hang due to bogus servers, not all records are supported. Changing types and re-displaying a level deosn't change what's displayed. Zones speaking for things outside of their zone don't work correctly. |
| 209 |
} |
| 210 |
} |
| 211 |
|
| 212 |
proc build.about w { |
| 213 |
build_formatted_text $w { |
| 214 |
<big>dns_browse</big> |
| 215 |
|
| 216 |
Copyright (c) 1997 by John Heidemann ([email protected]). |
| 217 |
|
| 218 |
A hack in two movements. |
| 219 |
|
| 220 |
The most recent version should be available at http://www.isi.edu/~johnh/SOFTWARE/DNS/index.html. |
| 221 |
|
| 222 |
<small> |
| 223 |
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or any later version. |
| 224 |
|
| 225 |
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| 226 |
|
| 227 |
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 228 |
</small> |
| 229 |
} |
| 230 |
} |
| 231 |
|
| 232 |
proc show_info {w t} { |
| 233 |
global options |
| 234 |
set wid [widget_to_wid $w] |
| 235 |
if {![info exists options($wid,info_next_id)]} { |
| 236 |
set options($wid,info_next_id) 0 |
| 237 |
} |
| 238 |
set id [incr options($wid,info_next_id)] |
| 239 |
set options($wid,info_active_id) $id |
| 240 |
$options($wid,info) configure -text $t |
| 241 |
update |
| 242 |
return $id |
| 243 |
} |
| 244 |
|
| 245 |
proc show_timed_info_expire {w id} { |
| 246 |
global options |
| 247 |
set wid [widget_to_wid $w] |
| 248 |
if {$options($wid,info_active_id) == $id} { |
| 249 |
show_info "" |
| 250 |
} |
| 251 |
} |
| 252 |
|
| 253 |
# flash a message, then hide it after a while |
| 254 |
proc show_timed_info {w time text} { |
| 255 |
global options |
| 256 |
set id [show_info $w $text] |
| 257 |
after [expr 1000*$time] "show_timed_info_expire $w $id" |
| 258 |
update |
| 259 |
} |
| 260 |
|
| 261 |
proc widget_to_wid w { |
| 262 |
set second_dot [string first "." [string range $w 1 end]] |
| 263 |
if {$second_dot != -1} { |
| 264 |
set w [string range $w 2 [expr $second_dot]] |
| 265 |
} else { |
| 266 |
set w [string range $w 2 end] |
| 267 |
} |
| 268 |
return $w |
| 269 |
} |
| 270 |
|
| 271 |
proc show_all_types wid { |
| 272 |
global maximal_types options |
| 273 |
foreach type $maximal_types { |
| 274 |
set options($wid,show_$type) 1 |
| 275 |
} |
| 276 |
} |
| 277 |
|
| 278 |
proc build_menu_with_binding {binding_w m label state key ul cmd} { |
| 279 |
$m add command -label $label -state $state -accelerator "^$key" -underline $ul -command $cmd |
| 280 |
bind $binding_w <Meta-$key> $cmd |
| 281 |
bind $binding_w <Control-$key> $cmd |
| 282 |
} |
| 283 |
|
| 284 |
proc build_menus {w binding_w dir} { |
| 285 |
global options |
| 286 |
|
| 287 |
set wid [widget_to_wid $w] |
| 288 |
|
| 289 |
frame $w.menu -relief groove -bd 2 |
| 290 |
pack $w.menu -side top -fill x |
| 291 |
|
| 292 |
set padx 4 |
| 293 |
|
| 294 |
set mb $w.menu.file |
| 295 |
set m $mb.m |
| 296 |
menubutton $mb -text "File" -menu $m -underline 0 \ |
| 297 |
-borderwidth 1 |
| 298 |
menu $m |
| 299 |
build_menu_with_binding $binding_w $m "Open..." disabled o 0 {} |
| 300 |
build_menu_with_binding $binding_w $m "Duplicate" disabled d 0 {} |
| 301 |
build_menu_with_binding $binding_w $m "Close" normal w 0 "after idle {destroy $w}" |
| 302 |
$m add separator |
| 303 |
build_menu_with_binding $binding_w $m "Quit" normal q 0 {exit 0} |
| 304 |
|
| 305 |
pack $mb -side left -padx $padx |
| 306 |
|
| 307 |
set mb $w.menu.types |
| 308 |
set m $mb.m |
| 309 |
menubutton $mb -text "Types" -menu $m -underline 0 \ |
| 310 |
-borderwidth 1 |
| 311 |
menu $m |
| 312 |
# also UINFO WKS |
| 313 |
global maximal_types |
| 314 |
foreach type $maximal_types { |
| 315 |
$m add checkbutton -label $type -variable options($wid,show_$type) |
| 316 |
} |
| 317 |
$m add separator |
| 318 |
$m add command -label "All" -command "show_all_types $wid" |
| 319 |
pack $mb -side left -padx $padx |
| 320 |
|
| 321 |
set mb $w.menu.options |
| 322 |
set m $mb.m |
| 323 |
menubutton $mb -text "Options" -menu $m -underline 0 \ |
| 324 |
-borderwidth 1 |
| 325 |
menu $m |
| 326 |
$m add checkbutton -label "Hide new iz's" -variable options($wid,hide_new_izs) |
| 327 |
$m add checkbutton -label "Disable safety checks" -variable options($wid,no_safety) |
| 328 |
$m add checkbutton -label "Show only web hosts" -variable options($wid,www_hosts_only) |
| 329 |
pack $mb -side left -padx $padx |
| 330 |
|
| 331 |
set info $w.menu.info |
| 332 |
set options($wid,info) $info |
| 333 |
label $info -text "" |
| 334 |
pack $info -side left -padx $padx |
| 335 |
|
| 336 |
set ad $w.menu.ad |
| 337 |
label $ad -text " dns_browse: $dir " -relief groove |
| 338 |
pack $ad -side left -padx $padx -expand 1 |
| 339 |
|
| 340 |
set mb $w.menu.help |
| 341 |
set m $mb.m |
| 342 |
menubutton $mb -text "Help" -menu $m -underline 0 \ |
| 343 |
-borderwidth 1 |
| 344 |
menu $m |
| 345 |
$m add command -label "Help" -command {toggle_window .help} |
| 346 |
$m add command -label "About dns_browse" -command {toggle_window .about} |
| 347 |
pack $mb -side right -padx $padx |
| 348 |
} |
| 349 |
|
| 350 |
proc text_matching_tag {w index head} { |
| 351 |
set depth -1 |
| 352 |
foreach tag [$w tag names $index] { |
| 353 |
if [string match "$head*" $tag] { |
| 354 |
set depth [string range $tag [string length $head] end] |
| 355 |
break |
| 356 |
} |
| 357 |
} |
| 358 |
return $depth |
| 359 |
} |
| 360 |
|
| 361 |
proc saved_text_insert {w index id} { |
| 362 |
global saved_text |
| 363 |
set t $saved_text($id) |
| 364 |
|
| 365 |
$w mark set imark $index |
| 366 |
|
| 367 |
# replay the dump |
| 368 |
set base "" |
| 369 |
foreach {key value index} $t { |
| 370 |
switch -exact $key { |
| 371 |
tagoff { |
| 372 |
if [info exists tags($value)] { |
| 373 |
$w tag add $value $tags($value) imark |
| 374 |
# puts "tagoff $index $value: $tags($value)" |
| 375 |
unset tags($value) |
| 376 |
} |
| 377 |
} |
| 378 |
tagon { |
| 379 |
set tags($value) [$w index imark] |
| 380 |
# puts "tagon $index $value: $tags($value)" |
| 381 |
} |
| 382 |
text { |
| 383 |
$w insert imark $value {} |
| 384 |
# puts "text $index $value" |
| 385 |
} |
| 386 |
} |
| 387 |
} |
| 388 |
# complete any hanging tags |
| 389 |
set search_id [array startsearch tags] |
| 390 |
while {[set i [array nextelement tags $search_id]] != ""} { |
| 391 |
# puts "d-tagoff - $i" |
| 392 |
$w tag add $i $tags($i) imark |
| 393 |
} |
| 394 |
array donesearch tags $search_id |
| 395 |
} |
| 396 |
|
| 397 |
proc saved_text_save {w beg end} { |
| 398 |
set t "" |
| 399 |
# first save tags that cross the whole range |
| 400 |
foreach tag [$w tag names $beg] { |
| 401 |
lappend t tagon $tag - |
| 402 |
} |
| 403 |
# then dump the range so we get internal chagnes |
| 404 |
return [concat $t [$w dump $beg $end]] |
| 405 |
} |
| 406 |
|
| 407 |
proc swap_line_tag {w linebeg lineend char newtag oldtag} { |
| 408 |
# puts "swap_line_tag: $linebeg $lineend" |
| 409 |
# change the sign of the current line |
| 410 |
# (insert first to preserve tag ranges) |
| 411 |
set len [string length $char] |
| 412 |
$w insert "$linebeg + $len char" $char |
| 413 |
$w delete $linebeg "$linebeg + $len char" |
| 414 |
$w tag remove $oldtag $linebeg $lineend |
| 415 |
$w tag add $newtag $linebeg $lineend |
| 416 |
} |
| 417 |
|
| 418 |
proc generate_fqdn {w index} { |
| 419 |
# start on current line, walk backwards |
| 420 |
set fqdn "" |
| 421 |
set beg [$w index "$index lineend"] |
| 422 |
set old_depth [expr [text_matching_tag $w $beg depth]+1] |
| 423 |
while {1} { |
| 424 |
set prev [$w tag prevrange elem $beg] |
| 425 |
if {$prev == ""} { |
| 426 |
break |
| 427 |
} |
| 428 |
set beg [lindex $prev 0] |
| 429 |
set end [lindex $prev 1] |
| 430 |
set new_depth [text_matching_tag $w $beg depth] |
| 431 |
set elem [$w get $beg $end] |
| 432 |
# puts "at $prev: $new_depth $elem ($beg-$end)" |
| 433 |
if {$new_depth >= $old_depth} { |
| 434 |
# only go up, not down or sideways |
| 435 |
continue |
| 436 |
} |
| 437 |
set fqdn "$fqdn.$elem" |
| 438 |
set old_depth $new_depth |
| 439 |
} |
| 440 |
return [string trimleft $fqdn {\.}] |
| 441 |
} |
| 442 |
|
| 443 |
proc expand_ns {w beg end base_depth} { |
| 444 |
# first find out the new subdomain |
| 445 |
set fqdn [generate_fqdn $w "$beg lineend"] |
| 446 |
$w mark set imark $end |
| 447 |
catch { |
| 448 |
fill_text $w imark $fqdn $base_depth |
| 449 |
} error |
| 450 |
} |
| 451 |
|
| 452 |
proc text_enable w { |
| 453 |
$w configure -state normal |
| 454 |
} |
| 455 |
proc text_disable w { |
| 456 |
$w configure -state disabled |
| 457 |
} |
| 458 |
|
| 459 |
proc act_add_tags {w index tags} { |
| 460 |
# puts "act_add_tags: $w $index $tags" |
| 461 |
text_enable $w |
| 462 |
foreach tag $tags { |
| 463 |
$w tag add $tag "$index linestart" "$index lineend + 1 line linestart" |
| 464 |
} |
| 465 |
text_disable $w |
| 466 |
} |
| 467 |
|
| 468 |
proc act_remove_tags {w index tags} { |
| 469 |
text_enable $w |
| 470 |
foreach tag $tags { |
| 471 |
$w tag remove highlight "$index linestart" "$index lineend" |
| 472 |
} |
| 473 |
text_disable $w |
| 474 |
} |
| 475 |
|
| 476 |
proc on_target {w index} { |
| 477 |
# puts "on_target $w $index: [$w tag names $index]" |
| 478 |
# sanity |
| 479 |
set on_target [lsearch -exact [$w tag names $index] target] |
| 480 |
$w tag remove target 0.0 end |
| 481 |
if {$on_target == -1} { |
| 482 |
return 0 |
| 483 |
} |
| 484 |
return 1 |
| 485 |
} |
| 486 |
|
| 487 |
proc if_on_target {cmd w index} { |
| 488 |
text_enable $w |
| 489 |
|
| 490 |
if [on_target $w $index] { |
| 491 |
$cmd $w $index |
| 492 |
} |
| 493 |
|
| 494 |
text_disable $w |
| 495 |
} |
| 496 |
|
| 497 |
proc act_plus {w index} { |
| 498 |
text_enable $w |
| 499 |
|
| 500 |
# find the bounds of the current line |
| 501 |
set linebeg [$w index "$index linestart"] |
| 502 |
set lineend [$w index "$index + 1 line linestart "] |
| 503 |
set depth [text_matching_tag $w $index depth] |
| 504 |
if {$depth == -1} { |
| 505 |
error "act_plus on line without depth" |
| 506 |
} |
| 507 |
|
| 508 |
# expand it |
| 509 |
set id [text_matching_tag $w $index save] |
| 510 |
if {$id == -1} { |
| 511 |
expand_ns $w $linebeg $lineend $depth |
| 512 |
} else { |
| 513 |
show_info $w "expanding" |
| 514 |
global saved_text |
| 515 |
saved_text_insert $w $lineend $id |
| 516 |
$w tag remove "save$id" $linebeg $lineend |
| 517 |
show_info $w "" |
| 518 |
} |
| 519 |
|
| 520 |
swap_line_tag $w $linebeg $lineend {- } minus plus |
| 521 |
text_disable $w |
| 522 |
} |
| 523 |
|
| 524 |
proc text_<=_depth {w index depth} { |
| 525 |
set beg end |
| 526 |
for {} {$depth >= 0} {incr depth -1} { |
| 527 |
set nextrange [$w tag nextrange "depth$depth" $index] |
| 528 |
if {$nextrange != ""} { |
| 529 |
set nextbeg [lindex $nextrange 0] |
| 530 |
if [$w compare $nextbeg <= $beg] { |
| 531 |
set beg $nextbeg |
| 532 |
} |
| 533 |
} |
| 534 |
} |
| 535 |
return $beg |
| 536 |
} |
| 537 |
|
| 538 |
proc act_minus {w index} { |
| 539 |
text_enable $w |
| 540 |
|
| 541 |
# find the bounds of the current line |
| 542 |
set linebeg [$w index "$index linestart"] |
| 543 |
set lineend [$w index "$index + 1 line linestart"] |
| 544 |
set depth [text_matching_tag $w $index depth] |
| 545 |
if {$depth == -1} { |
| 546 |
error "act_minus on line without depth" |
| 547 |
} |
| 548 |
|
| 549 |
# find what gets eliminated |
| 550 |
set delbeg [$w index $lineend] |
| 551 |
set delend [text_<=_depth $w $lineend $depth] |
| 552 |
|
| 553 |
# can't delete active text |
| 554 |
if {[$w tag nextrange expanding $delbeg $delend] != ""} { |
| 555 |
bell |
| 556 |
show_timed_info $w 3 "Cannot compress active trees" |
| 557 |
text_disable $w |
| 558 |
return |
| 559 |
} |
| 560 |
|
| 561 |
# delete it and save it |
| 562 |
global save_next_id saved_text |
| 563 |
set id [incr save_next_id] |
| 564 |
set saved_text($id) [saved_text_save $w $delbeg $delend] |
| 565 |
$w delete $delbeg $delend |
| 566 |
$w tag add "save$id" $linebeg $lineend |
| 567 |
|
| 568 |
swap_line_tag $w $linebeg $lineend {+} plus minus |
| 569 |
text_disable $w |
| 570 |
} |
| 571 |
|
| 572 |
proc act_new_window {w index} { |
| 573 |
set fqdn [generate_fqdn $w "$index lineend"] |
| 574 |
build_browser $fqdn $w |
| 575 |
} |
| 576 |
|
| 577 |
proc build_text w { |
| 578 |
frame $w.text |
| 579 |
set wt "$w.text.text" |
| 580 |
text $wt -relief sunken -bd 2 \ |
| 581 |
-xscrollcommand "$w.text.xscroll set" \ |
| 582 |
-yscrollcommand "$w.text.yscroll set" \ |
| 583 |
-setgrid 1 -height 20 \ |
| 584 |
-width 60 \ |
| 585 |
-wrap none \ |
| •586 |
-font {-*-Courier-Medium-R-*-14-*} |
| 587 |
scrollbar $w.text.xscroll -command "$w.text.text xview" -orient horizontal |
| 588 |
scrollbar $w.text.yscroll -command "$w.text.text yview" |
| 589 |
pack $w.text.xscroll -side bottom -fill x |
| 590 |
pack $w.text.yscroll -side right -fill y |
| 591 |
pack $w.text.text -expand yes -fill both |
| 592 |
pack $w.text -side bottom -expand yes -fill both |
| 593 |
|
| 594 |
# set up some tags |
| 595 |
$wt tag bind clickable <ButtonPress-1> {act_add_tags %W [%W index {@%x,%y}] target } |
| 596 |
$wt tag bind plus <ButtonRelease-1> {if_on_target act_plus %W [%W index {@%x,%y}] } |
| 597 |
$wt tag bind minus <ButtonRelease-1> {if_on_target act_minus %W [%W index {@%x,%y}] } |
| 598 |
# |
| 599 |
$wt tag bind clickable <ButtonPress-2> {act_add_tags %W [%W index {@%x,%y}] target } |
| 600 |
$wt tag bind plus <ButtonRelease-2> {if_on_target act_new_window %W [%W index {@%x,%y}] } |
| 601 |
$wt tag bind minus <ButtonRelease-2> {if_on_target act_new_window %W [%W index {@%x,%y}] } |
| 602 |
# |
| 603 |
$wt tag bind DEBUG <ButtonRelease-3> {set i [%W index {@%x,%y}]; puts "%W $i [%W tag names $i]"} |
| •604 |
$wt tag configure expanding -font {-*-Courier-Bold-R-*-14-*} |
| 605 |
$wt tag configure target -font {-*-Courier-Bold-R-*-14-*} |
| 606 |
# $wt tag configure ns -font {-*-Courier-Bold-R-*-14-*} |
| 607 |
|
| 608 |
return $wt |
| 609 |
} |
| 610 |
|
| 611 |
proc fill_text_line {w place line base_depth} { |
| 612 |
if {![regexp "^(\t*)(\[^\t\]+)\t+(\[^\t\]+)(.*)$" $line dummy new_tabs type value rest]} { |
| •613 |
error "fill_text_line: '$line' does not follow expected regular expression for records" |
| 614 |
} |
| 615 |
set new_depth [string length $new_tabs] |
| 616 |
set depth [expr $base_depth+$new_depth] |
| 617 |
set wtags {} |
| 618 |
switch -exact $type { |
| 619 |
m {set ch "! "; set tags message } |
| 620 |
mx {set ch "! "; set tags {message expanding} } |
| 621 |
z {set ch " "; set tags {}; set wtags elem } |
| 622 |
NS {set ch "+?"; set tags {clickable plus ns}; set wtags elem } |
| 623 |
iz {set ch "- "; set tags {clickable minus iz}; set wtags elem } |
| 624 |
default {set ch " "; set tags {}} |
| 625 |
} |
| 626 |
if {$base_depth > 0 && $new_depth == 0 && $type == "z"} { |
| 627 |
return 0 |
| 628 |
} |
| 629 |
# puts "$depth $line" |
| 630 |
lappend tags depth$depth DEBUG |
| 631 |
set wtags [concat $tags $wtags] |
| 632 |
set base_tabs [string range "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" 1 $base_depth] |
| 633 |
$w insert $place "$ch$base_tabs$new_tabs$type\t" $tags \ |
| 634 |
$value $wtags \ |
| 635 |
"$rest\n" $tags |
| 636 |
return 1 |
| 637 |
} |
| 638 |
|
| 639 |
proc fill_text_background {w index base_depth f iid} { |
| 640 |
text_enable $w |
| 641 |
global insertion_count |
| 642 |
while {1} { |
| 643 |
gets $f line |
| 644 |
if {$line == ""} { |
| 645 |
if [fblocked $f] { |
| 646 |
# no more input |
| 647 |
text_disable $w |
| 648 |
return |
| 649 |
} |
| 650 |
if [eof $f] { |
| 651 |
break |
| 652 |
} |
| 653 |
# empty line |
| 654 |
} |
| 655 |
incr insertion_count($iid) [fill_text_line $w $index $line $base_depth] |
| 656 |
} |
| 657 |
|
| 658 |
# eof |
| 659 |
catch { close $f } |
| 660 |
if {$insertion_count($iid) == 0} { |
| 661 |
fill_text_line $w $index "\te\tno-ouptut" $base_depth |
| 662 |
} |
| 663 |
|
| 664 |
# take down the message and fix the tags |
| 665 |
$w delete iend$iid "iend$iid + 1 line linestart" |
| 666 |
|
| 667 |
# apply options over ibeg$iid, iend$iid |
| 668 |
global options |
| 669 |
set wid [widget_to_wid $w] |
| 670 |
if {$options($wid,hide_new_izs)} { |
| 671 |
set index ibeg$iid |
| 672 |
while {[$w compare $index < iend$iid] != 0} { |
| 673 |
if {[lsearch -exact [$w tag names $index] iz] != -1} { |
| 674 |
act_minus $w $index |
| 675 |
} |
| 676 |
set index [$w index "$index + 1 line"] |
| 677 |
} |
| 678 |
} |
| 679 |
|
| 680 |
text_disable $w |
| 681 |
} |
| 682 |
|
| 683 |
proc fill_text {w index dir base_depth} { |
| 684 |
global dns_tree insertion_next_id insertion_count options maximal_types |
| 685 |
set iid [incr insertion_next_id] |
| 686 |
set insertion_count($iid) 0 |
| 687 |
|
| 688 |
set wid [widget_to_wid $w] |
| 689 |
set opts "" |
| 690 |
if {$options($wid,no_safety)} { |
| 691 |
set opts "$opts -f" |
| 692 |
} |
| 693 |
if {$options($wid,www_hosts_only)} { |
| 694 |
set opts "$opts -m www" |
| 695 |
} |
| 696 |
foreach type $maximal_types { |
| 697 |
if {$options($wid,show_$type)} { |
| 698 |
set opts "$opts -t $type" |
| 699 |
} |
| 700 |
} |
| 701 |
set f [open "| $dns_tree $opts $dir" r] |
| 702 |
|
| 703 |
fconfigure $f -blocking false |
| 704 |
# set up insertion marker |
| 705 |
$w mark set ibeg$iid $index |
| 706 |
$w mark gravity ibeg$iid left |
| 707 |
$w mark set iend$iid $index |
| 708 |
$w mark gravity iend$iid left |
| 709 |
fill_text_line $w $index "\tmx\texpanding $dir" $base_depth |
| 710 |
$w mark gravity iend$iid right |
| 711 |
# asynchronously fill in text |
| 712 |
fileevent $f readable "fill_text_background $w iend$iid $base_depth $f $iid" |
| 713 |
} |
| 714 |
|
| 715 |
proc build_browser {dir old_w} { |
| 716 |
# set w [toplevel ".$dir"] |
| 717 |
global window_next_id |
| 718 |
set wid [incr window_next_id] |
| 719 |
set w [toplevel ".w$wid"] |
| 720 |
global prog |
| •721 |
wm iconname $w "$prog: $dir" |
| 722 |
wm title $w "$prog: $dir" |
| 723 |
|
| 724 |
# set options |
| 725 |
global options user_types required_types maximal_types www_hosts_only |
| 726 |
if {$old_w == ""} { |
| 727 |
set options($wid,hide_new_izs) 1 |
| 728 |
set options($wid,www_hosts_only) $www_hosts_only |
| 729 |
set options($wid,no_safety) 0 |
| 730 |
global maximal_types |
| 731 |
foreach type $maximal_types { |
| 732 |
set options($wid,show_$type) 0 |
| 733 |
} |
| 734 |
foreach type $user_types { |
| 735 |
set options($wid,show_$type) 1 |
| 736 |
} |
| 737 |
foreach type $required_types { |
| 738 |
set options($wid,show_$type) 1 |
| 739 |
} |
| 740 |
} else { |
| 741 |
set old_wid [widget_to_wid $old_w] |
| 742 |
foreach key [array names options] { |
| 743 |
if [string match "$old_wid,*" $key] { |
| 744 |
set part [string range $key [expr [string length $old_wid]+1] end] |
| 745 |
set options($wid,$part) $options($key) |
| 746 |
} |
| 747 |
} |
| 748 |
} |
| 749 |
|
| 750 |
set tw [build_text $w] |
| 751 |
build_menus $w $tw $dir |
| 752 |
bind $w <Enter> "focus $tw" |
| 753 |
|
| 754 |
# (set up an insertion mark) |
| 755 |
$tw mark set imark 0.0 |
| 756 |
$tw mark gravity imark right |
| 757 |
|
| 758 |
fill_text $tw imark $dir 0 |
| 759 |
} |
| 760 |
|
| 761 |
proc main {} { |
| 762 |
global argv |
| 763 |
global save_next_id insertion_next_id window_next_id |
| 764 |
set save_next_id 0 |
| 765 |
set insertion_next_id 0 |
| 766 |
set window_next_id 0 |
| 767 |
|
| 768 |
# option processing |
| 769 |
global user_types maximal_types default_types www_hosts_only |
| 770 |
if {[llength $argv] < 1} { |
| 771 |
usage |
| 772 |
} |
| 773 |
while {[string index [lindex $argv 0] 0] == "-"} { |
| 774 |
set optc [lindex $argv 0] |
| 775 |
set argv [lrange $argv 1 end] |
| 776 |
if {[llength $argv] > 1} { |
| 777 |
set optarg [lindex $argv 0] |
| 778 |
} else { |
| 779 |
set optarg {} |
| 780 |
} |
| 781 |
switch -exact -- $optc { |
| •782 |
-h { usage } |
| 783 |
-t { |
| 784 |
lappend user_types $optarg |
| 785 |
set argv [lrange $argv 1 end] |
| 786 |
} |
| 787 |
-w { |
| 788 |
set www_hosts_only 1 |
| 789 |
} |
| 790 |
default { usage } |
| 791 |
} |
| 792 |
} |
| 793 |
if {$user_types == "all"} { |
| 794 |
set user_types $maximal_types |
| 795 |
} |
| 796 |
if {$user_types == ""} { |
| 797 |
set user_types $default_types |
| 798 |
} |
| 799 |
|
| •800 |
if [catch { wm withdraw .} ] { |
| 801 |
puts stderr "DISPLAY variable not set correctly or not running X" |
| 802 |
exit 1 |
| 803 |
} |
| 804 |
|
| 805 |
|
| 806 |
# argument processing |
| 807 |
foreach name $argv { |
| 808 |
build_browser $name {} |
| 809 |
} |
| 810 |
} |
| 811 |
|
| 812 |
main |