Skip to content

Commit

Permalink
Fixed issue #1119.
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsschmidt1337 committed Oct 2, 2024
1 parent f94278f commit a03e796
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
19 changes: 17 additions & 2 deletions src/org/nschmidt/ldparteditor/helper/compositetext/Inliner.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,13 @@ public static void inline(StyledText cText, int lineStart, int lineEnd, DatFile
for (Integer l : lineNumbers) {
String line = getLine(l, text2);
NLogger.debug(Inliner.class, "Inlining: {0}", line); //$NON-NLS-1$
text2 = Inliner.inline(l, line, text2, datFile, false);
try {
text2 = Inliner.inline(l, line, text2, datFile, false);
} catch (IllegalArgumentException | IndexOutOfBoundsException | IllegalStateException e) {
// To inline binary files shouldn't work!
logInlineError(line, e);
return;
}
}
Inliner.datfile = null;
cText.setText(restoreLineTermination(text2));
Expand Down Expand Up @@ -236,7 +242,12 @@ public static void inline(StyledText cText, List<Integer> lineNumbers, DatFile d
bfcStatusTarget = bfcStatusToLine.get(l);
String line = getLine(l, text2);
NLogger.debug(Inliner.class, "Inlining: {0}", line); //$NON-NLS-1$
text2 = Inliner.inline(l, line, text2, datFile, true);
try {
text2 = Inliner.inline(l, line, text2, datFile, true);
} catch (IllegalArgumentException | IndexOutOfBoundsException | IllegalStateException e) {
logInlineError(line, e);
return;
}
}
cText.setText(restoreLineTermination(text2));
int tl = cText.getText().length();
Expand Down Expand Up @@ -382,4 +393,8 @@ private static String inline(Integer lineNumber, String line, String source, Dat
return source;
}

private static void logInlineError(String line, Exception e) {
NLogger.error(Inliner.class, e);
NLogger.error(Inliner.class, e.getMessage() + ". On line: " + line); //$NON-NLS-1$
}
}
8 changes: 7 additions & 1 deletion src/org/nschmidt/ldparteditor/text/DatParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public static List<ParsingResult> parseLine(String line, int lineNumber, int dep
int linetype = 0;
final String[] dataSegments = WHITESPACE.split(line.trim());
char c;
if (dataSegments.length < 1 || dataSegments[0].length() > 1 || !Character.isDigit(c = dataSegments[0].charAt(0))) {
if (dataSegments.length < 1 || dataSegments[0].length() != 1 || !Character.isDigit(c = dataSegments[0].charAt(0))) {
result.add(new ParsingResult(I18n.DATPARSER_INVALID_TYPE, "[E0D] " + I18n.DATPARSER_SYNTAX_ERROR, ResultType.ERROR)); //$NON-NLS-1$
return new ArrayList<>(result);
}
Expand Down Expand Up @@ -661,6 +661,7 @@ private static List<ParsingResult> parseReference(String[] dataSegments, int dep
}
sb.append(dataSegments[dataSegments.length - 1]);
String shortFilename = sb.toString();
final File localFile = new File(shortFilename);
boolean isLowercase = shortFilename.equals(shortFilename.toLowerCase(Locale.ENGLISH));
boolean containsSlash = shortFilename.chars().anyMatch(c -> c == '/');
if (containsSlash) {
Expand Down Expand Up @@ -777,6 +778,11 @@ private static List<ParsingResult> parseReference(String[] dataSegments, int dep
}
}

if (!fileExists && fileToOpen == null && localFile.exists() && localFile.isFile() && localFile.canRead()) {
fileToOpen = localFile;
fileExists = true;
}

if (isVirtual) {

if (result.isEmpty()) {
Expand Down
7 changes: 7 additions & 0 deletions src/org/nschmidt/ldparteditor/text/TexMapParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ private static GData parseReference(String[] dataSegments, int depth, float r, f
}
sb.append(dataSegments[dataSegments.length - 1]);
String shortFilename = sb.toString();
final File localFile = new File(shortFilename);
shortFilename = shortFilename.toLowerCase(Locale.ENGLISH);
shortFilename = shortFilename.replace("s\\", "S" + File.separator).replace("\\", File.separator); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
if (alreadyParsed.contains(shortFilename)) {
Expand Down Expand Up @@ -525,6 +526,12 @@ private static GData parseReference(String[] dataSegments, int depth, float r, f
}
if (isVirtual) break;
}

if (!fileExists && fileToOpen == null && localFile.exists() && localFile.isFile() && localFile.canRead()) {
fileToOpen = localFile;
fileExists = true;
}

if (isVirtual) {
Matrix4f destMatrix = new Matrix4f();
Matrix4f.mul(productMatrix, tMatrix, destMatrix);
Expand Down

0 comments on commit a03e796

Please # to comment.