#!/usr/bin/perl -w

use strict;
use CORBA::IDL::parser24;
use CORBA::IDL::symbtab;
# visitors
use CORBA::IDL::repos_id;
use CORBA::C::literal;
use CORBA::C::name;
use CORBA::C::include;
use CORBA::XS::c_skel;
use CORBA::XS::c_stub;
use CORBA::XS::xs_c;
use CORBA::XS::pl_name;
use CORBA::XS::pl_stub;

my $parser = new Parser;
$parser->YYData->{IDL_version} = '2.4';
$parser->YYData->{verbose_error} = 1;
$parser->YYData->{verbose_warning} = 1;
$parser->YYData->{verbose_info} = 1;
$parser->YYData->{verbose_deprecated} = 0;
$parser->YYData->{symbtab} = new Symbtab($parser);
if ($^O eq 'MSWin32') {
	$parser->YYData->{preprocessor} = 'cpp -C -D__idl2pl';
#	$parser->YYData->{preprocessor} = 'CL /E /C /nologo /D__idl2pl';	# Microsoft VC
} else {
	$parser->YYData->{preprocessor} = 'cpp -C -D__idl2pl';
}
$parser->Run(@ARGV);
$parser->YYData->{symbtab}->CheckForward();

if (exists $parser->YYData->{nb_error}) {
	my $nb = $parser->YYData->{nb_error};
	print "$nb error(s).\n"
}
if (exists $parser->YYData->{nb_warning}) {
	my $nb = $parser->YYData->{nb_warning};
	print "$nb warning(s).\n"
}

if (		exists $parser->YYData->{root}
		and ! exists $parser->YYData->{nb_error} ) {
	$parser->YYData->{root}->visitName(new repositoryIdVisitor($parser));
	$parser->YYData->{root}->visitName(new CnameVisitor($parser));
	$parser->YYData->{root}->visitName(new CliteralVisitor($parser));
	$parser->YYData->{root}->visitName(new ClengthVisitor($parser));
	$parser->YYData->{root}->visitName(new CtypeVisitor($parser));
	$parser->YYData->{root}->visit(new CincludeVisitor($parser));
	$parser->YYData->{root}->visit(new CskeletonVisitor($parser));
	$parser->YYData->{root}->visit(new XS_CstubVisitor($parser));
	$parser->YYData->{root}->visitName(new PerlNameVisitor($parser));
	$parser->YYData->{root}->visit(new XS_PerlStubVisitor($parser));
	$parser->YYData->{root}->visit(new XS_C_Visitor($parser));
	do 'Makefile.PL';
}

__END__

=head1 NAME

idl2xs_c - IDL compiler to extension interface between Perl and C code

=head1 SYNOPSYS

idl2xs_c [options] I<spec>.idl

=head1 OPTIONS

All options are forwarded to C preprocessor.

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

=head1 DESCRIPTION

B<idl2xs_c> is an alternative to B<h2xs> and B<XS> language when an IDL interface is available.

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

=over 4

=item *
a Perl stub I<spec>.pm

(deals with CDR serialization, and autoload)

=item *
a C stub I<spec>.c

(deals with Perl API)

=item *
a C stub cdr_I<spec>.c

(deals with CDR serialization)

=item *
a include file I<spec>.h

(following the language C mapping rules)

=item *
a C skeleton skel_I<spec>.c0

=item *
Makefile.PL

=item *
Makefile

(from Makefile.PL)

=item *
test.pl

=item *
MANIFEST

=item *
Changes

=back

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

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

B<idl2xs_c> needs CORBA::IDL and CORBA::C modules.

CORBA Specifications, including (IDL : Interface Language Definition and
CDR : Common Data Representation) and
C Language Mapping are available on E<lt>http://www.omg.org/E<gt>.

CORBA mapping for Perl [mapping.pod - Draft 1, 7 October 1999] comes with the package
CORBA::MICO or CORBA::ORBit.

Exceptions are implemented using the Error module.

=head1 TUTORIAL

=head2 EXAMPLE 1

The file Calc.idl describes the interface of a simple calculator.

First, run :

    idl2xs_c Calc.idl

Second, make skel_Calc.c from skel_Calc.c0 by completing each methode between tag
START_EDIT and STOP_EDIT :

    // IDL : long Add(in long val1, in long val2);

    CORBA_long
    Calc_Add(
        Calc _o,
        CORBA_long val1, // in (fixed length)
        CORBA_long val2, // in (fixed length)
        CORBA_Environment * _ev
    )
    {
    /* START_EDIT (Calc_Add) */
        return val1 + val2;
    /* STOP_EDIT (Calc_Add) */
    }

Third, build :

    make
    make test
    make install

Fourth, if you use Test::Unit, you can continue with :

    cd testunit
    testrunner suite_calc

Finally, using the extension module :

    use Calc;
    my $calc = new Calc();
    print $calc->Add(2, 3);

=head1 SEE ALSO

cpp, perl, idl2html, idl2c

=head1 COPYRIGHT

(c) 2002 Francois PERRAD, France. All rights reserved.

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

=head1 AUTHOR

Francois PERRAD E<lt>perrad@besancon.sema.slb.comE<gt>

=cut

