* Makefile.in (dbxout.o): Depend on ggc.h.
[official-gcc.git] / libjava / classes.pl
blob5a19a5e009f445dfc52077ab09f4e41ceb8a020d
1 # classes.pl - A perl program to generate most of the contents of
2 # javaprims.h automatically.
4 # Copyright (C) 1998, 1999 Cygnus Solutions
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
10 # details.
12 # Usage: cd <top-srcdir> ; perl classes.pl.
13 # Can also be run from the `gcj' directory; this lets us
14 # more easily insert the output into javaprims.h (which is where it goes).
16 use DirHandle;
18 if (-d 'java')
20 # Ok here.
22 elsif (-d '../java')
24 chdir ('..');
26 else
28 die "couldn't find java directory\n";
31 &scan ('java', 2);
33 exit 0;
35 sub scan
37 local ($dir, $indent) = @_;
38 local (@subdirs) = ();
39 local (%classes) = ();
41 local ($d) = new DirHandle $dir;
42 local (*JFILE);
43 local ($name);
44 if (defined $d)
46 while (defined ($name = $d->read))
48 next if $name eq 'CVS';
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 =~ /\.java$/;
67 open (FILE, "< $dir/$name");
68 while (<FILE>)
70 # NOTE: we don't skip `/*' comments.
71 s,//.*$,,;
72 # For now assume that class names start with upper
73 # case letter.
74 next unless /(class|interface) ([A-Z][A-Za-z0-9]+)/;
75 $classes{$2} = 1;
77 close (FILE);
80 undef $d;
83 local ($spaces) = ' ' x $indent;
84 local ($classname);
85 ($classname = $dir) =~ s/^.*\///;
86 print $spaces, "namespace ", $classname, "\n";
87 print $spaces, "{\n";
89 foreach (sort keys %classes)
91 print $spaces, " class ", $_, ";\n";
93 print "\n" if scalar @classes > 0 && scalar @subdirs > 0;
95 local ($first) = 1;
96 foreach (sort @subdirs)
98 print "\n" unless $first;
99 $first = 0;
100 &scan ("$dir/$_", $indent + 2);
103 print $spaces, "}\n";