blob: 298bdb375edbf060246eccb0917ed6c34adc753c (
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
|
\section[lit2doc_for_prl]{Document-processing code for language \tr{prl}}
\begin{code}
sub rm_embedded_stuff { # return clean code + entries (\002 separated)
local($_) = @_;
local($entries) = '';
$* = 1;
while (/^\s*#idx::(.*)$/) {
$entries .= "$1\002";
s/^\s*#idx::(.*)$//;
}
s/^\s*#hide::.*$//g; # hidden comments
$* = 0;
chop($entries) if $entries ne '';
($_, $entries);
}
sub add_code_interests { # DO NOTHING
# section and blk to record in ($s == -1: don't update) + the code
local($s, $b, $_) = @_;
local($defs_to_return) = '';
local($uses_to_return) = '';
&setup_perl_keywords();
$* = 1; # multi-line searches
s/^>//g; # de-Bird-ize
s/^#.*$//g; # de-commentize
s/([^\\\n])#.*$/\1/g;
s/\"[^\"\n]*\"//g; # de-stringize
s/\'[^\'\n]*\'//g;
s/s?\/.*\/.*\/g?//g;# de-regexp
# OK, the "interesting" DEFS are subroutines and globals
# sub <thing>
# [@$%]<thing> (=|.=)
while (/^(\s*sub\s+)([A-Za-z0-9_]+)(\s*\{)/ ||
/^(\s*)([\@\$\%][A-Z][A-Za-z0-9_]+)(\s*=|\s*\.=)/) {
local($before) = $1;
local($interesting_thing) = $2; # see hacks below
local($after) = $3;
#print STDERR "defs=>$before::$interesting_thing::$after::\n";
local($really_interesting_thing) = (defined($IGNORE_WD{$interesting_thing})) ? '' : $interesting_thing;
if ($really_interesting_thing) {
if ($s != -1) {
$Blk_codethings_defd[$b] .= "$really_interesting_thing\001";
$Sec_codethings_defd[$s] .= "$really_interesting_thing\001";
} else {
$defs_to_return .= "$really_interesting_thing\001";
}
}
# escaping all magic chars in before/interesting/after
# is v important for avoiding infinite loops! (also below)
$before =~ s/\s+/\\s\+/g;
$interesting_thing =~ s/\$/\\\$/;
$interesting_thing =~ s/\@/\\\@/;
$interesting_thing =~ s/\%/\\\%/;
$after =~ s/\s+/\\s\+/g;
$after =~ s/\{/\\\{/;
$after =~ s/\./\\\./;
s/$before$interesting_thing$after//g;
}
# uses are the same sorts of things
while (/(\&\s*)([A-Za-z0-9_]+)(\s*)/ || # subroutine calls
/(\s*)([\@\$\%][A-Z][A-Za-z0-9_]+)(\s*)/) {
local($before) = $1;
local($interesting_thing) = $2; # more hacks below
local($after) = $3;
#print STDERR "uses=>$before::$interesting_thing::$after::\n";
local($really_interesting_thing) = (defined($IGNORE_WD{$interesting_thing})) ? '' : $interesting_thing;
if ($really_interesting_thing) {
if ($s != -1) {
$Blk_codethings_used[$b] .= "$really_interesting_thing\001";
$Sec_codethings_used[$s] .= "$really_interesting_thing\001";
} else {
$uses_to_return .= "$really_interesting_thing\001";
}
}
$before =~ s/\s+/\\s\+/g;
$interesting_thing =~ s/\$/\\\$/;
$interesting_thing =~ s/\@/\\\@/;
$interesting_thing =~ s/\%/\\\%/;
$after =~ s/\s+/\\s\+/g;
s/$before$interesting_thing$after//g;
}
$* = 0;
($defs_to_return, $uses_to_return);
}
sub setup_perl_keywords {
$IGNORE_WD{'ARGV'} = 1;
$IGNORE_WD{'SIG'} = 1;
$IGNORE_WD{'ENV'} = 1;
}
# this keeps 'do'ing happy
1;
\end{code}
|