aboutsummaryrefslogtreecommitdiff
path: root/src/mkhelp.pl
blob: d58ccf9891978fdf6d30e37be8c0ddec2bf97ee0 (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/local/bin/perl

# Yeah, I know, probably 1000 other persons already wrote a script like
# this, but I'll tell ya:

# THEY DON'T FIT ME :-)

# Get readme file as parameter:
$README = $ARGV[0];

if($README eq "") {
    print "usage: mkreadme.pl <README>\n";
    exit;
}


push @out, "                                  _   _ ____  _     \n";
push @out, "  Project                     ___| | | |  _ \\| |    \n";
push @out, "                             / __| | | | |_) | |    \n";
push @out, "                            | (__| |_| |  _ <| |___ \n";
push @out, "                             \\___|\\___/|_| \\_\\_____|\n";

$head=0;
loop:
while (<STDIN>) {
    $line = $_;

    # this kind should be removed first:
    $line =~ s/_//g;

    # then this:
    $line =~ s/.//g;

    if($line =~ /^curl/i) {
	# cut off the page headers
        $head=1;
	next loop;
    } 

    if($line =~ /^[ \t]*\n/) {
	$wline++;
	# we only make one empty line max
	next loop;
    }
    if($wline) {
	$wline = 0;
        if(!$head) {
            push @out, "\n";
        }
        $head =0;
    }
    push @out, $line;
}
push @out, "\n"; # just an extra newline

open(READ, "<$README") ||
    die "couldn't read the README infile";

while(<READ>) {
    push @out, $_;
}
close(READ);


print "/* NEVER EVER edit this manually, fix the mkhelp script instead! */\n"
;
print "#include <stdio.h>\n";
print "void hugehelp(void)\n";
print "{\n";
print " fputs (\n";

$outsize=0;
for(@out) {
    chop;

    $new = $_;

    $outsize += length($new)+1; # one for the newline

    $new =~ s/\\/\\\\/g;
    $new =~ s/\"/\\\"/g;

    # gcc 2.96 claims ISO C89 only is required to support 509 letter strings
    if($outsize > 500) {
        # terminate and make another fputs() call here
        print ", stdout);\n fputs(\n";
        $outsize=length($new)+1;
    }
    printf("\"%s\\n\"\n", $new);

}

print ", stdout) ;\n}\n"