1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-11-04 08:17:17 -05:00
elinks/doc/tools/code2doc
2006-01-09 06:49:15 +01:00

62 lines
1.1 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, $indent, $idpath);
$idpath = ''; $indent = '';
while (<>)
{
my $end = s/\s*\*+\//\n/ ? 'yes' : undef;
# Match:
# IDENT, /*:: ... */
# IDENT = value, /*:: ... */
# type ident; /*:: ... */
if ($end and /^(\s|[^\s=]+)*[\s*]([A-Za-z0-9_]+)(\s+=\s+[^,;]+)?[,;]\s*\/\*::\s*(.*)/)
{
print "\nid:[$idpath$2]::\n\t$4\n";
next;
}
if ($found)
{
s/^(\s|\*)*/$indent/;
s/^$indent$/\n/;
}
elsif (/^\s*\/\*\*\s(.*)/)
{
$_ = $1;
if (/struct:[[]([^\]]+)[\]]/) { $idpath = "$1."; } else { $idpath = ''; }
if (/::/)
{
$_ = "\n$_\n\n";
$indent = "\t";
}
else
{
my $dash; for (my $x = 0; $x < length($_); $x++) { $dash .= '-'; }
$_ = "\n$_\n$dash\n";
$indent = "";
}
$found = 'jep';
}
next if not $found;
$found = undef if $end;
print STDOUT $_;
}