- free(hp->s);
- hp->s = strdup(parsenextc);
- hp = hp->p;
- goto hop;
- }
- break;
- case '\t':
- {
- /* Do TAB completion */
- static int num_matches=0;
- static char **matches = (char **) NULL;
- int pos = cursor;
-
-
- if (lastWasTab == FALSE) {
- char *tmp, *tmp1, *matchBuf;
-
- /* For now, we will not bother with trying to distinguish
- * whether the cursor is in/at a command extression -- we
- * will always try all possable matches. If you don't like
- * that, feel free to fix it.
- */
-
- /* Make a local copy of the string -- up
- * to the the position of the cursor */
- matchBuf = (char *) calloc(BUFSIZ, sizeof(char));
- strncpy(matchBuf, parsenextc, cursor);
- tmp=matchBuf;
-
- /* skip past any command seperator tokens */
- while (*tmp && (tmp1=strpbrk(tmp, ";|&{(`")) != NULL) {
- tmp=++tmp1;
- /* skip any leading white space */
- while (*tmp && isspace(*tmp))
- ++tmp;
- }
-
- /* skip any leading white space */
- while (*tmp && isspace(*tmp))
- ++tmp;
-
- /* Free up any memory already allocated */
- if (matches) {
- free(matches);
- matches = (char **) NULL;
- }
-
- /* If the word starts in `~', and there is no slash in the word,
- * then try completing this word as a username. */
- if (*tmp == '~' && !strchr(tmp, '/'))
- matches = username_completion_matches(tmp, &num_matches);
-
- /* Try to match any executable in our patch, and everything
- * in the current working directory that matches.
- */
- if (!matches)
- matches = find_path_executable_n_cwd_matches(tmp, &num_matches);
- } else {
- if ( matches && num_matches>0 ) {
- int i, col;
-
- fprintf(stderr, "\nTabbing...\n");
-
- /* Make a list of the matches */
- col += xwrite(outputFd, "\n", 1);
- for (i=0,col=0; i<num_matches; i++) {
- col += xwrite(outputFd, prompt, strlen(matches[i]));
- if (col > 60 && matches[i+1] != NULL) {
- xwrite(outputFd, "\n", 1);
- col = 0;
- }
- }
- xwrite(outputFd, "\n", 1);
-
- len+=strlen(prompt);
- fprintf(stderr, "len=%d\n", len);
-
- /* Move to the beginning of the line */
- input_home(outputFd, &len);
-
- /* erase everything */
- for (j = 0; j < len; j++)
- xwrite(outputFd, " ", 1);
-
- /* return to begining of line */
- input_home(outputFd, &cursor);
-
- /* Rewrite the prompt) */
- xwrite(outputFd, prompt, strlen(prompt));
-
- /* Rewrite the command */
- len = strlen(parsenextc);
- xwrite(outputFd, parsenextc, len);
-
- /* Move back to where the cursor used to be */
- for (cursor=pos; cursor > 0; cursor--)
- xwrite(outputFd, "\b", 1);
- cursor = pos;
-
- //fprintf(stderr, "\nprompt='%s'\n", prompt);
- }
- }
- break;