Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempting to fix the curly brackets bug #166

Merged
merged 11 commits into from
Nov 4, 2023
33 changes: 27 additions & 6 deletions src/mminou.c
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ void printLongLine(const char *line, const char *startNextLine, const char *brea
vstring_def(prefix);
vstring_def(startNextLine1);
vstring_def(breakMatch1);
long i, j, p;
long i, j, p, k;
long startNextLineLen;
flag firstLine;
flag tildeFlag = 0;
Expand Down Expand Up @@ -546,6 +546,12 @@ void printLongLine(const char *line, const char *startNextLine, const char *brea
breakMatch1[0] = ' '; // Change to a space (the real break character)
}

// Do a bug check to make sure no real ASCII 3's are ever printed
j = (long)strlen(multiLine);
for (i = 0; i < j; i++) {
if (multiLine[i] == QUOTED_SPACE) bug(1514); // Should never be the case
}

// HTML mode
// The HTML mode is intended not to break inside quoted HTML tag
// strings. All HTML output should be called with this mode.
Expand All @@ -559,11 +565,6 @@ void printLongLine(const char *line, const char *startNextLine, const char *brea
// where all ASCII 3's are converted back to space.
// Note added 20-Oct-02: tidy.exe breaks HREF quotes with new line.
// Check HTML spec - do we really need this code?
j = (long)strlen(multiLine);
// Do a bug check to make sure no real ASCII 3's are ever printed
for (i = 0; i < j; i++) {
if (multiLine[i] == QUOTED_SPACE) bug(1514); // Should never be the case
}
if (breakMatch1[0] == '\"') {
breakMatch1[0] = ' '; // Change to a space (the real break character)
// Scan string for quoted strings
Expand All @@ -587,6 +588,26 @@ void printLongLine(const char *line, const char *startNextLine, const char *brea
}
} // if (breakMatch1[0] == '\"')

// TeX mode
// The TeX mode is intended not to break inside curly brace scopes.
// Whenever we are inside a scope of curly braces, we change a space to
// ASCII 3 to prevent matching it. The reverse is done in the print2()
// function, where all ASCII 3's are converted back to space.
if (breakMatch1[0] == ' ') {
i = 0;
// k counts the scope level we are in.
k = 0;
while (multiLine[i]) {
// We enter a non "\{" scope.
if (multiLine[i] == '{' && multiLine[i - 1] != '\\') k++;
// We escape a non "\}" scope.
if (multiLine[i] == '}' && multiLine[i - 1] != '\\') k--;
// If k > 0 then we are inside a scope.
if (multiLine[i] == ' ' && k > 0) multiLine[i] = QUOTED_SPACE;
i++;
}
}

GinoGiotto marked this conversation as resolved.
Show resolved Hide resolved
// The tilde is a special flag for printLongLine to print a
// tilde before the carriage return in a split line, not after.
if (startNextLine1[0] == '~') {
Expand Down
Loading