#!/usr/bin/perl

use strict;
use warnings;

use CORBA::IDL      2.60;
use CORBA::XMLSchemas;
# visitors
use CORBA::IDL::RepositoryIdVisitor;
use CORBA::XMLSchemas::NameVisitor;
use CORBA::XMLSchemas::RelaxngVisitor;

my $parser = CORBA::IDL::ParserFactory::create('3.0');
$parser->getopts('b:hi:qr:stvx');
if ($parser->YYData->{opt_v}) {
    print "CORBA::XMLSchemas $CORBA::XMLSchemas::VERSION\n";
    print "CORBA::IDL $CORBA::IDL::VERSION\n";
    print "IDL $CORBA::IDL::Parser::IDL_VERSION\n";
    print "$0\n";
    print "Perl $] on $^O\n";
    exit;
}
if ($parser->YYData->{opt_h}) {
    use Pod::Usage;
    pod2usage(-verbose => 1);
}

my $cflags = '-D__idl2rng';
if ($CORBA::IDL::Parser::IDL_VERSION lt '3.0') {
    $cflags .= ' -D_PRE_3_0_COMPILER_';
}
my $preprocessor;
if ($^O eq 'MSWin32') {
    $preprocessor = 'cpp -C ' . $cflags;
#    $preprocessor = 'CL /E /C /nologo ' . $cflags;      # Microsoft VC
}
else {
    $preprocessor = 'cpp -C ' . $cflags;
}
$parser->Configure(
        'preprocessor'          => $preprocessor,
        'verbose_error'         => 1,   # 0, 1
        'verbose_warning'       => 1,   # 0, 1
        'verbose_info'          => 1,   # 0, 1
        'verbose_deprecated'    => 0,   # 0, 1 (concerns only version '2.4' and upper)
#        'collision_allowed'     => 1,
);
$parser->Run(@ARGV);
$parser->DisplayStatus();
my $root = $parser->getRoot();
if (defined $root) {
    $root->visit(new CORBA::IDL::RepositoryIdVisitor($parser));
    if ($parser->YYData->{opt_x}) {
        $parser->Export();
    }
    $root->visit(new CORBA::XMLSchemas::NameVisitor($parser));
    $root->visit(new CORBA::XMLSchemas::RelaxngVisitor($parser, $parser->YYData->{opt_s}, $parser->YYData->{opt_r}));
}

__END__

=head1 NAME

idl2rng - IDL compiler to RELAX NG Schema

=head1 SYNOPSIS

idl2rng [options] I<spec>.idl

=head1 OPTIONS

All options are forwarded to C preprocessor, except -b -h -i -q -r -s -t -v -x.

With the GNU C Compatible Compiler Processor, useful options are :

=over 8

=item B<-D> I<name>

=item B<-D> I<name>=I<definition>

=item B<-I> I<directory>

=item B<-I->

=item B<-nostdinc>

=back

Specific options :

=over 8

=item B<-b> I<base uri>

Specify a base uri for location of include.

=item B<-h>

Display help.

=item B<-i> I<directory>

Specify a path for import (only for IDL version 3.0).

=item B<-q>

Generate qualified elements.

=item B<-r> I<root-element>

Specify a root element.

=item B<-s>

Generate a standalone Schema (not only type definition).

=item B<-t>

Generate tabulated XML (beautify for human).

=item B<-v>

Display version.

=item B<-x>

Enable export (only for IDL version 3.0).

=back

=head1 DESCRIPTION

B<idl2rng> parses the given input file (IDL) and generates :

=over 4

=item *
a RELAX NG Schema I<spec>.rng equivalent to W3C Schema following the CORBA
to WSDL/SOAP Interworking Specification (WS-I conformant soap binding).

=back

B<idl2rng> is a Perl OO application what uses the visitor design pattern.
The parser is generated by Parse::Yapp.

B<idl2rng> needs XML::DOM module.

B<idl2rng> needs a B<cpp> executable.

CORBA Specifications, including IDL (Interface Definition Language) and
CORBA to WSDL/SOAP Interworking Specification are
available on E<lt>http://www.omg.org/E<gt>.

=head1 SEE ALSO

cpp, perl, idl2html, idl2javaxml, idl2xsd

=head1 COPYRIGHT

(c) 2003-2007 Francois PERRAD, France. All rights reserved.

This program and all CORBA::XMLSchemas modules are distributed
under the terms of the Artistic Licence.

=head1 AUTHOR

Francois PERRAD, francois.perrad@gadz.org

=cut