blob: 83afbeb4374051d0b008a1d333083e5561fef2e3 [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 {
41 next unless $modules{$_};
42 open(O, '> '.$modules{$_});
43 print O;
44 $inmodule = 1;
45 delete $modules{$_};
46 }
47}
48
49# Make sure noone's missing.
50die "Modules not found: " . join(", ", keys %modules) . "\n" if keys %modules;