]> nuage.metani.fr Git - 3GPP.git/blob - awk/txt2asn.awk
e871003fe7402ce57c8f7b5b18dbbfca0ce321d8
[3GPP.git] / awk / txt2asn.awk
1 #!/bin/awk -f
2
3 BEGIN {
4 add_line_after != "" ;
5 separator = "" ;
6
7 wide_separator = "" ;
8 for(i=0;i<=140;i++) {
9 wide_separator = wide_separator "-" ;
10 }
11
12 ie_separator = "-- " ;
13 for (i=0;i<=137;i++) {
14 ie_separator = ie_separator "=" ;
15 }
16 }
17
18 # Section headers
19 # This will also catch bits of Short Message description but that won't cause issues
20 # A way not to catch those could be to check that the numbers are in sequence
21
22 /^[0-9]+(\.[0-9]+)*\t/ {
23 in_IE = "no" ;
24 # print "Titre" ;
25 # print ;
26 }
27
28 /^-- ASN1START/ {
29 print "";
30 in_ASN1 = "yes";
31 next;
32 }
33
34 /^-- ASN1STOP/ {
35 in_ASN1 = "no";
36 next;
37 }
38
39 /^-- TAG-/ {
40 next;
41 }
42
43 # Recording empty line (to avoid multiple empty lines)
44 # Printing separators in some cases
45
46 /^[[:space:]]*$/ {
47
48 if (next_line == "condition") {
49 print separator ;
50 }
51 if ((next_line == "field description") || (next_line == "field name")){
52 print separator ;
53 }
54
55 next_line = "" ;
56 # #if (empty_line == "yes") {
57 # next;
58 # }
59 empty_line = "yes" ;
60
61 # print "a" ;
62 # print ;
63 }
64
65 # Stopping before ASN.1 examples (end of specification)
66 /^-[[:space:]]+ParentIE-WithEM$/ {
67 exit 0 ;
68 }
69
70 # Start of IE definitions
71 # This cannot catch "Multiplicity and type constraints"
72 # This also cannot catch NR-InterNodeDefinitions
73 /^-[[:space:]]+[A-Za-z0-9-]+$/ {
74 if (empty_line == "yes") {
75 print ie_separator;
76 print "-- IE: " $2;
77 print "" ;
78 empty_line = "no" ;
79 conditions = "" ;
80 }
81 in_IE = "yes" ;
82 next ;
83 }
84
85 /^NR-InterNodeDefinitions/ {
86 if (empty_line == "yes") {
87 print ie_separator;
88 print "-- IE: NR-InterNodeDefinitions";
89 print "" ;
90 # Perhaps it could work without this if the "next" at the end is removed
91 print ;
92 empty_line = "no" ;
93 conditions = "" ;
94 }
95 in_IE = "yes" ;
96 next ;
97 }
98
99
100 # Sometimes there is an "s" to constraint, sometimes not
101 /^-[[:space:]]+Multiplicity and type constraints? definitions$/ {
102 if (empty_line == "yes") {
103 print ie_separator;
104 print "-- Multiplicity and type constraints definitions";
105 print "" ;
106 empty_line = "no" ;
107 conditions = "" ;
108 }
109 in_IE = "yes" ;
110 next ;
111 }
112
113 #/^-[[:space:]]+Multiplicity and type constraints definitions/ {
114 # in_IE = "yes" ;
115 # next ;
116 #}
117
118 /^Conditional Presence/ {
119 add_line_after = "";
120 separator = "" ;
121
122 $0 = "Conditional presence" ;
123 for(i=0;i<=140;i++) {
124 separator = separator "-" ;
125 }
126 # print separator;
127 #add_line_after = separator ;
128 next_line = "condition" ;
129 }
130
131 # Need to catch "x and y field descriptions"
132
133 /field descriptions$/ {
134 add_line_after = "";
135 separator = "" ;
136
137 for(i=0;i<=140;i++) {
138 separator = separator "-" ;
139 }
140 # print separator;
141 # add_line_after = separator ;
142 next_line = "field name" ;
143 }
144
145 #/^[A-Za-z0-9-]+[[:space:]]+[A-Za-z0-9-]+/ {
146 # if (next_line == "field description") {
147 # add_line_after = separator ;
148 # next_line = "field name";
149 # }
150 #}
151
152 /^[A-Za-z0-9-]+(, [A-Za-z0-9-]+)*$/ {
153 if (next_line == "field name") {
154
155 print separator ;
156
157 $0 = "Field: " $0
158 #add_line_after = " ";
159 next_line = "field description";
160 }
161 else if (next_line == "field description") {
162 print separator ;
163
164 $0 = "Field: " $0
165 #add_line_after = separator ;
166 #print "separator est " separator;
167 next_line = "field name";
168 }
169 }
170
171
172
173 {
174 if (in_IE == "yes") {
175 if ((next_line == "condition") && ($1 != "Conditional")) {
176
177 if (index(conditions, $1) != 0) {
178 print separator;
179 print "-- Condition: " $1;
180 $1 = "";
181 }
182 if ((in_ASN1 == "no") && !(/^\s*$/)) {
183 $0 = "-- " $0 ;
184 }
185 print ;
186 }
187
188 else {
189 if ((in_ASN1 == "no") && !(/^\s*$/)) {
190 $0 = "-- " $0 ;
191 }
192 print;
193 }
194
195 if (add_line_after != "") {
196 print add_line_after ;
197 add_line_after = "" ;
198 }
199
200 if (/-- Cond [A-Za-z0-9-]+$/) {
201 conditions = conditions " " $NF ;
202 }
203 }
204 }
205