2008-06-04 Xinliang David Li <davidxl@google.com>
[official-gcc.git] / libjava / scripts / classes.pl
blob761506fb6c9d68615590c46c7bad37565a2fda16
1 # classes.pl - A perl program to generate most of the contents of
2 # javaprims.h automatically.
4 # Copyright (C) 1998, 1999, 2000, 2002, 2005, 2006, 2007 Free Software
5 # Foundation
7 # This file is part of libgcj.
9 # This software is copyrighted work licensed under the terms of the
10 # Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
11 # details.
13 # Usage: cd <srcdir>/classpath/lib ; perl ../../scripts/classes.pl.
15 use DirHandle;
17 if (-d 'java')
19 # Ok here.
21 elsif (-d '../java')
23 chdir ('..');
25 else
27 die "couldn't find java directory\n";
30 &scan ('java', 2);
32 exit 0;
34 sub scan
36 local ($dir, $indent) = @_;
37 local (@subdirs) = ();
38 local (%classes) = ();
40 local ($d) = new DirHandle $dir;
41 local (*JFILE);
42 local ($name);
43 if (defined $d)
45 while (defined ($name = $d->read))
47 next if $name eq 'CVS';
48 next if $name eq '.svn';
49 next if $name eq '.';
50 next if $name eq '..';
51 if ($dir eq 'java'
52 && $name ne 'lang'
53 && $name ne 'util'
54 && $name ne 'io')
56 # We only generate decls for java.lang, java.io, and
57 # java.util.
58 next;
60 if (-d ($dir . '/' . $name))
62 push (@subdirs, $name);
63 next;
65 next unless $name =~ s/\.class$//;
66 $classes{$name} = 1;
69 undef $d;
72 local ($spaces) = ' ' x $indent;
73 local ($classname);
74 ($classname = $dir) =~ s/^.*\///;
75 print $spaces, "namespace ", $classname, "\n";
76 print $spaces, "{\n";
78 foreach (sort keys %classes)
80 print $spaces, " class ", $_, ";\n";
82 print "\n" if scalar @classes > 0 && scalar @subdirs > 0;
84 local ($first) = 1;
85 foreach (sort @subdirs)
87 print "\n" unless $first;
88 $first = 0;
89 &scan ("$dir/$_", $indent + 2);
92 print $spaces, "}\n";