-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathold_graphy.pl
210 lines (210 loc) · 6.03 KB
/
old_graphy.pl
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
##
## [\/+\*\.\\] [=] ...
## +===========+
## | xxxxxxxxx |
## | xxxxxxxxx |
## +===========+
##
$TOPSTART = '[\x2f\x2b\x2a\x2e\x5c\x7c]';
$TOPLINE = '[\x2d=_ox]{3,}?';
##
sub old_add_node {
my($context,$node) = @_;
my $content = $node->{content};
$content =~ s/\s+/ /g;
$content =~ s/^\s+//;
$content =~ s/\s+$//;
$node->{content} = $content;
my $off = $node->{off};
my $width = $node->{width};
my $nlines = $node->{nlines};
my $line = $node->{line};
# print "NODE:\n", xstring($node, 1), "\n";
$context->{nodes} = [] unless defined $context->{nodes};
push @{$context->{nodes}}, $node;
}
##
sub add_edge {
my($context,$node1,$port1,$node2,$port2,$dir) = @_;
}
##
sub dump_context {
my $context = shift(@_);
my $nnodes = scalar @{$context->{nodes}};
print "$nnodes NODES IN CONTEXT\n";
my $i = 0;
foreach my $node (@{$context->{nodes}}) {
my $nports = $node->{nports};
print " NODE $i: ",$node->{content}," w/$nports ports\n";
my $j = 0;
foreach my $port (@{$node->{ports}}) {
my($type,$loc) = ($port->{type},$port->{loc});
print " PORT $j: type $type on $loc\n";
++$j;
}
++$i;
}
}
##
sub old_graphy {
my $context = shift(@_);
my $fh = shift(@_);
my $ul = {};
my $last;
my $line_no = 0;
while (<$fh>) {
chomp(my $input = $_);
++$line_no;
$last = 0;
my $last_len = undef;
print qq{NEW LINE: "$input"\n};
while ($input) {
if (!defined($last_len)) {
$last_len = length($input);
} elsif (length($input) == $last_len) {
print "STOPPING: MAKING NO PROGRESS at $last_len\n";
last;
} else {
$last_len = length($input);
}
print qq{MATCHING $last: "$input"\n};
if ($input =~ /^(.*?)($TOPSTART)($TOPLINE)($TOPSTART)(.*)$/) { # top/bot
my ($a,$b,$c,$d,$e) = ($1,$2,$3,$4,$5);
my $off = length($a);
my $loc = $off + $last;
my $width = length($b) + length($c) + length($d);
#D+ print qq{MATCH: off=$off loc=$loc width=$width b="$b" c="$c" d="$d"\n};
my $node;
my $is_top = 0;
if ($c) {
if (!defined($ul->{$loc})) {
$node =
{
line => $line_no,
off => $off,
width => $width,
beg => $b,
bar => $c,
end => $d,
content => '',
nlines => 0,
nports => 0,
ports => [],
};
$ul->{$loc} = [ $node ];
$is_top = 1;
} else {
my $match_at = -1;
my $match = undef;
my $i = 0;
foreach my $x (@{$ul->{$loc}}) {
if ($x->{width} == $width) {
$match_at = $i;
$match = $x;
last;
}
++$i;
}
#D+ print "NO MATCH FOR NODE loc=$loc width=$width: ",
#D+ xstring($ul->{$loc}),"\n" unless defined $match;
if (defined($match)) {
$node = $match;
if ($match->{nlines} > 0) {
my @left = ();
$i = 0;
foreach my $y (@{$ul->{$loc}}) {
push @left, $y unless $i == $match_at;
++$i;
}
if (!scalar(@left)) {
delete $ul->{$loc};
} else {
$ul->{$loc} = \@left;
}
} else {
print "DITCHING EMPTY NODE: ",xstring($match),"\n";
}
}
}
#D+ print qq{SCANNING NODE FOR PORTS: },xstring($node),"\n";
## now deal with ports
my $bar = $c;
#D+ print
#D+ qq{SCANNING BAR ($is_top): "$bar"\nNODE IS: },xstring($node),"\n";
while ($bar) {
if ($bar =~ /^([\x2d=]+)([ox:\x2e\x2a])([^ox:\x2e\x2a].*)$/) {
my($a,$b,$c) = ($1,$2,$3);
#D+ print qq{BAR SCAN: a="$a" b="$b" c="$c"\n};
my $port =
{
type => $b,
number => $node->{nports},
loc => $is_top? 'top': 'bot',
};
++$node->{nports};
push @{$node->{ports}}, $port;
$bar = $c;
} else {
$bar = undef;
}
}
add_node($context, $node) if ($node && !$is_top);
}
$input = $e;
$last = $loc + $width;
#D+ print qq{AFTER MATCH: last=$last input="$input"\n};
} elsif ($input =~ /^([^|]+)([|x])(.+?)([|x])(.*)$/) { # guts of a node
my($a,$b,$c,$d,$e) = ($1,$3,$5,$2,$4);
my $off = length($a);
my $loc = $off + $last;
my $width = length($b);
my $node;
print
qq{MATCH2: off=$off loc=$loc width=$width }.
qq{a="$a" b="$b" c="$c" d="$d" e="$e"\n};
if ($b) {
$width += 2;
if (defined($ul->{$loc})) {
foreach my $x (@{$ul->{$loc}}) {
if ($x->{width} == $width) {
$x->{content} .= qq{ $b };
++$x->{nlines};
$node = $x;
last;
}
}
}
}
if ($node) {
if ($d =~ /[x\x2a]/) {
my $port =
{
type => 'x',
number => $node->{nports},
loc => 'lhs',
};
++$node->{nports};
push @{$node->{ports}}, $port;
}
if ($e =~ /[x\x2a]/) {
my $port =
{
type => 'x',
number => $node->{nports},
loc => 'rhs',
};
++$node->{nports};
push @{$node->{ports}}, $port;
}
}
$input = $c;
$last = $loc + $width;
#D print qq{AFTER MATCH2: last=$last input="$input"\n};
}
}
}
##
foreach my $key (sort ascending (keys %$ul)) {
print "key leftover: $key => ",xstring($ul->{$key}),"\n";
}
}