X-Git-Url: http://git.openwrt.org/?a=blobdiff_plain;f=data%2Fgen-common.pm;h=6c3492f25a8c6a937fdcc5272e44cb2d3e3614d9;hb=HEAD;hp=d9d281ca95d360546c985184abd140be3c627aa8;hpb=b29e4d756726e9685ad812210c5f2e5298100140;p=project%2Fuqmi.git diff --git a/data/gen-common.pm b/data/gen-common.pm index d9d281c..9275d4e 100644 --- a/data/gen-common.pm +++ b/data/gen-common.pm @@ -14,14 +14,65 @@ our %tlv_types = ( guint32 => "uint32_t", gint64 => "int64_t", guint64 => "uint64_t", + gfloat => "float", gboolean => "bool", ); +our %common_ref = (); + +my @c_reserved_keywords = ( + "alignas", + "alignof", + "auto", + "bool", + "break", + "case", + "char", + "const", + "constexpr", + "continue", + "default", + "do", + "double", + "else", + "enum", + "extern", + "false", + "float", + "for", + "goto", + "if", + "inline", + "int", + "long", + "nullptr", + "register", + "restrict", + "return", + "short", + "signed", + "sizeof", + "static", + "static_assert", + "struct", + "switch", + "thread_local", + "true", + "typedef", + "typeof", + "typeof_unqual", + "union", + "unsigned", + "void", + "volatile", + "while" +); $prefix eq 'ctl_' and $ctl = 1; sub get_json() { local $/; my $json = <>; + $json =~ s/^\s*\/\/.*$//mg; return decode_json($json); } @@ -29,13 +80,17 @@ sub gen_cname($) { my $name = shift; $name =~ s/[^a-zA-Z0-9_]/_/g; - return lc($name); + $name = "_${name}" if $name =~ /^\d/; + $name = lc($name); + $name = "_${name}" if (grep {$_ eq $name} @c_reserved_keywords); + return $name; } sub gen_has_types($) { my $data = shift; foreach my $field (@$data) { + $field = gen_common_ref($field); my $type = $field->{"format"}; $type and return 1; } @@ -66,22 +121,44 @@ sub gen_tlv_parse_func($$) { } } +sub gen_common_ref($$) { + my $field = shift; + $field = $common_ref{$field->{'common-ref'}} if $field->{'common-ref'} ne ''; + return $field; +} + sub gen_foreach_message_type($$$) { my $data = shift; my $req_sub = shift; my $res_sub = shift; + my $ind_sub = shift; foreach my $entry (@$data) { my $args = []; my $fields = []; + $common_ref{$entry->{'common-ref'}} = $entry if $entry->{'common-ref'} ne ''; + next if $entry->{type} ne 'Message'; next if not defined $entry->{input} and not defined $entry->{output}; &$req_sub($prefix.$entry->{name}." Request", $entry->{input}, $entry); &$res_sub($prefix.$entry->{name}." Response", $entry->{output}, $entry); } + + foreach my $entry (@$data) { + my $args = []; + my $fields = []; + + $common_ref{$entry->{'common-ref'}} = $entry if $entry->{'common-ref'} ne ''; + + next if $entry->{type} ne 'Indication'; + next if not defined $entry->{input} and not defined $entry->{output}; + + &$ind_sub($prefix.$entry->{name}." Indication", $entry->{output}, $entry); + } } + 1;