classes.pl 1.75 KB
Newer Older
Tom Tromey committed
1 2 3
# classes.pl - A perl program to generate most of the contents of
# javaprims.h automatically.

4 5
# Copyright (C) 1998, 1999, 2000, 2002, 2005, 2006, 2007  Free Software
# Foundation
Tom Tromey committed
6
#
Tom Tromey committed
7
# This file is part of libgcj.
Tom Tromey committed
8 9
#
# This software is copyrighted work licensed under the terms of the
Tom Tromey committed
10
# Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
Tom Tromey committed
11 12
# details.

13
# Usage: cd <srcdir>/classpath/lib ; perl ../../scripts/classes.pl.
Tom Tromey committed
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37

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) = ();
38
    local (%classes) = ();
Tom Tromey committed
39 40 41 42 43 44 45 46 47

    local ($d) = new DirHandle $dir;
    local (*JFILE);
    local ($name);
    if (defined $d)
    {
	while (defined ($name = $d->read))
	{
	    next if $name eq 'CVS';
48
	    next if $name eq '.svn';
Tom Tromey committed
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
	    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;
	    }
Tom Tromey committed
65 66
	    next unless $name =~ s/\.class$//;
	    $classes{$name} = 1;
Tom Tromey committed
67 68 69 70 71 72 73 74 75 76 77
	}

	undef $d;
    }

    local ($spaces) = ' ' x $indent;
    local ($classname);
    ($classname = $dir) =~ s/^.*\///;
    print $spaces, "namespace ", $classname, "\n";
    print $spaces, "{\n";

78
    foreach (sort keys %classes)
Tom Tromey committed
79 80 81 82 83 84 85 86 87 88 89 90 91
    {
	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);
    }

Tom Tromey committed
92
    print $spaces, "}\n";
Tom Tromey committed
93
}