1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00
elinks/doc/tools/code2doc

56 lines
1.3 KiB
Perl
Executable File

#!/usr/bin/perl -w
use strict;
use warnings;
use diagnostics;
use Getopt::Std;
my $HELP = "Usage: $0 [FILE]
Parses [FILE], outputing the result to stdout.";
sub usage {
print "@_\n";
exit;
}
our($opt_h, $opt_v);
getopts("hv") or usage($HELP);
$opt_v and usage("Copyleft (c) 2006, Russ Rowan (See `COPYING')");
usage($HELP) if $opt_h or @ARGV < 1;
my ($found, $first, $idpath);
$idpath = '';
while (<>)
{
# Match:
# IDENT, /*:: ... */
# IDENT = value, /*:: ... */
# type ident; /*:: ... */
if (/^(\s|[^\s=]+)*[\s*]([A-Za-z0-9_]+)(\s+=\s+[^,;]+)?[,;]\s*\/\*::\s*(.*)\s+\*\/$/)
{
print "\nid:[$idpath$2]::\n\t$4\n";
next;
}
if ($found)
{
if (/^\s+\*\s$/) { next if $first; $_ =~ s/\s\*// if not $first; }
if (/^\s\*+\/$/ or $_ !~ /^\s/) { $found = undef; next; }
$_ =~ s/^(\s*)\s\*\s/$1/;
$found = 'sorta' if s/\s*\*\/$/\n/; $first = undef;
}
elsif (/^\s*\/\*\*\s(.*)/)
{
$_ = $1; $first = 1;
if (/\s*\*\/$/) { $found = 'sorta'; } else { $found = $.; }
if (/struct:[[]([^\]]+)[\]]/) { $idpath = "$1."; } else { $idpath = ''; }
if (/::/) { $_ = "\n$_\n\n"; }
else
{
my $dash; for (my $x = 0; $x < length($_); $x++) { $dash .= '-'; }
$_ = "\n$_\n$dash\n\n";
}
}
next if not $found; $found = undef if $found eq 'sorta';
print STDOUT $_;
}