-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrel.pl
More file actions
executable file
·134 lines (111 loc) · 2.89 KB
/
rel.pl
File metadata and controls
executable file
·134 lines (111 loc) · 2.89 KB
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
#!/usr/bin/perl -w
use strict;
use warnings;
my %rel;
my %rel_back;
my $to_org = 0;
my $org_level = 1;
sub star{
my $num = shift;
return '*'x$num;
}
sub say{
print @_;
print "\n";
};
sub init_mind {
say '<map version="0.9.0" encoding="utf-8">' unless $to_org ;
say '#+STARTUP: hidestars' if $to_org ;
}
sub fini_mind {
say '</map>' unless $to_org;
}
sub open_class {
my $center_class = shift;
say "<node text=\"$center_class\">" unless $to_org;
say star($org_level++) . " " . $center_class if $to_org;
}
sub open_left_class {
my $base = shift;
say "<node text=\"$base\" style=\"bubble\" position=\"left\">" unless $to_org;
say star($org_level) . " " . $base if $to_org;
}
sub open_right_class {
my $base = shift;
say "<node text=\"$base\" style=\"bubble\" position=\"right\">" unless $to_org;
say star($org_level) . " " . $base if $to_org;
}
sub close_class() {
say "</node>" unless $to_org;
$org_level-- if $to_org;
}
sub add_base_classes {
my $center_class = shift;
return unless exists $rel{$center_class};
my @base_list = split /,/,$rel{$center_class};
for my $base (@base_list) {
&open_left_class($base);
$org_level++ if $to_org;
&add_base_classes($base);
&close_class;
}
}
sub add_child_classes {
my $center_class = shift;
return unless exists $rel_back{$center_class};
my @child_list = split /,/,$rel_back{$center_class};
for my $child (@child_list) {
&open_right_class($child);
$org_level++ if $to_org;
&add_child_classes($child);
&close_class;
}
}
sub main {
#to org mode support
$to_org = 1 if ($ARGV[2] && $ARGV[2] eq "--org");
my $FILE;
open $FILE, "<", $ARGV[0];
my $line;
my @tail_bases;
while ($line=<$FILE>) {
chop $line;
my ($cls, $base) = split /\s+--D\s+/, $line;
next unless $cls && $base;
$cls =~ s/\s//g;
$base =~ s/\s//g;
if (exists $rel{$cls}) {
$rel{$cls} = $rel{$cls} . "," . $base;
} else {
$rel{$cls} = $base;
}
push @tail_bases, $base;
}
for my $base (@tail_bases) {
$rel{$base} = "" unless exists $rel{$base};
}
for my $key (keys %rel) {
my $val = $rel{$key};
my @base_list = split /,/,$val;
for my $base (@base_list) {
if (exists $rel_back{$base}) {
$rel_back{$base} = $rel_back{$base} . "," . $key;
} else {
$rel_back{$base} = $key;
}
}
}
if ($ARGV[1] && exists $rel{$ARGV[1]}) {
my $center_class = $ARGV[1];
&init_mind;
&open_class($center_class);
&add_base_classes($center_class);
&close_class if $to_org;
$org_level = 1 if $to_org;
&open_class($center_class) if $to_org;
&add_child_classes($center_class);
&close_class;
&fini_mind;
}
}
&main;