An error now appears if you try to convert from format A to format B but no

glyphs in format A appear.  In this case, it is likely that you meant to convert
a different file or do a different conversion.
This commit is contained in:
dchandler 2003-06-29 21:31:48 +00:00
parent ee14b7b97f
commit aedef4b44d
5 changed files with 105 additions and 33 deletions

View file

@ -67,6 +67,12 @@ public class ConverterGUI implements FontConversion, FontConverterConstants {
"Conversion failed", "Conversion failed",
JOptionPane.ERROR_MESSAGE); JOptionPane.ERROR_MESSAGE);
return false; return false;
} else if (43 == returnCode) {
JOptionPane.showMessageDialog(cd,
"Though an output file has been created, this conversion did nothing.\nDid you choose the correct original file?\nDid you choose the correct type of conversion?",
"Nothing to do",
JOptionPane.ERROR_MESSAGE);
return false;
} else if (0 != returnCode) { } else if (0 != returnCode) {
JOptionPane.showMessageDialog(cd, JOptionPane.showMessageDialog(cd,
"The conversion failed with code " + returnCode + "; please e-mail\ndchandler@users.sourceforge.net to learn what that means if\nyou can't find out from the output.", "The conversion failed with code " + returnCode + "; please e-mail\ndchandler@users.sourceforge.net to learn what that means if\nyou can't find out from the output.",

View file

@ -1489,8 +1489,8 @@ public void paste(int offset) {
public void toWylie() { public void toWylie() {
int start = getSelectionStart(); int start = getSelectionStart();
int end = getSelectionEnd(); int end = getSelectionEnd();
long n[] = new long[] { 0 };
toWylie(start, end); toWylie(start, end, n);
} }
/** /**
@ -1499,8 +1499,11 @@ public void paste(int offset) {
* *
* @param start the point from which to begin converting to Wylie * @param start the point from which to begin converting to Wylie
* @param end the point at which to stop converting to Wylie * @param end the point at which to stop converting to Wylie
*/ * @param numAttemptedReplacements an array that contains one element;
public void toWylie(int start, int end) { * this first element will be, upon exit, incremented by the number of
* TMW glyphs that we encountered and attempted to convert to Wylie */
public void toWylie(int start, int end,
long numAttemptedReplacements[]) {
if (start == end) if (start == end)
return; return;
@ -1529,6 +1532,7 @@ public void paste(int offset) {
} else { } else {
char ch = getTibDoc().getText(i,1).charAt(0); char ch = getTibDoc().getText(i,1).charAt(0);
dcs.add(new DuffCode(fontNum, ch)); dcs.add(new DuffCode(fontNum, ch));
++numAttemptedReplacements[0];
} }
i++; i++;

View file

@ -374,8 +374,10 @@ public class Jskad extends JPanel implements DocumentListener {
toTMItem.addActionListener(new ThdlActionListener() { toTMItem.addActionListener(new ThdlActionListener() {
public void theRealActionPerformed(ActionEvent e) { public void theRealActionPerformed(ActionEvent e) {
StringBuffer errors = new StringBuffer(); StringBuffer errors = new StringBuffer();
long numAttemptedReplacements[] = new long[] { 0 };
boolean errorReturn boolean errorReturn
= ((TibetanDocument)dp.getDocument()).convertToTM(0, -1, errors); // entire document = ((TibetanDocument)dp.getDocument()).convertToTM(0, -1, errors,
numAttemptedReplacements); // entire document
if (errorReturn) { if (errorReturn) {
JOptionPane.showMessageDialog(Jskad.this, JOptionPane.showMessageDialog(Jskad.this,
"At least one error occurred while converting Tibetan Machine Web\nto Tibetan Machine. Your document is mostly converted,\nexcept for the following glyphs, which you should replace manually\nbefore retrying:\n" "At least one error occurred while converting Tibetan Machine Web\nto Tibetan Machine. Your document is mostly converted,\nexcept for the following glyphs, which you should replace manually\nbefore retrying:\n"
@ -383,9 +385,17 @@ public class Jskad extends JPanel implements DocumentListener {
"TMW to TM Errors", "TMW to TM Errors",
JOptionPane.PLAIN_MESSAGE); JOptionPane.PLAIN_MESSAGE);
} else { } else {
JOptionPane.showMessageDialog(Jskad.this, if (numAttemptedReplacements[0] > 0) {
"Converting Tibetan Machine Web to Tibetan Machine met with perfect success.", JOptionPane.showMessageDialog(Jskad.this,
"Success", JOptionPane.PLAIN_MESSAGE); "Converting Tibetan Machine Web to Tibetan Machine met with perfect success.",
"Success",
JOptionPane.PLAIN_MESSAGE);
} else {
JOptionPane.showMessageDialog(Jskad.this,
"No Tibetan Machine Web was found, so nothing was converted.",
"Nothing to do",
JOptionPane.ERROR_MESSAGE);
}
} }
} }
}); });
@ -394,17 +404,27 @@ public class Jskad extends JPanel implements DocumentListener {
toTMWItem.addActionListener(new ThdlActionListener() { toTMWItem.addActionListener(new ThdlActionListener() {
public void theRealActionPerformed(ActionEvent e) { public void theRealActionPerformed(ActionEvent e) {
StringBuffer errors = new StringBuffer(); StringBuffer errors = new StringBuffer();
long numAttemptedReplacements[] = new long[] { 0 };
boolean errorReturn boolean errorReturn
= ((TibetanDocument)dp.getDocument()).convertToTMW(0, -1, errors); // entire document = ((TibetanDocument)dp.getDocument()).convertToTMW(0, -1, errors,
numAttemptedReplacements); // entire document
if (errorReturn) { if (errorReturn) {
JOptionPane.showMessageDialog(Jskad.this, JOptionPane.showMessageDialog(Jskad.this,
"At least one error occurred while converting Tibetan Machine\nto Tibetan Machine Web. Your document is mostly converted,\nexcept for the following glyphs, which you should replace manually\nbefore retrying:\n" "At least one error occurred while converting Tibetan Machine\nto Tibetan Machine Web. Your document is mostly converted,\nexcept for the following glyphs, which you should replace manually\nbefore retrying:\n"
+ errors.toString(), + errors.toString(),
"TM to TMW Errors", JOptionPane.PLAIN_MESSAGE); "TM to TMW Errors", JOptionPane.PLAIN_MESSAGE);
} else { } else {
JOptionPane.showMessageDialog(Jskad.this, if (numAttemptedReplacements[0] > 0) {
"Converting Tibetan Machine to Tibetan Machine Web met with perfect success.", JOptionPane.showMessageDialog(Jskad.this,
"Success", JOptionPane.PLAIN_MESSAGE); "Converting Tibetan Machine to Tibetan Machine Web met with perfect success.",
"Success",
JOptionPane.PLAIN_MESSAGE);
} else {
JOptionPane.showMessageDialog(Jskad.this,
"No Tibetan Machine was found, so nothing was converted.",
"Nothing to do",
JOptionPane.ERROR_MESSAGE);
}
} }
} }
}); });
@ -413,18 +433,28 @@ public class Jskad extends JPanel implements DocumentListener {
toUnicodeItem.addActionListener(new ThdlActionListener() { toUnicodeItem.addActionListener(new ThdlActionListener() {
public void theRealActionPerformed(ActionEvent e) { public void theRealActionPerformed(ActionEvent e) {
StringBuffer errors = new StringBuffer(); StringBuffer errors = new StringBuffer();
long numAttemptedReplacements[] = new long[] { 0 };
boolean errorReturn boolean errorReturn
= ((TibetanDocument)dp.getDocument()).convertToUnicode(0, -1, errors, = ((TibetanDocument)dp.getDocument()).convertToUnicode(0, -1, errors,
ThdlOptions.getStringOption("thdl.tmw.to.unicode.font").intern()); // entire document ThdlOptions.getStringOption("thdl.tmw.to.unicode.font").intern(),
numAttemptedReplacements); // entire document
if (errorReturn) { if (errorReturn) {
JOptionPane.showMessageDialog(Jskad.this, JOptionPane.showMessageDialog(Jskad.this,
"At least one error occurred while converting Tibetan Machine Web\nto Unicode. Your document is mostly converted,\nexcept for the following glyphs, which you should replace manually\nbefore retrying:\n" "At least one error occurred while converting Tibetan Machine Web\nto Unicode. Your document is mostly converted,\nexcept for the following glyphs, which you should replace manually\nbefore retrying:\n"
+ errors.toString(), + errors.toString(),
"TMW to Unicode Errors", JOptionPane.PLAIN_MESSAGE); "TMW to Unicode Errors", JOptionPane.PLAIN_MESSAGE);
} else { } else {
JOptionPane.showMessageDialog(Jskad.this, if (numAttemptedReplacements[0] > 0) {
"Converting Tibetan Machine Web to Unicode met with perfect success.", JOptionPane.showMessageDialog(Jskad.this,
"Success", JOptionPane.PLAIN_MESSAGE); "Converting Tibetan Machine Web to Unicode met with perfect success.",
"Success",
JOptionPane.PLAIN_MESSAGE);
} else {
JOptionPane.showMessageDialog(Jskad.this,
"No Tibetan Machine Web was found, so nothing was converted.",
"Nothing to do",
JOptionPane.ERROR_MESSAGE);
}
} }
} }
}); });
@ -1032,7 +1062,8 @@ public class Jskad extends JPanel implements DocumentListener {
private void toWylie() { private void toWylie() {
Jskad.this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); Jskad.this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
dp.toWylie(dp.getSelectionStart(), dp.getSelectionEnd()); long n[] = new long[] { 0 };
dp.toWylie(dp.getSelectionStart(), dp.getSelectionEnd(), n);
Jskad.this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); Jskad.this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
} }

View file

@ -117,13 +117,14 @@ public class TibetanConverter implements FontConverterConstants {
out.println(" result to standard output (after dealing with the curly brace problem if"); 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(" 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(" glyphs couldn't be converted (in which case the output is just those glyphs),");
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 ");
out.println(" nonzero otherwise."); out.println(" nonzero otherwise.");
out.println(""); out.println("");
out.println(" You may find it helpful to use `--find-some-non-tmw' mode (or"); 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"); out.println(" `--find-some-non-tm' mode for Tibetan Machine input) before doing a");
out.println(" conversion so that you have confidence in the conversion's correctness."); out.println(" conversion so that you have confidence in the conversion's correctness.");
// DLC add Wylie->TMW mode. // DLC add Wylie->TMW mode.
// DLC give error if you have a TM file and try TMW->Unicode.
return 77; return 77;
} }
if (args[0].equals("--version") || args[0].equals("-v")) { if (args[0].equals("--version") || args[0].equals("-v")) {
@ -237,30 +238,34 @@ public class TibetanConverter implements FontConverterConstants {
((TibetanDocument)dp.getDocument()).replaceTahomaCurlyBracesAndBackslashes(0, -1); ((TibetanDocument)dp.getDocument()).replaceTahomaCurlyBracesAndBackslashes(0, -1);
if (debug) System.err.println("End : solving curly brace problem"); if (debug) System.err.println("End : solving curly brace problem");
} }
int exitCode = 0; int exitCode = 0;
ThdlDebug.verify(((TMW_TO_TM == ct) ? 1 : 0) ThdlDebug.verify(((TMW_TO_TM == ct) ? 1 : 0)
+ ((TMW_TO_UNI == ct) ? 1 : 0) + ((TMW_TO_UNI == ct) ? 1 : 0)
+ ((TM_TO_TMW == ct) ? 1 : 0) + ((TM_TO_TMW == ct) ? 1 : 0)
+ ((TMW_TO_WYLIE == ct) ? 1 : 0) + ((TMW_TO_WYLIE == ct) ? 1 : 0)
== 1); == 1);
long numAttemptedReplacements[] = new long[] { 0 };
if (TMW_TO_WYLIE == ct) { if (TMW_TO_WYLIE == ct) {
// Convert to THDL Wylie: // Convert to THDL Wylie:
dp.toWylie(0, dp.getDocument().getLength()); dp.toWylie(0, dp.getDocument().getLength(),
numAttemptedReplacements);
} else if (TMW_TO_UNI == ct) { } else if (TMW_TO_UNI == ct) {
StringBuffer errors = new StringBuffer(); StringBuffer errors = new StringBuffer();
// Convert to Unicode: // Convert to Unicode:
if (((TibetanDocument)dp.getDocument()).convertToUnicode(0, if (((TibetanDocument)dp.getDocument()).convertToUnicode(0,
dp.getDocument().getLength(), dp.getDocument().getLength(),
errors, errors,
ThdlOptions.getStringOption("thdl.tmw.to.unicode.font").intern())) { ThdlOptions.getStringOption("thdl.tmw.to.unicode.font").intern(),
numAttemptedReplacements)) {
System.err.println(errors); System.err.println(errors);
exitCode = 42; exitCode = 42;
} }
} else if (TM_TO_TMW == ct) { } else if (TM_TO_TMW == ct) {
StringBuffer errors = new StringBuffer(); StringBuffer errors = new StringBuffer();
// Convert to TibetanMachineWeb: // Convert to TibetanMachineWeb:
if (((TibetanDocument)dp.getDocument()).convertToTMW(0, dp.getDocument().getLength(), errors)) { if (((TibetanDocument)dp.getDocument()).convertToTMW(0, dp.getDocument().getLength(), errors,
numAttemptedReplacements)) {
System.err.println(errors); System.err.println(errors);
exitCode = 42; exitCode = 42;
} }
@ -268,7 +273,8 @@ public class TibetanConverter implements FontConverterConstants {
ThdlDebug.verify(TMW_TO_TM == ct); ThdlDebug.verify(TMW_TO_TM == ct);
StringBuffer errors = new StringBuffer(); StringBuffer errors = new StringBuffer();
// Convert to TibetanMachine: // Convert to TibetanMachine:
if (((TibetanDocument)dp.getDocument()).convertToTM(0, dp.getDocument().getLength(), errors)) { if (((TibetanDocument)dp.getDocument()).convertToTM(0, dp.getDocument().getLength(), errors,
numAttemptedReplacements)) {
System.err.println(errors); System.err.println(errors);
exitCode = 42; exitCode = 42;
} }
@ -282,6 +288,8 @@ public class TibetanConverter implements FontConverterConstants {
} }
if (out.checkError()) if (out.checkError())
exitCode = 41; exitCode = 41;
if (numAttemptedReplacements[0] < 1)
exitCode = 43;
return exitCode; return exitCode;
} }

View file

@ -10,7 +10,7 @@ License for the specific terms governing rights and limitations under the
License. License.
The Initial Developer of this software is the Tibetan and Himalayan Digital The Initial Developer of this software is the Tibetan and Himalayan Digital
Library (THDL). Portions created by the THDL are Copyright 2001 THDL. Library (THDL). Portions created by the THDL are Copyright 2001-2003 THDL.
All Rights Reserved. All Rights Reserved.
Contributor(s): ______________________________________. Contributor(s): ______________________________________.
@ -523,9 +523,15 @@ public class TibetanDocument extends DefaultStyledDocument {
was encountered was encountered
@param errors if non-null, then notes about all exceptional @param errors if non-null, then notes about all exceptional
cases will be appended to this StringBuffer cases will be appended to this StringBuffer
@param numAttemptedReplacements an array that contains one
element; this first element will be, upon exit, incremented by
the number of TMW glyphs that we encountered and attempted to
convert to TM
*/ */
public boolean convertToTM(int begin, int end, StringBuffer errors) { public boolean convertToTM(int begin, int end, StringBuffer errors,
return convertHelper(begin, end, true, false, errors, null); long numAttemptedReplacements[]) {
return convertHelper(begin, end, true, false, errors, null,
numAttemptedReplacements);
} }
/** Converts all TibetanMachine glyphs in the document to /** Converts all TibetanMachine glyphs in the document to
@ -539,9 +545,15 @@ public class TibetanDocument extends DefaultStyledDocument {
was encountered was encountered
@param errors if non-null, then notes about all exceptional @param errors if non-null, then notes about all exceptional
cases will be appended to this StringBuffer cases will be appended to this StringBuffer
@param numAttemptedReplacements an array that contains one
element; this first element will be, upon exit, incremented by
the number of TM glyphs that we encountered and attempted to
convert to TMW
*/ */
public boolean convertToTMW(int begin, int end, StringBuffer errors) { public boolean convertToTMW(int begin, int end, StringBuffer errors,
return convertHelper(begin, end, false, false, errors, null); long numAttemptedReplacements[]) {
return convertHelper(begin, end, false, false, errors, null,
numAttemptedReplacements);
} }
/** Converts all TibetanMachineWeb glyphs in the document to /** Converts all TibetanMachineWeb glyphs in the document to
@ -557,10 +569,16 @@ public class TibetanDocument extends DefaultStyledDocument {
cases will be appended to this StringBuffer cases will be appended to this StringBuffer
@param unicodeFont the name of the Unicode font to use; @param unicodeFont the name of the Unicode font to use;
defaults to Ximalaya if null defaults to Ximalaya if null
@param numAttemptedReplacements an array that contains one
element; this first element will be, upon exit, incremented by
the number of TMW glyphs that we encountered and attempted to
convert to Unicode
*/ */
public boolean convertToUnicode(int begin, int end, StringBuffer errors, public boolean convertToUnicode(int begin, int end, StringBuffer errors,
String unicodeFont) { String unicodeFont,
return convertHelper(begin, end, false, true, errors, unicodeFont); long numAttemptedReplacements[]) {
return convertHelper(begin, end, false, true, errors, unicodeFont,
numAttemptedReplacements);
} }
/** For debugging only. Start with an empty document, and call /** For debugging only. Start with an empty document, and call
@ -708,7 +726,8 @@ public class TibetanDocument extends DefaultStyledDocument {
@see #convertToTM(int,int,StringBuffer) */ @see #convertToTM(int,int,StringBuffer) */
private boolean convertHelper(int begin, int end, boolean toTM, private boolean convertHelper(int begin, int end, boolean toTM,
boolean toUnicode, StringBuffer errors, boolean toUnicode, StringBuffer errors,
String unicodeFont) { String unicodeFont,
long numAttemptedReplacements[]) {
// To preserve formatting, we go paragraph by paragraph. // To preserve formatting, we go paragraph by paragraph.
// Use positions, not offsets, because our work on paragraph K // Use positions, not offsets, because our work on paragraph K
@ -730,6 +749,7 @@ public class TibetanDocument extends DefaultStyledDocument {
boolean warn = false; boolean warn = false;
int lastTimeWeExamined = -1; // must be -1 int lastTimeWeExamined = -1; // must be -1
boolean noMore = false; boolean noMore = false;
while (!noMore while (!noMore
&& lastTimeWeExamined != ceh.lastOffsetExamined) { && lastTimeWeExamined != ceh.lastOffsetExamined) {
lastTimeWeExamined = ceh.lastOffsetExamined; lastTimeWeExamined = ceh.lastOffsetExamined;
@ -745,7 +765,8 @@ public class TibetanDocument extends DefaultStyledDocument {
? finalEndPos.getOffset() ? finalEndPos.getOffset()
: p_end), : p_end),
toTM, toUnicode, errors, ceh, toTM, toUnicode, errors, ceh,
unicodeFont); unicodeFont,
numAttemptedReplacements);
} }
if (!ceh.errorReturn if (!ceh.errorReturn
&& pl != getParagraphs(begin, finalEndPos.getOffset()).length) { && pl != getParagraphs(begin, finalEndPos.getOffset()).length) {
@ -829,7 +850,8 @@ public class TibetanDocument extends DefaultStyledDocument {
private void convertHelperHelper(int begin, int end, boolean toTM, private void convertHelperHelper(int begin, int end, boolean toTM,
boolean toUnicode, StringBuffer errors, boolean toUnicode, StringBuffer errors,
ConversionErrorHelper ceh, ConversionErrorHelper ceh,
String unicodeFont) { String unicodeFont,
long numAttemptedReplacements[]) {
final boolean debug = false; final boolean debug = false;
if (debug) if (debug)
System.out.println("cHH: [" + begin + ", " + end + ")"); System.out.println("cHH: [" + begin + ", " + end + ")");
@ -880,6 +902,7 @@ public class TibetanDocument extends DefaultStyledDocument {
: TibetanMachineWeb.getTMFontNumber(fontName)); : TibetanMachineWeb.getTMFontNumber(fontName));
if (0 != fontNum) { if (0 != fontNum) {
++numAttemptedReplacements[0];
// SPEED_FIXME: determining font size might be slow, allow an override. // SPEED_FIXME: determining font size might be slow, allow an override.
int fontSize = tibetanFontSize; int fontSize = tibetanFontSize;