History

scripts: get_abi.pl: parse description line per line

Change the description parsing logic in rst mode in order to parse it line per line. The end result is the same, but doing line per line allows to add some code to escape literal blocks when seeking for cross-references.

Mauro Carvalho Chehab committed 5 years ago

Commit c27c2e31 parent 87ec9ea1 file · +28 −21Browse files

Showing the changes to scripts (1 of 1 file). Show all

Unified · Split

scripts/get_abi.pl+28−21
@@ -381,34 +381,41 @@ sub output_rest { · 380 unmodified lines
381381
382382 # Enrich text by creating cross-references
383383
384− $desc =~ s,Documentation/(?!devicetree)(\S+)\.rst,:doc:`/$1`,g;
385−
386− my @matches = $desc =~ m,Documentation/ABI/([\w\/\-]+),g;
387− foreach my $f (@matches) {
388− my $xref = $f;
389− my $path = $f;
390− $path =~ s,.*/(.*/.*),$1,;;
391− $path =~ s,[/\-],_,g;;
392− $xref .= " <abi_file_" . $path . ">";
393− $desc =~ s,\bDocumentation/ABI/$f\b,:ref:`$xref`,g;
394− }
384+ my $new_desc = "";
385+ open(my $fh, "+<", \$desc);
386+ while (my $d = <$fh>) {
387+ $d =~ s,Documentation/(?!devicetree)(\S+)\.rst,:doc:`/$1`,g;
388+
389+ my @matches = $d =~ m,Documentation/ABI/([\w\/\-]+),g;
390+ foreach my $f (@matches) {
391+ my $xref = $f;
392+ my $path = $f;
393+ $path =~ s,.*/(.*/.*),$1,;;
394+ $path =~ s,[/\-],_,g;;
395+ $xref .= " <abi_file_" . $path . ">";
396+ $d =~ s,\bDocumentation/ABI/$f\b,:ref:`$xref`,g;
397+ }
395398
396− # Seek for cross reference symbols like /sys/...
397− @matches = $desc =~ m/$xref_match/g;
399+ # Seek for cross reference symbols like /sys/...
400+ @matches = $d =~ m/$xref_match/g;
398401
399− foreach my $s (@matches) {
400− next if (!($s =~ m,/,));
401− if (defined($data{$s}) && defined($data{$s}->{label})) {
402− my $xref = $s;
402+ foreach my $s (@matches) {
403+ next if (!($s =~ m,/,));
404+ if (defined($data{$s}) && defined($data{$s}->{label})) {
405+ my $xref = $s;
403406
404− $xref =~ s/$symbols/\\$1/g;
405− $xref = ":ref:`$xref <" . $data{$s}->{label} . ">`";
407+ $xref =~ s/$symbols/\\$1/g;
408+ $xref = ":ref:`$xref <" . $data{$s}->{label} . ">`";
406409
407− $desc =~ s,$start$s$bondary,$1$xref$2,g;
410+ $d =~ s,$start$s$bondary,$1$xref$2,g;
411+ }
408412 }
413+ $new_desc .= $d;
409414 }
415+ close $fh;
416+
410417
411− print "$desc\n\n";
418+ print "$new_desc\n\n";
412419 } else {
413420 $desc =~ s/^\s+//;
414421