diff -ur nano-1.3.0-p1/src/color.c nano-1.3.0-p2/src/color.c --- nano-1.3.0-p1/src/color.c 2003-11-01 00:49:10.000000000 -0700 +++ nano-1.3.0-p2/src/color.c 2003-11-08 23:44:09.000000000 -0700 @@ -109,6 +109,9 @@ /* use the syntax override when given */ if (syntaxstr != NULL) { + if (!strcasecmp("none", syntaxstr)) + return; + for (tmpsyntax = syntaxes; tmpsyntax != NULL; tmpsyntax = tmpsyntax->next) { if(tmpsyntax->desc == NULL) { if (!strcasecmp("default", syntaxstr)) { @@ -165,10 +168,15 @@ colortype *c; for (c = tmpsyntax->colors; c != NULL; c = c->next) { - regcomp(&c->start, c->start_regex, (c->flags.insensitive ? REG_ICASE : 0) | REG_EXTENDED); + if (c->flags.defaultcolor) + continue; + + regcomp(&c->start, c->start_regex, + (c->flags.insensitive ? REG_ICASE : 0) | REG_EXTENDED); if (c->end_regex != NULL) { c->end = (regex_t *)nmalloc(sizeof(regex_t)); - regcomp(c->end, c->end_regex, (c->flags.insensitive ? REG_ICASE : 0) | REG_EXTENDED); + regcomp(c->end, c->end_regex, + (c->flags.insensitive ? REG_ICASE : 0) | REG_EXTENDED); } } @@ -194,7 +202,7 @@ regfree((regex_t *)&color->start); regcomp((regex_t *)&color->start, color->start_regex, (color->flags.insensitive ? REG_ICASE : 0) | REG_EXTENDED); - if(color->end_regex != NULL){ + if (color->end_regex != NULL) { regfree(color->end); regcomp(color->end, color->end_regex, (color->flags.insensitive ? REG_ICASE : 0) | REG_EXTENDED); diff -ur nano-1.3.0-p1/src/nano.h nano-1.3.0-p2/src/nano.h --- nano-1.3.0-p1/src/nano.h 2003-10-31 22:20:30.000000000 -0700 +++ nano-1.3.0-p2/src/nano.h 2003-11-08 23:57:05.000000000 -0700 @@ -202,6 +202,7 @@ typedef struct colortype { struct { int insensitive:1; /* case-insensitive matches */ + int defaultcolor:1; /* default color for syntax - no regexps */ } flags; int fg; /* fg color */ int bg; /* bg color */ diff -ur nano-1.3.0-p1/src/rcfile.c nano-1.3.0-p2/src/rcfile.c --- nano-1.3.0-p1/src/rcfile.c 2003-10-31 22:21:55.000000000 -0700 +++ nano-1.3.0-p2/src/rcfile.c 2003-11-09 00:50:06.000000000 -0700 @@ -318,8 +318,8 @@ return 0; } - if (!strcasecmp("default", nameptr)) { - rcfile_error(_("-- Syntax name '%s' is reserved for the default syntax --"), nameptr); + if (!strcasecmp("default", nameptr) || !strcasecmp("none", nameptr)) { + rcfile_error(_("-- Syntax name '%s' is reserved --"), nameptr); return 0; } @@ -482,6 +482,7 @@ } #define CTFLAG_INSENSITIVE 1 +#define CTFLAG_DEFAULTCOLOR 2 /* Parse the color stuff into the colorstrings array */ void parse_colors(char *ptr, int ctflags) @@ -489,8 +490,7 @@ int fg, bg, bright = 0; int expectend = 0; /* Do we expect an end= line? */ char *fgstr; - colortype *tmpcolor = NULL; - syntaxtype *tmpsyntax = NULL; + syntaxtype *tmpsyntax; fgstr = ptr; ptr = parse_next_word(ptr); @@ -525,7 +525,42 @@ /* Now the fun part, start adding regexps to individual strings in the colorstrings array, woo! */ - while (*ptr != '\0') { + if (ctflags & CTFLAG_DEFAULTCOLOR) { + colortype *newcolor; + /* The new color structure. */ + + while (*ptr != '\0' && *ptr == ' ') + ptr++; + if (*ptr != '\0') { + rcfile_error(_("-- The default-color directive should only have a single color parameter --")); + return; + } + + newcolor = (colortype *)nmalloc(sizeof(colortype)); + + /* insensitive flag is ignored */ + newcolor->flags.defaultcolor = 1; + + newcolor->fg = fg; + newcolor->bg = bg; + newcolor->bright = bright; + newcolor->next = NULL; + newcolor->start_regex = NULL; + newcolor->end_regex = NULL; + newcolor->end = NULL; + newcolor->counter = 0; + + if (tmpsyntax->colors == NULL) { + tmpsyntax->colors = newcolor; +#ifdef DEBUG + fprintf(stderr, "Setting a default color for fg %d bg %d\n", fg, bg); +#endif + } else { + free(newcolor); + rcfile_error(_("-- Default color must be set before any other colors --")); + return; + } + } else while (*ptr != '\0') { colortype *newcolor; /* The new color structure. */ int cancelled = 0; @@ -561,6 +596,7 @@ cancelled = 1; } else { newcolor->flags.insensitive = ctflags & CTFLAG_INSENSITIVE; + newcolor->flags.defaultcolor = 0; newcolor->fg = fg; newcolor->bg = bg; @@ -577,6 +613,8 @@ fg, bg); #endif } else { + colortype *tmpcolor = NULL; + for (tmpcolor = tmpsyntax->colors; tmpcolor->next != NULL; tmpcolor = tmpcolor->next) ; @@ -655,49 +693,54 @@ if (!strcasecmp(keyword, "set")) { #ifdef ENABLE_COLOR if (color_only) - rcfile_error(_("-- Cannot add a set directive inside included files --")); + rcfile_error(_("-- Cannot use a set directive inside included files --")); else #endif set = 1; } else if (!strcasecmp(keyword, "unset")) { #ifdef ENABLE_COLOR if (color_only) - rcfile_error(_("-- Cannot add an unset directive inside included files --")); + rcfile_error(_("-- Cannot use an unset directive inside included files --")); else #endif set = -1; #ifdef ENABLE_COLOR } else if (!strcasecmp(keyword, "syntax")) { - if (color_only) - rcfile_error(_("-- Cannot add a syntax directive inside included files --")); - else { + if (color_only) { + rcfile_error(_("-- Cannot use a syntax directive inside included files --")); + } else { syntax_ok = parse_syntax(ptr); syntax = 1; } } else if (!strcasecmp(keyword, "default-syntax")) { - if (color_only) - rcfile_error(_("-- Cannot add a default-syntax directive inside included files --")); - else { + if (color_only) { + rcfile_error(_("-- Cannot use a default-syntax directive inside included files --")); + } else { syntax_ok = parse_defaultsyntax(ptr); syntax = 1; } } else if (!strcasecmp(keyword, "include")) { if (color_only) - rcfile_error(_("-- Cannot add an include directive inside included files --")); + rcfile_error(_("-- Cannot use an include directive inside included files --")); else if (!syntax) - rcfile_error(_("-- Cannot add an include directive without a syntax line --")); + rcfile_error(_("-- Cannot use an include directive without a syntax line --")); else if (syntax_ok) parse_include(ptr); } else if (!strcasecmp(keyword, "color")) { if (!syntax) - rcfile_error(_("-- Cannot add a color directive without a syntax line --")); + rcfile_error(_("-- Cannot use a color directive without a syntax line --")); else if (syntax_ok) parse_colors(ptr, 0); } else if (!strcasecmp(keyword, "icolor")) { if (!syntax) - rcfile_error(_("-- Cannot add an icolor directive without a syntax line --")); + rcfile_error(_("-- Cannot use an icolor directive without a syntax line --")); else if (syntax_ok) parse_colors(ptr, CTFLAG_INSENSITIVE); + } else if (!strcasecmp(keyword, "default-color")) { + if (!syntax) + rcfile_error(_("-- Cannot use a default-color directive without a syntax line --")); + else if (syntax_ok) + parse_colors(ptr, CTFLAG_DEFAULTCOLOR); #endif /* ENABLE_COLOR */ } else { rcfile_msg(_("Command %s not understood"), keyword); @@ -810,6 +853,33 @@ return; } +void display_syntax_colors(int level, char *desc, const colortype *color) +{ + for (; color != NULL; color = color->next) { + char *colorname; + int n; + + printf("%s: ", desc == NULL ? "default" : desc); + + for (n = 0; n < level; n++) + printf(" "); + + /* TODO: display human readable color names */ + colorname = "---"; + + if (color->flags.defaultcolor) + printf("default-color %s\n", colorname); + else if (color->end_regex == NULL) + printf("%s %s \"%s\"\n", + color->flags.insensitive ? "icolor" : "color", + colorname, color->start_regex); + else + printf("%s %s start=\"%s\" end=\"%s\"\n", + color->flags.insensitive ? "icolor" : "color", + colorname, color->start_regex, color->end_regex); + } +} + /* The main rc file function, tries to open the rc file */ void do_rcfile(void) { @@ -880,23 +950,15 @@ const syntaxtype *tmpsyntax; for(tmpsyntax = syntaxes; tmpsyntax != NULL; tmpsyntax = tmpsyntax->next) { - const colortype *tmpcolor; + const exttype *ext; - for(tmpcolor = tmpsyntax->colors; tmpcolor != NULL; tmpcolor = tmpcolor->next) { - if (tmpcolor->end_regex == NULL) - printf("%s: %s \"%s\"\n", - tmpsyntax->desc == NULL ? "default" : tmpsyntax->desc, - tmpcolor->flags.insensitive ? "icolor" : "color", - tmpcolor->start_regex); - else - printf("%s: %s start=\"%s\" end=\"%s\"\n", - tmpsyntax->desc == NULL ? "*" : tmpsyntax->desc, - tmpcolor->flags.insensitive ? "icolor" : "color", - tmpcolor->start_regex, tmpcolor->end_regex); + for (ext = tmpsyntax->extensions; ext != NULL; ext = ext->next) + printf("%s: extension \"%s\"\n", + tmpsyntax->desc == NULL ? "default" : tmpsyntax->desc, + ext->ext_regex); - /* TODO: display human readable color names */ + display_syntax_colors(0, tmpsyntax->desc, tmpsyntax->colors); - } printf("\n"); } exit(1); diff -ur nano-1.3.0-p1/src/winio.c nano-1.3.0-p2/src/winio.c --- nano-1.3.0-p1/src/winio.c 2003-11-03 18:48:08.000000000 -0700 +++ nano-1.3.0-p2/src/winio.c 2003-11-09 01:21:03.000000000 -0700 @@ -748,7 +748,7 @@ xend = strlen(history); /* if there is no newer search, we're here */ - + /* if currentbuf isn't NULL and use_cb isn't 2, it means that we're scrolling down at the bottom of the search history and we need to make the string in currentbuf @@ -1034,15 +1034,29 @@ assert(fileptr != NULL && converted != NULL); assert(strlen(converted) <= COLS); - /* Just paint the string in any case (we'll add color or reverse on - * just the text that needs it). */ - mvwaddstr(edit, yval, 0, converted); - #ifdef ENABLE_COLOR if (colorstrings != NULL && ISSET(COLOR_SYNTAX)) { - const colortype *tmpcolor; + const colortype *tmpcolor = colorstrings; + + if (tmpcolor->flags.defaultcolor) { + if (tmpcolor->bright) + wattron(edit, A_BOLD); + wattron(edit, COLOR_PAIR(tmpcolor->pairnum)); + + /* Display line - color will be added to just the text that needs it */ + mvwaddstr(edit, yval, 0, converted); + + if (tmpcolor->bright) + wattroff(edit, A_BOLD); + wattroff(edit, COLOR_PAIR(tmpcolor->pairnum)); + + tmpcolor = tmpcolor->next; + } else { + /* Display line - color will be added to just the text that needs it */ + mvwaddstr(edit, yval, 0, converted); + } - for (tmpcolor = colorstrings; tmpcolor != NULL; tmpcolor = tmpcolor->next) { + for (; tmpcolor != NULL; tmpcolor = tmpcolor->next) { int x_start; /* Starting column for mvwaddnstr. Zero-based. */ int paintlen; @@ -1075,12 +1089,15 @@ if (regexec_wrapper(tmpcolor, &tmpcolor->start, &fileptr->data[k], 1, &startmatch, k == 0 ? 0 : REG_NOTBOL) == REG_NOMATCH) break; + /* Translate the match to the beginning of the line. */ startmatch.rm_so += k; startmatch.rm_eo += k; + if (startmatch.rm_so == startmatch.rm_eo) { - startmatch.rm_eo++; - statusbar(_("Refusing 0 length regex match")); + /* Abort to prevent problems with this bad regular expression */ + statusbar(_("Refusing zero length \"%s\" regex match"), tmpcolor->start_regex); + break; } else if (startmatch.rm_so < endpos && startmatch.rm_eo > startpos) { if (startmatch.rm_so <= startpos) @@ -1254,11 +1271,18 @@ } /* if (tmp_color->end != NULL) */ skip_step_two: + if (tmpcolor->bright) wattroff(edit, A_BOLD); wattroff(edit, COLOR_PAIR(tmpcolor->pairnum)); } /* for tmpcolor in colorstrings */ + } else { + /* Display line - reverse will be added to just the text that needs it */ + mvwaddstr(edit, yval, 0, converted); } +#else + /* Display line - reverse will be added to just the text that needs it */ + mvwaddstr(edit, yval, 0, converted); #endif /* ENABLE_COLOR */ #ifndef NANO_SMALL