Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1 | #!/usr/bin/perl |
| 2 | |
| 3 | # |
| 4 | # $Id$ |
| 5 | # $Author$ |
| 6 | # |
Lev Walkin | 0634eb7 | 2004-09-07 06:36:22 +0000 | [diff] [blame] | 7 | # Simple tool that extracts known ASN.1 modules from the stream of LyX data. |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 8 | # |
| 9 | |
| 10 | if($#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. |
| 17 | for(my $i; $i <= $#ARGV; $i++) { |
| 18 | $modules{$ARGV[$i]} = $ARGV[$i].".asn1"; |
| 19 | } |
| 20 | |
| 21 | # Process incoming stream in search for ASN.1 modules. |
| 22 | while(<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 Walkin | afcd6df | 2004-09-30 06:22:13 +0000 | [diff] [blame] | 41 | /^([A-Za-z0-9-]+)(\s*{.*)?$/; |
| 42 | next unless $modules{$1}; |
| 43 | open(O, '> '.$modules{$1}); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 44 | print O; |
| 45 | $inmodule = 1; |
Lev Walkin | afcd6df | 2004-09-30 06:22:13 +0000 | [diff] [blame] | 46 | delete $modules{$1}; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 47 | } |
| 48 | } |
| 49 | |
| 50 | # Make sure noone's missing. |
| 51 | die "Modules not found: " . join(", ", keys %modules) . "\n" if keys %modules; |