⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 complete.def

📁 android-w.song.android.widget
💻 DEF
📖 第 1 页 / 共 2 页
字号:
This file is complete.def, from which is created complete.c.It implements the builtins "complete", "compgen", and "compopt" in Bash.Copyright (C) 1999-2010 Free Software Foundation, Inc.This file is part of GNU Bash, the Bourne Again SHell.Bash is free software: you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation, either version 3 of the License, or(at your option) any later version.Bash is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with Bash.  If not, see <http://www.gnu.org/licenses/>.$PRODUCES complete.c$BUILTIN complete$DEPENDS_ON PROGRAMMABLE_COMPLETION$FUNCTION complete_builtin$SHORT_DOC complete [-abcdefgjksuv] [-pr] [-DE] [-o option] [-A action] [-G globpat] [-W wordlist]  [-F function] [-C command] [-X filterpat] [-P prefix] [-S suffix] [name ...]Specify how arguments are to be completed by Readline.For each NAME, specify how arguments are to be completed.  If no optionsare supplied, existing completion specifications are printed in a way thatallows them to be reused as input.Options:  -p	print existing completion specifications in a reusable format  -r	remove a completion specification for each NAME, or, if no	NAMEs are supplied, all completion specifications  -D	apply the completions and actions as the default for commands	without any specific completion defined  -E	apply the completions and actions to "empty" commands --	completion attempted on a blank lineWhen completion is attempted, the actions are applied in the order theuppercase-letter options are listed above.  The -D option takesprecedence over -E.Exit Status:Returns success unless an invalid option is supplied or an error occurs.$END#include <config.h>#include <stdio.h>#include "../bashtypes.h"#if defined (HAVE_UNISTD_H)#  include <unistd.h>#endif#include "../bashansi.h"#include "../bashintl.h"#include "../shell.h"#include "../builtins.h"#include "../pcomplete.h"#include "../bashline.h"#include "common.h"#include "bashgetopt.h"#include <readline/readline.h>#define STRDUP(x)       ((x) ? savestring (x) : (char *)NULL)/* Structure containing all the non-action (binary) options; filled in by   build_actions(). */struct _optflags {  int pflag;  int rflag;  int Dflag;  int Eflag;};static int find_compact __P((char *));static int find_compopt __P((char *));static int build_actions __P((WORD_LIST *, struct _optflags *, unsigned long *, unsigned long *));static int remove_cmd_completions __P((WORD_LIST *));static int print_one_completion __P((char *, COMPSPEC *));static int print_compitem __P((BUCKET_CONTENTS *));static void print_compopts __P((const char *, COMPSPEC *, int));static void print_all_completions __P((void));static int print_cmd_completions __P((WORD_LIST *));static char *Garg, *Warg, *Parg, *Sarg, *Xarg, *Farg, *Carg;static const struct _compacts {  const char * const actname;  int actflag;  int actopt;} compacts[] = {  { "alias",     CA_ALIAS,     'a' },  { "arrayvar",  CA_ARRAYVAR,   0 },  { "binding",   CA_BINDING,    0 },  { "builtin",   CA_BUILTIN,   'b' },  { "command",   CA_COMMAND,   'c' },  { "directory", CA_DIRECTORY, 'd' },  { "disabled",  CA_DISABLED,   0 },  { "enabled",   CA_ENABLED,    0 },  { "export",    CA_EXPORT,    'e' },  { "file",      CA_FILE,      'f' },  { "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 },  { "stopped",   CA_STOPPED,    0 },  { "user",      CA_USER,      'u' },  { "variable",  CA_VARIABLE,  'v' },  { (char *)NULL, 0, 0 },};/* This should be a STRING_INT_ALIST */const static struct _compopt {  const char * const optname;  int optflag;} compopts[] = {  { "bashdefault", COPT_BASHDEFAULT },  { "default",	COPT_DEFAULT },  { "dirnames", COPT_DIRNAMES },  { "filenames",COPT_FILENAMES},  { "nospace",	COPT_NOSPACE },  { "plusdirs", COPT_PLUSDIRS },  { (char *)NULL, 0 },};static intfind_compact (name)     char *name;{  register int i;  for (i = 0; compacts[i].actname; i++)    if (STREQ (name, compacts[i].actname))      return i;  return -1;}static intfind_compopt (name)     char *name;{  register int i;  for (i = 0; compopts[i].optname; i++)    if (STREQ (name, compopts[i].optname))      return i;  return -1;}/* Build the actions and compspec options from the options specified in LIST.   ACTP is a pointer to an unsigned long in which to place the bitmap of   actions.  OPTP is a pointer to an unsigned long in which to place the   btmap of compspec options (arguments to `-o').  PP, if non-null, gets 1   if -p is supplied; RP, if non-null, gets 1 if -r is supplied.   If either is null, the corresponding option generates an error.   This also sets variables corresponding to options that take arguments as   a side effect; the caller should ensure that those variables are set to   NULL before calling build_actions.  Return value:   	EX_USAGE = bad option   	EXECUTION_SUCCESS = some options supplied   	EXECUTION_FAILURE = no options supplied*/static intbuild_actions (list, flagp, actp, optp)     WORD_LIST *list;     struct _optflags *flagp;     unsigned long *actp, *optp;{  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, "abcdefgjko:prsuvA:G:W:P:S:X:F:C:DE")) != -1)    {      opt_given = 1;      switch (opt)	{	case 'r':	  if (flagp)	    {	      flagp->rflag = 1;	      break;	    }	  else	    {	      sh_invalidopt ("-r");	      builtin_usage ();	      return (EX_USAGE);	    }	case 'p':	  if (flagp)	    {	      flagp->pflag = 1;	      break;	    }	  else	    {	      sh_invalidopt ("-p");	      builtin_usage ();	      return (EX_USAGE);	    }	case 'a':	  acts |= CA_ALIAS;	  break;	case 'b':	  acts |= CA_BUILTIN;	  break;	case 'c':	  acts |= CA_COMMAND;	  break;	case 'd':	  acts |= CA_DIRECTORY;	  break;	case 'e':	  acts |= CA_EXPORT;	  break;	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;	case 'v':	  acts |= CA_VARIABLE;	  break;	case 'o':	  ind = find_compopt (list_optarg);	  if (ind < 0)	    {	      sh_invalidoptname (list_optarg);	      return (EX_USAGE);	    }	  copts |= compopts[ind].optflag;	  break;	case 'A':	  ind = find_compact (list_optarg);	  if (ind < 0)	    {	      builtin_error (_("%s: invalid action name"), list_optarg);	      return (EX_USAGE);	    }	  acts |= compacts[ind].actflag;	  break;	case 'C':	  Carg = list_optarg;	  break;	case 'D':	  if (flagp)	    {	      flagp->Dflag = 1;	      break;	    }	  else	    {	      sh_invalidopt ("-D");	      builtin_usage ();	      return (EX_USAGE);	    }	case 'E':	  if (flagp)	    {	      flagp->Eflag = 1;	      break;	    }	  else	    {	      sh_invalidopt ("-E");	      builtin_usage ();	      return (EX_USAGE);	    }	case 'F':	  Farg = list_optarg;	  break;	case 'G':	  Garg = list_optarg;	  break;	case 'P':	  Parg = list_optarg;	  break;	case 'S':	  Sarg = list_optarg;	  break;	case 'W':	  Warg = list_optarg;	  break;	case 'X':	  Xarg = list_optarg;	  break;	default:	  builtin_usage ();	  return (EX_USAGE);	}    }  *actp = acts;  *optp = copts;  return (opt_given ? EXECUTION_SUCCESS : EXECUTION_FAILURE);}/* Add, remove, and display completion specifiers. */intcomplete_builtin (list)     WORD_LIST *list;{  int opt_given, rval;  unsigned long acts, copts;  COMPSPEC *cs;  struct _optflags oflags;  WORD_LIST *l, *wl;  if (list == 0)    {      print_all_completions ();      return (EXECUTION_SUCCESS);    }  opt_given = oflags.pflag = oflags.rflag = oflags.Dflag = oflags.Eflag = 0;  acts = copts = (unsigned long)0L;  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     as a side effect if they are supplied as options. */  rval = build_actions (list, &oflags, &acts, &copts);  if (rval == EX_USAGE)    return (rval);  opt_given = rval != EXECUTION_FAILURE;  list = loptend;  wl = oflags.Dflag ? make_word_list (make_bare_word (DEFAULTCMD), (WORD_LIST *)NULL)  		    : (oflags.Eflag ? make_word_list (make_bare_word (EMPTYCMD), (WORD_LIST *)NULL) : 0);  /* -p overrides everything else */  if (oflags.pflag || (list == 0 && opt_given == 0))    {      if (wl)	{	  rval = print_cmd_completions (wl);	  dispose_words (wl);	  return rval;	}      else if (list == 0)	{	  print_all_completions ();	  return (EXECUTION_SUCCESS);	}      return (print_cmd_completions (list));    }  /* next, -r overrides everything else. */  if (oflags.rflag)    {      if (wl)	{	  rval = remove_cmd_completions (wl);	  dispose_words (wl);	  return rval;	}      else if (list == 0)	{	  progcomp_flush ();	  return (EXECUTION_SUCCESS);	}      return (remove_cmd_completions (list));    }  if (wl == 0 && list == 0 && opt_given)    {      builtin_usage ();      return (EX_USAGE);    }  /* If we get here, we need to build a compspec and add it for each     remaining argument. */  cs = compspec_create ();  cs->actions = acts;  cs->options = copts;  cs->globpat = STRDUP (Garg);  cs->words = STRDUP (Warg);  cs->prefix = STRDUP (Parg);  cs->suffix = STRDUP (Sarg);  cs->funcname = STRDUP (Farg);  cs->command = STRDUP (Carg);  cs->filterpat = STRDUP (Xarg);  for (rval = EXECUTION_SUCCESS, l = wl ? wl : list ; l; l = l->next)    {      /* Add CS as the compspec for the specified commands. */      if (progcomp_insert (l->word->word, cs) == 0)	rval = EXECUTION_FAILURE;    }  dispose_words (wl);  return (rval);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -