1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-10-01 03:36:26 -04:00
elinks/doc/tools/code2doc

45 lines
1.3 KiB
Plaintext
Raw Normal View History

#!/usr/bin/perl -w
use strict;
use warnings;
use diagnostics;
2006-01-08 17:57:14 -05:00
print "Usage: $0 [FILE]\n\tParses [FILE], outputing the result to stdout.\n"
and exit if not @ARGV;
my ($input) = @ARGV;
my ($found, $start, $first, $gotone);
print "Copyleft<66> 2006, Russ Rowan (See `COPYING')\n" and exit if $input eq '-v';
open FILEIN, "<$input" or print "File `$input' was not found.\n" and exit;
while (<FILEIN>)
{
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(.*)/)
{
2006-01-08 16:20:46 -05:00
$_ = $1; $first = 1;
2006-01-08 17:57:14 -05:00
print STDOUT "\n\n" if $start;
if ($_ =~ s/\s*\*\/$//) { $found = 'sorta'; } else { $found = $.; }
if ($_ =~ /::/) { $_ = "$_\n\n"; }
else
{
my $dash; for (my $x = 0; $x < length($_); $x++) { $dash .= '-'; }
$_ = "$_\n$dash\n\n";
}
}
elsif ($_ =~ /\s*([A-Z0-9_]+)(\s+=\s+[0-9]+)?,\s*\/\*::\s*(.*)\s+\*\/$/)
{
2006-01-08 17:57:14 -05:00
print STDOUT "\n" if $gotone;
$_ =~ s/\s*([A-Z0-9_]+)(\s+=\s+[0-9]+|),\s*\/\*::\s*(.*)\s+\*\/$/id:[$1]::\n\t$3/;
2006-01-08 16:20:46 -05:00
$found = 'sorta'; $gotone = $.;
}
2006-01-08 17:57:14 -05:00
print STDOUT "\n" and $gotone = undef if $gotone and $gotone < $.;
next if not $found; $found = undef if $found eq 'sorta';
2006-01-08 17:57:14 -05:00
print STDOUT $_ and $start = 1;
}
close FILEIN;