add isblank() equivalent and use it instead of checking for (tab or
space) all over the code, properly detect whether we have strcasestr()
and only use nstristr() if we don't, and bump up CVS build requirements
to account for setting _GNU_SOURCE when running the test programs for
both
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1730 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
diff --git a/ChangeLog b/ChangeLog
index 2ec995e..1353858 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -79,6 +79,9 @@
display_string() that have been used in the search prompt
since 1.3.0. (David Benbennick)
- utils.c:
+ is_blank_char()
+ - Add new function is_blank_char() as an isblank() equivalent,
+ since isblank() is a GNU extension. (DLR)
nstricmp(), nstrnicmp()
- Add extra blank lines for greater readability, and remove
unneeded test for n's being less than zero (since it's already
@@ -88,6 +91,8 @@
- Rename to nstristr() to avoid a potential conflict with an
existing stristr() function, and move up to just after
nstrnicmp(). (DLR) David Benbennick: Tweak for efficiency.
+ - Include and use only when strcasestr() is unavailable, since
+ strcasestr() is a GNU extension. (DLR)
- winio.c:
get_verbatim_kbinput()
- Refactor the output in the DEBUG #ifdef. It didn't work
@@ -120,6 +125,10 @@
- Use napms() instead of nanosleep(), as it does the same thing
(aside from taking an argument in milliseconds instead of
microseconds) and curses includes it. (DLR)
+- configure.ac:
+ - Add tests for isblank() and strcasestr(), and define
+ _GNU_SOURCE so that the tests work properly. Increase the
+ minimum required autoconf version to 2.54. (DLR)
- faq.html:
- Removed question about the NumLock glitch, as it's no longer
needed. (DLR)
@@ -137,6 +146,13 @@
- nanorc.sample:
- Add missing mouse entry, and update the nanorc sample regexes
to account for the backupdir and mouse options. (DLR)
+- README.CVS:
+ - Increase the minimum required autoconf version to 2.54, and
+ change the recommended automake version 1.7 to the minimum
+ required automake version. Note that autoconf 2.54 will
+ technically also work with automake 1.6c, but that is a CVS
+ version as opposed to a stable release version, and automake
+ 1.7 requires at least autoconf 2.54 in any case. (DLR)
GNU nano 1.3.2 - 2004.03.31
- General:
diff --git a/README.CVS b/README.CVS
index fe55866..adad019 100644
--- a/README.CVS
+++ b/README.CVS
@@ -7,8 +7,8 @@
To successfully compile GNU nano from CVS, you'll need the
following packages:
-- autoconf (version >= 2.52)
-- automake (version >= 1.6, 1.7.x recommended)
+- autoconf (version >= 2.54)
+- automake (version >= 1.7)
- gettext (version >= 0.11.5)
- texinfo
- cvs
diff --git a/configure.ac b/configure.ac
index 0be9c28..ce5c261 100644
--- a/configure.ac
+++ b/configure.ac
@@ -24,9 +24,10 @@
AM_INIT_AUTOMAKE
AM_CONFIG_HEADER([config.h:config.h.in])
-AC_PREREQ(2.52)
+AC_PREREQ(2.54)
dnl Checks for programs.
+AC_GNU_SOURCE
AC_PROG_CC
AC_ISC_POSIX
AC_SYS_LARGEFILE
@@ -270,7 +271,7 @@
esac], [AC_MSG_RESULT(no)])
dnl Checks for functions
-AC_CHECK_FUNCS(snprintf vsnprintf strcasecmp strncasecmp)
+AC_CHECK_FUNCS(snprintf vsnprintf isblank strcasecmp strncasecmp strcasestr)
if test "x$ac_cv_func_snprintf" = "xno" -o "xac_cv_func_vsnprintf" = "xno"
then
AM_PATH_GLIB_2_0(2.0.0,,
diff --git a/src/files.c b/src/files.c
index c00b4a2..bd75be9 100644
--- a/src/files.c
+++ b/src/files.c
@@ -189,7 +189,7 @@
assume it's a DOS or Mac formatted file if it hasn't been
detected as one already! */
if (fileformat == 0 && !ISSET(NO_CONVERT)
- && is_cntrl_char((int)input) != 0 && input != '\t'
+ && is_cntrl_char(input) && input != '\t'
&& input != '\r' && input != '\n')
SET(NO_CONVERT);
#endif
@@ -2230,7 +2230,7 @@
tmp = matchbuf;
/* skip any leading white space */
- while (*tmp && isspace((int)*tmp))
+ while (*tmp && isblank(*tmp))
++tmp;
/* Free up any memory already allocated */
diff --git a/src/nano.c b/src/nano.c
index 0238aa1..0d7a2dd 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -1106,7 +1106,7 @@
int extra = 0;
const char *spc = current->data;
- while (*spc == ' ' || *spc == '\t') {
+ while (isblank(*spc)) {
extra++;
spc++;
}
@@ -1312,14 +1312,14 @@
wrap_line = inptr->data + i;
for (; i < len; i++, wrap_line++) {
/* record where the last word ended */
- if (*wrap_line != ' ' && *wrap_line != '\t')
+ if (!isblank(*wrap_line))
word_back = i;
/* if we have found a "legal wrap point" and the current word
* extends too far, then we stop */
if (wrap_loc != -1 && strnlenpt(inptr->data, word_back + 1) > fill)
break;
/* we record the latest "legal wrap point" */
- if (word_back != i && wrap_line[1] != ' ' && wrap_line[1] != '\t')
+ if (word_back != i && !isblank(wrap_line[1]))
wrap_loc = i;
}
if (wrap_loc < 0 || i == len)
@@ -1387,7 +1387,7 @@
* between after_break and wrap_line. If the line already ends
* in a tab or a space, we don't add a space and decrement
* totsize to account for that. */
- if (!isspace((int) newline[strlen(newline) - 1]))
+ if (!isblank(newline[strlen(newline) - 1]))
strcat(newline, " ");
else
totsize--;
@@ -1885,7 +1885,7 @@
size_t len = 0;
assert(line != NULL);
- while (*line == ' ' || *line == '\t') {
+ while (isblank(*line)) {
line++;
len++;
}
@@ -1917,7 +1917,7 @@
assert(line != NULL);
assert(line->data != NULL);
assert(skip < strlen(line->data));
- assert(line->data[skip] != ' ' && line->data[skip] != '\t');
+ assert(!isblank(line->data[skip]));
back = line->data + skip;
front = back;
@@ -2078,7 +2078,7 @@
int breakable(const char *line, int goal)
{
for (; *line != '\0' && goal >= 0; line++) {
- if (*line == ' ' || *line == '\t')
+ if (isblank(*line))
return TRUE;
if (is_cntrl_char(*line) != 0)
@@ -2334,7 +2334,7 @@
* characters, as searching for the end of the paragraph
* does. */
for (i = 0; current->data[i] != '\0'; i++) {
- if (isspace(current->data[i]))
+ if (isblank(current->data[i]))
j++;
else {
i = 0;
diff --git a/src/nano.h b/src/nano.h
index bd2ca43..0f1c883 100644
--- a/src/nano.h
+++ b/src/nano.h
@@ -91,7 +91,12 @@
# endif
#endif
-/* If no strcasecmp() or strncasecmp(), use the versions we have. */
+/* If no isblank(), strcasecmp(), strncasecmp(), or strcasestr(), use
+ * the versions we have. */
+#ifndef HAVE_ISBLANK
+#define isblank is_blank_char
+#endif
+
#ifndef HAVE_STRCASECMP
#define strcasecmp nstricmp
#endif
@@ -100,6 +105,10 @@
#define strncasecmp nstrnicmp
#endif
+#ifndef HAVE_STRCASESTR
+#define strcasestr nstristr
+#endif
+
/* Assume ERR is defined as -1. To avoid duplicate case values when
* some key definitions are missing, we have to set all of these, and
* all of the special sentinel values below, to different negative
diff --git a/src/proto.h b/src/proto.h
index 5effeef..895ac48 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -413,6 +413,9 @@
#endif
int regexp_bol_or_eol(const regex_t *preg, const char *string);
#endif
+#ifndef HAVE_ISBLANK
+int is_blank_char(int c);
+#endif
int is_cntrl_char(int c);
int num_of_digits(int n);
void align(char **strp);
diff --git a/src/rcfile.c b/src/rcfile.c
index 306faa0..4d28856 100644
--- a/src/rcfile.c
+++ b/src/rcfile.c
@@ -31,6 +31,7 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <pwd.h>
+#include <ctype.h>
#include <assert.h>
#include "proto.h"
#include "nano.h"
@@ -131,7 +132,7 @@
/* Parse the next word from the string. Returns NULL if we hit EOL. */
char *parse_next_word(char *ptr)
{
- while (*ptr != ' ' && *ptr != '\t' && *ptr != '\n' && *ptr != '\0')
+ while (!isblank(*ptr) && *ptr != '\n' && *ptr != '\0')
ptr++;
if (*ptr == '\0')
@@ -140,7 +141,7 @@
/* Null terminate and advance ptr */
*ptr++ = 0;
- while (*ptr == ' ' || *ptr == '\t')
+ while (isblank(*ptr))
ptr++;
return ptr;
@@ -179,7 +180,7 @@
ptr = last_quote + 1;
}
if (ptr != NULL)
- while (*ptr == ' ' || *ptr == '\t')
+ while (isblank(*ptr))
ptr++;
return ptr;
}
@@ -237,7 +238,7 @@
/* Null terminate and advance ptr. */
*ptr++ = '\0';
- while (*ptr == ' ' || *ptr == '\t')
+ while (isblank(*ptr))
ptr++;
return ptr;
@@ -484,7 +485,7 @@
while (fgets(buf, 1023, rcstream) != 0) {
lineno++;
ptr = buf;
- while (*ptr == ' ' || *ptr == '\t')
+ while (isblank(*ptr))
ptr++;
if (*ptr == '\n' || *ptr == '\0')
diff --git a/src/utils.c b/src/utils.c
index da41430..4e5cbe0 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -52,10 +52,20 @@
}
#endif /* HAVE_REGEX_H */
+#ifndef HAVE_ISBLANK
+/* This function is equivalent to isblank(). */
+int is_blank_char(int c)
+{
+ return (c == '\t' || c == ' ');
+}
+#endif
+
+/* This function is equivalent to iscntrl(), except in that it also
+ * handles control characters with their high bits set. */
int is_cntrl_char(int c)
{
return (-128 <= c && c < -96) || (0 <= c && c < 32) ||
- (127 <= c && c < 160);
+ (127 <= c && c < 160);
}
int num_of_digits(int n)
@@ -146,6 +156,7 @@
}
#endif
+#ifndef HAVE_STRCASESTR
/* This function is equivalent to strcasestr(). It was adapted from
* mutt's mutt_stristr() function. */
const char *nstristr(const char *haystack, const char *needle)
@@ -165,6 +176,7 @@
return NULL;
}
+#endif
/* None of this is needed if we're using NANO_SMALL! */
#ifndef NANO_SMALL
@@ -256,7 +268,7 @@
else if (ISSET(REVERSE_SEARCH))
return revstristr(haystack, needle, start);
#endif
- return nstristr(start, needle);
+ return strcasestr(start, needle);
}
/* This is a wrapper for the perror() function. The wrapper takes care