blob: e544baa57915c31f8c8db9a40d5d21e8baa15977 [file] [log] [blame]
vlmfa67ddc2004-06-03 03:38:44 +00001#!/usr/bin/perl
2
3#
4# $Id$
5# $Author$
6#
7# Simple tool that fetches known ASN.1 specifications from the
8# stream of LyX data.
9#
10
11if($#ARGV == -1) {
12 print STDERR "Extract known modules from LyX data\n";
13 print STDERR "Usage: cat *.lyx | $0 <ASN-Module-Name> ...\n";
14 exit 64;
15}
16
17# Convert arguments into a hash for quicker search.
18for(my $i; $i <= $#ARGV; $i++) {
19 $modules{$ARGV[$i]} = $ARGV[$i].".asn1";
20}
21
22# Process incoming stream in search for ASN.1 modules.
23while(<STDIN>) {
24 chop;
25 if($inmodule) {
26 next if(/^$/);
27 if(/^\\layout /) {
28 print O "\n";
29 next;
30 }
31 if(/^\\begin_inset Quotes/) {
32 print O '"';
33 next;
34 }
35 next if(/^\\/);
36 print O;
37 if(/^END$/) {
38 $inmodule = 0;
39 print O "\n";
40 }
41 } else {
42 next unless $modules{$_};
43 open(O, '> '.$modules{$_});
44 print O;
45 $inmodule = 1;
46 delete $modules{$_};
47 }
48}
49
50# Make sure noone's missing.
51die "Modules not found: " . join(", ", keys %modules) . "\n" if keys %modules;