+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>
* 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
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_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
AC_MSG_ERROR([
*** The header file regex.h was not found. If you wish to use color
* already. */
if (not_compiled) {
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
* regexes if we haven't already. */
if (tmpcolor->start == NULL) {
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));
}
if (tmpcolor->end_regex != NULL && tmpcolor->end == NULL) {
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));
}
}
#endif
#ifdef HAVE_REGEX_H
bool regexp_bol_or_eol(const regex_t *preg, const char *string);
+const char *fixbounds(const char *r);
#endif
#ifndef DISABLE_SPELLER
bool is_whole_word(size_t pos, const char *buf, const char *word);
bool nregcomp(const char *regex, int eflags)
{
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) {
size_t len = regerror(rc, &preg, NULL, 0);
char *str = charalloc(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);
}
regfree(&preg);
-
return (rc == 0);
}
regexec(preg, string, 0, NULL, REG_NOTBOL | REG_NOTEOL) ==
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
#ifndef DISABLE_SPELLER