-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsummarize-proc
executable file
·51 lines (43 loc) · 1.07 KB
/
summarize-proc
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
#!/opt/homebrew/bin/perl
# summarize-proc infile
# Reads one of the standard procedure files and produces a summary.
my $filename = $ARGV[0];
open(my $INFILE, "<", $filename) or die "Could not find file '$filename'";
# Make a link to the file
my $link = $filename;
$link =~ s/^_//;
$link =~ s/.md$/.html/;
# Print the header
my $line = <$INFILE>;
print $line;
while (($line = <$INFILE>) && ($line ne "---\n")) {
print $line;
}
print "link: $link\n";
# Get the signature
while (($line = <$INFILE>) && ($line !~ m/^;;;/)) { }
my $sig = $line;
$sig =~ s/ ->.*//;
$sig =~ s/ :.*//;
$sig =~ s/^;;; *//;
if ($sig =~ m/\(([^ ]*) (.*)\)/) {
print "proc: $1\n";
print "params: \"$2\"\n";
} elsif ($sig =~ m/\(([^ ]*)\)/) {
print "proc: $1\n";
} else {
print "constant: $sig\n";
}
# Get the documentation
my $docs = "";
while (($line = <$INFILE>) && ($line =~ m/^;;; /)) { }
do {
my $doc = $line;
chomp($doc);
$doc =~ s/^;;; //;
$docs .= " $doc\n";
} while (($line = <$INFILE>) && ($line =~ m/^;;; [^ ]/));
print "docs: |\n$docs";
# And we're done
print "---\n";
close($INFILE);