]> nuage.metani.fr Git - 3GPP.git/blob - bin/asn1-split.awk
asn1-split.awk does not add new lines
[3GPP.git] / bin / asn1-split.awk
1 #!/bin/awk -f
2
3 BEGIN {
4 # A record is an IE heading
5 RS = "-- =+\n-- IE: [A-Z][A-Za-z0-9-]+"
6
7 # A field is a line
8 FS = "\n"
9
10 # Do not add new lines when printing
11 ORS = ""
12
13 # Usage explanation
14 if (ARGC != "2") {
15 print "Usage: " ARGV[0] " file.asn"
16 print "Splits file.asn generated by txt2asn into one file per module"
17 exit
18 }
19 file_prefix = ARGV[1]
20 gsub(/.asn$/, "", file_prefix)
21
22 outfile = ""
23 heading = ""
24 }
25 {
26 # Search for the start of a module definition in every field (= line) of the IE
27 for (i = 1; i <= NF; i++) {
28 if ($i ~ /[[A-Z][A-Za-z0-9-]+ DEFINITIONS AUTOMATIC TAGS ::=/) {
29 split($i, module_name, " ")
30 outfile = file_prefix "-" module_name[1] ".asn"
31 }
32 }
33
34 # See below about heading
35 if (outfile != "") {
36 print heading $0 > outfile
37 }
38
39 # RT is the record terminator i.e., the string that matched RS
40 # It actually is the heading of the next record, so store it
41 # to be printed with the next record.
42
43 heading = RT
44 }
45