Changeset 1828
- Timestamp:
- Jul 15, 2010, 7:28:00 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/scripts/utils.tcl
r1715 r1828 23 23 proc Rappture::utils::hexdump {args} { 24 24 Rappture::getopts args params { 25 25 value -lines unlimited 26 26 } 27 27 if {[llength $args] != 1} { 28 28 error "wrong # args: should be \"hexdump ?-lines num? data\"" 29 29 } 30 30 set newval [lindex $args 0] … … 34 34 35 35 if {$params(-lines) != "unlimited" && $params(-lines) <= 0} { 36 36 return $rval 37 37 } 38 38 … … 40 40 set len [string length $newval] 41 41 for {set i 0} {$i < $len} {incr i 8} { 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 42 append rval [format "%#06x: " $i] 43 set ascii "" 44 for {set j 0} {$j < 8} {incr j} { 45 if {$i+$j < $len} { 46 set char [string index $newval [expr {$i+$j}]] 47 binary scan $char c ichar 48 set hexchar [format "%02x" [expr {0xff & $ichar}]] 49 } else { 50 set char " " 51 set hexchar " " 52 } 53 append rval "$hexchar " 54 if {[regexp {[\000-\037\177-\377]} $char]} { 55 append ascii "." 56 } else { 57 append ascii $char 58 } 59 } 60 append rval " | $ascii\n" 61 61 62 63 64 65 66 67 62 if {"unlimited" != $params(-lines) && $i/8+1 >= $params(-lines)} { 63 if {$i < $len-1} { 64 append rval "more..." 65 } 66 break 67 } 68 68 } 69 69 return $rval … … 78 78 proc Rappture::utils::binsize {size} { 79 79 foreach {factor units} { 80 81 82 83 80 1073741824 GB 81 1048576 MB 82 1024 kB 83 1 bytes 84 84 } { 85 86 87 88 89 90 85 if {$size/$factor > 0} { 86 if {$factor > 1} { 87 set size [format "%.1f" [expr {double($size)/$factor}]] 88 } 89 break 90 } 91 91 } 92 92 return "$size $units" … … 127 127 return $desc 128 128 } 129 130 # ---------------------------------------------------------------------- 131 # USAGE: expandPath <path> 132 # 133 # Returns the true location of the provided path, 134 # automatically expanding links to form an absolute path. 135 # ---------------------------------------------------------------------- 136 proc Rappture::utils::expandPath {args} { 137 set path "" 138 set dirs [file split [lindex $args 0]] 139 140 while {[llength $dirs] > 0} { 141 set d [lindex $dirs 0] 142 set dirs [lrange $dirs 1 end] 143 if {[catch {file link [file join $path $d]} out] == 0} { 144 # directory d is a link, follow it 145 set outdirs [file split $out] 146 if {[string compare "/" [lindex $outdirs 0]] == 0} { 147 # directory leads back to root 148 # clear path 149 # reset dirs list 150 set path "" 151 set dirs $outdirs 152 } else { 153 # relative path for the link 154 # prepend directory to dirs list 155 set dirs [concat $outdirs $dirs] 156 } 157 } else { 158 set path [file join $path $d] 159 } 160 } 161 return $path 162 } 163
Note: See TracChangeset
for help on using the changeset viewer.