summaryrefslogtreecommitdiff
path: root/d/sys/lampion/local/bin/extractdoc
blob: 01c0198c6f7eddcf5fcdc183793801fa1996eee6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/perl -w
use strict;

while (<>)
{
    if (/^\/\*\*/)
    {
	my @doc;
	my @def;
	my $stop;
	# Capture comments.
	INNER: {
	    do {
		chomp;
		last INNER if /^[ \t]*\*\/[ \t]*$/;
		$stop = 1 if /\*\//;
		s/^\/?[ \t]*\*+ ?//;
		s/^[ \t]+/\t/;
		s/^\t- *([^:-]+) *:/\t[$1]/;
		s/[ \t]*\*\///;
		push @doc, $_;
		last INNER if defined $stop;
	    } while (<>);
	}
	# Capture definition.
	$_ = <>;
	if (/^# *define /)
	{
	    INNER: {
		do {
		    chomp;
		    push @def, $_ . ' ';
		    if ($#def > 5)
		    {
			push @def, '...';
			last;
		    }
		    last unless /\\$/
		} while (<>);
	    }
	}
	else
	{
	    INNER: {
		do {
		    chomp;
		    s/\)[^)]*$/);/;
		    push @def, $_;
		    last if /\)/;
		} while (<>);
	    }
	}
	print join "\n", @doc, '', '^<<', @def, '^>>', '', '';
    }
}