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

52 lines
1.0 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;
2006-01-09 02:25:03 -05:00
my ($header, $indent, $idpath);
$idpath = ''; $indent = '';
while (<>)
{
2006-01-09 00:49:15 -05:00
my $end = s/\s*\*+\//\n/ ? 'yes' : undef;
2006-01-09 02:25:03 -05:00
if ($end and /[^=]*[\s*](\w+)[\s,;].*\/\*::\s*(.*)/) {
# Implicit id for enum values and struct members.
$_ = "\nid:[$idpath$1]::\n\t$2\n";
2006-01-09 02:25:03 -05:00
} elsif ($header) {
# Redo the indentation, preserve empty lines.
s/^(\s|\*)*/$indent/;
s/^$indent$/\n/;
2006-01-09 02:25:03 -05:00
} elsif (s/^\s*\/\*\*\s(.*)$/$1/) {
# Found magic header; record idpath and underline title.
$header = "$1";
$idpath = /struct:[[]([^\]]+)[\]]/ ? "$1." : "";
$indent = /::/ ? "\t" : "";
$_ = '' if $indent;
s/[^-]/-/g; chop;
$_ = "\n$header\n$_\n";
} else {
next;
}
2006-01-09 02:25:03 -05:00
$header = undef if $end;
print STDOUT $_;
}