22# SPDX-License-Identifier: GPL-2.0
33
44use strict;
5+ use warnings;
56use Pod::Usage;
67use Getopt::Long;
78use File::Find;
89use Fcntl ' :mode' ;
910
10- my $help ;
11- my $man ;
12- my $debug ;
13- my $enable_lineno ;
11+ my $help = 0 ;
12+ my $man = 0 ;
13+ my $debug = 0 ;
14+ my $enable_lineno = 0 ;
1415my $prefix =" Documentation/ABI" ;
1516
1617#
4041require Data::Dumper if ($debug );
4142
4243my %data ;
44+ my %symbols ;
4345
4446#
4547# Displays an error message, printing file name and line
@@ -76,12 +78,12 @@ sub parse_abi {
7678
7779 my $what ;
7880 my $new_what ;
79- my $tag ;
81+ my $tag = " " ;
8082 my $ln ;
8183 my $xrefs ;
8284 my $space ;
8385 my @labels ;
84- my $label ;
86+ my $label = " " ;
8587
8688 print STDERR " Opening $file \n " if ($debug > 1);
8789 open IN, $file ;
@@ -110,10 +112,18 @@ sub parse_abi {
110112
111113 if ($new_tag =~ m / what/ ) {
112114 $space = " " ;
115+ $content =~ s / [,.;]$// ;
116+
113117 if ($tag =~ m / what/ ) {
114118 $what .= " , " . $content ;
115119 } 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+ }
117127
118128 $what = $content ;
119129 $label = $content ;
@@ -122,7 +132,7 @@ sub parse_abi {
122132 push @labels , [($content , $label )];
123133 $tag = $new_tag ;
124134
125- push @{$data {$nametag }-> {xrefs }}, [( $content , $label )] if ($data {$nametag }-> {what });
135+ push @{$data {$nametag }-> {symbols }}, $content if ($data {$nametag }-> {what });
126136 next ;
127137 }
128138
@@ -132,7 +142,7 @@ sub parse_abi {
132142 $data {$what }-> {line_no } = $ln ;
133143
134144 if ($new_what ) {
135- @{$data {$what }-> {label }} = @labels if ($data {$nametag }-> {what });
145+ @{$data {$what }-> {label_list }} = @labels if ($data {$nametag }-> {what });
136146 @labels = ();
137147 $label = " " ;
138148 $new_what = 0;
@@ -203,36 +213,24 @@ sub parse_abi {
203213 # Everything else is error
204214 parse_error($file , $ln , " Unexpected line:" , $_ );
205215 }
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+ }
207224 close IN;
208225}
209226
210- #
211- # Outputs the book on ReST format
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 ;
227+ sub create_labels {
228+ my %labels ;
233229
230+ foreach my $what (keys %data ) {
231+ next if ($data {$what }-> {file } eq " File" );
234232
235- foreach my $p (@{$data {$what }-> {label }}) {
233+ foreach my $p (@{$data {$what }-> {label_list }}) {
236234 my ($content , $label ) = @{$p };
237235 $label = " abi_" . $label . " " ;
238236 $label =~ tr / A-Z/ a-z/ ;
@@ -249,16 +247,39 @@ sub output_rest {
249247 }
250248 $labels {$label } = 1;
251249
252- $data {$what }-> {label } .= $label ;
253-
254- printf " .. _%s :\n\n " , $label ;
250+ $data {$what }-> {label } = $label ;
255251
256252 # only one label is enough
257253 last ;
258254 }
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+ }
259278
279+ my $w = $what ;
280+ $w =~ s / ([\(\)\_\-\*\=\^\~\\ ])/ \\ $1 / g ;
260281
261- $filepath =~ s ,.*/(.*/.*),\ 1,;;
282+ $filepath =~ s ,.*/(.*/.*),$ 1 ,;;
262283 $filepath =~ s ,[/\-],_,g;;
263284 my $fileref = " abi_file_" .$filepath ;
264285
@@ -269,8 +290,9 @@ sub output_rest {
269290 print " .. _$fileref :\n\n " ;
270291 print " $w \n $bar \n\n " ;
271292 } else {
272- my @names = split /\ s *,\ s */, $w ;
293+ printf " .. _ %s : \n\n " , $data { $what } -> { label } ;
273294
295+ my @names = split /, /,$w ;
274296 my $len = 0;
275297
276298 foreach my $name (@names ) {
@@ -284,12 +306,13 @@ sub output_rest {
284306 printf " | %s " , $name . " " x ($len - length ($name )) . " |\n " ;
285307 print " +-" . " -" x $len . " -+\n " ;
286308 }
287- print " \n " ;
288- }
289309
290- print " Defined on file :ref:`$file <$fileref >`\n\n " if ($type ne " File" );
310+ print " \n Defined on file :ref:`$file <$fileref >`\n\n " ;
311+ }
291312
292- my $desc = $data {$what }-> {description };
313+ my $desc = " " ;
314+ $desc = $data {$what }-> {description } if (defined ($data {$what }-> {description }));
315+ $desc =~ s /\s +$/ \n / ;
293316
294317 if (!($desc =~ / ^\s *$ / )) {
295318 if ($description_is_rst ) {
@@ -316,18 +339,11 @@ sub output_rest {
316339 print " DESCRIPTION MISSING for $what \n\n " if (!$data {$what }-> {is_file });
317340 }
318341
319- if ($data {$what }-> {xrefs }) {
342+ if ($data {$what }-> {symbols }) {
320343 printf " Has the following ABI:\n\n " ;
321344
322- foreach my $p (@{$data {$what }-> {xrefs }}) {
323- my ($content , $label ) = @{$p };
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 ,_$, ,;
345+ foreach my $content (@{$data {$what }-> {symbols }}) {
346+ my $label = $data {$symbols {$content }}-> {label };
331347
332348 # Escape special chars from content
333349 $content =~s / ([\x00 -\x1f\x21 -\x2f\x3a -\x40\x7b -\xff ])/ \\ $1 / g ;
@@ -355,17 +371,20 @@ sub search_symbols {
355371
356372 print " \n $what \n $bar \n\n " ;
357373
358- my $kernelversion = $data {$what }-> {kernelversion };
359- my $contact = $data {$what }-> {contact };
360- my $users = $data {$what }-> {users };
361- my $date = $data {$what }-> {date };
362- my $desc = $data {$what }-> {description };
363- $kernelversion =~ s / ^\s +// ;
364- $contact =~ s / ^\s +// ;
365- $users =~ s / ^\s +// ;
366- $users =~ s /\n // g ;
367- $date =~ s / ^\s +// ;
368- $desc =~ s / ^\s +// ;
374+ my $kernelversion = $data {$what }-> {kernelversion } if (defined ($data {$what }-> {kernelversion }));
375+ my $contact = $data {$what }-> {contact } if (defined ($data {$what }-> {contact }));
376+ my $users = $data {$what }-> {users } if (defined ($data {$what }-> {users }));
377+ my $date = $data {$what }-> {date } if (defined ($data {$what }-> {date }));
378+ my $desc = $data {$what }-> {description } if (defined ($data {$what }-> {description }));
379+
380+ $kernelversion =~ s / ^\s +// if ($kernelversion );
381+ $contact =~ s / ^\s +// if ($contact );
382+ if ($users ) {
383+ $users =~ s / ^\s +// ;
384+ $users =~ s /\n // g ;
385+ }
386+ $date =~ s / ^\s +// if ($date );
387+ $desc =~ s / ^\s +// if ($desc );
369388
370389 printf " Kernel version:\t\t %s \n " , $kernelversion if ($kernelversion );
371390 printf " Date:\t\t\t %s \n " , $date if ($date );
0 commit comments