"SfR Fresh" - the SfR Freeware/Shareware Archive

Member "OpenVerse/lib/Debug.tcl" of archive OpenVerse-0.8-7.tar.gz:


As a special service "SfR Fresh" has tried to format the requested source page into HTML format using (guessed) Tcl/Tk source code syntax highlighting with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. That can be also achieved for any archive member file by clicking within an archive contents listing on the first character of the file(path) respectively on the according byte size field.
    1 # OpenVerse Debugging GUI
    2 #
    3 # this file initalizes the program and does any
    4 # platform specific things/setup. It will then source
    5 # supporting modules.
    6 #
    7 # Module Name		- Debugging GUI
    8 # Current Maintainter 	- Cruise <cruise@openverse.org>
    9 # Sourced By		- InitMain
   10 #
   11 # Copyright (C) 1999 David Gale <cruise@openverse.org>
   12 # For more information visit http://OpenVerse.org/
   13 #
   14 # This program is free software; you can redistribute it and/or
   15 # modify it under the terms of the GNU General Public License
   16 # as published by the Free Software Foundation; either version 2
   17 # of the License, or (at your option) any later version.
   18 #
   19 # This program is distributed in the hope that it will be useful,
   20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
   21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   22 # GNU General Public License for more details.
   23 #
   24 # You should have received a copy of the GNU General Public License
   25 # along with this program; if not, write to the Free Software
   26 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
   27 # USA.
   28 
   29 # NOTE: Now using string compare to increase performance
   30 
   31 proc ToggleDebug {} {
   32 	global MV
   33 
   34 	if $MV(debug) {
   35 		set MV(debug) 0
   36 		if {[winfo exists .debug]} {destroy .debug}
   37 	} else {
   38 		OpenDebugWindow
   39 		set MV(debug) 1
   40 	}
   41 }
   42 
   43 proc OpenDebugWindow {} {
   44 	global MV
   45 
   46 	toplevel .debug
   47 	wm title .debug [Trns openverse_debug_window]
   48 	frame .debug.stuff -relief sunken -borderwidth 2
   49 	frame .debug.text -relief sunken -borderwidth 2
   50 
   51 	label .debug.stuff.pos -text [Trns current_position] -relief raised -borderwidth 2
   52 	label .debug.stuff.x -width 3 -textvariable MV(x) -relief raised -borderwidth 2
   53 	label .debug.stuff.y -width 3 -textvariable MV(y) -relief raised -borderwidth 2
   54 	checkbutton .debug.stuff.scr_prot -variable MV(debug.scroll.prot) \
   55 		-text [Trns autoscroll_protocol]
   56 	checkbutton .debug.stuff.scr_other -variable MV(debug.scroll.other) \
   57 		-text [Trns autoscroll_other]
   58 	button .debug.stuff.mem -text [Trns dump_memory] \
   59 		-command Debug_MemDump
   60 
   61 
   62 	text .debug.text.text_prot -relief raised -borderwidth 2 -height 10
   63 	text .debug.text.text_other -relief raised -borderwidth 2 -height 10
   64 
   65 	pack .debug.stuff -side top -fill both -expand y
   66 	pack .debug.text -side bottom -fill both -expand y
   67 	pack .debug.stuff.pos .debug.stuff.x .debug.stuff.y \
   68 		.debug.stuff.scr_prot .debug.stuff.scr_other \
   69 		.debug.stuff.mem -side left
   70 
   71 	pack .debug.text.text_other -side bottom -fill both -expand y
   72 	pack .debug.text.text_prot -side bottom -fill both -expand y
   73 }
   74 
   75 proc DebugIt { what type} {
   76 	global MV
   77 
   78 	#
   79 	# Verify type.
   80 	#
   81 	switch -- $type {
   82 		"prot" {}
   83 		"other" {}
   84 		default {set type "other"}
   85 	}
   86 
   87 	if $MV(debug) {
   88 		if {[winfo exists .debug]} {
   89 			.debug.text.text_$type insert end "$what\n"
   90 			if {$MV(debug.scroll.$type)} {
   91 				.debug.text.text_$type see end
   92 			}
   93 		}
   94 	}
   95 }
   96 
   97 #
   98 # Debug_MemDump
   99 #
  100 # This function will write out the whole MV array to a disk file for you
  101 # to view. it's quite ugly :)
  102 #
  103 proc Debug_MemDump {} {
  104 	global MV AE tl MVS SMVS SET
  105 
  106 	set outfile [open "$MV(homedir)/Dump.mem" w]
  107 	set arrays [list MV AE tl MVS SMVS SET]
  108 	#
  109 	# debug all the arrays.
  110 	#
  111 	foreach ar $arrays {
  112 		puts $outfile "------------------------------------------------------------------------------"
  113 		puts $outfile " THIS IS THE $ar\() ARRAY"
  114 		puts $outfile "------------------------------------------------------------------------------"
  115 		set toggle 0
  116 		set values {}
  117 		set keys {}
  118 		foreach var [array get $ar] {
  119 			if {!$toggle} {
  120 				lappend keys $var
  121 				set toggle 1
  122 			} else {
  123 				set toggle 0
  124 			}
  125 		}
  126 		set keys [lsort $keys]
  127 		foreach key $keys {
  128 			puts $outfile [format "%-39.39s %-39.39s" $key [set $ar\($key)]]
  129 		}
  130 	}
  131 	puts $outfile "------------------------------------------------------------------------------"
  132 	puts $outfile " IMAGES using memory"
  133 	puts $outfile "------------------------------------------------------------------------------"
  134 	set keys {}
  135 	foreach image [image names] {
  136 		lappend keys $image
  137 	}
  138 	set keys [lsort $keys]
  139 	foreach key $keys {
  140 		puts $outfile [format "%-39.39s %-39.39s" $key [image type $key]]
  141 	}
  142         #
  143         # Process Plugins!
  144         #
  145         foreach plugin $MV(plugin.traps.Debug_memory) {
  146                 if ![$MV(plugin.traps.Debug_memory.$plugin) $outfile] {
  147 			DebugIt "Debug_MemDump: Plugin $plugin requested to cancel processing... ignoring." other
  148 		}
  149         }
  150 
  151 	close $outfile
  152 	DebugIt "MV array (main memory) written to $MV(homedir)/Dump.mem, Enjoy!" other
  153 }