Instead of using a ReST compilant label while parsing, move the label to ReST output. That makes the parsing logic more generic, allowing it to provide other types of output. As a side effect, now all files used to generate the output will be output. We can later add command line arguments to filter.
Unified · Split
| @@ -49,17 +49,23 @@ sub parse_abi { · 48 unmodified lines | |||
| 49 | my $name = $file; | 49 | my $name = $file; |
| 50 | $name =~ s,.*/,,; | 50 | $name =~ s,.*/,,; |
| 51 | 51 | ||
| 52 | my $nametag = "File $name"; | ||
| 53 | $data{$nametag}->{what} = "File $name"; | ||
| 54 | $data{$nametag}->{type} = "File"; | ||
| 55 | $data{$nametag}->{file} = $name; | ||
| 56 | $data{$nametag}->{is_file} = 1; | ||
| 57 | |||
| 52 | my $type = $file; | 58 | my $type = $file; |
| 53 | $type =~ s,.*/(.*)/.*,$1,; | 59 | $type =~ s,.*/(.*)/.*,$1,; |
| 54 | 60 | ||
| 55 | my $what; | 61 | my $what; |
| 56 | my $new_what; | 62 | my $new_what; |
| 57 | my $tag; | 63 | my $tag; |
| 58 | my $label; | ||
| 59 | my $ln; | 64 | my $ln; |
| 60 | my $has_file; | ||
| 61 | my $xrefs; | 65 | my $xrefs; |
| 62 | my $space; | 66 | my $space; |
| 67 | my @labels; | ||
| 68 | my $label; | ||
| 63 | 69 | ||
| 64 | print STDERR "Opening $file\n" if ($debug > 1); | 70 | print STDERR "Opening $file\n" if ($debug > 1); |
| 65 | open IN, $file; | 71 | open IN, $file; |
| @@ -88,28 +94,13 @@ sub parse_abi { · 22 unmodified lines | |||
| 88 | parse_error($file, $ln, "What '$what' doesn't have a description", "") if ($what && !$data{$what}->{description}); | 94 | parse_error($file, $ln, "What '$what' doesn't have a description", "") if ($what && !$data{$what}->{description}); |
| 89 | 95 | ||
| 90 | $what = $content; | 96 | $what = $content; |
| 97 | $label = $content; | ||
| 91 | $new_what = 1; | 98 | $new_what = 1; |
| 92 | } | 99 | } |
| 100 | push @labels, [($content, $label)]; | ||
| 93 | $tag = $new_tag; | 101 | $tag = $new_tag; |
| 94 | 102 | ||
| 95 | if ($has_file) { | 103 | push @{$data{$nametag}->{xrefs}}, [($content, $label)] if ($data{$nametag}->{what}); |
| 96 | $label = "abi_" . $content . " "; | ||
| 97 | $label =~ tr/A-Z/a-z/; | ||
| 98 | |||
| 99 | # Convert special chars to "_" | ||
| 100 | $label =~s/[\x00-\x2f]+/_/g; | ||
| 101 | $label =~s/[\x3a-\x40]+/_/g; | ||
| 102 | $label =~s/[\x7b-\xff]+/_/g; | ||
| 103 | $label =~ s,_+,_,g; | ||
| 104 | $label =~ s,_$,,; | ||
| 105 | |||
| 106 | $data{$what}->{label} .= $label; | ||
| 107 | |||
| 108 | # Escape special chars from content | ||
| 109 | $content =~s/([\x00-\x1f\x21-\x2f\x3a-\x40\x7b-\xff])/\\$1/g; | ||
| 110 | |||
| 111 | $xrefs .= "- :ref:`$content <$label>`\n\n"; | ||
| 112 | } | ||
| 113 | next; | 104 | next; |
| 114 | } | 105 | } |
| 115 | 106 | ||
| @@ -117,6 +108,9 @@ sub parse_abi { · 1 unmodified line | |||
| 117 | $tag = $new_tag; | 108 | $tag = $new_tag; |
| 118 | 109 | ||
| 119 | if ($new_what) { | 110 | if ($new_what) { |
| 111 | @{$data{$what}->{label}} = @labels if ($data{$nametag}->{what}); | ||
| 112 | @labels = (); | ||
| 113 | $label = ""; | ||
| 120 | $new_what = 0; | 114 | $new_what = 0; |
| 121 | 115 | ||
| 122 | $data{$what}->{type} = $type; | 116 | $data{$what}->{type} = $type; |
| @@ -145,15 +139,8 @@ sub parse_abi { · 22 unmodified lines | |||
| 145 | } | 139 | } |
| 146 | 140 | ||
| 147 | # Store any contents before tags at the database | 141 | # Store any contents before tags at the database |
| 148 | if (!$tag) { | 142 | if (!$tag && $data{$nametag}->{what}) { |
| 149 | next if (/^\n/); | 143 | $data{$nametag}->{description} .= $_; |
| 150 | |||
| 151 | my $my_what = "File $name"; | ||
| 152 | $data{$my_what}->{what} = "File $name"; | ||
| 153 | $data{$my_what}->{type} = "File"; | ||
| 154 | $data{$my_what}->{file} = $name; | ||
| 155 | $data{$my_what}->{description} .= $_; | ||
| 156 | $has_file = 1; | ||
| 157 | next; | 144 | next; |
| 158 | } | 145 | } |
| 159 | 146 | ||
| @@ -192,12 +179,8 @@ sub parse_abi { · 32 unmodified lines | |||
| 192 | # Everything else is error | 179 | # Everything else is error |
| 193 | parse_error($file, $ln, "Unexpected line:", $_); | 180 | parse_error($file, $ln, "Unexpected line:", $_); |
| 194 | } | 181 | } |
| 182 | $data{$nametag}->{description} =~ s/^\n+//; | ||
| 195 | close IN; | 183 | close IN; |
| 196 | |||
| 197 | if ($has_file) { | ||
| 198 | my $my_what = "File $name"; | ||
| 199 | $data{$my_what}->{xrefs} = $xrefs; | ||
| 200 | } | ||
| 201 | } | 184 | } |
| 202 | 185 | ||
| 203 | # Outputs the output on ReST format | 186 | # Outputs the output on ReST format |
| @@ -212,11 +195,22 @@ sub output_rest { · 8 unmodified lines | |||
| 212 | my $bar = $w; | 195 | my $bar = $w; |
| 213 | $bar =~ s/./-/g; | 196 | $bar =~ s/./-/g; |
| 214 | 197 | ||
| 215 | if ($data{$what}->{label}) { | 198 | foreach my $p (@{$data{$what}->{label}}) { |
| 216 | my @labels = split(/\s/, $data{$what}->{label}); | 199 | my ($content, $label) = @{$p}; |
| 217 | foreach my $label (@labels) { | 200 | $label = "abi_" . $label . " "; |
| 218 | printf ".. _%s:\n\n", $label; | 201 | $label =~ tr/A-Z/a-z/; |
| 219 | } | 202 | |
| 203 | # Convert special chars to "_" | ||
| 204 | $label =~s/([\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xff])/_/g; | ||
| 205 | $label =~ s,_+,_,g; | ||
| 206 | $label =~ s,_$,,; | ||
| 207 | |||
| 208 | $data{$what}->{label} .= $label; | ||
| 209 | |||
| 210 | printf ".. _%s:\n\n", $label; | ||
| 211 | |||
| 212 | # only one label is enough | ||
| 213 | last; | ||
| 220 | } | 214 | } |
| 221 | 215 | ||
| 222 | print "$w\n$bar\n\n"; | 216 | print "$w\n$bar\n\n"; |
| @@ -243,10 +237,28 @@ sub output_rest { · 20 unmodified lines | |||
| 243 | print "$desc\n\n"; | 237 | print "$desc\n\n"; |
| 244 | } | 238 | } |
| 245 | } else { | 239 | } else { |
| 246 | print "DESCRIPTION MISSING for $what\n\n"; | 240 | print "DESCRIPTION MISSING for $what\n\n" if (!$data{$what}->{is_file}); |
| 247 | } | 241 | } |
| 248 | 242 | ||
| 249 | printf "Has the following ABI:\n\n%s", $data{$what}->{xrefs} if ($data{$what}->{xrefs}); | 243 | if ($data{$what}->{xrefs}) { |
| 244 | printf "Has the following ABI:\n\n"; | ||
| 245 | |||
| 246 | foreach my $p(@{$data{$what}->{xrefs}}) { | ||
| 247 | my ($content, $label) = @{$p}; | ||
| 248 | $label = "abi_" . $label . " "; | ||
| 249 | $label =~ tr/A-Z/a-z/; | ||
| 250 | |||
| 251 | # Convert special chars to "_" | ||
| 252 | $label =~s/([\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xff])/_/g; | ||
| 253 | $label =~ s,_+,_,g; | ||
| 254 | $label =~ s,_$,,; | ||
| 255 | |||
| 256 | # Escape special chars from content | ||
| 257 | $content =~s/([\x00-\x1f\x21-\x2f\x3a-\x40\x7b-\xff])/\\$1/g; | ||
| 258 | |||
| 259 | print "- :ref:`$content <$label>`\n\n"; | ||
| 260 | } | ||
| 261 | } | ||
| 250 | } | 262 | } |
| 251 | } | 263 | } |
| 252 | 264 | ||