gtk_label_set -> gtk_label_set_text
[metze/wireshark/wip.git] / tools / extract_asn1_from_spec.pl
1 #$Id$
2 #!/usr/bin/perl
3 # This script extracts the ASN1 definition from and TS 36.331 and generates 3 output files that can be processed by asn2wrs
4 # First download the specification from 3gpp.org as a word document and open it
5 # Then in "view" menu, select normal or web layout (needed to removed page header and footers)
6 # Finally save the document as a text file
7 # Call the script: "perl extract_asn1 36331-xxx.txt"
8 # It should generate: EUTRA-RRC-Definitions.asn, EUTRA-UE-Variables.asn and EUTRA-InterNodeDefinitions
9 use warnings;
10 $input_file = $ARGV[0];
11 $def_output_file = "EUTRA-RRC-Definitions.asn";
12 $var_output_file = "EUTRA-UE-Variables.asn";
13 $internode_output_file = "EUTRA-InterNodeDefinitions.asn";
14
15 sub extract_asn1;
16
17 open(INPUT_FILE, "< $input_file") or die "Can not open file $input_file";
18
19 while (<INPUT_FILE>) {
20   # Process the EUTRA-RRC-Definitions section
21   if( m/EUTRA-RRC-Definitions DEFINITIONS AUTOMATIC TAGS ::=/){
22     open(OUTPUT_FILE, "> $def_output_file") or die "Can not open file $def_output_file";
23     syswrite OUTPUT_FILE,"$_ \n";
24     syswrite OUTPUT_FILE,"BEGIN\n\n";
25
26     # Get all the text delimited by -- ASN1START and -- ASN1STOP
27     extract_asn1();
28
29     syswrite OUTPUT_FILE,"END\n\n";
30     close(OUTPUT_FILE);
31   }
32
33   # Process the EUTRA-RRC-Variables section
34   if( m/EUTRA-UE-Variables DEFINITIONS AUTOMATIC TAGS ::=/){
35     open(OUTPUT_FILE, "> $var_output_file") or die "Can not open file $def_output_file";
36     syswrite OUTPUT_FILE,"$_ \n";
37     syswrite OUTPUT_FILE,"BEGIN\n\n";
38
39     # Get all the text delimited by -- ASN1START and -- ASN1STOP
40     extract_asn1();
41
42     syswrite OUTPUT_FILE,"END\n\n";
43     close(OUTPUT_FILE);
44   }
45   # Process the EUTRA-InterNodeDefinitions section
46   if( m/EUTRA-InterNodeDefinitions DEFINITIONS AUTOMATIC TAGS ::=/){
47     open(OUTPUT_FILE, "> $internode_output_file") or die "Can not open file $def_output_file";
48     syswrite OUTPUT_FILE,"$_ \n";
49     syswrite OUTPUT_FILE,"BEGIN\n\n";
50
51     # Get all the text delimited by -- ASN1START and -- ASN1STOP
52     extract_asn1();
53
54     syswrite OUTPUT_FILE,"END\n\n";
55     close(OUTPUT_FILE);
56   }
57 }
58
59 close(INPUT_FILE);
60
61 # This subroutine copies the text delimited by -- ASN1START and -- ASN1STOP in INPUT_FILE
62 # and copies it into OUTPUT_FILE.
63 # It stops when it meets the keyword "END"
64 sub extract_asn1 {
65   my $line = <INPUT_FILE>;
66   my $is_asn1 = 0;
67
68   while(($line ne "END\n") && ($line ne "END\r\n")){
69     if ($line =~ m/-- ASN1STOP/) {
70       $is_asn1 = 0;
71     }
72     if ($is_asn1 == 1){
73       syswrite OUTPUT_FILE,"$line";
74     }
75     if ($line =~ m/-- ASN1START/) {
76       $is_asn1 = 1;
77     }
78     $line = <INPUT_FILE>;
79   }
80 }