return ptr;
}
-int colortoint(char *colorname, char *filename, int *lineno)
+int colortoint(char *colorname, int *bright, char *filename, int *lineno)
{
int mcolor = 0;
return -1;
if (strcasestr(colorname, "bright")) {
- mcolor += 8;
+ *bright = 1;
colorname += 6;
}
/* Parse the color stuff into the colorstrings array */
void parse_colors(FILE *rcstream, char *filename, int *lineno, char *buf, char *ptr)
{
- int i = 0, fg, bg;
+ int i = 0, fg, bg, bright = 0;
char prev = '\\';
char *tmp = NULL, *beginning, *fgstr, *bgstr;
colortype *tmpcolor = NULL;
} else
bgstr = NULL;
- fg = colortoint(fgstr, filename, lineno);
- bg = colortoint(bgstr, filename, lineno);
+ fg = colortoint(fgstr, &bright, filename, lineno);
+ bg = colortoint(bgstr, &bright, filename, lineno);
/* Now the fun part, start adding regexps to individual strings
in the colorstrings array, woo! */
colorstrings = nmalloc(sizeof(colortype));
colorstrings->fg = fg;
colorstrings->bg = bg;
+ colorstrings->bright = bright;
colorstrings->str = NULL;
colorstrings->str = nmalloc(sizeof(colorstr));
colorstrings->str->val = tmp;
colorstrings->str->next = NULL;
colorstrings->next = NULL;
} else {
- for (tmpcolor = colorstrings;
- tmpcolor->next != NULL && !(tmpcolor->fg == fg
- && tmpcolor->bg == bg); tmpcolor = tmpcolor->next)
+ for (tmpcolor = colorstrings; tmpcolor->next != NULL;
+ tmpcolor = tmpcolor->next)
;
-
- /* An entry for this color pair already exists, add it
- to the str list */
- if (tmpcolor->fg == fg && tmpcolor->bg == bg) {
- for (tmpstr = tmpcolor->str; tmpstr->next != NULL;
- tmpstr = tmpstr->next)
- ;
-
-#ifdef DEBUG
- fprintf(stderr, "Adding to existing entry for fg %d bg %d\n", fg, bg);
-#endif
-
- tmpstr->next = nmalloc (sizeof(colorstr));
- tmpstr->next->val = tmp;
- tmpstr->next->next = NULL;
- } else {
-
#ifdef DEBUG
fprintf(stderr, "Adding new entry for fg %d bg %d\n", fg, bg);
#endif
- tmpcolor->next = nmalloc(sizeof(colortype));
- tmpcolor->next->fg = fg;
- tmpcolor->next->bg = bg;
- tmpcolor->next->str = nmalloc(sizeof(colorstr));
- tmpcolor->next->str->val = tmp;
- tmpcolor->next->str->next = NULL;
- tmpcolor->next->next = NULL;
- }
+ tmpcolor->next = nmalloc(sizeof(colortype));
+ tmpcolor->next->fg = fg;
+ tmpcolor->next->bg = bg;
+ tmpcolor->next->bright = bright;
+ tmpcolor->next->str = nmalloc(sizeof(colorstr));
+ tmpcolor->next->str->val = tmp;
+ tmpcolor->next->str->next = NULL;
+ tmpcolor->next->next = NULL;
}
i = 0;
sel_data_len = end - begin;
post_data_len = this_page_end - end;
- /* Paint this line! */
- mvwaddnstr(edit, y, 0, &fileptr->data[this_page_start], pre_data_len);
-
#ifdef ENABLE_COLOR
color_on(edit, COLOR_MARKER);
#else
wattroff(edit, A_REVERSE);
#endif /* ENABLE_COLOR */
- mvwaddnstr(edit, y, end - this_page_start,
- &fileptr->data[end], post_data_len);
}
#endif
{
#ifndef NANO_SMALL
+ colortype *tmpcolor = NULL;
+ colorstr *tmpstr = NULL;
+ int k, paintlen;
+#endif
+
+
+
+ /* Just paint the string in any case (we'll add color or reverse on
+ just the text that needs it */
+ mvwaddnstr(edit, yval, 0, &fileptr->data[start],
+ get_page_end_virtual(this_page) - start + 1);
+
+#ifndef NANO_SMALL
+ if (colorstrings != NULL)
+ for (tmpcolor = colorstrings; tmpcolor != NULL; tmpcolor = tmpcolor->next) {
+ for (tmpstr = tmpcolor->str; tmpstr != NULL; tmpstr = tmpstr->next) {
+
+ k = start;
+ regcomp(&search_regexp, tmpstr->val, 0);
+ while (!regexec(&search_regexp, &fileptr->data[k], 1,
+ regmatches, 0)) {
+
+#ifdef DEBUG
+ fprintf(stderr, "Match! (%d chars) \"%s\"\n",
+ regmatches[0].rm_eo - regmatches[0].rm_so,
+ &fileptr->data[k + regmatches[0].rm_so]);
+#endif
+ if (regmatches[0].rm_so < COLS - 1) {
+ if (tmpcolor->bright)
+ wattron(edit, A_BOLD);
+ wattron(edit, COLOR_PAIR(tmpcolor->pairnum));
+
+ if (regmatches[0].rm_eo - regmatches[0].rm_so
+ + k <= COLS)
+ paintlen = regmatches[0].rm_eo - regmatches[0].rm_so;
+ else
+ paintlen = COLS - (regmatches[0].rm_eo
+ - regmatches[0].rm_so);
+
+ mvwaddnstr(edit, yval, regmatches[0].rm_so + k,
+ &fileptr->data[k + regmatches[0].rm_so],
+ paintlen);
+
+
+ }
+
+ if (tmpcolor->bright)
+ wattroff(edit, A_BOLD);
+ wattroff(edit, COLOR_PAIR(tmpcolor->pairnum));
+
+ k += regmatches[0].rm_eo;
+ }
+ }
+ }
+
/* There are quite a few cases that could take place; we'll deal
* with them each in turn */
- if (ISSET(MARK_ISSET)
- && !((fileptr->lineno > mark_beginbuf->lineno
+ if (ISSET(MARK_ISSET) &&
+ !((fileptr->lineno > mark_beginbuf->lineno
&& fileptr->lineno > current->lineno)
|| (fileptr->lineno < mark_beginbuf->lineno
&& fileptr->lineno < current->lineno))) {
#else
wattron(edit, A_REVERSE);
#endif /* ENABLE_COLOR */
- }
- target =
- (virt_mark_beginx <
- COLS - 1) ? virt_mark_beginx : COLS - 1;
+ target =
+ (virt_mark_beginx < COLS - 1) ? virt_mark_beginx : COLS - 1;
- mvwaddnstr(edit, yval, 0, fileptr->data, target);
-
- if (mark_beginbuf->lineno < current->lineno) {
+ mvwaddnstr(edit, yval, 0, fileptr->data, target);
#ifdef ENABLE_COLOR
- color_on(edit, COLOR_MARKER);
+ color_off(edit, COLOR_MARKER);
#else
- wattron(edit, A_REVERSE);
+ wattroff(edit, A_REVERSE);
#endif /* ENABLE_COLOR */
- } else {
+ }
+
+ if (mark_beginbuf->lineno < current->lineno) {
#ifdef ENABLE_COLOR
- color_off(edit, COLOR_MARKER);
+ color_on(edit, COLOR_MARKER);
#else
- wattroff(edit, A_REVERSE);
+ wattron(edit, A_REVERSE);
#endif /* ENABLE_COLOR */
- }
+ target = (COLS - 1) - virt_mark_beginx;
- target = (COLS - 1) - virt_mark_beginx;
- if (target < 0)
- target = 0;
+ if (target < 0)
+ target = 0;
- mvwaddnstr(edit, yval, virt_mark_beginx,
+ mvwaddnstr(edit, yval, virt_mark_beginx,
&fileptr->data[virt_mark_beginx], target);
- if (mark_beginbuf->lineno < current->lineno) {
-
#ifdef ENABLE_COLOR
color_off(edit, COLOR_MARKER);
#else
wattron(edit, A_REVERSE);
#endif /* ENABLE_COLOR */
- }
-
- if (virt_cur_x > COLS - 2) {
- mvwaddnstr(edit, yval, 0,
+ if (virt_cur_x > COLS - 2) {
+ mvwaddnstr(edit, yval, 0,
&fileptr->data[this_page_start],
virt_cur_x - this_page_start);
- } else {
- mvwaddnstr(edit, yval, 0, fileptr->data, virt_cur_x);
- }
-
- if (mark_beginbuf->lineno > current->lineno) {
+ } else
+ mvwaddnstr(edit, yval, 0, fileptr->data, virt_cur_x);
#ifdef ENABLE_COLOR
- color_on(edit, COLOR_MARKER);
+ color_off(edit, COLOR_MARKER);
#else
- wattron(edit, A_REVERSE);
+ wattroff(edit, A_REVERSE);
#endif /* ENABLE_COLOR */
- } else {
+ }
+
+ if (mark_beginbuf->lineno > current->lineno) {
#ifdef ENABLE_COLOR
- color_off(edit, COLOR_MARKER);
+ color_on(edit, COLOR_MARKER);
#else
- wattroff(edit, A_REVERSE);
+ wattron(edit, A_REVERSE);
#endif /* ENABLE_COLOR */
- }
-
- if (virt_cur_x > COLS - 2)
- mvwaddnstr(edit, yval, virt_cur_x - this_page_start,
+ if (virt_cur_x > COLS - 2)
+ mvwaddnstr(edit, yval, virt_cur_x - this_page_start,
&fileptr->data[virt_cur_x],
this_page_end - virt_cur_x);
- else
- mvwaddnstr(edit, yval, virt_cur_x,
+ else
+ mvwaddnstr(edit, yval, virt_cur_x,
&fileptr->data[virt_cur_x], COLS - virt_cur_x);
- if (mark_beginbuf->lineno > current->lineno) {
-
#ifdef ENABLE_COLOR
color_off(edit, COLOR_MARKER);
#else
}
}
-
- } else
-#endif
- /* Just paint the string (no mark on this line) */
- mvwaddnstr(edit, yval, 0, &fileptr->data[start],
- get_page_end_virtual(this_page) - start + 1);
-
-#ifdef ENABLE_COLOR
- {
- colortype *tmpcolor = NULL;
- colorstr *tmpstr = NULL;
- int k, paintlen;
-
- if (colorstrings != NULL)
- for (tmpcolor = colorstrings; tmpcolor != NULL; tmpcolor = tmpcolor->next) {
- for (tmpstr = tmpcolor->str; tmpstr != NULL; tmpstr = tmpstr->next) {
-
- k = start;
- regcomp(&search_regexp, tmpstr->val, 0);
- while (!regexec(&search_regexp, &fileptr->data[k], 1,
- regmatches, 0)) {
-
-#ifdef DEBUG
- fprintf(stderr, "Match! (%d chars) \"%s\"\n",
- regmatches[0].rm_eo - regmatches[0].rm_so,
- &fileptr->data[k + regmatches[0].rm_so]);
-#endif
- if (regmatches[0].rm_so < COLS - 1) {
- if (tmpcolor->fg > 8 || tmpcolor->bg > 8) {
- wattron(edit, A_BOLD);
- wattron(edit, COLOR_PAIR(tmpcolor->pairnum));
- }
- else
- wattron(edit, COLOR_PAIR(tmpcolor->pairnum));
-
- if (regmatches[0].rm_eo - regmatches[0].rm_so
- + k <= COLS)
- paintlen = regmatches[0].rm_eo - regmatches[0].rm_so;
- else
- paintlen = COLS - (regmatches[0].rm_eo
- - regmatches[0].rm_so);
-
- mvwaddnstr(edit, yval, regmatches[0].rm_so + k,
- &fileptr->data[k + regmatches[0].rm_so],
- paintlen);
-
-
- }
-
- if (tmpcolor->fg > 8 || tmpcolor->bg > 8) {
- wattroff(edit, A_BOLD);
- wattroff(edit, COLOR_PAIR(tmpcolor->pairnum));
- }
- else
- wattroff(edit, COLOR_PAIR(tmpcolor->pairnum));
-
- k += regmatches[0].rm_eo;
- }
- }
- }
}
-
#endif
}