]>
Commit | Line | Data |
---|---|---|
6f248ce1 TL |
1 | #!/usr/bin/perl -w |
2 | ||
3 | use strict; | |
4 | ||
5 | my $DEB_HOST_ARCH_OS = `dpkg-architecture -qDEB_HOST_ARCH_OS`; | |
6 | ||
7 | $DEB_HOST_ARCH_OS =~ s/\n//; | |
8 | ||
9 | # declarations | |
10 | my $line; | |
11 | my $match; | |
12 | my $arch = ""; | |
13 | ||
14 | # subroutines | |
15 | sub nextline { | |
16 | $line = <>; | |
17 | while($line and ($line =~ /^#/ or $line =~ /^\s*$/)) { | |
18 | $line = <>; | |
19 | } | |
20 | if (!$line) { return 0; } | |
21 | chomp $line; | |
22 | while ($line =~ m/^(.*)\\$/) { | |
23 | my $addon = <>; | |
24 | chomp $addon; | |
25 | $line = $1 . $addon; | |
26 | } | |
27 | return 1; | |
28 | } | |
29 | sub our_arch { | |
30 | return ($arch eq $DEB_HOST_ARCH_OS) || ($arch eq "any") | |
31 | } | |
32 | sub match { | |
33 | my $line = $_[0]; | |
34 | my $cmd = "$_[1]" ? "$_[1]\\b\\s*" : "";; | |
35 | my $indentexp = (@_ == 3) ? "$_[2]\\s+" : ""; | |
36 | ||
37 | if ($line =~ /^${indentexp}${cmd}(([^\s](.*[^\s])?)?)\s*$/) { | |
38 | $match = $1; | |
39 | return 1; | |
40 | } else { | |
41 | return 0; | |
42 | } | |
43 | } | |
44 | sub skip_section { | |
45 | my $struct = $_[0]; | |
46 | my $indent = ($line =~ /(\s*)[^\s]/) ? $1 : ""; | |
47 | ||
48 | 1 while (nextline && match($line, "", $indent)); | |
49 | } | |
50 | sub get_address_family { | |
51 | print ".SH " . uc($match) . " ADDRESS FAMILY\n"; | |
52 | print "This section documents the methods available in the\n"; | |
53 | print "$match address family.\n"; | |
54 | nextline; | |
55 | } | |
56 | sub get_architecture { | |
57 | $arch = $_[0]; | |
58 | nextline; | |
59 | } | |
60 | sub get_method { | |
61 | my $method = shift; | |
62 | my $indent = ($line =~ /(\s*)\S/) ? $1 : ""; | |
63 | my $description = ""; | |
64 | my @options = (); | |
65 | ||
66 | nextline; | |
67 | while ($line and match($line, "", $indent)) { | |
68 | if (match($line, "description", $indent)) { | |
69 | $description = get_description(); | |
70 | } elsif (match($line, "options", $indent)) { | |
71 | @options = get_options(); | |
72 | } else { | |
73 | skip_section; | |
74 | } | |
75 | } | |
76 | ||
77 | print ".SS The $method Method\n"; | |
78 | if ($description ne "") { | |
79 | print usenet2man($description) . "\n"; | |
80 | } else { | |
81 | print "(No description)\n"; | |
82 | } | |
83 | print ".PP\n"; | |
84 | print ".B Options\n"; | |
85 | print ".RS\n"; | |
86 | if (@options) { | |
87 | foreach my $o (@options) { | |
88 | if ($o =~ m/^\s*(\S*)\s*(.*)\s+--\s+(\S[^[]*)(\s+\[([^]]*)\]\s*)?$/) { | |
89 | my $opt = $1; | |
90 | my $optargs = $2; | |
91 | my $dsc = $3; | |
92 | $dsc .= (length($5)) ? ". Default value: \"$5\"" : ""; | |
93 | print ".TP\n"; | |
94 | print ".BI $opt"; | |
95 | print " \" $optargs\"" unless($optargs =~ m/^\s*$/); | |
96 | print "\n"; | |
97 | print usenet2man($dsc) . "\n"; | |
98 | } else { | |
99 | print ".TP\n"; | |
100 | print ".B $o\n"; | |
101 | } | |
102 | } | |
103 | } else { | |
104 | print ".TP\n"; | |
105 | print "(No options)\n"; | |
106 | } | |
107 | print ".RE\n"; | |
108 | } | |
109 | sub get_description { | |
110 | my $desc = ""; | |
111 | my $indent = ($line =~ /(\s*)\S/) ? $1 : ""; | |
112 | while(nextline && match($line, "", $indent)) { | |
113 | $desc .= "$match\n"; | |
114 | } | |
115 | return $desc; | |
116 | } | |
117 | sub usenet2man { | |
118 | my $in = shift; | |
119 | my $out = ""; | |
120 | ||
121 | $in =~ s/\s+/ /g; | |
122 | while ($in =~ m%^([^*/]*)([*/])([^*/]*)([*/])(.*)$%s) { | |
123 | my ($pre, $l, $mid, $r, $post) = ($1, $2, $3, $4, $5); | |
124 | if ($l eq $r && " $pre" =~ m/[[:punct:][:space:]]$/ | |
125 | && "$post " =~ m/^[[:punct:][:space:]]/) { | |
126 | $out .= $pre; | |
127 | $out .= ($l eq "*" ? '\fB' : '\fI') . $mid . '\fP'; | |
128 | ($in = $post) =~ s/^\s+/ /; | |
129 | } else { | |
130 | $out .= $pre . $l; | |
131 | $in = $mid . $r . $post; | |
132 | } | |
133 | } | |
134 | return $out . $in; | |
135 | } | |
136 | sub get_options { | |
137 | my @opts = (); | |
138 | my $indent = ($line =~ /(\s*)\S/) ? $1 : ""; | |
139 | while(nextline && match($line, "", $indent)) { | |
140 | push @opts, $match; | |
141 | } | |
142 | return @opts; | |
143 | } | |
144 | ||
145 | # main code | |
146 | nextline; | |
147 | while($line) { | |
148 | if (match($line, "address_family")) { | |
149 | get_address_family $match; | |
150 | next; | |
151 | } | |
152 | if (match($line, "architecture")) { | |
153 | get_architecture $match; | |
154 | next; | |
155 | } | |
156 | if (match($line, "method")) { | |
157 | if (our_arch()) { | |
158 | get_method $match; | |
159 | } else { | |
160 | skip_section; | |
161 | } | |
162 | next; | |
163 | } | |
164 | ||
165 | # ...otherwise | |
166 | die("Unknown command \"$line\""); | |
167 | } |