File: make-func-list.pl

package info (click to toggle)
gnumeric 1.4.3-4
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 71,576 kB
  • ctags: 28,555
  • sloc: ansic: 282,333; xml: 45,788; sh: 8,479; makefile: 3,119; yacc: 1,129; lisp: 200; perl: 173; python: 86
file content (153 lines) | stat: -rw-r--r-- 3,336 bytes parent folder | download
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
use strict;

my $state = 0;
my $cat = "";
my $func = "";

while (<>) {
    s/\s+$//;
    if (/^\@CATEGORY=(.*)/) {
	if ($cat ne $1) {
	    if ($cat ne "") {
		print "</sect1>\n";
	    }
	    $cat = $1;
	    my $cat_id = "CATEGORY_" . $cat;
	    $cat_id =~ s/\s+/_/g;
	    $cat_id =~ s/[^A-Za-z_]//g;
	    print "<sect1 id=\"$cat_id\">\n";
	    print "  <title>", &quote_stuff ($cat), "</title>\n";
	}
	$state = 0;
    }
    if (/^\@FUNCTION=(.*)/) {
	if ($state) {
	    if ($state == 3) {
		print "        </itemizedlist>\n";
	    }
	    print "      </refsect1>\n";
	    print "    </refentry>\n\n";
	}
	$func = $1;
	my $mod_func = &fixup_function_name ($1);
	$state = 0;
	print "\n\n";
	print "  <refentry id=\"gnumeric-$mod_func\">\n";
	print "    <refmeta>\n";
	print "      <refentrytitle><function>$func</function></refentrytitle>\n";
	print "    </refmeta>\n";
	print "    <refnamediv>\n";
	print "      <refname><function>$func</function></refname>\n";
	print "    </refnamediv>\n";
	next;
    }

    if (/^\@SYNTAX=(.*)/) {
	my $str = &markup_stuff ($1);
	$str =~ s/([\(\,])(\w*)/\1<parameter>\2<\/parameter>/g;
	print "    <refsynopsisdiv>\n";
	print "      <synopsis>$str</synopsis>\n";
	print "    </refsynopsisdiv>\n";
	next;
    }

    if (/^\@DESCRIPTION=(.*)/) {
	print "    <refsect1>\n";
	print "      <title>Description</title>\n";
	print "      <para>", &markup_stuff ($1), "</para>\n";
	$state = 1;
	next;
    }

    if (/^\@EXAMPLES=(.*)/) {
	if ($state) {
	    if ($state == 3) {
		print "        </itemizedlist>\n";
	    }
	    print "    </refsect1>\n";
	}
	print "    <refsect1>\n";
	print "      <title>Examples</title>\n";
	print "      <para>", &markup_stuff ($1), "</para>\n";
	$state = 2;
	next;
    }

    if (/^\@SEEALSO=(.*)/) {
	my $linktxt = $1;
	$linktxt =~ s/\s//g;
	$linktxt =~ s/\.$//;
	my @links = split (/,/, $linktxt);

	if ($state) {
	    print "    </refsect1>\n";
	}
	print "    <refsect1>\n";
	print "      <title>See also</title>\n";
	my @a = ();
	print   "      <para>\n";
	foreach my $link (@links) {
	    my $fixed_name = &fixup_function_name ($link);
	    push @a, "        <link linkend=\"gnumeric-$fixed_name\"><function>$link</function></link>";
	}
	if (@a > 0) {
	    print join (",\n", @a), ".\n";
	}
	print "      </para>\n";
	print "    </refsect1>\n";
	print "  </refentry>\n\n";
	$state = 0;
	next;
    }

    if ($state) {
	if (/^\*\s/) {
	    my $str = &markup_stuff ($_);
	    $str =~ s/^\*\s+//;
	    if ($state ne 3) {
		print "        <itemizedlist>\n";
		$state = 3;
	    }
	    print "          <listitem><para>$str</para></listitem>\n";
	}
	elsif ($_ ne "") {
	    if ($state == 3) {
		print "        </itemizedlist>\n";
		$state = 1;
	    }
	    print "        <para>", &markup_stuff ($_), "</para>\n";
	}
    }
}

print "</sect1>\n";

sub markup_stuff {
    my ($str) = @_;

    $str = &quote_stuff ($str);

    $str =~ s/\b$func\b/<function>$func<\/function>/g;
    $str =~ s/\@(\w*)\b/<parameter>\1<\/parameter>/g;

    return $str;
}

sub quote_stuff {
    my ($str) = @_;

    # Let's do this one first...
    $str =~ s/\&/\&amp;/g;

    $str =~ s/</\&lt;/g;
    $str =~ s/>/\&gt;/g;
    return $str;
}

sub fixup_function_name {
    my ($name) = @_;
#    why did we need this ?  leave the routine here just in case
#    $name =~ s/_/x/g;
    return $name;
}