]> nuage.metani.fr Git - 3GPP.git/blob - awk/txt2asn-integrated.awk
Add command to set git proxy to windows system proxy
[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]+(\.[0-9]+)*\t/ {
141 if (in_IE == "yes") { asn1_print(); }
142 in_IE = "no" ;
143 }
144
145 /^[A-Za-z0-9-]+ message$/ {
146 # No need to print this
147 next;
148 }
149
150 /^[A-Za-z0-9-]+ information element$/ {
151 # No need to print this
152 next;
153 }
154
155 /^-- ASN1START/ {
156 print "";
157 in_ASN1 = "yes";
158 line_number = 0;
159 #empty_line = "yes";
160 next;
161 }
162
163 /^-- ASN1STOP/ {
164 in_ASN1 = "no";
165 direct_print = "no" ;
166 next;
167 }
168
169 /^-- TAG-/ {
170 next;
171 }
172
173 /^[[:space:]]*$/ {
174
175 if (next_line == "condition") {
176 #print separator ;
177 }
178 if ((next_line == "field description") || (next_line == "field name")){
179 #print separator ;
180 }
181
182 if (next_line != "field description") {
183 next_line = "" ;
184 }
185 # #if (empty_line == "yes") {
186 # next;
187 # }
188
189 current_condition = "" ;
190 if (empty_line == "yes") { next; }
191 empty_line = "yes" ;
192
193
194 #print "empty_line set to yes" ;
195 # print ;
196 }
197
198 /\S/ {
199
200 # The empty_line condition is meant for what is directly printed, i.e. messages decriptions
201 # ASN.1, field descriptions and conditions descriptions are not directly printed, so
202 # this should not apply to them
203
204
205
206 #if ((next_line == "field description") || (next_line == "field name")){
207 empty_line = "no" ;
208 #print "empty_line set to no"
209 #}
210
211 }
212
213 /^-[[:space:]]+ParentIE-WithEM$/ {
214 exit 0 ;
215 }
216
217 /^-[[:space:]]+[A-Za-z0-9-]+$/ {
218 asn1_print();
219
220 # if (empty_line == "yes") {
221 #print "";
222 print ie_separator;
223 print "-- IE: " $2;
224 print "" ;
225 empty_line = "no" ;
226 conditions = "" ;
227 IE_name = $2;
228
229 #if (IE_name == "PosSI-SchedulingInfo") { print "IE trouvé" ; }
230 # }
231 in_IE = "yes" ;
232
233 next ;
234 }
235
236 /^-[[:space:]]+Multiplicity and type constraints? definitions?$/ {
237
238 #print "Trouvé" ;
239 if (in_IE == "yes") {
240 asn1_print();
241 }
242 in_IE = "yes" ;
243 #print "Trouvé 2" ;
244
245 # In this case, directly print ASN.1 without processing
246 direct_print = "yes" ;
247
248 print ie_separator;
249 print "-- IE: Constants";
250 print "" ;
251 empty_line = "no" ;
252 conditions = "" ;
253
254 next ;
255 }
256
257 /^-[[:space:]]+End of [A-Za-z0-9-]+$/ {
258 if (in_IE == "yes") {
259 asn1_print();
260 }
261 in_IE = "yes" ;
262 empty_line = "no" ;
263 conditions = "" ;
264 }
265
266 /^NR-InterNodeDefinitions/ {
267
268 print ie_separator;
269 print "-- IE: NR-InterNodeDefinitions";
270 print "" ;
271 print ;
272
273 empty_line = "no" ;
274 conditions = "" ;
275
276 in_IE = "no" ;
277 direct_print = "yes" ;
278 next ;
279 }
280
281 /^Conditional [Pp]resence/ {
282 add_line_after = "";
283 separator = "" ;
284
285 $0 = "Conditional presence" ;
286 for(i=0;i<=140;i++) {
287 separator = separator "-" ;
288 }
289 # print separator;
290 #add_line_after = separator ;
291 next_line = "condition" ;
292 #print "Conditional Presence"
293 #if (IE_name == "PosSI-SchedulingInfo") { print "condition trouvée" ; }
294 }
295
296 # Need to catch "x and y field descriptions"
297
298 /field descriptions$/ {
299 add_line_after = "";
300 separator = "" ;
301
302 for(i=0;i<=140;i++) {
303 separator = separator "-" ;
304 }
305 # print separator;
306 # add_line_after = separator ;
307 next_line = "field name" ;
308
309 field_struct = $1;
310
311 #print "Trouvé description des champs de " $1;
312 # do not print
313 next;
314 }
315
316 #/^[A-Za-z0-9-]+[[:space:]]+[A-Za-z0-9-]+/ {
317 # if (next_line == "field description") {
318 # add_line_after = separator ;
319 # next_line = "field name";
320 # }
321 #}
322
323 # This is matched for any non-empty line
324 /[A-Za-z0-9-]+/ {
325
326
327 if ((in_IE == "yes") && (in_ASN1 == "no")){
328
329 # if we are coming from a "IE X field description" statement
330 # or we were in a field description
331 if ((next_line == "field name") || (next_line == "field description")) {
332
333
334 # If the whole line is a coma-separated list in an IE (=> field names)
335 if (/^[A-Za-z0-9-]+(, [A-Za-z0-9-]+)*$/) {
336 # Then, this is a new field, or list of fields
337 #print separator ;
338
339 names = $0;
340
341 # remove leading/trailing spaces
342 sub(/^[[:space:]]+/, "", names);
343 sub(/[[:space:]]+$/, "", names);
344
345 # remove comas and duplicate spaces
346 gsub(/,/, "", names);
347 gsub(/[[:space:]]+/, " ", names);
348
349 #print "coucou " names;
350 #print $0;
351
352 delete field_list;
353 # this will delete any previous field_list
354 ret = split(names, field_list, " ");
355
356 #print "hello";
357 #print "split returned " ret ;
358 #for (abc in field_list)
359 #{ print "field_list contient " field_list[abc];}
360
361
362 $0 = "Field: " $0
363 #add_line_after = " ";
364
365 # Add one entry for each of the fields
366 for (ii in field_list) {
367 num = field_description_len[field_struct][field_list[ii]] = 0;
368 #print "Trouvé description de " field_list[ii];
369 }
370
371 if (next_line == "field name") {
372 next_line = "field description";
373 }
374
375 else { next_line = "field name" ; }
376 next;
377 }
378
379 else {
380 # This is a field description
381 #print "coucou";
382 #if (index($0,"BAP")!=0) {
383 #print "BAP trouvé" $0 ;
384 #}
385 #print "contenu " $0;
386
387 if ((next_line == "field name") || (next_line == "field description")) {
388 for (ii in field_list) {
389 field_description_len[field_struct][field_list[ii]]++;
390 num = field_description_len[field_struct][field_list[ii]];
391 field_description[field_struct][field_list[ii]][num] = $0;
392 #print "ajouté une ligne pour " field_list[ii] "dans " field_struct;
393 }
394 next;
395 }
396 }
397 }
398 }
399
400 else if ((in_ASN1 == "yes") && (direct_print == "yes")) {
401 print ;
402 next ;
403 }
404 }
405
406 #/^[A-Za-z0-9-]+/ {
407 # # remove suffix
408 # sub(/-[vr][0-9]+$/, "", $1);
409 #
410 # current_structure = $1 ;
411 #}
412
413
414
415 {
416 if (in_IE == "yes") {
417
418 #print "$0 est " $0 " in_ASN1 est " in_ASN1;
419 if (next_line == "condition") {
420 #print "branche condition " $0;
421 if ($1 != "Conditional") {
422 if (index(conditions, $1) != 0) {
423 current_condition = $1 ;
424 condition_description_len[current_condition] = 1 ;
425 $1 = "" ;
426 condition_description[current_condition][1] = $0 ;
427 condition_code[current_condition] = need_code($0);
428
429 #print separator;
430 #print "-- Condition: " $1;
431
432 #print "Condition " current_condition " trouvée";
433 }
434
435
436 #if ((in_ASN1 == "no") && !(/^\s*$/)) {
437 #$0 = "-- " $0 ;
438 #}
439
440 # prints first line of condition
441 #print $0 " aaa";
442
443
444 else {
445 #print "La description est " $0;
446 condition_description_len[current_condition]++;
447 condition_description[current_condition][condition_description_len[current_condition]] = $0 ;
448 condition_code[current_condition] = need_code($0);
449 }
450 }
451 }
452 else {
453
454 #print "in_ASN1 est " in_ASN1 " ligne " $0;
455 if ((in_ASN1 == "no") && !(/^\s*$/)) {
456 $0 = "-- " $0 ;
457 #print $0 " bbb";
458 }
459
460 if (in_ASN1 == "no") {
461
462 # prints subsequent lines of condition or IE description
463 if ((!(/\S/) && (empty_line == "yes"))) {next}
464 print $0 #" ccc";
465
466 }
467 else {
468 #print line_number;
469 if((line_number==0) && (/^[[:space:]]*$/)) { next ; }
470 line_number++;
471 text[line_number] = $0;
472
473 if (/Multiplicity/) {
474 print "Trouvé 3";
475 print $0;
476 }
477 #print "text[" line_number "] est " text[line_number];
478 if (/^[A-Za-z0-9-]+[[:space:]]+:/) {
479 # remove suffix
480 sub(/-[vr][0-9]+(-IEs)*$/, "", $1);
481 #print "ddd" ;
482 current_structure = $1 ;
483 text_level[line_number] = level(text[line_number]);
484
485 #print $1;
486 }
487 else {
488
489 if (/[[:space:]]+[a-z][A-Za-z0-9-]*/) {
490 text_level[line_number] = text_level[line_number-1] + level(text[line_number]) ;
491
492 # remove suffix
493 sub(/-[vr][0-9]+$/, "", $1);
494 # remove ToAddModList extension suffixes
495 sub(/ToAddModListExt/, "ToAddModList", $1);
496 sub(/ToAddModListSizeExt/, "ToAddModList", $1);
497
498 field[line_number] = $1;
499
500 #print "field est " field[line_number];
501 structure[line_number] = current_structure ;
502 field_description_len[current_structure][$1] = 0;
503
504
505 }
506 else {
507 field[line_number] = "";
508 text_level[line_number] = text_level[line_number-1] + level(text[line_number]) ;
509 }
510
511 if (/-- Cond [A-Za-z0-9_-]+$/) {
512 if(/}\s*(OPTIONAL)*,*\s*-- Cond [A-Za-z0-9_-]+$/) {
513 #print "trouvé" ;
514
515 # The condition should be placed above the field name,
516 # It is something like
517 # field0 ..... level X
518 # field1 { ..... level X+1
519 # abc ABC, ..... level X+1
520 # def DEF ..... level X+1
521 # } OPTIONAL, -- Cond XYZ ..... level X
522 # So we go back up while level > level of the Cond line
523 # Then we reach field0, so this is the line after
524 # We then associate that line with the condition
525
526 for (b=1;text_level[line_number-b]>text_level[line_number];b++) {};
527 condition[line_number-b+1] = $ NF ;
528
529 # Still, to replace -- Cond XXX with - Need M/R/N,
530 # we need to know the line associated with the condition
531 condition_reference[line_number] = line_number-b+1;
532 }
533
534 condition[line_number] = $NF ;
535
536 #print "condition[" line_number "] est " condition[line_number]
537 }
538 else {
539 condition[line_number] = "";
540 }
541 }
542 }
543 }
544 if (add_line_after != "") {
545 print add_line_after ;
546 add_line_after = "" ;
547 }
548
549 if (/-- Cond [A-Za-z0-9_-]+$/) {
550 conditions = conditions " " $NF ;
551 }
552 }
553 else if ((in_ASN1 == "yes") && (direct_print == "yes")) {
554 print ;
555 }
556 }
557