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
master
David Lawrence Ramsey 2004-05-13 17:19:54 +00:00
parent 71d0a1fab3
commit 9830d7500f
9 changed files with 64 additions and 22 deletions

View File

@ -79,6 +79,9 @@ CVS code -
display_string() that have been used in the search prompt display_string() that have been used in the search prompt
since 1.3.0. (David Benbennick) since 1.3.0. (David Benbennick)
- utils.c: - utils.c:
is_blank_char()
- Add new function is_blank_char() as an isblank() equivalent,
since isblank() is a GNU extension. (DLR)
nstricmp(), nstrnicmp() nstricmp(), nstrnicmp()
- Add extra blank lines for greater readability, and remove - Add extra blank lines for greater readability, and remove
unneeded test for n's being less than zero (since it's already unneeded test for n's being less than zero (since it's already
@ -88,6 +91,8 @@ CVS code -
- Rename to nstristr() to avoid a potential conflict with an - Rename to nstristr() to avoid a potential conflict with an
existing stristr() function, and move up to just after existing stristr() function, and move up to just after
nstrnicmp(). (DLR) David Benbennick: Tweak for efficiency. nstrnicmp(). (DLR) David Benbennick: Tweak for efficiency.
- Include and use only when strcasestr() is unavailable, since
strcasestr() is a GNU extension. (DLR)
- winio.c: - winio.c:
get_verbatim_kbinput() get_verbatim_kbinput()
- Refactor the output in the DEBUG #ifdef. It didn't work - Refactor the output in the DEBUG #ifdef. It didn't work
@ -120,6 +125,10 @@ CVS code -
- Use napms() instead of nanosleep(), as it does the same thing - Use napms() instead of nanosleep(), as it does the same thing
(aside from taking an argument in milliseconds instead of (aside from taking an argument in milliseconds instead of
microseconds) and curses includes it. (DLR) 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: - faq.html:
- Removed question about the NumLock glitch, as it's no longer - Removed question about the NumLock glitch, as it's no longer
needed. (DLR) needed. (DLR)
@ -137,6 +146,13 @@ CVS code -
- nanorc.sample: - nanorc.sample:
- Add missing mouse entry, and update the nanorc sample regexes - Add missing mouse entry, and update the nanorc sample regexes
to account for the backupdir and mouse options. (DLR) 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 GNU nano 1.3.2 - 2004.03.31
- General: - General:

View File

@ -7,8 +7,8 @@ more care than the official stable and unstable tarballs.
To successfully compile GNU nano from CVS, you'll need the To successfully compile GNU nano from CVS, you'll need the
following packages: following packages:
- autoconf (version >= 2.52) - autoconf (version >= 2.54)
- automake (version >= 1.6, 1.7.x recommended) - automake (version >= 1.7)
- gettext (version >= 0.11.5) - gettext (version >= 0.11.5)
- texinfo - texinfo
- cvs - cvs

View File

@ -24,9 +24,10 @@ AC_CONFIG_SRCDIR([src/nano.c])
AM_INIT_AUTOMAKE AM_INIT_AUTOMAKE
AM_CONFIG_HEADER([config.h:config.h.in]) AM_CONFIG_HEADER([config.h:config.h.in])
AC_PREREQ(2.52) AC_PREREQ(2.54)
dnl Checks for programs. dnl Checks for programs.
AC_GNU_SOURCE
AC_PROG_CC AC_PROG_CC
AC_ISC_POSIX AC_ISC_POSIX
AC_SYS_LARGEFILE AC_SYS_LARGEFILE
@ -270,7 +271,7 @@ AC_MSG_WARN([*** Can not use slang when cross-compiling])),
esac], [AC_MSG_RESULT(no)]) esac], [AC_MSG_RESULT(no)])
dnl Checks for functions 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" if test "x$ac_cv_func_snprintf" = "xno" -o "xac_cv_func_vsnprintf" = "xno"
then then
AM_PATH_GLIB_2_0(2.0.0,, AM_PATH_GLIB_2_0(2.0.0,,

View File

@ -189,7 +189,7 @@ int read_file(FILE *f, const char *filename, int quiet)
assume it's a DOS or Mac formatted file if it hasn't been assume it's a DOS or Mac formatted file if it hasn't been
detected as one already! */ detected as one already! */
if (fileformat == 0 && !ISSET(NO_CONVERT) if (fileformat == 0 && !ISSET(NO_CONVERT)
&& is_cntrl_char((int)input) != 0 && input != '\t' && is_cntrl_char(input) && input != '\t'
&& input != '\r' && input != '\n') && input != '\r' && input != '\n')
SET(NO_CONVERT); SET(NO_CONVERT);
#endif #endif
@ -2230,7 +2230,7 @@ char *input_tab(char *buf, int place, int *lastwastab, int *newplace, int *list)
tmp = matchbuf; tmp = matchbuf;
/* skip any leading white space */ /* skip any leading white space */
while (*tmp && isspace((int)*tmp)) while (*tmp && isblank(*tmp))
++tmp; ++tmp;
/* Free up any memory already allocated */ /* Free up any memory already allocated */

View File

@ -1106,7 +1106,7 @@ int do_enter(void)
int extra = 0; int extra = 0;
const char *spc = current->data; const char *spc = current->data;
while (*spc == ' ' || *spc == '\t') { while (isblank(*spc)) {
extra++; extra++;
spc++; spc++;
} }
@ -1312,14 +1312,14 @@ int do_wrap(filestruct *inptr)
wrap_line = inptr->data + i; wrap_line = inptr->data + i;
for (; i < len; i++, wrap_line++) { for (; i < len; i++, wrap_line++) {
/* record where the last word ended */ /* record where the last word ended */
if (*wrap_line != ' ' && *wrap_line != '\t') if (!isblank(*wrap_line))
word_back = i; word_back = i;
/* if we have found a "legal wrap point" and the current word /* if we have found a "legal wrap point" and the current word
* extends too far, then we stop */ * extends too far, then we stop */
if (wrap_loc != -1 && strnlenpt(inptr->data, word_back + 1) > fill) if (wrap_loc != -1 && strnlenpt(inptr->data, word_back + 1) > fill)
break; break;
/* we record the latest "legal wrap point" */ /* 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; wrap_loc = i;
} }
if (wrap_loc < 0 || i == len) if (wrap_loc < 0 || i == len)
@ -1387,7 +1387,7 @@ int do_wrap(filestruct *inptr)
* between after_break and wrap_line. If the line already ends * 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 * in a tab or a space, we don't add a space and decrement
* totsize to account for that. */ * totsize to account for that. */
if (!isspace((int) newline[strlen(newline) - 1])) if (!isblank(newline[strlen(newline) - 1]))
strcat(newline, " "); strcat(newline, " ");
else else
totsize--; totsize--;
@ -1885,7 +1885,7 @@ size_t indent_length(const char *line)
size_t len = 0; size_t len = 0;
assert(line != NULL); assert(line != NULL);
while (*line == ' ' || *line == '\t') { while (isblank(*line)) {
line++; line++;
len++; len++;
} }
@ -1917,7 +1917,7 @@ int justify_format(int changes_allowed, filestruct *line, size_t skip)
assert(line != NULL); assert(line != NULL);
assert(line->data != NULL); assert(line->data != NULL);
assert(skip < strlen(line->data)); assert(skip < strlen(line->data));
assert(line->data[skip] != ' ' && line->data[skip] != '\t'); assert(!isblank(line->data[skip]));
back = line->data + skip; back = line->data + skip;
front = back; front = back;
@ -2078,7 +2078,7 @@ filestruct *backup_lines(filestruct *first_line, size_t par_len,
int breakable(const char *line, int goal) int breakable(const char *line, int goal)
{ {
for (; *line != '\0' && goal >= 0; line++) { for (; *line != '\0' && goal >= 0; line++) {
if (*line == ' ' || *line == '\t') if (isblank(*line))
return TRUE; return TRUE;
if (is_cntrl_char(*line) != 0) if (is_cntrl_char(*line) != 0)
@ -2334,7 +2334,7 @@ int do_para_search(int search_type, size_t *quote, size_t *par, size_t
* characters, as searching for the end of the paragraph * characters, as searching for the end of the paragraph
* does. */ * does. */
for (i = 0; current->data[i] != '\0'; i++) { for (i = 0; current->data[i] != '\0'; i++) {
if (isspace(current->data[i])) if (isblank(current->data[i]))
j++; j++;
else { else {
i = 0; i = 0;

View File

@ -91,7 +91,12 @@
# endif # endif
#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 #ifndef HAVE_STRCASECMP
#define strcasecmp nstricmp #define strcasecmp nstricmp
#endif #endif
@ -100,6 +105,10 @@
#define strncasecmp nstrnicmp #define strncasecmp nstrnicmp
#endif #endif
#ifndef HAVE_STRCASESTR
#define strcasestr nstristr
#endif
/* Assume ERR is defined as -1. To avoid duplicate case values when /* 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 * some key definitions are missing, we have to set all of these, and
* all of the special sentinel values below, to different negative * all of the special sentinel values below, to different negative

View File

@ -413,6 +413,9 @@ int regexec_safe(const regex_t *preg, const char *string, size_t nmatch,
#endif #endif
int regexp_bol_or_eol(const regex_t *preg, const char *string); int regexp_bol_or_eol(const regex_t *preg, const char *string);
#endif #endif
#ifndef HAVE_ISBLANK
int is_blank_char(int c);
#endif
int is_cntrl_char(int c); int is_cntrl_char(int c);
int num_of_digits(int n); int num_of_digits(int n);
void align(char **strp); void align(char **strp);

View File

@ -31,6 +31,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include <pwd.h> #include <pwd.h>
#include <ctype.h>
#include <assert.h> #include <assert.h>
#include "proto.h" #include "proto.h"
#include "nano.h" #include "nano.h"
@ -131,7 +132,7 @@ void rcfile_msg(const char *msg, ...)
/* Parse the next word from the string. Returns NULL if we hit EOL. */ /* Parse the next word from the string. Returns NULL if we hit EOL. */
char *parse_next_word(char *ptr) char *parse_next_word(char *ptr)
{ {
while (*ptr != ' ' && *ptr != '\t' && *ptr != '\n' && *ptr != '\0') while (!isblank(*ptr) && *ptr != '\n' && *ptr != '\0')
ptr++; ptr++;
if (*ptr == '\0') if (*ptr == '\0')
@ -140,7 +141,7 @@ char *parse_next_word(char *ptr)
/* Null terminate and advance ptr */ /* Null terminate and advance ptr */
*ptr++ = 0; *ptr++ = 0;
while (*ptr == ' ' || *ptr == '\t') while (isblank(*ptr))
ptr++; ptr++;
return ptr; return ptr;
@ -179,7 +180,7 @@ char *parse_argument(char *ptr)
ptr = last_quote + 1; ptr = last_quote + 1;
} }
if (ptr != NULL) if (ptr != NULL)
while (*ptr == ' ' || *ptr == '\t') while (isblank(*ptr))
ptr++; ptr++;
return ptr; return ptr;
} }
@ -237,7 +238,7 @@ char *parse_next_regex(char *ptr)
/* Null terminate and advance ptr. */ /* Null terminate and advance ptr. */
*ptr++ = '\0'; *ptr++ = '\0';
while (*ptr == ' ' || *ptr == '\t') while (isblank(*ptr))
ptr++; ptr++;
return ptr; return ptr;
@ -484,7 +485,7 @@ void parse_rcfile(FILE *rcstream)
while (fgets(buf, 1023, rcstream) != 0) { while (fgets(buf, 1023, rcstream) != 0) {
lineno++; lineno++;
ptr = buf; ptr = buf;
while (*ptr == ' ' || *ptr == '\t') while (isblank(*ptr))
ptr++; ptr++;
if (*ptr == '\n' || *ptr == '\0') if (*ptr == '\n' || *ptr == '\0')

View File

@ -52,6 +52,16 @@ int regexp_bol_or_eol(const regex_t *preg, const char *string)
} }
#endif /* HAVE_REGEX_H */ #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) int is_cntrl_char(int c)
{ {
return (-128 <= c && c < -96) || (0 <= c && c < 32) || return (-128 <= c && c < -96) || (0 <= c && c < 32) ||
@ -146,6 +156,7 @@ int nstrnicmp(const char *s1, const char *s2, size_t n)
} }
#endif #endif
#ifndef HAVE_STRCASESTR
/* This function is equivalent to strcasestr(). It was adapted from /* This function is equivalent to strcasestr(). It was adapted from
* mutt's mutt_stristr() function. */ * mutt's mutt_stristr() function. */
const char *nstristr(const char *haystack, const char *needle) const char *nstristr(const char *haystack, const char *needle)
@ -165,6 +176,7 @@ const char *nstristr(const char *haystack, const char *needle)
return NULL; return NULL;
} }
#endif
/* None of this is needed if we're using NANO_SMALL! */ /* None of this is needed if we're using NANO_SMALL! */
#ifndef NANO_SMALL #ifndef NANO_SMALL
@ -256,7 +268,7 @@ const char *strstrwrapper(const char *haystack, const char *needle,
else if (ISSET(REVERSE_SEARCH)) else if (ISSET(REVERSE_SEARCH))
return revstristr(haystack, needle, start); return revstristr(haystack, needle, start);
#endif #endif
return nstristr(start, needle); return strcasestr(start, needle);
} }
/* This is a wrapper for the perror() function. The wrapper takes care /* This is a wrapper for the perror() function. The wrapper takes care