From 645eeb81184444a196c90675145b104022824e1a Mon Sep 17 00:00:00 2001 From: Pavel Roskin Date: Mon, 24 Nov 2003 21:22:00 +0000 Subject: [PATCH] * complete.c (check_is_cd): Simplify logic, use isspace(). --- src/ChangeLog | 4 ++++ src/complete.c | 30 +++++++++++++++++++++--------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index a755cd1a4..9ecc4c365 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2003-11-24 Pavel Roskin + + * complete.c (check_is_cd): Simplify logic, use isspace(). + 2003-11-24 Andrew V. Samoilov * hotlist.c (add_new_group_input): Clean up. diff --git a/src/complete.c b/src/complete.c index 6ed6e6162..e7fb7ac5a 100644 --- a/src/complete.c +++ b/src/complete.c @@ -22,6 +22,7 @@ #include #include #include +#include #ifdef HAVE_UNISTD_H # include #endif @@ -608,17 +609,28 @@ completion_matches (char *text, CompletionFunction entry_function) return match_list; } +/* Check if directory completion is needed */ static int -check_is_cd (char *text, int start, int flags) +check_is_cd (const char *text, int start, int flags) { - char *p, *q = text + start; - - for (p = text; *p && p < q && (*p == ' ' || *p == '\t'); p++); - if (((flags & INPUT_COMPLETE_COMMANDS) && - !strncmp (p, "cd", 2) && (p [2] == ' ' || p [2] == '\t') && - p + 2 < q) || - (flags & INPUT_COMPLETE_CD)) - return 1; + const unsigned char *p, *q; + + if (flags & INPUT_COMPLETE_CD) + return 1; + + if (!(flags & INPUT_COMPLETE_COMMANDS)) + return 0; + + /* Skip initial spaces */ + p = text; + q = text + start; + while (p < q && *p && isspace (*p)) + p++; + + /* Check if the command is "cd" and the cursor is after it */ + if (p[0] == 'c' && p[1] == 'd' && isspace (p[2]) && (p + 2 < q)) + return 1; + return 0; }