/usr/share/tcltk/xotcl1.6.7-serialize/ScriptCreator.xotcl is in xotcl 1.6.7-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | # $Id: ScriptCreator.xotcl,v 1.4 2006/02/18 22:17:33 neumann Exp $
package provide xotcl::scriptCreation::scriptCreator 0.8
package require XOTcl
namespace eval ::xotcl::scriptCreation::scriptCreator {
namespace import ::xotcl::*
Class ScriptCreator \
-parameter {
{excludedObjs {Object Class Class::Parameter}}
{excludeNames ""}
{dependencyChecking 1}
}
#
# queries the excludedObjs variable whether a given object
# is already defined/predefined or not
# -> a way to exclude classes/objs from saving
#
ScriptCreator instproc isExcluded {n} {
my instvar excludedObjs
#puts stderr "Checking Excluded: $n in $excludedObjs"
if {[lsearch $excludedObjs [string trimleft $n :]] == -1} {
return 0
} else {
return 1
}
}
ScriptCreator instproc appendExcluded {n} {
my instvar excludedObjs
lappend excludedObjs [string trimleft $n :]
}
#
# compare command for lsort
#
ScriptCreator instproc namespaceDepth {a b} {
set aCount 0
set bCount 0
for {set i 0} {$i < [string length $a]} {incr i} {
if {[string index $a $i] eq ":"} {
incr aCount
}
}
for {set i 0} {$i < [string length $b]} {incr i} {
if {[string index $b $i] eq ":"} {
incr bCount
}
}
if {$aCount == $bCount} {
return 0
} elseif {$aCount > $bCount} {
return 1
}
return -1
}
#
# produces a script containing the current state of
# the given obj
#
ScriptCreator instproc stateScript {obj} {
set script ""
foreach v [$obj info vars] {
if {[lsearch [my set excludeNames] $v] == -1} {
if {[$obj array exists $v]} {
foreach name [$obj array names $v] {
set arr ${v}($name)
set value [$obj set $arr]
append script "$obj set $arr \"$value\"\n"
}
} else {
set value [$obj set $v]
append script "$obj set $v \"$value\"\n"
}
}
}
return $script
}
#
# produces a script containing the procs of the given obj
#
ScriptCreator instproc procScript {obj} {
set script ""
foreach p [$obj info procs] {
if {[lsearch [my set excludeNames] $p] == -1} {
append script \
"$obj proc $p \{[$obj info args $p]\} \{[$obj info body $p]\}\n"
}
}
return $script
}
#
# produces a script containing the instprocs of the given class
#
ScriptCreator instproc instprocScript {cl} {
set script ""
foreach p [$cl info instprocs] {
if {[lsearch [my set excludeNames] $p] == -1} {
append script \
"$cl instproc $p \{[$cl info instargs $p]\} \{[$cl info instbody $p]\}\n"
}
}
return $script
}
#
# saves a script to a file
#
ScriptCreator instproc saveScript {filename script} {
set f [open $filename w]
puts $f $script
close $f
}
#
# load a script from a file
#
ScriptCreator instproc loadScript {filename} {
set f [open $filename r]
set r [read $f]
close $f
return $r
}
#
# check parent obj/classes/namespaces of an object completly
#
ScriptCreator instproc checkParents {name} {
set p ""
set n $name
while {[set np [namespace parent ::$n]] != "::"} {
lappend p $np
set n $np
}
set p [lsort -command {my namespaceDepth} $p]
foreach n $p {
if {![my isExcluded $n] &&
![my isAppended $n]} {
error "ScriptCreator: $name needs parent $n, neither appended nor excluded yet."
}
}
}
ScriptCreator instproc checkClass {obj class} {
if {![my isExcluded $class] &&
![my isAppended $class]} {
error "ScriptCreator: $obj depends on $class, neither appended nor excluded yet."
}
}
ScriptCreator instproc isAppended name {
set n [string trimleft $name :]
if {[lsearch [my set appendedNames] $n]!=-1} {
return 1
} else {
return 0
}
}
ScriptCreator instproc appendName name {
set n [string trimleft $name :]
my lappend appendedNames $n
}
ScriptCreator instproc makeScript args {
my instvar dependencyChecking
my set appendedNames ""
set script ""
foreach name $args {
#puts stderr "Script Creator -- $name"
if {![my isExcluded $name] &&
![my isAppended $name]} {
if {$dependencyChecking} {
my checkParents $name
}
if {[Object isobject $name]} {
set class [$name info class]
if {$dependencyChecking} {
my checkClass $name $class
}
if {[Object isclass $name]} {
# append the class
#puts stderr "Appending Class: $name"
append script "[$name info class] $name"
set sl [$name info superclass]
if {$dependencyChecking} {
foreach c $sl {
my checkClass $name $c
}
}
if {$sl ne ""} {
append script " -superclass \{$sl\}\n"
} else {
append script "\n"
}
append script [my instprocScript $name]
} else {
# append the obj
#puts stderr "Appending Object: $name"
append script "[$name info class] $name\n"
}
append script [my procScript $name]
} else {
append script "namespace eval $name \{\}\n"
#puts stderr "Appending Namespace: $name"
}
my appendName $name
}
}
return $script
}
namespace export ScriptCreator
}
namespace import ::xotcl::scriptCreation::scriptCreator::*
|