#!/usr/bin/perl -I/Users/duke/src/kde/kdebindings/kalyptus

# KDOC -- C++ and CORBA IDL interface documentation tool.
# Sirtaj Singh Kang <taj@kde.org>, Jan 1999.
# $Id: kalyptus,v 1.1 2003/08/29 13:54:34 lypanov Exp $

# All files in this project are distributed under the GNU General
# Public License. This is Free Software.

require 5.000;

use Carp;
use Getopt::Long;
use File::Basename;
use strict;

use Ast;

use kdocUtil;
use kdocAstUtil;
use kdocParseDoc;

use vars qw/ %rootNodes $declNodeType @includes_list %options @formats_wanted $allow_k_dcop_accessors
        @includeclasses $includeclasses $skipInternal %defines $defines $match_qt_defines
	$libdir $libname $outputdir @libs $parse_global_space $striphpath $doPrivate $readstdin
	$Version $quiet $debug $debuggen $parseonly $currentfile $cSourceNode $exe
	%formats %flagnames @allowed_k_dcop_accesors $allowed_k_dcop_accesors_re $rootNode 
	@classStack $cNode $globalSpaceClassName
	$lastLine $docNode @includes $cpp $defcppcmd $cppcmd $docincluded
	$inExtern %stats %definitions @inputqueue @codeqobject /;
     
## globals

%rootNodes = ();			# root nodes for each file type
$declNodeType = undef;			# last declaration type

@includes_list = ();			# list of files included from the parsed .h

# All options

%options = ();				# hash of options (set getopt below)
@formats_wanted = ();
$libdir = $ENV{KDOCLIBS};
$libname = "";
$outputdir = ".";
@libs = ();				# list of includes
$striphpath = 0;

@includeclasses = ();                     # names of classes to include
$includeclasses = "";

$doPrivate = 0;
$Version = "0.9";

$quiet = 0;
$debug = 0;
$debuggen = 0;
$parseonly = 0;
$globalSpaceClassName = "QGlobalSpace";

$currentfile = "";

$cpp = 0;
$defcppcmd = "g++ -Wp,-C -E";
$cppcmd = "";

$exe = basename $0;

@inputqueue = ();
@codeqobject = split "\n", <<CODE;
public:
    virtual QMetaObject *metaObject() const;
    virtual const char *className() const;
    virtual void* qt_cast( const char* );
    virtual bool qt_invoke( int, QUObject* );
    virtual bool qt_emit( int, QUObject* );
    virtual bool qt_property( int, int, QVariant* );
    static QMetaObject* staticMetaObject();
    QObject* qObject();
    static QString tr( const char *, const char * = 0 );
    static QString trUtf8( const char *, const char * = 0 );
private:
CODE

# Supported formats
%formats = ( "java" => "kalyptusCxxToJava", "c" => "kalyptusCxxToC",
	"objc" => "kalyptusCxxToObjc", "dcopidl" => "kalyptusCxxToDcopIDL",
	"smoke" => "kalyptusCxxToSmoke", "csharp" => "kalyptusCxxToCSharp",
        "ECMA" => "kalyptusCxxToECMA", "swig" => "kalyptusCxxToSwig" );

# these are for expansion of method flags
%flagnames = ( v => 'virtual', 's' => 'static', p => 'pure',
	c => 'const', l => 'slot', i => 'inline', n => 'signal',
 	d => 'k_dcop', z => 'k_dcop_signals', y => 'k_dcop_hidden' );

@allowed_k_dcop_accesors = qw(k_dcop k_dcop_hidden k_dcop_signals);
$allowed_k_dcop_accesors_re = join("|", @allowed_k_dcop_accesors);
        
%definitions = {
    _STYLE_CDE => '',
    _STYLE_MOTIF => '',
    _STYLE_MOTIF_PLUS => '',
    PLUS => '',
    _STYLE_PLATINUM => '',
    _STYLE_SGI => '',
    _STYLE_WINDOWS => '',
    QT_STATIC_CONST => 'static const',
    Q_EXPORT => '',
    Q_REFCOUNT => '',
    QM_EXPORT_CANVAS => '',
    QM_EXPORT_DNS => '',
    QM_EXPORT_ICONVIEW => '',
    QM_EXPORT_NETWORK => '',
    QM_EXPORT_SQL => '',
    QM_EXPORT_WORKSPACE => '',
    QT_NO_REMOTE => 'QT_NO_REMOTE',
    QT_ACCESSIBILITY_SUPPORT => 'QT_ACCESSIBILITY_SUPPORT',
    Q_WS_X11 => 'Q_WS_X11',
    Q_DISABLE_COPY => 'Q_DISABLE_COPY',
    Q_WS_QWS => 'undef',
    Q_WS_MAC => 'undef',
    Q_OBJECT => <<'CODE',
public:
    virtual QMetaObject *metaObject() const;
    virtual const char *className() const;
    virtual bool qt_invoke( int, QUObject* );
    virtual bool qt_emit( int, QUObject* );
    static QString tr( const char *, const char * = 0 );
    static QString trUtf8( const char *, const char * = 0 );
private:
CODE
};

=head1 KDOC -- Source documentation tool

	Sirtaj Singh Kang <taj@kde.org>, Dec 1998.

=cut

# read options

Getopt::Long::config qw( no_ignore_case permute bundling auto_abbrev );

GetOptions( \%options,
	"format|f=s", \@formats_wanted,
	"url|u=s",
	"skip-internal", \$skipInternal,
	"skip-deprecated|e",
	"document-all|a",
	"compress|z",
        "no-cache",      # do not create $HOME/.kalyptus cache
	# HTML options
	"html-cols=i",
	"html-logo=s",

	"strip-h-path",	\$striphpath,
	"outputdir|d=s", \$outputdir,
	"stdin|i",	\$readstdin,
	"name|n=s",	\$libname,
	"help|h", 	\&show_usage,
	"version|v|V", 	\&show_version,
	"private|p",	\$doPrivate,
	"libdir|L=s",	\$libdir,
	"xref|l=s",	\@libs,
	"classes|c=s",    \@includeclasses,
	"globspace",	\$parse_global_space,
	"allow_k_dcop_accessors", \$allow_k_dcop_accessors,

	"cpp|P",	\$cpp,
	"docincluded",  \$docincluded,
	"cppcmd|C=s",	\$cppcmd,
	"includedir|I=s", \@includes,
	"define=s", \%defines, # define a single preprocessing symbol
	"defines=s", \$defines, # file containing preprocessing symbols, one per line

	"quiet|q",	\$quiet,
	"debug|D",	\$debug, # debug the parsing
	"debuggen",	\$debuggen, # debug the file generation
	"parse-only",	\$parseonly )
		|| exit 1;

$| = 1 if $debug or $debuggen;

# preprocessor settings

if ( $cppcmd eq "" ) {
	$cppcmd = $defcppcmd;
}
else {
	$cpp = 1;
}

if ($#includeclasses>=0)
{
    $includeclasses = join (" ", @includeclasses);
    print "Using Classes: $includeclasses\n" unless $quiet;
}

if ( $#includes >= 0 && !$cpp ) {
	die "$exe: --includedir requires --cpp\n";
}

# Check output formats. HTML is the default
if( $#formats_wanted < 0 ) {
	push @formats_wanted, "java";
}

foreach my $format ( @formats_wanted ) {
	die "$exe: unsupported format '$format'.\n"
		if !defined $formats{$format};
}

if( $defines )
{
    open( DEFS, $defines ) or die "Couldn't open $defines: $!\n";
    my @defs = <DEFS>;
    chomp @defs;
    close DEFS;
    foreach (@defs)
    {
        $defines{ $_ } = 1 unless exists $defines{ $_ };
    }
}

# Check the %defines hash for QT_* symbols and compile the corresponding RE
# Otherwise, compile the default ones. Used for filtering in readCxxLine.
if ( my @qt_defines = map { ($_=~m/^QT_(.*)/)[0] } keys %defines)
{
    my $regexp = "m/^#\\s*ifn?def\\s+QT_(?:" . join('|', map { "\$qt_defines[$_]" } 0..$#qt_defines).")/o";
    $match_qt_defines = eval "sub { my \$s=shift;
                                   \$s=~/^#\\s*if(n)?def/ || return 0;
                                   if(!\$1) { return \$s=~$regexp ? 0:1 }
                                   else { return \$s=~$regexp ? 1:0 }
                                  }";
    die if $@;
}
else
{
    $match_qt_defines = eval q
    sub
    {
        my $s = shift;
        $s =~ m/^\#\s*ifndef\s+QT_NO_(?:REMOTE| # not in the default compile options
                                        NIS|    #  ...
                                        XINERAMA|
                                        IMAGEIO_(?:MNG|JPEG)|
                                        STYLE_(?:MAC|INTERLACE|COMPACT)
                                     )/x;
    }
    ;
    die if $@;
}
# Check if there any files to process.
# We do it here to prevent the libraries being loaded up first.

checkFileArgs();

# work out libdir. This is created by kdocLib:writeDoc when
# required.
$libdir = $ENV{HOME}."/.kalyptus" unless $libdir ne "";


######
###### main program
######
	readLibraries();
	parseFiles();

	if ( $parseonly ) {
		print "\n\tParse Tree\n\t------------\n\n";
		kdocAstUtil::dumpAst( $rootNode );
	}
	else {
		writeDocumentation();
		writeLibrary() unless $libname eq "";
	}

	kdocAstUtil::printDebugStats() if $debug;

	exit 0;
######

sub checkFileArgs
{
	return unless $#ARGV < 0;

	die "$exe: no input files.\n" unless $readstdin;

	# read filenames from standard input
    	while (<STDIN>) {
		chop;
		$_ =~ s,\\,/,g;	# back to fwd slash (for Windows)
		foreach my $file ( split( /\s+/, $_ ) ) {
			push @ARGV, $file;
		}
	}
}

sub readLibraries
{
	return if $#libs < 0;

	require kdocLib;
	foreach my $lib ( @libs ) {
		print "$exe: reading lib: $lib\n" unless $quiet;

		my $relpath = exists $options{url} ? 
			$options{url} : $outputdir;
		kdocLib::readLibrary( \&getRoot, $lib, $libdir, $relpath );
	}
}

sub parseFiles
{
	foreach $currentfile ( @ARGV ) {
		my $lang = "CXX";

		if ( $currentfile =~ /\.idl\s*$/ ) {
			# IDL file
			$lang = "IDL";
		}

		# assume cxx file
		if( $cpp ) {
			# pass through preprocessor
			my $cmd = $cppcmd;
			foreach my $dir ( @includes ) {
				$cmd .= " -I $dir ";
			}

			$cmd .= " -DQOBJECTDEFS_H $currentfile";

			open( INPUT, "$cmd |" )
				|| croak "Can't preprocess $currentfile";
		}
		else {
			open( INPUT, "$currentfile" ) 
				|| croak "Can't read from $currentfile";
		}

		print STDERR "$exe: processing $currentfile\n" unless $quiet;

		# reset vars
		$rootNode = getRoot( $lang );


		# add to file lookup table
		my $showname = $striphpath ? basename( $currentfile )
						: $currentfile;
		$cSourceNode = Ast::New( $showname );
		$cSourceNode->AddProp( "NodeType", "source" );
		$cSourceNode->AddProp( "Path", $currentfile );
		$rootNode->AddPropList( "Sources", $cSourceNode );

		# reset state
		@classStack = ();
		$cNode = $rootNode;
		$inExtern = 0;

		# parse
		my $k = undef;
		while ( defined ($k = readDecl()) ) {
			print "\nDecl: <$k>[$declNodeType]\n" if $debug;
			if( identifyDecl( $k ) && $k =~ /{/ ) {
				readCxxCodeBlock();
			} 
		}
		close INPUT;
	}
}


sub writeDocumentation
{
	foreach my $node ( values %rootNodes ) {
		# postprocess
		kdocAstUtil::linkNamespaces( $node );
		kdocAstUtil::makeInherit( $node, $node );
		kdocAstUtil::linkReferences( $node, $node );
		kdocAstUtil::calcStats( \%stats, $node, $node );

		# write
		no strict "refs";
		foreach my $format ( @formats_wanted ) {
			my $pack = $formats{ $format };
			require $pack.".pm";

			print STDERR "Generating bindings for $format ",
				          "language...\n" unless $quiet;

			my $f = "$pack\::writeDoc";
			&$f( $libname, $node, $outputdir, \%options );
		}
	}
}

sub writeLibrary
{
	if( $libname ne "" and !exists $options{'no-cache'} ) {
		require kdocLib;
		foreach my $lang ( keys %rootNodes ) {
			my $node = $rootNodes{ $lang };
			kdocLib::writeDoc( $libname, $node, $lang, $libdir,
					$outputdir, $options{url},
					exists $options{compress} ? 1 : 0 );
		}
	}
}

###### Parser routines

=head2 readSourceLine

	Returns a raw line read from the current input file.
	This is used by routines outside main, since I don t know
	how to share fds.

=cut

sub readSourceLine
{
	return <INPUT>;
}

=head2 readCxxLine

	Reads a C++ source line, skipping comments, blank lines,
	preprocessor tokens and the Q_OBJECT macro

=cut

sub readCxxLine
{
	my( $p );
	my( $l );
	
	while( 1 ) {
		$p = shift @inputqueue || <INPUT>;
		return undef if !defined ($p);

		$p =~ s#//.*$##g;			# C++ comment
		$p =~ s#/\*(?!\*).*?\*/##g;		# C comment

		# join all multiline comments
		if( $p =~ m#/\*(?!\*)#s ) {
			# unterminated comment
LOOP:
			while( defined ($l = <INPUT>) ) {
				$l =~ s#//.*$##g;		# C++ comment
				$p .= $l;
				$p =~ s#/\*(?!\*).*?\*/##sg;	# C comment
				last LOOP unless $p =~ m#(/\*(?!\*))|(\*/)#sg;
			}
		}

		if ( $p =~ /^\s*Q_OBJECT/ ) {
			push @inputqueue, @codeqobject;
			next;
		}
		# Hack, waiting for real handling of preprocessor defines
		$p =~ s/QT_STATIC_CONST/static const/;
		$p =~ s/KSVG_GET/KJS::Value get();/;
		$p =~ s/KSVG_BASECLASS_GET/KJS::Value get();/;
		$p =~ s/KSVG_BRIDGE/KJS::ObjectImp *bridge();/;
		$p =~ s/KSVG_FORWARDGET/KJS::Value getforward();/;
		$p =~ s/KSVG_PUT/bool put();/;
		$p =~ s/KSVG_FORWARDPUT/bool putforward();/;
		$p =~ s/KSVG_BASECLASS/virtual KJS::Value cache();/;
		if ( $p =~ m/KSVG_DEFINE_PROTOTYPE\((\w+)\)/ ) {
			push @inputqueue, split('\n',"namespace KSVG {\nclass $1 {\n};\n};");
		}

		next if ( $p =~ /^\s*$/s ); 		# blank lines
#			|| $p =~ /^\s*Q_OBJECT/		# QObject macro
#			);
#

		next if ( $p =~ /^\s*Q_ENUMS/           # ignore Q_ENUMS
                        || $p =~ /^\s*Q_PROPERTY/       # and Q_PROPERTY
                        || $p =~ /^\s*Q_OVERRIDE/       # and Q_OVERRIDE
                        || $p =~ /^\s*Q_SETS/
                        || $p =~ /^\s*Q_DUMMY_COMPARISON_OPERATOR/
                        || $p =~ /^\s*K_SYCOCATYPE/     # and K_SYCOCA stuff
                        || $p =~ /^\s*K_SYCOCAFACTORY/  #
                        || $p =~ /^\s*KSVG_/            # and KSVG stuff ;)
			);

		push @includes_list, $1 if $p =~ /^#include\s+<?(.*?)>?\s*$/;

		# remove all preprocessor macros
		if( $p =~ /^\s*#\s*(\w+)/ ) {
			# Handling of preprocessed sources: skip anything included from
			# other files, unless --docincluded wasrenceaces", $node, \@interfaces, $startgrpsub,
			$methodsub, $endgrpsub);
		doGroup( "$uc_access Methods", $node, \@methods, $startgrpsub,
			$methodsub, $endgrpsub);
		doGroup( "$uc_access Slots", $node, \@slots, $startgrpsub,
			$methodsub, $endgrpsub);
		doGroup( "Signals", $node, \@signals, $startgrpsub,
			$methodsub, $endgrpsub);
		doGroup( "k_dcop", $node, \@k_dcops, $startgrpsub,
			$methodsub, $endgrpsub);
		doGroup( "k_dcop_signals", $node, \@k_dcop_signals, $startgrpsub,
			$methodsub, $endgrpsub);
		doGroup( "k_dcop_hiddens", $node, \@k_dcop_hiddens, $startgrpsub,
			$methodsub, $endgrpsub);
		doGroup( "$uc_access Static Methods", $node, \@static, 
			$startgrpsub, $methodsub, $endgrpsub);
		doGroup( "$uc_access Members", $node, \@data, $startgrpsub,
			$methodsub, $endgrpsub);
	}
}

sub doGroup
{
	my ( $name, $node, $list, $startgrpsub, $methodsub, $endgrpsub ) = @_;

        my ( $hasMembers ) = 0;
        foreach my $kid ( @$list ) {
                if ( !exists $kid->{DocNode}->{Reimplemented} ) {
                        $hasMembers = 1;
                        break;
                }
        }
	return if !$hasMembers;
	
	if ( defined $methodsub ) {
		foreach my $kid ( @$list ) {
                        if ( !exists $kid->{DocNode}->{Reimplemented} ) {
         		        $methodsub->( $node, $kid );
                        }
		}
	}

	$endgrpsub->( $name ) if defined $endgrpsub;
}

sub ByGroupLogical
{
	my ( $root, $startgrpsub, $itemsub, $endgrpsub ) = @_;

	return 0 unless defined $root->{Groups};

	foreach my $groupname ( sort keys %{$root->{Groups}} ) {
		next if $groupname eq "astNodeName"||$groupname eq "NodeType";

		my $group = $root->{Groups}->{ $group };
		next unless $group->{Kids};
		
		$startgrpsub->( $group->{astNodeName}, $group->{Desc} );

		foreach my $kid (sort {$a->{astNodeName} cmp $b->{astNodeName}}
					@group->{Kids} ) {
			$itemsub->( $root, $kid );
		}
		$endgrpsub->( $group->{Desc} );	
	}

	return 1;
}

sub SeeAlso
{
	my ( $node, $nonesub, $startsub, $printsub, $endsub ) = @_;

	if( !defined $node ) {
		$nonesub->();
		return;
	}

	my $doc = $node;

	if ( $node->{NodeType} ne "DocNode" ) {
		$doc = $node->{DocNode};
		if ( !defined $doc ) {
			$nonesub->() if defined $nonesub;
			return;
		}
	}

	if ( !defined $doc->{See} ) {
		$nonesub->() if defined $nonesub;
		return;
	}

	my $see = $doc->{See};
	my $ref = $doc->{SeeRef};

	if ( $#$see < 1 ) {
		$nonesub->() if defined $nonesub;
		return;
	}

	$startsub->( $node ) if defined $startsub;

	for my $i ( 0..$#$see ) {
		my $seelabel = $see->[ $i ];
		my $seenode = undef;
		if ( defined $ref ) {
			$seenode = $ref->[ $i ]; 
		}

		$printsub->( $seelabel, $seenode ) if defined $printsub;
	}

	$endsub->( $node ) if defined $endsub;

	return;
}

1;
                                                                                                                                                                                                                                                                                                                               ./usr/share/apps/dcopidlng/kalyptus                                                                 0000755 0000000 0000000 00000115256 07723655432 017623  0                                                                                                    ustar   root                            root                            0000000 0000000                                                                                                                                                                        #!/usr/bin/perl -I/Users/duke/src/kde/kdebindings/kalyptus

# KDOC -- C++ and CORBA IDL interface documentation tool.
# Sirtaj Singh Kang <taj@kde.org>, Jan 1999.
# $Id: kalyptus,v 1.1 2003/08/29 13:54:34 lypanov Exp $

# All files in this project are distributed under the GNU General
# Public License. This is Free Software.

require 5.000;

use Carp;
use Getopt::Long;
use File::Basename;
use strict;

use Ast;

use kdocUtil;
use kdocAstUtil;
use kdocParseDoc;

use vars qw/ %rootNodes $declNodeType @includes_list %options @formats_wanted $allow_k_dcop_accessors
        @includeclasses $includeclasses $skipInternal %defines $defines $match_qt_defines
	$libdir $libname $outputdir @libs $parse_global_space $striphpath $doPrivate $readstdin
	$Version $quiet $debug $debuggen $parseonly $currentfile $cSourceNode $exe
	%formats %flagnames @allowed_k_dcop_accesors $allowed_k_dcop_accesors_re $rootNode 
	@classStack $cNode $globalSpaceClassName
	$lastLine $docNode @includes $cpp $defcppcmd $cppcmd $docincluded
	$inExtern %stats %definitions @inputqueue @codeqobject /;
     
## globals

%rootNodes = ();			# root nodes for each file type
$declNodeType = undef;			# last declaration type

@includes_list = ();			# list of files included from the parsed .h

# All options

%options = ();				# hash of options (set getopt below)
@formats_wanted = ();
$libdir = $ENV{KDOCLIBS};
$libname = "";
$outputdir = ".";
@libs = ();				# list of includes
$striphpath = 0;

@includeclasses = ();                     # names of classes to include
$includeclasses = "";

$doPrivate = 0;
$Version = "0.9";

$quiet = 0;
$debug = 0;
$debuggen = 0;
$parseonly = 0;
$globalSpaceClassName = "QGlobalSpace";

$currentfile = "";

$cpp = 0;
$defcppcmd = "g++ -Wp,-C -E";
$cppcmd = "";

$exe = basename $0;

@inputqueue = ();
@codeqobject = split "\n", <<CODE;
public:
    virtual QMetaObject *metaObject() const;
    virtual const char *className() const;
    virtual void* qt_cast( const char* );
    virtual bool qt_invoke( int, QUObject* );
    virtual bool qt_emit( int, QUObject* );
    virtual bool qt_property( int, int, QVariant* );
    static QMetaObject* staticMetaObject();
    QObject* qObject();
    static QString tr( const char *, const char * = 0 );
    static QString trUtf8( const char *, const char * = 0 );
private:
CODE

# Supported formats
%formats = ( "java" => "kalyptusCxxToJava", "c" => "kalyptusCxxToC",
	"objc" => "kalyptusCxxToObjc", "dcopidl" => "kalyptusCxxToDcopIDL",
	"smoke" => "kalyptusCxxToSmoke", "csharp" => "kalyptusCxxToCSharp",
        "ECMA" => "kalyptusCxxToECMA", "swig" => "kalyptusCxxToSwig" );

# these are for expansion of method flags
%flagnames = ( v => 'virtual', 's' => 'static', p => 'pure',
	c => 'const', l => 'slot', i => 'inline', n => 'signal',
 	d => 'k_dcop', z => 'k_dcop_signals', y => 'k_dcop_hidden' );

@allowed_k_dcop_accesors = qw(k_dcop k_dcop_hidden k_dcop_signals);
$allowed_k_dcop_accesors_re = join("|", @allowed_k_dcop_accesors);
        
%definitions = {
    _STYLE_CDE => '',
    _STYLE_MOTIF => '',
    _STYLE_MOTIF_PLUS => '',
    PLUS => '',
    _STYLE_PLATINUM => '',
    _STYLE_SGI => '',
    _STYLE_WINDOWS => '',
    QT_STATIC_CONST => 'static const',
    Q_EXPORT => '',
    Q_REFCOUNT => '',
    QM_EXPORT_CANVAS => '',
    QM_EXPORT_DNS => '',
    QM_EXPORT_ICONVIEW => '',
    QM_EXPORT_NETWORK => '',
    QM_EXPORT_SQL => '',
    QM_EXPORT_WORKSPACE => '',
    QT_NO_REMOTE => 'QT_NO_REMOTE',
    QT_ACCESSIBILITY_SUPPORT => 'QT_ACCESSIBILITY_SUPPORT',
    Q_WS_X11 => 'Q_WS_X11',
    Q_DISABLE_COPY => 'Q_DISABLE_COPY',
    Q_WS_QWS => 'undef',
    Q_WS_MAC => 'undef',
    Q_OBJECT => <<'CODE',
public:
    virtual QMetaObject *metaObject() const;
    virtual const char *className() const;
    virtual bool qt_invoke( int, QUObject* );
    virtual bool qt_emit( int, QUObject* );
    static QString tr( const char *, const char * = 0 );
    static QString trUtf8( const char *, const char * = 0 );
private:
CODE
};

=head1 KDOC -- Source documentation tool

	Sirtaj Singh Kang <taj@kde.org>, Dec 1998.

=cut

# read options

Getopt::Long::config qw( no_ignore_case permute bundling auto_abbrev );

GetOptions( \%options,
	"format|f=s", \@formats_wanted,
	"url|u=s",
	"skip-internal", \$skipInternal,
	"skip-deprecated|e",
	"document-all|a",
	"compress|z",
        "no-cache",      # do not create $HOME/.kalyptus cache
	# HTML options
	"html-cols=i",
	"html-logo=s",

	"strip-h-path",	\$striphpath,
	"outputdir|d=s", \$outputdir,
	"stdin|i",	\$readstdin,
	"name|n=s",	\$libname,
	"help|h", 	\&show_usage,
	"version|v|V", 	\&show_version,
	"private|p",	\$doPrivate,
	"libdir|L=s",	\$libdir,
	"xref|l=s",	\@libs,
	"classes|c=s",    \@includeclasses,
	"globspace",	\$parse_global_space,
	"allow_k_dcop_accessors", \$allow_k_dcop_accessors,

	"cpp|P",	\$cpp,
	"docincluded",  \$docincluded,
	"cppcmd|C=s",	\$cppcmd,
	"includedir|I=s", \@includes,
	"define=s", \%defines, # define a single preprocessing symbol
	"defines=s", \$defines, # file containing preprocessing symbols, one per line

	"quiet|q",	\$quiet,
	"debug|D",	\$debug, # debug the parsing
	"debuggen",	\$debuggen, # debug the file generation
	"parse-only",	\$parseonly )
		|| exit 1;

$| = 1 if $debug or $debuggen;

# preprocessor settings

if ( $cppcmd eq "" ) {
	$cppcmd = $defcppcmd;
}
else {
	$cpp = 1;
}

if ($#includeclasses>=0)
{
    $includeclasses = join (" ", @includeclasses);
    print "Using Classes: $includeclasses\n" unless $quiet;
}

if ( $#includes >= 0 && !$cpp ) {
	die "$exe: --includedir requires --cpp\n";
}

# Check output formats. HTML is the default
if( $#formats_wanted < 0 ) {
	push @formats_wanted, "java";
}

foreach my $format ( @formats_wanted ) {
	die "$exe: unsupported format '$format'.\n"
		if !defined $formats{$format};
}

if( $defines )
{
    open( DEFS, $defines ) or die "Couldn't open $defines: $!\n";
    my @defs = <DEFS>;
    chomp @defs;
    close DEFS;
    foreach (@defs)
    {
        $defines{ $_ } = 1 unless exists $defines{ $_ };
    }
}

# Check the %defines hash for QT_* symbols and compile the corresponding RE
# Otherwise, compile the default ones. Used for filtering in readCxxLine.
if ( my @qt_defines = map { ($_=~m/^QT_(.*)/)[0] } keys %defines)
{
    my $regexp = "m/^#\\s*ifn?def\\s+QT_(?:" . join('|', map { "\$qt_defines[$_]" } 0..$#qt_defines).")/o";
    $match_qt_defines = eval "sub { my \$s=shift;
                                   \$s=~/^#\\s*if(n)?def/ || return 0;
                                   if(!\$1) { return \$s=~$regexp ? 0:1 }
                                   else { return \$s=~$regexp ? 1:0 }
                                  }";
    die if $@;
}
else
{
    $match_qt_defines = eval q
    sub
    {
        my $s = shift;
        $s =~ m/^\#\s*ifndef\s+QT_NO_(?:REMOTE| # not in the default compile options
                                        NIS|    #  ...
                                        XINERAMA|
                                        IMAGEIO_(?:MNG|JPEG)|
                                        STYLE_(?:MAC|INTERLACE|COMPACT)
                                     )/x;
    }
    ;
    die if $@;
}
# Check if there any files to process.
# We do it here to prevent the libraries being loaded up first.

checkFileArgs();

# work out libdir. This is created by kdocLib:writeDoc when
# required.
$libdir = $ENV{HOME}."/.kalyptus" unless $libdir ne "";


######
###### main program
######
	readLibraries();
	parseFiles();

	if ( $parseonly ) {
		print "\n\tParse Tree\n\t------------\n\n";
		kdocAstUtil::dumpAst( $rootNode );
	}
	else {
		writeDocumentation();
		writeLibrary() unless $libname eq "";
	}

	kdocAstUtil::printDebugStats() if $debug;

	exit 0;
######

sub checkFileArgs
{
	return unless $#ARGV < 0;

	die "$exe: no input files.\n" unless $readstdin;

	# read filenames from standard input
    	while (<STDIN>) {
		chop;
		$_ =~ s,\\,/,g;	# back to fwd slash (for Windows)
		foreach my $file ( split( /\s+/, $_ ) ) {
			push @ARGV, $file;
		}
	}
}

sub readLibraries
{
	return if $#libs < 0;

	require kdocLib;
	foreach my $lib ( @libs ) {
		print "$exe: reading lib: $lib\n" unless $quiet;

		my $relpath = exists $options{url} ? 
			$options{url} : $outputdir;
		kdocLib::readLibrary( \&getRoot, $lib, $libdir, $relpath );
	}
}

sub parseFiles
{
	foreach $currentfile ( @ARGV ) {
		my $lang = "CXX";

		if ( $currentfile =~ /\.idl\s*$/ ) {
			# IDL file
			$lang = "IDL";
		}

		# assume cxx file
		if( $cpp ) {
			# pass through preprocessor
			my $cmd = $cppcmd;
			foreach my $dir ( @includes ) {
				$cmd .= " -I $dir ";
			}

			$cmd .= " -DQOBJECTDEFS_H $currentfile";

			open( INPUT, "$cmd |" )
				|| croak "Can't preprocess $currentfile";
		}
		else {
			open( INPUT, "$currentfile" ) 
				|| croak "Can't read from $currentfile";
		}

		print STDERR "$exe: processing $currentfile\n" unless $quiet;

		# reset vars
		$rootNode = getRoot( $lang );


		# add to file lookup table
		my $showname = $striphpath ? basename( $currentfile )
						: $currentfile;
		$cSourceNode = Ast::New( $showname );
		$cSourceNode->AddProp( "NodeType", "source" );
		$cSourceNode->AddProp( "Path", $currentfile );
		$rootNode->AddPropList( "Sources", $cSourceNode );

		# reset state
		@classStack = ();
		$cNode = $rootNode;
		$inExtern = 0;

		# parse
		my $k = undef;
		while ( defined ($k = readDecl()) ) {
			print "\nDecl: <$k>[$declNodeType]\n" if $debug;
			if( identifyDecl( $k ) && $k =~ /{/ ) {
				readCxxCodeBlock();
			} 
		}
		close INPUT;
	}
}


sub writeDocumentation
{
	foreach my $node ( values %rootNodes ) {
		# postprocess
		kdocAstUtil::linkNamespaces( $node );
		kdocAstUtil::makeInherit( $node, $node );
		kdocAstUtil::linkReferences( $node, $node );
		kdocAstUtil::calcStats( \%stats, $node, $node );

		# write
		no strict "refs";
		foreach my $format ( @formats_wanted ) {
			my $pack = $formats{ $format };
			require $pack.".pm";

			print STDERR "Generating bindings for $format ",
				          "language...\n" unless $quiet;

			my $f = "$pack\::writeDoc";
			&$f( $libname, $node, $outputdir, \%options );
		}
	}
}

sub writeLibrary
{
	if( $libname ne "" and !exists $options{'no-cache'} ) {
		require kdocLib;
		foreach my $lang ( keys %rootNodes ) {
			my $node = $rootNodes{ $lang };
			kdocLib::writeDoc( $libname, $node, $lang, $libdir,
					$outputdir, $options{url},
					exists $options{compress} ? 1 : 0 );
		}
	}
}

###### Parser routines

=head2 readSourceLine

	Returns a raw line read from the current input file.
	This is used by routines outside main, since I don t know
	how to share fds.

=cut

sub readSourceLine
{
	return <INPUT>;
}

=head2 readCxxLine

	Reads a C++ source line, skipping comments, blank lines,
	preprocessor tokens and the Q_OBJECT macro

=cut

sub readCxxLine
{
	my( $p );
	my( $l );
	
	while( 1 ) {
		$p = shift @inputqueue || <INPUT>;
		return undef if !defined ($p);

		$p =~ s#//.*$##g;			# C++ comment
		$p =~ s#/\*(?!\*).*?\*/##g;		# C comment

		# join all multiline comments
		if( $p =~ m#/\*(?!\*)#s ) {
			# unterminated comment
LOOP:
			while( defined ($l = <INPUT>) ) {
				$l =~ s#//.*$##g;		# C++ comment
				$p .= $l;
				$p =~ s#/\*(?!\*).*?\*/##sg;	# C comment
				last LOOP unless $p =~ m#(/\*(?!\*))|(\*/)#sg;
			}
		}

		if ( $p =~ /^\s*Q_OBJECT/ ) {
			push @inputqueue, @codeqobject;
			next;
		}
		# Hack, waiting for real handling of preprocessor defines
		$p =~ s/QT_STATIC_CONST/static const/;
		$p =~ s/KSVG_GET/KJS::Value get();/;
		$p =~ s/KSVG_BASECLASS_GET/KJS::Value get();/;
		$p =~ s/KSVG_BRIDGE/KJS::ObjectImp *bridge();/;
		$p =~ s/KSVG_FORWARDGET/KJS::Value getforward();/;
		$p =~ s/KSVG_PUT/bool put();/;
		$p =~ s/KSVG_FORWARDPUT/bool putforward();/;
		$p =~ s/KSVG_BASECLASS/virtual KJS::Value cache();/;
		if ( $p =~ m/KSVG_DEFINE_PROTOTYPE\((\w+)\)/ ) {
			push @inputqueue, split('\n',"namespace KSVG {\nclass $1 {\n};\n};");
		}

		next if ( $p =~ /^\s*$/s ); 		# blank lines
#			|| $p =~ /^\s*Q_OBJECT/		# QObject macro
#			);
#

		next if ( $p =~ /^\s*Q_ENUMS/           # ignore Q_ENUMS
                        || $p =~ /^\s*Q_PROPERTY/       # and Q_PROPERTY
                        || $p =~ /^\s*Q_OVERRIDE/       # and Q_OVERRIDE
                        || $p =~ /^\s*Q_SETS/
                        || $p =~ /^\s*Q_DUMMY_COMPARISON_OPERATOR/
                        || $p =~ /^\s*K_SYCOCATYPE/     # and K_SYCOCA stuff
                        || $p =~ /^\s*K_SYCOCAFACTORY/  #
                        || $p =~ /^\s*KSVG_/            # and KSVG stuff ;)
			);

		push @includes_list, $1 if $p =~ /^#include\s+<?(.*?)>?\s*$/;

		# remove all preprocessor macros
		if( $p =~ /^\s*#\s*(\w+)/ ) {
			# Handling of preprocessed sources: skip anything included from
			# other files, unless --docincluded wasrenceaces", $node, \@interfaces, $startgrpsub,
			$methodsub, $endgrpsub);
		doGroup( "$uc_access Methods", $node, \@methods, $startgrpsub,
			$methodsub, $endgrpsub);
		doGroup( "$uc_access Slots", $node, \@slots, $startgrpsub,
			$methodsub, $endgrpsub);
		doGroup( "Signals", $node, \@signals, $startgrpsub,
			$methodsub, $endgrpsub);
		doGroup( "k_dcop", $node, \@k_dcops, $startgrpsub,
			$methodsub, $endgrpsub);
		doGroup( "k_dcop_signals", $node, \@k_dcop_signals, $startgrpsub,
			$methodsub, $endgrpsub);
		doGroup( "k_dcop_hiddens", $node, \@k_dcop_hiddens, $startgrpsub,
			$methodsub, $endgrpsub);
		doGroup( "$uc_access Static Methods", $node, \@static, 
			$startgrpsub, $methodsub, $endgrpsub);
		doGroup( "$uc_access Members", $node, \@data, $startgrpsub,
			$methodsub, $endgrpsub);
	}
}

sub doGroup
{
	my ( $name, $node, $list, $startgrpsub, $methodsub, $endgrpsub ) = @_;

        my ( $hasMembers ) = 0;
        foreach my $kid ( @$list ) {
                if ( !exists $kid->{DocNode}->{Reimplemented} ) {
                        $hasMembers = 1;
                        break;
                }
        }
	return if !$hasMembers;
	
	if ( defined $methodsub ) {
		foreach my $kid ( @$list ) {
                        if ( !exists $kid->{DocNode}->{Reimplemented} ) {
         		        $methodsub->( $node, $kid );
                        }
		}
	}

	$endgrpsub->( $name ) if defined $endgrpsub;
}

sub ByGroupLogical
{
	my ( $root, $startgrpsub, $itemsub, $endgrpsub ) = @_;

	return 0 unless defined $root->{Groups};

	foreach my $groupname ( sort keys %{$root->{Groups}} ) {
		next if $groupname eq "astNodeName"||$groupname eq "NodeType";

		my $group = $root->{Groups}->{ $group };
		next unless $group->{Kids};
		
		$startgrpsub->( $group->{astNodeName}, $group->{Desc} );

		foreach my $kid (sort {$a->{astNodeName} cmp $b->{astNodeName}}
					@group->{Kids} ) {
			$itemsub->( $root, $kid );
		}
		$endgrpsub->( $group->{Desc} );	
	}

	return 1;
}

sub SeeAlso
{
	my ( $node, $nonesub, $startsub, $printsub, $endsub ) = @_;

	if( !defined $node ) {
		$nonesub->();
		return;
	}

	my $doc = $node;

	if ( $node->{NodeType} ne "DocNode" ) {
		$doc = $node->{DocNode};
		if ( !defined $doc ) {
			$nonesub->() if defined $nonesub;
			return;
		}
	}

	if ( !defined $doc->{See} ) {
		$nonesub->() if defined $nonesub;
		return;
	}

	my $see = $doc->{See};
	my $ref = $doc->{SeeRef};

	if ( $#$see < 1 ) {
		$nonesub->() if defined $nonesub;
		return;
	}

	$startsub->( $node ) if defined $startsub;

	for my $i ( 0..$#$see ) {
		my $seelabel = $see->[ $i ];
		my $seenode = undef;
		if ( defined $ref ) {
			$seenode = $ref->[ $i ]; 
		}

		$printsub->( $seelabel, $seenode ) if defined $printsub;
	}

	$endsub->( $node ) if defined $endsub;

	return;
}

1;
                                                                                                                                                                                                                                                                                                                               ./usr/share/apps/dcopidlng/kalyptus                                                                 0000755 0000000 0000000 00000115256 07723655432 017623  0                                                                                                    ustar   root                            root                            0000000 0000000                                                                                                                                                                        #!/usr/bin/perl -I/Users/duke/src/kde/kdebindings/kalyptus

# KDOC -- C++ and CORBA IDL interface documentation tool.
# Sirtaj Singh Kang <taj@kde.org>, Jan 1999.
# $Id: kalyptus,v 1.1 2003/08/29 13:54:34 lypanov Exp $

# All files in this project are distributed under the GNU General
# Public License. This is Free Software.

require 5.000;

use Carp;
use Getopt::Long;
use File::Basename;
use strict;

use Ast;

use kdocUtil;
use kdocAstUtil;
use kdocParseDoc;

use vars qw/ %rootNodes $declNodeType @includes_list %options @formats_wanted $allow_k_dcop_accessors
        @includeclasses $includeclasses $skipInternal %defines $defines $match_qt_defines
	$libdir $libname $outputdir @libs $parse_global_space $striphpath $doPrivate $readstdin
	$Version $quiet $debug $debuggen $parseonly $currentfile $cSourceNode $exe
	%formats %flagnames @allowed_k_dcop_accesors $allowed_k_dcop_accesors_re $rootNode 
	@classStack $cNode $globalSpaceClassName
	$lastLine $docNode @includes $cpp $defcppcmd $cppcmd $docincluded
	$inExtern %stats %definitions @inputqueue @codeqobject /;
     
## globals

%rootNodes = ();			# root nodes for each file type
$declNodeType = undef;			# last declaration type

@includes_list = ();			# list of files included from the parsed .h

# All options

%options = ();				# hash of options (set getopt below)
@formats_wanted = ();
$libdir = $ENV{KDOCLIBS};
$libname = "";
$outputdir = ".";
@libs = ();				# list of includes
$striphpath = 0;

@includeclasses = ();                     # names of classes to include
$includeclasses = "";

$doPrivate = 0;
$Version = "0.9";

$quiet = 0;
$debug = 0;
$debuggen = 0;
$parseonly = 0;
$globalSpaceClassName = "QGlobalSpace";

$currentfile = "";

$cpp = 0;
$defcppcmd = "g++ -Wp,-C -E";
$cppcmd = "";

$exe = basename $0;

@inputqueue = ();
@codeqobject = split "\n", <<CODE;
public:
    virtual QMetaObject *metaObject() const;
    virtual const char *className() const;
    virtual void* qt_cast( const char* );
    virtual bool qt_invoke( int, QUObject* );
    virtual bool qt_emit( int, QUObject* );
    virtual bool qt_property( int, int, QVariant* );
    static QMetaObject* staticMetaObject();
    QObject* qObject();
    static QString tr( const char *, const char * = 0 );
    static QString trUtf8( const char *, const char * = 0 );
private:
CODE

# Supported formats
%formats = ( "java" => "kalyptusCxxToJava", "c" => "kalyptusCxxToC",
	"objc" => "kalyptusCxxToObjc", "dcopidl" => "kalyptusCxxToDcopIDL",
	"smoke" => "kalyptusCxxToSmoke", "csharp" => "kalyptusCxxToCSharp",
        "ECMA" => "kalyptusCxxToECMA", "swig" => "kalyptusCxxToSwig" );

# these are for expansion of method flags
%flagnames = ( v => 'virtual', 's' => 'static', p => 'pure',
	c => 'const', l => 'slot', i => 'inline', n => 'signal',
 	d => 'k_dcop', z => 'k_dcop_signals', y => 'k_dcop_hidden' );

@allowed_k_dcop_accesors = qw(k_dcop k_dcop_hidden k_dcop_signals);
$allowed_k_dcop_accesors_re = join("|", @allowed_k_dcop_accesors);
        
%definitions = {
    _STYLE_CDE => '',
    _STYLE_MOTIF => '',
    _STYLE_MOTIF_PLUS => '',
    PLUS => '',
    _STYLE_PLATINUM => '',
    _STYLE_SGI => '',
    _STYLE_WINDOWS => '',
    QT_STATIC_CONST => 'static const',
    Q_EXPORT => '',
    Q_REFCOUNT => '',
    QM_EXPORT_CANVAS => '',
    QM_EXPORT_DNS => '',
    QM_EXPORT_ICONVIEW => '',
    QM_EXPORT_NETWORK => '',
    QM_EXPORT_SQL => '',
    QM_EXPORT_WORKSPACE => '',
    QT_NO_REMOTE => 'QT_NO_REMOTE',
    QT_ACCESSIBILITY_SUPPORT => 'QT_ACCESSIBILITY_SUPPORT',
    Q_WS_X11 => 'Q_WS_X11',
    Q_DISABLE_COPY => 'Q_DISABLE_COPY',
    Q_WS_QWS => 'undef',
    Q_WS_MAC => 'undef',
    Q_OBJECT => <<'CODE',
public:
    virtual QMetaObject *metaObject() const;
    virtual const char *className() const;
    virtual bool qt_invoke( int, QUObject* );
    virtual bool qt_emit( int, QUObject* );
    static QString tr( const char *, const char * = 0 );
    static QString trUtf8( const char *, const char * = 0 );
private:
CODE
};

=head1 KDOC -- Source documentation tool

	Sirtaj Singh Kang <taj@kde.org>, Dec 1998.

=cut

# read options

Getopt::Long::config qw( no_ignore_case permute bundling auto_abbrev );

GetOptions( \%options,
	"format|f=s", \@formats_wanted,
	"url|u=s",
	"skip-internal", \$skipInternal,
	"skip-deprecated|e",
	"document-all|a",
	"compress|z",
        "no-cache",      # do not create $HOME/.kalyptus cache
	# HTML options
	"html-cols=i",
	"html-logo=s",

	"strip-h-path",	\$striphpath,
	"outputdir|d=s", \$outputdir,
	"stdin|i",	\$readstdin,
	"name|n=s",	\$libname,
	"help|h", 	\&show_usage,
	"version|v|V", 	\&show_version,
	"private|p",	\$doPrivate,
	"libdir|L=s",	\$libdir,
	"xref|l=s",	\@libs,
	"classes|c=s",    \@includeclasses,
	"globspace",	\$parse_global_space,
	"allow_k_dcop_accessors", \$allow_k_dcop_accessors,

	"cpp|P",	\$cpp,
	"docincluded",  \$docincluded,
	"cppcmd|C=s",	\$cppcmd,
	"includedir|I=s", \@includes,
	"define=s", \%defines, # define a single preprocessing symbol
	"defines=s", \$defines, # file containing preprocessing symbols, one per line

	"quiet|q",	\$quiet,
	"debug|D",	\$debug, # debug the parsing
	"debuggen",	\$debuggen, # debug the file generation
	"parse-only",	\$parseonly )
		|| exit 1;

$| = 1 if $debug or $debuggen;

# preprocessor settings

if ( $cppcmd eq "" ) {
	$cppcmd = $defcppcmd;
}
else {
	$cpp = 1;
}

if ($#includeclasses>=0)
{
    $includeclasses = join (" ", @includeclasses);
    print "Using Classes: $includeclasses\n" unless $quiet;
}

if ( $#includes >= 0 && !$cpp ) {
	die "$exe: --includedir requires --cpp\n";
}

# Check output formats. HTML is the default
if( $#formats_wanted < 0 ) {
	push @formats_wanted, "java";
}

foreach my $format ( @formats_wanted ) {
	die "$exe: unsupported format '$format'.\n"
		if !defined $formats{$format};
}

if( $defines )
{
    open( DEFS, $defines ) or die "Couldn't open $defines: $!\n";
    my @defs = <DEFS>;
    chomp @defs;
    close DEFS;
    foreach (@defs)
    {
        $defines{ $_ } = 1 unless exists $defines{ $_ };
    }
}

# Check the %defines hash for QT_* symbols and compile the corresponding RE
# Otherwise, compile the default ones. Used for filtering in readCxxLine.
if ( my @qt_defines = map { ($_=~m/^QT_(.*)/)[0] } keys %defines)
{
    my $regexp = "m/^#\\s*ifn?def\\s+QT_(?:" . join('|', map { "\$qt_defines[$_]" } 0..$#qt_defines).")/o";
    $match_qt_defines = eval "sub { my \$s=shift;
                                   \$s=~/^#\\s*if(n)?def/ || return 0;
                                   if(!\$1) { return \$s=~$regexp ? 0:1 }
                                   else { return \$s=~$regexp ? 1:0 }
                                  }";
    die if $@;
}
else
{
    $match_qt_defines = eval q
    sub
    {
        my $s = shift;
        $s =~ m/^\#\s*ifndef\s+QT_NO_(?:REMOTE| # not in the default compile options