X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=builtins%2Fcomplete.def;h=f39162048ffce730946d2900a676824c857c4c62;hb=refs%2Ftags%2Fdevel-base-dist;hp=3ac41d04fd3d1e714431b4b717307cb2fecf2418;hpb=28ef6c316f1aff914bb95ac09787a3c83c1815fd;p=platform%2Fupstream%2Fbash.git diff --git a/builtins/complete.def b/builtins/complete.def index 3ac41d0..f391620 100644 --- a/builtins/complete.def +++ b/builtins/complete.def @@ -1,7 +1,7 @@ This file is complete.def, from which is created complete.c. It implements the builtins "complete" and "compgen" in Bash. -Copyright (C) 1999 Free Software Foundation, Inc. +Copyright (C) 1999-2002 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. @@ -24,7 +24,7 @@ $PRODUCES complete.c $BUILTIN complete $DEPENDS_ON PROGRAMMABLE_COMPLETION $FUNCTION complete_builtin -$SHORT_DOC complete [-abcdefjkvu] [-pr] [-o option] [-A action] [-G globpat] [-W wordlist] [-P prefix] [-S suffix] [-X filterpat] [-F function] [-C command] [name ...] +$SHORT_DOC complete [-abcdefgjksuv] [-pr] [-o option] [-A action] [-G globpat] [-W wordlist] [-P prefix] [-S suffix] [-X filterpat] [-F function] [-C command] [name ...] For each NAME, specify how arguments are to be completed. If the -p option is supplied, or if no options are supplied, existing completion specifications are printed in a way that allows them to be @@ -51,14 +51,23 @@ $END #include "common.h" #include "bashgetopt.h" +#include + #define STRDUP(x) ((x) ? savestring (x) : (char *)NULL) -static int remove_cmd_completions (); +static int find_compact __P((char *)); +static int find_compopt __P((char *)); + +static int build_actions __P((WORD_LIST *, int *, int *, unsigned long *, unsigned long *)); + +static int remove_cmd_completions __P((WORD_LIST *)); -static void print_all_completions (); -static int print_cmd_completions (); +static int print_one_completion __P((char *, COMPSPEC *)); +static int print_compitem __P((BUCKET_CONTENTS *)); +static void print_all_completions __P((void)); +static int print_cmd_completions __P((WORD_LIST *)); -static char *Aarg, *Garg, *Warg, *Parg, *Sarg, *Xarg, *Farg, *Carg; +static char *Garg, *Warg, *Parg, *Sarg, *Xarg, *Farg, *Carg; static struct _compacts { char *actname; @@ -78,9 +87,11 @@ static struct _compacts { { "function", CA_FUNCTION, 0 }, { "helptopic", CA_BUILTIN, 0 }, /* for now */ { "hostname", CA_HOSTNAME, 0 }, + { "group", CA_GROUP, 'g' }, { "job", CA_JOB, 'j' }, { "keyword", CA_KEYWORD, 'k' }, { "running", CA_RUNNING, 0 }, + { "service", CA_SERVICE, 's' }, { "setopt", CA_SETOPT, 0 }, { "shopt", CA_SHOPT, 0 }, { "signal", CA_SIGNAL, 0 }, @@ -90,6 +101,7 @@ static struct _compacts { { (char *)NULL, 0, 0 }, }; +/* This should be a STRING_INT_ALIST */ static struct _compopt { char *optname; int optflag; @@ -97,6 +109,7 @@ static struct _compopt { { "default", COPT_DEFAULT }, { "dirnames", COPT_DIRNAMES }, { "filenames",COPT_FILENAMES}, + { "nospace", COPT_NOSPACE }, { (char *)NULL, 0 }, }; @@ -144,14 +157,14 @@ build_actions (list, pp, rp, actp, optp) int *pp, *rp; unsigned long *actp, *optp; { - int opt, ind, pflag, rflag, opt_given; + int opt, ind, opt_given; unsigned long acts, copts; acts = copts = (unsigned long)0L; opt_given = 0; reset_internal_getopt (); - while ((opt = internal_getopt (list, "abcdefjko:pruvA:G:W:P:S:X:F:C:")) != -1) + while ((opt = internal_getopt (list, "abcdefgjko:prsuvA:G:W:P:S:X:F:C:")) != -1) { opt_given = 1; switch (opt) @@ -164,7 +177,7 @@ build_actions (list, pp, rp, actp, optp) } else { - builtin_error ("illegal option: -r"); + sh_invalidopt ("-r"); builtin_usage (); return (EX_USAGE); } @@ -177,7 +190,7 @@ build_actions (list, pp, rp, actp, optp) } else { - builtin_error ("illegal option: -p"); + sh_invalidopt ("-p"); builtin_usage (); return (EX_USAGE); } @@ -200,12 +213,18 @@ build_actions (list, pp, rp, actp, optp) case 'f': acts |= CA_FILE; break; + case 'g': + acts |= CA_GROUP; + break; case 'j': acts |= CA_JOB; break; case 'k': acts |= CA_KEYWORD; break; + case 's': + acts |= CA_SERVICE; + break; case 'u': acts |= CA_USER; break; @@ -216,7 +235,7 @@ build_actions (list, pp, rp, actp, optp) ind = find_compopt (list_optarg); if (ind < 0) { - builtin_error ("%s: invalid option name", list_optarg); + sh_invalidoptname (list_optarg); return (EX_USAGE); } copts |= compopts[ind].optflag; @@ -270,7 +289,6 @@ complete_builtin (list) { int opt_given, pflag, rflag, rval; unsigned long acts, copts; - char *cmd; COMPSPEC *cs; if (list == 0) @@ -281,7 +299,7 @@ complete_builtin (list) opt_given = pflag = rflag = 0; acts = copts = (unsigned long)0L; - Aarg = Garg = Warg = Parg = Sarg = Xarg = Farg = Carg = (char *)NULL; + Garg = Warg = Parg = Sarg = Xarg = Farg = Carg = (char *)NULL; cs = (COMPSPEC *)NULL; /* Build the actions from the arguments. Also sets the [A-Z]arg variables @@ -309,7 +327,7 @@ complete_builtin (list) { if (list == 0) { - clear_progcomps (); + progcomp_flush (); return (EXECUTION_SUCCESS); } return (remove_cmd_completions (list)); @@ -323,7 +341,7 @@ complete_builtin (list) /* If we get here, we need to build a compspec and add it for each remaining argument. */ - cs = alloc_compspec (); + cs = compspec_create (); cs->actions = acts; cs->options = copts; @@ -338,8 +356,7 @@ complete_builtin (list) for (rval = EXECUTION_SUCCESS ; list; list = list->next) { /* Add CS as the compspec for the specified commands. */ - cmd = list->word->word; - if (add_progcomp (cmd, cs) == 0) + if (progcomp_insert (list->word->word, cs) == 0) rval = EXECUTION_FAILURE; } @@ -355,7 +372,7 @@ remove_cmd_completions (list) for (ret = EXECUTION_SUCCESS, l = list; l; l = l->next) { - if (remove_progcomp (l->word->word) == 0) + if (progcomp_remove (l->word->word) == 0) { builtin_error ("%s: no completion specification", l->word->word); ret = EXECUTION_FAILURE; @@ -398,7 +415,7 @@ remove_cmd_completions (list) printf ("-o %s ", f); \ } while (0) -static void +static int print_one_completion (cmd, cs) char *cmd; COMPSPEC *cs; @@ -414,6 +431,7 @@ print_one_completion (cmd, cs) PRINTCOMPOPT (COPT_DEFAULT, "default"); PRINTCOMPOPT (COPT_DIRNAMES, "dirnames"); PRINTCOMPOPT (COPT_FILENAMES, "filenames"); + PRINTCOMPOPT (COPT_NOSPACE, "nospace"); acts = cs->actions; @@ -424,8 +442,10 @@ print_one_completion (cmd, cs) PRINTOPT (CA_DIRECTORY, "-d"); PRINTOPT (CA_EXPORT, "-e"); PRINTOPT (CA_FILE, "-f"); - PRINTOPT (CA_KEYWORD, "-k"); + PRINTOPT (CA_GROUP, "-g"); PRINTOPT (CA_JOB, "-j"); + PRINTOPT (CA_KEYWORD, "-k"); + PRINTOPT (CA_SERVICE, "-s"); PRINTOPT (CA_USER, "-u"); PRINTOPT (CA_VARIABLE, "-v"); @@ -457,12 +477,27 @@ print_one_completion (cmd, cs) PRINTARG (cs->command, "-C"); printf ("%s\n", cmd); + + return (0); +} + +static int +print_compitem (item) + BUCKET_CONTENTS *item; +{ + COMPSPEC *cs; + char *cmd; + + cmd = item->key; + cs = (COMPSPEC *)item->data; + + return (print_one_completion (cmd, cs)); } static void print_all_completions () { - print_all_compspecs (print_one_completion); + progcomp_walk (print_compitem); } static int @@ -475,7 +510,7 @@ print_cmd_completions (list) for (ret = EXECUTION_SUCCESS, l = list; l; l = l->next) { - cs = find_compspec (l->word->word); + cs = progcomp_search (l->word->word); if (cs) print_one_completion (l->word->word, cs); else @@ -490,7 +525,7 @@ print_cmd_completions (list) $BUILTIN compgen $DEPENDS_ON PROGRAMMABLE_COMPLETION $FUNCTION compgen_builtin -$SHORT_DOC compgen [-abcdefjkvu] [-o option] [-A action] [-G globpat] [-W wordlist] [-P prefix] [-S suffix] [-X filterpat] [-F function] [-C command] [word] +$SHORT_DOC compgen [-abcdefgjksuv] [-o option] [-A action] [-G globpat] [-W wordlist] [-P prefix] [-S suffix] [-X filterpat] [-F function] [-C command] [word] Display the possible completions depending on the options. Intended to be used from within a shell function generating possible completions. If the optional WORD argument is supplied, matches against WORD are @@ -511,7 +546,7 @@ compgen_builtin (list) return (EXECUTION_SUCCESS); acts = copts = (unsigned long)0L; - Aarg = Garg = Warg = Parg = Sarg = Xarg = Farg = Carg = (char *)NULL; + Garg = Warg = Parg = Sarg = Xarg = Farg = Carg = (char *)NULL; cs = (COMPSPEC *)NULL; /* Build the actions from the arguments. Also sets the [A-Z]arg variables @@ -532,7 +567,7 @@ compgen_builtin (list) internal_warning ("compgen: -C option may not work as you expect"); /* If we get here, we need to build a compspec and evaluate it. */ - cs = alloc_compspec (); + cs = compspec_create (); cs->actions = acts; cs->options = copts; cs->refcount = 1; @@ -547,16 +582,28 @@ compgen_builtin (list) rval = EXECUTION_FAILURE; sl = gen_compspec_completions (cs, "compgen", word, 0, 0); + + /* This isn't perfect, but it's the best we can do, given what readline + exports from its set of completion utility functions. */ + if ((sl == 0 || sl->list_len == 0) && (copts & COPT_DEFAULT)) + { + char **matches; + + matches = rl_completion_matches (word, rl_filename_completion_function); + sl = completions_to_stringlist (matches); + strvec_dispose (matches); + } + if (sl) { - if (sl->list) + if (sl->list && sl->list_len) { rval = EXECUTION_SUCCESS; - print_stringlist (sl, (char *)NULL); + strlist_print (sl, (char *)NULL); } - free_stringlist (sl); + strlist_dispose (sl); } - free_compspec (cs); + compspec_dispose (cs); return (rval); }