blob: 20e1f9f792533f227bd46fb8dc36d50ec6c381e8 [file] [log] [blame]
Lev Walkinf15320b2004-06-03 03:38:44 +00001#!/usr/bin/perl
2
3#
4# $Id$
5# $Author$
6#
7# Simple tool that fetches the ASN.1 specifications from the
8# given set of RFC files.
9#
10
11
12my $inasn = 0; # Are we inside ASN.1 grammar?
13my $found = 0;
14
15if(-t STDIN && $#ARGV == -1) {
16 print STDERR "Rip ASN.1 specification from RFC file\n";
17 print STDERR "Usage: $0 <rfc-file.txt> ...\n";
18 print STDERR "Usage: <someprog> | $0\n";
19 exit(1);
20}
21
22while(<>) {
23 #
24 # Strip RFC page delimiters.
25 #
26 next if /^[A-Z].*\[Page [0-9]+\]$/;
27 next if /^ $/;
28 next if /^RFC [0-9].*[0-9]+$/;
29
30 if($inasn == 0) {
31 #
32 # The least correct way to find the start of ASN
33 # definition.
34 #
35 if(/^[ \t]*END[ \t]*$/) {
36 print STDERR
37 "Missed an ASN.1 grammar before line ". $. ."?\n";
38 exit(1);
39 }
40
41 my $rfcid = '';
42 $rfcid = $1 . '-' if($ARGV =~ /([a-z0-9]+)/i);
43
44 if(/^[ \t]+([A-Za-z0-9-]+).*DEFINITIONS.*::=/) {
45 my $fname = $rfcid . $1 . ".asn1";
46 open(O, "> $fname") or die "Can't open $fname";
47 select(O);
48 $inasn = 1;
49 } elsif(/^[ \t]*([A-Za-z0-9-]+).*{.*iso/) {
50 my $fname = $rfcid . $1 . ".asn1";
51 my @a = ($_);
52 my $i;
53 for($i = 0; $i < 8; $i++) {
54 $_ = <>;
55 push(@a, $_);
56 if(/DEFINITIONS/) {
57 $_ = join('', @a);
58 $inasn = 1;
59 last;
60 }
61 }
62 next unless $inasn;
63 open(O, "> $fname") or die "Can't open $fname";
64 select(O);
65 } else {
66 next;
67 }
68
69 $found++;
70 print "\n";
71 print "-- \n";
72 print "-- Grammar found in $ARGV by $0 at " . $. . "\n";
73 print "-- \n";
74 print "\n";
75 }
76
77 print;
78
79 if(/^[ \t]*END[ \t]*$/) {
80 select(STDOUT);
81 close(O);
82 $inasn = 0;
83 }
84}
85
86die "No ASN.1 specifications found\n" unless $found;