eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
    & eval 'exec perl -S $0 $argv:q'
    if 0;

# -*- perl -*-
#

require POSIX;
require File::Path;

use Cwd;
use File::Spec;
use File::Temp qw/ tempfile tempdir /;
use Env qw(ACE_ROOT TAO_ROOT CIAO_ROOT DDS_ROOT);

# Configuration and default values

if (!defined $TAO_ROOT) {
    $TAO_ROOT = "$ACE_ROOT/TAO";
}
if (!defined $CIAO_ROOT) {
    $CIAO_ROOT = "$TAO_ROOT/CIAO";
}
if (!defined $DANCE_ROOT) {
    $DANCE_ROOT = "$TAO_ROOT/DAnCE";
}

$is_release = 0;
$exclude_ace = 0;
$exclude_tao = !-r "$TAO_ROOT/VERSION";
$exclude_ciao = !-r "$CIAO_ROOT/VERSION";
$exclude_dance = !-r "$DANCE_ROOT/VERSION";
$verbose = 0;
$perl_path = '/usr/bin/perl';
$html_output_dir = '.';
$footer = '';

$dds = 0;
if (defined $DDS_ROOT && -r "$DDS_ROOT/VERSION") {
    $dds_path = Cwd::abs_path($DDS_ROOT);
    $cwd_path = Cwd::abs_path(getcwd());
    if ($dds_path eq $cwd_path) {
        $dds = $exclude_ace = $exclude_tao = $exclude_ciao = 1;
    }
}

@ACE_DOCS = ('ace',
             'ace_rmcast',
             'ace_ssl',
             'ace_qos',
             'ace_inet',
             'acexml');
@TAO_DOCS = ('tao'
             ,'tao_anytypecode'
             ,'tao_portableserver'
             ,'tao_pi'
             ,'tao_pi_server'
             ,'tao_rtportableserver'
             ,'tao_compression'
             ,'tao_transportcurrent'
             ,'tao_rtcorba'
             ,'tao_dynamicany'
             ,'tao_dynamicinterface'
             ,'tao_iormanip'
             ,'tao_iortable'
             ,'tao_ziop'
             ,'tao_esf'
             ,'tao_rtevent'
             ,'tao_cosevent'
             ,'tao_cosnotification'
             ,'tao_implrepo'
             ,'tao_strategies'
             ,'tao_smartproxies'
             ,'tao_av'
             ,'tao_security'
             ,'tao_ssliop'
             ,'tao_cosnaming'
             ,'tao_costime'
             ,'tao_costrader'
             ,'tao_portablegroup'
             ,'tao_ifr');
@CIAO_DOCS = ('ciao_dds4ccm'
             ,'ciao');
@DANCE_DOCS = ('DAnCE');
@DDS_DOCS = ('dds');

# Modify defaults using the command line arguments
&parse_args ();

$wrote_configh = 0;
if (!-r "$ACE_ROOT/ace/config.h") {
    open(CONFIG_H, ">$ACE_ROOT/ace/config.h")
        || die "Cannot create config file\n";
    print CONFIG_H "#include \"ace/config-doxygen.h\"\n";
    close(CONFIG_H);
    $wrote_configh = 1;
}

&generate_doxy_files ('ACE',  " $ACE_ROOT", " $ACE_ROOT/VERSION", @ACE_DOCS) if (!$exclude_ace);
&generate_doxy_files ('TAO',  " $TAO_ROOT", " $TAO_ROOT/VERSION", @TAO_DOCS) if (!$exclude_tao);
&generate_doxy_files ('CIAO', " $CIAO_ROOT", " $CIAO_ROOT/VERSION", @CIAO_DOCS) if (!$exclude_ciao);
&generate_doxy_files ('DANCE'," $DANCE_ROOT", " $DANCE_ROOT/VERSION", @DANCE_DOCS) if (!$exclude_dance);
&generate_doxy_files ('DDS',   "$DDS_ROOT", " $DDS_ROOT/VERSION", @DDS_DOCS) if $dds;

unlink "$ACE_ROOT/ace/config.h" if $wrote_configh;

exit 0;

sub parse_args {
  my @ARGS = ();
  while ($#ARGV >= 0) {
    if (!($ARGV[0] =~ m/^-/)) {
      push @ARGS, $ARGV[0];
    } elsif ($ARGV[0] eq "-is_release") {
      $is_release = 1;
    } elsif ($ARGV[0] eq "-exclude_ace") {
      $exclude_ace = 1;
    } elsif ($ARGV[0] eq "-exclude_tao") {
      $exclude_tao = 1;
    } elsif ($ARGV[0] eq "-exclude_ciao") {
      $exclude_ciao = 1;
    } elsif ($ARGV[0] eq "-exclude_dance") {
      $exclude_dance = 1;
    } elsif ($ARGV[0] eq "-include_dds") {
      $dds = 1;
    } elsif ($ARGV[0] eq "-verbose") {
      $verbose = 1;
    } elsif ($ARGV[0] eq "-perl_path" && $#ARGV >= 1) {
      $perl_path = $ARGV[1];
      shift;
    } elsif ($ARGV[0] eq "-footer" && $#ARGV >= 1) {
      $footer = $ARGV[1];
      shift;
    } elsif ($ARGV[0] eq "-html_output" && $#ARGV >= 1) {
      $html_output_dir = $ARGV[1];
      shift;
    } else {
      print "Ignoring option $ARGV[0]\n";
    }
    shift @ARGV;
  }
  @ARGV = @ARGS;
}

#is $arg1 the same path as "$arg2/$arg3"?
sub same_dir {
  my $lhs = shift;
  my $rhs_base = shift;
  my $rhs_dir = shift;
  my $rhs = File::Spec->catdir($rhs_base, $rhs_dir);
  return File::Spec->canonpath($lhs) eq File::Spec->canonpath($rhs);
}

sub generate_doxy_files {

  my $KIT = shift;
  my $ROOT_DIR = shift;
  my $VERSION_FILE= shift;
  my @DOCS = @_;

  my $VERSION = 'Snapshot ('.
    POSIX::strftime("%Y/%m/%d-%H:%M", localtime)
      .')';

  my $KIT_path = ($KIT eq 'CIAO') ? 'TAO/CIAO' : $KIT;
  my $translate_paths =
    ($KIT eq 'TAO' && !same_dir($TAO_ROOT, $ACE_ROOT, 'TAO')) ||
    ($KIT eq 'CIAO' && !same_dir($CIAO_ROOT, $TAO_ROOT, 'CIAO'));

  foreach my $i (@DOCS) {
    if ($is_release) {
      my ($major, $minor, $beta) = &get_versions ($KIT, $VERSION_FILE);
      $VERSION = $major.'.'.$minor.'.'.$beta;
    }

    my $input = "$ROOT_DIR/etc/".$i.".doxygen";
    ($fh, $output) = tempfile(TEMPLATE => 'XXXXXXXX', SUFFIX => '.doxygen', TMPDIR => 1, DESTROY => 1);

    open(DOXYINPUT, $input)
      || die "Cannot open doxygen input file $input\n";
    open(DOXYOUTPUT, ">$output")
      || die "Cannot open doxygen output file $output\n";

    my $generate_man  = 0;
    my $generate_html = 0;
    my @output_dirs = ();
    while (<DOXYINPUT>) {
      chomp;
      if (/^PROJECT_NUMBER/) {
        print DOXYOUTPUT "PROJECT_NUMBER        = ", $VERSION, "\n";
        next;
      } elsif (/^PERL_PATH /) {
	print DOXYOUTPUT "PERL_PATH = $perl_path\n";
	next;
      } elsif (/^QUIET / && $verbose) {
	print DOXYOUTPUT "QUIET = NO\n";
	next;
      } elsif (/^INLINE_SOURCES/ && $is_release) {
	print DOXYOUTPUT "INLINE_SOURCES = NO\n";
	next;
      } elsif (/^SOURCE_BROWSER/ && $is_release) {
	print DOXYOUTPUT "SOURCE_BROWSER = NO\n";
	next;
      } elsif (/^VERBATIM_HEADERS/ && $is_release) {
	print DOXYOUTPUT "VERBATIM_HEADERS = NO\n";
	next;
      } elsif (/^GENERATE_MAN/ && /= YES/) {
        $generate_man = 1;
      } elsif (/^GENERATE_HTML/ && /= YES/) {
        $generate_html = 1;
      } elsif ($generate_html && /^HTML_OUTPUT/) {
        my @field = split(' = ');
        if ($#field >= 1) {
          my $html_out_dir = "$html_output_dir/$field[1]";
          push @output_dirs, $html_out_dir;
	  print DOXYOUTPUT "HTML_OUTPUT = $html_out_dir\n";
	  next;
        }
      } elsif ($generate_html && /^GENERATE_TAGFILE/) {
        my @field = split(' = ');
        if ($#field >= 1) {
          my $html_out_dir = "$html_output_dir/$field[1]";
	  print DOXYOUTPUT "GENERATE_TAGFILE = $html_out_dir\n";
	  next;
        }
      } elsif ($generate_html && /^TAGFILES\s*=\s*(.*)$/) {
        my $value = $1;
        while ($value =~ /\\$/) {
          chop $value; #removes trailing \
          my $line = <DOXYINPUT>;
          chomp $line;
          $value .= ' ' . $line;
	}
	my @values = split(' ', $value);
  print DOXYOUTPUT "HTML_FOOTER = $footer\n";
	map {$_ = $html_output_dir . '/' . $_; } @values;
	print DOXYOUTPUT 'TAGFILES = ' . join(' ', @values) . "\n";
	next;
      } elsif ($generate_man && /^MAN_OUTPUT/) {
        my @field = split(' = ');
        if ($#field >= 1) {
          push @output_dirs, $field[1];
        }
      } elsif ($translate_paths && /^(INPUT|INCLUDE_PATH)\s*=\s*(.*)$/) {
	my $keyword = $1;
        my $value = $2;
        while ($value =~ /\\$/) {
          chop $value; #removes trailing \
          my $line = <DOXYINPUT>;
          chomp $line;
          $value .= ' ' . $line;
        }
        $value =~ s/$KIT_path/${"${KIT}_ROOT"}/g;
        print DOXYOUTPUT "$keyword = $value\n";
        next;
      }

      print DOXYOUTPUT $_, "\n";
    }
    close (DOXYOUTPUT);
    close (DOXYINPUT);

    foreach my $i (@output_dirs) {
      File::Path::mkpath($i, 0, 0755);
    }

    &run_doxy ($output);

    unlink $output;
  }

  if ($generate_man) {
    open(FIND, "find man -type f -print |") or die "Can't run find\n";
    while (<FIND>) {
      chomp;
      my $name_with_whitespace = $_;
      next unless ($name_with_whitespace =~ /\s/);
      my $name_without_whitespace = $name_with_whitespace;
      $name_without_whitespace =~ s/\s+//g;
      rename $name_with_whitespace, $name_without_whitespace;
    }
    close FIND;
  }
}

sub run_doxy {
  my $config = shift;
  open(DOX,"doxygen $config 2>&1 |")
    || die "cannot start ACE doxygen process\n";
  while (<DOX>) {
    print $_;
  }
  close (DOX)
    || die "error while running doxygen on $config\n";
}

########
######## Retrieve version information from VERSION file(s).
########
sub get_versions () {
  my $KIT = shift;
  my $VERSION_FILE = shift;
  my ($major_version, $minor_version, $beta_version);

  open (VERSION, '<'.$VERSION_FILE)  ||
    die "$0: unable to open $VERSION_FILE\n";
  while (<VERSION>) {
    chomp;
    if (/$KIT version (\d+)\.(\d+)\.(\d+)/) {
      $major_version = $1;
      $minor_version = $2;
      $beta_version = $3;
      last;
    } elsif (/$KIT version (\d+)\.(\d+)[^\.]/) {
      #### Previous release was a minor.
      $major_version = $1;
      $minor_version = $2;
      $beta_version  = '0';
      last;
    } elsif (/$KIT version (\d+)[^\.]/) {
      #### Previous release was a major.
      $major_version = $1;
      $minor_version = '0';
      $beta_version  = '0';
      last;
    }
  }
  close VERSION;

  return ($major_version, $minor_version, $beta_version);
}


#! /usr/bin/perl
eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
    & eval 'exec perl -S $0 $argv:q'
    if 0;

# -*- perl -*-
# Replacement for the old trusty GenExportH.bat
# Creates the nice little *_export file which is used for
# importing and exporting of symbols in DLLs.
# (they are soooo cute!)

use Getopt::Std;

##############################################################################
# Grab the options

$flags = join (" ", @ARGV);

if (!getopts ('df:hsn') || $opt_h) {
    print STDERR
          "generate_export_file.pl [-d] [-f dependency] [-n] library_name\n",
          "\n",
          "    -d         Turn on debug mode\n",
          "    -f         Adds a dependency to another *_HAS_DLL macro\n",
          "    -n         Do not add in ACE_AS_STATIC_LIBS check\n",
          "\n",
          "generate_export_file creates the *_export files that are used\n",
          "in exporting of symbols for DLLs (and not exporting them when\n",
          "the library is static).  If library_name is something like\n",
          "\"Foo\", then the file will contain definitions for Foo_Export\n",
          "and FOO_SINGLETON_DECLARE, etc. which will be controlled by\n",
          "FOO_HAS_DLL, etc.\n";
    exit (1);
}

if (defined $opt_d) {
    print STDERR "Debugging Turned on\n";

    if (defined $opt_f) {
        print STDERR "Dependency to $opt_f\n";
    }

    if (defined $opt_n) {
        print STDERR "ACE_AS_STATIC_LIBS turned off\n";
    }
}

if ($#ARGV < 0) {
    print STDERR "No library_name specified, use -h for help\n";
    exit (1);
}

$name = shift @ARGV;
$ucname = uc $name;

##############################################################################
# Prologue

$prologue = '
// -*- C++ -*-
// Definition for Win32 Export directives.
// This file is generated automatically by generate_export_file.pl '."$flags".'
// ------------------------------'."
#ifndef -UC-_EXPORT_H
#define -UC-_EXPORT_H

#include \"ace/config-all.h\"
";

##############################################################################
# Static Stuff

if (!defined $opt_n)
{
    $static_stuff = "
#if defined (ACE_AS_STATIC_LIBS) && !defined (-UC-_HAS_DLL)
#  define -UC-_HAS_DLL 0
#endif /* ACE_AS_STATIC_LIBS && -UC-_HAS_DLL */
";
}

##############################################################################
# Dependencies

if (defined $opt_f)
{
    $has_dll = "
#if defined ($opt_f)
#  if !defined (-UC-_HAS_DLL)
#    define -UC-_HAS_DLL 0
#  endif /* ! -UC-_HAS_DLL */
#else
#  if !defined (-UC-_HAS_DLL)
#    define -UC-_HAS_DLL 1
#  endif /* ! -UC-_HAS_DLL */
#endif
";
}
else
{
    $has_dll = "
#if !defined (-UC-_HAS_DLL)
#  define -UC-_HAS_DLL 1
#endif /* ! -UC-_HAS_DLL */
";
}

##############################################################################
# Epilogue

$epilogue = "
#if defined (-UC-_HAS_DLL) && (-UC-_HAS_DLL == 1)
#  if defined (-UC-_BUILD_DLL)
#    define -NC-_Export ACE_Proper_Export_Flag
#    define -UC-_SINGLETON_DECLARATION(T) ACE_EXPORT_SINGLETON_DECLARATION (T)
#    define -UC-_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_EXPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK)
#  else /* -UC-_BUILD_DLL */
#    define -NC-_Export ACE_Proper_Import_Flag
#    define -UC-_SINGLETON_DECLARATION(T) ACE_IMPORT_SINGLETON_DECLARATION (T)
#    define -UC-_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_IMPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK)
#  endif /* -UC-_BUILD_DLL */
#else /* -UC-_HAS_DLL == 1 */
#  define -NC-_Export
#  define -UC-_SINGLETON_DECLARATION(T)
#  define -UC-_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK)
#endif /* -UC-_HAS_DLL == 1 */

// Set -UC-_NTRACE = 0 to turn on library specific tracing even if
// tracing is turned off for ACE.
#if !defined (-UC-_NTRACE)
#  if (ACE_NTRACE == 1)
#    define -UC-_NTRACE 1
#  else /* (ACE_NTRACE == 1) */
#    define -UC-_NTRACE 0
#  endif /* (ACE_NTRACE == 1) */
#endif /* !-UC-_NTRACE */

#if (-UC-_NTRACE == 1)
#  define -UC-_TRACE(X)
#else /* (-UC-_NTRACE == 1) */
#  if !defined (ACE_HAS_TRACE)
#    define ACE_HAS_TRACE
#  endif /* ACE_HAS_TRACE */
#  define -UC-_TRACE(X) ACE_TRACE_IMPL(X)
#  include \"ace/Trace.h\"
#endif /* (-UC-_NTRACE == 1) */

#endif /* -UC-_EXPORT_H */

// End of auto generated file.
";

##############################################################################
# Print the stuff out

foreach $export ($prologue, $static_stuff, $has_dll, $epilogue)
{
## -NC- stands for normal case, the name as it is
## -UC- stands for the name all upper case
    map { s/-NC-/$name/g; s/-UC-/$ucname/g; } $export;

    print $export;
};


eval '(exit $?0)' && eval 'exec perl -i -S $0 ${1+"$@"}'
    & eval 'exec perl -i -S $0 $argv:q'
    if 0;

# This perl script re-arrange the macro indentation so it's easier to
# see the layering relationship.

$lineno = 0;
$indent = 0;

sub inc_indent
{
    $indent += 2;
}

sub dec_indent
{
    $indent -= 2;
}

sub get_indent
{
    $retv = 0;
    print STDERR "$0 (", $lineno, "): Unbalanced macro pairs\n" if ($indent < 0);
    $retv = $indent - 1 if ($indent > 0);
    $retv;
}

while (<>) {
    $lineno++;
    if (/^[ \t]*\#[ \t]*((if|el|en|).*)/)
    {
        $cont = $1;
        $temp = $2;
        if ($temp =~ /if/) {
            print "#", " " x &get_indent (), $cont,"\n";
            inc_indent ();
        }
        elsif ($temp =~ /el/) {
            dec_indent ();
            print "#", " " x &get_indent (), $cont,"\n";
            inc_indent ();
        }
        elsif ($temp =~ /en/) {
            dec_indent ();
            print "#", " " x &get_indent (), $cont,"\n";
        }
        else {
            print "#", " " x &get_indent (), $cont,"\n";
        }
    }
    else {
        print $_;
    }
}

die ("$0 (EOF): Unbalanced macro pairs\n") if ($indent != 0);


eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
    & eval 'exec perl -S $0 $argv:q'
    if 0;

#
# Provides size breakdown of ACE, TAO, or orbsvcs libs.
#
# Assumes (or builds) the lib with debug=0.  Allows other make args,
# such as -j 4, to be passed on the command line.

$usage =
  "$0 [-h, for html output] [-s, for shared libs] [-v] [make arguments]\n";

####
#### Configuration parameters.
####
$build_args =
  'debug=0 optimize=1 static_libs_only=1 DEFFLAGS=-DACE_USE_RCSID=0';
$ACE_COMPONENTS =
  'OS Utils Logging Threads Demux Connection Sockets IPC Svcconf ' .
    'Streams Memory Token Other';
$TAO_COMPONENTS =
  'POA Pluggable_Protocols Default_Resources Interpretive_Marshaling ' .
    'IDL_Compiler ORB_Core Dynamic_Any';
$ORBSVCS_COMPONENTS =
  'Naming ImplRepo Time Concurrency Property Trader LifeCycle Sched ' .
    'Event CosEvent Event2 AV';

#### The following are only used for VxWorks libraries, and
#### only if the corresponding environment variable isn't set.
$default_toolenv = '386';
$default_wind_base = '/project/doc/pkg/wind';
$default_host_type = 'sun4-solaris2';

#### Use gmake if it's on the user's PATH, otherwise use make.  Use
#### sh -c to avoid warning if gmake isn't found.
$make =
  system ("sh -c \"gmake --version\" > /dev/null 2>&1")  ?  'make'  :  'gmake';

$ACE_ROOT = $ENV{'ACE_ROOT'}  ||
  die "$0: ACE_ROOT was not set!\n";

$html = $verbose = 0;
$lib_extension = 'a';

####
#### Process command line args.
####
while ($#ARGV >= $[  &&  $ARGV[0] =~ /^-/) {
  if ($ARGV[0] eq '-h') {
    $html = 1;
    chop ($sysname = `uname -s`);
    chop ($sysrev = `uname -r`);
    shift;
  } elsif ($ARGV[0] eq '-s') {
    $lib_extension = 'so';
    $build_args =~ s/ static_libs_only=1//;
    shift;
  } elsif ($ARGV[0] eq '-v') {
    $verbose = 1;
    shift;
  } elsif ($ARGV[0] eq '-?') {
    print "$usage";
    exit;
  } else {
    #### Pass remaining args to make.
  }
}

$make_args = join (' ', @ARGV) . $build_args;

chop ($pwd = `pwd`);

if ($pwd =~ m%/ace$%) {
  #### libACE
  $COMPONENTS = "$ACE_COMPONENTS";
  $LIB_COMPONENTS = 'ACE_COMPONENTS';
  $libname = 'ACE';
} elsif ($pwd =~ m%/tao$%) {
  $COMPONENTS = "$TAO_COMPONENTS";
  $LIB_COMPONENTS = 'TAO_COMPONENTS';
  $libname = 'TAO';
} elsif ($pwd =~ m%/orbsvcs/orbsvcs$%) {
  $COMPONENTS = "$ORBSVCS_COMPONENTS";
  $LIB_COMPONENTS = 'TAO_ORBSVCS';
  $libname = 'orbsvcs';
} else {
  die "$0: unsupported directory; $pwd\n";
}

$lib = "lib${libname}.$lib_extension";

####
#### Select the size command based on ACE_ROOT setting.
####
if ($ACE_ROOT =~ /vxworks/) {
  $TOOLENV = $ENV{'TOOLENV'}  ||  $default_toolenv;
  $WIND_BASE = $ENV{'WIND_BASE'}  ||  $default_wind_base;
  $WIND_HOST_TYPE = $ENV{'WIND_HOST_TYPE'}  ||  $default_host_type;
  $size = "$WIND_BASE/host/$WIND_HOST_TYPE/bin/size$TOOLENV";
} elsif ($ACE_ROOT =~ /lynx-ppc/) {
  $size = '/usr/lynx/3.0.0/ppc/cdk/sunos-xcoff-ppc/bin/size';
} elsif ($ACE_ROOT =~ /lynx/) {
  $size = '/usr/lynx/3.0.0/x86/cdk/sunos-coff-x86/bin/size';
} elsif ($ACE_ROOT =~ /chorus/) {
  $size = '/project/doc/mvme/green68k/gnu/bin/size';
} else {
  $size = 'size';
}

####
#### Measure the size of the entire library.
####
$sizeTotal = build_lib ("$LIB_COMPONENTS=\"$COMPONENTS\"");
$components = "   Platform\n    Component\n    Total";
$componentSize = "   Size, bytes\n    $sizeTotal";
$componentPercentage =
  "   Percentage of
total size\n    100";
print "Total $sizeTotal (100)\n" unless $html;

####
#### Measure the size of each library component.
####
foreach my $i (split (' ', $COMPONENTS)) {
  $sizeLib = build_lib ("$LIB_COMPONENTS=\"$i\"");
  $components .= "\n    $i";
  $componentSize .= "\n    $sizeLib";
  $thisPercentage = percentage ($sizeLib, $sizeTotal);
  $componentPercentage .= "\n    $thisPercentage";
  print "$i $sizeLib ($thisPercentage)\n" unless $html;
}

####
#### Produce HTML output, if requested.
####
if ($html) {
  print '
' . "\n";
  print '
' . "\n";
  print "$echoArgs $components\n";
  print '
' . "\n";
  print "    $sysname $sysrev $ACE_ROOT\n";
  print "$echoArgs $componentSize\n";
  print '
' . "\n";
  print "$echoArgs $componentPercentage\n";
  print '

' . "\n";
}

####
#### Build library with components specified in argument.
####
sub build_lib ()
{
  my ($lib_components) = @_;

  unlink "$lib";

  print "$make $make_args $lib_components\n" if $verbose;

  system ("$make $make_args $lib_components >> make.log 2>&1")  &&
    die "$0: command failed; $make $make_args $lib_components\n";

  my $libSize = 0;

  open (SIZE, "$size $lib |")  ||
    die "$0: unable to open $size\n";
  while (<SIZE>) {
    my (@field) = split;
    $libSize += $field[3] if $field[3] =~ /\d/;  #### Skip size header line.
  }
  close (SIZE);

  $libSize;
}

####
#### Return percentage of first argument as fraction of second.
#### Returns a string with two-decimal place precision.
####
sub percentage ()
{
  my ($size, $total) = @_;

  sprintf ("%.2f", $size * 100 / $total);
}


eval '(exit $?0)' && eval 'exec perl -pi -S $0 ${1+"$@"}'
    & eval 'exec perl -pi -S $0 $argv:q'
    if 0;

#
# You may want to run the "find" command with this script, which maybe
# something like this:
#
# find . -type f \( -name "*.C" -o -name "*.cc" -o -name "*.c" -o -name "*.cpp" \) -print | xargs $ACE_ROOT/bin/auto_ptr.perl

# The first three lines above let this script run without specifying the
# full path to perl, as long as it is in the user's PATH.
# Taken from perlrun man page.

s/main( *\(int[ A-Za-z]*, *ACE_TCHAR)/ACE_TMAIN$1/g;


#! /usr/bin/perl
eval '(exit $?0)' && eval 'exec perl -w -S $0 ${1+"$@"}'
    & eval 'exec perl -w -S $0 $argv:q'
    if 0;

# ******************************************************************
#      Author: Chad Elliott
#        Date: 6/17/2002
# ******************************************************************

# ******************************************************************
# Pragma Section
# ******************************************************************

require 5.006;

use strict;
use FindBin;
use File::Spec;
use File::Basename;

my($basePath) = (defined $FindBin::RealBin ? $FindBin::RealBin :
                                             File::Spec->rel2abs(dirname($0)));
if ($^O eq 'VMS') {
  $basePath = File::Spec->rel2abs(dirname($0)) if ($basePath eq '');
  $basePath = VMS::Filespec::unixify($basePath);
}
$basePath .= '/MakeProjectCreator';

my($mpcroot) = $ENV{MPC_ROOT};
my($mpcpath) = (defined $mpcroot ? $mpcroot :
                                   dirname(dirname($basePath)) . '/MPC');
unshift(@INC, $mpcpath . '/modules');

if (defined $mpcroot) {
  print STDERR "MPC_ROOT was set to $mpcroot.\n";
}

if (! -d "$mpcpath/modules") {
  print STDERR "ERROR: Unable to find the MPC modules in $mpcpath.\n";
  if (defined $mpcroot) {
    print STDERR "Your MPC_ROOT environment variable does not point to a ",
                 "valid MPC location.\n";
  }
  else {
    print STDERR "You can set the MPC_ROOT environment variable to the ",
                 "location of MPC.\n";
  }
  exit(255);
}

require Driver;

# ************************************************************
# Subroutine Section
# ************************************************************

sub getBasePath {
  return $mpcpath;
}

# ************************************************************
# Main Section
# ************************************************************

my($driver) = new Driver($basePath, Driver::projects());
exit($driver->run(@ARGV));


eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
    & eval 'exec perl -S $0 $argv:q'
    if 0;

#   Win32 auto_compile script.

use File::Find;
use Cwd;

if (!$ENV{ACE_ROOT}) {
    $ACE_ROOT = getcwd ()."\\";
    warn "ACE_ROOT not defined, defaulting to ACE_ROOT=$ACE_ROOT";
}
else {
    $ACE_ROOT = $ENV{ACE_ROOT};
    $TAO_ROOT = $ENV{TAO_ROOT};
    $CIAO_ROOT = $ENV{CIAO_ROOT};
    $DANCE_ROOT = $ENV{DANCE_ROOT};
}

@directories = ();

@ace_core_dirs = ("$ACE_ROOT\\ace",
                  "$ACE_ROOT\\Kokyu",
                  "$ACE_ROOT\\ACEXML",
                  "$ACE_ROOT\\examples",
                  "$ACE_ROOT\\tests",
                  "$ACE_ROOT\\protocols");

@tao_core_dirs = ("$ACE_ROOT\\apps\\gperf\\src",
                  "$TAO_ROOT\\TAO_IDL",
                  "$TAO_ROOT\\tao",
                  "$TAO_ROOT\\tests");

@orbsvcs_core_dirs = ("$TAO_ROOT\\orbsvcs\\orbsvcs");

@dance_core_dirs = ("$DANCE_ROOT");

@ciao_core_dirs = ("$CIAO_ROOT");

$debug = 0;
$verbose = 0;
$print_status = 0;
$Ignore_errors = 0;              # By default, bail out if an error occurs.
$Build_Debug = 0;
$Build_Release = 0;
$build_all = 0;
$Build_Cmd = "/BUILD";
$use_custom_dir = 0;
$useenv = '';
$vc7 = 0;
$project_root = "$ACE_ROOT";

# Build_Config takes in a string of the type "project--configuration" and
# runs msdev to build it.
# sub Build_Config ($)
#{
#    my ($arg) = @_;
#    my ($project, $config) = split /--/, $arg;
#
#    return Build ($project, $config);
#}

# Build
sub Build ($$)
{
  my ($project, $config) = @_;

  if ($debug == 1) {
    print "$project\n";
    return 0;
  }
  else {
    print "Auto_compiling $project : $config\n";

    print "Building $project $config\n" if $verbose;

    return system ("msdev.com $project /MAKE \"$config\" $Build_Cmd $useenv");
  }
}

# Build
sub Build_VC7 ($$)
{
  my ($project, $config) = @_;

  if ($debug == 1) {
    print "$project\n";
    return 0;
  }
  else {
    print "Auto_compiling $project : $config\n";

    print "Building $project $config\n" if $verbose;

    return system ("devenv.com $project $Build_Cmd $config $useenv");
  }
}

sub Find_Dsw (@)
{
    my (@dir) = @_;
    @array = ();

    sub wanted_dsw {
        $array[++$#array] =
            $File::Find::name if ($File::Find::name =~ /\.dsw$/i);
    }

    find (\&wanted_dsw, @dir);

    print "List of dsw's\n" if ($verbose == 1);
    return @array;
}

sub Find_Sln (@)
{
    my (@dir) = @_;
    @array = ();

    print "Searching for list of sln's\n" if ($verbose == 1);

    sub wanted_sln {
        $array[++$#array] =
            $File::Find::name if ($File::Find::name =~ /\.sln$/i);
    }

    find (\&wanted_sln, @dir);

    print "List of sln's\n" if ($verbose == 1);
    return @array;
}

# Only builds the core libraries.
sub Build_Custom ()
{
    print STDERR "Building Custom\n";
    print "Building Custom directories specified\n";# if ($verbose == 1);

    print "Build " if ($verbose);
    print "Debug " if ($verbose) && ($Build_Debug);
    print "Release " if ($verbose) && ($Build_Release);
    print "\n" if ($verbose);

    my @custom_list = Find_Dsw (@directories);

    print "List now is @custom_list \n";
    foreach $c (@custom_list) {
        print "List now is $c \n";
        if ($Build_Debug) {
            $Status = Build ($c, "ALL - Win32 Debug");
            return if $Status != 0 && !$Ignore_errors;
        }
        if ($Build_Release) {
            $Status = Build ($c, "ALL - Win32 Release");
            return if $Status != 0 && !$Ignore_errors;
        }
    }
}

# Build all examples and directories
sub Build_All ()
{
    push @directories, @ace_core_dirs;
    push @directories, @tao_core_dirs;
    push @directories, @orbsvcs_core_dirs;
    push @directories, @dance_core_dirs;
    push @directories, @ciao_core_dirs;

    print STDERR "First pass (libraries)\n" if ($print_status == 1);
    print "\nmsvc_mpc_auto_compile: First Pass CORE (libraries)\n";

    Build_Custom ();

    my @new_directory_search = "$project_root";

    my @configurations = Find_Dsw (@new_directory_search);

    print STDERR "Second pass (for other things)\n" if ($print_status == 1);
    print "\nmsvc_mpc_auto_compile: Second  Pass (rest of the stuff)\n";

    foreach $c (@configurations) {
        print "\nUsing $c for compilation\n";
        if ($Build_Debug) {
            $Status = Build ($c, "ALL - Win32 Debug");
            return if $Status != 0 && !$Ignore_errors;
        }
        if ($Build_Release) {
            $Status = Build ($c, "ALL - Win32 Release");
            return if $Status != 0 && !$Ignore_errors;
        }
    }
}

# Only builds the core libraries.
sub Build_Custom_VC7 ()
{
    print STDERR "Building Custom\n";
    print "Building Custom directories specified\n";# if ($verbose == 1);

    print "Build " if ($verbose);
    print "Debug " if ($verbose) && ($Build_Debug);
    print "Release " if ($verbose) && ($Build_Release);
    print "\n" if ($verbose);

    my @custom_list = Find_Sln (@directories);

    print "List now is @custom_list \n";
    foreach $c (@custom_list) {
        print "List now is $c \n";
        if ($Build_Debug) {
            $Status = Build_VC7 ($c, "debug");
            return if $Status != 0 && !$Ignore_errors;
        }
        if ($Build_Release) {
            $Status = Build_VC7 ($c, "release");
            return if $Status != 0 && !$Ignore_errors;
        }
    }
}

# Build all examples and directories
sub Build_All_VC7 ()
{
    push @directories, @ace_core_dirs;
    push @directories, @tao_core_dirs;
    push @directories, @orbsvcs_core_dirs;
    push @directories, @dance_core_dirs;
    push @directories, @ciao_core_dirs;

    print STDERR "First pass (libraries)\n" if ($print_status == 1);
    print "\nmsvc_mpc_auto_compile: First Pass CORE (libraries)\n";

    Build_Custom_VC7 ();

    my @new_directory_search = "$project_root";

    my @configurations = Find_Sln (@new_directory_search);

    print STDERR "Second pass (for other things)\n" if ($print_status == 1);
    print "\nmsvc_mpc_auto_compile: Second  Pass (rest of the stuff)\n";

    foreach $c (@configurations) {
        print "\nUsing $c for compilation\n";
        if ($Build_Debug) {
            $Status = Build_VC7 ($c, "debug");
            return if $Status != 0 && !$Ignore_errors;
        }
        if ($Build_Release) {
            $Status = Build_VC7 ($c, "release");
            return if $Status != 0 && !$Ignore_errors;
        }
    }
}

## Parse command line argument
while ( $#ARGV >= 0  &&  $ARGV[0] =~ /^(-|\/)/ )
{
    if ($ARGV[0] =~ '-k') {             # Ignore errors
        print "Ignore errors\n" if ( $verbose );
        $Ignore_errors = 1;
    }
    elsif ($ARGV[0] =~ /^-d$/i) {       # debug
        $debug = 1;
    }
    elsif ($ARGV[0] =~ '-vc7') {    # Use VC7 project and solution files.
        print "Using VC7 files\n" if ( $verbose );
        $vc7 = 1;
    }
    elsif ($ARGV[0] =~ '-vc8') {    # Use VC8 project and solution files.
        print "Using VC8 files\n" if ( $verbose );
        $vc7 = 1; # vc8 is like vc7
    }
    elsif ($ARGV[0] =~ '-vc9') {    # Use VC9 project and solution files.
        print "Using VC9 files\n" if ( $verbose );
        $vc7 = 1; # vc9 is like vc7
    }
    elsif ($ARGV[0] =~ '-v') {          # verbose mode
        $verbose = 1;
    }
    elsif ($ARGV[0] =~ '-s') {          # status messages
        $print_status = 1;
    }
    elsif ($ARGV[0] =~ '-u') {          # USEENV
        print "Using Environment\n" if ($verbose);
        $useenv = '/USEENV';
    }
    elsif ($ARGV[0] =~ '-ACE') {# Build ACE and its tests
        print "Building ACE\n" if ( $verbose );
        $use_custom_dir = 1;
        push @directories, @ace_core_dirs;
    }
    elsif ($ARGV[0] =~ '-TAO') {# Build TAO and its tests
        print "Building TAO\n" if ( $verbose );
        $use_custom_dir = 1;
        push @directories, @ace_core_dirs;
        push @directories, @tao_core_dirs;
    }
    elsif ($ARGV[0] =~ '-ORBSVCS') {# Build TAO/ORBSVCS and its tests
        print "Building ACE+TAO+orbsvcs\n" if ( $verbose );
        $use_custom_dir = 1;
        push @directories, @ace_core_dirs;
        push @directories, @tao_core_dirs;
        push @directories, @orbsvcs_core_dirs;
    }
    elsif ($ARGV[0] =~ '-CIAO') {# Build the CIAO and related
                                 # libraries
        print "Building only CIAO\n" if ( $verbose );
        $use_custom_dir = 1;
        push @directories, @ace_core_dirs;
        push @directories, @tao_core_dirs;
        push @directories, @orbsvcs_core_dirs;
        push @directories, @dance_core_dirs;
        push @directories, @ciao_core_dirs;
    }
    elsif ($ARGV[0] =~ '-ALL') {# Build the CIAO and related
                                 # libraries
        print "Building ALL \n" if ( $verbose );
        $build_all = 1;
    }
    elsif ($ARGV[0] =~ '-dir') {        # Compile only a specific directory
        shift;
        print "Adding directory $ARGV[0]\n" if ( $verbose );
        $use_custom_dir = 1;
        push @directories, $ARGV[0];
    }
    elsif ($ARGV[0] =~ '-project_root') {  # use different root than ACE_ROOT
        shift;
        print "Using project root $ARGV[0]\n" if ( $verbose );
        $project_root = $ARGV[0];
    }
    elsif ($ARGV[0] =~ '-rebuild') {    # Rebuild all
        print "Rebuild all\n" if ( $verbose );
        $Build_Cmd = "/REBUILD";
    }
    elsif ($ARGV[0] =~ '-clean') {      # Clean
        print "Cleaning all\n" if ( $verbose );
        $Build_Cmd = "/CLEAN";
    }
    elsif ($ARGV[0] =~ '-Debug') {      # Debug versions
        print "Building Debug Version\n" if ( $verbose );
        $Build_Debug = 1;
    }
    elsif ($ARGV[0] =~ '-Release') {    # Release versions
        print "Building Release Version\n" if ( $verbose );
        $Build_Release = 1;
    }
    elsif ($ARGV[0] =~ '-(\?|h)') {     # Help information
        print "Options\n";
        print "-d         = Debug (only print out projects)\n";
        print "-k         = Ignore Errors\n";
        print "-v         = Script verbose Mode\n";
        print "-s         = Print status messages to STDERR\n";
        print "-u         = Tell MSVC to use the environment\n";
        print "-vc7       = Use MSVC 7 toolset\n";
        print "-vc8       = Use MSVC 8 toolset\n";
        print "-vc9       = Use MSVC 9 toolset\n";
        print "\n";
        print "-ACE       = Build ACE and its tests\n";
        print "-TAO       = Build ACE+TAO and its tests\n";
        print "-ORBSVCS   = Build ACE+TAO+ORBSVCS and its tests\n";
        print "-CIAO      = Build ACE+TAO+ORBSVCS+CIAO and its tests\n";
        print "-dir <dir> = Compile custom directories\n";
        print "-project_root <dir> = Use different root directory than ACE_ROOT\n";
        print "\n";
        print "-rebuild   = Rebuild All\n";
        print "-clean     = Clean\n";
        print "-Debug     = Compile Debug versions\n";
        print "-Release   = Compile Release versions\n";
        exit;
    }
    else {
        warn "$0: error unknown option $ARGV[0]\n";
        die -1;
    }
    shift;
}

if (!$Build_Debug && !$Build_Release) {
    $Build_Debug = 1;
    $Build_Release = 1;
}

print "MPC version of msvc_mpc_auto_compile: Begin\n";
if ($vc7) {
    Build_All_VC7 if ($build_all && !$use_custom_dir);
    Build_Custom_VC7 if $use_custom_dir;
}
else {
    Build_All if ($build_all && !$use_custom_dir);
    Build_Custom if $use_custom_dir;
}
print "msvc_mpc_auto_compile: End\n";
print STDERR "End\n" if ($print_status == 1);


#   Win32 auto_compile script.
if (!$ENV{ACE_ROOT}) {
    $ACE_ROOT = getcwd ()."\\";
    warn "ACE_ROOT not defined, defaulting to ACE_ROOT=$ACE_ROOT";
}
else {
    $ACE_ROOT = $ENV{ACE_ROOT};
}

use lib "$ENV{ACE_ROOT}/bin";

use File::Find;
use PerlACE::Run_Test;
use Cwd;

@directories = ();

@ace_dirs = ("$ACE_ROOT\\ace",
             "$ACE_ROOT\\ACEXML\\common",
             "$ACE_ROOT\\ACEXML\\parser",
             "$ACE_ROOT\\ACEXML\\apps",
             "$ACE_ROOT\\ACEXML\\tests",
             "$ACE_ROOT\\ACEXML\\examples",
             "$ACE_ROOT\\apps",
             "$ACE_ROOT\\ASNMP",
             "$ACE_ROOT\\examples",
             "$ACE_ROOT\\netsvcs",
             "$ACE_ROOT\\performance-tests",
             "$ACE_ROOT\\protocols",
             "$ACE_ROOT\\tests",
             "$ACE_ROOT\\websvcs");

$debug = 0;
$verbose = 0;
$print_status = 0;
$Ignore_errors = 0;              # By default, bail out if an error occurs.
$Build_LIB = 0;
$Build_Debug = 0;
$Build_Release = 0;
$Build_All = 1;
$build_core_only = 0;
$Build_Cmd = "/BUILD";
$use_custom_dir = 0;
$useenv = '';
$vc7 = 0;
$name_mod = '';
$mod_name = 0;
$proj_ext = '.dsp';

# Build
sub Build ($$)
{
  my ($project, $config) = @_;

  if ($debug == 1) {
    print "$project\n";
    return 0;
  }
  else {
    print "Auto_compiling $project : $config\n";

    print "Building $project $config\n" if $verbose;

    return system ("msdev.com $project /MAKE \"$config\" $Build_Cmd $useenv");
  }
}

# Build
sub Build_VC7 ($$)
{
  my ($project, $config) = @_;

  if ($debug == 1) {
    print "$project\n";
    return 0;
  }
  else {
    print "Auto_compiling $project : $config\n";

    print "Building $project $config\n" if $verbose;

    return system ("devenv.com $project $Build_Cmd $config $useenv");
  }
}

sub Find_Dsw (@)
{
    my (@dir) = @_;
    @array = ();

    sub wanted_dsw {
        $array[++$#array] =
            $File::Find::name if ($File::Find::name =~ /\.dsw$/i);
    }

    find (\&wanted_dsw, @dir);

    print "List of dsw's \n" if ($verbose == 1);
    return @array;
}

sub Find_Sln (@)
{
    my (@dir) = @_;
    @array = ();

    sub wanted_sln {
        $array[++$#array] =
            $File::Find::name if ($File::Find::name =~ /\.sln$/i);
    }

    find (\&wanted_sln, @dir);

    print "List of sln's \n" if ($verbose == 1);
    return @array;
}

sub Rename_Files ($$)
{
  my ($target) = shift;
  my ($newext) = shift;
  my (@array)  = ();

  sub wanted_file {
    my ($text) = shift;
    my ($next) = shift;
    if ($File::Find::name =~ /^(.*)$text$/i) {
      my ($newname) = $1 . $next;
      rename ($File::Find::name, $newname);
    }
  }

  find (sub { wanted_file ($target, $newext) }, $ACE_ROOT);
}

# Only builds the core libraries.
sub Build_Core ()
{
    print STDERR "Building Core of ACE/TAO\n" if ($print_status == 1);
    print "\nmsvc_static_compile: Building Core of ACE/TAO\n";

    print "Build \n" if ($verbose);
    print "Debug " if ($verbose) && ($Build_Debug);
    print "Release " if ($verbose) && ($Build_Release);
    print "LIB " if ($verbose) && ($Build_LIB);
    print "\n" if ($verbose);

    my @core_list = ();

    if ($Build_LIB) {
      push (@file_list, "/bin/msvc_static_order.lst");

      foreach my$test_lst (@file_list) {
        my $config_list = new PerlACE::ConfigList;
        $config_list->load ($ACE_ROOT.$test_lst);

        foreach $test ($config_list->valid_entries ()) {
          if ($mod_name) {
            @plist = split (/\//, $test);
            $fname = pop @plist;
            $fname_mod = $name_mod;
            $fname_mod =~ s/\*/$fname/;
	    push @plist,($fname_mod);
            push (@core_list, join('/', @plist) . $proj_ext);
          }
          else {
            push (@core_list, $test . $proj_ext);
          }
        }
      }

      if ( $vc7 ) {
          foreach $c (@core_list) {
              if ($Build_Debug) {
                  $Status = Build_VC7 ($c, "debug");
                  return if $Status != 0 && !$Ignore_errors;
              }
              if ($Build_Release) {
                  $Status = Build_VC7 ($c, "release");
                  return if $Status != 0 && !$Ignore_errors;
              }
          }
      }
      else {
          foreach $c (@core_list) {
              if ($Build_Debug) {
                  $Status = Build ($c, "ALL - Win32 Debug");
                  return if $Status != 0 && !$Ignore_errors;
              }
              if ($Build_Release) {
                  $Status = Build ($c, "ALL - Win32 Release");
                  return if $Status != 0 && !$Ignore_errors;
              }
          }
      }
    }
}

sub Build_All ()
{
    my @configurations = Find_Dsw (@directories);

    print STDERR "Building selected projects\n" if ($print_status == 1);
    print "\nmsvc_static_compile: Building selected projects\n";

    $count = 0;
    foreach $c (@configurations) {
        print STDERR "Configuration ".$count++." of ".$#configurations."\n" if ($print_status == 1);
        if ($Build_Debug) {
            $Status = Build ($c, "ALL - Win32 Debug");
            return if $Status != 0 && !$Ignore_errors;
        }
        if ($Build_Release) {
            $Status = Build ($c, "ALL - Win32 Release");
            return if $Status != 0 && !$Ignore_errors;
        }
    }
}

sub Build_All_VC7 ()
{
    my @configurations = Find_Sln (@directories);

    print STDERR "Building selected projects\n" if ($print_status == 1);
    print "\nmsvc_static_compile: Building selected projects\n";

    $count = 0;
    foreach $c (@configurations) {
        print STDERR "Configuration ".$count++." of ".$#configurations."\n" if ($print_status == 1);
        if ($Build_Debug) {
            $Status = Build_VC7 ($c, "debug");
            return if $Status != 0 && !$Ignore_errors;
        }
        if ($Build_Release) {
            $Status = Build_VC7 ($c, "release");
            return if $Status != 0 && !$Ignore_errors;
        }
    }
}

## Parse command line argument
while ( $#ARGV >= 0  &&  $ARGV[0] =~ /^(-|\/)/ )
{
    if ($ARGV[0] =~ '-k') {             # Ignore errors
        print "Ignore errors\n" if ( $verbose );
        $Ignore_errors = 1;
    }
    elsif ($ARGV[0] =~ /^-d$/i) {       # debug
        $debug = 1;
    }
    elsif ($ARGV[0] =~ '-vc7') {    # Use VC7 project and solution files.
        print "Using VC7 files\n" if ( $verbose );
        $vc7 = 1;
        $proj_ext = '.vcproj';
    }
    elsif ($ARGV[0] =~ '-vc8') {    # Use VC8 project and solution files.
        print "Using VC8 files\n" if ( $verbose );
        $vc7 = 1; # VC8 is like VC7
        $proj_ext = '.vcproj';
    }
    elsif ($ARGV[0] =~ '-vc9') {    # Use VC9 project and solution files.
        print "Using VC9 files\n" if ( $verbose );
        $vc7 = 1; # VC9 is like VC7
        $proj_ext = '.vcproj';
    }
    elsif ($ARGV[0] =~ '-v') {          # verbose mode
        $verbose = 1;
    }
    elsif ($ARGV[0] =~ '-name_modifier') {          # use MPC name_modifier for project
        shift;
        print "Setting name_modifier $ARGV[0]\n" if ( $verbose );
        $name_mod = $ARGV[0];
        $mod_name = 1;
    }
    elsif ($ARGV[0] =~ '-s') {          # status messages
        $print_status = 1;
    }
    elsif ($ARGV[0] =~ '-u') {          # USEENV
        print "Using Environment\n" if ($verbose);
        $useenv = '/USEENV';
    }
    elsif ($ARGV[0] =~ '-CORE') {       # Build the core of ace/tao
        print "Building only Core\n" if ( $verbose );
        $build_core_only = 1;
    }
    elsif ($ARGV[0] =~ '-ACE') {       # Build ACE and its programs
        print "Building ACE\n" if ( $verbose );
        $use_custom_dir = 1;
	push @directories, @ace_dirs;
    }
    elsif ($ARGV[0] =~ '-TAO') {       # Build TAO and its programs
        print "Building TAO\n" if ( $verbose );
        $use_custom_dir = 1;
	# Other tests depend on the lib in this dir so we need to force it
	# to the front of the build list. This is pretty ugly.
	push @directories, ("$ACE_ROOT\\TAO\\orbsvcs\\tests\\Notify\\lib");
	push @directories, ("$ACE_ROOT\\TAO");
    }
    elsif ($ARGV[0] =~ '-dir') {        # Compile only a specific directory
        shift;
        print "Adding directory $ARGV[0]\n" if ( $verbose );
        $use_custom_dir = 1;
        push @directories, $ARGV[0];
    }
    elsif ($ARGV[0] =~ '-rebuild') {    # Rebuild all
        print "Rebuild all\n" if ( $verbose );
        $Build_Cmd = "/REBUILD";
    }
    elsif ($ARGV[0] =~ '-clean') {      # Clean
        print "Cleaning all\n" if ( $verbose );
        $Build_Cmd = "/CLEAN";
    }
    elsif ($ARGV[0] =~ '-Debug') {      # Debug versions
        print "Building Debug Version\n" if ( $verbose );
        $Build_Debug = 1;
        $Build_All = 0;
    }
    elsif ($ARGV[0] =~ '-Release') {    # Release versions
        print "Building Release Version\n" if ( $verbose );
        $Build_Release = 1;
        $Build_All = 0;
    }
    elsif ($ARGV[0] =~ '-LIB') {        # Build LIB only
        print "Build LIB only\n" if ( $verbose );
        $Build_LIB = 1;
        $Build_All = 0;
    }
    elsif ($ARGV[0] =~ '-(\?|h)') {     # Help information
        print "Options\n";
        print "-d         = Debug (only print out projects)\n";
        print "-k         = Ignore Errors\n";
        print "-v         = Script verbose Mode\n";
        print "-s         = Print status messages to STDERR\n";
        print "-u         = Tell MSVC to use the environment\n";
        print "-vc7       = Use MSVC 7 toolset\n";
        print "-vc8       = Use MSVC 8 toolset\n";
        print "-name_modifier <mod> = Use MPC name_modifier to match projects\n";
        print "\n";
        print "-CORE      = Build the Core libraries\n";
        print "-ACE       = Build ACE and its programs\n";
        print "-TAO       = Build TAO and its programs\n";
        print "-dir <dir> = Compile custom directories\n";
        print "\n";
        print "-rebuild   = Rebuild All\n";
        print "-clean     = Clean\n";
        print "-Debug     = Compile Debug versions\n";
        print "-Release   = Compile Release versions\n";
        print "-LIB       = Comple LIB Configurations\n";
        exit;
    }
    else {
        warn "$0: error unknown option $ARGV[0]\n";
        die -1;
    }
    shift;
}

if (!$Build_DLL && !$Build_LIB) {
    $Build_DLL = 1;
    $Build_LIB = 1;
}

if (!$Build_Debug && !$Build_Release) {
    $Build_Debug = 1;
    $Build_Release = 1;
}

if ($#directories < 0) {
    @directories = ($ACE_ROOT);
}

print "msvc_static_compile: Begin\n";
print STDERR "Beginning Core Build\n" if ($print_status == 1);
if (!$use_custom_dir || $build_core_only) {
  if ($vc7) {
    ## devenv is too smart for it's own good.  When a .vcproj is specified,
    ## as is done when building the CORE, it will find the solution to which
    ## the .vcproj belongs and begin to build additional portions of the
    ## solution.  This is not what we want as dependencies are not set up
    ## between library projects.
    my($sln) = '.sln';
    my($core_sln) = $sln . '.build_core';

    Rename_Files ($sln, $core_sln);

    foreach my $sig ('INT', 'TERM') {
      $SIG{$sig} = sub { print STDERR "Renaming solution files, please be patient...\n";
                         Rename_Files ($core_sln, $sln);
                         exit(1); };
    }

    Build_Core ();

    Rename_Files ($core_sln, $sln);

    foreach my $sig ('INT', 'TERM') {
      $SIG{$sig} = 'DEFAULT';
    }
  }
  else {
    Build_Core ();
  }
}
print STDERR "Beginning Full Build\n" if ($print_status == 1);
if ( $vc7 ) {
    Build_All_VC7 if !$build_core_only;
}
else {
    Build_All if !$build_core_only;
}

print "msvc_static_compile: End\n";
print STDERR "End\n" if ($print_status == 1);


#! /usr/bin/perl
eval '(exit $?0)' && eval 'exec perl -w -S $0 ${1+"$@"}'
    & eval 'exec perl -w -S $0 $argv:q'
    if 0;

# ******************************************************************
#      Author: Chad Elliott
#        Date: 6/17/2002
# ******************************************************************

# ******************************************************************
# Pragma Section
# ******************************************************************

require 5.006;

use strict;
use FindBin;
use File::Spec;
use File::Basename;

my($basePath) = (defined $FindBin::RealBin ? $FindBin::RealBin :
                                             File::Spec->rel2abs(dirname($0)));
if ($^O eq 'VMS') {
  $basePath = File::Spec->rel2abs(dirname($0)) if ($basePath eq '');
  $basePath = VMS::Filespec::unixify($basePath);
}
$basePath .= '/MakeProjectCreator';

my($mpcroot) = $ENV{MPC_ROOT};
my($mpcpath) = (defined $mpcroot ? $mpcroot :
                                   dirname(dirname($basePath)) . '/MPC');
unshift(@INC, $mpcpath . '/modules');

if (defined $mpcroot) {
  print "MPC_ROOT was set to $mpcroot.\n";
}

if (! -d "$mpcpath/modules") {
  print STDERR "ERROR: Unable to find the MPC modules in $mpcpath.\n";
  if (defined $mpcroot) {
    print STDERR "Your MPC_ROOT environment variable does not point to a ",
                 "valid MPC location.\n";
  }
  else {
    print STDERR "You can set the MPC_ROOT environment variable to the ",
                 "location of MPC.\n";
  }
  exit(255);
}

require Driver;

# ************************************************************
# Subroutine Section
# ************************************************************

sub getBasePath {
  return $mpcpath;
}

# ************************************************************
# Main Section
# ************************************************************

my($driver) = new Driver($basePath, Driver::workspaces());
exit($driver->run(@ARGV));


BEGIN {
    use Cwd;
    if (!$ENV{ACE_ROOT}) {
        $ACE_ROOT = getcwd ()."\\";
        print STDERR "Error: ACE_ROOT not defined\n";
        exit 1;
    }
    else {
        $ACE_ROOT = $ENV{ACE_ROOT};
    }
}
use lib "$ACE_ROOT/bin";
use PerlACE::MSProject::DSP;
use PerlACE::MSProject::VCP;
use File::DosGlob 'glob';
use DirHandle;
use strict;

################################################################################

my $extension;
my $recurse = 0;
my $list = 0;
my $verbose = 0;
my @arguments;
my @configs;
my @roots;
my $auto_compile = 0;
my $clean = 0;
my $debug = 0;

my $aceroot = 0;

################################################################################

# Parse command line arguments

while ( $#ARGV >= 0)
{
    if ($ARGV[0] =~ m/^-list/i) {
        $list = 1;
    }
    elsif ($ARGV[0] =~ m/^-evc3/i) {
        $extension = "vcp";
    }
    elsif ($ARGV[0] =~ m/^-msvc6/i) {
        $extension = "dsp";
    }
    elsif ($ARGV[0] =~ m/^-msvc7/i) {
        $extension = "vcproj";
    }
    elsif ($ARGV[0] =~ m/^-config/i) {
        push @configs, $ARGV[1];
        shift;
    }
    elsif ($ARGV[0] =~ m/^-r/i) {
        $recurse = 1;
    }
    elsif ($ARGV[0] =~ m/^-v/i) {
        $verbose = 1;
    }
    elsif ($ARGV[0] =~ m/^-auto_compile/i) {
        $auto_compile = 1;
    }
    elsif ($ARGV[0] =~ m/^-clean/i) {
        $clean = 1;
    }
    elsif ($ARGV[0] =~ m/^-useroot/i) {
        push @roots, $ARGV[1];
        shift;
    }
    elsif ($ARGV[0] =~ m/^-aceroot/i) {
        $aceroot = 1;
    }
    elsif ($ARGV[0] =~ m/^-(\?|h)/i) {     # Help information
        print "Options\n";
        print "-list          - Prints out the list of project files\n";
        print "-config <c>    - Use <c> as a configuration\n";
        print "-evc3          - Looks for eMbedded Visual C++ 3.0 projects\n";
        print "-msvc6         - Looks for Visual C++ 5.0/6.0 projects\n";
        print "-msvc7         - Looks for Visual C++ 7.0 projects\n";
        print "-clean         - Clean instead of building\n";
        print "-recurse       - Recurse into directories\n";
        print "-verbose       - Make some noise\n";
        print "-auto_compile  - Print out auto_compile info during build\n";
        print "-useroot <dir> - Use <dir> as a root to look for dependencies\n";
        print "-aceroot       - Use %ACE_ROOT% as a dependency root\n";
        exit;
    }
    elsif ($ARGV[0] =~ m/^-/) {
        warn "$0:  unknown option $ARGV[0]\n";
        exit 1;
    }
    else {
        push @arguments, $ARGV[0];
    }
    shift;
}

if ($#configs < 0) {
    if (defined $ENV{WINMAKE_CONFIGS}) {
        @configs = split /:/, $ENV{WINMAKE_CONFIGS};
    }
    elsif (defined $ENV{PIPPEN_CONFIGS}) {
        @configs = split /:/, $ENV{PIPPEN_CONFIGS};
    }
    else {
        print STDERR "Error: No config specified\n";
        exit 1;
    }
}

if (!defined $extension) {
    my $compiler = '';
    if (defined $ENV{WINMAKE_COMPILER}) {
        $compiler = $ENV{WINMAKE_COMPILER};
    }
    elsif (defined $ENV{PIPPEN_COMPILER}) {
        $compiler = $ENV{PIPPEN_COMPILER};
    }
    else {
        print STDERR "Error: No compiler specified\n";
        exit 1;
    }

    if ($compiler eq "evc3") {
        $extension = "vcp";
    }
    elsif ($compiler eq "msvc6") {
        $extension = "dsp";
    }
    elsif ($compiler eq "msvc7") {
        $extension = "vcproj";
    }
}

################################################################################

# I like these variables

# %projects->{$file}->{BUILD} <- Are we supposed to build this file?
#                   ->{PROJ} <- MSProject object
#                   ->{CONFIGS}->{$config}->{DEPS} <- List of dependencies
#                                         ->{DONE} <- Have we compiled it yet?

my %projects;

# %names->{$output} <- points to the $file used in the above %projects

my %names;

################################################################################

# Expand all the files/directories passed in on the command line

sub ProjectSearch ($@)
{
    my $build = shift;
    my @targets = @_;

    while ($#targets >= 0) {
        my $target = $targets[0];
        if (-d $target) {
            print "    Reading Directory $target\n" if ($verbose);
            if ($recurse) {
                my $dh = new DirHandle ($target);

                if (defined $dh) {
                    foreach my $entry ($dh->read ()) {
                        if (-d "$target/$entry" && $entry ne "." && $entry ne "..") {
                            $entry =~ s/^.\\//; # / <- fix for color coding in devenv
                            push @targets, ($target . "\\". $entry);
                        }
                    }
                }
                else {
                    print STDERR "Error: Cannot read $target: $!\n";
                }
            }

            foreach my $t (glob ($target . "\\*." . $extension)) {
                print "    Adding project $t\n" if ($verbose);
                %projects->{$t}->{BUILD} = $build;
            }
        }
        else {
            foreach my $t (glob ($target)) {
                print "    Adding project $t\n" if ($verbose);
                %projects->{$t}->{BUILD} = $build;
            }
        }
        shift @targets;
    }
}

print "=== Expanding Command line Arguments\n" if ($verbose);

if ($#arguments < 0) {
    print "    No files specified, defaulting to \".\"\n" if ($verbose);
    push @arguments, (".");
}

ProjectSearch (1, @arguments);

print "=== Expanding Root Arguments\n" if ($verbose);

ProjectSearch (0, @roots);

if ($aceroot == 1) {
    my $oldrecurse = $recurse;
    $recurse = 1;
    my @aceroots = ($ENV{ACE_ROOT}."\\ace",
                    $ENV{ACE_ROOT}."\\apps\\gperf\\src",
                    $ENV{ACE_ROOT}."\\TAO\\TAO_IDL",
                    $ENV{ACE_ROOT}."\\TAO\\tao",
                    $ENV{ACE_ROOT}."\\TAO\\orbsvcs\\orbsvcs");
    ProjectSearch (0, @aceroots);
    $recurse = $oldrecurse;
}

################################################################################

# Read each project file to gather dependency and output information

print "=== Reading Project Files\n" if ($verbose);

foreach my $project (keys %projects) {
    my $proj;

    if ($project =~ m/\.dsp$/i) {
        $proj = new PerlACE::MSProject::DSP ($project);
    }
    elsif ($project =~ m/\.vcp$/i) {
        $proj = new PerlACE::MSProject::VCP ($project);
    }
    elsif ($project =~ m/\.vcproj$/i) {
        print STDERR "Error: MSVC7 not supported yet\n";
    }
    else {
        print STDERR "Error: Unrecognized file: $project\n";
    }

    print "    Loading $project:" if ($verbose);

    $proj->Load ();

    foreach my $config (@configs) {
        foreach my $proj_config ($proj->Configs ()) {
            if ($proj_config =~ m/\Q$config\E/i) {
                print " \"$proj_config\"" if ($verbose);
                my $name = $proj->DepOutputFile ($proj_config);

                %names->{lc $name} = $project;
                my @deps = split / /, $proj->Libs ($proj_config);

                foreach my $dep (@deps) {
#                    $dep =~ s/.*[\/\\]//g;
                    push (@{%projects->{$project}->{CONFIGS}->{$proj_config}->{DEPS}}, $dep);
                }
                if ($proj->UsesTAOIDL () == 1) {
                    push @{%projects->{$project}->{CONFIGS}->{$proj_config}->{DEPS}}, ("gperf.exe", "tao_idl.exe");
                }
            }
        }
    }

    print "\n" if ($verbose);

    %projects->{$project}->{PROJ} = $proj;
}

################################################################################

# Clean out the dependency lists, we only keep the libraries which we know
# how to generate

print "=== Cleaning out Dependency Lists\n" if ($verbose);

foreach my $project (keys %projects) {
    foreach my $config (keys %{%projects->{$project}->{CONFIGS}}) {
        print "    Cleaning Dependencies: $project ($config)\n" if ($verbose);
        print "        Before:", join (" ", @{%projects->{$project}->{CONFIGS}->{$config}->{DEPS}}), "\n" if ($verbose);
        my @newdeps;
        foreach my $dep (@{%projects->{$project}->{CONFIGS}->{$config}->{DEPS}}) {
            $dep =~ s/.*[\/\\]//g;

            if (defined %names->{lc $dep}) {
                push @newdeps, $dep;
            }
        }
        print "        After:", join (" ", @newdeps), "\n" if ($verbose);
        @{%projects->{$project}->{CONFIGS}->{$config}->{DEPS}} = @newdeps;
    }
}

################################################################################

# Make sure to build any dependencies found

print "=== Walking Dependency Lists\n" if ($verbose);

my $finished = 0;

do {
    $finished = 1;
    foreach my $project (keys %projects) {
        foreach my $config (keys %{%projects->{$project}->{CONFIGS}}) {
            if (%projects->{$project}->{BUILD} == 1) {
                foreach my $dep (@{%projects->{$project}->{CONFIGS}->{$config}->{DEPS}}) {
                    if (%projects->{%names->{lc $dep}}->{BUILD} != 1) {
                        %projects->{%names->{lc $dep}}->{BUILD} = 1;
                        $finished = 0;
                    }
                }
            }
        }
    }

} while (!$finished);

################################################################################

# Output a list, if requested

if ($debug) {
    print "List of Dependencies\n";
    print "--------------------\n";
    foreach my $project (keys %projects) {
        print "=== $project\n";
        foreach my $config (keys %{%projects->{$project}->{CONFIGS}}) {
            print "    Config: $config\n";
            print "        Depends: ", join (" ", @{%projects->{$project}->{CONFIGS}->{$config}->{DEPS}}), "\n";
        }
    }

    print "\n";
    print "List of Outputs\n";
    print "---------------\n";

    foreach my $name (keys %names) {
        print "$name\n";
    }
}

################################################################################

# Loop through and

print "=== Compiling\n" if ($verbose);

my $compilations;  # Keep track of the number of compiles done during a pass
my $unfinished;
my $loop = 1;

do {
    $compilations = 0;
    $unfinished = 0;

    foreach my $project (keys %projects) {
        if (%projects->{$project}->{BUILD} == 1) {
            foreach my $config (keys %{%projects->{$project}->{CONFIGS}}) {
                if (%projects->{$project}->{CONFIGS}->{$config}->{DONE} != 1) {
                    my $depsleft = 0;
                    foreach my $dep (@{%projects->{$project}->{CONFIGS}->{$config}->{DEPS}}) {
                        if (%projects->{%names->{lc $dep}}->{CONFIGS}->{$config}->{DONE} != 1) {
                            ++$depsleft;
                        }
                    }

                    if ($depsleft == 0) {
                        ++$compilations;
                        print "Auto_compiling $project : $config\n" if ($auto_compile);

                        if ($list == 1) {
                            if ($clean == 1) {
                                print "Cleaning ";
                            }
                            else {
                                print "Compiling ";
                            }

                            print "$project : $config\n";
                        }
                        elsif ($clean == 1) {
                            %projects->{$project}->{PROJ}->Clean ($config);
                        }
                        else {
                            %projects->{$project}->{PROJ}->Build ($config);
                        }

                        %projects->{$project}->{CONFIGS}->{$config}->{DONE} = 1;
                    }
                    else {
                        ++$unfinished;
                    }
                }
            }
        }
    }

    print "    === Loop $loop: $compilations compiles, $unfinished left\n" if ($verbose);
    ++$loop;
} while ($compilations != 0);

# Loop through and see if anything wasn't compiled.  If so, this means either there is
# an error in the script or that there are circular dependencies

foreach my $project (keys %projects) {
    if (%projects->{$project}->{BUILD} == 1) {
        foreach my $config (keys %{%projects->{$project}->{CONFIGS}}) {
            if (%projects->{$project}->{CONFIGS}->{$config}->{DONE} != 1) {
                print STDERR "Error: Project not compiled: $project - $config\n",
            }
        }
    }
}


eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
    & eval 'exec perl -S $0 $argv:q'
    if 0;

# Goes through ACE/TAO and replaces

use File::Find;
use Cwd;

$args = '';
$root = cwd.'/';

while ($#ARGV >= 0) {
  $args = $args . ' ' . shift @ARGV;
}

# wanted is only used for the File::Find
sub wanted
{
    my $file = $File::Find::name;

    $file =~ s/\.\//$root/;

    if ($File::Find::name =~ /\_export\.h$/i) {
        my $flag = 0;
        my $name = '';

        if (!open (FILE, $file)) {
            print STDERR "Error: Could not open $file\n";
        }

        while (<FILE>) {
            $flag = 1 if ((/generate_export/ || /GenExportH/) && $flag == 0);
            $name = $1 if (/define (\w*)_Export/);
        }

        if ($flag == 1) {
            print "Regenerating: $file\n";
            if ($OSNAME eq 'MSWIn32') {
                $file =~ s/\//\\/g;
            }
            system ("perl -S generate_export_file.pl $args $name > $file");
        }
        else {
            print "Skipping:     $file\n";
        }
        close FILE;
    }
}

find (\&wanted, ".");


#! /usr/bin/perl
eval '(exit $?0)' && eval 'exec perl -w -S $0 ${1+"$@"}'
    & eval 'exec perl -w -S $0 $argv:q'
    if 0;

#
# Splits C++ source files into one file per function or data item.
#
# Author: David L. Levine, with much help and encouragment from
#         Umar Syyid and Gonzalo A. Diethelm.
#         Completed by Andrew Gilpin, July 2000
# Date:   10 November 1998
#
# For each C++ source file:
# 1) Extracts the "intro" code, i.e., #includes and declarations.
# 2) Identifies function definitions, relying on {, and } at the
#    beginning of a line, to delineate the function begin and
#    end.
#
# Assumptions: (applies only to the files being split, i.e. .cpp files)
# * Function definition bodies are terminated with } appearing at
#   the beginning of a line.
# * Free-standing (outside of functions) macro invocations must be
#   followed by a blank line, or terminated with a semicolon.
# * A function must not have a blank line between its header
#   (signature) and its body.
# * There aren't multiple C-style comments on one line, with code
#   between them.
# * typedefs are on a single line
# * A #endif doesn't have a multi-line C comment starting on that line.

# The first three lines above let this script run without specifying the
# full path to perl, as long as it is in the user's PATH.
# Taken from perlrun man page.

# Changes made by Andrew Gilpin (June - July 2000)
# * Added option -c to use .c extension instead of .cpp extension
# * Prints message when no filenames are specified on the command line
# * Changed -? option to -h so that it works properly in most shells
# * Added option -s to skip certain files, but copy them to $split_dir,
#   renaming them. (filename.cpp -> $split_dir/filename_S1.cpp). This is
#   here so that ACE can selectively not split certain files (namely those
#   that this script doesn't work with :)
# * Added support for classes declared in the .cpp file.

$usage="usage: $0 [-h] [-d] [-v] [-c] [-s filename] filenames\n";

#### Configuration parameters.
$verbose = 0;
$debug = 0;
$split_dir = 'SPLIT';
$extension = 'cpp';
@files_to_skip = ();

#### Constants.
$DIR_SEPARATOR = $^O eq "MSWin32"  ?  '\\'  :  '/';

####
#### Process command line args.
####
while ( $#ARGV >= $[  &&  $ARGV[0] =~ /^-/ ) {
  if ( $ARGV[0] eq '-d' ) {
    $debug = 1;
  } elsif ( $ARGV[0] eq '-v' ) {
    $verbose = 1;
  } elsif ( $ARGV[0] eq '-c' ) {
    $extension = 'c';
  } elsif ( $ARGV[0] eq '-s' ) {
    push @files_to_skip, $ARGV[1];
    shift;
  } elsif ( $ARGV[0] eq '-h' ) {
    print "$usage";
    exit;
  } else {
    print STDERR "$0:  unknown option $ARGV[0]\n";
    die $usage;
  }
  shift;
}

&main ();

####
#### Reset state, to process a new file starting with a clean slate.
####
sub reset {
    #### Working data buffers.
  @intro = ();
  @current_comments = ();
  @current_code = ();
  @if = ();
  @save_if = ();
  @endif = ();
  @unknown = ();
  ####@unknown_s = ();

  #### State variables.
  $current_file_number = 0;
  $top_of_file = 1;
  $in_braces = 0;
  $in_nonfunction_code = 0;
  $in_C_comment = 0;
  $intro_length = 0;
  $preprocessor_continuation = 0;
  $preserved_ifs = 0;
}

sub main {
  #### Print error message if no files are specified.
  #### We need to do this before we modify anything on disk.
  die "No files specified!\n$usage" if (@ARGV == 0);

  #### Remove the destination subdirectory, if it exists.
  #### Attempts to clean it out using unlink may fail because
  #### it can have many files.
  if (-d "$split_dir") {
    system ("/bin/rm -r $split_dir") << 256  &&
      die "$0: unable to rm \"$split_dir\"\n";
  }

  #### Create the destination subdirectory.
  mkdir "$split_dir", 0755  ||
    die "$0: unable to create $split_dir directory: $!\n";

  MAIN_LOOP: foreach $file (@ARGV) {
    #### Strip off filename extension.
    ($basename = $file) =~ s/\.[^\.]+$//;

    foreach $skip_file (@files_to_skip) {
      if ($skip_file eq $file) {
        system ("/bin/cp $file $split_dir/" . $basename. "_S1\.$extension");
	next MAIN_LOOP;
      }
    }

    &reset ();

    print "FILE: $file\n" if $verbose;
    open INPUT, "$file"  ||  die "$0: unable to open \"$file\"\n";

    while (<INPUT>) {
      #### Strip comments from $line and use that for processing.
      #### But, use $_ for output, so that comments will be preserved.
      my $line = $_;

      #### If we're in the midst of a multiline C comment, see
      #### if it's finished on this line.
      if ($in_C_comment) {
        if ($line =~ s%^.*\*/%%) {
          #### End C-style comment.
          $in_C_comment = 0;

          if ($line =~ /^\s*$/  &&  ! $in_braces) {
            #### No code on the line.
            #&save_comment ($_);
            next;
          }
        } else {
          unless ($in_braces) {
            #&save_comment ($_);
            next;
          }
        }
      }

      #### Strip C++-style comments.
      if ($line =~ s%\s*//.*$%%) {
        if ($line =~ /^\s*$/  &&  ! $in_braces) {
          #### C++-style comment, without any code on the line.
          #&save_comment ($_);
          next;
        }
      }

      #### And C-style comments.
      if ($line =~ m%/\*%) {
        #### Begin C-style comment.  Strip any complete comment(s),
        #### then see what's left.

        $line =~ s%\s*/\*.*\*/\s*%%g;

        #### check to see if a preprocessor is on this line
        if (! $in_braces) {
          if ($line eq '') {
          #### The line just had comment(s).  Save it.
            #&save_comment ($_);
            next;
          } else {
            #### There's other text on the line.  See if it's just the
            #### start of a comment.
            if ($line =~ m%/\*%  &&  $line !~ m%\*/%) {
              #### The C-style comment isn't terminated on this line.
              $in_C_comment = 1;
              #&save_comment ($_);
              next;
            }
          }
        }
      }

      #### For now, skip ACE_RCSID's.  Eventually, we might want to
      #### consider putting them in _every_ file, if they're enabled.
      next if $line =~ /^ACE_RCSID/;

      if ($in_braces) {
        push @unknown, $_;
        if ($line =~ /{/) {
          ++$in_braces;
        } elsif ($line =~ /^};/) {
          #### }; at beginning of line could signify end of class
          --$in_braces;
          if ($in_braces == 0) {
            push @intro, @unknown;
            @unknown = ();
          }
        } elsif ($line =~ /^}/) {
          #### } at beginning of line signifies end of function.
          --$in_braces;
          push @current_code, @unknown;
          @unknown = ();
          &finish_current ($basename, ++$current_file_number);
        } elsif ($line =~ /};/) {
          #### end of multi-line data delcaration
          --$in_braces;
          if ($in_braces == 0) {
            push @current_code, @unknown;
            @unknown = ();
            &finish_current ($basename, ++$current_file_number);
          }
        }
      } else {
        #### Not in braces.
        if (($line =~ m%[^/]*{%) && (! $preprocessor_continuation)) {
          #### { signifies beginning of braces (obviously :).
          if ($line =~ /};/) {
            #### braces end on this line
            push @unknown, $_;
            push @current_code, @unknown;
            @unknown = ();
            &finish_current ($basename, ++$current_file_number);
          } else {
            push @unknown, $_;
            $in_braces = 1;
            $in_nonfunction_code = $top_of_file = 0;
          }
        } elsif ($line =~ /^}/) {
          warn "$0: skipping unexpected } on line $. of \"$file\"\n";
          next;
        } elsif ($line =~ /^typedef/) {
          push @intro, $_;
        } elsif ($line =~ /^\s*#/  ||  $preprocessor_continuation) {
          #### Preprocessor directive.
          if ($in_nonfunction_code) {
            push @unknown, $_;
          } else {
            push @intro, $_;
          }
          $top_of_file = 0;
          $preprocessor_continuation = /\\$/  ?  1  :  0;

          if ($line =~ m%^\s*#\s*if\s*(.*)(/.*)*$%) {
            push @save_if, $_;
            unshift @endif, "#endif /* $1 [Added by split-cpp.] */\n";

          } elsif ($line =~ /^\s*#\s*endif/) {
            #### End an #if/#else block.
            unless (defined pop @save_if) {
              pop @if;
              if ($preserved_ifs > 0) {
                --$preserved_ifs;
              }
            }
            shift @endif;

          #### } elsif ($line =~ /^\s*#/) {
            #### Any other preprocessor directive.
          }

        } elsif ($line =~ /^\s*$/) {
          #### Whitespace only, or empty line..
          push @current_code, "\n";
          if ($in_nonfunction_code) {
            #### In the midst of non-function code, we reached a
            #### blank line.  Assume that we're done with it.
            &finish_current ($basename, ++$current_file_number);
          } else {
            #### Not in a function, so add to intro.  Just in case data or
            #### a function follow it, flush now.
            $preserved_ifs += $#save_if + 1;
            &flush_current (\@intro);
          }

        } elsif ($line =~ /;/) {
          #### Data definition or semicolon-terminated macro invocation.
          push @unknown, $_;
          $top_of_file = 0;

          #### Is it file-static?  Squash newlines out of @current_code.
          my $statement = join (' ', @current_code);
          if ($statement =~ /([^=[(]+)[=[(](.*)/) {
            if ($1 =~ /static/) {
              #### Move code to the intro.
              push @intro, @current_comments;
              @current_comments = ();
              &flush_current (\@intro);

              #### Not separate code.
              $in_nonfunction_code = 0;

              #### ???? Extract name from the left side and save for
              #### later matching.
            } else {
              if ($statement =~ /^USEUNIT\s*\(/) {
                #### Special-case those Borland USEUNIT things.
                &flush_current (\@intro);
              } else {
                #### Non-static entity, with semicolon.  Wrap it up.
                push @current_code, @unknown;
                @unknown = ();
                &finish_current ($basename, ++$current_file_number);
              }
            }
          } else {
            #### Dunno.  Wrap it up, anyways.
            push @current_code, @unknown;
            @unknown = ();
            &finish_current ($basename, ++$current_file_number);
          }
        } else {
          #### Beginning of data definition or function or class.
          push @unknown, $_;
          $in_nonfunction_code = 1;
          $top_of_file = 0;
        }
      }

      if (eof) {
        close (ARGV);  #### To reset line number counter.
        if ($#intro > $intro_length) {
          #### Leftover prepreprocessor statement(s), such as #pragma
          #### instantiate.
          &finish_current ($basename, ++$current_file_number);
        }
      }
    }

    close INPUT;
  }
};

####
#### Save a comment in the appropriate array.
####
#sub save_comment {
#  my ($comment) = @_;
#
#  if ($top_of_file) {
#    push @intro, $comment;
#  } else {
#    push @current_comments, $comment;
#  }
#}

####
#### Flush the contents of the @current_code array to the destination
#### argument array.  It is passed by reference.
####
sub flush_current {
  my ($destination) = @_;

  push @$destination, @current_code;
  @current_code = ();
}

####
#### Flush what we've got now to an output (split) file.
####
sub finish_current {
  my ($basename, $current_file_number) = @_;

  my $current_file_name =
    sprintf "$split_dir$DIR_SEPARATOR${basename}_S%d.$extension",
      $current_file_number++;

  if ($verbose) {
    print "CURRENT OUTPUT FILE: $current_file_name\n";
    print "INTRO:\n";
    print @intro;
    print @if;
    print @current_comments;
    print "CURRENT CODE:\n";
    print @current_code;
    print @endif;
  }

  open OUTPUT, "> $current_file_name"  ||
    die "unable to open $current_file_name\n";

  print OUTPUT "// Automatically generated by ACE's split-cpp.\n" .
               "// DO NOT EDIT!\n\n";
  if ($debug) {
      print OUTPUT "INTRO:\n", @intro, "IF:\n", @if,
                   "COMMENTS:\n", @current_comments,
                   "CURRENT:\n", @current_code, "ENDIF:\n", @endif;
  } else {
      print OUTPUT @intro, @if, @current_comments, @current_code, @endif;
  }

  close OUTPUT;

  #### For detection of leftover preprocessor statements and
  #### comments at end of file.
  $intro_length = $#intro;

  @current_comments = @current_code = @save_if = ();
  $in_braces = $in_nonfunction_code = 0;
}


eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
    & eval 'exec perl -S $0 $argv:q'
    if 0;

#
# File: svcconf-convert.pl:
# Purpose: This perl script convert classic svc.conf file into XML svc.conf file format.
# Usage: svcconf-convert.pl [-i infile] [-o outfile] [-verbose] [-nocomment]
#           -i: Specify the input classic svc.conf filename.
#               If omitted, the default input filename is "svc.conf".
#           -o: Specify the output XML svc.conf filename.
#               If this argument is omitted, the resulting XML file will be written
#               to file called <input filename>.xml.
#           -verbose: Verbose output.
#           -nocomment: Remove all comments.  Use this argument if you have comments
#                       mixing in the middle of a classic svc.conf directive.

$indent = 0;

sub inc_indent
{
    $indent += 2;
}

sub dec_indent
{
    $indent -= 2;
}

sub get_indent
{
    $retv = 0;
    print STDERR "$0 (", $lineno, "): Unbalanced macro pairs\n" if ($indent < 0);
    $retv = $indent - 1 if ($indent > 0);
    $retv;
}

sub acexml_comment
{
    my $comment = shift;
    print OUT " " x &get_indent (), "<!-- $comment -->\n";
}

sub acexml_start
{
    my $name = shift;
    my $standalone = shift;

    print OUT " " x &get_indent (), "<$name";

    while (@attnames)
    {
        print OUT " ", pop (@attnames), '="', pop (@attvalues), '"';
    }

    if ($standalone != 0)
    {
        print OUT "/>\n";
    }
    else
    {
        print OUT ">\n";
        inc_indent ();
    }
}

sub acexml_end
{
    my $name = shift;

    dec_indent ();
    print OUT " " x &get_indent (), "</$name>\n";
}

$verbose = 0;
$nocomment = 0;
@attvalues = ();
@attnames = ();
$stream = "";
$infile = "";
$outfile = "";

while ( $#ARGV >= 0)
{
    if ($ARGV[0] =~ m/^-i/i) {
        shift;
        $infile = "$ARGV[0]";
    }
    elsif ($ARGV[0] =~ m/^-o/i) {
        shift;
        $outfile = "$ARGV[0]";
    }
    elsif ($ARGV[0] =~ m/^-verbose/i) {
        $verbose = 1;
    }
    elsif ($ARGV[0] =~ m/^-nocomment/i) {
        $nocomment = 1;
    }
    elsif ($ARGV[0] =~ m/^-(\?|h|help)/i) {     # Help information
        print
" Usage: svcconf-convert.pl [-i infile] [-o outfile] [-verbose] [-nocomment]
           -i: Specify the input classic svc.conf filename.
               If omitted, the default input filename is 'svc.conf'.
           -o: Specify the output XML svc.conf filename.
               If this argument is omitted, the resulting XML file will
               be written to file called <input filename>.xml.
           -verbose: Verbose output.
           -nocomment: Remove all comments.  Use this argument if you
                       have comments mixing in the middle of a classic
                       svc.conf directive.
";
        exit;
    }
    elsif ($ARGV[0] =~ m/^-/) {
        warn "$0:  unknown option $ARGV[0]\n";
        exit 1;
    }
    else {
        die "unknow argument\n";
    }
    shift;
}

if ($infile eq "") {
    print "Using default svc.conf name\n" if ($verbose != 0);
    $infile = "svc.conf";
}

if ($outfile eq "") {
    $outfile = "$infile.xml";
}
print "OUTFILE = $outfile \n" if ($verbose);

open (OUT, "> $outfile") or die "Unable to open $outfile\n";

undef $/;
open (FH, "< $infile");
$_ = <FH>;

if ($nocomment) {
    if (s/^\#(.*)$//mg) {
        print "ts = $_\n" if ($verbose != 0);
    }
}

print "------------------------------------------------------------\n" if ($verbose != 0);

print OUT "<?xml version='1.0'?>\n";
print OUT "<!-- Converted from $infile by svcconf-convert.pl -->\n";
acexml_start ("ACE_Svc_Conf", 0);

while (length ($_) != 0) {
    s/^\s*$//mg;

    print "INPUT =\n$_\n" if ($verbose);
  PARSE: {
      if (s/^\s*\#(.*)//) {
          acexml_comment ($1);
          print "# $1\n" if ($verbose);
      }
      if (s/^\s*{//) {
          acexml_start ("module", 0);
          print "open module\n" if ($verbose);
      }

      if (s/^\s*}//) {
          acexml_end ("module");
          acexml_end ($stream);
          print "close module\n" if ($verbose);
      }

      if (s/^\s*stream\s+dynamic\s+(\w+)\s+(\w+)\s*\*\s*(\S+):(\S+)\s*\(\s*\)(\s+(active|inactive))?(\s+"([^"]*)")?//) {
          $name = $1;
          $type = $2;
          $path = $3;
          $init = $4;
          $state = $6;
          $param = $8;
          acexml_start ("streamdef");
          if ($status ne "") {
              push @attnames, ("status");
              push @attvalues, ("$state");
          }
          push @attnames, ("type");
          push @attvalues, ("$type");
          push @attnames, ("id");
          push @attvalues, ("$name");
          acexml_start ("dynamic", 0);
          if ($param ne "") {
              push @attnames, ("params");
              push @attvalues, ("$param");
          }
          push @attnames, ("init");
          push @attvalues, ("$init");
          push @attnames, ("path");
          push @attvalues, ("$path");
          acexml_start ("initializer", 1);
          acexml_end ("dynamic");
          $stream = "streamdef";
          print "stream dynamic $name $type * $init:$path \"$param\" $state\n" if ($verbose);
      }

      if (s/^\s*stream\s+static\s+(\w+)(\s+("(.*)"))?//) {
          $name = $1;
          $param = $4;
          acexml_start ("streamdef", 0);
          if ($param ne "") {
              push @attnames, ("params");
              push @attvalues, ("$param");
          }
          push @attnames, ("id");
          push @attvalues, ("$name");
          acexml_start ("static", 1);
          $stream = "streamdef";
          print "static $name \"$param\"\n" if ($verbose);
      }

      if (s/^\s*stream\s+(\w+)//) {
          $name = $1;
          push @attnames, ("id");
          push @attvalues, ("$name");
          acexml_start ("stream", 0);
          $stream = "stream";
          print "stream $name\n" if ($verbose);
      }

      if (s/^\s*dynamic\s+(\w+)\s+(\w+)\s*\*\s*(\S+):(\S+)\s*\(\s*\)(\s+(active|inactive))?(\s+"([^"]*)")?//) {
          $name = $1;
          $type = $2;
          $path = $3;
          $init = $4;
          $state = $6;
          $param = $8;
          if ($status ne "") {
              push @attnames, ("status");
              push @attvalues, ("$state");
          }
          push @attnames, ("type");
          push @attvalues, ("$type");
          push @attnames, ("id");
          push @attvalues, ("$name");
          acexml_start ("dynamic", 0);
          if ($param ne "") {
              push @attnames, ("params");
              push @attvalues, ("$param");
          }
          push @attnames, ("init");
          push @attvalues, ("$init");
          push @attnames, ("path");
          push @attvalues, ("$path");
          acexml_start ("initializer", 1);
          acexml_end ("dynamic");
          print "dynamic $name $type * $init:$path \"$param\" $state\n" if ($verbose);
      }

      if (s/^\s*static\s+(\w+)(\s+("(.*)"))?//) {
          $name = $1;
          $param = $4;
          if ($param ne "") {
              push @attnames, ("params");
              push @attvalues, ("$param");
          }
          push @attnames, ("id");
          push @attvalues, ("$name");
          acexml_start ("static", 1);
          print "static $name \"$param\"\n" if ($verbose);
      }

      if ( s/^\s*resume\s+(\w+)//) {
          $name = $1;
          push @attnames, ("id");
          push @attvalues, ("$name");
          acexml_start ("resume", 1);
          print "resume $name\n" if ($verbose);
      }

      if ( s/^\s*remove\s+(\w+)//) {
          $name = $1;
          push @attnames, ("id");
          push @attvalues, ("$name");
          acexml_start ("remove", 1);
          print "remove $name\n" if ($verbose);
      }

      if ( s/^\s*suspend\s+(\w+)//) {
          $name = $1;
          push @attnames, ("id");
          push @attvalues, ("$name");
          acexml_start ("suspend", 1);
          print "suspend $name\n" if ($verbose);
      }

      $nothing = 1;
  }
}

acexml_end ("ACE_Svc_Conf");


eval '(exit $?0)' && eval 'exec perl -pi -S $0 ${1+"$@"}'
    & eval 'exec perl -0 -S $0 $argv:q'
    if 0;

# You may want to run the "find" command with this script, which maybe
# something like this:
#
# find . -type f \( -name "*.inl" -o -name "*.h" -o -name "*.cxx" -o -name "*.java" -o -name "*.l" -o -name "*.c" -o -name "*.mpd" -o -name "*.py" -o -name "*.cpp" -o -name "*.mpc" -o -name "*.idl" -o -name "*.conf" -o -name "*.mpb" -o -name "*.hpp" -o -name "*.pl"  -o -name "*.mpt"   -o -name "*.pm" -o -name "*.html" -o -name "*.xml" -o -name "*.y" \) -print | xargs $ACE_ROOT/bin/zap_svn_id.pl

# The first three lines above let this script run without specifying the
# full path to perl, as long as it is in the user's PATH.
# Taken from perlrun man page.

# Replace the old cvs-id tag with nothing
BEGIN{undef $/;} s///smg;
# Replace a single doxygen style with two spaces before the Id with one space
BEGIN{undef $/;} s/ \*\n \*  \$Id\$\n \*\n/ \*\n \* \$Id\$\n \*\n/smg;
# Replace a three line doxygen style Id tag with just line *
BEGIN{undef $/;} s/ \*\n \* \$Id\$\n \*\n/ \*\n/smg;
# Replace a three line doxygen style Id tag with just line *
BEGIN{undef $/;} s/\*\*\n \* \$Id\$\n \*\n/\*\*\n/smg;
# Replace a three line c-style id tag with an empty line below that with nothing
BEGIN{undef $/;} s/\/\/\n\/\/ \$Id\$\n\/\/\n\n//smg;
# Replace a three line c-style id tag with nothing
BEGIN{undef $/;} s/\/\/\n\/\/ \$Id\$\n\/\/\n//smg;
# Replace a two line c-style id tag with an empty line below that with nothing
BEGIN{undef $/;} s/\/\/\n\/\/ \$Id\$\n\n//smg;
# Replace a two line c-style id tag with nothing
BEGIN{undef $/;} s/\/\/\n\/\/ \$Id\$\n//smg;
# Replace a one line c-style id tag with an empty line below that with nothing
BEGIN{undef $/;} s/\/\/ \$Id\$\n\n//smg;
# Replace a one line c-style id tag with nothing
BEGIN{undef $/;} s/\/\/ \$Id\$\n//smg;
# Replace a one line c-style id tag with an empty line below that with nothing
BEGIN{undef $/;} s/\/\/\$Id\$\n\n//smg;
# Replace a one line c-style id tag with nothing
BEGIN{undef $/;} s/\/\/\$Id\$\n//smg;
# Replace a one line start C++ line with Id with
BEGIN{undef $/;} s/\/\/ -\*- C\+\+ -\*-   \$Id\$\n/\/\/ -\*- C\+\+ -\*-\n/smg;
# Replace a one line start C++ line with Id with
BEGIN{undef $/;} s/\/\/ -\*- C\+\+ -\*-  \$Id\$\n/\/\/ -\*- C\+\+ -\*-\n/smg;
# Replace a one line start C++ line with Id with
BEGIN{undef $/;} s/\/\/ -\*- C\+\+ -\*- \$Id\$\n/\/\/ -\*- C\+\+ -\*-\n/smg;
# Replace a three line doxygen style Id tag with just line *
BEGIN{undef $/;} s/\/\*\n \* \$Id\$\n \*\n/\/\*\n/smg;
# Replace a one line c++-style id tag with an empty line below that with nothing
BEGIN{undef $/;} s/\/\* \$Id\$ \*\/\n\n//smg;
# Replace a one line c++-style id tag with an empty line below that with nothing
BEGIN{undef $/;} s/\/\* \$Id\$ \*\/\n//smg;
# Replace a three perl style Id tag with just line #
BEGIN{undef $/;} s/ \#\n \# \$Id\$\n \#\n/ \#\n/smg;
BEGIN{undef $/;} s/\#\n\# \$Id\$\n\#\n/\#\n/smg;
BEGIN{undef $/;} s/ \#\n \#\$Id\$\n \#\n/ \#\n/smg;
BEGIN{undef $/;} s/\#\n\#\$Id\$\n\#\n/\#\n/smg;
BEGIN{undef $/;} s/\#\$Id\$\n//smg;
BEGIN{undef $/;} s/\# \$Id\$\n//smg;
BEGIN{undef $/;} s/\$Id\$//smg;

# Trailing whitespaces
BEGIN{undef $/;} s/\#         \n//smg;
BEGIN{undef $/;} s/\*\* \n/\*\*\n/smg;
BEGIN{undef $/;} s/\/\*\n\*\*\n\*\*\n/\/\*\n/smg;
BEGIN{undef $/;} s/\/\* \n/\/\*\n/smg;
BEGIN{undef $/;} s/ \* \n/ \*\n/smg;
BEGIN{undef $/;} s/ \*  \n/ \*\n/smg;
BEGIN{undef $/;} s/\*\n\*  \n\*\n/\*\n/smg;
BEGIN{undef $/;} s/ \*\n \*\n \*\n/ \*\n/smg;
BEGIN{undef $/;} s/ \*\n \*\/\n/ \*\/\n/smg;
BEGIN{undef $/;} s/\/\/  \n/\/\/\n/smg;
BEGIN{undef $/;} s/ \*\n \*\n/ \*\n/smg;

BEGIN{undef $/;} s/\/\/\n\/\/\n/\/\/\n/smg;
BEGIN{undef $/;} s/ \n/\n/smg;

BEGIN{undef $/;} s/\/\/ cvs-id    :\n//smg;

# Empty header
BEGIN{undef $/;} s/\/\*\n \*\/\n//smg;
BEGIN{undef $/;} s/\/\*\*\n \*\/\n//smg;
BEGIN{undef $/;} s/\/\*\*\n \*\n \*\/\n//smg;
BEGIN{undef $/;} s/\/\*\*\n\*\n\*\/\n//smg;


eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
    & eval 'exec perl -S $0 $argv:q'
    if 0;
#########################################################################
# FOCUS: A Feature Oriented Customization tool for ACE+TAO.
#
# Usage:
# ======
# --prefix-path - gives the prefix to the place where ACE+TAO is installed
# --reactor-spl - provide the component that needs to be specialized
# --protocol-spl - provide the concrete protocol to specialize
# --output-prefix-path -
#                  (Optional) if specified, copies all the files to the
#                  output prefix. The directory structure is maintained.
#                  That is if foo/bar.h file was specialized. Then the
#                  output will be <prefix_output>/foo/bar.h
#
# Adding New Specializations
# ===========================
# (1) Add a new command line option if the specialization belongs to a
#     new family of components. For example, Concurrency strategy
# (1.b) If not, then enhance exisiting option with a new value
# (2) Associate a specialization file for the concrete component being
#     specialized.
# (3) Update the specializations directory appropriately to add the
#     specializations file.
#
# @author Arvind S. Krishna <arvindk@dre.vanderbilt.edu>
#
########################################################################
use Getopt::Long;

# This script can be invoked from anywhere. We need to add this to the
# path
use lib "$ENV{ACE_ROOT}/bin";

use FOCUS::Parser::FOCUSParser;

sub usage
{

  # How to use FOCUS
  # Currently FOCUS supports the specialization of reactor and protocol
  # families
  my $usage = "usage: \n ./FOCUS "
              . " \n --prefix-path=<path to module root>"
              . " [\n --reactor-spl=<select-mt, select-st, tp-reactor>"
              . " \n --protocol-spl=<iiop>"
              . " \n --wait-strategy-spl=<rw, lf>"
              . " \n --output-prefix=<output path>"
              . " \n --context-specific-optimizations=<dispatch>"
              . " \n ]"
              . "\n";
  print "$usage \n";
}

# Global Table that maps the specialization name to the file
# select => "../specializations/Reactor_Family/Select_Reactor.spl
# For each component that one needs to specialize add an entry in
# this simple global table to execute the specializations.

# Get the ACE_ROOT ENV variable. Then the specializations
# can be accessed via $ACE_ROOT/bin/FOCUS/.....
my $spl_prefix_path = "";
if (defined $ENV{"ACE_ROOT"})
{
  $spl_prefix_path = $ENV{"ACE_ROOT"};

  # Check if the prefix path ends with a / or not
  # if it does not then manually add the / to it
  my $last = substr ($spl_prefix_path, -1);
  if ($last ne "/")
  {
    $spl_prefix_path = $spl_prefix_path . "/";
  }

  # Add the bin/FOCUS directory to the prefix path
  $spl_prefix_path = $spl_prefix_path . "bin/FOCUS/";

}
else
{
  print "FOCUS: ACE_ROOT environment variable not defined. Exiting... \n";
  exit 1;
}

my %specialization_table  = (
 "select-mt", $spl_prefix_path . "specializations/Reactor_Family/Select_Reactor_MT.spl",
 "select-st", $spl_prefix_path . "specializations/Reactor_Family/Select_Reactor_ST.spl",
 "tp-reactor",$spl_prefix_path . "specializations/Reactor_Family/TP_Reactor.spl",
 "iiop", $spl_prefix_path . "specializations/Protocol_Family/IIOP/iiop.spl",
 "rw",   $spl_prefix_path . "specializations/Wait_Strategy/Wait_On_Read.spl",
 "lf",   $spl_prefix_path . "specializations/Wait_Strategy/Wait_On_Leader_Follower.spl",
 "dispatch", $spl_prefix_path . "specializations/Context-Specific-Optimizations/Dispatch-Resolution-Optimization.spl");

# Get the command line options
my $ret = GetOptions ("prefix-path=s"   => \$prefix_path,
                      "reactor-spl=s"   => \$reactor_type,
                      "protocol-spl=s"  => \$protocol_type,
                      "wait-strategy-spl=s" => \$wait_strat_type,
                      "output-prefix:s" => \$output_prefix,
                      "context-specific-optimizations=s" => \$context_opt);

# Check if the prefix path is specified
if (!$prefix_path)
{
  usage;
  exit 1;
}

#
# Check if the optional outputpath is specified
# if it not specified then the output_prefix will
# be same as the prefix_path.
# So if the prefix is something like:
# /build/arvindk/ACE_wrappers, then the output_prefix
# will be the same.
#
# Upshot: The source files will be directly replaced.
#
if (! $output_prefix)
{
  $output_prefix = $prefix_path;
}

# Check if the type of each component specialized is valid!
if ($reactor_type)
{
  my $spl_file = $specialization_table {$reactor_type};
  if (! length ($spl_file))
  {
    print "Invalid reactor type specified \n";
    usage;
    exit 1;
  }

  # specialize the Reactor component
  FOCUSParser::Specialize_Components ($prefix_path, $spl_file, $output_prefix);
}

# protocol specialization
if ($protocol_type)
{
  my $spl_file = $specialization_table {$protocol_type};
  if (! spl_file)
  {
    print "Invalid reactor type specified \n";
    usage;
    exit 1;
  }

  # specialize the Protocol component
  FOCUSParser::Specialize_Components ($prefix_path, $spl_file, $output_prefix);
}

# Wait Strategy specialization
if ($wait_strat_type)
{
  my $spl_file = $specialization_table {$wait_strat_type};
  if (! spl_file)
  {
    print "Invalid specialization for the Wait strategy \n";
    usage;
    exit 1;
  }

  # specialize the wait strategy
  FOCUSParser::Specialize_Components ($prefix_path, $spl_file, $output_prefix);
}

# Context specific optimizations present
if ($context_opt)
{
  my $spl_file = $specialization_table {$context_opt};
  if (! spl_file)
  {
    print "Invalid Context specialization optimization specified\n";
    usage;
    exit 1;
  }

  # specialize the wait strategy
  FOCUSParser::Specialize_Components ($prefix_path, $spl_file, $output_prefix);
}


eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
    & eval 'exec perl -S $0 $argv:q'
    if 0;

# -*- perl -*-

use lib "$ENV{ACE_ROOT}/bin";
use PerlACE::TestTarget;

my $server = PerlACE::TestTarget::create_target (1) || die "Create target 1 failed\n";

$SV = $server->CreateProcess ("test");

$test = $SV->SpawnWaitKill ($server->ProcessStartWaitInterval());

if ($test != 0) {
    print STDERR "ERROR: test returned $test\n";
    exit 1;
}

exit 0;


#! /usr/bin/perl
eval '(exit $?0)' && eval 'exec perl -w -S $0 ${1+"$@"}'
    & eval 'exec perl -w -S $0 $argv:q'
    if 0;

#
# Summarizes results from a series of runs of run_test, with
# different numbers of clients.  Example usage:
#
# $ for i in 1 2 5 10 15 20 25 30 35 40 45 50; do ./run_test $i; done
# $ ./summarize
#
# The first three lines above let this script run without specifying the
# full path to perl, as long as it is in the user's PATH.
# Taken from perlrun man page.

@files = glob 'client-*.log';
@total_threads = ();

foreach $file (@files) {
  my ($i);
  ($i = $file) =~ s/client-(\d+).log/$1/;
  push @total_threads, $i;
}

print "No.of threads\t\tAverage Latency\n\n";

foreach $total_threads (sort {$a <=> $b} @total_threads) {
  undef $high_latency;

  $high_latency = 0;
  open (FILE, "client-${total_threads}.log")  ||
    die "$0: unable to open \"client-${total_threads}.log\"\n";
  while ($line = <FILE>) {
    if ($line =~ /.*usec-per-message = ([\d\.]+)/)
    {
        $high_latency  += $1 ;
	$number++;
    }
  }
  close FILE;

  printf "%3d\t\t\t%8f\n",
    $total_threads, $high_latency/$number;
}


eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
    & eval 'exec perl -S $0 $argv:q'
    if 0;

# -*- perl -*-

use lib "$ENV{ACE_ROOT}/bin";
use PerlACE::TestTarget;

$iorfile = PerlACE::LocalFile ("ior");

unlink $iorfile;
$status = 0;

$CL = new PerlACE::Process ("diffserv_test", "localhost 20002");
$SV = new PerlACE::Process ("server");

$server = $SV->Spawn ();
$SV->TimedWait(2);

$client = $CL->SpawnWaitKill (200);

if ($client != 0) {
    $time = localtime;
    print STDERR "ERROR: client returned $client at $time\n";
    $status = 1;
}

$server = $SV->WaitKill (400);

if ($server != 0) {
    $time = localtime;
    print STDERR "ERROR: server returned $server at $time\n";
    $status = 1;
}

unlink $iorfile;

exit $status;


eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
     & eval 'exec perl -S $0 $argv:q'
     if 0;

# -*- perl -*-

use lib "$ENV{ACE_ROOT}/bin";
use PerlACE::TestTarget;

$status = 0;

$SV = new PerlACE::Process ("server", "");
$CL1 = new PerlACE::Process ("client", "80 100");
$CL2 = new PerlACE::Process ("client", "80 100");
$SV->Spawn ();

sleep (1);

$client1 = $CL1->Spawn ();

if ($client1 != 0) {
    print STDERR "ERROR: client 1 returned $client1\n";
    $status = 1;
}

$client2 = $CL2->Spawn ();

if ($client2 != 0) {
    print STDERR "ERROR: client 2 returned $client2\n";
    $status = 1;
}

$server = $SV->WaitKill (1000);

if ($server != 0) {
    print STDERR "ERROR: server returned $server\n";
    $status = 1;
}

exit $status;


eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
    & eval 'exec perl -S $0 $argv:q'
    if 0;

# -*- perl -*-

use lib "$ENV{ACE_ROOT}/bin";
use PerlACE::TestTarget;

#
# These tests only run on Win32
#
if ($^O ne "MSWin32") {
    exit;
}

@tests =
    (
     "Abandoned",
     "APC",
#    "Console_Input",            # This test is interactive
     "Directory_Changes",
     "Exceptions",
     "Handle_Close",
     "Multithreading",
#    "Network_Events",           # This test is interactive
     "Prerun_State_Changes",
     "Registration",
     "Registry_Changes",
     "Removals",
     "Suspended_Removals",
#    "Talker",                   # This test is interactive
     "Timeouts",
     "Window_Messages",
     );

my $target = PerlACE::TestTarget::create_target (1) || die "Create target 1 failed\n";;
$test_timeout = 60 + $target->ProcessStartWaitInterval();

for $test (@tests) {
    print STDOUT "\n________________________________________\n";
    print STDOUT "\nStarting test \"$test\"";
    print STDOUT "\n________________________________________\n\n";

    my $test_process = $target->CreateProcess($test);

    if (! -e $test_process->Executable ()) {
        print STDERR "Error: " . $test_process->Executable () .
                     " does not exist or is not runnable\n";
    } else {
       $test_process->Spawn ();
       $test_result = $test_process->WaitKill ($test_timeout);

       if ($test_result != 0) {
           print STDERR "\n________________________________________\n";
           print STDERR "\nERROR: \"$test\" returned $test_result";
           print STDERR "\n________________________________________\n";
       }
    }
    print STDOUT "\n________________________________________\n";
    print STDOUT "\n\"$test\" completed";
    print STDOUT "\n________________________________________\n";
}