2016-07-13 Thomas Preud'homme <thomas.preudhomme@arm.com>
[official-gcc.git] / libjava / classpath / lib / mkcollections.pl.in
blob2c80aa1def7411d7ce30fb616e196f28a080c968
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 Iterable);
30 my @javautilclasses=qw(AbstractCollection
31 AbstractList
32 AbstractMap
33 AbstractSequentialList
34 AbstractSet
35 ArrayList
36 Arrays
37 List
38 Collection
39 Collections
40 Comparator
41 ConcurrentModificationException
42 HashMap
43 HashSet
44 Hashtable
45 Iterator
46 LinkedList
47 ListIterator
48 Map
49 NoSuchElementException
50 Random
51 RandomAccess
52 Set
53 SortedMap
54 SortedSet
55 TreeMap
56 TreeSet
57 Vector);
58 my @externalclasses=qw(AbstractQueue
59 ArrayDeque
60 Deque
61 NavigableMap
62 NavigableSet
63 Queue);
65 my $destPkg = $destpath;
66 $destPkg =~ s!/!.!g;
68 my %imports = ( "Collections" => [ "Enumeration" ],
69 "Hashtable" => [ "Dictionary", "Enumeration" ],
70 "Vector" => [ "Enumeration" ]);
73 sub mymkdir ($)
75 my ($dir) = @_;
76 if ($dir =~ /^(.*)\/\w+$/)
78 $parentdir = "$1";
79 if (! (-d $parentdir))
81 mymkdir ($parentdir);
84 print "$dir";
85 mkdir ($dir, 0777);
88 sub convert($$$) {
89 my ($file, $infile, $outfile) = @_;
91 open (INPUT, "<$infile") || die "Could not open ", $infile, " for reading\n";
93 my $dir = "$outfile";
94 $dir =~ /^(.*)\/\S+\.java$/ and
95 $dir = "$1";
96 if (! (-d $dir)) {
97 mymkdir ($dir);
100 open (OUTPUT, ">$outfile") || die "Could not open ", $outfile, " for writing\n";
101 print OUTPUT <<'EOF';
102 /* This file was converted from the GNU Classpath Project by a
103 * perl script, written by Jochen Hoenicke <jochen\@gnu.org>.
106 while (<INPUT>) {
107 $_ = "package $destPkg;\n" if ($_ =~ /^package java.(lang|util);$/);
109 next if $_ =~ /^import java.io.Object.*putStream.*Field;$/;
110 next if $_ =~ /^import java.io.ObjectStreamField;$/;
112 for $clazz (@javalangclasses) {
113 $_ =~ s/java.lang.$clazz/$clazz/g;
115 for $clazz (@javautilclasses) {
116 $_ =~ s/java.util.$clazz/$clazz/g;
118 for $clazz (@externalclasses) {
119 $_ =~ s/java.util.$clazz/$clazz/g;
122 $_ =~ s/abstract (interface)/$1/g;
124 print OUTPUT $_;
125 if ($_ =~ /^package $destPkg;$/
126 && exists $imports{$file}) {
127 for $imp (@{$imports{$file}}) {
128 print OUTPUT "import java.util.$imp;\n";
132 close (OUTPUT);
133 close (INPUT);
136 my $file;
138 for $file (@javalangclasses) {
139 my $infile = "$classpath/java/lang/$file.java";
140 my $outfile = "$destpath/$file.java";
141 print "$outfile\n";
142 convert ($file, $infile, $outfile);
145 for $file (@javautilclasses) {
146 my $infile = "$classpath/java/util/$file.java";
147 my $outfile = "$destpath/$file.java";
148 print "$outfile\n";
149 convert ($file, $infile, $outfile);
152 for $file (@externalclasses) {
153 my $infile = "$classpath/external/jsr166/java/util/$file.java";
154 my $outfile = "$destpath/$file.java";
155 print "$outfile\n";
156 convert ($file, $infile, $outfile);