001: /*
002: *******************************************************************************
003: * Copyright (C) 1998-2004, International Business Machines Corporation and *
004: * others. All Rights Reserved. *
005: *******************************************************************************
006: */
007: package com.ibm.icu.dev.tool.layout;
008:
009: import java.util.*;
010: import com.ibm.icu.impl.Utility;
011:
012: public class ScriptRunModuleWriter extends ScriptModuleWriter {
013: public ScriptRunModuleWriter(ScriptData theScriptData) {
014: super (theScriptData, null);
015: }
016:
017: public void writeScriptRuns(String fileName) {
018: int minScript = scriptData.getMinValue();
019: int maxScript = scriptData.getMaxValue();
020: int recordCount = scriptData.getRecordCount();
021:
022: openFile(fileName);
023: writeHeader(null, includeFiles);
024: output.println(preamble);
025:
026: for (int record = 0; record < recordCount; record += 1) {
027: int script = scriptData.getRecord(record).scriptCode();
028:
029: output.print(" {0x");
030: output.print(Utility.hex(scriptData.getRecord(record)
031: .startChar(), 6));
032: output.print(", 0x");
033: output.print(Utility.hex(scriptData.getRecord(record)
034: .endChar(), 6));
035: output.print(", ");
036: output.print(scriptData.getTag(script));
037: output.print("ScriptCode}");
038: output.print((record == recordCount - 1) ? " " : ",");
039: output.print(" // ");
040: output.println(scriptData.getName(script));
041: }
042:
043: output.println(postamble);
044:
045: int power = 1 << Utility.highBit(recordCount);
046: int extra = recordCount - power;
047:
048: output.print("le_int32 ScriptRun::scriptRecordsPower = 0x");
049: output.print(Utility.hex(power, 4));
050: output.println(";");
051:
052: output.print("le_int32 ScriptRun::scriptRecordsExtra = 0x");
053: output.print(Utility.hex(extra, 4));
054: output.println(";");
055:
056: Vector[] scriptRangeOffsets = new Vector[maxScript - minScript
057: + 1];
058:
059: for (int script = minScript; script <= maxScript; script += 1) {
060: scriptRangeOffsets[script - minScript] = new Vector();
061: }
062:
063: for (int record = 0; record < recordCount; record += 1) {
064: scriptRangeOffsets[scriptData.getRecord(record)
065: .scriptCode()
066: - minScript].addElement(new Integer(record));
067: }
068:
069: output.println();
070:
071: for (int script = minScript; script <= maxScript; script += 1) {
072: Vector offsets = scriptRangeOffsets[script - minScript];
073:
074: output.print("le_int16 ");
075: output.print(scriptData.getTag(script));
076: output.println("ScriptRanges[] = {");
077: output.print(" ");
078:
079: for (int offset = 0; offset < offsets.size(); offset += 1) {
080: Integer i = (Integer) offsets.elementAt(offset);
081:
082: output.print(i.intValue());
083: output.print(", ");
084: }
085:
086: output.println("-1");
087: output.println(postamble);
088: }
089:
090: output.println("le_int16 *ScriptRun::scriptRangeOffsets[] = {");
091:
092: for (int script = minScript; script <= maxScript; script += 1) {
093: output.print(" ");
094: output.print(scriptData.getTag(script));
095: output.print("ScriptRanges");
096: output.print(script == maxScript ? " " : ", ");
097: output.print("// ");
098: output.println(scriptData.getName(script));
099: }
100:
101: output.println(postamble);
102:
103: writeTrailer();
104: closeFile();
105: }
106:
107: private static final String[] includeFiles = { "LETypes.h",
108: "LEScripts.h", "ScriptRun.h" };
109:
110: private static final String preamble = "\n"
111: + "ScriptRecord ScriptRun::scriptRecords[] = {";
112:
113: private static final String postamble = "};\n";
114: }
|