2008-08-29 Chris Allegretta <chrisa@asty.org>
* configure.ac, color.c, rcfile.c, utils.c: 1st attempt at supporting systems which don't support GNU-style word boundaries. New function fixbounds() to translate from GNU-style to BSD-style, autoconf option GNU_WORDBOUNDS. git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4315 35c25a1d-7b9e-4130-9fde-d3aeb78583b8master
parent
faeeb5bd7e
commit
6b83e5290c
|
@ -1,3 +1,8 @@
|
||||||
|
2008-08-29 Chris Allegretta <chrisa@asty.org>
|
||||||
|
* configure.ac, color.c, rcfile.c, utils.c: 1st attempt at supporting systems which don't support
|
||||||
|
GNU-style word boundaries. New function fixbounds() to translate from GNU-style to
|
||||||
|
BSD-style, autoconf option GNU_WORDBOUNDS.
|
||||||
|
|
||||||
2008-08-28 Chris Allegretta <chrisa@asty.org>
|
2008-08-28 Chris Allegretta <chrisa@asty.org>
|
||||||
* configure.ac, rcfile.c: Add support for an alternate rcfilename at configure time. Maybe this
|
* configure.ac, rcfile.c: Add support for an alternate rcfilename at configure time. Maybe this
|
||||||
should become a command line option some day, but I don't see the need currently. Start of
|
should become a command line option some day, but I don't see the need currently. Start of
|
||||||
|
|
26
configure.ac
26
configure.ac
|
@ -144,6 +144,32 @@ AC_ARG_ENABLE(color,
|
||||||
if test x$ac_cv_header_regex_h = xyes; then
|
if test x$ac_cv_header_regex_h = xyes; then
|
||||||
AC_DEFINE(ENABLE_NANORC, 1, [Define this to use .nanorc files.]) nanorc_support=yes
|
AC_DEFINE(ENABLE_NANORC, 1, [Define this to use .nanorc files.]) nanorc_support=yes
|
||||||
AC_DEFINE(ENABLE_COLOR, 1, [Define this to have syntax highlighting, requires regex.h and ENABLE_NANORC too!]) color_support=yes
|
AC_DEFINE(ENABLE_COLOR, 1, [Define this to have syntax highlighting, requires regex.h and ENABLE_NANORC too!]) color_support=yes
|
||||||
|
|
||||||
|
# now check for the end of word boundary support (/< and />)
|
||||||
|
AC_MSG_CHECKING([for GNU-style word boundary regex support])
|
||||||
|
AC_TRY_RUN([
|
||||||
|
#ifdef HAVE_SYS_TYPES_H
|
||||||
|
#include <sys/types.h>
|
||||||
|
#endif
|
||||||
|
#include <regex.h>
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
regex_t r;
|
||||||
|
size_t nmatch;
|
||||||
|
regmatch_t pmatch;
|
||||||
|
|
||||||
|
if (regcomp(&r, "\\\\>", REG_EXTENDED|REG_NOSUB))
|
||||||
|
return 1;
|
||||||
|
if (regexec(&r, "word boundary", nmatch, &pmatch, 0))
|
||||||
|
return 1;
|
||||||
|
return 0;
|
||||||
|
}],
|
||||||
|
AC_MSG_RESULT(yes)
|
||||||
|
AC_DEFINE(GNU_WORDBOUNDS, 1, [Define if the system supports GNU-style word boundaries in regexes.]) gnu_wordbounds=yes,
|
||||||
|
AC_MSG_RESULT(no),
|
||||||
|
AC_MSG_WARN([*** Can't check for gnu word boundary support when cross-compiling])
|
||||||
|
)
|
||||||
|
|
||||||
else
|
else
|
||||||
AC_MSG_ERROR([
|
AC_MSG_ERROR([
|
||||||
*** The header file regex.h was not found. If you wish to use color
|
*** The header file regex.h was not found. If you wish to use color
|
||||||
|
|
|
@ -153,7 +153,7 @@ void color_update(void)
|
||||||
* already. */
|
* already. */
|
||||||
if (not_compiled) {
|
if (not_compiled) {
|
||||||
e->ext = (regex_t *)nmalloc(sizeof(regex_t));
|
e->ext = (regex_t *)nmalloc(sizeof(regex_t));
|
||||||
regcomp(e->ext, e->ext_regex, REG_EXTENDED);
|
regcomp(e->ext, fixbounds(e->ext_regex), REG_EXTENDED);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set colorstrings if we matched the extension
|
/* Set colorstrings if we matched the extension
|
||||||
|
@ -188,13 +188,13 @@ void color_update(void)
|
||||||
* regexes if we haven't already. */
|
* regexes if we haven't already. */
|
||||||
if (tmpcolor->start == NULL) {
|
if (tmpcolor->start == NULL) {
|
||||||
tmpcolor->start = (regex_t *)nmalloc(sizeof(regex_t));
|
tmpcolor->start = (regex_t *)nmalloc(sizeof(regex_t));
|
||||||
regcomp(tmpcolor->start, tmpcolor->start_regex,
|
regcomp(tmpcolor->start, fixbounds(tmpcolor->start_regex),
|
||||||
REG_EXTENDED | (tmpcolor->icase ? REG_ICASE : 0));
|
REG_EXTENDED | (tmpcolor->icase ? REG_ICASE : 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tmpcolor->end_regex != NULL && tmpcolor->end == NULL) {
|
if (tmpcolor->end_regex != NULL && tmpcolor->end == NULL) {
|
||||||
tmpcolor->end = (regex_t *)nmalloc(sizeof(regex_t));
|
tmpcolor->end = (regex_t *)nmalloc(sizeof(regex_t));
|
||||||
regcomp(tmpcolor->end, tmpcolor->end_regex,
|
regcomp(tmpcolor->end, fixbounds(tmpcolor->end_regex),
|
||||||
REG_EXTENDED | (tmpcolor->icase ? REG_ICASE : 0));
|
REG_EXTENDED | (tmpcolor->icase ? REG_ICASE : 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -685,6 +685,7 @@ ssize_t ngetdelim(char **lineptr, size_t *n, int delim, FILE *stream);
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_REGEX_H
|
#ifdef HAVE_REGEX_H
|
||||||
bool regexp_bol_or_eol(const regex_t *preg, const char *string);
|
bool regexp_bol_or_eol(const regex_t *preg, const char *string);
|
||||||
|
const char *fixbounds(const char *r);
|
||||||
#endif
|
#endif
|
||||||
#ifndef DISABLE_SPELLER
|
#ifndef DISABLE_SPELLER
|
||||||
bool is_whole_word(size_t pos, const char *buf, const char *word);
|
bool is_whole_word(size_t pos, const char *buf, const char *word);
|
||||||
|
|
|
@ -217,19 +217,19 @@ char *parse_next_regex(char *ptr)
|
||||||
bool nregcomp(const char *regex, int eflags)
|
bool nregcomp(const char *regex, int eflags)
|
||||||
{
|
{
|
||||||
regex_t preg;
|
regex_t preg;
|
||||||
int rc = regcomp(&preg, regex, REG_EXTENDED | eflags);
|
const char *r = fixbounds(regex);
|
||||||
|
int rc = regcomp(&preg, r, REG_EXTENDED | eflags);
|
||||||
|
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
size_t len = regerror(rc, &preg, NULL, 0);
|
size_t len = regerror(rc, &preg, NULL, 0);
|
||||||
char *str = charalloc(len);
|
char *str = charalloc(len);
|
||||||
|
|
||||||
regerror(rc, &preg, str, len);
|
regerror(rc, &preg, str, len);
|
||||||
rcfile_error(N_("Bad regex \"%s\": %s"), regex, str);
|
rcfile_error(N_("Bad regex \"%s\": %s"), r, str);
|
||||||
free(str);
|
free(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
regfree(&preg);
|
regfree(&preg);
|
||||||
|
|
||||||
return (rc == 0);
|
return (rc == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
36
src/utils.c
36
src/utils.c
|
@ -253,6 +253,42 @@ bool regexp_bol_or_eol(const regex_t *preg, const char *string)
|
||||||
regexec(preg, string, 0, NULL, REG_NOTBOL | REG_NOTEOL) ==
|
regexec(preg, string, 0, NULL, REG_NOTBOL | REG_NOTEOL) ==
|
||||||
REG_NOMATCH);
|
REG_NOMATCH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Fix the regex if we're on platforms which requires an adjustment
|
||||||
|
* from GNU-style to BSD-style word boundaries. */
|
||||||
|
const char *fixbounds(const char *r) {
|
||||||
|
#ifndef GNU_WORDBOUNDS
|
||||||
|
int i, j = 0;
|
||||||
|
char *r2 = charalloc(strlen(r) * 5);
|
||||||
|
char *r3;
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
fprintf(stderr, "fixbounds(): Start string = \"%s\"\n", r);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
for (i = 0; i < strlen(r); i++) {
|
||||||
|
if (r[i] != '\0' && r[i] == '\\' && (r[i+1] == '>' || r[i+1] == '<')) {
|
||||||
|
strcpy(&r2[j], "[[:");
|
||||||
|
r2[j+3] = r[i+1];
|
||||||
|
strcpy(&r2[j+4], ":]]");
|
||||||
|
i++;
|
||||||
|
j += 6;
|
||||||
|
} else
|
||||||
|
r2[j] = r[i];
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
r2[j] = '\0';
|
||||||
|
r3 = mallocstrcpy(NULL, r2);
|
||||||
|
free(r2);
|
||||||
|
#ifdef DEBUG
|
||||||
|
fprintf(stderr, "fixbounds(): Ending string = \"%s\"\n", r3);
|
||||||
|
#endif
|
||||||
|
return (const char *) r3;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef DISABLE_SPELLER
|
#ifndef DISABLE_SPELLER
|
||||||
|
|
Loading…
Reference in New Issue