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",
JOptionPane.ERROR_MESSAGE);
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) {
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.",

View file

@ -1489,8 +1489,8 @@ public void paste(int offset) {
public void toWylie() {
int start = getSelectionStart();
int end = getSelectionEnd();
toWylie(start, end);
long n[] = new long[] { 0 };
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 end the point at which to stop converting to Wylie
*/
public void toWylie(int start, int end) {
* @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 Wylie */
public void toWylie(int start, int end,
long numAttemptedReplacements[]) {
if (start == end)
return;
@ -1529,6 +1532,7 @@ public void paste(int offset) {
} else {
char ch = getTibDoc().getText(i,1).charAt(0);
dcs.add(new DuffCode(fontNum, ch));
++numAttemptedReplacements[0];
}
i++;

View file

@ -374,8 +374,10 @@ public class Jskad extends JPanel implements DocumentListener {
toTMItem.addActionListener(new ThdlActionListener() {
public void theRealActionPerformed(ActionEvent e) {
StringBuffer errors = new StringBuffer();
long numAttemptedReplacements[] = new long[] { 0 };
boolean errorReturn
= ((TibetanDocument)dp.getDocument()).convertToTM(0, -1, errors); // entire document
= ((TibetanDocument)dp.getDocument()).convertToTM(0, -1, errors,
numAttemptedReplacements); // entire document
if (errorReturn) {
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"
@ -383,9 +385,17 @@ public class Jskad extends JPanel implements DocumentListener {
"TMW to TM Errors",
JOptionPane.PLAIN_MESSAGE);
} else {
JOptionPane.showMessageDialog(Jskad.this,
"Converting Tibetan Machine Web to Tibetan Machine met with perfect success.",
"Success", JOptionPane.PLAIN_MESSAGE);
if (numAttemptedReplacements[0] > 0) {
JOptionPane.showMessageDialog(Jskad.this,
"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() {
public void theRealActionPerformed(ActionEvent e) {
StringBuffer errors = new StringBuffer();
long numAttemptedReplacements[] = new long[] { 0 };
boolean errorReturn
= ((TibetanDocument)dp.getDocument()).convertToTMW(0, -1, errors); // entire document
= ((TibetanDocument)dp.getDocument()).convertToTMW(0, -1, errors,
numAttemptedReplacements); // entire document
if (errorReturn) {
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"
+ errors.toString(),
"TM to TMW Errors", JOptionPane.PLAIN_MESSAGE);
} else {
JOptionPane.showMessageDialog(Jskad.this,
"Converting Tibetan Machine to Tibetan Machine Web met with perfect success.",
"Success", JOptionPane.PLAIN_MESSAGE);
if (numAttemptedReplacements[0] > 0) {
JOptionPane.showMessageDialog(Jskad.this,
"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() {
public void theRealActionPerformed(ActionEvent e) {
StringBuffer errors = new StringBuffer();
long numAttemptedReplacements[] = new long[] { 0 };
boolean errorReturn
= ((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) {
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"
+ errors.toString(),
"TMW to Unicode Errors", JOptionPane.PLAIN_MESSAGE);
} else {
JOptionPane.showMessageDialog(Jskad.this,
"Converting Tibetan Machine Web to Unicode met with perfect success.",
"Success", JOptionPane.PLAIN_MESSAGE);
if (numAttemptedReplacements[0] > 0) {
JOptionPane.showMessageDialog(Jskad.this,
"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() {
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));
}

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(" 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(" 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("");
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(" conversion so that you have confidence in the conversion's correctness.");
// 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")) {
@ -237,30 +238,34 @@ public class TibetanConverter implements FontConverterConstants {
((TibetanDocument)dp.getDocument()).replaceTahomaCurlyBracesAndBackslashes(0, -1);
if (debug) System.err.println("End : solving curly brace problem");
}
int exitCode = 0;
ThdlDebug.verify(((TMW_TO_TM == ct) ? 1 : 0)
+ ((TMW_TO_UNI == ct) ? 1 : 0)
+ ((TM_TO_TMW == ct) ? 1 : 0)
+ ((TMW_TO_WYLIE == ct) ? 1 : 0)
== 1);
long numAttemptedReplacements[] = new long[] { 0 };
if (TMW_TO_WYLIE == ct) {
// Convert to THDL Wylie:
dp.toWylie(0, dp.getDocument().getLength());
dp.toWylie(0, dp.getDocument().getLength(),
numAttemptedReplacements);
} else if (TMW_TO_UNI == ct) {
StringBuffer errors = new StringBuffer();
// Convert to Unicode:
if (((TibetanDocument)dp.getDocument()).convertToUnicode(0,
dp.getDocument().getLength(),
errors,
ThdlOptions.getStringOption("thdl.tmw.to.unicode.font").intern())) {
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 (((TibetanDocument)dp.getDocument()).convertToTMW(0, dp.getDocument().getLength(), errors)) {
if (((TibetanDocument)dp.getDocument()).convertToTMW(0, dp.getDocument().getLength(), errors,
numAttemptedReplacements)) {
System.err.println(errors);
exitCode = 42;
}
@ -268,7 +273,8 @@ public class TibetanConverter implements FontConverterConstants {
ThdlDebug.verify(TMW_TO_TM == ct);
StringBuffer errors = new StringBuffer();
// 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);
exitCode = 42;
}
@ -282,6 +288,8 @@ public class TibetanConverter implements FontConverterConstants {
}
if (out.checkError())
exitCode = 41;
if (numAttemptedReplacements[0] < 1)
exitCode = 43;
return exitCode;
}