unsigned char complete_args(struct ghs *c, char *word, int dolist, EditLine *el, char **table, int stlen, int level) { #ifdef CMPLDEBUG printf("[%s]",&c->complete[level]); #endif switch (c->complete[level]) { case 'l': /* local complete */ case 'L': return (complete_local(word, dolist, el)); case 'c': /* command complete */ case 'C': return (complete_command(word, dolist, el, table, stlen)); case 'i': case 'I': return (complete_ifname(word, dolist, el)); case 't': /* points to a table */ case 'T': if (c->table == NULL) return(CC_ERROR); return (complete_command(word, dolist, el, c->table, c->stlen)); case 'a': case 'A': if (c->table == NULL) return(CC_ERROR); return (complete_subcommand(word, dolist, el, c->table, c->stlen)); case 'n': /* no complete */ return (CC_ERROR); } return (CC_ERROR); }
/* * Generic complete routine */ unsigned char complete(EditLine *el, int ch) { static char word[FTPBUFLEN]; static int lastc_argc, lastc_argo; const struct cmd *c; const LineInfo *lf; int celems, dolist; size_t len; ch = ch; /* not used */ lf = el_line(el); len = lf->lastchar - lf->buffer; if (len >= sizeof(line)) return (CC_ERROR); (void)memcpy(line, lf->buffer, len); line[len] = '\0'; cursor_pos = line + (lf->cursor - lf->buffer); lastc_argc = cursor_argc; /* remember last cursor pos */ lastc_argo = cursor_argo; makeargv(); /* build argc/argv of current line */ if (cursor_argo >= sizeof(word)) return (CC_ERROR); dolist = 0; /* if cursor and word is same, list alternatives */ if (lastc_argc == cursor_argc && lastc_argo == cursor_argo && strncmp(word, margv[cursor_argc], cursor_argo) == 0) dolist = 1; else if (cursor_argo) memcpy(word, margv[cursor_argc], cursor_argo); word[cursor_argo] = '\0'; if (cursor_argc == 0) return (complete_command(word, dolist)); c = getcmd(margv[0]); if (c == (struct cmd *)-1 || c == 0) return (CC_ERROR); celems = strlen(c->c_complete); /* check for 'continuation' completes (which are uppercase) */ if ((cursor_argc > celems) && (celems > 0) && isupper(c->c_complete[celems-1])) cursor_argc = celems; if (cursor_argc > celems) return (CC_ERROR); switch (c->c_complete[cursor_argc - 1]) { case 'l': /* local complete */ case 'L': return (complete_local(word, dolist)); case 'r': /* remote complete */ case 'R': if (connected != -1) { fputs("\nMust be logged in to complete.\n", ttyout); return (CC_REDISPLAY); } return (complete_remote(word, dolist)); case 'c': /* command complete */ case 'C': return (complete_command(word, dolist)); case 'n': /* no complete */ return (CC_ERROR); } return (CC_ERROR); }
/* * Generic complete routine */ unsigned char complete(EditLine *cel, int ch) { static char word[FTPBUFLEN]; static size_t lastc_argc, lastc_argo; struct cmd *c; const LineInfo *lf; int dolist, cmpltype; size_t celems, len; lf = el_line(cel); len = lf->lastchar - lf->buffer; if (len >= sizeof(line)) return (CC_ERROR); (void)strlcpy(line, lf->buffer, len + 1); cursor_pos = line + (lf->cursor - lf->buffer); lastc_argc = cursor_argc; /* remember last cursor pos */ lastc_argo = cursor_argo; makeargv(); /* build argc/argv of current line */ if (cursor_argo >= sizeof(word)) return (CC_ERROR); dolist = 0; /* if cursor and word is same, list alternatives */ if (lastc_argc == cursor_argc && lastc_argo == cursor_argo && strncmp(word, margv[cursor_argc] ? margv[cursor_argc] : "", cursor_argo) == 0) dolist = 1; else if (cursor_argc < (size_t)margc) (void)strlcpy(word, margv[cursor_argc], cursor_argo + 1); word[cursor_argo] = '\0'; if (cursor_argc == 0) return (complete_command(word, dolist)); c = getcmd(margv[0]); if (c == (struct cmd *)-1 || c == 0) return (CC_ERROR); celems = strlen(c->c_complete); /* check for 'continuation' completes (which are uppercase) */ if ((cursor_argc > celems) && (celems > 0) && isupper((unsigned char) c->c_complete[celems-1])) cursor_argc = celems; if (cursor_argc > celems) return (CC_ERROR); cmpltype = c->c_complete[cursor_argc - 1]; switch (cmpltype) { case 'c': /* command complete */ case 'C': return (complete_command(word, dolist)); case 'l': /* local complete */ case 'L': return (complete_local(word, dolist)); case 'n': /* no complete */ case 'N': /* no complete */ return (CC_ERROR); case 'o': /* local complete */ case 'O': return (complete_option(word, dolist)); case 'r': /* remote complete */ case 'R': if (connected != -1) { fputs("\nMust be logged in to complete.\n", ttyout); return (CC_REDISPLAY); } return (complete_remote(word, dolist)); default: errx(1, "complete: unknown complete type `%c'", cmpltype); return (CC_ERROR); } /* NOTREACHED */ }