tweaks: frob some comments, and reshuffle two fragments of code

master
Benno Schulenberg 2021-01-28 12:11:52 +01:00
parent befe4ea5de
commit 85cc99a2a3
1 changed files with 13 additions and 15 deletions

View File

@ -317,24 +317,24 @@ void precalc_multicolorinfo(void)
for (line = openfile->filetop; line != NULL; line = line->next) { for (line = openfile->filetop; line != NULL; line = line->next) {
int index = 0; int index = 0;
/* Assume nothing applies until proven otherwise below. */ /* For an unpaired start match, mark each remaining line. */
line->multidata[ink->id] = CNONE;
/* For an unpaired start match, mark all remaining lines. */
if (line->prev && line->prev->multidata[ink->id] == CWOULDBE) { if (line->prev && line->prev->multidata[ink->id] == CWOULDBE) {
line->multidata[ink->id] = CWOULDBE; line->multidata[ink->id] = CWOULDBE;
continue; continue;
} }
/* When the line contains a start match, look for an end, and if /* Assume nothing applies until proven otherwise below. */
* found, mark all the lines that are affected. */ line->multidata[ink->id] = CNONE;
/* When the line contains a start match, look for an end,
* and if found, mark all the lines that are affected. */
while (regexec(ink->start, line->data + index, 1, while (regexec(ink->start, line->data + index, 1,
&startmatch, (index == 0) ? 0 : REG_NOTBOL) == 0) { &startmatch, (index == 0) ? 0 : REG_NOTBOL) == 0) {
/* Begin looking for an end match after the start match. */ /* Begin looking for an end match after the start match. */
index += startmatch.rm_eo; index += startmatch.rm_eo;
/* If there is an end match on this line, mark the line, but /* If there is an end match on this line, mark the line,
* continue looking for other starts after it. */ * but continue looking for other starts after it. */
if (regexec(ink->end, line->data + index, 1, if (regexec(ink->end, line->data + index, 1,
&endmatch, (index == 0) ? 0 : REG_NOTBOL) == 0) { &endmatch, (index == 0) ? 0 : REG_NOTBOL) == 0) {
line->multidata[ink->id] = CSTARTENDHERE; line->multidata[ink->id] = CSTARTENDHERE;
@ -353,27 +353,25 @@ void precalc_multicolorinfo(void)
/* Look for an end match on later lines. */ /* Look for an end match on later lines. */
tailline = line->next; tailline = line->next;
while (tailline != NULL) { while (tailline && regexec(ink->end, tailline->data,
if (regexec(ink->end, tailline->data, 1, &endmatch, 0) == 0) 1, &endmatch, 0) != 0)
break;
tailline = tailline->next; tailline = tailline->next;
}
if (tailline == NULL) { if (tailline == NULL) {
line->multidata[ink->id] = CWOULDBE; line->multidata[ink->id] = CWOULDBE;
break; break;
} }
/* We found it, we found it, la la la la la. Mark all /* We found it, we found it, la lala lala. Mark the lines. */
* the lines in between and the end properly. */
line->multidata[ink->id] = CENDAFTER; line->multidata[ink->id] = CENDAFTER;
// Note that this also advances the line in the main loop.
for (line = line->next; line != tailline; line = line->next) for (line = line->next; line != tailline; line = line->next)
line->multidata[ink->id] = CWHOLELINE; line->multidata[ink->id] = CWHOLELINE;
tailline->multidata[ink->id] = CBEGINBEFORE; tailline->multidata[ink->id] = CBEGINBEFORE;
/* Begin looking for a new start after the end match. */ /* Look for a possible new start after the end match. */
index = endmatch.rm_eo; index = endmatch.rm_eo;
} }
} }