001: /*
002: *******************************************************************************
003: * Copyright (C) 1996-2005, International Business Machines Corporation and *
004: * others. All Rights Reserved. *
005: *******************************************************************************
006: */
007: package com.ibm.icu.dev.tool.compression;
008:
009: /**
010: * Utility class to generate the tables used by the SCSU interface and
011: * the UnicodeCompressor class.
012: *
013: * @author Stephen F. Booth
014: * @version 1.0 08 Mar 99
015: */
016: class CompressionTableGenerator {
017: // duplicate of constants in SCSU
018:
019: final static int LATININDEX = 0xF9;
020: final static int IPAEXTENSIONINDEX = 0xFA;
021: final static int GREEKINDEX = 0xFB;
022: final static int ARMENIANINDEX = 0xFC;
023: final static int HIRAGANAINDEX = 0xFD;
024: final static int KATAKANAINDEX = 0xFE;
025: final static int HALFWIDTHKATAKANAINDEX = 0xFF;
026:
027: final static int SDEFINEX = 0x0B;
028: final static int SRESERVED = 0x0C; // reserved value
029: final static int SQUOTEU = 0x0E;
030: final static int SCHANGEU = 0x0F;
031:
032: final static int SQUOTE0 = 0x01;
033: final static int SQUOTE1 = 0x02;
034: final static int SQUOTE2 = 0x03;
035: final static int SQUOTE3 = 0x04;
036: final static int SQUOTE4 = 0x05;
037: final static int SQUOTE5 = 0x06;
038: final static int SQUOTE6 = 0x07;
039: final static int SQUOTE7 = 0x08;
040:
041: final static int SCHANGE0 = 0x10;
042: final static int SCHANGE1 = 0x11;
043: final static int SCHANGE2 = 0x12;
044: final static int SCHANGE3 = 0x13;
045: final static int SCHANGE4 = 0x14;
046: final static int SCHANGE5 = 0x15;
047: final static int SCHANGE6 = 0x16;
048: final static int SCHANGE7 = 0x17;
049:
050: final static int SDEFINE0 = 0x18;
051: final static int SDEFINE1 = 0x19;
052: final static int SDEFINE2 = 0x1A;
053: final static int SDEFINE3 = 0x1B;
054: final static int SDEFINE4 = 0x1C;
055: final static int SDEFINE5 = 0x1D;
056: final static int SDEFINE6 = 0x1E;
057: final static int SDEFINE7 = 0x1F;
058:
059: //==========================
060: // Unicode mode tags
061: //==========================
062: final static int UCHANGE0 = 0xE0;
063: final static int UCHANGE1 = 0xE1;
064: final static int UCHANGE2 = 0xE2;
065: final static int UCHANGE3 = 0xE3;
066: final static int UCHANGE4 = 0xE4;
067: final static int UCHANGE5 = 0xE5;
068: final static int UCHANGE6 = 0xE6;
069: final static int UCHANGE7 = 0xE7;
070:
071: final static int UDEFINE0 = 0xE8;
072: final static int UDEFINE1 = 0xE9;
073: final static int UDEFINE2 = 0xEA;
074: final static int UDEFINE3 = 0xEB;
075: final static int UDEFINE4 = 0xEC;
076: final static int UDEFINE5 = 0xED;
077: final static int UDEFINE6 = 0xEE;
078: final static int UDEFINE7 = 0xEF;
079:
080: final static int UQUOTEU = 0xF0;
081: final static int UDEFINEX = 0xF1;
082: final static int URESERVED = 0xF2; // reserved value
083:
084: final static int BLOCKSIZE = 0xFF;
085:
086: /**
087: * Generate the table used as sOffsetTable in SCSU.
088: * This table contains preformed indices so we can do array lookups
089: * instead of calculations for speed during decompression.
090: */
091: static void printOffsetTable() {
092: int i = 0;
093: int[] offsetTable = new int[BLOCKSIZE + 1];
094:
095: // 0x00 is reserved
096:
097: // half blocks from U+0080 to U+3380
098: for (i = 0x01; i < 0x68; i++)
099: offsetTable[i] = i * 0x80;
100:
101: // half blocks from U+E000 to U+FF80
102: for (i = 0x68; i < 0xA8; i++)
103: offsetTable[i] = (i * 0x80) + 0xAC00;
104:
105: // 0xA8..0xF8 is reserved
106:
107: offsetTable[LATININDEX] = 0x00C0;
108: offsetTable[IPAEXTENSIONINDEX] = 0x0250;
109: offsetTable[GREEKINDEX] = 0x0370;
110: offsetTable[ARMENIANINDEX] = 0x0530;
111: offsetTable[HIRAGANAINDEX] = 0x3040;
112: offsetTable[KATAKANAINDEX] = 0x30A0;
113: offsetTable[HALFWIDTHKATAKANAINDEX] = 0xFF60;
114:
115: // dump the generated table
116: System.out.println("static int [] sOffsetTable = {");
117: for (i = 0; i < offsetTable.length - 1; i++)
118: System.out.print("0x" + Integer.toHexString(offsetTable[i])
119: + ", ");
120: for (i = offsetTable.length - 1; i < offsetTable.length; i++)
121: System.out
122: .print("0x" + Integer.toHexString(offsetTable[i]));
123: System.out.println();
124: System.out.println("};");
125: }
126:
127: /**
128: * Generate the table used as sSingleTagTable in UnicodeCompressor.
129: * This table contains boolean values indicating if a byte is a
130: * single-byte mode tag.
131: */
132: static void printSingleTagTable() {
133: int i = 0;
134: boolean[] singleTagTable = new boolean[BLOCKSIZE + 1];
135:
136: for (i = 0x00; i <= BLOCKSIZE; i++) {
137: switch (i) {
138:
139: case SQUOTEU:
140: case SCHANGEU:
141: case SDEFINEX:
142: case SRESERVED:
143: case SQUOTE0:
144: case SQUOTE1:
145: case SQUOTE2:
146: case SQUOTE3:
147: case SQUOTE4:
148: case SQUOTE5:
149: case SQUOTE6:
150: case SQUOTE7:
151: case SCHANGE0:
152: case SCHANGE1:
153: case SCHANGE2:
154: case SCHANGE3:
155: case SCHANGE4:
156: case SCHANGE5:
157: case SCHANGE6:
158: case SCHANGE7:
159: case SDEFINE0:
160: case SDEFINE1:
161: case SDEFINE2:
162: case SDEFINE3:
163: case SDEFINE4:
164: case SDEFINE5:
165: case SDEFINE6:
166: case SDEFINE7:
167: singleTagTable[i] = true;
168: break;
169:
170: default:
171: singleTagTable[i] = false;
172: break;
173: }
174: }
175:
176: // dump the generated table
177: System.out
178: .println("private static boolean [] sSingleTagTable = {");
179: for (i = 0; i < singleTagTable.length - 1; i++)
180: System.out.print(singleTagTable[i] + ", ");
181: for (i = singleTagTable.length - 1; i < singleTagTable.length; i++)
182: System.out.print(singleTagTable[i]);
183: System.out.println();
184: System.out.println("};");
185: }
186:
187: /**
188: * Generate the table used as sUnicodeTagTable in
189: * This table contains boolean values indicating if a byte is a
190: * unicode mode tag.
191: */
192: static void printUnicodeTagTable() {
193: int i = 0;
194: boolean[] unicodeTagTable = new boolean[BLOCKSIZE + 1];
195:
196: for (i = 0x00; i <= BLOCKSIZE; i++) {
197: switch (i) {
198: case UQUOTEU:
199: case UDEFINEX:
200: case URESERVED:
201: case UCHANGE0:
202: case UCHANGE1:
203: case UCHANGE2:
204: case UCHANGE3:
205: case UCHANGE4:
206: case UCHANGE5:
207: case UCHANGE6:
208: case UCHANGE7:
209: case UDEFINE0:
210: case UDEFINE1:
211: case UDEFINE2:
212: case UDEFINE3:
213: case UDEFINE4:
214: case UDEFINE5:
215: case UDEFINE6:
216: case UDEFINE7:
217: unicodeTagTable[i] = true;
218: break;
219:
220: default:
221: unicodeTagTable[i] = false;
222: break;
223: }
224: }
225:
226: // dump the generated table
227: System.out
228: .println("private static boolean [] sUnicodeTagTable = {");
229: for (i = 0; i < unicodeTagTable.length - 1; i++)
230: System.out.print(unicodeTagTable[i] + ", ");
231: for (i = unicodeTagTable.length - 1; i < unicodeTagTable.length; i++)
232: System.out.print(unicodeTagTable[i]);
233: System.out.println();
234: System.out.println("};");
235: }
236:
237: public static void main(String[] argv) {
238: printOffsetTable();
239: printSingleTagTable();
240: printUnicodeTagTable();
241: }
242: }
|