File: fixmanpage

package info (click to toggle)
erlang 1%3A27.3.4.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 225,000 kB
  • sloc: erlang: 1,658,966; ansic: 405,769; cpp: 177,850; xml: 82,435; makefile: 15,031; sh: 14,401; lisp: 9,812; java: 8,603; asm: 6,541; perl: 5,836; python: 5,484; sed: 72
file content (67 lines) | stat: -rwxr-xr-x 1,415 bytes parent folder | download | duplicates (2)
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
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/perl

use strict;
use warnings;

my $filename = $ARGV[0];
my $section = $ARGV[1];

my $module = '';
my $filedata;
open(my $fh, '<', $filename) or die "Cannot open file $filename";
{
    local $/;
    $filedata = <$fh>;
}
close($fh);

# For .erl files extract moduledoc
if ($filename =~ /.erl$/) {
    $filedata =~ /-module\((.*?)\)./s;
    $module = $1;
    $filedata =~ /-moduledoc \"\"\"\n([^\n]*)\n(.*?)\"\"\"/s;
    $filedata = "# $module\n\n$1\n\n## Description\n$2";
}

# Drop language hints since ronn does not support them
$filedata =~ s/\`\`\`\w+/\`\`\`/gs;

my @lines = split /\n/, $filedata;

my $header = '';
my $rest = '';
my $state = 0;

foreach my $line (@lines) {
    chomp $line;
    if ($state == 0) {
	if ($line =~ /^# /) {
	    $header = "$line($section) -- ";
	    $state = 1;
	}
    } elsif ($state == 1) {
	if ($line =~ /^#/) {
	    $rest .= "$line\n";
	    $state = 2;
	} else {
	    $header .= $line;
	}
    } elsif ($state == 2) {
        if ($line =~ "\`\`\`") {
	    $rest .= "$line\n";
            $state = 3;
        } else {
	    $line =~ s/#### ([^\{]*) \{.*/_$1_/;
	    $line =~ s/\[\]\([^\)]*\)(\{[^\}]*\})?(\s*)//g;
	    $line =~ s/\[([^\[]*)\]\([^\)]*\)(\{[^\}]*\})?(\s*)/*$1*$3/g;
	    $rest .= "$line\n";
        }
    } elsif ($state == 3) {
        if ($line =~ "\`\`\`") {
            $state = 2;
        }
	$rest .= "$line\n";
    }
}

print "$header\n\n$rest";