blob: 45033493f98b5c6d4e9d80d4e69e1071ea669e8c [file] [log] [blame]
ohair92de5662012-04-10 08:22:03 -07001#! /bin/sh
2
3#
alanb0d058232012-11-02 15:50:11 +00004# Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
ohair92de5662012-04-10 08:22:03 -07005# 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. Oracle designates this
10# particular file as subject to the "Classpath" exception as provided
11# by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
24# or visit www.oracle.com if you need additional information or have any
25# 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 %s\"\n", $2, $3; }
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
erikje78df742012-06-07 20:40:50 -070051$SH ${SCRIPTS}/addNotices.sh "$COPYRIGHT_YEARS" > $OUT
ohair92de5662012-04-10 08:22:03 -070052
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__