commit ad96aff50daf66a69eba4079af314850d2560622
parent 60e329e3b20cd2e12d52382327fa26b75fc369ae
Author: David Lawrence Ramsey <pooka109@gmail.com>
Date: Tue, 22 Feb 2005 23:22:37 +0000
rework things so that strrchrn() is no longer needed, and remove it
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2325 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
Diffstat:
7 files changed, 13 insertions(+), 28 deletions(-)
diff --git a/ChangeLog b/ChangeLog
@@ -151,7 +151,7 @@ CVS code -
get_totals(), and do_cursorpos(). (DLR)
- Overhaul the tab completion code, the file browser code, and
related functions to increase efficiency and support multibyte
- characters. New functions strrchrn() and is_dir(); changes to
+ characters. New function is_dir(); changes to
get_full_path(), check_writable_directory(), safe_tempnam(),
diralphasort(), username_tab_completion(),
cwd_tab_completion(), input_tab(), tail(), striponedir(),
diff --git a/src/chars.c b/src/chars.c
@@ -591,7 +591,7 @@ const char *mbstrcasestr(const char *haystack, const char *needle)
#endif
}
-#ifndef NANO_SMALL
+#if !defined(NANO_SMALL) || !defined(DISABLE_TABCOMP)
/* This function is equivalent to strstr(), except in that it scans the
* string in reverse, starting at rev_start. */
const char *revstrstr(const char *haystack, const char *needle, const
@@ -611,7 +611,9 @@ const char *revstrstr(const char *haystack, const char *needle, const
return NULL;
}
+#endif
+#ifndef NANO_SMALL
/* This function is equivalent to strcasestr(), except in that it scans
* the string in reverse, starting at rev_start. */
const char *revstrcasestr(const char *haystack, const char *needle,
@@ -750,19 +752,3 @@ size_t mbstrnlen(const char *s, size_t maxlen)
nstrnlen(s, maxlen);
#endif
}
-
-#ifndef DISABLE_TABCOMP
-/* Find the one-based position of the last occurrence of character c in
- * the first n characters of s. Return 0 if c is not found. */
-size_t strrchrn(const char *s, int c, size_t n)
-{
- assert(n <= strlen(s));
-
- for (s += n - 1; n >= 1; n--, s--) {
- if (c == *s)
- return n;
- }
-
- return 0;
-}
-#endif
diff --git a/src/files.c b/src/files.c
@@ -2157,8 +2157,10 @@ char *input_tab(char *buf, size_t *place, bool *lastwastab, bool *list)
beep();
else {
size_t match, common_len = 0;
- size_t lastslash = strrchrn(buf, '/', *place);
char *mzero;
+ const char *lastslash = revstrstr(buf, "/", buf + *place);
+ size_t lastslash_len = (lastslash == NULL) ? 0 :
+ lastslash - buf + 1;
while (TRUE) {
for (match = 1; match < num_matches; match++) {
@@ -2173,11 +2175,11 @@ char *input_tab(char *buf, size_t *place, bool *lastwastab, bool *list)
common_len++;
}
- mzero = charalloc(lastslash + common_len + 1);
- sprintf(mzero, "%.*s%.*s", lastslash, buf, common_len,
+ mzero = charalloc(lastslash_len + common_len + 1);
+ sprintf(mzero, "%.*s%.*s", lastslash_len, buf, common_len,
matches[0]);
- common_len += lastslash;
+ common_len += lastslash_len;
assert(common_len >= *place);
diff --git a/src/global.c b/src/global.c
@@ -356,7 +356,7 @@ void shortcut_init(bool unjustify)
const char *nano_backup_msg = N_("Back up original file when saving");
const char *nano_execute_msg = N_("Execute external command");
#endif
-#if defined(ENABLE_MULTIBUFFER) && !defined(NANO_SMALL)
+#if !defined(NANO_SMALL) && defined(ENABLE_MULTIBUFFER)
const char *nano_multibuffer_msg = N_("Insert into new buffer");
#endif
#ifndef DISABLE_BROWSER
diff --git a/src/proto.h b/src/proto.h
@@ -203,9 +203,6 @@ size_t mbstrlen(const char *s);
size_t nstrnlen(const char *s, size_t maxlen);
#endif
size_t mbstrnlen(const char *s, size_t maxlen);
-#ifndef DISABLE_TABCOMP
-size_t strrchrn(const char *s, int c, size_t n);
-#endif
/* Public functions in color.c. */
#ifdef ENABLE_COLOR
diff --git a/src/utils.c b/src/utils.c
@@ -249,7 +249,7 @@ const char *strstrwrapper(const char *haystack, const char *needle,
return NULL;
}
#endif /* HAVE_REGEX_H */
-#if !defined(DISABLE_SPELLER) || !defined(NANO_SMALL)
+#if !defined(NANO_SMALL) || !defined(DISABLE_SPELLER)
if (ISSET(CASE_SENSITIVE)) {
#ifndef NANO_SMALL
if (ISSET(REVERSE_SEARCH))
diff --git a/src/winio.c b/src/winio.c
@@ -3026,7 +3026,7 @@ void reset_cursor(void)
void edit_add(const filestruct *fileptr, const char *converted, int
yval, size_t start)
{
-#if defined(ENABLE_COLOR) || !defined(NANO_SMALL)
+#if !defined(NANO_SMALL) || defined(ENABLE_COLOR)
size_t startpos = actual_x(fileptr->data, start);
/* The position in fileptr->data of the leftmost character
* that displays at least partially on the window. */