tweaks: rearrange and reindent some lines in the painting routines

Also adjust a few comments.
master
Benno Schulenberg 2017-01-07 20:42:37 +01:00
parent 8177e62c18
commit 88cf22f804
1 changed files with 25 additions and 31 deletions

View File

@ -2357,10 +2357,8 @@ void edit_draw(filestruct *fileptr, const char *converted, int
* COLS characters on a whole line. */ * COLS characters on a whole line. */
size_t index; size_t index;
/* Index in converted where we paint. */ /* Index in converted where we paint. */
regmatch_t startmatch; regmatch_t startmatch, endmatch;
/* Match position for start_regex. */ /* Match positions for the start and end regexes. */
regmatch_t endmatch;
/* Match position for end_regex. */
wattron(edit, varnish->attributes); wattron(edit, varnish->attributes);
/* Two notes about regexec(). A return value of zero means /* Two notes about regexec(). A return value of zero means
@ -2394,7 +2392,7 @@ void edit_draw(filestruct *fileptr, const char *converted, int
if (startmatch.rm_so == startmatch.rm_eo) if (startmatch.rm_so == startmatch.rm_eo)
startmatch.rm_eo++; startmatch.rm_eo++;
else if (startmatch.rm_so < endpos && else if (startmatch.rm_so < endpos &&
startmatch.rm_eo > startpos) { startmatch.rm_eo > startpos) {
x_start = (startmatch.rm_so <= startpos) ? 0 : x_start = (startmatch.rm_so <= startpos) ? 0 :
strnlenpt(fileptr->data, strnlenpt(fileptr->data,
startmatch.rm_so) - start; startmatch.rm_so) - start;
@ -2407,8 +2405,8 @@ void edit_draw(filestruct *fileptr, const char *converted, int
assert(0 <= x_start && 0 <= paintlen); assert(0 <= x_start && 0 <= paintlen);
mvwaddnstr(edit, line, x_start + margin, converted + mvwaddnstr(edit, line, x_start + margin,
index, paintlen); converted + index, paintlen);
} }
k = startmatch.rm_eo; k = startmatch.rm_eo;
} }
@ -2432,15 +2430,20 @@ void edit_draw(filestruct *fileptr, const char *converted, int
if (endmatch.rm_eo <= startpos) if (endmatch.rm_eo <= startpos)
goto tail_of_loop; goto tail_of_loop;
paintlen = actual_x(converted, strnlenpt(fileptr->data, paintlen = actual_x(converted, strnlenpt(fileptr->data,
endmatch.rm_eo) - start); endmatch.rm_eo) - start);
mvwaddnstr(edit, line, margin, converted, paintlen); mvwaddnstr(edit, line, margin, converted, paintlen);
goto tail_of_loop; goto tail_of_loop;
} if (fileptr->multidata[varnish->id] == -1) }
/* Assume this until proven otherwise below. */
/* There is no precalculated multidata, or it is CENDAFTER or
* CSTARTENDHERE. In all cases, find out what to paint. */
/* When the multidata is unitialized, assume CNONE until one
* of the steps below concludes otherwise. */
if (fileptr->multidata[varnish->id] == -1)
fileptr->multidata[varnish->id] = CNONE; fileptr->multidata[varnish->id] = CNONE;
/* There is no precalculated multidata, so find it out now. /* First check if the beginning of the line is colored by a
* First check if the beginning of the line is colored by a
* start on an earlier line, and an end on this line or later. * start on an earlier line, and an end on this line or later.
* *
* So: find the first line before fileptr matching the start. * So: find the first line before fileptr matching the start.
@ -2510,42 +2513,33 @@ void edit_draw(filestruct *fileptr, const char *converted, int
goto step_two; goto step_two;
} }
/* Now paint the start of fileptr. If the start of fileptr /* Now paint the start of the line. However, if the end match
* is on a different line from the end, paintlen is -1, which * is on a different line, paint the whole line, and go on. */
* means that everything on the line gets painted. Otherwise,
* paintlen is the expanded location of the end of the match
* minus the expanded location of the beginning of the page. */
if (end_line != fileptr) { if (end_line != fileptr) {
paintlen = -1; mvwaddnstr(edit, line, margin, converted, -1);
fileptr->multidata[varnish->id] = CWHOLELINE; fileptr->multidata[varnish->id] = CWHOLELINE;
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, " Marking for id %i line %i as CWHOLELINE\n", varnish->id, line); fprintf(stderr, " Marking for id %i line %i as CWHOLELINE\n", varnish->id, line);
#endif #endif
/* Don't bother looking for any more starts. */
goto tail_of_loop;
} else { } else {
paintlen = actual_x(converted, strnlenpt(fileptr->data, paintlen = actual_x(converted, strnlenpt(fileptr->data,
endmatch.rm_eo) - start); endmatch.rm_eo) - start);
mvwaddnstr(edit, line, margin, converted, paintlen);
fileptr->multidata[varnish->id] = CBEGINBEFORE; fileptr->multidata[varnish->id] = CBEGINBEFORE;
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, " Marking for id %i line %i as CBEGINBEFORE\n", varnish->id, line); fprintf(stderr, " Marking for id %i line %i as CBEGINBEFORE\n", varnish->id, line);
#endif #endif
} }
mvwaddnstr(edit, line, margin, converted, paintlen);
/* If the whole line has been painted, don't bother looking
* for any more starts. */
if (paintlen < 0)
goto tail_of_loop;
step_two: step_two:
/* Second step: look for starts on this line, but start /* Second step: look for starts on this line, but begin
* looking only after an end match, if there is one. */ * looking only after an end match, if there is one. */
start_col = (paintlen == 0) ? 0 : endmatch.rm_eo; start_col = (paintlen == 0) ? 0 : endmatch.rm_eo;
while (TRUE) { while (regexec(varnish->start, fileptr->data + start_col,
if (regexec(varnish->start, fileptr->data + start_col,
1, &startmatch, (start_col == 0) ? 1, &startmatch, (start_col == 0) ?
0 : REG_NOTBOL) == REG_NOMATCH) 0 : REG_NOTBOL) == 0) {
/* No more starts on this line. */
break;
/* Translate the match to be relative to the /* Translate the match to be relative to the
* beginning of the line. */ * beginning of the line. */
startmatch.rm_so += start_col; startmatch.rm_so += start_col;
@ -2569,7 +2563,7 @@ void edit_draw(filestruct *fileptr, const char *converted, int
* it appear on this page, and is the match * it appear on this page, and is the match
* more than zero characters long? */ * more than zero characters long? */
if (endmatch.rm_eo > startpos && if (endmatch.rm_eo > startpos &&
endmatch.rm_eo > startmatch.rm_so) { endmatch.rm_eo > startmatch.rm_so) {
paintlen = actual_x(converted + index, paintlen = actual_x(converted + index,
strnlenpt(fileptr->data, strnlenpt(fileptr->data,
endmatch.rm_eo) - start - x_start); endmatch.rm_eo) - start - x_start);