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