aboutsummaryrefslogtreecommitdiffstats
path: root/examples/clyx2asn1.pl
blob: 77251bf85788f4e44d783d13a57559c801eb20ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/perl

#
# $Id$
# $Author$
#
# Simple tool that extracts known ASN.1 modules from the stream of LyX data.
#

if($#ARGV == -1) {
	print STDERR "Extract known modules from LyX data\n";
	print STDERR "Usage: cat *.lyx | $0 <ASN-Module-Name> ...\n";
	exit 64;
}

# Convert arguments into a hash for quicker search.
for(my $i; $i <= $#ARGV; $i++) {
	$modules{$ARGV[$i]} = $ARGV[$i].".asn1";
}

# Process incoming stream in search for ASN.1 modules.
while(<STDIN>) {
	chop;
	if($inmodule) {
		next if(/^$/);
		if(/^\\layout /) {
			print O "\n";
			next;
		}
		if(/^\\begin_inset Quotes/) {
			print O '"';
			next;
		}
		next if(/^\\/);
		print O;
		if(/^END$/) {
			$inmodule = 0;
			print O "\n";
		}
	} else {
		/^([A-Za-z0-9-]+)(\s*{.*)?$/;
		next unless $modules{$1};
		open(O, '> '.$modules{$1});
		print O;
		$inmodule = 1;
		delete $modules{$1};
	}
}

# Make sure noone's missing.
die "Modules not found: " . join(", ", keys %modules) . "\n" if keys %modules;