diff --git a/src/kit/shell/src/shellAuto.c b/src/kit/shell/src/shellAuto.c index 04cfe69ef6918b5b8c6b15b70128a0cac4fb5067..29df87a1115e08931f2f40ca9713f18ccdf1712c 100644 --- a/src/kit/shell/src/shellAuto.c +++ b/src/kit/shell/src/shellAuto.c @@ -944,39 +944,43 @@ bool matchVarWord(SWord* word1, SWord* word2) { // -// compare command cmd1 come from shellCommands , cmd2 come from user input -int32_t compareCommand(SWords * cmd1, SWords * cmd2) { - SWord * word1 = cmd1->head; - SWord * word2 = cmd2->head; +// compare command cmdPattern come from shellCommands , cmdInput come from user input +int32_t compareCommand(SWords* cmdPattern, SWords* cmdInput) { + SWord* wordPattern = cmdPattern->head; + SWord* wordInput = cmdInput->head; - if (word1 == NULL || word2 == NULL) { + if (wordPattern == NULL || wordInput == NULL) { return -1; } - for (int32_t i = 0; i < cmd1->count; i++) { - if (word1->type == WT_TEXT) { + for (int32_t i = 0; i < cmdPattern->count; i++) { + if (wordPattern->type == WT_TEXT) { // WT_TEXT match - if (word1->len == word2->len) { - if (strncasecmp(word1->word, word2->word, word1->len) != 0) - return -1; - } else if (word1->len < word2->len) { + if (wordPattern->len == wordInput->len) { + if (strncasecmp(wordPattern->word, wordInput->word, wordPattern->len) != 0) return -1; + } else if (wordPattern->len < wordInput->len) { return -1; } else { - // word1->len > word2->len - if (strncasecmp(word1->word, word2->word, word2->len) == 0) { - cmd1->matchIndex = i; - cmd1->matchLen = word2->len; - return i; + // wordPattern->len > wordInput->len + if (strncasecmp(wordPattern->word, wordInput->word, wordInput->len) == 0) { + if (i + 1 == cmdInput->count) { + // last word return match + cmdPattern->matchIndex = i; + cmdPattern->matchLen = wordInput->len; + return i; + } else { + return -1; + } } else { return -1; } } } else { // WT_VAR auto match any one word - if (word2->next == NULL) { // input words last one - if (matchVarWord(word1, word2)) { - cmd1->matchIndex = i; - cmd1->matchLen = word2->len; + if (wordInput->next == NULL) { // input words last one + if (matchVarWord(wordPattern, wordInput)) { + cmdPattern->matchIndex = i; + cmdPattern->matchLen = wordInput->len; varMode = true; return i; } @@ -985,9 +989,9 @@ int32_t compareCommand(SWords * cmd1, SWords * cmd2) { } // move next - word1 = word1->next; - word2 = word2->next; - if (word1 == NULL || word2 == NULL) { + wordPattern = wordPattern->next; + wordInput = wordInput->next; + if (wordPattern == NULL || wordInput == NULL) { return -1; } }