--- bsflite-0.82/bsf.c 2007-08-30 14:42:31.840748704 -0400 +++ bsflite-0.82.new/bsf.c 2007-08-30 22:59:22.068905184 -0400 @@ -47,6 +47,55 @@ time_t last_keystroke_time; /* PROTO */ +int +length(char string[]) +{ + int index; + + for (index = 0; string[index] != '\0'; ++index) + continue; + + return (index); +} + +/* void remove_last_word(char *string) + * + * *string: A pointer to a string to remove the last word from. + * + * Returns: Absolutely nothing. + * + * Remove the last "word" from a string, including trailing + * spaces, if any. + */ +void remove_last_word(char *string) { + int cursor; + + /* First shave off trailing spaces. */ + for(cursor=strlen(string)-1; string[cursor] == ' ' && cursor > 0; cursor--) + string[cursor] = 0; + + /* Then shave off everything until the next space. */ + for(cursor=strlen(string)-1; string[cursor] != ' ' && cursor > 0; cursor--) + continue; + + /* If we've removed everything from the string, just null + * it all out. Otherwise, shuffle some strings around to + * make the final truncated copy. */ + if(cursor < 1) { + memset(string, 0, strlen(string)); + } else { + char *newstring; + newstring = malloc((cursor+1) * sizeof(char)); + memset(newstring, 0, (cursor+1) * sizeof(char)); + + strncpy(newstring, string, cursor); + memset(string, 0, strlen(string)); + + strcpy(string, newstring); + free(newstring); + } +} + void addtoinputbuf(char inchr) { @@ -245,6 +294,11 @@ show_prompt(); break; + case 23: /* CTRL-W */ + eraseline(); + remove_last_word(inputbuf); + show_prompt(); + break; case 12: #if !defined(__MINGW32__) && !defined(PLAN9)