This converter now performs TMW->Unicode conversions.
This commit is contained in:
parent
da70434e52
commit
34a7b5da9b
1 changed files with 42 additions and 25 deletions
|
@ -23,14 +23,16 @@ import java.io.*;
|
|||
import org.thdl.util.*;
|
||||
import org.thdl.tib.text.*;
|
||||
|
||||
/** DLC FIXME: this is misnamed and it doesn't allow for TM->TMW conversion.
|
||||
/** DLC FIXME: this is misnamed
|
||||
*
|
||||
* TMW_RTF_TO_THDL_WYLIE is a command-line utility for converting TMW
|
||||
* to Wylie or to Tibetan Machine. It is a
|
||||
* TibetanMachineWeb-in-RichTextFormat to your choice of
|
||||
* TibetanMachine-in-RichTextFormat or THDL Extended
|
||||
* Wylie-in-RichTextFormat converter, more specifically. Invoke it
|
||||
* with no parameters for usage information.
|
||||
* TMW_RTF_TO_THDL_WYLIE is a command-line utility for converting to
|
||||
* and from Tibetan Machine Web (TMW). It converts TMW to Wylie, to
|
||||
* Unicode, or to Tibetan Machine (TM). It also converts TM to TMW.
|
||||
* It is a TibetanMachineWeb-in-RichTextFormat to your choice of
|
||||
* TibetanMachine-in-RichTextFormat, THDL Extended
|
||||
* Wylie-in-RichTextFormat, or Unicode-in-RichTextFormat converter,
|
||||
* more specifically, as well as converting from TM to TMW. Invoke
|
||||
* it with no parameters for usage information.
|
||||
* @author David Chandler */
|
||||
public class TMW_RTF_TO_THDL_WYLIE {
|
||||
static final String rtfErrorMessage
|
||||
|
@ -51,6 +53,7 @@ public class TMW_RTF_TO_THDL_WYLIE {
|
|||
* @return the exit code. */
|
||||
public static int realMain(String[] args, PrintStream out) {
|
||||
try {
|
||||
boolean convertToUnicodeMode = false;
|
||||
boolean convertToTMMode = false;
|
||||
boolean convertToTMWMode = false;
|
||||
boolean convertToWylieMode = false;
|
||||
|
@ -68,12 +71,16 @@ public class TMW_RTF_TO_THDL_WYLIE {
|
|||
= args[0].equals("--to-tibetan-machine"))
|
||||
|| (convertToTMWMode
|
||||
= args[0].equals("--to-tibetan-machine-web"))
|
||||
|| (convertToUnicodeMode
|
||||
= args[0].equals("--to-unicode"))
|
||||
|| (convertToWylieMode
|
||||
= args[0].equals("--to-wylie"))
|
||||
|| (findSomeNonTMWMode
|
||||
= args[0].equals("--find-some-non-tmw"))))) {
|
||||
out.println("TMW_RTF_TO_THDL_WYLIE [--find-all-non-tmw | --find-some-non-tmw | --to-tibetan-machine | --to-tibetan-machine-web | --to-wylie] RTF_file |");
|
||||
out.println("TMW_RTF_TO_THDL_WYLIE [--version | -v | --help | -h]");
|
||||
out.println("TMW_RTF_TO_THDL_WYLIE [--find-all-non-tmw | --find-some-non-tmw");
|
||||
out.println(" | --to-tibetan-machine | --to-tibetan-machine-web");
|
||||
out.println(" | --to-unicode | --to-wylie] RTF_file");
|
||||
out.println(" | TMW_RTF_TO_THDL_WYLIE [--version | -v | --help | -h]");
|
||||
out.println("");
|
||||
out.println("Distributed under the terms of the THDL Open Community License Version 1.0.");
|
||||
out.println("");
|
||||
|
@ -85,23 +92,26 @@ public class TMW_RTF_TO_THDL_WYLIE {
|
|||
out.println(" --find-some-non-tmw to locate all distinct characters in the input document");
|
||||
out.println(" not in Tibetan Machine Web fonts, exit zero iff none found");
|
||||
out.println(" --to-tibetan-machine to convert TibetanMachineWeb to TibetanMachine");
|
||||
out.println(" --to-unicode to convert TibetanMachineWeb to Unicode");
|
||||
out.println(" --to-tibetan-machine-web to convert TibetanMachine to TibetanMachineWeb");
|
||||
out.println(" --to-wylie to convert TibetanMachineWeb to THDL Extended Wylie");
|
||||
out.println(" In --to... modes, needs one argument, the name of the TibetanMachineWeb RTF");
|
||||
out.println(" file (for --to-wylie and --to-tibetan-machine) or the name of TibetanMachine");
|
||||
out.println(" RTF file (for --to-tibetan-machine-web). Writes the THDL Extended Wylie");
|
||||
out.println(" transliteration of that file [in --to-wylie mode]");
|
||||
out.println(" or the TibetanMachine equivalent of that file [in");
|
||||
out.println(" --to-tibetan-machine mode] to standard output after dealing with the curly");
|
||||
out.println(" brace problem. Exit code is zero on success, 42 if some TibetanMachine glyphs");
|
||||
out.println(" couldn't be understood (though output is still given), nonzero otherwise.");
|
||||
out.println(" file (for --to-wylie, --to-unicode, and --to-tibetan-machine) or the name of");
|
||||
out.println(" the TibetanMachine RTF file (for --to-tibetan-machine-web). Writes the");
|
||||
out.println(" result to standard output (after dealing with the curly brace problem if");
|
||||
out.println(" the input is TibetanMachineWeb). Exit code is zero on success, 42 if some");
|
||||
out.println(" glyphs couldn't be converted (in which case the output is just those glyphs),");
|
||||
out.println(" nonzero otherwise.");
|
||||
out.println("");
|
||||
out.println(" You may find it helpful to use `--find-some-non-tmw' mode before doing a");
|
||||
out.println(" conversion so that you have confidence in the conversion's correctness.");
|
||||
// DLC add find-some/all-non-tm
|
||||
// DLC add Wylie->TMW mode.
|
||||
// DLC give error if you have a TM file and try TMW->Unicode.
|
||||
return 77;
|
||||
}
|
||||
if (args[0].equals("--version") || args[0].equals("-v")) {
|
||||
out.println("TMW_RTF_TO_THDL_WYLIE version 0.81");
|
||||
out.println("TMW_RTF_TO_THDL_WYLIE version 0.82");
|
||||
out.println("Compiled at "
|
||||
+ ThdlVersion.getTimeOfCompilation());
|
||||
return 77;
|
||||
|
@ -131,28 +141,35 @@ public class TMW_RTF_TO_THDL_WYLIE {
|
|||
} else { // conversion {to Wylie or TM} mode
|
||||
// Fix curly braces in the entire document if the input is TMW:
|
||||
if (!convertToTMWMode) {
|
||||
// DLC make me optional
|
||||
((TibetanDocument)dp.getDocument()).replaceTahomaCurlyBracesAndBackslashes(0, -1);
|
||||
}
|
||||
|
||||
int exitCode = 0;
|
||||
ThdlDebug.verify((convertToTMMode ? 1 : 0)
|
||||
+ (convertToUnicodeMode ? 1 : 0)
|
||||
+ (convertToTMWMode ? 1 : 0)
|
||||
+ (convertToWylieMode ? 1 : 0)
|
||||
== 1);
|
||||
if (convertToWylieMode) {
|
||||
ThdlDebug.verify(!convertToTMMode);
|
||||
ThdlDebug.verify(!convertToTMWMode);
|
||||
// Convert to THDL Wylie:
|
||||
dp.toWylie(0, dp.getDocument().getLength());
|
||||
} else if (convertToTMWMode) {
|
||||
ThdlDebug.verify(!convertToTMMode);
|
||||
ThdlDebug.verify(!convertToWylieMode);
|
||||
} else if (convertToUnicodeMode) {
|
||||
StringBuffer errors = new StringBuffer();
|
||||
// Convert to TibetanMachine:
|
||||
// Convert to Unicode:
|
||||
if (((TibetanDocument)dp.getDocument()).convertToUnicode(0, dp.getDocument().getLength(), errors)) {
|
||||
System.err.println(errors);
|
||||
exitCode = 42;
|
||||
}
|
||||
} else if (convertToTMWMode) {
|
||||
StringBuffer errors = new StringBuffer();
|
||||
// Convert to TibetanMachineWeb:
|
||||
if (((TibetanDocument)dp.getDocument()).convertToTMW(0, dp.getDocument().getLength(), errors)) {
|
||||
System.err.println(errors);
|
||||
exitCode = 42;
|
||||
}
|
||||
} else {
|
||||
ThdlDebug.verify(convertToTMMode);
|
||||
ThdlDebug.verify(!convertToTMWMode);
|
||||
ThdlDebug.verify(!convertToWylieMode);
|
||||
StringBuffer errors = new StringBuffer();
|
||||
// Convert to TibetanMachine:
|
||||
if (((TibetanDocument)dp.getDocument()).convertToTM(0, dp.getDocument().getLength(), errors)) {
|
||||
|
|
Loading…
Reference in a new issue