nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit 329021e24af6f6f0c62a73c2ac3069da9650f847
parent b06407fbd781b53c9ea9cd0a1d373162fe746dce
Author: Benno Schulenberg <bensberg@justemail.net>
Date:   Sat, 25 Jun 2016 21:36:58 +0200

tweaks: rename two variables, because this 'rev_start' is irksome

And one-letter variables I cannot "see" -- they are too small.

Diffstat:
Msrc/chars.c | 43+++++++++++++++++++++----------------------
Msrc/proto.h | 6++----
2 files changed, 23 insertions(+), 26 deletions(-)

diff --git a/src/chars.c b/src/chars.c @@ -647,51 +647,50 @@ char *mbstrpbrk(const char *s, const char *accept) return (char *) strpbrk(s, accept); } -/* This function is equivalent to strpbrk(), except in that it scans the - * string in reverse, starting at rev_start. */ -char *revstrpbrk(const char *s, const char *accept, const char - *rev_start) +/* Locate the first occurrence in the string that starts at head + * of any of the characters in the string accept, starting from + * the given index and searching backwards. */ +char *revstrpbrk(const char *head, const char *accept, const char *index) { - if (*rev_start == '\0') { - if (rev_start == s) + if (*index == '\0') { + if (index == head) return NULL; - rev_start--; + index--; } - for (; rev_start >= s; rev_start--) { - if (strchr(accept, *rev_start) != NULL) - return (char *)rev_start; + while (index >= head) { + if (strchr(accept, *index) != NULL) + return (char *)index; + index--; } return NULL; } -/* This function is equivalent to strpbrk() for multibyte strings, - * except in that it scans the string in reverse, starting at rev_start. */ -char *mbrevstrpbrk(const char *s, const char *accept, const char - *rev_start) +/* The same as the preceding function but then for multibyte strings. */ +char *mbrevstrpbrk(const char *head, const char *accept, const char *index) { #ifdef ENABLE_UTF8 if (use_utf8) { - if (*rev_start == '\0') { - if (rev_start == s) + if (*index == '\0') { + if (index == head) return NULL; - rev_start = s + move_mbleft(s, rev_start - s); + index = head + move_mbleft(head, index - head); } while (TRUE) { - if (mbstrchr(accept, rev_start) != NULL) - return (char *)rev_start; + if (mbstrchr(accept, index) != NULL) + return (char *)index; /* If we've reached the head of the string, we found nothing. */ - if (rev_start == s) + if (index == head) return NULL; - rev_start = s + move_mbleft(s, rev_start - s); + index = head + move_mbleft(head, index - head); } } else #endif - return revstrpbrk(s, accept, rev_start); + return revstrpbrk(head, accept, index); } #endif /* !NANO_TINY */ diff --git a/src/proto.h b/src/proto.h @@ -216,10 +216,8 @@ char *mbstrchr(const char *s, const char *c); #endif #ifndef NANO_TINY char *mbstrpbrk(const char *s, const char *accept); -char *revstrpbrk(const char *s, const char *accept, const char - *rev_start); -char *mbrevstrpbrk(const char *s, const char *accept, const char - *rev_start); +char *revstrpbrk(const char *head, const char *accept, const char *index); +char *mbrevstrpbrk(const char *head, const char *accept, const char *index); #endif #if !defined(DISABLE_NANORC) && (!defined(NANO_TINY) || !defined(DISABLE_JUSTIFY)) bool has_blank_mbchars(const char *s);