blob: 1c344dacabd65e5e29200093ef2e1285b7734b28 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001#! /bin/sh
2
3#
4# Copyright 2004-2005 Sun Microsystems, Inc. All Rights Reserved.
5# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6#
7# This code is free software; you can redistribute it and/or modify it
8# under the terms of the GNU General Public License version 2 only, as
9# published by the Free Software Foundation. Sun designates this
10# particular file as subject to the "Classpath" exception as provided
11# by Sun in the LICENSE file that accompanied this code.
12#
13# This code is distributed in the hope that it will be useful, but WITHOUT
14# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16# version 2 for more details (a copy is included in the LICENSE file that
17# accompanied this code).
18#
19# You should have received a copy of the GNU General Public License version
20# 2 along with this work; if not, write to the Free Software Foundation,
21# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
22#
23# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
24# CA 95054 USA or visit www.sun.com if you need additional information or
25# have any questions.
26#
27
28# Generate a charset provider class
29
30# Required environment variables
31# NAWK awk tool
32# TEMPDIR temporary directory
33# HASHER Hasher program
34
35SPEC=$1; shift
36DST=$1; shift
37
38eval `$NAWK <$SPEC '
39 /^[ \t]*copyright / { printf "COPYRIGHT_YEARS=%s\n", $2; }
40 /^[ \t]*package / { printf "PKG=%s\n", $2; }
41 /^[ \t]*class / { printf "CLASS=%s\n", $2; }
42'`
43
44OUT=$DST/$CLASS.java
45echo '-->' $OUT
46
47
48# Header
49#
50
51$SHELL addNotices.sh "$COPYRIGHT_YEARS" > $OUT
52
53cat <<__END__ >>$OUT
54
55// -- This file was mechanically generated: Do not edit! -- //
56
57package $PKG;
58
59import java.nio.charset.*;
60
61
62public class $CLASS
63 extends FastCharsetProvider
64{
65
66__END__
67
68
69# Alias tables
70#
71$NAWK <$SPEC >>$OUT '
72 BEGIN { n = 1; m = 1; }
73
74 /^[ \t]*charset / {
75 csn = $2; cln = $3;
76 lcsn = tolower(csn);
77 lcsns[n++] = lcsn;
78 csns[lcsn] = csn;
79 classMap[lcsn] = cln;
80 if (n > 2)
81 printf " };\n\n";
82 printf " static final String[] aliases_%s = new String[] {\n", cln;
83 }
84
85 /^[ \t]*alias / {
86 acsns[m++] = tolower($2);
87 aliasMap[tolower($2)] = lcsn;
88 printf " \"%s\",\n", $2;
89 }
90
91 END {
92 printf " };\n\n";
93 }
94'
95
96
97# Prehashed alias and class maps
98#
99$NAWK <$SPEC >$TEMPDIR/aliases '
100 /^[ \t]*charset / {
101 csn = $2;
102 lcsn = tolower(csn);
103 }
104 /^[ \t]*alias / {
105 an = tolower($2);
106 printf "%-20s \"%s\"\n", an, lcsn;
107 }
108'
109
110$NAWK <$SPEC >$TEMPDIR/classes '
111 /^[ \t]*charset / {
112 csn = $2; cln = $3;
113 lcsn = tolower(csn);
114 printf "%-20s \"%s\"\n", lcsn, cln;
115 }
116'
117
118${HASHER} -i Aliases <$TEMPDIR/aliases >>$OUT
119${HASHER} -i Classes <$TEMPDIR/classes >>$OUT
120${HASHER} -i -e Cache -t Charset <$TEMPDIR/classes >>$OUT
121
122
123# Constructor
124#
125cat <<__END__ >>$OUT
126 public $CLASS() {
127 super("$PKG", new Aliases(), new Classes(), new Cache());
128 }
129
130}
131__END__