File: extract_static_table.pl

package info (click to toggle)
libprotocol-http2-perl 1.11-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 448 kB
  • sloc: perl: 3,370; makefile: 7
file content (52 lines) | stat: -rw-r--r-- 1,078 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/perl
#
use strict;
use warnings;

use XML::LibXML;

sub usage {
    "Usage: $0 draft-ietf-httpbis-header-compression.xml\n";
}

my $file = $ARGV[0] or die usage;
die usage unless -f $file;

open my $fh, '<', $file or die $!;
my $doc = XML::LibXML->load_xml( IO => $fh );
my $stattable =
  XML::LibXML::XPathExpression->new(
    '//texttable[@title="Static Table Entries"]/c');
my @nodes = $doc->findnodes($stattable);

print <<'EOF';
package Protocol::HTTP2::StaticTable;
use strict;
use warnings;
require Exporter;
our @ISA = qw(Exporter);
our ( @stable, %rstable );
our @EXPORT = qw(@stable %rstable);

@stable = (
EOF

while (@nodes) {
    my ( $idx, $name, $value ) = map { $_->textContent } splice( @nodes, 0, 3 );
    last unless $idx;
    printf qq{    [ "%s", "%s" ],\n}, $name, $value;
}

print <<'EOF';
);

for my $k ( 0 .. $#stable ) {
    my $key = join ' ', @{ $stable[$k] };
    $rstable{$key} = $k + 1;
    $rstable{ $stable[$k]->[0] . ' ' } = $k + 1
      if ( $stable[$k]->[1] ne ''
        && !exists $rstable{ $stable[$k]->[0] . ' ' } );
}

1;
EOF