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
This commit is contained in:
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
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 @@ CVS code -
- 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 @@ CVS code -
- 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 @@ CVS code -
- 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:

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
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

View File

@ -24,9 +24,10 @@ AC_CONFIG_SRCDIR([src/nano.c])
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 @@ AC_MSG_WARN([*** Can not use slang when cross-compiling])),
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,,

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
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 @@ char *input_tab(char *buf, int place, int *lastwastab, int *newplace, int *list)
tmp = matchbuf;
/* skip any leading white space */
while (*tmp && isspace((int)*tmp))
while (*tmp && isblank(*tmp))
++tmp;
/* Free up any memory already allocated */

View File

@ -1106,7 +1106,7 @@ int do_enter(void)
int extra = 0;
const char *spc = current->data;
while (*spc == ' ' || *spc == '\t') {
while (isblank(*spc)) {
extra++;
spc++;
}
@ -1312,14 +1312,14 @@ int do_wrap(filestruct *inptr)
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 @@ int do_wrap(filestruct *inptr)
* 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 indent_length(const char *line)
size_t len = 0;
assert(line != NULL);
while (*line == ' ' || *line == '\t') {
while (isblank(*line)) {
line++;
len++;
}
@ -1917,7 +1917,7 @@ int justify_format(int changes_allowed, filestruct *line, size_t skip)
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 @@ filestruct *backup_lines(filestruct *first_line, size_t par_len,
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 @@ int do_para_search(int search_type, size_t *quote, size_t *par, size_t
* 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;

View File

@ -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

View File

@ -413,6 +413,9 @@ int regexec_safe(const regex_t *preg, const char *string, size_t nmatch,
#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);

View File

@ -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 @@ void rcfile_msg(const char *msg, ...)
/* 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 @@ char *parse_next_word(char *ptr)
/* Null terminate and advance ptr */
*ptr++ = 0;
while (*ptr == ' ' || *ptr == '\t')
while (isblank(*ptr))
ptr++;
return ptr;
@ -179,7 +180,7 @@ char *parse_argument(char *ptr)
ptr = last_quote + 1;
}
if (ptr != NULL)
while (*ptr == ' ' || *ptr == '\t')
while (isblank(*ptr))
ptr++;
return ptr;
}
@ -237,7 +238,7 @@ char *parse_next_regex(char *ptr)
/* Null terminate and advance ptr. */
*ptr++ = '\0';
while (*ptr == ' ' || *ptr == '\t')
while (isblank(*ptr))
ptr++;
return ptr;
@ -484,7 +485,7 @@ void parse_rcfile(FILE *rcstream)
while (fgets(buf, 1023, rcstream) != 0) {
lineno++;
ptr = buf;
while (*ptr == ' ' || *ptr == '\t')
while (isblank(*ptr))
ptr++;
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 */
#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) ||
@ -146,6 +156,7 @@ int nstrnicmp(const char *s1, const char *s2, size_t n)
}
#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 @@ const char *nstristr(const char *haystack, const char *needle)
return NULL;
}
#endif
/* None of this is needed if we're using NANO_SMALL! */
#ifndef NANO_SMALL
@ -256,7 +268,7 @@ const char *strstrwrapper(const char *haystack, const char *needle,
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