Mauro Carvalho Chehab | bbc249f | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 1 | #!/usr/bin/perl |
| 2 | |
| 3 | use strict; |
| 4 | use Pod::Usage; |
| 5 | use Getopt::Long; |
| 6 | use File::Find; |
| 7 | use Fcntl ':mode'; |
| 8 | |
| 9 | my $help; |
| 10 | my $man; |
| 11 | my $debug; |
Mauro Carvalho Chehab | 33e3e99 | 2019-06-20 14:22:59 -0300 | [diff] [blame] | 12 | my $prefix="Documentation/ABI"; |
Mauro Carvalho Chehab | bbc249f | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 13 | |
| 14 | GetOptions( |
| 15 | "debug|d+" => \$debug, |
Mauro Carvalho Chehab | 33e3e99 | 2019-06-20 14:22:59 -0300 | [diff] [blame] | 16 | "dir=s" => \$prefix, |
Mauro Carvalho Chehab | bbc249f | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 17 | 'help|?' => \$help, |
| 18 | man => \$man |
| 19 | ) or pod2usage(2); |
| 20 | |
| 21 | pod2usage(1) if $help; |
| 22 | pod2usage(-exitstatus => 0, -verbose => 2) if $man; |
| 23 | |
Mauro Carvalho Chehab | 33e3e99 | 2019-06-20 14:22:59 -0300 | [diff] [blame] | 24 | pod2usage(2) if (scalar @ARGV < 1 || @ARGV > 2); |
Mauro Carvalho Chehab | bbc249f | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 25 | |
Mauro Carvalho Chehab | 33e3e99 | 2019-06-20 14:22:59 -0300 | [diff] [blame] | 26 | my ($cmd, $arg) = @ARGV; |
| 27 | |
| 28 | pod2usage(2) if ($cmd ne "search" && $cmd ne "rest"); |
| 29 | pod2usage(2) if ($cmd eq "search" && !$arg); |
Mauro Carvalho Chehab | bbc249f | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 30 | |
| 31 | require Data::Dumper if ($debug); |
| 32 | |
| 33 | my %data; |
| 34 | |
| 35 | # |
| 36 | # Displays an error message, printing file name and line |
| 37 | # |
| 38 | sub parse_error($$$$) { |
| 39 | my ($file, $ln, $msg, $data) = @_; |
| 40 | |
| 41 | print STDERR "file $file#$ln: $msg at\n\t$data"; |
| 42 | } |
| 43 | |
| 44 | # |
| 45 | # Parse an ABI file, storing its contents at %data |
| 46 | # |
| 47 | sub parse_abi { |
| 48 | my $file = $File::Find::name; |
| 49 | |
| 50 | my $mode = (stat($file))[2]; |
| 51 | return if ($mode & S_IFDIR); |
| 52 | return if ($file =~ m,/README,); |
| 53 | |
| 54 | my $name = $file; |
| 55 | $name =~ s,.*/,,; |
| 56 | |
Mauro Carvalho Chehab | d0ebaf5 | 2019-06-20 14:22:58 -0300 | [diff] [blame] | 57 | my $nametag = "File $name"; |
| 58 | $data{$nametag}->{what} = "File $name"; |
| 59 | $data{$nametag}->{type} = "File"; |
| 60 | $data{$nametag}->{file} = $name; |
Mauro Carvalho Chehab | 33e3e99 | 2019-06-20 14:22:59 -0300 | [diff] [blame] | 61 | $data{$nametag}->{filepath} = $file; |
Mauro Carvalho Chehab | d0ebaf5 | 2019-06-20 14:22:58 -0300 | [diff] [blame] | 62 | $data{$nametag}->{is_file} = 1; |
| 63 | |
Mauro Carvalho Chehab | bbc249f | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 64 | my $type = $file; |
| 65 | $type =~ s,.*/(.*)/.*,$1,; |
| 66 | |
| 67 | my $what; |
| 68 | my $new_what; |
| 69 | my $tag; |
| 70 | my $ln; |
Mauro Carvalho Chehab | 6619c66 | 2019-06-20 14:22:56 -0300 | [diff] [blame] | 71 | my $xrefs; |
Mauro Carvalho Chehab | 4e6a623 | 2019-06-20 14:22:57 -0300 | [diff] [blame] | 72 | my $space; |
Mauro Carvalho Chehab | d0ebaf5 | 2019-06-20 14:22:58 -0300 | [diff] [blame] | 73 | my @labels; |
| 74 | my $label; |
Mauro Carvalho Chehab | bbc249f | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 75 | |
| 76 | print STDERR "Opening $file\n" if ($debug > 1); |
| 77 | open IN, $file; |
| 78 | while(<IN>) { |
| 79 | $ln++; |
Mauro Carvalho Chehab | 4e6a623 | 2019-06-20 14:22:57 -0300 | [diff] [blame] | 80 | if (m/^(\S+)(:\s*)(.*)/i) { |
Mauro Carvalho Chehab | bbc249f | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 81 | my $new_tag = lc($1); |
Mauro Carvalho Chehab | 4e6a623 | 2019-06-20 14:22:57 -0300 | [diff] [blame] | 82 | my $sep = $2; |
| 83 | my $content = $3; |
Mauro Carvalho Chehab | bbc249f | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 84 | |
| 85 | if (!($new_tag =~ m/(what|date|kernelversion|contact|description|users)/)) { |
| 86 | if ($tag eq "description") { |
Mauro Carvalho Chehab | 4e6a623 | 2019-06-20 14:22:57 -0300 | [diff] [blame] | 87 | # New "tag" is actually part of |
| 88 | # description. Don't consider it a tag |
| 89 | $new_tag = ""; |
Mauro Carvalho Chehab | 7d7ea8d | 2019-06-20 14:23:01 -0300 | [diff] [blame] | 90 | } elsif ($tag ne "") { |
Mauro Carvalho Chehab | bbc249f | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 91 | parse_error($file, $ln, "tag '$tag' is invalid", $_); |
| 92 | } |
| 93 | } |
| 94 | |
Mauro Carvalho Chehab | 2c0700e | 2019-06-20 14:23:03 -0300 | [diff] [blame^] | 95 | # Invalid, but it is a common mistake |
| 96 | if ($new_tag eq "where") { |
| 97 | parse_error($file, $ln, "tag 'Where' is invalid. Should be 'What:' instead", $_); |
| 98 | $new_tag = "what"; |
| 99 | } |
| 100 | |
Mauro Carvalho Chehab | bbc249f | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 101 | if ($new_tag =~ m/what/) { |
Mauro Carvalho Chehab | 4e6a623 | 2019-06-20 14:22:57 -0300 | [diff] [blame] | 102 | $space = ""; |
Mauro Carvalho Chehab | bbc249f | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 103 | if ($tag =~ m/what/) { |
| 104 | $what .= ", " . $content; |
| 105 | } else { |
Mauro Carvalho Chehab | 4e6a623 | 2019-06-20 14:22:57 -0300 | [diff] [blame] | 106 | parse_error($file, $ln, "What '$what' doesn't have a description", "") if ($what && !$data{$what}->{description}); |
| 107 | |
Mauro Carvalho Chehab | bbc249f | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 108 | $what = $content; |
Mauro Carvalho Chehab | d0ebaf5 | 2019-06-20 14:22:58 -0300 | [diff] [blame] | 109 | $label = $content; |
Mauro Carvalho Chehab | bbc249f | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 110 | $new_what = 1; |
| 111 | } |
Mauro Carvalho Chehab | d0ebaf5 | 2019-06-20 14:22:58 -0300 | [diff] [blame] | 112 | push @labels, [($content, $label)]; |
Mauro Carvalho Chehab | bbc249f | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 113 | $tag = $new_tag; |
Mauro Carvalho Chehab | 6619c66 | 2019-06-20 14:22:56 -0300 | [diff] [blame] | 114 | |
Mauro Carvalho Chehab | d0ebaf5 | 2019-06-20 14:22:58 -0300 | [diff] [blame] | 115 | push @{$data{$nametag}->{xrefs}}, [($content, $label)] if ($data{$nametag}->{what}); |
Mauro Carvalho Chehab | bbc249f | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 116 | next; |
| 117 | } |
| 118 | |
Mauro Carvalho Chehab | 7d7ea8d | 2019-06-20 14:23:01 -0300 | [diff] [blame] | 119 | if ($tag ne "" && $new_tag) { |
Mauro Carvalho Chehab | 4e6a623 | 2019-06-20 14:22:57 -0300 | [diff] [blame] | 120 | $tag = $new_tag; |
Mauro Carvalho Chehab | bbc249f | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 121 | |
Mauro Carvalho Chehab | 4e6a623 | 2019-06-20 14:22:57 -0300 | [diff] [blame] | 122 | if ($new_what) { |
Mauro Carvalho Chehab | d0ebaf5 | 2019-06-20 14:22:58 -0300 | [diff] [blame] | 123 | @{$data{$what}->{label}} = @labels if ($data{$nametag}->{what}); |
| 124 | @labels = (); |
| 125 | $label = ""; |
Mauro Carvalho Chehab | 4e6a623 | 2019-06-20 14:22:57 -0300 | [diff] [blame] | 126 | $new_what = 0; |
Mauro Carvalho Chehab | bbc249f | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 127 | |
Mauro Carvalho Chehab | 4e6a623 | 2019-06-20 14:22:57 -0300 | [diff] [blame] | 128 | $data{$what}->{type} = $type; |
| 129 | $data{$what}->{file} = $name; |
Mauro Carvalho Chehab | 33e3e99 | 2019-06-20 14:22:59 -0300 | [diff] [blame] | 130 | $data{$what}->{filepath} = $file; |
Mauro Carvalho Chehab | 4e6a623 | 2019-06-20 14:22:57 -0300 | [diff] [blame] | 131 | print STDERR "\twhat: $what\n" if ($debug > 1); |
| 132 | } |
Mauro Carvalho Chehab | bbc249f | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 133 | |
Mauro Carvalho Chehab | 4e6a623 | 2019-06-20 14:22:57 -0300 | [diff] [blame] | 134 | if (!$what) { |
| 135 | parse_error($file, $ln, "'What:' should come first:", $_); |
| 136 | next; |
| 137 | } |
| 138 | if ($tag eq "description") { |
| 139 | next if ($content =~ m/^\s*$/); |
| 140 | if ($content =~ m/^(\s*)(.*)/) { |
| 141 | my $new_content = $2; |
| 142 | $space = $new_tag . $sep . $1; |
| 143 | while ($space =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e) {} |
| 144 | $space =~ s/./ /g; |
| 145 | $data{$what}->{$tag} .= "$new_content\n"; |
| 146 | } |
| 147 | } else { |
| 148 | $data{$what}->{$tag} = $content; |
| 149 | } |
Mauro Carvalho Chehab | bbc249f | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 150 | next; |
| 151 | } |
Mauro Carvalho Chehab | bbc249f | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 152 | } |
| 153 | |
Mauro Carvalho Chehab | 4e6a623 | 2019-06-20 14:22:57 -0300 | [diff] [blame] | 154 | # Store any contents before tags at the database |
Mauro Carvalho Chehab | d0ebaf5 | 2019-06-20 14:22:58 -0300 | [diff] [blame] | 155 | if (!$tag && $data{$nametag}->{what}) { |
| 156 | $data{$nametag}->{description} .= $_; |
Mauro Carvalho Chehab | 6619c66 | 2019-06-20 14:22:56 -0300 | [diff] [blame] | 157 | next; |
| 158 | } |
Mauro Carvalho Chehab | bbc249f | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 159 | |
Mauro Carvalho Chehab | 4e6a623 | 2019-06-20 14:22:57 -0300 | [diff] [blame] | 160 | if ($tag eq "description") { |
| 161 | if (!$data{$what}->{description}) { |
| 162 | next if (m/^\s*\n/); |
| 163 | if (m/^(\s*)(.*)/) { |
| 164 | $space = $1; |
| 165 | while ($space =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e) {} |
| 166 | $data{$what}->{$tag} .= "$2\n"; |
| 167 | } |
| 168 | } else { |
| 169 | my $content = $_; |
| 170 | if (m/^\s*\n/) { |
| 171 | $data{$what}->{$tag} .= $content; |
| 172 | next; |
| 173 | } |
| 174 | |
| 175 | while ($content =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e) {} |
| 176 | $space = "" if (!($content =~ s/^($space)//)); |
| 177 | |
| 178 | # Compress spaces with tabs |
| 179 | $content =~ s<^ {8}> <\t>; |
| 180 | $content =~ s<^ {1,7}\t> <\t>; |
| 181 | $content =~ s< {1,7}\t> <\t>; |
| 182 | $data{$what}->{$tag} .= $content; |
| 183 | } |
| 184 | next; |
| 185 | } |
Mauro Carvalho Chehab | bbc249f | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 186 | if (m/^\s*(.*)/) { |
| 187 | $data{$what}->{$tag} .= "\n$1"; |
| 188 | $data{$what}->{$tag} =~ s/\n+$//; |
| 189 | next; |
| 190 | } |
| 191 | |
| 192 | # Everything else is error |
| 193 | parse_error($file, $ln, "Unexpected line:", $_); |
| 194 | } |
Mauro Carvalho Chehab | d0ebaf5 | 2019-06-20 14:22:58 -0300 | [diff] [blame] | 195 | $data{$nametag}->{description} =~ s/^\n+//; |
Mauro Carvalho Chehab | bbc249f | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 196 | close IN; |
| 197 | } |
| 198 | |
Mauro Carvalho Chehab | 33e3e99 | 2019-06-20 14:22:59 -0300 | [diff] [blame] | 199 | # |
| 200 | # Outputs the book on ReST format |
| 201 | # |
Mauro Carvalho Chehab | 45f9651 | 2019-06-20 14:23:00 -0300 | [diff] [blame] | 202 | |
Mauro Carvalho Chehab | 2e7ce05 | 2019-06-20 14:23:02 -0300 | [diff] [blame] | 203 | my %labels; |
| 204 | |
Mauro Carvalho Chehab | bbc249f | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 205 | sub output_rest { |
Mauro Carvalho Chehab | 45f9651 | 2019-06-20 14:23:00 -0300 | [diff] [blame] | 206 | foreach my $what (sort { |
| 207 | ($data{$a}->{type} eq "File") cmp ($data{$b}->{type} eq "File") || |
| 208 | $a cmp $b |
| 209 | } keys %data) { |
Mauro Carvalho Chehab | bbc249f | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 210 | my $type = $data{$what}->{type}; |
| 211 | my $file = $data{$what}->{file}; |
Mauro Carvalho Chehab | 45f9651 | 2019-06-20 14:23:00 -0300 | [diff] [blame] | 212 | my $filepath = $data{$what}->{filepath}; |
Mauro Carvalho Chehab | bbc249f | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 213 | |
| 214 | my $w = $what; |
| 215 | $w =~ s/([\(\)\_\-\*\=\^\~\\])/\\$1/g; |
| 216 | |
Mauro Carvalho Chehab | 4e6a623 | 2019-06-20 14:22:57 -0300 | [diff] [blame] | 217 | |
Mauro Carvalho Chehab | d0ebaf5 | 2019-06-20 14:22:58 -0300 | [diff] [blame] | 218 | foreach my $p (@{$data{$what}->{label}}) { |
| 219 | my ($content, $label) = @{$p}; |
| 220 | $label = "abi_" . $label . " "; |
| 221 | $label =~ tr/A-Z/a-z/; |
| 222 | |
| 223 | # Convert special chars to "_" |
| 224 | $label =~s/([\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xff])/_/g; |
| 225 | $label =~ s,_+,_,g; |
| 226 | $label =~ s,_$,,; |
| 227 | |
Mauro Carvalho Chehab | 2e7ce05 | 2019-06-20 14:23:02 -0300 | [diff] [blame] | 228 | # Avoid duplicated labels |
| 229 | while (defined($labels{$label})) { |
| 230 | my @chars = ("A".."Z", "a".."z"); |
| 231 | $label .= $chars[rand @chars]; |
| 232 | } |
| 233 | $labels{$label} = 1; |
| 234 | |
Mauro Carvalho Chehab | d0ebaf5 | 2019-06-20 14:22:58 -0300 | [diff] [blame] | 235 | $data{$what}->{label} .= $label; |
| 236 | |
| 237 | printf ".. _%s:\n\n", $label; |
| 238 | |
| 239 | # only one label is enough |
| 240 | last; |
Mauro Carvalho Chehab | 6619c66 | 2019-06-20 14:22:56 -0300 | [diff] [blame] | 241 | } |
| 242 | |
Mauro Carvalho Chehab | 6619c66 | 2019-06-20 14:22:56 -0300 | [diff] [blame] | 243 | |
Mauro Carvalho Chehab | 45f9651 | 2019-06-20 14:23:00 -0300 | [diff] [blame] | 244 | $filepath =~ s,.*/(.*/.*),\1,;; |
| 245 | $filepath =~ s,[/\-],_,g;; |
| 246 | my $fileref = "abi_file_".$filepath; |
| 247 | |
| 248 | if ($type eq "File") { |
| 249 | my $bar = $w; |
| 250 | $bar =~ s/./-/g; |
| 251 | |
| 252 | print ".. _$fileref:\n\n"; |
| 253 | print "$w\n$bar\n\n"; |
| 254 | } else { |
| 255 | my @names = split /\s*,\s*/,$w; |
| 256 | |
| 257 | my $len = 0; |
| 258 | |
| 259 | foreach my $name (@names) { |
| 260 | $len = length($name) if (length($name) > $len); |
| 261 | } |
| 262 | |
| 263 | print "What:\n\n"; |
| 264 | |
| 265 | print "+-" . "-" x $len . "-+\n"; |
| 266 | foreach my $name (@names) { |
| 267 | printf "| %s", $name . " " x ($len - length($name)) . " |\n"; |
| 268 | print "+-" . "-" x $len . "-+\n"; |
| 269 | } |
| 270 | print "\n"; |
| 271 | } |
| 272 | |
| 273 | print "Defined on file :ref:`$file <$fileref>`\n\n" if ($type ne "File"); |
Mauro Carvalho Chehab | bbc249f | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 274 | |
| 275 | my $desc = $data{$what}->{description}; |
| 276 | $desc =~ s/^\s+//; |
| 277 | |
| 278 | # Remove title markups from the description, as they won't work |
| 279 | $desc =~ s/\n[\-\*\=\^\~]+\n/\n/g; |
| 280 | |
Mauro Carvalho Chehab | bbc249f | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 281 | if (!($desc =~ /^\s*$/)) { |
Mauro Carvalho Chehab | 4e6a623 | 2019-06-20 14:22:57 -0300 | [diff] [blame] | 282 | if ($desc =~ m/\:\n/ || $desc =~ m/\n[\t ]+/ || $desc =~ m/[\x00-\x08\x0b-\x1f\x7b-\xff]/) { |
| 283 | # put everything inside a code block |
| 284 | $desc =~ s/\n/\n /g; |
| 285 | |
| 286 | print "::\n\n"; |
| 287 | print " $desc\n\n"; |
| 288 | } else { |
| 289 | # Escape any special chars from description |
| 290 | $desc =~s/([\x00-\x08\x0b-\x1f\x21-\x2a\x2d\x2f\x3c-\x40\x5c\x5e-\x60\x7b-\xff])/\\$1/g; |
| 291 | |
| 292 | print "$desc\n\n"; |
| 293 | } |
Mauro Carvalho Chehab | bbc249f | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 294 | } else { |
Mauro Carvalho Chehab | d0ebaf5 | 2019-06-20 14:22:58 -0300 | [diff] [blame] | 295 | print "DESCRIPTION MISSING for $what\n\n" if (!$data{$what}->{is_file}); |
Mauro Carvalho Chehab | bbc249f | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 296 | } |
Mauro Carvalho Chehab | 6619c66 | 2019-06-20 14:22:56 -0300 | [diff] [blame] | 297 | |
Mauro Carvalho Chehab | d0ebaf5 | 2019-06-20 14:22:58 -0300 | [diff] [blame] | 298 | if ($data{$what}->{xrefs}) { |
| 299 | printf "Has the following ABI:\n\n"; |
| 300 | |
| 301 | foreach my $p(@{$data{$what}->{xrefs}}) { |
| 302 | my ($content, $label) = @{$p}; |
| 303 | $label = "abi_" . $label . " "; |
| 304 | $label =~ tr/A-Z/a-z/; |
| 305 | |
| 306 | # Convert special chars to "_" |
| 307 | $label =~s/([\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xff])/_/g; |
| 308 | $label =~ s,_+,_,g; |
| 309 | $label =~ s,_$,,; |
| 310 | |
| 311 | # Escape special chars from content |
| 312 | $content =~s/([\x00-\x1f\x21-\x2f\x3a-\x40\x7b-\xff])/\\$1/g; |
| 313 | |
| 314 | print "- :ref:`$content <$label>`\n\n"; |
| 315 | } |
| 316 | } |
Mauro Carvalho Chehab | bbc249f | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 317 | } |
| 318 | } |
| 319 | |
| 320 | # |
Mauro Carvalho Chehab | 33e3e99 | 2019-06-20 14:22:59 -0300 | [diff] [blame] | 321 | # Searches for ABI symbols |
| 322 | # |
| 323 | sub search_symbols { |
| 324 | foreach my $what (sort keys %data) { |
| 325 | next if (!($what =~ m/($arg)/)); |
| 326 | |
| 327 | my $type = $data{$what}->{type}; |
| 328 | next if ($type eq "File"); |
| 329 | |
| 330 | my $file = $data{$what}->{filepath}; |
| 331 | |
| 332 | my $bar = $what; |
| 333 | $bar =~ s/./-/g; |
| 334 | |
| 335 | print "\n$what\n$bar\n\n"; |
| 336 | |
| 337 | my $kernelversion = $data{$what}->{kernelversion}; |
| 338 | my $contact = $data{$what}->{contact}; |
| 339 | my $users = $data{$what}->{users}; |
| 340 | my $date = $data{$what}->{date}; |
| 341 | my $desc = $data{$what}->{description}; |
| 342 | $kernelversion =~ s/^\s+//; |
| 343 | $contact =~ s/^\s+//; |
| 344 | $users =~ s/^\s+//; |
| 345 | $users =~ s/\n//g; |
| 346 | $date =~ s/^\s+//; |
| 347 | $desc =~ s/^\s+//; |
| 348 | |
| 349 | printf "Kernel version:\t\t%s\n", $kernelversion if ($kernelversion); |
| 350 | printf "Date:\t\t\t%s\n", $date if ($date); |
| 351 | printf "Contact:\t\t%s\n", $contact if ($contact); |
| 352 | printf "Users:\t\t\t%s\n", $users if ($users); |
| 353 | print "Defined on file:\t$file\n\n"; |
| 354 | print "Description:\n\n$desc"; |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | |
| 359 | # |
Mauro Carvalho Chehab | bbc249f | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 360 | # Parses all ABI files located at $prefix dir |
| 361 | # |
| 362 | find({wanted =>\&parse_abi, no_chdir => 1}, $prefix); |
| 363 | |
| 364 | print STDERR Data::Dumper->Dump([\%data], [qw(*data)]) if ($debug); |
| 365 | |
| 366 | # |
Mauro Carvalho Chehab | 33e3e99 | 2019-06-20 14:22:59 -0300 | [diff] [blame] | 367 | # Handles the command |
Mauro Carvalho Chehab | bbc249f | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 368 | # |
Mauro Carvalho Chehab | 33e3e99 | 2019-06-20 14:22:59 -0300 | [diff] [blame] | 369 | if ($cmd eq "rest") { |
| 370 | output_rest; |
| 371 | } else { |
| 372 | search_symbols; |
| 373 | } |
Mauro Carvalho Chehab | bbc249f | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 374 | |
| 375 | |
| 376 | __END__ |
| 377 | |
| 378 | =head1 NAME |
| 379 | |
| 380 | abi_book.pl - parse the Linux ABI files and produce a ReST book. |
| 381 | |
| 382 | =head1 SYNOPSIS |
| 383 | |
Mauro Carvalho Chehab | 33e3e99 | 2019-06-20 14:22:59 -0300 | [diff] [blame] | 384 | B<abi_book.pl> [--debug] <COMAND> [<ARGUMENT>] |
| 385 | |
| 386 | Where <COMMAND> can be: |
| 387 | |
| 388 | =over 8 |
| 389 | |
| 390 | B<search> [SEARCH_REGEX] - search for [SEARCH_REGEX] inside ABI |
| 391 | |
| 392 | B<rest> - output the ABI in ReST markup language |
| 393 | |
| 394 | =back |
Mauro Carvalho Chehab | bbc249f | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 395 | |
| 396 | =head1 OPTIONS |
| 397 | |
| 398 | =over 8 |
| 399 | |
Mauro Carvalho Chehab | 33e3e99 | 2019-06-20 14:22:59 -0300 | [diff] [blame] | 400 | =item B<--dir> |
| 401 | |
| 402 | Changes the location of the ABI search. By default, it uses |
| 403 | the Documentation/ABI directory. |
| 404 | |
Mauro Carvalho Chehab | bbc249f | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 405 | =item B<--debug> |
| 406 | |
| 407 | Put the script in verbose mode, useful for debugging. Can be called multiple |
| 408 | times, to increase verbosity. |
| 409 | |
| 410 | =item B<--help> |
| 411 | |
| 412 | Prints a brief help message and exits. |
| 413 | |
| 414 | =item B<--man> |
| 415 | |
| 416 | Prints the manual page and exits. |
| 417 | |
| 418 | =back |
| 419 | |
| 420 | =head1 DESCRIPTION |
| 421 | |
Mauro Carvalho Chehab | 33e3e99 | 2019-06-20 14:22:59 -0300 | [diff] [blame] | 422 | Parse the Linux ABI files from ABI DIR (usually located at Documentation/ABI), |
| 423 | allowing to search for ABI symbols or to produce a ReST book containing |
| 424 | the Linux ABI documentation. |
| 425 | |
| 426 | =head1 EXAMPLES |
| 427 | |
| 428 | Search for all stable symbols with the word "usb": |
| 429 | |
| 430 | =over 8 |
| 431 | |
| 432 | $ scripts/get_abi.pl search usb --dir Documentation/ABI/stable |
| 433 | |
| 434 | =back |
| 435 | |
| 436 | Search for all symbols that match the regex expression "usb.*cap": |
| 437 | |
| 438 | =over 8 |
| 439 | |
| 440 | $ scripts/get_abi.pl search usb.*cap |
| 441 | |
| 442 | =back |
| 443 | |
| 444 | Output all obsoleted symbols in ReST format |
| 445 | |
| 446 | =over 8 |
| 447 | |
| 448 | $ scripts/get_abi.pl rest --dir Documentation/ABI/obsolete |
| 449 | |
| 450 | =back |
Mauro Carvalho Chehab | bbc249f | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 451 | |
| 452 | =head1 BUGS |
| 453 | |
| 454 | Report bugs to Mauro Carvalho Chehab <mchehab@s-opensource.com> |
| 455 | |
| 456 | =head1 COPYRIGHT |
| 457 | |
Mauro Carvalho Chehab | 33e3e99 | 2019-06-20 14:22:59 -0300 | [diff] [blame] | 458 | Copyright (c) 2016-2017 by Mauro Carvalho Chehab <mchehab@s-opensource.com>. |
Mauro Carvalho Chehab | bbc249f | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 459 | |
| 460 | License GPLv2: GNU GPL version 2 <http://gnu.org/licenses/gpl.html>. |
| 461 | |
| 462 | This is free software: you are free to change and redistribute it. |
| 463 | There is NO WARRANTY, to the extent permitted by law. |
| 464 | |
| 465 | =cut |