1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-09-17 01:16:16 -04:00
elinks/doc/tools/code2doc

60 lines
1.2 KiB
Plaintext
Raw Normal View History

#!/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 (<>)
{
# 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)
{
$found = 'sorta' if s/\s*\*+\//\n/;
s/^(\s|\*)*/$indent/;
s/^$indent$/\n/;
}
elsif (/^\s*\/\*\*\s(.*)/)
{
$_ = $1;
if (/\s*\*\/$/) { $found = 'sorta'; } else { $found = $.; }
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 = "";
}
}
next if not $found; $found = undef if $found eq 'sorta';
print STDOUT $_;
}