blob: 5a9536fbb8be3e6984a644e5297b07564c2194a6 (
plain)
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
|
package Tk::Zinc::TraceUtils;
use vars qw( $VERSION );
($VERSION) = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);
use Tk;
use strict;
use Tk::Font;
use Tk::Photo;
use vars qw(@EXPORT);
@EXPORT = qw(printItem printArray printList Item Array List);
sub printItem {
print &Item (@_);
}
sub printArray {
print &Array (@_);
}
sub printList {
print &List (@_);
}
sub Item {
my ($value) = @_;
my $ref = ref($value);
# print "VALUE=$value REF=$ref\n";
if ($ref eq 'ARRAY') {
return Array ( @{$value} );
} elsif ($ref eq 'CODE') {
return "{CODE}";
} elsif ($ref eq 'Tk::Photo') {
# print " **** $value ***** ";
return "Tk::Photo(\"". scalar $value->cget('-file') . "\")";
} elsif ($ref eq 'Tk::Font') {
return "'$value'";
} elsif ($ref eq '') { # scalar
print "value: $value\n";
if (defined $value) {
print "defined value: $value\n";
{ no strict;
if ($value eq eval ($value)) {
return $value;
} else {
return "'$value'";
}
use strict;
}
} else {
return "_undef";
}
} else { # some class instance
return $value;
}
} # end Item
### to print something
sub Item {
my ($value) = @_;
my $ref = ref($value);
# print "VALUE=$value REF=$ref\n";
if ($ref eq 'ARRAY') {
return Array ( @{$value} );
} elsif ($ref eq 'CODE') {
return "{CODE}";
} elsif ($ref eq 'Tk::Photo') {
# print " **** $value ***** ";
return "Tk::Photo(\"". scalar $value->cget('-file') . "\")";
} elsif ($ref eq 'Tk::Font') {
return "'$value'";
} elsif ($ref eq '') { # scalar
if (defined $value) {
if ($value =~ /^-?\d+(\.\d*(e[+-]?\d+)?)?$/ or # -1. or 1.0
$value =~ /^-[a-zA-Z]([\w])*$/ # -option1 or -option-1
) {
return $value;
} elsif ($value eq ''
or $value =~ /\s/
or $value =~ /^[a-zA-Z]/
or $value =~ /^[\W]/
) {
return "'$value'";
} else {
return $value;
}
} else {
return "_undef";
}
} else { # some class instance
return $value;
}
} # end Item
### to print a list of something
sub Array {
my (@values) = @_;
if (! scalar @values) {
return "[]";
}
else { # the list is not empty
my $res = "[";
while (@values) {
my $value = shift @values;
$res .= &Item ($value);
$res .= ", " if (@values);
}
return $res. "]" ;
}
} # end Array
sub List {
my $res = "(";
while (@_) {
my $v = shift @_;
$res .= Item ($v);
if (@_ > 0) {
## still some elements
if ($v =~ /^-\d+$/) {
$res .= ", ";
} elsif ($v =~ /^-\w+$/) {
$res .= " => ";
} else {
$res .= ", ";
}
}
}
return $res. ")";
} # end List
1;
|