classes.pl 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # classes.pl - A perl program to generate most of the contents of
  2. # javaprims.h automatically.
  3. # Copyright (C) 1998, 1999, 2000, 2002, 2005, 2006, 2007 Free Software
  4. # Foundation
  5. #
  6. # This file is part of libgcj.
  7. #
  8. # This software is copyrighted work licensed under the terms of the
  9. # Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
  10. # details.
  11. # Usage: cd <srcdir>/classpath/lib ; perl ../../scripts/classes.pl.
  12. use DirHandle;
  13. if (-d 'java')
  14. {
  15. # Ok here.
  16. }
  17. elsif (-d '../java')
  18. {
  19. chdir ('..');
  20. }
  21. else
  22. {
  23. die "couldn't find java directory\n";
  24. }
  25. &scan ('java', 2);
  26. exit 0;
  27. sub scan
  28. {
  29. local ($dir, $indent) = @_;
  30. local (@subdirs) = ();
  31. local (%classes) = ();
  32. local ($d) = new DirHandle $dir;
  33. local (*JFILE);
  34. local ($name);
  35. if (defined $d)
  36. {
  37. while (defined ($name = $d->read))
  38. {
  39. next if $name eq 'CVS';
  40. next if $name eq '.svn';
  41. next if $name eq '.';
  42. next if $name eq '..';
  43. if ($dir eq 'java'
  44. && $name ne 'lang'
  45. && $name ne 'util'
  46. && $name ne 'io')
  47. {
  48. # We only generate decls for java.lang, java.io, and
  49. # java.util.
  50. next;
  51. }
  52. if (-d ($dir . '/' . $name))
  53. {
  54. push (@subdirs, $name);
  55. next;
  56. }
  57. next unless $name =~ s/\.class$//;
  58. $classes{$name} = 1;
  59. }
  60. undef $d;
  61. }
  62. local ($spaces) = ' ' x $indent;
  63. local ($classname);
  64. ($classname = $dir) =~ s/^.*\///;
  65. print $spaces, "namespace ", $classname, "\n";
  66. print $spaces, "{\n";
  67. foreach (sort keys %classes)
  68. {
  69. print $spaces, " class ", $_, ";\n";
  70. }
  71. print "\n" if scalar @classes > 0 && scalar @subdirs > 0;
  72. local ($first) = 1;
  73. foreach (sort @subdirs)
  74. {
  75. print "\n" unless $first;
  76. $first = 0;
  77. &scan ("$dir/$_", $indent + 2);
  78. }
  79. print $spaces, "}\n";
  80. }