]> nuage.metani.fr Git - 3GPP.git/blob - awk/txt2asn-integrated.awk
407715431fca2c5fd90eee092ccbd24834ca40f2
[3GPP.git] / awk / txt2asn-integrated.awk
1 #!/bin/awk -f
2
3 # Arrays used:
4
5 # Information about each ASN.1 line, indexed by number
6
7 # text: the complete line
8 # field: the field, without suffix (if there is one)
9 # structure: the outer structure (if it is a field)
10 # condition: the condition, if there is one
11
12 # Information about each field description, indexed by outer structure and field name (when a description is for a coma-separated list of fields, a separate entry is created for each field).
13
14 # field_description_len: how many descriptions lines (0 means none)
15 # field_description: the lines of a field descritpion, indexed from 1
16
17 function asn1_print()
18 {
19
20 if (!(1 in text)) { return ; }
21 #print "entering asn1_print";
22 for (line=1; line<=line_number; line++) {
23 #if (field[line] != "") {
24 # print "Ligne " line " champs " field[line] ;
25 # print "Structure " structure[line] ;
26 # print "Description de longueur " field_description_len[structure[line]][field[line]];
27 #}
28 if (((field[line] != "") &&
29 (field_description_len[structure[line]][field[line]] > 0)) ||
30 ((condition[line] != "") &&
31 (condition_description_len[condition[line]] > 0))) {
32
33 indentation = "";
34 position = index(text[line], field[line]) - 1;
35
36 #print "ligne " line " position " position " field " field[line] " structure " structure[line];
37 indentation = "";
38 for (i=0;i<position;i++) {
39 indentation = indentation " ";
40 }
41
42 #print "Il y a " field_description_len[structure[line]][field[line]] " ligne(s)";
43
44 print "";
45
46 if (field_description_len[structure[line]][field[line]] > 0) {
47 for (i=1;i<=field_description_len[structure[line]][field[line]]; i++) {
48
49 print indentation "-- " field_description[structure[line]][field[line]][i];
50
51 }
52 }
53
54 if (condition_description_len[condition[line]] > 0) {
55 if(field[line] != "")
56 {
57 for(i=1;i<=condition_description_len[condition[line]];i++) {
58 gsub(/(, )*[Nn]eed [MNSR],*/, "", condition_description[condition[line]][i]);
59 print indentation "--" condition_description[condition[line]][i];
60 }
61 }
62
63
64 if (condition_code[condition[line]] == "")
65 { sub(/-- Cond [A-Za-z0-9_-]+/, "", text[line]); }
66 else
67 { sub(/-- Cond [A-Za-z0-9_-]+/, "-- Need " condition_code[condition[line]], text[line]); }
68 }
69
70 print text[line] ;
71
72
73 }
74
75 else {
76 if (text[line] ~ /-- Cond [A-Za-z0-9_-]+/)
77 {
78 #print "trouvé";
79 if (condition_code[condition[line]] == "")
80 { sub(/-- Cond [A-Za-z0-9_-]+/, "", text[line]); }
81 else
82 {
83 #print "Ligne " text[condition_reference[line]];
84 #print "Condition " ;
85 sub(/-- Cond [A-Za-z0-9_-]+/, "-- Need " condition_code[condition[line]], text[line]); }
86 }
87 #if((line>0) || (text[line] ~ /[a-zA-Z0-9-]/)) {
88 print text[line] ;
89 #}
90 }
91 }
92
93 delete text;
94 delete text_level;
95 delete field;
96 delete structure;
97 delete condition;
98 delete field_description_len;
99 delete field_description;
100 delete condition_description_len;
101 delete condition_description;
102 delete condition_code;
103 delete condition_reference;
104
105 #print "end of asn1_print"
106 }
107
108 function need_code(aaa)
109 {
110 if (aaa ~ /[Nn]eed M[ ,.]/) { return "M" }
111 if (aaa ~ /[Nn]eed N[ ,.]/) { return "N" }
112 if (aaa ~ /[Nn]eed R[ ,.]/) { return "R" }
113 if (aaa ~ /[Nn]eed S[ ,.]/) { return "S" }
114 return ""
115 }
116
117 function level(bbb)
118 {
119 local_bbb1 = bbb
120 local_bbb2 = bbb
121 return gsub(/{/, "", local_bbb1) - gsub(/}/, "", local_bbb2)
122 }
123
124 BEGIN {
125 add_line_after != "" ;
126 separator = "" ;
127
128 wide_separator = "" ;
129 for(i=0;i<=140;i++) {
130 wide_separator = wide_separator "-" ;
131 }
132
133 ie_separator = "-- " ;
134 for (i=0;i<=137;i++) {
135 ie_separator = ie_separator "=" ;
136 }
137
138 }
139
140 /^[0-9]+\./ {
141 if (in_IE == "yes") { asn1_print(); }
142 in_IE = "no" ;
143 }
144
145 /^-- ASN1START/ {
146 print "";
147 in_ASN1 = "yes";
148 line_number = 0;
149 #empty_line = "yes";
150 next;
151 }
152
153 /^-- ASN1STOP/ {
154 in_ASN1 = "no";
155 next;
156 }
157
158 /^-- TAG-/ {
159 next;
160 }
161
162 /^[[:space:]]*$/ {
163
164 if (next_line == "condition") {
165 #print separator ;
166 }
167 if ((next_line == "field description") || (next_line == "field name")){
168 #print separator ;
169 }
170
171 next_line = "" ;
172 # #if (empty_line == "yes") {
173 # next;
174 # }
175
176 current_condition = "" ;
177 if (empty_line == "yes") { next; }
178 empty_line = "yes" ;
179
180
181 #print "empty_line set to yes" ;
182 # print ;
183 }
184
185 /\S/ {
186
187 # The empty_line condition is meant for what is directly printed, i.e. messages decriptions
188 # ASN.1, field descriptions and conditions descriptions are not directly printed, so
189 # this should not apply to them
190
191
192
193 #if ((next_line == "field description") || (next_line == "field name")){
194 empty_line = "no" ;
195 #print "empty_line set to no"
196 #}
197
198 }
199
200 /^–[[:space:]]+ParentIE-WithEM$/ {
201 exit 0 ;
202 }
203
204 /^–[[:space:]]+[A-Za-z0-9-]+$/ {
205 asn1_print();
206
207 # if (empty_line == "yes") {
208 #print "";
209 print ie_separator;
210 print "-- IE: " $2;
211 print "" ;
212 empty_line = "no" ;
213 conditions = "" ;
214 IE_name = $2;
215
216 #if (IE_name == "PosSI-SchedulingInfo") { print "IE trouvé" ; }
217 # }
218 in_IE = "yes" ;
219
220 next ;
221 }
222
223 /^Conditional [Pp]resence/ {
224 add_line_after = "";
225 separator = "" ;
226
227 $0 = "Conditional presence" ;
228 for(i=0;i<=140;i++) {
229 separator = separator "-" ;
230 }
231 # print separator;
232 #add_line_after = separator ;
233 next_line = "condition" ;
234 #print "Conditional Presence"
235 #if (IE_name == "PosSI-SchedulingInfo") { print "condition trouvée" ; }
236 }
237
238 # Need to catch "x and y field descriptions"
239
240 /field descriptions$/ {
241 add_line_after = "";
242 separator = "" ;
243
244 for(i=0;i<=140;i++) {
245 separator = separator "-" ;
246 }
247 # print separator;
248 # add_line_after = separator ;
249 next_line = "field name" ;
250
251 field_struct = $1;
252
253 #print "Trouvé description des champs de " $1;
254 # do not print
255 next;
256 }
257
258 #/^[A-Za-z0-9-]+[[:space:]]+[A-Za-z0-9-]+/ {
259 # if (next_line == "field description") {
260 # add_line_after = separator ;
261 # next_line = "field name";
262 # }
263 #}
264
265 # This is matched for any non-empty line
266 /^[A-Za-z0-9-]+/ {
267
268
269 if ((in_IE == "yes") && (in_ASN1 == "no")){
270
271 # if we are coming from a "IE X field description" statement
272 # or we were in a field description
273 if ((next_line == "field name") || (next_line == "field description")) {
274
275
276 # If the whole line is a coma-separated list in an IE (=> field names)
277 if (/^[A-Za-z0-9-]+(, [A-Za-z0-9-]+)*$/) {
278 # Then, this is a new field, or list of fields
279 #print separator ;
280
281 names = $0;
282
283 # remove leading/trailing spaces
284 sub(/^[[:space:]]+/, "", names);
285 sub(/[[:space:]]+$/, "", names);
286
287 # remove comas and duplicate spaces
288 gsub(/,/, "", names);
289 gsub(/[[:space:]]+/, " ", names);
290
291 #print "coucou " names;
292 #print $0;
293
294 delete field_list;
295 # this will delete any previous field_list
296 ret = split(names, field_list, " ");
297
298 #print "hello";
299 #print "split returned " ret ;
300 #for (abc in field_list)
301 #{ print "field_list contient " field_list[abc];}
302
303
304 $0 = "Field: " $0
305 #add_line_after = " ";
306
307 # Add one entry for each of the fields
308 for (ii in field_list) {
309 num = field_description_len[field_struct][field_list[ii]] = 0;
310 #print "Trouvé description de " field_list[ii];
311 }
312
313 if (next_line == "field name") {
314 next_line = "field description";
315 }
316
317 else { next_line = "field name" ; }
318 next;
319 }
320
321 else {
322 # This is a field description
323 #print "coucou";
324 #if (index($0,"BAP")!=0) {
325 #print "BAP trouvé" $0 ;
326 #}
327 #print "contenu " $0;
328
329 if ((next_line == "field name") || (next_line == "field description")) {
330 for (ii in field_list) {
331 field_description_len[field_struct][field_list[ii]]++;
332 num = field_description_len[field_struct][field_list[ii]];
333 field_description[field_struct][field_list[ii]][num] = $0;
334 #print "ajouté une ligne pour " field_list[ii] "dans " field_struct;
335 }
336 next;
337 }
338 }
339 }
340 }
341 }
342
343 #/^[A-Za-z0-9-]+/ {
344 # # remove suffix
345 # sub(/-[vr][0-9]+$/, "", $1);
346 #
347 # current_structure = $1 ;
348 #}
349
350
351
352 {
353 if (in_IE == "yes") {
354
355 #print "$0 est " $0 " in_ASN1 est " in_ASN1;
356 if (next_line == "condition") {
357 #print "branche condition " $0;
358 if ($1 != "Conditional") {
359 if (index(conditions, $1) != 0) {
360 current_condition = $1 ;
361 condition_description_len[current_condition] = 1 ;
362 $1 = "" ;
363 condition_description[current_condition][1] = $0 ;
364 condition_code[current_condition] = need_code($0);
365
366 #print separator;
367 #print "-- Condition: " $1;
368
369 #print "Condition " current_condition " trouvée";
370 }
371
372
373 #if ((in_ASN1 == "no") && !(/^\s*$/)) {
374 #$0 = "-- " $0 ;
375 #}
376
377 # prints first line of condition
378 #print $0 " aaa";
379
380
381 else {
382 #print "La description est " $0;
383 condition_description_len[current_condition]++;
384 condition_description[current_condition][condition_description_len[current_condition]] = $0 ;
385 condition_code[current_condition] = need_code($0);
386 }
387 }
388 }
389 else {
390
391 #print "in_ASN1 est " in_ASN1 " ligne " $0;
392 if ((in_ASN1 == "no") && !(/^\s*$/)) {
393 $0 = "-- " $0 ;
394 #print $0 " bbb";
395 }
396
397 if (in_ASN1 == "no") {
398
399 # prints subsequent lines of condition or IE description
400 if ((!(/\S/) && (empty_line == "yes"))) {next}
401 print $0 #" ccc";
402
403 }
404 else {
405 #print line_number;
406 if((line_number==0) && (/^[[:space:]]*$/)) { next ; }
407 line_number++;
408 text[line_number] = $0;
409
410 #print "text[" line_number "] est " text[line_number];
411 if (/^[A-Za-z0-9-]+[[:space:]]+:/) {
412 # remove suffix
413 sub(/-[vr][0-9]+(-IEs)*$/, "", $1);
414 #print "ddd" ;
415 current_structure = $1 ;
416 text_level[line_number] = level(text[line_number]);
417
418 #print $1;
419 }
420 else {
421
422 if (/[[:space:]]+[a-z][A-Za-z0-9-]*/) {
423 text_level[line_number] = text_level[line_number-1] + level(text[line_number]) ;
424
425 # remove suffix
426 sub(/-[vr][0-9]+$/, "", $1);
427 # remove ToAddModList extension suffixes
428 sub(/ToAddModListExt/, "ToAddModList", $1);
429 sub(/ToAddModListSizeExt/, "ToAddModList", $1);
430
431 field[line_number] = $1;
432
433 #print "field est " field[line_number];
434 structure[line_number] = current_structure ;
435 field_description_len[current_structure][$1] = 0;
436
437
438 }
439 else {
440 field[line_number] = "";
441 text_level[line_number] = text_level[line_number-1] + level(text[line_number]) ;
442 }
443
444 if (/-- Cond [A-Za-z0-9_-]+$/) {
445 if(/}\s*(OPTIONAL)*,*\s*-- Cond [A-Za-z0-9_-]+$/) {
446 #print "trouvé" ;
447
448 # The condition should be placed above the field name,
449 # It is something like
450 # field0 ..... level X
451 # field1 { ..... level X+1
452 # abc ABC, ..... level X+1
453 # def DEF ..... level X+1
454 # } OPTIONAL, -- Cond XYZ ..... level X
455 # So we go back up while level > level of the Cond line
456 # Then we reach field0, so this is the line after
457 # We then associate that line with the condition
458
459 for (b=1;text_level[line_number-b]>text_level[line_number];b++) {};
460 condition[line_number-b+1] = $ NF ;
461
462 # Still, to replace -- Cond XXX with - Need M/R/N,
463 # we need to know the line associated with the condition
464 condition_reference[line_number] = line_number-b+1;
465 }
466
467 condition[line_number] = $NF ;
468
469 #print "condition[" line_number "] est " condition[line_number]
470 }
471 else {
472 condition[line_number] = "";
473 }
474 }
475 }
476 }
477 if (add_line_after != "") {
478 print add_line_after ;
479 add_line_after = "" ;
480 }
481
482 if (/-- Cond [A-Za-z0-9_-]+$/) {
483 conditions = conditions " " $NF ;
484 }
485 }
486 }
487