Commit 202d3c2f authored by David Lawrence Ramsey's avatar David Lawrence Ramsey
Browse files

add DB's overhaul of the rcfile parsing code and related miscellaneous

bits


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2345 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
No related merge requests found
Showing with 288 additions and 288 deletions
+288 -288
...@@ -162,6 +162,15 @@ CVS code - ...@@ -162,6 +162,15 @@ CVS code -
routine to get the current user's home directory into the new routine to get the current user's home directory into the new
function get_homedir(), and use it where necessary. Also add function get_homedir(), and use it where necessary. Also add
a few miscellaneous tweaks. a few miscellaneous tweaks.
- Overhaul the rcfile parsing code to make it simpler and more
accurate, remove now-redundant checks from the color code,
change the COLOR_SYNTAX toggle to the NO_COLOR_SYMTAX toggle,
and improve various debugging messsages. Changes to
set_colorpairs(), do_colorinit(), parse_next_word(),
parse_argument(), colortoint(), parse_next_regex(),
parse_syntax(), parse_colors(), parse_rcfile(), do_rcfile(),
etc. (David Benbennick) DLR: Rename colortoint() to
color_to_int(), and add a few miscellaneous tweaks.
- cut.c: - cut.c:
do_cut_text() do_cut_text()
- If keep_cutbuffer is FALSE, only blow away the text in the - If keep_cutbuffer is FALSE, only blow away the text in the
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
/************************************************************************** /**************************************************************************
* color.c * * color.c *
* * * *
* Copyright (C) 1999-2004 Chris Allegretta * * Copyright (C) 1999-2005 Chris Allegretta *
* This program is free software; you can redistribute it and/or modify * * This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by * * it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2, or (at your option) * * the Free Software Foundation; either version 2, or (at your option) *
...@@ -46,14 +46,14 @@ void set_colorpairs(void) ...@@ -46,14 +46,14 @@ void set_colorpairs(void)
for (; this_color != NULL; this_color = this_color->next) { for (; this_color != NULL; this_color = this_color->next) {
const colortype *beforenow = this_syntax->color; const colortype *beforenow = this_syntax->color;
for (; beforenow != NULL && beforenow != this_color && for (; beforenow != this_color &&
(beforenow->fg != this_color->fg || (beforenow->fg != this_color->fg ||
beforenow->bg != this_color->bg || beforenow->bg != this_color->bg ||
beforenow->bright != this_color->bright); beforenow->bright != this_color->bright);
beforenow = beforenow->next) beforenow = beforenow->next)
; ;
if (beforenow != NULL && beforenow != this_color) if (beforenow != this_color)
this_color->pairnum = beforenow->pairnum; this_color->pairnum = beforenow->pairnum;
else { else {
this_color->pairnum = color_pair; this_color->pairnum = color_pair;
...@@ -68,14 +68,14 @@ void do_colorinit(void) ...@@ -68,14 +68,14 @@ void do_colorinit(void)
if (has_colors()) { if (has_colors()) {
const colortype *tmpcolor = NULL; const colortype *tmpcolor = NULL;
#ifdef HAVE_USE_DEFAULT_COLORS #ifdef HAVE_USE_DEFAULT_COLORS
int defok; bool defok;
#endif #endif
start_color(); start_color();
/* Add in colors, if available */
/* Add in colors, if available. */
#ifdef HAVE_USE_DEFAULT_COLORS #ifdef HAVE_USE_DEFAULT_COLORS
defok = use_default_colors() != ERR; defok = (use_default_colors() != ERR);
#endif #endif
for (tmpcolor = colorstrings; tmpcolor != NULL; for (tmpcolor = colorstrings; tmpcolor != NULL;
...@@ -91,8 +91,8 @@ void do_colorinit(void) ...@@ -91,8 +91,8 @@ void do_colorinit(void)
init_pair(tmpcolor->pairnum, tmpcolor->fg, background); init_pair(tmpcolor->pairnum, tmpcolor->fg, background);
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "Running %s with fg = %d and bg = %d\n", fprintf(stderr, "init_pair(): fg = %d, bg = %d\n",
"init_pair()", tmpcolor->fg, tmpcolor->bg); tmpcolor->fg, tmpcolor->bg);
#endif #endif
} }
} }
...@@ -104,11 +104,12 @@ void update_color(void) ...@@ -104,11 +104,12 @@ void update_color(void)
const syntaxtype *tmpsyntax; const syntaxtype *tmpsyntax;
colorstrings = NULL; colorstrings = NULL;
for (tmpsyntax = syntaxes; tmpsyntax != NULL; tmpsyntax = tmpsyntax->next) { for (tmpsyntax = syntaxes; tmpsyntax != NULL;
tmpsyntax = tmpsyntax->next) {
const exttype *e; const exttype *e;
for (e = tmpsyntax->extensions; e != NULL; e = e->next) { for (e = tmpsyntax->extensions; e != NULL; e = e->next) {
/* Set colorstrings if we matched the extension regex */ /* Set colorstrings if we matched the extension regex. */
if (regexec(&e->val, filename, 0, NULL, 0) == 0) if (regexec(&e->val, filename, 0, NULL, 0) == 0)
colorstrings = tmpsyntax->color; colorstrings = tmpsyntax->color;
...@@ -117,10 +118,10 @@ void update_color(void) ...@@ -117,10 +118,10 @@ void update_color(void)
} }
} }
/* if we haven't found a match, use the override string */ /* If we haven't found a match, use the override string. */
if (colorstrings == NULL && syntaxstr != NULL) { if (colorstrings == NULL && syntaxstr != NULL) {
for (tmpsyntax = syntaxes; tmpsyntax != NULL; for (tmpsyntax = syntaxes; tmpsyntax != NULL;
tmpsyntax = tmpsyntax->next) { tmpsyntax = tmpsyntax->next) {
if (strcasecmp(tmpsyntax->desc, syntaxstr) == 0) if (strcasecmp(tmpsyntax->desc, syntaxstr) == 0)
colorstrings = tmpsyntax->color; colorstrings = tmpsyntax->color;
} }
......
...@@ -54,7 +54,7 @@ void new_file(void) ...@@ -54,7 +54,7 @@ void new_file(void)
#ifdef ENABLE_COLOR #ifdef ENABLE_COLOR
update_color(); update_color();
if (ISSET(COLOR_SYNTAX)) if (!ISSET(NO_COLOR_SYNTAX))
edit_refresh(); edit_refresh();
#endif #endif
} }
...@@ -675,7 +675,7 @@ void do_insertfile( ...@@ -675,7 +675,7 @@ void do_insertfile(
break; break;
} }
} /* while (TRUE) */ }
free(ans); free(ans);
} }
...@@ -1640,7 +1640,7 @@ int write_file(const char *name, bool tmp, int append, bool ...@@ -1640,7 +1640,7 @@ int write_file(const char *name, bool tmp, int append, bool
filename = mallocstrcpy(filename, realname); filename = mallocstrcpy(filename, realname);
#ifdef ENABLE_COLOR #ifdef ENABLE_COLOR
update_color(); update_color();
if (ISSET(COLOR_SYNTAX)) if (!ISSET(NO_COLOR_SYNTAX))
edit_refresh(); edit_refresh();
#endif #endif
} }
......
...@@ -1106,7 +1106,7 @@ void toggle_init(void) ...@@ -1106,7 +1106,7 @@ void toggle_init(void)
SMART_HOME); SMART_HOME);
#ifdef ENABLE_COLOR #ifdef ENABLE_COLOR
toggle_init_one(TOGGLE_SYNTAX_KEY, N_("Color syntax highlighting"), toggle_init_one(TOGGLE_SYNTAX_KEY, N_("Color syntax highlighting"),
COLOR_SYNTAX); NO_COLOR_SYNTAX);
#endif #endif
#ifdef ENABLE_NANORC #ifdef ENABLE_NANORC
toggle_init_one(TOGGLE_WHITESPACE_KEY, N_("Whitespace display"), toggle_init_one(TOGGLE_WHITESPACE_KEY, N_("Whitespace display"),
......
...@@ -1299,7 +1299,7 @@ void do_delete(void) ...@@ -1299,7 +1299,7 @@ void do_delete(void)
#ifdef ENABLE_COLOR #ifdef ENABLE_COLOR
/* If color syntaxes are turned on, we need to call /* If color syntaxes are turned on, we need to call
* edit_refresh(). */ * edit_refresh(). */
if (ISSET(COLOR_SYNTAX)) if (!ISSET(NO_COLOR_SYNTAX))
do_refresh = TRUE; do_refresh = TRUE;
#endif #endif
...@@ -3833,7 +3833,7 @@ void do_output(char *output, size_t output_len) ...@@ -3833,7 +3833,7 @@ void do_output(char *output, size_t output_len)
#ifdef ENABLE_COLOR #ifdef ENABLE_COLOR
/* If color syntaxes are turned on, we need to call /* If color syntaxes are turned on, we need to call
* edit_refresh(). */ * edit_refresh(). */
if (ISSET(COLOR_SYNTAX)) if (!ISSET(NO_COLOR_SYNTAX))
do_refresh = TRUE; do_refresh = TRUE;
#endif #endif
} }
......
...@@ -291,7 +291,7 @@ typedef struct historyheadtype { ...@@ -291,7 +291,7 @@ typedef struct historyheadtype {
#define NO_CONVERT (1<<19) #define NO_CONVERT (1<<19)
#define BACKUP_FILE (1<<20) #define BACKUP_FILE (1<<20)
#define NO_RCFILE (1<<21) #define NO_RCFILE (1<<21)
#define COLOR_SYNTAX (1<<22) #define NO_COLOR_SYNTAX (1<<22)
#define PRESERVE (1<<23) #define PRESERVE (1<<23)
#define HISTORY_CHANGED (1<<24) #define HISTORY_CHANGED (1<<24)
#define HISTORYLOG (1<<25) #define HISTORYLOG (1<<25)
......
...@@ -462,9 +462,9 @@ void rcfile_error(const char *msg, ...); ...@@ -462,9 +462,9 @@ void rcfile_error(const char *msg, ...);
char *parse_next_word(char *ptr); char *parse_next_word(char *ptr);
char *parse_argument(char *ptr); char *parse_argument(char *ptr);
#ifdef ENABLE_COLOR #ifdef ENABLE_COLOR
int colortoint(const char *colorname, int *bright); int color_to_int(const char *colorname, bool *bright);
char *parse_next_regex(char *ptr); char *parse_next_regex(char *ptr);
int nregcomp(regex_t *preg, const char *regex, int eflags); bool nregcomp(regex_t *preg, const char *regex, int eflags);
void parse_syntax(char *ptr); void parse_syntax(char *ptr);
void parse_colors(char *ptr); void parse_colors(char *ptr);
#endif /* ENABLE_COLOR */ #endif /* ENABLE_COLOR */
......
This diff is collapsed.
...@@ -844,7 +844,7 @@ ssize_t do_replace_loop(const char *needle, const filestruct ...@@ -844,7 +844,7 @@ ssize_t do_replace_loop(const char *needle, const filestruct
if (!replaceall) { if (!replaceall) {
#ifdef ENABLE_COLOR #ifdef ENABLE_COLOR
if (ISSET(COLOR_SYNTAX)) if (!ISSET(NO_COLOR_SYNTAX))
edit_refresh(); edit_refresh();
else else
#endif #endif
......
...@@ -2658,7 +2658,7 @@ int statusq(bool allow_tabs, const shortcut *s, const char *def, ...@@ -2658,7 +2658,7 @@ int statusq(bool allow_tabs, const shortcut *s, const char *def,
blank_statusbar(); blank_statusbar();
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "I got \"%s\"\n", answer); fprintf(stderr, "answer = \"%s\"\n", answer);
#endif #endif
#ifndef DISABLE_TABCOMP #ifndef DISABLE_TABCOMP
...@@ -3052,7 +3052,7 @@ void edit_add(const filestruct *fileptr, const char *converted, int ...@@ -3052,7 +3052,7 @@ void edit_add(const filestruct *fileptr, const char *converted, int
mvwaddstr(edit, yval, 0, converted); mvwaddstr(edit, yval, 0, converted);
#ifdef ENABLE_COLOR #ifdef ENABLE_COLOR
if (colorstrings != NULL && ISSET(COLOR_SYNTAX)) { if (colorstrings != NULL && !ISSET(NO_COLOR_SYNTAX)) {
const colortype *tmpcolor = colorstrings; const colortype *tmpcolor = colorstrings;
for (; tmpcolor != NULL; tmpcolor = tmpcolor->next) { for (; tmpcolor != NULL; tmpcolor = tmpcolor->next) {
...@@ -3087,17 +3087,19 @@ void edit_add(const filestruct *fileptr, const char *converted, int ...@@ -3087,17 +3087,19 @@ void edit_add(const filestruct *fileptr, const char *converted, int
* unless k is 0. If regexec() returns REG_NOMATCH, * unless k is 0. If regexec() returns REG_NOMATCH,
* there are no more matches in the line. */ * there are no more matches in the line. */
if (regexec(&tmpcolor->start, &fileptr->data[k], 1, if (regexec(&tmpcolor->start, &fileptr->data[k], 1,
&startmatch, k == 0 ? 0 : &startmatch, (k == 0) ? 0 :
REG_NOTBOL) == REG_NOMATCH) REG_NOTBOL) == REG_NOMATCH)
break; break;
/* Translate the match to the beginning of the line. */ /* Translate the match to the beginning of the
* line. */
startmatch.rm_so += k; startmatch.rm_so += k;
startmatch.rm_eo += k; startmatch.rm_eo += k;
if (startmatch.rm_so == startmatch.rm_eo) { if (startmatch.rm_so == startmatch.rm_eo) {
startmatch.rm_eo++; startmatch.rm_eo++;
statusbar(_("Refusing 0 length regex match")); statusbar(
_("Refusing zero-length regex match"));
} else if (startmatch.rm_so < endpos && } else if (startmatch.rm_so < endpos &&
startmatch.rm_eo > startpos) { startmatch.rm_eo > startpos) {
if (startmatch.rm_so <= startpos) if (startmatch.rm_so <= startpos)
x_start = 0; x_start = 0;
else else
...@@ -3157,7 +3159,7 @@ void edit_add(const filestruct *fileptr, const char *converted, int ...@@ -3157,7 +3159,7 @@ void edit_add(const filestruct *fileptr, const char *converted, int
startmatch.rm_eo -= startmatch.rm_so; startmatch.rm_eo -= startmatch.rm_so;
if (regexec(tmpcolor->end, start_line->data + if (regexec(tmpcolor->end, start_line->data +
start_col + startmatch.rm_eo, 0, NULL, start_col + startmatch.rm_eo, 0, NULL,
start_col + startmatch.rm_eo == 0 ? 0 : (start_col + startmatch.rm_eo == 0) ? 0 :
REG_NOTBOL) == REG_NOMATCH) REG_NOTBOL) == REG_NOMATCH)
/* No end found after this start. */ /* No end found after this start. */
break; break;
...@@ -3209,7 +3211,8 @@ void edit_add(const filestruct *fileptr, const char *converted, int ...@@ -3209,7 +3211,8 @@ void edit_add(const filestruct *fileptr, const char *converted, int
while (start_col < endpos) { while (start_col < endpos) {
if (regexec(&tmpcolor->start, if (regexec(&tmpcolor->start,
fileptr->data + start_col, 1, &startmatch, fileptr->data + start_col, 1, &startmatch,
start_col == 0 ? 0 : REG_NOTBOL) == REG_NOMATCH || (start_col == 0) ? 0 :
REG_NOTBOL) == REG_NOMATCH ||
start_col + startmatch.rm_so >= endpos) start_col + startmatch.rm_so >= endpos)
/* No more starts on this line. */ /* No more starts on this line. */
break; break;
...@@ -3228,7 +3231,8 @@ void edit_add(const filestruct *fileptr, const char *converted, int ...@@ -3228,7 +3231,8 @@ void edit_add(const filestruct *fileptr, const char *converted, int
if (regexec(tmpcolor->end, if (regexec(tmpcolor->end,
fileptr->data + startmatch.rm_eo, 1, &endmatch, fileptr->data + startmatch.rm_eo, 1, &endmatch,
startmatch.rm_eo == 0 ? 0 : REG_NOTBOL) == 0) { (startmatch.rm_eo == 0) ? 0 :
REG_NOTBOL) == 0) {
/* Translate the end match to be relative to the /* Translate the end match to be relative to the
* beginning of the line. */ * beginning of the line. */
endmatch.rm_so += startmatch.rm_eo; endmatch.rm_so += startmatch.rm_eo;
...@@ -3268,12 +3272,12 @@ void edit_add(const filestruct *fileptr, const char *converted, int ...@@ -3268,12 +3272,12 @@ void edit_add(const filestruct *fileptr, const char *converted, int
} }
} }
start_col = startmatch.rm_so + 1; start_col = startmatch.rm_so + 1;
} /* while start_col < endpos */ }
} /* if (tmp_color->end != NULL) */ }
wattroff(edit, A_BOLD); wattroff(edit, A_BOLD);
wattroff(edit, COLOR_PAIR(tmpcolor->pairnum)); wattroff(edit, COLOR_PAIR(tmpcolor->pairnum));
} /* for tmpcolor in colorstrings */ }
} }
#endif /* ENABLE_COLOR */ #endif /* ENABLE_COLOR */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment