Skip to content

Commit d0ebaf5

Browse files
mchehabgregkh
authored andcommitted
scripts/get_abi.pl: split label naming from xref logic
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. Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 4e6a623 commit d0ebaf5

1 file changed

Lines changed: 53 additions & 41 deletions

File tree

‎scripts/get_abi.pl‎

Lines changed: 53 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,23 @@ sub parse_abi {
4949
my $name = $file;
5050
$name =~ s,.*/,,;
5151

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+
5258
my $type = $file;
5359
$type =~ s,.*/(.*)/.*,$1,;
5460

5561
my $what;
5662
my $new_what;
5763
my $tag;
58-
my $label;
5964
my $ln;
60-
my $has_file;
6165
my $xrefs;
6266
my $space;
67+
my @labels;
68+
my $label;
6369

6470
print STDERR "Opening $file\n" if ($debug > 1);
6571
open IN, $file;
@@ -88,35 +94,23 @@ sub parse_abi {
8894
parse_error($file, $ln, "What '$what' doesn't have a description", "") if ($what && !$data{$what}->{description});
8995

9096
$what = $content;
97+
$label = $content;
9198
$new_what = 1;
9299
}
100+
push @labels, [($content, $label)];
93101
$tag = $new_tag;
94102

95-
if ($has_file) {
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-
}
103+
push @{$data{$nametag}->{xrefs}}, [($content, $label)] if ($data{$nametag}->{what});
113104
next;
114105
}
115106

116107
if ($new_tag) {
117108
$tag = $new_tag;
118109

119110
if ($new_what) {
111+
@{$data{$what}->{label}} = @labels if ($data{$nametag}->{what});
112+
@labels = ();
113+
$label = "";
120114
$new_what = 0;
121115

122116
$data{$what}->{type} = $type;
@@ -145,15 +139,8 @@ sub parse_abi {
145139
}
146140

147141
# Store any contents before tags at the database
148-
if (!$tag) {
149-
next if (/^\n/);
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;
142+
if (!$tag && $data{$nametag}->{what}) {
143+
$data{$nametag}->{description} .= $_;
157144
next;
158145
}
159146

@@ -192,12 +179,8 @@ sub parse_abi {
192179
# Everything else is error
193180
parse_error($file, $ln, "Unexpected line:", $_);
194181
}
182+
$data{$nametag}->{description} =~ s/^\n+//;
195183
close IN;
196-
197-
if ($has_file) {
198-
my $my_what = "File $name";
199-
$data{$my_what}->{xrefs} = $xrefs;
200-
}
201184
}
202185

203186
# Outputs the output on ReST format
@@ -212,11 +195,22 @@ sub output_rest {
212195
my $bar = $w;
213196
$bar =~ s/./-/g;
214197

215-
if ($data{$what}->{label}) {
216-
my @labels = split(/\s/, $data{$what}->{label});
217-
foreach my $label (@labels) {
218-
printf ".. _%s:\n\n", $label;
219-
}
198+
foreach my $p (@{$data{$what}->{label}}) {
199+
my ($content, $label) = @{$p};
200+
$label = "abi_" . $label . " ";
201+
$label =~ tr/A-Z/a-z/;
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;
220214
}
221215

222216
print "$w\n$bar\n\n";
@@ -243,10 +237,28 @@ sub output_rest {
243237
print "$desc\n\n";
244238
}
245239
} else {
246-
print "DESCRIPTION MISSING for $what\n\n";
240+
print "DESCRIPTION MISSING for $what\n\n" if (!$data{$what}->{is_file});
247241
}
248242

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+
}
250262
}
251263
}
252264

0 commit comments

Comments
 (0)