1999-04-07 16:42:40 +02:00
|
|
|
# classes.pl - A perl program to generate most of the contents of
|
|
|
|
# javaprims.h automatically.
|
|
|
|
|
2000-07-20 21:34:29 +02:00
|
|
|
# Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
|
1999-04-07 16:42:40 +02:00
|
|
|
#
|
|
|
|
# This file is part of libjava.
|
|
|
|
#
|
|
|
|
# This software is copyrighted work licensed under the terms of the
|
|
|
|
# Libjava License. Please consult the file "LIBJAVA_LICENSE" for
|
|
|
|
# details.
|
|
|
|
|
|
|
|
# Usage: cd <top-srcdir> ; perl classes.pl.
|
2000-05-19 19:55:34 +02:00
|
|
|
# Can also be run from the `include' directory; this lets us
|
1999-04-07 16:42:40 +02:00
|
|
|
# more easily insert the output into javaprims.h (which is where it goes).
|
|
|
|
|
|
|
|
use DirHandle;
|
|
|
|
|
|
|
|
if (-d 'java')
|
|
|
|
{
|
|
|
|
# Ok here.
|
|
|
|
}
|
|
|
|
elsif (-d '../java')
|
|
|
|
{
|
|
|
|
chdir ('..');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
die "couldn't find java directory\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
&scan ('java', 2);
|
|
|
|
|
|
|
|
exit 0;
|
|
|
|
|
|
|
|
sub scan
|
|
|
|
{
|
|
|
|
local ($dir, $indent) = @_;
|
|
|
|
local (@subdirs) = ();
|
1999-05-12 13:23:44 +02:00
|
|
|
local (%classes) = ();
|
1999-04-07 16:42:40 +02:00
|
|
|
|
|
|
|
local ($d) = new DirHandle $dir;
|
|
|
|
local (*JFILE);
|
|
|
|
local ($name);
|
|
|
|
if (defined $d)
|
|
|
|
{
|
|
|
|
while (defined ($name = $d->read))
|
|
|
|
{
|
|
|
|
next if $name eq 'CVS';
|
|
|
|
next if $name eq '.';
|
|
|
|
next if $name eq '..';
|
|
|
|
if ($dir eq 'java'
|
|
|
|
&& $name ne 'lang'
|
|
|
|
&& $name ne 'util'
|
|
|
|
&& $name ne 'io')
|
|
|
|
{
|
|
|
|
# We only generate decls for java.lang, java.io, and
|
|
|
|
# java.util.
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
if (-d ($dir . '/' . $name))
|
|
|
|
{
|
|
|
|
push (@subdirs, $name);
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
next unless $name =~ /\.java$/;
|
|
|
|
|
|
|
|
open (FILE, "< $dir/$name");
|
2000-07-20 21:34:29 +02:00
|
|
|
local ($outer, $classname);
|
1999-04-07 16:42:40 +02:00
|
|
|
while (<FILE>)
|
|
|
|
{
|
|
|
|
s,//.*$,,;
|
2000-12-11 22:50:39 +01:00
|
|
|
# NOTE: we don't skip `/*' comments. However, we do
|
|
|
|
# skip lines with a `*' with leading whitespace. This
|
|
|
|
# catches the most important cases.
|
|
|
|
s,^\s*\*.*$,,;
|
|
|
|
|
1999-04-07 16:42:40 +02:00
|
|
|
# For now assume that class names start with upper
|
|
|
|
# case letter.
|
2000-07-20 21:34:29 +02:00
|
|
|
next unless /\b(class|interface) ([A-Z][A-Za-z0-9]+)/;
|
|
|
|
$classname = $2;
|
|
|
|
|
|
|
|
# We assume the code is properly indented, so that we
|
|
|
|
# can print inner classes properly.
|
|
|
|
if (/^\s/)
|
|
|
|
{
|
|
|
|
die "no outer class for $classname in $dir/$name"
|
|
|
|
unless $outer;
|
|
|
|
$classes{$outer . "\$" . $classname} = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$classes{$classname} = 1;
|
|
|
|
$outer = $classname;
|
|
|
|
}
|
1999-04-07 16:42:40 +02:00
|
|
|
}
|
|
|
|
close (FILE);
|
|
|
|
}
|
|
|
|
|
|
|
|
undef $d;
|
|
|
|
}
|
|
|
|
|
|
|
|
local ($spaces) = ' ' x $indent;
|
|
|
|
local ($classname);
|
|
|
|
($classname = $dir) =~ s/^.*\///;
|
|
|
|
print $spaces, "namespace ", $classname, "\n";
|
|
|
|
print $spaces, "{\n";
|
|
|
|
|
1999-05-12 13:23:44 +02:00
|
|
|
foreach (sort keys %classes)
|
1999-04-07 16:42:40 +02:00
|
|
|
{
|
|
|
|
print $spaces, " class ", $_, ";\n";
|
|
|
|
}
|
|
|
|
print "\n" if scalar @classes > 0 && scalar @subdirs > 0;
|
|
|
|
|
|
|
|
local ($first) = 1;
|
|
|
|
foreach (sort @subdirs)
|
|
|
|
{
|
|
|
|
print "\n" unless $first;
|
|
|
|
$first = 0;
|
|
|
|
&scan ("$dir/$_", $indent + 2);
|
|
|
|
}
|
|
|
|
|
2000-05-19 19:55:34 +02:00
|
|
|
print $spaces, "};\n";
|
1999-04-07 16:42:40 +02:00
|
|
|
}
|