| 1 | #!/usr/bin/perl -w
|
|---|
| 2 |
|
|---|
| 3 | ###################################################
|
|---|
| 4 | # package to parse ASN.1 files and generate code for
|
|---|
| 5 | # LDAP functions in Samba
|
|---|
| 6 | # Copyright tridge@samba.org 2002-2003
|
|---|
| 7 | # Copyright metze@samba.org 2004
|
|---|
| 8 |
|
|---|
| 9 | # released under the GNU GPL
|
|---|
| 10 |
|
|---|
| 11 | use strict;
|
|---|
| 12 |
|
|---|
| 13 | use FindBin qw($RealBin);
|
|---|
| 14 | use lib "$RealBin";
|
|---|
| 15 | use lib "$RealBin/lib";
|
|---|
| 16 | use Getopt::Long;
|
|---|
| 17 | use File::Basename;
|
|---|
| 18 | use asn1;
|
|---|
| 19 | use util;
|
|---|
| 20 |
|
|---|
| 21 | my($opt_help) = 0;
|
|---|
| 22 | my($opt_output);
|
|---|
| 23 |
|
|---|
| 24 | my $asn1_parser = new asn1;
|
|---|
| 25 |
|
|---|
| 26 | #####################################################################
|
|---|
| 27 | # parse an ASN.1 file returning a structure containing all the data
|
|---|
| 28 | sub ASN1Parse($)
|
|---|
| 29 | {
|
|---|
| 30 | my $filename = shift;
|
|---|
| 31 | my $asn1 = $asn1_parser->parse_asn1($filename);
|
|---|
| 32 | util::CleanData($asn1);
|
|---|
| 33 | return $asn1;
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 | #########################################
|
|---|
| 38 | # display help text
|
|---|
| 39 | sub ShowHelp()
|
|---|
| 40 | {
|
|---|
| 41 | print "
|
|---|
| 42 | perl ASN.1 parser and code generator
|
|---|
| 43 | Copyright (C) tridge\@samba.org
|
|---|
| 44 | Copyright (C) metze\@samba.org
|
|---|
| 45 |
|
|---|
| 46 | Usage: pasn1.pl [options] <asn1file>
|
|---|
| 47 |
|
|---|
| 48 | Options:
|
|---|
| 49 | --help this help page
|
|---|
| 50 | --output OUTNAME put output in OUTNAME
|
|---|
| 51 | \n";
|
|---|
| 52 | exit(0);
|
|---|
| 53 | }
|
|---|
| 54 |
|
|---|
| 55 | # main program
|
|---|
| 56 | GetOptions (
|
|---|
| 57 | 'help|h|?' => \$opt_help,
|
|---|
| 58 | 'output|o=s' => \$opt_output,
|
|---|
| 59 | );
|
|---|
| 60 |
|
|---|
| 61 | if ($opt_help) {
|
|---|
| 62 | ShowHelp();
|
|---|
| 63 | exit(0);
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|
| 66 | sub process_file($)
|
|---|
| 67 | {
|
|---|
| 68 | my $input_file = shift;
|
|---|
| 69 | my $output_file;
|
|---|
| 70 | my $pasn1;
|
|---|
| 71 |
|
|---|
| 72 | my $basename = basename($input_file, ".asn1");
|
|---|
| 73 |
|
|---|
| 74 | if (!defined($opt_output)) {
|
|---|
| 75 | $output_file = util::ChangeExtension($input_file, ".pasn1");
|
|---|
| 76 | } else {
|
|---|
| 77 | $output_file = $opt_output;
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | # if (file is .pasn1) {
|
|---|
| 81 | # $pasn1 = util::LoadStructure($pasn1_file);
|
|---|
| 82 | # defined $pasn1 || die "Failed to load $pasn1_file - maybe you need --parse\n";
|
|---|
| 83 | # } else {
|
|---|
| 84 | $pasn1 = ASN1Parse($input_file);
|
|---|
| 85 | defined $pasn1 || die "Failed to parse $input_file";
|
|---|
| 86 | util::SaveStructure($output_file, $pasn1) ||
|
|---|
| 87 | die "Failed to save $output_file\n";
|
|---|
| 88 | #}
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | foreach my $filename (@ARGV) {
|
|---|
| 92 | process_file($filename);
|
|---|
| 93 | }
|
|---|