Using less memory and time to figure out if warnings occurred.
This commit is contained in:
parent
76c2e969ac
commit
01e65176d4
4 changed files with 31 additions and 15 deletions
|
@ -241,12 +241,16 @@ public class TibetanConverter implements FontConverterConstants {
|
||||||
} catch (ThdlLazyException e) {
|
} catch (ThdlLazyException e) {
|
||||||
out.println("TibetanConverter has a BUG:");
|
out.println("TibetanConverter has a BUG:");
|
||||||
e.getRealException().printStackTrace(out);
|
e.getRealException().printStackTrace(out);
|
||||||
|
System.err.println("TibetanConverter has a BUG:");
|
||||||
|
e.getRealException().printStackTrace(System.err);
|
||||||
return 7;
|
return 7;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace(out);
|
e.printStackTrace(out);
|
||||||
|
e.printStackTrace(System.err);
|
||||||
return 4;
|
return 4;
|
||||||
} catch (OutOfMemoryError e) {
|
} catch (OutOfMemoryError e) {
|
||||||
e.printStackTrace(out);
|
e.printStackTrace(out);
|
||||||
|
e.printStackTrace(System.err);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -263,26 +267,27 @@ public class TibetanConverter implements FontConverterConstants {
|
||||||
try {
|
try {
|
||||||
ArrayList al = ACIPTshegBarScanner.scanStream(in, null,
|
ArrayList al = ACIPTshegBarScanner.scanStream(in, null,
|
||||||
ThdlOptions.getIntegerOption("thdl.most.errors.a.tibetan.acip.document.can.have",
|
ThdlOptions.getIntegerOption("thdl.most.errors.a.tibetan.acip.document.can.have",
|
||||||
250 - 1)
|
1000 - 1)
|
||||||
);
|
);
|
||||||
if (null == al)
|
if (null == al)
|
||||||
return 47;
|
return 47;
|
||||||
StringBuffer warnings = new StringBuffer();
|
|
||||||
boolean embeddedWarnings = (warningLevel != "None");
|
boolean embeddedWarnings = (warningLevel != "None");
|
||||||
|
boolean hasWarnings[] = new boolean[] { false };
|
||||||
if (ACIP_TO_UNI_TEXT == ct) {
|
if (ACIP_TO_UNI_TEXT == ct) {
|
||||||
if (!ACIPConverter.convertToUnicodeText(al, out, null,
|
if (!ACIPConverter.convertToUnicodeText(al, out, null,
|
||||||
warnings,
|
null, hasWarnings,
|
||||||
embeddedWarnings,
|
embeddedWarnings,
|
||||||
warningLevel))
|
warningLevel))
|
||||||
return 46;
|
return 46;
|
||||||
} else {
|
} else {
|
||||||
if (ct != ACIP_TO_TMW) throw new Error("badness");
|
if (ct != ACIP_TO_TMW) throw new Error("badness");
|
||||||
if (!ACIPConverter.convertToTMW(al, out, null, warnings,
|
if (!ACIPConverter.convertToTMW(al, out, null, null,
|
||||||
|
hasWarnings,
|
||||||
embeddedWarnings,
|
embeddedWarnings,
|
||||||
warningLevel, colors))
|
warningLevel, colors))
|
||||||
return 46;
|
return 46;
|
||||||
}
|
}
|
||||||
if (embeddedWarnings && warnings.length() > 0)
|
if (embeddedWarnings && hasWarnings[0])
|
||||||
return 45;
|
return 45;
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -348,7 +348,7 @@ public class TibTextUtils implements THDLWylieConstants {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
int tloc[] = new int[] { loc };
|
int tloc[] = new int[] { loc };
|
||||||
ACIPConverter.convertToTMW(al, tdoc, null, null,
|
ACIPConverter.convertToTMW(al, tdoc, null, null, null,
|
||||||
putWarningsInOutput, warningLevel,
|
putWarningsInOutput, warningLevel,
|
||||||
colors, tloc);
|
colors, tloc);
|
||||||
return tloc[0] - loc;
|
return tloc[0] - loc;
|
||||||
|
|
|
@ -55,7 +55,7 @@ public class ACIPConverter {
|
||||||
System.out.println("Bad args! Need just the name of the ACIP text file.");
|
System.out.println("Bad args! Need just the name of the ACIP text file.");
|
||||||
}
|
}
|
||||||
StringBuffer errors = new StringBuffer();
|
StringBuffer errors = new StringBuffer();
|
||||||
int maxErrors = 250;
|
int maxErrors = 1000; // DLC NOW PER CAPITA
|
||||||
ArrayList al = ACIPTshegBarScanner.scanFile(args[0], errors, maxErrors - 1);
|
ArrayList al = ACIPTshegBarScanner.scanFile(args[0], errors, maxErrors - 1);
|
||||||
|
|
||||||
if (null == al) {
|
if (null == al) {
|
||||||
|
@ -88,7 +88,7 @@ public class ACIPConverter {
|
||||||
warnings = new StringBuffer();
|
warnings = new StringBuffer();
|
||||||
putWarningsInOutput = true;
|
putWarningsInOutput = true;
|
||||||
}
|
}
|
||||||
convertToTMW(al, System.out, errors, warnings,
|
convertToTMW(al, System.out, errors, warnings, null,
|
||||||
putWarningsInOutput, warningLevel, colors);
|
putWarningsInOutput, warningLevel, colors);
|
||||||
int retCode = 0;
|
int retCode = 0;
|
||||||
if (errors.length() > 0) {
|
if (errors.length() > 0) {
|
||||||
|
@ -128,6 +128,7 @@ public class ACIPConverter {
|
||||||
OutputStream out,
|
OutputStream out,
|
||||||
StringBuffer errors,
|
StringBuffer errors,
|
||||||
StringBuffer warnings,
|
StringBuffer warnings,
|
||||||
|
boolean[] hasWarnings,
|
||||||
boolean writeWarningsToResult,
|
boolean writeWarningsToResult,
|
||||||
String warningLevel,
|
String warningLevel,
|
||||||
boolean colors)
|
boolean colors)
|
||||||
|
@ -135,7 +136,7 @@ public class ACIPConverter {
|
||||||
{
|
{
|
||||||
TibetanDocument tdoc = new TibetanDocument();
|
TibetanDocument tdoc = new TibetanDocument();
|
||||||
boolean rv
|
boolean rv
|
||||||
= convertToTMW(scan, tdoc, errors, warnings,
|
= convertToTMW(scan, tdoc, errors, warnings, hasWarnings,
|
||||||
writeWarningsToResult, warningLevel, colors,
|
writeWarningsToResult, warningLevel, colors,
|
||||||
new int[] { tdoc.getLength() });
|
new int[] { tdoc.getLength() });
|
||||||
tdoc.writeRTFOutputStream(out);
|
tdoc.writeRTFOutputStream(out);
|
||||||
|
@ -155,6 +156,7 @@ public class ACIPConverter {
|
||||||
TibetanDocument tdoc,
|
TibetanDocument tdoc,
|
||||||
StringBuffer errors,
|
StringBuffer errors,
|
||||||
StringBuffer warnings,
|
StringBuffer warnings,
|
||||||
|
boolean[] hasWarnings,
|
||||||
boolean writeWarningsToResult,
|
boolean writeWarningsToResult,
|
||||||
String warningLevel,
|
String warningLevel,
|
||||||
boolean colors,
|
boolean colors,
|
||||||
|
@ -162,8 +164,8 @@ public class ACIPConverter {
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
return convertTo(false, true, scan, null, tdoc, errors, warnings,
|
return convertTo(false, true, scan, null, tdoc, errors, warnings,
|
||||||
writeWarningsToResult, warningLevel, colors,
|
hasWarnings, writeWarningsToResult, warningLevel,
|
||||||
loc, loc[0] == tdoc.getLength());
|
colors, loc, loc[0] == tdoc.getLength());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns UTF-8 encoded Unicode. A bit indirect, so use this
|
/** Returns UTF-8 encoded Unicode. A bit indirect, so use this
|
||||||
|
@ -187,7 +189,7 @@ public class ACIPConverter {
|
||||||
try {
|
try {
|
||||||
if (null != al) {
|
if (null != al) {
|
||||||
convertToUnicodeText(al, sw, errors,
|
convertToUnicodeText(al, sw, errors,
|
||||||
warnings, writeWarningsToResult,
|
warnings, null, writeWarningsToResult,
|
||||||
warningLevel);
|
warningLevel);
|
||||||
return sw.toString("UTF-8");
|
return sw.toString("UTF-8");
|
||||||
} else {
|
} else {
|
||||||
|
@ -212,6 +214,9 @@ public class ACIPConverter {
|
||||||
* @param errors if non-null, all error messages are appended
|
* @param errors if non-null, all error messages are appended
|
||||||
* @param warnings if non-null, all warning messages appropriate
|
* @param warnings if non-null, all warning messages appropriate
|
||||||
* to warningLevel are appended
|
* to warningLevel are appended
|
||||||
|
* @param hasWarnings if non-null, then hasWarnings[0] will be
|
||||||
|
* updated to true if and only if warnings are encountered and
|
||||||
|
* false otherwise
|
||||||
* @param writeWarningsToOut if true, then all warning messages
|
* @param writeWarningsToOut if true, then all warning messages
|
||||||
* are written to out in the appropriate places
|
* are written to out in the appropriate places
|
||||||
* @throws IOException if we cannot write to out
|
* @throws IOException if we cannot write to out
|
||||||
|
@ -220,12 +225,14 @@ public class ACIPConverter {
|
||||||
OutputStream out,
|
OutputStream out,
|
||||||
StringBuffer errors,
|
StringBuffer errors,
|
||||||
StringBuffer warnings,
|
StringBuffer warnings,
|
||||||
|
boolean[] hasWarnings,
|
||||||
boolean writeWarningsToOut,
|
boolean writeWarningsToOut,
|
||||||
String warningLevel)
|
String warningLevel)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
return convertTo(true, false, scan, out, null, errors, warnings,
|
return convertTo(true, false, scan, out, null, errors, warnings,
|
||||||
writeWarningsToOut, warningLevel, false, new int[] { -1 } , true);
|
hasWarnings, writeWarningsToOut, warningLevel, false,
|
||||||
|
new int[] { -1 } , true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean peekaheadFindsSpacesAndComma(ArrayList /* of TString */ scan,
|
private static boolean peekaheadFindsSpacesAndComma(ArrayList /* of TString */ scan,
|
||||||
|
@ -253,6 +260,7 @@ public class ACIPConverter {
|
||||||
TibetanDocument tdoc, // for !toUnicode mode or (toUnicode && toRTF) mode
|
TibetanDocument tdoc, // for !toUnicode mode or (toUnicode && toRTF) mode
|
||||||
StringBuffer errors,
|
StringBuffer errors,
|
||||||
StringBuffer warnings,
|
StringBuffer warnings,
|
||||||
|
boolean[] hasWarnings,
|
||||||
boolean writeWarningsToOut,
|
boolean writeWarningsToOut,
|
||||||
String warningLevel,
|
String warningLevel,
|
||||||
boolean colors,
|
boolean colors,
|
||||||
|
@ -299,6 +307,7 @@ public class ACIPConverter {
|
||||||
|
|
||||||
int sz = scan.size();
|
int sz = scan.size();
|
||||||
boolean hasErrors = false;
|
boolean hasErrors = false;
|
||||||
|
if (null != hasWarnings) hasWarnings[0] = false;
|
||||||
BufferedWriter writer = null;
|
BufferedWriter writer = null;
|
||||||
if (toUnicode && !toRTF)
|
if (toUnicode && !toRTF)
|
||||||
writer
|
writer
|
||||||
|
@ -360,6 +369,7 @@ public class ACIPConverter {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null != warnings) {
|
if (null != warnings) {
|
||||||
|
if (null != hasWarnings) hasWarnings[0] = true;
|
||||||
warnings.append("Warning: Lexical warning: ");
|
warnings.append("Warning: Lexical warning: ");
|
||||||
warnings.append(s.getText());
|
warnings.append(s.getText());
|
||||||
warnings.append('\n');
|
warnings.append('\n');
|
||||||
|
@ -424,7 +434,7 @@ public class ACIPConverter {
|
||||||
// differently, but now, I think
|
// differently, but now, I think
|
||||||
// this is impossible. DLC FIXME:
|
// this is impossible. DLC FIXME:
|
||||||
// run with -Dthdl.debug=true on
|
// run with -Dthdl.debug=true on
|
||||||
// all ACIP Release IV texts you
|
// all ACIP Release V texts you
|
||||||
// can find.
|
// can find.
|
||||||
ThdlDebug.noteIffyCode();
|
ThdlDebug.noteIffyCode();
|
||||||
hasErrors = true;
|
hasErrors = true;
|
||||||
|
@ -479,6 +489,7 @@ public class ACIPConverter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (null != warnings) {
|
if (null != warnings) {
|
||||||
|
if (null != hasWarnings) hasWarnings[0] = true;
|
||||||
warnings.append(warning);
|
warnings.append(warning);
|
||||||
warnings.append('\n');
|
warnings.append('\n');
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ public class ACIPTshegBarScanner {
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
StringBuffer errors = new StringBuffer();
|
StringBuffer errors = new StringBuffer();
|
||||||
int maxErrors = 250;
|
int maxErrors = 1000;
|
||||||
ArrayList al = scanFile(args[0], errors, maxErrors - 1);
|
ArrayList al = scanFile(args[0], errors, maxErrors - 1);
|
||||||
|
|
||||||
if (null == al) {
|
if (null == al) {
|
||||||
|
|
Loading…
Reference in a new issue