blob: 6aa959fdefa863c872cd110273ec3e3772d89c04 (
plain)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
package VarnishMib::MIBTable;
use strict;
use warnings;
use parent 'VarnishMib::HashTable';
use Carp;
sub new {
my ($class, $type, $table, %args) = @_;
my @oids =
sort { $table->{$a}[1] cmp $table->{$b}[1] }
grep { $table->{$_}[0] eq 'DICT' } keys %{$table};
my @equiv;
my @uniq_oids;
for (my $i = 0; $i <= $#oids; $i++) {
unless ($i > 0
&& $table->{$uniq_oids[-1]}[1] eq $table->{$oids[$i]}[1]) {
push @uniq_oids, $oids[$i];
}
push @equiv, $#uniq_oids;
}
my $self = bless $class->SUPER::new(%args), $class;
$self->{oids_all} = \@oids;
$self->{oids_uniq} = \@uniq_oids;
$self->{equiv} = \@equiv;
$self->{type} = $type;
$self->create([map { $table->{$_}[1] } @{$self->{oids_uniq}}]);
return $self;
}
sub format_oids {
my ($self, $fh) = @_;
$fh ||= \*STDOUT;
print $fh "enum ".$self->prefix."oid {\n";
for (my $i = 0; $i <= $#{$self->{oids_all}}; $i++) {
print $fh $self->indent . $self->{oids_all}[$i];
if ($i > 0
&& $self->{oids_all}[$i] ne $self->{oids_uniq}[$self->{equiv}[$i]]) {
print $fh ' = ' . $self->{oids_uniq}[$self->{equiv}[$i]];
}
print $fh ",\n";
}
print $fh $self->indent . 'MAX_' . uc($self->prefix) . "OID\n";
print $fh "};\n\n";
}
sub format_program {
my ($self, $fh) = @_;
$fh ||= \*STDOUT;
$self->format_oids($fh);
$self->SUPER::format_program($self->{type}, $fh);
}
sub str {
my $self = shift;
my $str;
open(my $fh, '>', \$str) or croak "can't write to string";
$self->format_program($fh);
close $fh;
return $str;
};
use overload '""' => \&str;
1;
|