/* * CompleteLine - do command completion on the entire command line * (which may have trailing newline). * Return value: * 0: No command matched or failure * 1: One command matched * 2: Several commands matched */ static int CompleteLine(void) { int endflag, tmatch; Char *argptr, *OldCursor, *OldLastChar; OldLastChar = LastChar; OldCursor = Cursor; argptr = InputBuf; endflag = 1; do { while (ismetahash(*argptr) || iscmdmeta(*argptr)) argptr++; for (Cursor = argptr; *Cursor != '\0' && ((Cursor != argptr && Cursor[-1] == '\\') || (!ismetahash(*Cursor) && !iscmdmeta(*Cursor))); Cursor++) continue; if (*Cursor == '\0') { Cursor = LastChar; if (LastChar[-1] == '\n') Cursor--; endflag = 0; } if (!MISMATCH(*argptr) && starting_a_command(argptr, InputBuf)) { tmatch = tenematch(InputBuf, Cursor - InputBuf, RECOGNIZE); if (tmatch <= 0) { return 0; } else if (tmatch > 1) { return 2; } if (LastChar != OldLastChar) { if (argptr < OldCursor) OldCursor += (LastChar - OldLastChar); OldLastChar = LastChar; } } argptr = Cursor; } while (endflag); Cursor = OldCursor; return 1; }
/* tw_tok(): * Return the next word from string, unquoteing it. */ static Char * tw_tok(Char *str) { static Char *bf = NULL; if (str != NULL) bf = str; /* skip leading spaces */ for (; *bf && Isspace(*bf); bf++) continue; for (str = bf; *bf && !Isspace(*bf); bf++) { if (ismetahash(*bf)) return INVPTR; *bf = *bf & ~QUOTE; } if (*bf != '\0') *bf++ = '\0'; return *str ? str : NULL; } /* end tw_tok */
/* * SpellLine - do spelling correction on the entire command line * (which may have trailing newline). * If cmdonly is set, only check spelling of command words. * Return value: * -1: Something was incorrectible, and nothing was corrected * 0: Everything was correct * 1: Something was corrected */ static int SpellLine(int cmdonly) { int endflag, matchval; Char *argptr, *OldCursor, *OldLastChar; OldLastChar = LastChar; OldCursor = Cursor; argptr = InputBuf; endflag = 1; matchval = 0; do { while (ismetahash(*argptr) || iscmdmeta(*argptr)) argptr++; for (Cursor = argptr; *Cursor != '\0' && ((Cursor != argptr && Cursor[-1] == '\\') || (!ismetahash(*Cursor) && !iscmdmeta(*Cursor))); Cursor++) continue; if (*Cursor == '\0') { Cursor = LastChar; if (LastChar[-1] == '\n') Cursor--; endflag = 0; } if (!MISMATCH(*argptr) && (!cmdonly || starting_a_command(argptr, InputBuf))) { #ifdef WINNT_NATIVE /* * This hack avoids correcting drive letter changes */ if((Cursor - InputBuf) != 2 || (char)InputBuf[1] != ':') #endif /* WINNT_NATIVE */ { #ifdef HASH_SPELL_CHECK Char save; size_t len = Cursor - InputBuf; save = InputBuf[len]; InputBuf[len] = '\0'; if (find_cmd(InputBuf, 0) != 0) { InputBuf[len] = save; argptr = Cursor; continue; } InputBuf[len] = save; #endif /* HASH_SPELL_CHECK */ switch (tenematch(InputBuf, Cursor - InputBuf, SPELL)) { case 1: /* corrected */ matchval = 1; break; case -1: /* couldn't be corrected */ if (!matchval) matchval = -1; break; default: /* was correct */ break; } } if (LastChar != OldLastChar) { if (argptr < OldCursor) OldCursor += (LastChar - OldLastChar); OldLastChar = LastChar; } } argptr = Cursor; } while (endflag); Cursor = OldCursor; return matchval; }