summaryrefslogtreecommitdiff
path: root/source4/build/pasn1/pasn1.pl
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2004-06-30 17:35:26 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:56:49 -0500
commit8991c6cd96a6f635dffdb77390b09483bcad1c05 (patch)
tree022033356fe734434654465ec9e6682b068b3a63 /source4/build/pasn1/pasn1.pl
parentfb667783ac59959ac37f1ae8b6b29c32addc5e1b (diff)
downloadsamba-8991c6cd96a6f635dffdb77390b09483bcad1c05.tar.gz
samba-8991c6cd96a6f635dffdb77390b09483bcad1c05.tar.bz2
samba-8991c6cd96a6f635dffdb77390b09483bcad1c05.zip
r1306: commit the first steps of my ASN.1 compiler
called 'pasn1', it works like 'pidl' and we may can autogenerate ASN.1 code out of it. (NOTE: the complete LDAP ASN.1 definition is in the RFC 2251, and maybe some others too :-) I'm not completly shure if we'll use it in future, but I commit it so that it won't be lost... metze (This used to be commit ddcaf7b63a0bc49ef1fc2d85d0ba81d67db48790)
Diffstat (limited to 'source4/build/pasn1/pasn1.pl')
-rwxr-xr-xsource4/build/pasn1/pasn1.pl114
1 files changed, 114 insertions, 0 deletions
diff --git a/source4/build/pasn1/pasn1.pl b/source4/build/pasn1/pasn1.pl
new file mode 100755
index 0000000000..f4d0b06bd2
--- /dev/null
+++ b/source4/build/pasn1/pasn1.pl
@@ -0,0 +1,114 @@
+#!/usr/bin/perl -W
+
+###################################################
+# package to parse ASN.1 files and generate code for
+# LDAP functions in Samba
+# Copyright tridge@samba.org 2002-2003
+# Copyright metze@samba.org 2004
+
+# released under the GNU GPL
+
+use strict;
+
+use FindBin qw($RealBin);
+use lib "$RealBin";
+use lib "$RealBin/lib";
+use Getopt::Long;
+use File::Basename;
+use asn1;
+use util;
+
+my($opt_help) = 0;
+my($opt_parse) = 0;
+my($opt_dump) = 0;
+my($opt_keep) = 0;
+my($opt_output);
+
+my $asn1_parser = new asn1;
+
+#####################################################################
+# parse an ASN.1 file returning a structure containing all the data
+sub ASN1Parse($)
+{
+ my $filename = shift;
+ my $asn1 = $asn1_parser->parse_asn1($filename);
+ util::CleanData($asn1);
+ return $asn1;
+}
+
+
+#########################################
+# display help text
+sub ShowHelp()
+{
+ print "
+ perl ASN.1 parser and code generator
+ Copyright (C) tridge\@samba.org
+ Copyright (C) metze\@samba.org
+
+ Usage: pasn1.pl [options] <asn1file>
+
+ Options:
+ --help this help page
+ --output OUTNAME put output in OUTNAME.*
+ --parse parse a asn1 file to a .pasn1 file
+ --dump dump a pasn1 file back to asn1
+ --parser create a C parser
+ --keep keep the .pasn1 file
+ \n";
+ exit(0);
+}
+
+# main program
+GetOptions (
+ 'help|h|?' => \$opt_help,
+ 'output=s' => \$opt_output,
+ 'parse' => \$opt_parse,
+ 'dump' => \$opt_dump,
+ 'keep' => \$opt_keep
+ );
+
+if ($opt_help) {
+ ShowHelp();
+ exit(0);
+}
+
+sub process_file($)
+{
+ my $asn1_file = shift;
+ my $output;
+ my $pasn1;
+
+ my $basename = basename($asn1_file, ".asn1");
+
+ if (!defined($opt_output)) {
+ $output = $asn1_file;
+ } else {
+ $output = $opt_output . $basename;
+ }
+
+ my($pasn1_file) = util::ChangeExtension($output, ".pasn1");
+
+ print "Compiling $asn1_file\n";
+
+ if ($opt_parse) {
+ $pasn1 = ASN1Parse($asn1_file);
+ defined $pasn1 || die "Failed to parse $asn1_file";
+ #ASN1Validator::Validate($pasn1);
+ if ($opt_keep && !util::SaveStructure($pasn1_file, $pasn1)) {
+ die "Failed to save $pasn1_file\n";
+ }
+ } else {
+ $pasn1 = util::LoadStructure($pasn1_file);
+ defined $pasn1 || die "Failed to load $pasn1_file - maybe you need --parse\n";
+ }
+
+ if ($opt_dump) {
+ print ASN1Dump::Dump($pasn1);
+ }
+}
+
+
+foreach my $filename (@ARGV) {
+ process_file($filename);
+}