1 # classes.pl - A perl program to generate most of the contents of
2 # javaprims.h automatically.
4 # Copyright (C) 1998, 1999, 2000, 2002 Red Hat, Inc.
6 # This file is part of libjava.
8 # This software is copyrighted work licensed under the terms of the
9 # Libjava License. Please consult the file "LIBJAVA_LICENSE" for
12 # Usage: cd <top-srcdir> ; perl classes.pl.
13 # Can also be run from the `include' directory; this lets us
14 # more easily insert the output into javaprims.h (which is where it goes).
28 die "couldn't find java directory\n";
37 local ($dir, $indent) = @_;
38 local (@subdirs) = ();
39 local (%classes) = ();
41 local ($d) = new DirHandle
$dir;
46 while (defined ($name = $d->read))
48 next if $name eq 'CVS';
50 next if $name eq '..';
56 # We only generate decls for java.lang, java.io, and
60 if (-d
($dir . '/' . $name))
62 push (@subdirs, $name);
65 next unless $name =~ /\.java$/;
67 open (FILE
, "< $dir/$name");
68 local ($outer, $classname);
72 # NOTE: we don't skip `/*' comments. However, we do
73 # skip lines with a `*' with leading whitespace. This
74 # catches the most important cases.
77 # For now assume that class names start with upper
79 next unless /\b(class|interface) ([A-Z][A-Za-z0-9]+)/;
82 # We assume the code is properly indented, so that we
83 # can print inner classes properly.
86 die "no outer class for $classname in $dir/$name"
88 $classes{$outer . "\$" . $classname} = 1;
92 $classes{$classname} = 1;
102 local ($spaces) = ' ' x
$indent;
104 ($classname = $dir) =~ s/^.*\///;
105 print $spaces, "namespace ", $classname, "\n";
106 print $spaces, "{\n";
108 foreach (sort keys %classes)
110 print $spaces, " class ", $_, ";\n";
112 print "\n" if scalar @classes > 0 && scalar @subdirs > 0;
115 foreach (sort @subdirs)
117 print "\n" unless $first;
119 &scan
("$dir/$_", $indent + 2);
122 print $spaces, "}\n";