Mercurial > hg > freeDiameter
annotate contrib/tools/org_to_fd.pl @ 1324:729e5074839f
Consistently start names of Enumerated types with 'Enumerated'.
author | Thomas Klausner <tk@giga.or.at> |
---|---|
date | Mon, 27 Nov 2017 15:15:59 +0100 |
parents | b6885b0d8b10 |
children | 3338f135989d |
rev | line source |
---|---|
953
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
1 #!/usr/bin/env perl |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
2 use strict; |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
3 use Getopt::Std; |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
4 |
960
f39fa6cd86e0
Include vendor name in enumerated type name.
Thomas Klausner <tk@giga.or.at>
parents:
953
diff
changeset
|
5 our ($opt_V, $opt_v); |
f39fa6cd86e0
Include vendor name in enumerated type name.
Thomas Klausner <tk@giga.or.at>
parents:
953
diff
changeset
|
6 |
f39fa6cd86e0
Include vendor name in enumerated type name.
Thomas Klausner <tk@giga.or.at>
parents:
953
diff
changeset
|
7 # default to 3GPP |
f39fa6cd86e0
Include vendor name in enumerated type name.
Thomas Klausner <tk@giga.or.at>
parents:
953
diff
changeset
|
8 my ($vendor) = 10415; |
f39fa6cd86e0
Include vendor name in enumerated type name.
Thomas Klausner <tk@giga.or.at>
parents:
953
diff
changeset
|
9 my ($vendor_name) = "3GPP"; |
953
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
10 |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
11 sub convert_must_to_flags($) { |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
12 my ($allmust) = @_; |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
13 my ($mustfields) = ""; |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
14 $mustfields .= "AVP_FLAG_VENDOR |" if ($allmust =~ m/V/); |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
15 $mustfields .= "AVP_FLAG_MANDATORY |" if ($allmust =~ m/M/); |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
16 $mustfields =~ s/ \|$//; |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
17 return $mustfields; |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
18 } |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
19 |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
20 sub base_type($) { |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
21 my ($type) = @_; |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
22 |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
23 return "AVP_TYPE_GROUPED" if ($type =~ m/Grouped/); |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
24 return "AVP_TYPE_OCTETSTRING" if ($type =~ m/(Address|DiameterIdentity|DiameterURI|OctetString|IPFilterRule|Time|UTF8String)/); |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
25 return "AVP_TYPE_INTEGER32" if ($type =~ m/Enumerated|Integer32/); |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
26 return "AVP_TYPE_INTEGER64" if ($type =~ m/Integer64/); |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
27 return "AVP_TYPE_UNSIGNED32" if ($type =~ m/Unsigned32/); |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
28 return "AVP_TYPE_UNSIGNED64" if ($type =~ m/Unsigned64/); |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
29 return "AVP_TYPE_FLOAT32" if ($type =~ m/Float32/); |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
30 return "AVP_TYPE_FLOAT64" if ($type =~ m/Float64/); |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
31 |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
32 return "UNKNOWN TYPE: $type"; |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
33 } |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
34 |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
35 sub print_insert($$) { |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
36 my ($type, $name) = @_; |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
37 my $avp_type; |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
38 |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
39 if ($type =~ m/(Grouped|OctetString|Integer32|Integer64|Unsigned32|Unsigned64|Float32|Float64)/) { |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
40 $avp_type = "NULL"; |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
41 } elsif ($type =~ m/Enumerated/) { |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
42 print "\t\tstruct dict_object *type;\n"; |
1324
729e5074839f
Consistently start names of Enumerated types with 'Enumerated'.
Thomas Klausner <tk@giga.or.at>
parents:
1114
diff
changeset
|
43 print "\t\tstruct dict_type_data tdata = { AVP_TYPE_INTEGER32, \"Enumerated(" . ($vendor_name ? "$vendor_name/" : "") ."$name)\", NULL, NULL, NULL };\n"; |
953
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
44 # XXX: add enumerated values |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
45 print "\t\tCHECK_dict_new(DICT_TYPE, &tdata, NULL, &type);\n"; |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
46 $avp_type = "type"; |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
47 } else { |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
48 $avp_type = "${type}_type"; |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
49 } |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
50 |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
51 print "\t\tCHECK_dict_new(DICT_AVP, &data, $avp_type, NULL);\n"; |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
52 } |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
53 |
960
f39fa6cd86e0
Include vendor name in enumerated type name.
Thomas Klausner <tk@giga.or.at>
parents:
953
diff
changeset
|
54 sub usage($) { |
1114 | 55 die("usage: org_to_fd.pl [-V vendor_name -v vendor_code] [file ...]\n"); |
960
f39fa6cd86e0
Include vendor name in enumerated type name.
Thomas Klausner <tk@giga.or.at>
parents:
953
diff
changeset
|
56 exit(@_); |
f39fa6cd86e0
Include vendor name in enumerated type name.
Thomas Klausner <tk@giga.or.at>
parents:
953
diff
changeset
|
57 } |
953
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
58 |
960
f39fa6cd86e0
Include vendor name in enumerated type name.
Thomas Klausner <tk@giga.or.at>
parents:
953
diff
changeset
|
59 getopts("V:v:") || usage(1); |
f39fa6cd86e0
Include vendor name in enumerated type name.
Thomas Klausner <tk@giga.or.at>
parents:
953
diff
changeset
|
60 |
953
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
61 if (defined($opt_v)) { |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
62 $vendor = $opt_v; |
960
f39fa6cd86e0
Include vendor name in enumerated type name.
Thomas Klausner <tk@giga.or.at>
parents:
953
diff
changeset
|
63 if (!defined($opt_V)) { |
f39fa6cd86e0
Include vendor name in enumerated type name.
Thomas Klausner <tk@giga.or.at>
parents:
953
diff
changeset
|
64 usage(1); |
f39fa6cd86e0
Include vendor name in enumerated type name.
Thomas Klausner <tk@giga.or.at>
parents:
953
diff
changeset
|
65 } |
f39fa6cd86e0
Include vendor name in enumerated type name.
Thomas Klausner <tk@giga.or.at>
parents:
953
diff
changeset
|
66 $vendor_name = $opt_V; |
953
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
67 } |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
68 |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
69 print "\t/* The following is created automatically. Do not modify. */\n"; |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
70 print "\t/* Changes will be lost during the next update. Modify the source org file instead. */\n\n"; |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
71 |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
72 while (<>) { |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
73 my ($dummy, $name, $code, $section, $type, $must, $may, $shouldnot, $mustnot, $encr) = split /\|/; |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
74 |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
75 next if ($name =~ m/Attribute Name/); |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
76 if ($name =~ m/ # (.*)/) { |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
77 print "\t/* $1 */\n"; |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
78 next; |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
79 } |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
80 |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
81 |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
82 $name =~ s/ *//g; |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
83 $code =~ s/ *//g; |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
84 $type =~ s/ *//g; |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
85 |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
86 print "\t/* $name */\n\t{\n\t\tstruct dict_avp_data data = {\n"; |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
87 print "\t\t\t$code,\t/* Code */\n"; |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
88 print "\t\t\t$vendor,\t/* Vendor */\n"; |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
89 print "\t\t\t\"$name\",\t/* Name */\n"; |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
90 print "\t\t\t" . convert_must_to_flags("$must, $mustnot") . ",\t/* Fixed flags */\n"; |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
91 print "\t\t\t" . convert_must_to_flags("$must") . ",\t/* Fixed flag values */\n"; |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
92 print "\t\t\t" . base_type($type) . "\t/* base type of data */\n"; |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
93 print "\t\t};\n"; |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
94 print_insert($type, $name); |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
95 print "\t};\n\n"; |
d35276067342
Add tools that create freeDiameter C code from org tables containing the information.
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
96 } |