2003-05-18 14:14:47 +00:00
/ *
The contents of this file are subject to the THDL Open Community License
Version 1 . 0 ( the " License " ) ; you may not use this file except in compliance
with the License . You may obtain a copy of the License on the THDL web site
( http : //www.thdl.org/).
Software distributed under the License is distributed on an " AS IS " basis ,
WITHOUT WARRANTY OF ANY KIND , either express or implied . See the
License for the specific terms governing rights and limitations under the
License .
The Initial Developer of this software is the Tibetan and Himalayan Digital
Library ( THDL ) . Portions created by the THDL are Copyright 2003 THDL .
All Rights Reserved .
Contributor ( s ) : ______________________________________ .
* /
package org.thdl.tib.input ;
import java.io.* ;
2003-07-01 01:21:57 +00:00
import javax.swing.text.rtf.RTFEditorKit ;
2003-07-01 03:43:33 +00:00
import javax.swing.text.SimpleAttributeSet ;
import javax.swing.text.StyleConstants ;
2003-05-18 14:14:47 +00:00
import org.thdl.util.* ;
import org.thdl.tib.text.* ;
2003-08-24 06:40:53 +00:00
import org.thdl.tib.text.ttt.ACIPConverter ;
import org.thdl.tib.text.ttt.ACIPTshegBarScanner ;
import java.util.ArrayList ;
2003-06-15 19:19:23 +00:00
/ * * TibetanConverter is a command - line utility for converting to
2003-06-15 18:38:42 +00:00
* 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 .
2003-05-18 14:14:47 +00:00
* @author David Chandler * /
2003-06-25 01:04:24 +00:00
public class TibetanConverter implements FontConverterConstants {
private static final boolean debug = false ;
2003-06-24 03:02:29 +00:00
/** Default constructor; does nothing */
TibetanConverter ( ) { }
2003-05-18 17:17:52 +00:00
static final String rtfErrorMessage
= " The Rich Text Format (RTF) file selected contains constructs that \ nJskad cannot handle. If you got the RTF file from saving a Word \ ndocument as RTF, try saving that same document as RTF in \ nWord 2000 instead of Word XP or in Word 97 instead of \ nWord 2000. Older versions of Word produce RTF that Jskad \ ncan more easily deal with. OpenOffice and StarOffice may also \ nproduce better-behaved RTF. " ;
2003-05-18 14:14:47 +00:00
/ * *
* Runs the converter . * /
public static void main ( String [ ] args ) {
2003-09-04 04:34:18 +00:00
// No need for the TM or TMW fonts.
System . setProperty ( " thdl.rely.on.system.tmw.fonts " , " true " ) ;
System . setProperty ( " thdl.rely.on.system.tm.fonts " , " true " ) ;
2003-07-01 02:50:09 +00:00
// Runs on Linux/Unix boxes without X11 servers:
System . setProperty ( " java.awt.headless " , " true " ) ;
2003-05-18 17:17:52 +00:00
System . exit ( realMain ( args , System . out ) ) ;
}
/ * * Runs the converter without exiting the program .
* @return the exit code . * /
public static int realMain ( String [ ] args , PrintStream out ) {
2003-05-18 14:14:47 +00:00
try {
2003-06-15 18:38:42 +00:00
boolean convertToUnicodeMode = false ;
2003-05-31 23:21:29 +00:00
boolean convertToTMMode = false ;
2003-08-24 06:40:53 +00:00
boolean convertACIPToUniMode = false ;
2003-08-31 16:06:35 +00:00
boolean convertACIPToTMWMode = false ;
2003-06-08 22:43:27 +00:00
boolean convertToTMWMode = false ;
2003-09-05 02:05:34 +00:00
boolean convertToWylieRTFMode = false ;
boolean convertToWylieTextMode = false ;
boolean convertToACIPRTFMode = false ;
boolean convertToACIPTextMode = false ;
2003-05-18 14:14:47 +00:00
boolean findSomeNonTMWMode = false ;
boolean findAllNonTMWMode = false ;
2003-06-22 00:14:18 +00:00
boolean findSomeNonTMMode = false ;
boolean findAllNonTMMode = false ;
2003-09-06 22:56:10 +00:00
boolean colors = false ;
2003-09-04 05:16:47 +00:00
2003-05-18 14:14:47 +00:00
// Process arguments:
2003-09-06 22:56:10 +00:00
final int numArgs = 6 ;
if ( ( args . length ! = 1 & & args . length ! = numArgs )
2003-05-18 14:14:47 +00:00
| | ( args . length = = 1
2003-05-31 23:21:29 +00:00
& & ! ( args [ 0 ] . equals ( " -v " )
| | args [ 0 ] . equals ( " --version " ) ) )
2003-09-06 22:56:10 +00:00
| | ( args . length = = numArgs
& & ( ! ( args [ numArgs - 6 ] . equals ( " --colors " ) )
| | ! ( ( colors = args [ numArgs - 5 ] . equals ( " yes " ) )
| | args [ numArgs - 5 ] . equals ( " no " ) )
| | ! ( args [ numArgs - 4 ] . equals ( " --warning-level " ) )
| | ! ( args [ numArgs - 3 ] . equals ( " Most " )
| | args [ numArgs - 3 ] . equals ( " Some " )
| | args [ numArgs - 3 ] . equals ( " All " )
| | args [ numArgs - 3 ] . equals ( " None " ) )
| | ! ( ( findAllNonTMWMode
= args [ numArgs - 2 ] . equals ( " --find-all-non-tmw " ) )
| | ( convertToTMMode
= args [ numArgs - 2 ] . equals ( " --to-tibetan-machine " ) )
| | ( convertToTMWMode
= args [ numArgs - 2 ] . equals ( " --to-tibetan-machine-web " ) )
| | ( convertACIPToUniMode
= args [ numArgs - 2 ] . equals ( " --acip-to-unicode " ) )
| | ( convertACIPToTMWMode
= args [ numArgs - 2 ] . equals ( " --acip-to-tmw " ) )
| | ( convertToUnicodeMode
= args [ numArgs - 2 ] . equals ( " --to-unicode " ) )
| | ( convertToWylieRTFMode
= args [ numArgs - 2 ] . equals ( " --to-wylie " ) )
| | ( convertToWylieTextMode
= args [ numArgs - 2 ] . equals ( " --to-wylie-text " ) )
| | ( convertToACIPRTFMode
= args [ numArgs - 2 ] . equals ( " --to-acip " ) )
| | ( convertToACIPTextMode
= args [ numArgs - 2 ] . equals ( " --to-acip-text " ) )
| | ( findSomeNonTMWMode
= args [ numArgs - 2 ] . equals ( " --find-some-non-tmw " ) )
| | ( findSomeNonTMMode
= args [ numArgs - 2 ] . equals ( " --find-some-non-tm " ) )
| | ( findAllNonTMMode
= args [ numArgs - 2 ] . equals ( " --find-all-non-tm " ) )
) ) ) ) {
2003-09-04 04:34:18 +00:00
out . println ( " TibetanConverter --find-all-non-tmw | --find-some-non-tmw " ) ;
out . println ( " | --to-tibetan-machine | --to-tibetan-machine-web " ) ;
2003-09-04 05:16:47 +00:00
out . println ( " | --to-unicode | --to-wylie | --to-acip " ) ;
out . println ( " | --to-wylie-text | --to-acip-text RTF_file " ) ;
2003-09-04 04:34:18 +00:00
out . println ( " | TibetanConverter --acip-to-unicode | --acip-to-tmw TXT_file " ) ;
2003-06-15 19:19:23 +00:00
out . println ( " | TibetanConverter [--version | -v | --help | -h] " ) ;
2003-05-18 17:17:52 +00:00
out . println ( " " ) ;
out . println ( " Distributed under the terms of the THDL Open Community License Version 1.0. " ) ;
out . println ( " " ) ;
out . println ( " Usage: " ) ;
out . println ( " -v | --version for version info " ) ;
2003-09-04 04:34:18 +00:00
out . println ( " " ) ;
2003-05-18 17:17:52 +00:00
out . println ( " -h | --help for this message " ) ;
2003-09-04 04:34:18 +00:00
out . println ( " " ) ;
2003-08-24 06:40:53 +00:00
out . println ( " --to-tibetan-machine to convert TibetanMachineWeb to TibetanMachine " ) ;
2003-09-04 04:34:18 +00:00
out . println ( " " ) ;
2003-08-24 06:40:53 +00:00
out . println ( " --to-unicode to convert TibetanMachineWeb to Unicode " ) ;
2003-09-04 04:34:18 +00:00
out . println ( " " ) ;
2003-08-24 06:40:53 +00:00
out . println ( " --to-tibetan-machine-web to convert TibetanMachine to TibetanMachineWeb " ) ;
2003-09-04 04:34:18 +00:00
out . println ( " " ) ;
2003-09-04 05:16:47 +00:00
out . println ( " --to-wylie to convert TibetanMachineWeb to THDL Extended Wylie in RTF " ) ;
out . println ( " " ) ;
out . println ( " --to-wylie-text to convert TibetanMachineWeb to THDL Extended Wylie in text " ) ;
2003-09-04 04:34:18 +00:00
out . println ( " " ) ;
2003-09-04 05:16:47 +00:00
out . println ( " --to-acip to convert TibetanMachineWeb to ACIP in RTF " ) ;
out . println ( " " ) ;
out . println ( " --to-acip-text to convert TibetanMachineWeb to ACIP in text " ) ;
2003-09-04 04:34:18 +00:00
out . println ( " " ) ;
2003-08-24 06:40:53 +00:00
out . println ( " --acip-to-unicode to convert ACIP text file to Unicode text file " ) ;
2003-09-04 04:34:18 +00:00
out . println ( " " ) ;
out . println ( " --acip-to-tmw to convert ACIP text file to Tibetan Machine Web RTF File. " ) ;
out . println ( " " ) ;
2003-05-18 17:17:52 +00:00
out . println ( " --find-all-non-tmw to locate all characters in the input document that are " ) ;
2003-06-22 00:14:18 +00:00
out . println ( " not in Tibetan Machine Web fonts, exit zero if and only if none found " ) ;
2003-09-04 04:34:18 +00:00
out . println ( " " ) ;
2003-05-18 17:17:52 +00:00
out . println ( " --find-some-non-tmw to locate all distinct characters in the input document " ) ;
2003-06-22 00:14:18 +00:00
out . println ( " not in Tibetan Machine Web fonts, exit zero if and only if none found " ) ;
2003-09-04 04:34:18 +00:00
out . println ( " " ) ;
2003-06-22 00:14:18 +00:00
out . println ( " --find-all-non-tm to locate all characters in the input document that are " ) ;
out . println ( " not in Tibetan Machine fonts, exit zero if and only if none found " ) ;
2003-09-04 04:34:18 +00:00
out . println ( " " ) ;
2003-06-22 00:14:18 +00:00
out . println ( " --find-some-non-tm to locate all distinct characters in the input document " ) ;
out . println ( " not in Tibetan Machine fonts, exit zero if and only if none found " ) ;
out . println ( " " ) ;
2003-09-04 04:34:18 +00:00
out . println ( " " ) ;
2003-08-24 06:40:53 +00:00
out . println ( " In --to... and --acip-to... modes, needs one argument, the name of the " ) ;
out . println ( " TibetanMachineWeb RTF " ) ;
2003-06-15 18:38:42 +00:00
out . println ( " file (for --to-wylie, --to-unicode, and --to-tibetan-machine) or the name of " ) ;
2003-08-24 06:40:53 +00:00
out . println ( " the TibetanMachine RTF file (for --to-tibetan-machine-web) or the name of the " ) ;
out . println ( " ACIP text file (for --acip-to-unicode). Writes the " ) ;
2003-06-15 18:38:42 +00:00
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), " ) ;
2003-07-01 03:43:33 +00:00
out . println ( " 44 if a TMW->Wylie conversion ran into some glyphs that couldn't be " ) ;
out . println ( " converted, in which case ugly error messages like " ) ;
out . println ( " \" <<[[JSKAD_TMW_TO_WYLIE_ERROR_NO_SUCH_WYLIE: Cannot convert DuffCode... \" " ) ;
out . println ( " are in your document waiting for your personal attention, " ) ;
2003-06-29 21:31:48 +00:00
out . println ( " 43 if not even one glyph found was eligible for this conversion, which means " ) ;
out . println ( " that you probably selected the wrong conversion or the wrong document, or " ) ;
2003-06-15 18:38:42 +00:00
out . println ( " nonzero otherwise. " ) ;
2003-05-18 17:17:52 +00:00
out . println ( " " ) ;
2003-06-22 00:14:18 +00:00
out . println ( " You may find it helpful to use `--find-some-non-tmw' mode (or " ) ;
out . println ( " `--find-some-non-tm' mode for Tibetan Machine input) before doing a " ) ;
2003-05-18 17:17:52 +00:00
out . println ( " conversion so that you have confidence in the conversion's correctness. " ) ;
return 77 ;
2003-05-18 14:14:47 +00:00
}
if ( args [ 0 ] . equals ( " --version " ) | | args [ 0 ] . equals ( " -v " ) ) {
2003-08-24 06:40:53 +00:00
out . println ( " TibetanConverter version 0.83 " ) ;
2003-05-31 23:21:29 +00:00
out . println ( " Compiled at "
+ ThdlVersion . getTimeOfCompilation ( ) ) ;
2003-05-18 17:17:52 +00:00
return 77 ;
2003-05-18 14:14:47 +00:00
}
2003-06-22 21:05:16 +00:00
String inputRtfPath = args [ args . length - 1 ] ;
2003-05-18 14:14:47 +00:00
2003-06-24 03:02:29 +00:00
InputStream in ;
if ( inputRtfPath . equals ( " - " ) )
in = System . in ;
else
in = new FileInputStream ( inputRtfPath ) ;
String conversionTag = null ;
2003-05-18 14:14:47 +00:00
if ( findAllNonTMWMode ) {
2003-06-25 01:04:24 +00:00
conversionTag = FIND_ALL_NON_TMW ;
2003-05-18 14:14:47 +00:00
} else if ( findSomeNonTMWMode ) {
2003-06-25 01:04:24 +00:00
conversionTag = FIND_SOME_NON_TMW ;
2003-06-22 00:14:18 +00:00
} else if ( findSomeNonTMMode ) {
2003-06-25 01:04:24 +00:00
conversionTag = FIND_SOME_NON_TM ;
2003-06-22 00:14:18 +00:00
} else if ( findAllNonTMMode ) {
2003-06-25 01:04:24 +00:00
conversionTag = FIND_ALL_NON_TM ;
2003-05-31 23:21:29 +00:00
} else { // conversion {to Wylie or TM} mode
2003-09-05 02:05:34 +00:00
if ( convertToWylieRTFMode ) {
2003-06-25 01:04:24 +00:00
conversionTag = TMW_TO_WYLIE ;
2003-09-05 02:05:34 +00:00
} else if ( convertToWylieTextMode ) {
conversionTag = TMW_TO_WYLIE_TEXT ;
} else if ( convertToACIPRTFMode ) {
2003-09-02 06:39:33 +00:00
conversionTag = TMW_TO_ACIP ;
2003-09-05 02:05:34 +00:00
} else if ( convertToACIPTextMode ) {
conversionTag = TMW_TO_ACIP_TEXT ;
2003-06-15 18:38:42 +00:00
} else if ( convertToUnicodeMode ) {
2003-06-25 01:04:24 +00:00
conversionTag = TMW_TO_UNI ;
2003-06-08 22:43:27 +00:00
} else if ( convertToTMWMode ) {
2003-06-25 01:04:24 +00:00
conversionTag = TM_TO_TMW ;
2003-08-24 06:40:53 +00:00
} else if ( convertACIPToUniMode ) {
2003-09-05 02:05:34 +00:00
conversionTag = ACIP_TO_UNI_TEXT ;
2003-08-31 16:06:35 +00:00
} else if ( convertACIPToTMWMode ) {
conversionTag = ACIP_TO_TMW ;
2003-05-31 23:21:29 +00:00
} else {
ThdlDebug . verify ( convertToTMMode ) ;
2003-06-26 22:48:51 +00:00
conversionTag = TMW_TO_TM ;
2003-05-31 23:21:29 +00:00
}
2003-05-18 14:14:47 +00:00
}
2003-09-05 02:05:34 +00:00
return reallyConvert ( in , out , conversionTag ,
2003-09-06 22:56:10 +00:00
args [ numArgs - 3 ] . intern ( ) , colors ) ;
2003-05-18 14:14:47 +00:00
} catch ( ThdlLazyException e ) {
2003-06-15 19:19:23 +00:00
out . println ( " TibetanConverter has a BUG: " ) ;
2003-05-18 17:17:52 +00:00
e . getRealException ( ) . printStackTrace ( out ) ;
return 7 ;
2003-05-18 14:14:47 +00:00
} catch ( IOException e ) {
2003-05-18 17:17:52 +00:00
e . printStackTrace ( out ) ;
return 4 ;
2003-05-18 14:14:47 +00:00
}
}
2003-06-24 03:02:29 +00:00
/ * * Reads from in , closes in , converts ( or finds some / all
non - TM / TMW ) , writes the result to out , does not close out .
The action taken depends on ct , which must be one of a set
number of strings - - see the code . Returns an appropriate
return code so that TibetanConverter ' s usage message is
honored . * /
2003-08-24 06:40:53 +00:00
static int reallyConvert ( InputStream in , PrintStream out , String ct ,
2003-09-06 22:56:10 +00:00
String warningLevel , boolean colors ) {
2003-09-05 02:05:34 +00:00
if ( ACIP_TO_UNI_TEXT = = ct | | ACIP_TO_TMW = = ct ) {
2003-08-24 06:40:53 +00:00
try {
ArrayList al = ACIPTshegBarScanner . scanStream ( in , null ,
2003-09-06 22:56:10 +00:00
ThdlOptions . getIntegerOption ( " thdl.most.errors.a.tibetan.acip.document.can.have " ,
250 - 1 )
2003-08-24 06:40:53 +00:00
) ;
if ( null = = al )
return 47 ;
StringBuffer warnings = new StringBuffer ( ) ;
boolean embeddedWarnings = ( warningLevel ! = " None " ) ;
2003-09-05 02:05:34 +00:00
if ( ACIP_TO_UNI_TEXT = = ct ) {
2003-08-31 16:06:35 +00:00
if ( ! ACIPConverter . convertToUnicode ( al , out , null , warnings ,
embeddedWarnings ,
warningLevel ) )
return 46 ;
} else {
2003-09-06 22:56:10 +00:00
if ( ct ! = ACIP_TO_TMW ) throw new Error ( " badness " ) ;
2003-08-31 16:06:35 +00:00
if ( ! ACIPConverter . convertToTMW ( al , out , null , warnings ,
2003-08-24 06:40:53 +00:00
embeddedWarnings ,
2003-09-06 22:56:10 +00:00
warningLevel , colors ) )
2003-08-31 16:06:35 +00:00
return 46 ;
}
2003-08-24 06:40:53 +00:00
if ( embeddedWarnings & & warnings . length ( ) > 0 )
return 45 ;
else
return 0 ;
} catch ( IOException e ) {
return 48 ;
}
} else {
TibetanDocument tdoc = new TibetanDocument ( ) ;
{
SimpleAttributeSet ras = new SimpleAttributeSet ( ) ;
StyleConstants . setFontFamily ( ras ,
ThdlOptions . getStringOption ( " thdl.default.roman.font.face " ,
" Serif " ) ) ;
StyleConstants . setFontSize ( ras ,
ThdlOptions . getIntegerOption ( " thdl.default.roman.font.size " ,
14 ) ) ;
tdoc . setRomanAttributeSet ( ras ) ;
}
try {
// Read in the rtf file.
if ( debug ) System . err . println ( " Start: reading in old RTF file " ) ;
if ( ! ThdlOptions . getBooleanOption ( " thdl.do.not.fix.rtf.hex.escapes " ) )
in = new RTFFixerInputStream ( in ) ;
( new RTFEditorKit ( ) ) . read ( in , tdoc , 0 ) ;
if ( debug ) System . err . println ( " End : reading in old RTF file " ) ;
} catch ( Exception e ) {
out . println ( " TibetanConverter: \ n "
+ rtfErrorMessage ) ;
return 3 ;
}
try {
in . close ( ) ;
} catch ( IOException e ) {
// silently ignore; we don't care about the input so much...
ThdlDebug . noteIffyCode ( ) ;
2003-06-24 03:02:29 +00:00
}
2003-06-29 21:31:48 +00:00
2003-08-24 06:40:53 +00:00
if ( FIND_ALL_NON_TMW = = ct ) {
// 0, -1 is the entire document.
int exitCode
= tdoc . findAllNonTMWCharacters ( 0 , - 1 , out ) ;
if ( out . checkError ( ) )
exitCode = 41 ;
return exitCode ;
} else if ( FIND_SOME_NON_TMW = = ct ) {
// 0, -1 is the entire document.
int exitCode
= tdoc . findSomeNonTMWCharacters ( 0 , - 1 , out ) ;
if ( out . checkError ( ) )
exitCode = 41 ;
return exitCode ;
} else if ( FIND_SOME_NON_TM = = ct ) {
// 0, -1 is the entire document.
int exitCode
= tdoc . findSomeNonTMCharacters ( 0 , - 1 , out ) ;
if ( out . checkError ( ) )
exitCode = 41 ;
return exitCode ;
} else if ( FIND_ALL_NON_TM = = ct ) {
// 0, -1 is the entire document.
int exitCode
= tdoc . findAllNonTMCharacters ( 0 , - 1 , out ) ;
if ( out . checkError ( ) )
exitCode = 41 ;
return exitCode ;
} else { // conversion {to Wylie or TM} mode
// Fix curly braces in the entire document if the input is TMW:
if ( TM_TO_TMW ! = ct ) {
// DLC make me optional
if ( debug ) System . err . println ( " Start: solving curly brace problem " ) ;
tdoc . replaceTahomaCurlyBracesAndBackslashes ( 0 , - 1 ) ;
if ( debug ) System . err . println ( " End : solving curly brace problem " ) ;
2003-06-24 03:02:29 +00:00
}
2003-08-24 06:40:53 +00:00
int exitCode = 0 ;
ThdlDebug . verify ( ( ( TMW_TO_TM = = ct ) ? 1 : 0 )
+ ( ( TMW_TO_UNI = = ct ) ? 1 : 0 )
+ ( ( TM_TO_TMW = = ct ) ? 1 : 0 )
2003-09-02 06:39:33 +00:00
+ ( ( TMW_TO_ACIP = = ct ) ? 1 : 0 )
2003-09-05 02:05:34 +00:00
+ ( ( TMW_TO_ACIP_TEXT = = ct ) ? 1 : 0 )
2003-08-24 06:40:53 +00:00
+ ( ( TMW_TO_WYLIE = = ct ) ? 1 : 0 )
2003-09-05 02:05:34 +00:00
+ ( ( TMW_TO_WYLIE_TEXT = = ct ) ? 1 : 0 )
2003-08-24 06:40:53 +00:00
= = 1 ) ;
long numAttemptedReplacements [ ] = new long [ ] { 0 } ;
if ( TMW_TO_WYLIE = = ct ) {
// Convert to THDL Wylie:
if ( ! tdoc . toWylie ( 0 ,
tdoc . getLength ( ) ,
2003-07-01 01:21:57 +00:00
numAttemptedReplacements ) ) {
2003-08-24 06:40:53 +00:00
exitCode = 44 ;
}
2003-09-02 06:39:33 +00:00
} else if ( TMW_TO_ACIP = = ct ) {
// Convert to ACIP:
if ( ! tdoc . toACIP ( 0 ,
tdoc . getLength ( ) ,
numAttemptedReplacements ) ) {
exitCode = 49 ;
}
2003-08-24 06:40:53 +00:00
} else if ( TMW_TO_UNI = = ct ) {
StringBuffer errors = new StringBuffer ( ) ;
// Convert to Unicode:
if ( tdoc . convertToUnicode ( 0 ,
tdoc . getLength ( ) ,
errors ,
ThdlOptions . getStringOption ( " thdl.tmw.to.unicode.font " ) . intern ( ) ,
numAttemptedReplacements ) ) {
System . err . println ( errors ) ;
exitCode = 42 ;
}
} else if ( TM_TO_TMW = = ct ) {
StringBuffer errors = new StringBuffer ( ) ;
// Convert to TibetanMachineWeb:
if ( tdoc . convertToTMW ( 0 , tdoc . getLength ( ) , errors ,
numAttemptedReplacements ) ) {
System . err . println ( errors ) ;
exitCode = 42 ;
}
} else {
ThdlDebug . verify ( TMW_TO_TM = = ct ) ;
StringBuffer errors = new StringBuffer ( ) ;
// Convert to TibetanMachine:
if ( tdoc . convertToTM ( 0 , tdoc . getLength ( ) , errors ,
numAttemptedReplacements ) ) {
System . err . println ( errors ) ;
exitCode = 42 ;
}
2003-06-24 03:02:29 +00:00
}
2003-08-24 06:40:53 +00:00
// Write to standard output the result:
2003-09-05 02:05:34 +00:00
if ( TMW_TO_WYLIE_TEXT = = ct | | TMW_TO_ACIP_TEXT = = ct ) {
2003-09-04 05:16:47 +00:00
try {
tdoc . writeTextOutput ( new BufferedWriter ( new OutputStreamWriter ( out ) ) ) ;
} catch ( IOException e ) {
exitCode = 40 ;
}
} else {
try {
tdoc . writeRTFOutputStream ( out ) ;
} catch ( IOException e ) {
exitCode = 40 ;
}
2003-06-24 03:02:29 +00:00
}
2003-08-24 06:40:53 +00:00
if ( out . checkError ( ) )
exitCode = 41 ;
if ( numAttemptedReplacements [ 0 ] < 1 )
exitCode = 43 ;
2003-06-24 03:02:29 +00:00
2003-08-24 06:40:53 +00:00
return exitCode ;
2003-06-24 03:02:29 +00:00
}
}
}
2003-05-18 14:14:47 +00:00
}