Right now, the cross-references are generated on a single step, when doing ReST output. While this is nice optimization, it prevents auto-creating cross-references for ABI symbols. So, split it into a separate logic. While here, turn on Perl warnings, as it helps to debug problems inside the script.
Showing the changes to scripts (1 of 1 file). Show all
Unified · Split
| @@ -2,15 +2,16 @@ · 1 unmodified line | |||
| 2 | # SPDX-License-Identifier: GPL-2.0 | 2 | # SPDX-License-Identifier: GPL-2.0 |
| 3 | 3 | ||
| 4 | use strict; | 4 | use strict; |
| 5 | use warnings; | ||
| 5 | use Pod::Usage; | 6 | use Pod::Usage; |
| 6 | use Getopt::Long; | 7 | use Getopt::Long; |
| 7 | use File::Find; | 8 | use File::Find; |
| 8 | use Fcntl ':mode'; | 9 | use Fcntl ':mode'; |
| 9 | 10 | ||
| 10 | my $help; | 11 | my $help = 0; |
| 11 | my $man; | 12 | my $man = 0; |
| 12 | my $debug; | 13 | my $debug = 0; |
| 13 | my $enable_lineno; | 14 | my $enable_lineno = 0; |
| 14 | my $prefix="Documentation/ABI"; | 15 | my $prefix="Documentation/ABI"; |
| 15 | 16 | ||
| 16 | # | 17 | # |
| @@ -40,6 +41,7 @@ pod2usage(2) if ($cmd eq "search" && !$arg); · 23 unmodified lines | |||
| 40 | require Data::Dumper if ($debug); | 41 | require Data::Dumper if ($debug); |
| 41 | 42 | ||
| 42 | my %data; | 43 | my %data; |
| 44 | my %symbols; | ||
| 43 | 45 | ||
| 44 | # | 46 | # |
| 45 | # Displays an error message, printing file name and line | 47 | # Displays an error message, printing file name and line |
| @@ -76,12 +78,12 @@ sub parse_abi { · 30 unmodified lines | |||
| 76 | 78 | ||
| 77 | my $what; | 79 | my $what; |
| 78 | my $new_what; | 80 | my $new_what; |
| 79 | my $tag; | 81 | my $tag = ""; |
| 80 | my $ln; | 82 | my $ln; |
| 81 | my $xrefs; | 83 | my $xrefs; |
| 82 | my $space; | 84 | my $space; |
| 83 | my @labels; | 85 | my @labels; |
| 84 | my $label; | 86 | my $label = ""; |
| 85 | 87 | ||
| 86 | print STDERR "Opening $file\n" if ($debug > 1); | 88 | print STDERR "Opening $file\n" if ($debug > 1); |
| 87 | open IN, $file; | 89 | open IN, $file; |
| @@ -110,10 +112,18 @@ sub parse_abi { · 22 unmodified lines | |||
| 110 | 112 | ||
| 111 | if ($new_tag =~ m/what/) { | 113 | if ($new_tag =~ m/what/) { |
| 112 | $space = ""; | 114 | $space = ""; |
| 115 | $content =~ s/[,.;]$//; | ||
| 116 | |||
| 113 | if ($tag =~ m/what/) { | 117 | if ($tag =~ m/what/) { |
| 114 | $what .= ", " . $content; | 118 | $what .= ", " . $content; |
| 115 | } else { | 119 | } else { |
| 116 | parse_error($file, $ln, "What '$what' doesn't have a description", "") if ($what && !$data{$what}->{description}); | 120 | if ($what) { |
| 121 | parse_error($file, $ln, "What '$what' doesn't have a description", "") if (!$data{$what}->{description}); | ||
| 122 | |||
| 123 | foreach my $w(split /, /, $what) { | ||
| 124 | $symbols{$w} = $what; | ||
| 125 | }; | ||
| 126 | } | ||
| 117 | 127 | ||
| 118 | $what = $content; | 128 | $what = $content; |
| 119 | $label = $content; | 129 | $label = $content; |
| @@ -122,7 +132,7 @@ sub parse_abi { · 2 unmodified lines | |||
| 122 | push @labels, [($content, $label)]; | 132 | push @labels, [($content, $label)]; |
| 123 | $tag = $new_tag; | 133 | $tag = $new_tag; |
| 124 | 134 | ||
| 125 | push @{$data{$nametag}->{xrefs}}, [($content, $label)] if ($data{$nametag}->{what}); | 135 | push @{$data{$nametag}->{symbols}}, $content if ($data{$nametag}->{what}); |
| 126 | next; | 136 | next; |
| 127 | } | 137 | } |
| 128 | 138 | ||
| @@ -132,7 +142,7 @@ sub parse_abi { · 3 unmodified lines | |||
| 132 | $data{$what}->{line_no} = $ln; | 142 | $data{$what}->{line_no} = $ln; |
| 133 | 143 | ||
| 134 | if ($new_what) { | 144 | if ($new_what) { |
| 135 | @{$data{$what}->{label}} = @labels if ($data{$nametag}->{what}); | 145 | @{$data{$what}->{label_list}} = @labels if ($data{$nametag}->{what}); |
| 136 | @labels = (); | 146 | @labels = (); |
| 137 | $label = ""; | 147 | $label = ""; |
| 138 | $new_what = 0; | 148 | $new_what = 0; |
| @@ -203,36 +213,24 @@ sub parse_abi { · 64 unmodified lines | |||
| 203 | # Everything else is error | 213 | # Everything else is error |
| 204 | parse_error($file, $ln, "Unexpected line:", $_); | 214 | parse_error($file, $ln, "Unexpected line:", $_); |
| 205 | } | 215 | } |
| 206 | $data{$nametag}->{description} =~ s/^\n+//; | 216 | $data{$nametag}->{description} =~ s/^\n+// if ($data{$nametag}->{description}); |
| 217 | if ($what) { | ||
| 218 | parse_error($file, $ln, "What '$what' doesn't have a description", "") if (!$data{$what}->{description}); | ||
| 219 | |||
| 220 | foreach my $w(split /, /,$what) { | ||
| 221 | $symbols{$w} = $what; | ||
| 222 | }; | ||
| 223 | } | ||
| 207 | close IN; | 224 | close IN; |
| 208 | } | 225 | } |
| 209 | 226 | ||
| 210 | # | 227 | sub create_labels { |
| 211 | # Outputs the book on ReST format | 228 | my %labels; |
| 212 | # | ||
| 213 | |||
| 214 | my %labels; | ||
| 215 | |||
| 216 | sub output_rest { | ||
| 217 | foreach my $what (sort { | ||
| 218 | ($data{$a}->{type} eq "File") cmp ($data{$b}->{type} eq "File") || | ||
| 219 | $a cmp $b | ||
| 220 | } keys %data) { | ||
| 221 | my $type = $data{$what}->{type}; | ||
| 222 | my $file = $data{$what}->{file}; | ||
| 223 | my $filepath = $data{$what}->{filepath}; | ||
| 224 | |||
| 225 | if ($enable_lineno) { | ||
| 226 | printf "#define LINENO %s%s#%s\n\n", | ||
| 227 | $prefix, $data{$what}->{file}, | ||
| 228 | $data{$what}->{line_no}; | ||
| 229 | } | ||
| 230 | |||
| 231 | my $w = $what; | ||
| 232 | $w =~ s/([\(\)\_\-\*\=\^\~\\])/\\$1/g; | ||
| 233 | 229 | ||
| 230 | foreach my $what (keys %data) { | ||
| 231 | next if ($data{$what}->{file} eq "File"); | ||
| 234 | 232 | ||
| 235 | foreach my $p (@{$data{$what}->{label}}) { | 233 | foreach my $p (@{$data{$what}->{label_list}}) { |
| 236 | my ($content, $label) = @{$p}; | 234 | my ($content, $label) = @{$p}; |
| 237 | $label = "abi_" . $label . " "; | 235 | $label = "abi_" . $label . " "; |
| 238 | $label =~ tr/A-Z/a-z/; | 236 | $label =~ tr/A-Z/a-z/; |
| @@ -249,16 +247,39 @@ sub output_rest { · 10 unmodified lines | |||
| 249 | } | 247 | } |
| 250 | $labels{$label} = 1; | 248 | $labels{$label} = 1; |
| 251 | 249 | ||
| 252 | $data{$what}->{label} .= $label; | 250 | $data{$what}->{label} = $label; |
| 253 | |||
| 254 | printf ".. _%s:\n\n", $label; | ||
| 255 | 251 | ||
| 256 | # only one label is enough | 252 | # only one label is enough |
| 257 | last; | 253 | last; |
| 258 | } | 254 | } |
| 255 | } | ||
| 256 | } | ||
| 257 | |||
| 258 | # | ||
| 259 | # Outputs the book on ReST format | ||
| 260 | # | ||
| 261 | |||
| 262 | sub output_rest { | ||
| 263 | create_labels(); | ||
| 264 | |||
| 265 | foreach my $what (sort { | ||
| 266 | ($data{$a}->{type} eq "File") cmp ($data{$b}->{type} eq "File") || | ||
| 267 | $a cmp $b | ||
| 268 | } keys %data) { | ||
| 269 | my $type = $data{$what}->{type}; | ||
| 270 | my $file = $data{$what}->{file}; | ||
| 271 | my $filepath = $data{$what}->{filepath}; | ||
| 272 | |||
| 273 | if ($enable_lineno) { | ||
| 274 | printf "#define LINENO %s%s#%s\n\n", | ||
| 275 | $prefix, $data{$what}->{file}, | ||
| 276 | $data{$what}->{line_no}; | ||
| 277 | } | ||
| 259 | 278 | ||
| 279 | my $w = $what; | ||
| 280 | $w =~ s/([\(\)\_\-\*\=\^\~\\])/\\$1/g; | ||
| 260 | 281 | ||
| 261 | $filepath =~ s,.*/(.*/.*),\1,;; | 282 | $filepath =~ s,.*/(.*/.*),$1,;; |
| 262 | $filepath =~ s,[/\-],_,g;; | 283 | $filepath =~ s,[/\-],_,g;; |
| 263 | my $fileref = "abi_file_".$filepath; | 284 | my $fileref = "abi_file_".$filepath; |
| 264 | 285 | ||
| @@ -269,8 +290,9 @@ sub output_rest { · 4 unmodified lines | |||
| 269 | print ".. _$fileref:\n\n"; | 290 | print ".. _$fileref:\n\n"; |
| 270 | print "$w\n$bar\n\n"; | 291 | print "$w\n$bar\n\n"; |
| 271 | } else { | 292 | } else { |
| 272 | my @names = split /\s*,\s*/,$w; | 293 | printf ".. _%s:\n\n", $data{$what}->{label}; |
| 273 | 294 | ||
| 295 | my @names = split /, /,$w; | ||
| 274 | my $len = 0; | 296 | my $len = 0; |
| 275 | 297 | ||
| 276 | foreach my $name (@names) { | 298 | foreach my $name (@names) { |
| @@ -284,12 +306,13 @@ sub output_rest { · 7 unmodified lines | |||
| 284 | printf "| %s", $name . " " x ($len - length($name)) . " |\n"; | 306 | printf "| %s", $name . " " x ($len - length($name)) . " |\n"; |
| 285 | print "+-" . "-" x $len . "-+\n"; | 307 | print "+-" . "-" x $len . "-+\n"; |
| 286 | } | 308 | } |
| 287 | print "\n"; | ||
| 288 | } | ||
| 289 | 309 | ||
| 290 | print "Defined on file :ref:`$file <$fileref>`\n\n" if ($type ne "File"); | 310 | print "\nDefined on file :ref:`$file <$fileref>`\n\n"; |
| 311 | } | ||
| 291 | 312 | ||
| 292 | my $desc = $data{$what}->{description}; | 313 | my $desc = ""; |
| 314 | $desc = $data{$what}->{description} if (defined($data{$what}->{description})); | ||
| 315 | $desc =~ s/\s+$/\n/; | ||
| 293 | 316 | ||
| 294 | if (!($desc =~ /^\s*$/)) { | 317 | if (!($desc =~ /^\s*$/)) { |
| 295 | if ($description_is_rst) { | 318 | if ($description_is_rst) { |
| @@ -316,18 +339,11 @@ sub output_rest { · 20 unmodified lines | |||
| 316 | print "DESCRIPTION MISSING for $what\n\n" if (!$data{$what}->{is_file}); | 339 | print "DESCRIPTION MISSING for $what\n\n" if (!$data{$what}->{is_file}); |
| 317 | } | 340 | } |
| 318 | 341 | ||
| 319 | if ($data{$what}->{xrefs}) { | 342 | if ($data{$what}->{symbols}) { |
| 320 | printf "Has the following ABI:\n\n"; | 343 | printf "Has the following ABI:\n\n"; |
| 321 | 344 | ||
| 322 | foreach my $p(@{$data{$what}->{xrefs}}) { | 345 | foreach my $content(@{$data{$what}->{symbols}}) { |
| 323 | my ($content, $label) = @{$p}; | 346 | my $label = $data{$symbols{$content}}->{label}; |
| 324 | $label = "abi_" . $label . " "; | ||
| 325 | $label =~ tr/A-Z/a-z/; | ||
| 326 | |||
| 327 | # Convert special chars to "_" | ||
| 328 | $label =~s/([\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xff])/_/g; | ||
| 329 | $label =~ s,_+,_,g; | ||
| 330 | $label =~ s,_$,,; | ||
| 331 | 347 | ||
| 332 | # Escape special chars from content | 348 | # Escape special chars from content |
| 333 | $content =~s/([\x00-\x1f\x21-\x2f\x3a-\x40\x7b-\xff])/\\$1/g; | 349 | $content =~s/([\x00-\x1f\x21-\x2f\x3a-\x40\x7b-\xff])/\\$1/g; |
| @@ -355,17 +371,20 @@ sub search_symbols { · 21 unmodified lines | |||
| 355 | 371 | ||
| 356 | print "\n$what\n$bar\n\n"; | 372 | print "\n$what\n$bar\n\n"; |
| 357 | 373 | ||
| 358 | my $kernelversion = $data{$what}->{kernelversion}; | 374 | my $kernelversion = $data{$what}->{kernelversion} if (defined($data{$what}->{kernelversion})); |
| 359 | my $contact = $data{$what}->{contact}; | 375 | my $contact = $data{$what}->{contact} if (defined($data{$what}->{contact})); |
| 360 | my $users = $data{$what}->{users}; | 376 | my $users = $data{$what}->{users} if (defined($data{$what}->{users})); |
| 361 | my $date = $data{$what}->{date}; | 377 | my $date = $data{$what}->{date} if (defined($data{$what}->{date})); |
| 362 | my $desc = $data{$what}->{description}; | 378 | my $desc = $data{$what}->{description} if (defined($data{$what}->{description})); |
| 363 | $kernelversion =~ s/^\s+//; | 379 | |
| 364 | $contact =~ s/^\s+//; | 380 | $kernelversion =~ s/^\s+// if ($kernelversion); |
| 365 | $users =~ s/^\s+//; | 381 | $contact =~ s/^\s+// if ($contact); |
| 366 | $users =~ s/\n//g; | 382 | if ($users) { |
| 367 | $date =~ s/^\s+//; | 383 | $users =~ s/^\s+//; |
| 368 | $desc =~ s/^\s+//; | 384 | $users =~ s/\n//g; |
| 385 | } | ||
| 386 | $date =~ s/^\s+// if ($date); | ||
| 387 | $desc =~ s/^\s+// if ($desc); | ||
| 369 | 388 | ||
| 370 | printf "Kernel version:\t\t%s\n", $kernelversion if ($kernelversion); | 389 | printf "Kernel version:\t\t%s\n", $kernelversion if ($kernelversion); |
| 371 | printf "Date:\t\t\t%s\n", $date if ($date); | 390 | printf "Date:\t\t\t%s\n", $date if ($date); |