in various functions in rcfile.c, add quotes around invalid string
arguments in error messages, for consistency; also, move color_to_short() dowm so that it's near parse_colors(), for consistency git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3593 35c25a1d-7b9e-4130-9fde-d3aeb78583b8master
parent
5cadadd4c2
commit
8d2d0d9a11
|
@ -260,21 +260,30 @@ CVS code -
|
||||||
- rcfile.c:
|
- rcfile.c:
|
||||||
parse_argument()
|
parse_argument()
|
||||||
- Rename variable ptr_bak to ptr_save, for consistency. (DLR)
|
- Rename variable ptr_bak to ptr_save, for consistency. (DLR)
|
||||||
|
- Add quotes around invalid string arguments in error messages,
|
||||||
|
for consistency. (DLR)
|
||||||
parse_syntax()
|
parse_syntax()
|
||||||
- Don't generate an error if we find a duplicate syntax name,
|
- Don't generate an error if we find a duplicate syntax name,
|
||||||
since we might be trying to override a syntax in the global
|
since we might be trying to override a syntax in the global
|
||||||
nanorc with one in our local nanorc. Instead, free any
|
nanorc with one in our local nanorc. Instead, free any
|
||||||
duplicate syntaxes we find, so that we always use the last
|
duplicate syntaxes we find, so that we always use the last
|
||||||
syntax with a given name. (DLR)
|
syntax with a given name. (DLR)
|
||||||
|
color_to_short()
|
||||||
|
- Add quotes around invalid string arguments in error messages,
|
||||||
|
for consistency. (DLR)
|
||||||
parse_colors()
|
parse_colors()
|
||||||
- Check for a color command's not following a syntax line before
|
- Check for a color command's not following a syntax line before
|
||||||
anything else. (DLR)
|
anything else. (DLR)
|
||||||
|
- Add quotes around invalid string arguments in error messages,
|
||||||
|
for consistency. (DLR)
|
||||||
parse_rcfile()
|
parse_rcfile()
|
||||||
- Properly generate an error if we've read in a syntax without
|
- Properly generate an error if we've read in a syntax without
|
||||||
any associated color commands. (DLR)
|
any associated color commands. (DLR)
|
||||||
- Change variable i from an int to a size_t, for consistency.
|
- Change variable i from an int to a size_t, for consistency.
|
||||||
(DLR)
|
(DLR)
|
||||||
- Properly handle rcfiles that don't end in newlines. (DLR)
|
- Properly handle rcfiles that don't end in newlines. (DLR)
|
||||||
|
- Add quotes around invalid string arguments in error messages,
|
||||||
|
for consistency. (DLR)
|
||||||
do_rcfile()
|
do_rcfile()
|
||||||
- Check for the rcfile's being a directory or device file and
|
- Check for the rcfile's being a directory or device file and
|
||||||
reject it if it is, for consistency with file handling
|
reject it if it is, for consistency with file handling
|
||||||
|
|
104
src/rcfile.c
104
src/rcfile.c
|
@ -171,7 +171,7 @@ char *parse_argument(char *ptr)
|
||||||
ptr = NULL;
|
ptr = NULL;
|
||||||
else
|
else
|
||||||
*ptr++ = '\0';
|
*ptr++ = '\0';
|
||||||
rcfile_error(N_("Argument %s has unterminated \""), ptr_save);
|
rcfile_error(N_("Argument \"%s\" has unterminated \""), ptr_save);
|
||||||
} else {
|
} else {
|
||||||
*last_quote = '\0';
|
*last_quote = '\0';
|
||||||
ptr = last_quote + 1;
|
ptr = last_quote + 1;
|
||||||
|
@ -183,45 +183,6 @@ char *parse_argument(char *ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ENABLE_COLOR
|
#ifdef ENABLE_COLOR
|
||||||
/* Return the short value corresponding to the color named in colorname,
|
|
||||||
* and set bright to TRUE if that color is bright. */
|
|
||||||
short color_to_short(const char *colorname, bool *bright)
|
|
||||||
{
|
|
||||||
short mcolor = -1;
|
|
||||||
|
|
||||||
assert(colorname != NULL && bright != NULL);
|
|
||||||
|
|
||||||
if (strncasecmp(colorname, "bright", 6) == 0) {
|
|
||||||
*bright = TRUE;
|
|
||||||
colorname += 6;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strcasecmp(colorname, "green") == 0)
|
|
||||||
mcolor = COLOR_GREEN;
|
|
||||||
else if (strcasecmp(colorname, "red") == 0)
|
|
||||||
mcolor = COLOR_RED;
|
|
||||||
else if (strcasecmp(colorname, "blue") == 0)
|
|
||||||
mcolor = COLOR_BLUE;
|
|
||||||
else if (strcasecmp(colorname, "white") == 0)
|
|
||||||
mcolor = COLOR_WHITE;
|
|
||||||
else if (strcasecmp(colorname, "yellow") == 0)
|
|
||||||
mcolor = COLOR_YELLOW;
|
|
||||||
else if (strcasecmp(colorname, "cyan") == 0)
|
|
||||||
mcolor = COLOR_CYAN;
|
|
||||||
else if (strcasecmp(colorname, "magenta") == 0)
|
|
||||||
mcolor = COLOR_MAGENTA;
|
|
||||||
else if (strcasecmp(colorname, "black") == 0)
|
|
||||||
mcolor = COLOR_BLACK;
|
|
||||||
else
|
|
||||||
rcfile_error(N_("Color %s not understood.\n"
|
|
||||||
"Valid colors are \"green\", \"red\", \"blue\",\n"
|
|
||||||
"\"white\", \"yellow\", \"cyan\", \"magenta\" and\n"
|
|
||||||
"\"black\", with the optional prefix \"bright\"\n"
|
|
||||||
"for foreground colors."), colorname);
|
|
||||||
|
|
||||||
return mcolor;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Parse the next regex string from the line at ptr, and return it. */
|
/* Parse the next regex string from the line at ptr, and return it. */
|
||||||
char *parse_next_regex(char *ptr)
|
char *parse_next_regex(char *ptr)
|
||||||
{
|
{
|
||||||
|
@ -445,6 +406,45 @@ void parse_include(char *ptr)
|
||||||
free(full_option);
|
free(full_option);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Return the short value corresponding to the color named in colorname,
|
||||||
|
* and set bright to TRUE if that color is bright. */
|
||||||
|
short color_to_short(const char *colorname, bool *bright)
|
||||||
|
{
|
||||||
|
short mcolor = -1;
|
||||||
|
|
||||||
|
assert(colorname != NULL && bright != NULL);
|
||||||
|
|
||||||
|
if (strncasecmp(colorname, "bright", 6) == 0) {
|
||||||
|
*bright = TRUE;
|
||||||
|
colorname += 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strcasecmp(colorname, "green") == 0)
|
||||||
|
mcolor = COLOR_GREEN;
|
||||||
|
else if (strcasecmp(colorname, "red") == 0)
|
||||||
|
mcolor = COLOR_RED;
|
||||||
|
else if (strcasecmp(colorname, "blue") == 0)
|
||||||
|
mcolor = COLOR_BLUE;
|
||||||
|
else if (strcasecmp(colorname, "white") == 0)
|
||||||
|
mcolor = COLOR_WHITE;
|
||||||
|
else if (strcasecmp(colorname, "yellow") == 0)
|
||||||
|
mcolor = COLOR_YELLOW;
|
||||||
|
else if (strcasecmp(colorname, "cyan") == 0)
|
||||||
|
mcolor = COLOR_CYAN;
|
||||||
|
else if (strcasecmp(colorname, "magenta") == 0)
|
||||||
|
mcolor = COLOR_MAGENTA;
|
||||||
|
else if (strcasecmp(colorname, "black") == 0)
|
||||||
|
mcolor = COLOR_BLACK;
|
||||||
|
else
|
||||||
|
rcfile_error(N_("Color \"%s\" not understood.\n"
|
||||||
|
"Valid colors are \"green\", \"red\", \"blue\",\n"
|
||||||
|
"\"white\", \"yellow\", \"cyan\", \"magenta\" and\n"
|
||||||
|
"\"black\", with the optional prefix \"bright\"\n"
|
||||||
|
"for foreground colors."), colorname);
|
||||||
|
|
||||||
|
return mcolor;
|
||||||
|
}
|
||||||
|
|
||||||
/* Parse the color string in the line at ptr, and add it to the current
|
/* Parse the color string in the line at ptr, and add it to the current
|
||||||
* file's associated colors. If icase is TRUE, treat the color string
|
* file's associated colors. If icase is TRUE, treat the color string
|
||||||
* as case insensitive. */
|
* as case insensitive. */
|
||||||
|
@ -483,7 +483,7 @@ void parse_colors(char *ptr, bool icase)
|
||||||
}
|
}
|
||||||
if (strncasecmp(bgcolorname, "bright", 6) == 0) {
|
if (strncasecmp(bgcolorname, "bright", 6) == 0) {
|
||||||
rcfile_error(
|
rcfile_error(
|
||||||
N_("Background color %s cannot be bright"),
|
N_("Background color \"%s\" cannot be bright"),
|
||||||
bgcolorname);
|
bgcolorname);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -644,7 +644,7 @@ void parse_rcfile(FILE *rcstream
|
||||||
#ifdef ENABLE_COLOR
|
#ifdef ENABLE_COLOR
|
||||||
if (syntax_only)
|
if (syntax_only)
|
||||||
rcfile_error(
|
rcfile_error(
|
||||||
N_("Command %s not allowed in included file"),
|
N_("Command \"%s\" not allowed in included file"),
|
||||||
keyword);
|
keyword);
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
|
@ -653,7 +653,7 @@ void parse_rcfile(FILE *rcstream
|
||||||
#ifdef ENABLE_COLOR
|
#ifdef ENABLE_COLOR
|
||||||
if (syntax_only)
|
if (syntax_only)
|
||||||
rcfile_error(
|
rcfile_error(
|
||||||
N_("Command %s not allowed in included file"),
|
N_("Command \"%s\" not allowed in included file"),
|
||||||
keyword);
|
keyword);
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
|
@ -663,13 +663,13 @@ void parse_rcfile(FILE *rcstream
|
||||||
else if (strcasecmp(keyword, "include") == 0) {
|
else if (strcasecmp(keyword, "include") == 0) {
|
||||||
if (syntax_only)
|
if (syntax_only)
|
||||||
rcfile_error(
|
rcfile_error(
|
||||||
N_("Command %s not allowed in included file"),
|
N_("Command \"%s\" not allowed in included file"),
|
||||||
keyword);
|
keyword);
|
||||||
else
|
else
|
||||||
parse_include(ptr);
|
parse_include(ptr);
|
||||||
} else if (strcasecmp(keyword, "syntax") == 0) {
|
} else if (strcasecmp(keyword, "syntax") == 0) {
|
||||||
if (endsyntax != NULL && endcolor == NULL)
|
if (endsyntax != NULL && endcolor == NULL)
|
||||||
rcfile_error(N_("Syntax %s has no color commands"),
|
rcfile_error(N_("Syntax \"%s\" has no color commands"),
|
||||||
endsyntax->desc);
|
endsyntax->desc);
|
||||||
parse_syntax(ptr);
|
parse_syntax(ptr);
|
||||||
} else if (strcasecmp(keyword, "color") == 0)
|
} else if (strcasecmp(keyword, "color") == 0)
|
||||||
|
@ -678,7 +678,7 @@ void parse_rcfile(FILE *rcstream
|
||||||
parse_colors(ptr, TRUE);
|
parse_colors(ptr, TRUE);
|
||||||
#endif /* ENABLE_COLOR */
|
#endif /* ENABLE_COLOR */
|
||||||
else
|
else
|
||||||
rcfile_error(N_("Command %s not understood"), keyword);
|
rcfile_error(N_("Command \"%s\" not understood"), keyword);
|
||||||
|
|
||||||
if (set == 0)
|
if (set == 0)
|
||||||
continue;
|
continue;
|
||||||
|
@ -706,7 +706,7 @@ void parse_rcfile(FILE *rcstream
|
||||||
* an argument. */
|
* an argument. */
|
||||||
if (*ptr == '\0') {
|
if (*ptr == '\0') {
|
||||||
rcfile_error(
|
rcfile_error(
|
||||||
N_("Option %s requires an argument"),
|
N_("Option \"%s\" requires an argument"),
|
||||||
rcopts[i].name);
|
rcopts[i].name);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -737,7 +737,7 @@ void parse_rcfile(FILE *rcstream
|
||||||
if (strcasecmp(rcopts[i].name, "fill") == 0) {
|
if (strcasecmp(rcopts[i].name, "fill") == 0) {
|
||||||
if (!parse_num(option, &wrap_at)) {
|
if (!parse_num(option, &wrap_at)) {
|
||||||
rcfile_error(
|
rcfile_error(
|
||||||
N_("Requested fill size %s invalid"),
|
N_("Requested fill size \"%s\" invalid"),
|
||||||
option);
|
option);
|
||||||
wrap_at = -CHARS_FROM_EOL;
|
wrap_at = -CHARS_FROM_EOL;
|
||||||
} else
|
} else
|
||||||
|
@ -812,7 +812,7 @@ void parse_rcfile(FILE *rcstream
|
||||||
if (!parse_num(option, &tabsize) ||
|
if (!parse_num(option, &tabsize) ||
|
||||||
tabsize <= 0) {
|
tabsize <= 0) {
|
||||||
rcfile_error(
|
rcfile_error(
|
||||||
N_("Requested tab size %s invalid"),
|
N_("Requested tab size \"%s\" invalid"),
|
||||||
option);
|
option);
|
||||||
tabsize = -1;
|
tabsize = -1;
|
||||||
} else
|
} else
|
||||||
|
@ -826,17 +826,17 @@ void parse_rcfile(FILE *rcstream
|
||||||
} else if (rcopts[i].flag != 0)
|
} else if (rcopts[i].flag != 0)
|
||||||
UNSET(rcopts[i].flag);
|
UNSET(rcopts[i].flag);
|
||||||
else
|
else
|
||||||
rcfile_error(N_("Cannot unset flag %s"),
|
rcfile_error(N_("Cannot unset flag \"%s\""),
|
||||||
rcopts[i].name);
|
rcopts[i].name);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (rcopts[i].name == NULL)
|
if (rcopts[i].name == NULL)
|
||||||
rcfile_error(N_("Unknown flag %s"), option);
|
rcfile_error(N_("Unknown flag \"%s\""), option);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (endsyntax != NULL && endcolor == NULL)
|
if (endsyntax != NULL && endcolor == NULL)
|
||||||
rcfile_error(N_("Syntax %s has no color commands"),
|
rcfile_error(N_("Syntax \"%s\" has no color commands"),
|
||||||
endsyntax->desc);
|
endsyntax->desc);
|
||||||
|
|
||||||
free(buf);
|
free(buf);
|
||||||
|
|
Loading…
Reference in New Issue