diff options
Diffstat (limited to 'contrib/tools/org_to_fd.pl')
| -rwxr-xr-x | contrib/tools/org_to_fd.pl | 75 |
1 files changed, 55 insertions, 20 deletions
diff --git a/contrib/tools/org_to_fd.pl b/contrib/tools/org_to_fd.pl index 9cc0631..a0825d6 100755 --- a/contrib/tools/org_to_fd.pl +++ b/contrib/tools/org_to_fd.pl @@ -1,12 +1,15 @@ #!/usr/bin/env perl use strict; +use File::Basename; use Getopt::Std; +my ($progname) = basename($0); + our ($opt_V, $opt_v); -# default to 3GPP -my ($vendor) = 10415; -my ($vendor_name) = "3GPP"; +# default to Base +my ($vendor) = 0; +my ($vendor_name) = ""; sub convert_must_to_flags($) { my ($allmust) = @_; @@ -21,7 +24,7 @@ sub base_type($) { my ($type) = @_; return "AVP_TYPE_GROUPED" if ($type =~ m/Grouped/); - return "AVP_TYPE_OCTETSTRING" if ($type =~ m/(Address|DiameterIdentity|DiameterURI|OctetString|IPFilterRule|Time|UTF8String)/); + return "AVP_TYPE_OCTETSTRING" if ($type =~ m/(Address|DiameterIdentity|DiameterURI|OctetString|IPFilterRule|Time|UTF8String|QoSFilterRule)/); return "AVP_TYPE_INTEGER32" if ($type =~ m/Enumerated|Integer32/); return "AVP_TYPE_INTEGER64" if ($type =~ m/Integer64/); return "AVP_TYPE_UNSIGNED32" if ($type =~ m/Unsigned32/); @@ -29,7 +32,19 @@ sub base_type($) { return "AVP_TYPE_FLOAT32" if ($type =~ m/Float32/); return "AVP_TYPE_FLOAT64" if ($type =~ m/Float64/); - return "UNKNOWN TYPE: $type"; + die("unknown type '$type'"); +} + + +my ($comment_width) = 64; + +sub print_header() { + printf "\t/*=%s=*/\n", '=' x $comment_width; +} + +sub print_comment($) { + my ($str) = @_; + printf "\t/* %-*s */\n", $comment_width, $str; } sub print_insert($$) { @@ -39,8 +54,8 @@ sub print_insert($$) { if ($type =~ m/(Grouped|OctetString|Integer32|Integer64|Unsigned32|Unsigned64|Float32|Float64)/) { $avp_type = "NULL"; } elsif ($type =~ m/Enumerated/) { - print "\t\tstruct dict_object *type;\n"; - print "\t\tstruct dict_type_data tdata = { AVP_TYPE_INTEGER32, \"" . ($vendor_name ? "$vendor_name/" : "") ."Enumerated($name)\", NULL, NULL, NULL };\n"; + print "\t\tstruct dict_object\t*type;\n"; + print "\t\tstruct dict_type_data\t tdata = { AVP_TYPE_INTEGER32, \"Enumerated(" . ($vendor_name ? "$vendor_name/" : "") ."$name)\", NULL, NULL, NULL };\n"; # XXX: add enumerated values print "\t\tCHECK_dict_new(DICT_TYPE, &tdata, NULL, &type);\n"; $avp_type = "type"; @@ -52,8 +67,8 @@ sub print_insert($$) { } sub usage($) { - die("usage: org_to_fd.pl [-V vendor_name -v vendor_code] [file ...]\n"); - exit(@_); + print STDERR "usage: $progname [-V vendor_name] [-v vendor_code] [file ...]\n"; + exit(1); } getopts("V:v:") || usage(1); @@ -61,29 +76,45 @@ getopts("V:v:") || usage(1); if (defined($opt_v)) { $vendor = $opt_v; if (!defined($opt_V)) { - usage(1); + usage(1); } $vendor_name = $opt_V; } -print "\t/* The following is created automatically. Do not modify. */\n"; -print "\t/* Changes will be lost during the next update. Modify the source org file instead. */\n\n"; +print_header(); +print_comment("Start of generated data."); +print_comment(""); +print_comment("The following is created automatically with:"); +print_comment(" org_to_fd.pl -V '$vendor_name' -v $vendor"); +print_comment("Changes will be lost during the next update."); +print_comment("Do not modify; modify the source .org file instead."); +print_header(); +print "\n"; while (<>) { - my ($dummy, $name, $code, $section, $type, $must, $may, $shouldnot, $mustnot, $encr) = split /\|/; + my ($dummy, $name, $code, $section, $type, $must, $may, $shouldnot, $mustnot, $encr) = split /\s*\|\s*/; next if ($name =~ m/Attribute Name/); - if ($name =~ m/ # (.*)/) { - print "\t/* $1 */\n"; + if ($name =~ m/# (.*)/) { + print_comment($1); + next; + } + if ($name =~ m/#/) { + print("\n"); next; } - - $name =~ s/ *//g; - $code =~ s/ *//g; - $type =~ s/ *//g; + if ($name =~ m/\s/) { + die("name '$name' contains space"); + } - print "\t/* $name */\n\t{\n\t\tstruct dict_avp_data data = {\n"; + my ($desc) = $name; + $desc .= ", " . $type; + $desc .= ", code " . $code; + $desc .= ", section " . $section if $section ne ""; + print_comment($desc); + print "\t{\n"; + print "\t\tstruct dict_avp_data data = {\n"; print "\t\t\t$code,\t/* Code */\n"; print "\t\t\t$vendor,\t/* Vendor */\n"; print "\t\t\t\"$name\",\t/* Name */\n"; @@ -94,3 +125,7 @@ while (<>) { print_insert($type, $name); print "\t};\n\n"; } + +print_header(); +print_comment("End of generated data."); +print_header(); |
