Browse Source

Fix issue #83

git-svn-id: https://klish.googlecode.com/svn/trunk@530 0eaa4687-2ee9-07dd-09d9-bcdd2d2dd5fb
Serj Kalichev 12 years ago
parent
commit
606ffbc32d
4 changed files with 30 additions and 18 deletions
  1. 8 2
      clish/shell/shell_tinyrl.c
  2. 5 5
      lub/argv/argv_new.c
  3. 10 11
      lub/argv/argv_nextword.c
  4. 7 0
      tinyrl/tinyrl.c

+ 8 - 2
clish/shell/shell_tinyrl.c

@@ -318,14 +318,20 @@ tinyrl_completion_func_t clish_shell_tinyrl_completion;
 char **clish_shell_tinyrl_completion(tinyrl_t * tinyrl,
 	const char *line, unsigned start, unsigned end)
 {
-	lub_argv_t *matches = lub_argv_new(NULL, 0);
+	lub_argv_t *matches;
 	clish_context_t *context = tinyrl__get_context(tinyrl);
 	clish_shell_t *this = context->shell;
 	clish_shell_iterator_t iter;
 	const clish_command_t *cmd = NULL;
-	char *text = lub_string_dupn(line, end);
+	char *text;
 	char **result = NULL;
 
+	if (tinyrl_is_quoting(tinyrl))
+		return result;
+
+	matches = lub_argv_new(NULL, 0);
+	text = lub_string_dupn(line, end);
+
 	/* Don't bother to resort to filename completion */
 	tinyrl_completion_over(tinyrl);
 

+ 5 - 5
lub/argv/argv_new.c

@@ -14,7 +14,7 @@ static void lub_argv_init(lub_argv_t * this, const char *line, size_t offset)
 	size_t len;
 	const char *word;
 	lub_arg_t *arg;
-	bool_t quoted;
+	size_t quoted;
 
 	this->argv = NULL;
 	this->argc = 0;
@@ -30,17 +30,17 @@ static void lub_argv_init(lub_argv_t * this, const char *line, size_t offset)
 
 	/* then fill out the array with the words */
 	for (word = lub_argv_nextword(line, &len, &offset, &quoted);
-		*word;
+		*word || quoted;
 		word = lub_argv_nextword(word + len, &len, &offset, &quoted)) {
 		(*arg).arg = lub_string_ndecode(word, len);
 		(*arg).offset = offset;
-		(*arg).quoted = quoted;
+		(*arg).quoted = quoted ? BOOL_TRUE : BOOL_FALSE;
 
 		offset += len;
 
 		if (quoted) {
-			len += 1; /* account for terminating quotation mark */
-			offset += 2; /* account for quotation marks */
+			len += quoted - 1; /* account for terminating quotation mark */
+			offset += quoted; /* account for quotation marks */
 		}
 		arg++;
 	}

+ 10 - 11
lub/argv/argv_nextword.c

@@ -9,12 +9,11 @@
 
 /*--------------------------------------------------------- */
 const char *lub_argv_nextword(const char *string,
-	size_t * len, size_t * offset, bool_t * quoted)
+	size_t * len, size_t * offset, size_t * quoted)
 {
 	const char *word;
-	bool_t quote = BOOL_FALSE;
 
-	*quoted = BOOL_FALSE;
+	*quoted = 0;
 
 	/* find the start of a word (not including an opening quote) */
 	while (*string && isspace(*string)) {
@@ -28,7 +27,7 @@ const char *lub_argv_nextword(const char *string,
 	}
 	/* is this the start of a quoted string ? */
 	if (*string == '"') {
-		quote = BOOL_TRUE;
+		*quoted = 1;
 		string++;
 	}
 	word = string;
@@ -45,18 +44,18 @@ const char *lub_argv_nextword(const char *string,
 			}
 			continue;
 		}
-		if ((BOOL_FALSE == quote) && isspace(*string)) {
-			/* end of word */
+		/* end of word */
+		if (!*quoted && isspace(*string))
 			break;
-		}
 		if (*string == '"') {
 			/* end of a quoted string */
-			*quoted = BOOL_TRUE;
+			*quoted = 2;
 			break;
 		}
 		(*len)++;
 		string++;
 	}
+
 	return word;
 }
 
@@ -66,13 +65,13 @@ unsigned lub_argv_wordcount(const char *line)
 	const char *word;
 	unsigned result = 0;
 	size_t len = 0, offset = 0;
-	bool_t quoted;
+	size_t quoted;
 
 	for (word = lub_argv_nextword(line, &len, &offset, &quoted);
-		*word;
+		*word || quoted;
 		word = lub_argv_nextword(word + len, &len, &offset, &quoted)) {
 		/* account for the terminating quotation mark */
-		len += (BOOL_TRUE == quoted) ? 1 : 0;
+		len += quoted ? quoted - 1 : 0;
 		result++;
 	}
 

+ 7 - 0
tinyrl/tinyrl.c

@@ -1328,6 +1328,13 @@ bool_t tinyrl_is_quoting(const tinyrl_t * this)
 	/* count the quotes upto the current insertion point */
 	unsigned i = 0;
 	while (i < this->point) {
+		if (result && (this->line[i] == '\\')) {
+			i++;
+			if (i >= this->point)
+				break;
+			i++;
+			continue;
+		}
 		if (this->line[i++] == '"') {
 			result = result ? BOOL_FALSE : BOOL_TRUE;
 		}