]> nuage.metani.fr Git - 3GPP.git/blob - awk/txt2asn.awk
38331-convert.sh directly converts docx to text and generates ASN.1 with comments...
[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<=70;i++) {
9 wide_separator = wide_separator "-" ;
10 }
11
12 ie_separator = "-- " ;
13 for (i=0;i<=70;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 "-- IE: Constants";
105 empty_line = "no" ;
106 conditions = "" ;
107 }
108 in_IE = "yes" ;
109 next ;
110 }
111
112 #/^-[[:space:]]+Multiplicity and type constraints definitions/ {
113 # in_IE = "yes" ;
114 # next ;
115 #}
116
117 /^Conditional Presence/ {
118 add_line_after = "";
119 separator = ie_separator ;
120
121 $0 = "Conditional presence" ;
122
123 print separator;
124 #add_line_after = separator ;
125 next_line = "condition" ;
126 }
127
128 # Need to catch "x and y field descriptions"
129
130 /field descriptions$/ {
131 add_line_after = "";
132
133 separator = ie_separator;
134 print separator;
135 # add_line_after = separator ;
136 next_line = "field name" ;
137 }
138
139 #/^[A-Za-z0-9-]+[[:space:]]+[A-Za-z0-9-]+/ {
140 # if (next_line == "field description") {
141 # add_line_after = separator ;
142 # next_line = "field name";
143 # }
144 #}
145
146 /^[A-Za-z0-9-]+(, [A-Za-z0-9-]+)*$/ {
147 if (next_line == "field name") {
148
149 print separator ;
150 separator = wide_separator ;
151
152 $0 = "Field: " $0
153 #add_line_after = " ";
154 next_line = "field description";
155 }
156 else if (next_line == "field description") {
157 print separator ;
158 separator = wide_separator ;
159
160 $0 = "Field: " $0
161 #add_line_after = separator ;
162 #print "separator est " separator;
163 next_line = "field name";
164 }
165 }
166
167
168
169 {
170 if (in_IE == "yes") {
171 if ((next_line == "condition") && ($1 != "Conditional")) {
172
173 if (index(conditions, $1) != 0) {
174 print separator;
175 separator = wide_separator ;
176 print "-- Condition: " $1;
177 $1 = "";
178 }
179 if ((in_ASN1 == "no") && !(/^\s*$/)) {
180 $0 = "-- " $0 ;
181 }
182 print ;
183 }
184
185 else {
186 if ((in_ASN1 == "no") && !(/^\s*$/)) {
187 $0 = "-- " $0 ;
188 }
189 print;
190 }
191
192 if (add_line_after != "") {
193 print add_line_after ;
194 add_line_after = "" ;
195 }
196
197 if (/-- Cond [A-Za-z0-9-]+$/) {
198 conditions = conditions " " $NF ;
199 }
200 }
201 }
202