summaryrefslogtreecommitdiff
path: root/lib/mkcollections.pl.in
blob: ea34a39f2588c61436571dd1900a20ebf23fe266 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!@PERL@
#
# mkcollections.pl - small perl script to convert GNU Classpath's
#                    Collection classes into its own package for java 1.1
#
# USAGE: mkcollections.pl <Destination-Path>
#
# Copyright (C) 2000 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING.  If not, write to
# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.

my $destpath=pop || "gnu/java/util/collections";
my $classpath="..";
my @javalangclasses=qw(UnsupportedOperationException
		       Comparable);
my @javautilclasses=qw(AbstractCollection
		       AbstractList
		       AbstractMap
		       AbstractSequentialList
		       AbstractSet
		       ArrayList
		       Arrays
		       BasicMapEntry
		       List
		       Collection
		       Collections
		       Comparator
		       ConcurrentModificationException
		       HashMap
		       HashSet
		       Hashtable
		       Iterator
		       LinkedList
		       ListIterator
		       Map
		       NoSuchElementException
		       Random
		       Set
		       SortedMap
		       SortedSet
		       TreeMap
		       TreeSet
		       Vector);

my $destPkg = $destpath;
$destPkg  =~ s!/!.!g;

my %imports = ( "Collections" => [ "Enumeration" ],
		"Hashtable" => [ "Dictionary", "Enumeration" ],
		"Vector" => [ "Enumeration" ]);


sub mymkdir ($)
  {
    my ($dir) = @_;
    if ($dir =~ /^(.*)\/\w+$/)
      {
	$parentdir = "$1";
	if (! (-d $parentdir))
	  { 
	    mymkdir ($parentdir);
	  }
      }
    print "$dir";
    mkdir ($dir, 0777);
  }

sub convert($$$) {
    my ($file, $infile, $outfile) = @_;

    open (INPUT, "<$infile") || die "Could not open ", $infile, " for reading\n";

    my $dir = "$outfile";
    $dir =~ /^(.*)\/\S+\.java$/ and
	$dir = "$1";
    if (! (-d $dir)) { 
	mymkdir ($dir); 
    }
 
    open (OUTPUT, ">$outfile") || die "Could not open ", $outfile, " for writing\n";
    print OUTPUT <<'EOF';
/* This file was converted from the GNU Classpath Project by a
 * perl script, written by Jochen Hoenicke <jochen\@gnu.org>.
 */
EOF
    while (<INPUT>) {
	$_ = "package $destPkg;\n" if ($_ =~ /^package java.(lang|util);$/);

	next if $_ =~ /^import java.io.Object.*putStream.*Field;$/;
	next if $_ =~ /^import java.io.ObjectStreamField;$/;

	for $clazz (@javalangclasses) {
	    $_ =~ s/java.lang.$clazz/$clazz/g;
	}
	for $clazz (@javautilclasses) {
	    $_ =~ s/java.util.$clazz/$clazz/g;
	}

	$_ =~ s/abstract (interface)/$1/g;

	print OUTPUT $_;
	if ($_ =~ /^package $destPkg;$/
	    && exists $imports{$file}) {
	    for $imp (@{$imports{$file}}) {
		print OUTPUT "import java.util.$imp;\n";
	    }
	}
    }
    close (OUTPUT);
    close (INPUT);
}

my $file;

for $file (@javalangclasses) {
    my $infile = "$classpath/java/lang/$file.java";
    my $outfile = "$destpath/$file.java";
    print "$outfile\n";
    convert ($file, $infile, $outfile);
}

for $file (@javautilclasses) {
    my $infile = "$classpath/java/util/$file.java";
    my $outfile = "$destpath/$file.java";
    print "$outfile\n";
    convert ($file, $infile, $outfile);
}