From 21954765ca32e1386d8991b333aa1e52c5c42443 Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey Date: Tue, 18 Jan 2005 17:00:00 +0000 Subject: [PATCH] reorganization: move revstrstr() back to chars.c, and move is_byte() there too, since they both deal with strings and hence characters git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2286 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 11 ++++++----- src/chars.c | 29 +++++++++++++++++++++++++++++ src/proto.h | 2 +- src/utils.c | 29 ++--------------------------- 4 files changed, 38 insertions(+), 33 deletions(-) diff --git a/ChangeLog b/ChangeLog index a2220db2..048fca66 100644 --- a/ChangeLog +++ b/ChangeLog @@ -98,11 +98,12 @@ CVS code - is_blank_wchar(), is_cntrl_mbchar(), is_cntrl_wchar(), control_mbrep(), control_wrep(), mbwidth(), mb_cur_max(), make_mbchar(), mbstrnlen(), mbstrcasecmp(), and - mbstrncasecmp(); changes to is_blank_char() (moved to - chars.c), is_cntrl_char() (moved to chars.c), nstricmp() - (renamed nstrcasecmp() and moved to chars.c), nstrnicmp() - (renamed nstrncasecmp() and moved to chars.c), nstristr() - (renamed nstrcasestr() and moved to chars.c), revstristr() + mbstrncasecmp(); changes to is_byte() (moved to chars.c), + is_blank_char() (moved to chars.c), is_cntrl_char() (moved to + chars.c), nstricmp() (renamed nstrcasecmp() and moved to + chars.c), nstrnicmp() (renamed nstrncasecmp() and moved to + chars.c), nstristr() (renamed nstrcasestr() and moved to + chars.c), revstrstr() (moved to chars.c), revstristr() (renamed revstrcasestr() and moved to chars.c), nstrnlen() (moved to chars.c), parse_char() (renamed parse_mbchar() and moved to chars.c), move_left() (renamed move_mbleft() and diff --git a/src/chars.c b/src/chars.c index 5c160ce1..f1dc5034 100644 --- a/src/chars.c +++ b/src/chars.c @@ -38,6 +38,13 @@ #include #endif +/* Return TRUE if the value of c is in byte range, and FALSE + * otherwise. */ +bool is_byte(unsigned int c) +{ + return (c == (unsigned char)c); +} + /* This function is equivalent to isalnum(). */ bool is_alnum_char(unsigned int c) { @@ -596,6 +603,28 @@ const char *nstrcasestr(const char *haystack, const char *needle) #endif #ifndef NANO_SMALL +/* This function is equivalent to strstr(), except in that it scans the + * string in reverse. */ +const char *revstrstr(const char *haystack, const char *needle, const + char *rev_start) +{ + assert(haystack != NULL && needle != NULL && rev_start != NULL); + + for (; rev_start >= haystack; rev_start--) { + const char *r, *q; + + for (r = rev_start, q = needle; *q == *r && *q != '\0'; r++, q++) + ; + + if (*q == '\0') + return rev_start; + } + + return NULL; +} + +/* This function is equivalent to strcasestr(), except in that it scans + * the string in reverse. */ const char *revstrcasestr(const char *haystack, const char *needle, const char *rev_start) { diff --git a/src/proto.h b/src/proto.h index 0738f727..25321a71 100644 --- a/src/proto.h +++ b/src/proto.h @@ -151,6 +151,7 @@ extern char *homedir; /* Functions we want available. */ /* Public functions in chars.c. */ +bool is_byte(unsigned int c); bool is_alnum_char(unsigned int c); bool is_alnum_mbchar(const char *c); #ifdef NANO_WIDE @@ -525,7 +526,6 @@ int regexec_safe(const regex_t *preg, const char *string, size_t nmatch, int regexp_bol_or_eol(const regex_t *preg, const char *string); #endif int num_of_digits(int n); -bool is_byte(unsigned int c); bool parse_num(const char *str, ssize_t *val); void align(char **strp); void null_at(char **data, size_t index); diff --git a/src/utils.c b/src/utils.c index e00cb9f4..9f7d2005 100644 --- a/src/utils.c +++ b/src/utils.c @@ -67,11 +67,6 @@ int num_of_digits(int n) return i; } -bool is_byte(unsigned int c) -{ - return (c == (unsigned char)c); -} - /* Read a ssize_t from str, and store it in *val (if val is not NULL). * On error, we return FALSE and don't change *val. Otherwise, we * return TRUE. */ @@ -131,26 +126,7 @@ void sunder(char *str) } } -#ifndef NANO_SMALL -const char *revstrstr(const char *haystack, const char *needle, const - char *rev_start) -{ - assert(haystack != NULL && needle != NULL && rev_start != NULL); - - for (; rev_start >= haystack; rev_start--) { - const char *r, *q; - - for (r = rev_start, q = needle; *q == *r && *q != '\0'; r++, q++) - ; - - if (*q == '\0') - return rev_start; - } - - return NULL; -} - -#ifdef ENABLE_NANORC +#if !defined(NANO_SMALL) && defined(ENABLE_NANORC) #ifndef HAVE_GETLINE /* This function is equivalent to getline(). It was adapted from * GNU mailutils' getline() function. */ @@ -208,8 +184,7 @@ ssize_t ngetdelim(char **lineptr, size_t *n, int delim, FILE *stream) return (c == EOF && (indx - 1) == 0) ? -1 : indx - 1; } #endif -#endif /* ENABLE_NANORC */ -#endif /* !NANO_SMALL */ +#endif /* !NANO_SMALL && ENABLE_NANORC */ /* If we are searching backwards, we will find the last match that * starts no later than start. Otherwise we find the first match -- 2.39.5