Using the now correct parsing of header regexes also for parsing magic regexes.
This fixes Savannah bug #47292. git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5692 35c25a1d-7b9e-4130-9fde-d3aeb78583b8master
parent
3e7591f534
commit
1fba31e7b5
|
@ -1,6 +1,9 @@
|
||||||
2016-02-28 Benno Schulenberg <bensberg@justemail.net>
|
2016-02-28 Benno Schulenberg <bensberg@justemail.net>
|
||||||
* src/rcfile.c (parse_header_exp): Don't continue when something is
|
* src/rcfile.c (parse_header_exp): Don't continue when something is
|
||||||
wrong -- skip the rest of the line. This fixes Savannah bug #47289.
|
wrong -- skip the rest of the line. This fixes Savannah bug #47289.
|
||||||
|
* src/rcfile.c (parse_header_exp, parse_magic_exp, grab_and_store):
|
||||||
|
Use the now correct parsing of header regexes also for parsing magic
|
||||||
|
regexes. This fixes Savannah bug #47292 and saves 50 lines of code.
|
||||||
|
|
||||||
2016-02-26 Benno Schulenberg <bensberg@justemail.net>
|
2016-02-26 Benno Schulenberg <bensberg@justemail.net>
|
||||||
* doc/man/nanorc.5, doc/texinfo/nano.texi, doc/syntax/nanorc.nanorc,
|
* doc/man/nanorc.5, doc/texinfo/nano.texi, doc/syntax/nanorc.nanorc,
|
||||||
|
|
93
src/rcfile.c
93
src/rcfile.c
|
@ -855,24 +855,25 @@ bool parse_color_names(char *combostr, short *fg, short *bg, bool *bright)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Parse the header-line regexes that may influence the choice of syntax. */
|
|
||||||
void parse_header_exp(char *ptr)
|
|
||||||
{
|
|
||||||
regexlisttype *endheader = NULL;
|
|
||||||
|
|
||||||
assert(ptr != NULL);
|
/* Read regex strings enclosed in double quotes from the line pointed at
|
||||||
|
* by ptr, and store them quoteless in the passed storage place. */
|
||||||
|
void grab_and_store(char *ptr, const char *kind, regexlisttype **storage)
|
||||||
|
{
|
||||||
|
regexlisttype *lastthing = NULL;
|
||||||
|
|
||||||
if (syntaxes == NULL) {
|
if (syntaxes == NULL) {
|
||||||
rcfile_error(
|
rcfile_error(
|
||||||
N_("Cannot add a header regex without a syntax command"));
|
N_("A '%s' command requires a preceding 'syntax' command"), kind);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*ptr == '\0') {
|
if (*ptr == '\0') {
|
||||||
rcfile_error(N_("Missing regex string"));
|
rcfile_error(N_("Missing regex string after '%s' command"), kind);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Now load the regexes into their part of the struct. */
|
||||||
while (*ptr != '\0') {
|
while (*ptr != '\0') {
|
||||||
const char *regexstring;
|
const char *regexstring;
|
||||||
regexlisttype *newheader;
|
regexlisttype *newheader;
|
||||||
|
@ -893,84 +894,32 @@ void parse_header_exp(char *ptr)
|
||||||
newheader = (regexlisttype *)nmalloc(sizeof(regexlisttype));
|
newheader = (regexlisttype *)nmalloc(sizeof(regexlisttype));
|
||||||
|
|
||||||
/* Save the regex string if it's valid. */
|
/* Save the regex string if it's valid. */
|
||||||
if (nregcomp(regexstring, 0)) {
|
if (nregcomp(regexstring, REG_NOSUB)) {
|
||||||
newheader->full_regex = mallocstrcpy(NULL, regexstring);
|
newheader->full_regex = mallocstrcpy(NULL, regexstring);
|
||||||
newheader->rgx = NULL;
|
newheader->rgx = NULL;
|
||||||
|
|
||||||
if (endheader == NULL)
|
if (lastthing == NULL)
|
||||||
endsyntax->headers = newheader;
|
*storage = newheader;
|
||||||
else
|
else
|
||||||
endheader->next = newheader;
|
lastthing->next = newheader;
|
||||||
endheader = newheader;
|
lastthing = newheader;
|
||||||
endheader->next = NULL;
|
lastthing->next = NULL;
|
||||||
} else
|
} else
|
||||||
free(newheader);
|
free(newheader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Parse the header-line regexes that may influence the choice of syntax. */
|
||||||
|
void parse_header_exp(char *ptr)
|
||||||
|
{
|
||||||
|
grab_and_store(ptr, "header", &endsyntax->headers);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef HAVE_LIBMAGIC
|
#ifdef HAVE_LIBMAGIC
|
||||||
/* Parse the magic regexes that may influence the choice of syntax. */
|
/* Parse the magic regexes that may influence the choice of syntax. */
|
||||||
void parse_magic_exp(char *ptr)
|
void parse_magic_exp(char *ptr)
|
||||||
{
|
{
|
||||||
regexlisttype *endmagic = NULL;
|
grab_and_store(ptr, "magic", &endsyntax->magics);
|
||||||
|
|
||||||
assert(ptr != NULL);
|
|
||||||
|
|
||||||
if (syntaxes == NULL) {
|
|
||||||
rcfile_error(
|
|
||||||
N_("Cannot add a magic string regex without a syntax command"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (*ptr == '\0') {
|
|
||||||
rcfile_error(N_("Missing magic string name"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (*ptr != '"') {
|
|
||||||
rcfile_error(
|
|
||||||
N_("Regex strings must begin and end with a \" character"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
fprintf(stderr, "Starting a magic type: \"%s\"\n", ptr);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Now load the magic regexes into their part of the struct. */
|
|
||||||
while (*ptr != '\0') {
|
|
||||||
const char *regexstring;
|
|
||||||
regexlisttype *newmagic;
|
|
||||||
|
|
||||||
while (*ptr != '"' && *ptr != '\0')
|
|
||||||
ptr++;
|
|
||||||
|
|
||||||
if (*ptr == '\0')
|
|
||||||
return;
|
|
||||||
|
|
||||||
ptr++;
|
|
||||||
|
|
||||||
regexstring = ptr;
|
|
||||||
ptr = parse_next_regex(ptr);
|
|
||||||
if (ptr == NULL)
|
|
||||||
break;
|
|
||||||
|
|
||||||
newmagic = (regexlisttype *)nmalloc(sizeof(regexlisttype));
|
|
||||||
|
|
||||||
/* Save the regex string if it's valid. */
|
|
||||||
if (nregcomp(regexstring, REG_NOSUB)) {
|
|
||||||
newmagic->full_regex = mallocstrcpy(NULL, regexstring);
|
|
||||||
newmagic->rgx = NULL;
|
|
||||||
|
|
||||||
if (endmagic == NULL)
|
|
||||||
endsyntax->magics = newmagic;
|
|
||||||
else
|
|
||||||
endmagic->next = newmagic;
|
|
||||||
endmagic = newmagic;
|
|
||||||
endmagic->next = NULL;
|
|
||||||
} else
|
|
||||||
free(newmagic);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif /* HAVE_LIBMAGIC */
|
#endif /* HAVE_LIBMAGIC */
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue