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

📄 pcomplete.c

📁 android-w.song.android.widget
💻 C
📖 第 1 页 / 共 3 页
字号:
     ITEMLIST *itp;     int jstate;{#if defined (JOB_CONTROL)  STRINGLIST *sl;  register int i;  register PROCESS *p;  char *s, *t;  JOB *j;  JOB_STATE ws;		/* wanted state */  ws = JNONE;  if (jstate == 0)    ws = JRUNNING;  else if (jstate == 1)    ws = JSTOPPED;  sl = strlist_create (js.j_jobslots);  for (i = js.j_jobslots - 1; i >= 0; i--)    {      j = get_job_by_jid (i);      if (j == 0)	continue;      p = j->pipe;      if (jstate == -1 || JOBSTATE(i) == ws)	{	  s = savestring (p->command);	  t = strpbrk (s, " \t\n");	  if (t)	    *t = '\0';	  sl->list[sl->list_len++] = s;	}    }  itp->slist = sl;#else  itp->slist = (STRINGLIST *)NULL;#endif  return 0;}static intit_init_jobs (itp)     ITEMLIST *itp;{  return (it_init_joblist (itp, -1));}static intit_init_running (itp)     ITEMLIST *itp;{  return (it_init_joblist (itp, 0));}static intit_init_stopped (itp)     ITEMLIST *itp;{  return (it_init_joblist (itp, 1));}static intit_init_keywords (itp)     ITEMLIST *itp;{  STRINGLIST *sl;  register int i, n;  for (n = 0; word_token_alist[n].word; n++)    ;  sl = strlist_create (n);  for (i = 0; i < n; i++)    sl->list[i] = word_token_alist[i].word;  sl->list[sl->list_len = i] = (char *)NULL;  itp->flags |= LIST_DONTFREEMEMBERS;  itp->slist = sl;  return 0;}static intit_init_signals (itp)     ITEMLIST *itp;{  STRINGLIST *sl;  sl = strlist_create (0);  sl->list = signal_names;  sl->list_len = strvec_len (sl->list);  itp->flags |= LIST_DONTFREE;  itp->slist = sl;  return 0;}static intit_init_variables (itp)     ITEMLIST *itp;{  init_itemlist_from_varlist (itp, all_visible_variables);  return 0;}static intit_init_setopts (itp)     ITEMLIST *itp;{  STRINGLIST *sl;  sl = strlist_create (0);  sl->list = get_minus_o_opts ();  sl->list_len = strvec_len (sl->list);  itp->slist = sl;  itp->flags |= LIST_DONTFREEMEMBERS;  return 0;}static intit_init_shopts (itp)     ITEMLIST *itp;{  STRINGLIST *sl;  sl = strlist_create (0);  sl->list = get_shopt_options ();  sl->list_len = strvec_len (sl->list);  itp->slist = sl;  itp->flags |= LIST_DONTFREEMEMBERS;  return 0;}/* Generate a list of all matches for TEXT using the STRINGLIST in itp->slist   as the list of possibilities.  If the itemlist has been marked dirty or   it should be regenerated every time, destroy the old STRINGLIST and make a   new one before trying the match.  TEXT is dequoted before attempting a   match. */static STRINGLIST *gen_matches_from_itemlist (itp, text)     ITEMLIST *itp;     const char *text;{  STRINGLIST *ret, *sl;  int tlen, i, n;  char *ntxt;  if ((itp->flags & (LIST_DIRTY|LIST_DYNAMIC)) ||      (itp->flags & LIST_INITIALIZED) == 0)    {      if (itp->flags & (LIST_DIRTY|LIST_DYNAMIC))	clean_itemlist (itp);      if ((itp->flags & LIST_INITIALIZED) == 0)	initialize_itemlist (itp);    }  if (itp->slist == 0)    return ((STRINGLIST *)NULL);  ret = strlist_create (itp->slist->list_len+1);  sl = itp->slist;  ntxt = bash_dequote_text (text);  tlen = STRLEN (ntxt);  for (i = n = 0; i < sl->list_len; i++)    {      if (tlen == 0 || STREQN (sl->list[i], ntxt, tlen))	ret->list[n++] = STRDUP (sl->list[i]);    }  ret->list[ret->list_len = n] = (char *)NULL;  FREE (ntxt);  return ret;}/* A wrapper for rl_filename_completion_function that dequotes the filename   before attempting completions. */static char *pcomp_filename_completion_function (text, state)     const char *text;     int state;{  static char *dfn;	/* dequoted filename */  int qc;  if (state == 0)    {      FREE (dfn);      /* remove backslashes quoting special characters in filenames. */#if 1      if (RL_ISSTATE (RL_STATE_COMPLETING) && rl_filename_dequoting_function)#else      if (rl_filename_dequoting_function)#endif	{	  /* Use rl_completion_quote_character because any single or	     double quotes have been removed by the time TEXT makes it	     here, and we don't want to remove backslashes inside	     quoted strings. */	  dfn = (*rl_filename_dequoting_function) ((char *)text, rl_completion_quote_character);	}      else	dfn = savestring (text);    }  return (rl_filename_completion_function (dfn, state));}#define GEN_COMPS(bmap, flag, it, text, glist, tlist) \  do { \    if (bmap & flag) \      { \	tlist = gen_matches_from_itemlist (it, text); \	if (tlist) \	  { \	    glist = strlist_append (glist, tlist); \	    strlist_dispose (tlist); \	  } \      } \  } while (0)#define GEN_XCOMPS(bmap, flag, text, func, cmatches, glist, tlist) \  do { \    if (bmap & flag) \      { \	cmatches = rl_completion_matches (text, func); \	tlist = completions_to_stringlist (cmatches); \	glist = strlist_append (glist, tlist); \	strvec_dispose (cmatches); \	strlist_dispose (tlist); \      } \  } while (0)/* Functions to generate lists of matches from the actions member of CS. */static STRINGLIST *gen_action_completions (cs, text)     COMPSPEC *cs;     const char *text;{  STRINGLIST *ret, *tmatches;  char **cmatches;	/* from rl_completion_matches ... */  unsigned long flags;  ret = tmatches = (STRINGLIST *)NULL;  flags = cs->actions;  GEN_COMPS (flags, CA_ALIAS, &it_aliases, text, ret, tmatches);  GEN_COMPS (flags, CA_ARRAYVAR, &it_arrayvars, text, ret, tmatches);  GEN_COMPS (flags, CA_BINDING, &it_bindings, text, ret, tmatches);  GEN_COMPS (flags, CA_BUILTIN, &it_builtins, text, ret, tmatches);  GEN_COMPS (flags, CA_DISABLED, &it_disabled, text, ret, tmatches);  GEN_COMPS (flags, CA_ENABLED, &it_enabled, text, ret, tmatches);  GEN_COMPS (flags, CA_EXPORT, &it_exports, text, ret, tmatches);  GEN_COMPS (flags, CA_FUNCTION, &it_functions, text, ret, tmatches);  GEN_COMPS (flags, CA_HOSTNAME, &it_hostnames, text, ret, tmatches);  GEN_COMPS (flags, CA_JOB, &it_jobs, text, ret, tmatches);  GEN_COMPS (flags, CA_KEYWORD, &it_keywords, text, ret, tmatches);  GEN_COMPS (flags, CA_RUNNING, &it_running, text, ret, tmatches);  GEN_COMPS (flags, CA_SETOPT, &it_setopts, text, ret, tmatches);  GEN_COMPS (flags, CA_SHOPT, &it_shopts, text, ret, tmatches);  GEN_COMPS (flags, CA_SIGNAL, &it_signals, text, ret, tmatches);  GEN_COMPS (flags, CA_STOPPED, &it_stopped, text, ret, tmatches);  GEN_COMPS (flags, CA_VARIABLE, &it_variables, text, ret, tmatches);  GEN_XCOMPS(flags, CA_COMMAND, text, command_word_completion_function, cmatches, ret, tmatches);  GEN_XCOMPS(flags, CA_FILE, text, pcomp_filename_completion_function, cmatches, ret, tmatches);  GEN_XCOMPS(flags, CA_USER, text, rl_username_completion_function, cmatches, ret, tmatches);  GEN_XCOMPS(flags, CA_GROUP, text, bash_groupname_completion_function, cmatches, ret, tmatches);  GEN_XCOMPS(flags, CA_SERVICE, text, bash_servicename_completion_function, cmatches, ret, tmatches);  /* And lastly, the special case for directories */  if (flags & CA_DIRECTORY)    {      rl_completion_mark_symlink_dirs = 1;	/* override user preference */      cmatches = bash_directory_completion_matches (text);      tmatches = completions_to_stringlist (cmatches);      ret = strlist_append (ret, tmatches);      strvec_dispose (cmatches);      strlist_dispose (tmatches);    }  return ret;}/* Generate a list of matches for CS->globpat.  Unresolved: should this use   TEXT as a match prefix, or just go without?  Currently, the code does not   use TEXT, just globs CS->globpat and returns the results.  If we do decide   to use TEXT, we should call quote_string_for_globbing before the call to   glob_filename. */static STRINGLIST *gen_globpat_matches (cs, text)      COMPSPEC *cs;      const char *text;{  STRINGLIST *sl;  sl = strlist_create (0);  sl->list = glob_filename (cs->globpat, 0);  if (GLOB_FAILED (sl->list))    sl->list = (char **)NULL;  if (sl->list)    sl->list_len = sl->list_size = strvec_len (sl->list);  return sl;}/* Perform the shell word expansions on CS->words and return the results.   Again, this ignores TEXT. */static STRINGLIST *gen_wordlist_matches (cs, text)     COMPSPEC *cs;     const char *text;{  WORD_LIST *l, *l2;  STRINGLIST *sl;  int nw, tlen;  char *ntxt;		/* dequoted TEXT to use in comparisons */  if (cs->words == 0 || cs->words[0] == '\0')    return ((STRINGLIST *)NULL);  /* This used to be a simple expand_string(cs->words, 0), but that won't     do -- there's no way to split a simple list into individual words     that way, since the shell semantics say that word splitting is done     only on the results of expansion. */  l = split_at_delims (cs->words, strlen (cs->words), (char *)NULL, -1, 0, (int *)NULL, (int *)NULL);  if (l == 0)    return ((STRINGLIST *)NULL);  /* This will jump back to the top level if the expansion fails... */  l2 = expand_words_shellexp (l);  dispose_words (l);  nw = list_length (l2);  sl = strlist_create (nw + 1);  ntxt = bash_dequote_text (text);  tlen = STRLEN (ntxt);  for (nw = 0, l = l2; l; l = l->next)    {      if (tlen == 0 || STREQN (l->word->word, ntxt, tlen))	sl->list[nw++] = STRDUP (l->word->word);    }  sl->list[sl->list_len = nw] = (char *)NULL;  dispose_words (l2);  FREE (ntxt);  return sl;}#ifdef ARRAY_VARSstatic SHELL_VAR *bind_comp_words (lwords)     WORD_LIST *lwords;{  SHELL_VAR *v;  v = find_variable ("COMP_WORDS");  if (v == 0)    v = make_new_array_variable ("COMP_WORDS");  if (readonly_p (v))    VUNSETATTR (v, att_readonly);  if (array_p (v) == 0)    v = convert_var_to_array (v);  v = assign_array_var_from_word_list (v, lwords, 0);  VUNSETATTR (v, att_invisible);  return v;}#endif /* ARRAY_VARS */static voidbind_compfunc_variables (line, ind, lwords, cw, exported)     char *line;     int ind;     WORD_LIST *lwords;     int cw, exported;{  char ibuf[INT_STRLEN_BOUND(int) + 1];  char *value;  SHELL_VAR *v;  /* Set the variables that the function expects while it executes.  Maybe     these should be in the function environment (temporary_env). */  v = bind_variable ("COMP_LINE", line, 0);  if (v && exported)    VSETATTR(v, att_exported);  value = inttostr (ind, ibuf, sizeof(ibuf));  v = bind_int_variable ("COMP_POINT", value);  if (v && exported)    VSETATTR(v, att_exported);  value = inttostr (rl_completion_type, ibuf, sizeof (ibuf));  v = bind_int_variable ("COMP_TYPE", value);  if (v && exported)    VSETATTR(v, att_exported);  value = inttostr (rl_completion_invoking_key, ibuf, sizeof (ibuf));  v = bind_int_variable ("COMP_KEY", value);  if (v && exported)    VSETATTR(v, att_exported);  /* Since array variables can't be exported, we don't bother making the     array of words. */  if (exported == 0)    {#ifdef ARRAY_VARS      v = bind_comp_words (lwords);      value = inttostr (cw, ibuf, sizeof(ibuf));      bind_int_variable ("COMP_CWORD", value);#endif    }  else    array_needs_making = 1;}static voidunbind_compfunc_variables (exported)     int exported;{  unbind_variable ("COMP_LINE");  unbind_variable ("COMP_POINT");  unbind_variable ("COMP_TYPE");  unbind_variable ("COMP_KEY");#ifdef ARRAY_VARS  unbind_variable ("COMP_WORDS");  unbind_variable ("COMP_CWORD");#endif  if (exported)    array_needs_making = 1;}/* Build the list of words to pass to a function or external command   as arguments.  When the function or command is invoked,	$0 == function or command being invoked   	$1 == command name   	$2 == word to be completed (possibly null)   	$3 == previous word   Functions can access all of the words in the current command line   with the COMP_WORDS array.  External commands cannot; they have to   make do  with the COMP_LINE and COMP_POINT variables. */static WORD_LIST *build_arg_list (cmd, text, lwords, ind)     char *cmd;     const char *text;     WORD_LIST *lwords;     int ind;{  WORD_LIST *ret, *cl, *l;  WORD_DESC *w;  int i;  ret = (WORD_LIST *)NULL;  w = make_word (cmd);  ret = make_word_list (w, (WORD_LIST *)NULL);  w = (lwords && lwords->word) ? copy_word (lwords->word) : make_word ("");  cl = ret->next = make_word_list (w, (WORD_LIST *)NULL);  w = make_word (text);  cl->next = make_word_list (w, (WORD_LIST *)NULL);  cl = cl->next;  /* Search lwords for current word */  for (l = lwords, i = 1; l && i < ind-1; l = l->next, i++)    ;  w = (l && l->word) ? copy_word (l->word) : make_word ("");  cl->next = make_word_list (w, (WORD_LIST *)NULL);  return ret;}/* Build a command string with	$0 == cs->funcname	(function to execute for completion list)   	$1 == command name	(command being completed)   	$2 = word to be completed (possibly null)   	$3 = previous word   and run in the current shell.  The function should put its completion   list into the array variable COMPREPLY.  We build a STRINGLIST   from the results and return it.   Since the shell function should return its list of matches in an array   variable, this does nothing if arrays are not compiled into the shell. */static STRINGLIST *gen_shell_function_matches (cs, text, line, ind, lwords, nw, cw, foundp)     COMPSPEC *cs;     const char *text;     char *line;     int ind;     WORD_LIST *lwords;     int nw, cw;     int *foundp;{  char *funcname;  STRINGLIST *sl;  SHELL_VAR *f, *v;  WORD_LIST *cmdlist;  int fval, found;  sh_parser_state_t ps;  sh_parser_state_t * restrict pps;#if defined (ARRAY_VARS)  ARRAY *a;#endif  found = 0;  if (foundp)    *foundp = found;  funcname = cs->funcname;  f = find_function (funcname);  if (f == 0)    {      internal_error (_("completion: function `%s' not found"), funcname);      rl_ding ();      rl_on_new_line ();

⌨️ 快捷键说明

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