PR target/27599
[official-gcc.git] / libjava / classpath / lib / mkcollections.pl.in
blobbd00f01f29e8047009797dcf8c791cba52f8a879
1 #!@PERL@
3 # mkcollections.pl - small perl script to convert GNU Classpath's
4 # Collection classes into its own package for java 1.1
6 # USAGE: mkcollections.pl <Destination-Path>
8 # Copyright (C) 2000 Free Software Foundation, Inc.
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2, or (at your option)
13 # any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program; see the file COPYING. If not, write to
22 # the Free Software Foundation, 51 Franklin St, Fifth Floor,
23 # Boston, MA 02110-1301 USA
25 my $destpath=@COLLECTIONS_PREFIX@;
26 my $classpath=pop;
27 my @javalangclasses=qw(UnsupportedOperationException
28 Comparable);
29 my @javautilclasses=qw(AbstractCollection
30 AbstractList
31 AbstractMap
32 AbstractSequentialList
33 AbstractSet
34 ArrayList
35 Arrays
36 List
37 Collection
38 Collections
39 Comparator
40 ConcurrentModificationException
41 HashMap
42 HashSet
43 Hashtable
44 Iterator
45 LinkedList
46 ListIterator
47 Map
48 NoSuchElementException
49 Random
50 RandomAccess
51 Set
52 SortedMap
53 SortedSet
54 TreeMap
55 TreeSet
56 Vector);
58 my $destPkg = $destpath;
59 $destPkg =~ s!/!.!g;
61 my %imports = ( "Collections" => [ "Enumeration" ],
62 "Hashtable" => [ "Dictionary", "Enumeration" ],
63 "Vector" => [ "Enumeration" ]);
66 sub mymkdir ($)
68 my ($dir) = @_;
69 if ($dir =~ /^(.*)\/\w+$/)
71 $parentdir = "$1";
72 if (! (-d $parentdir))
74 mymkdir ($parentdir);
77 print "$dir";
78 mkdir ($dir, 0777);
81 sub convert($$$) {
82 my ($file, $infile, $outfile) = @_;
84 open (INPUT, "<$infile") || die "Could not open ", $infile, " for reading\n";
86 my $dir = "$outfile";
87 $dir =~ /^(.*)\/\S+\.java$/ and
88 $dir = "$1";
89 if (! (-d $dir)) {
90 mymkdir ($dir);
93 open (OUTPUT, ">$outfile") || die "Could not open ", $outfile, " for writing\n";
94 print OUTPUT <<'EOF';
95 /* This file was converted from the GNU Classpath Project by a
96 * perl script, written by Jochen Hoenicke <jochen\@gnu.org>.
98 EOF
99 while (<INPUT>) {
100 $_ = "package $destPkg;\n" if ($_ =~ /^package java.(lang|util);$/);
102 next if $_ =~ /^import java.io.Object.*putStream.*Field;$/;
103 next if $_ =~ /^import java.io.ObjectStreamField;$/;
105 for $clazz (@javalangclasses) {
106 $_ =~ s/java.lang.$clazz/$clazz/g;
108 for $clazz (@javautilclasses) {
109 $_ =~ s/java.util.$clazz/$clazz/g;
112 $_ =~ s/abstract (interface)/$1/g;
114 print OUTPUT $_;
115 if ($_ =~ /^package $destPkg;$/
116 && exists $imports{$file}) {
117 for $imp (@{$imports{$file}}) {
118 print OUTPUT "import java.util.$imp;\n";
122 close (OUTPUT);
123 close (INPUT);
126 my $file;
128 for $file (@javalangclasses) {
129 my $infile = "$classpath/java/lang/$file.java";
130 my $outfile = "$destpath/$file.java";
131 print "$outfile\n";
132 convert ($file, $infile, $outfile);
135 for $file (@javautilclasses) {
136 my $infile = "$classpath/java/util/$file.java";
137 my $outfile = "$destpath/$file.java";
138 print "$outfile\n";
139 convert ($file, $infile, $outfile);