cli-decode.c

来自「这个是LINUX下的GDB调度工具的源码」· C语言 代码 · 共 1,605 行 · 第 1/4 页

C
1,605 行
字号
		if (strlen (ambbuf) + strlen (c->name) + 6 < (int) sizeof ambbuf)		  {		    if (strlen (ambbuf))		      strcat (ambbuf, ", ");		    strcat (ambbuf, c->name);		  }		else		  {		    strcat (ambbuf, "..");		    break;		  }	      }	  error ("Ambiguous %scommand \"%s\": %s.", local_cmdtype,		 *line, ambbuf);	  return 0;		/* lint */	}    }  else    {      /* We've got something.  It may still not be what the caller         wants (if this command *needs* a subcommand).  */      while (**line == ' ' || **line == '\t')	(*line)++;      if (c->prefixlist && **line && !c->allow_unknown)	undef_cmd_error (c->prefixname, *line);      /* Seems to be what he wants.  Return it.  */      return c;    }  return 0;}/* We are here presumably because an alias or command in *TEXT is    deprecated and a warning message should be generated.  This function   decodes *TEXT and potentially generates a warning message as outlined   below.      Example for 'set endian big' which has a fictitious alias 'seb'.      If alias wasn't used in *TEXT, and the command is deprecated:   "warning: 'set endian big' is deprecated."       If alias was used, and only the alias is deprecated:   "warning: 'seb' an alias for the command 'set endian big' is deprecated."      If alias was used and command is deprecated (regardless of whether the   alias itself is deprecated:      "warning: 'set endian big' (seb) is deprecated."   After the message has been sent, clear the appropriate flags in the   command and/or the alias so the user is no longer bothered.   */voiddeprecated_cmd_warning (char **text){  struct cmd_list_element *alias = NULL;  struct cmd_list_element *prefix_cmd = NULL;  struct cmd_list_element *cmd = NULL;  struct cmd_list_element *c;  char *type;   if (!lookup_cmd_composition (*text, &alias, &prefix_cmd, &cmd))    /* return if text doesn't evaluate to a command */    return;  if (!((alias ? (alias->flags & DEPRECATED_WARN_USER) : 0)      || (cmd->flags & DEPRECATED_WARN_USER) ) )     /* return if nothing is deprecated */    return;    printf_filtered ("Warning:");    if (alias && !(cmd->flags & CMD_DEPRECATED))    printf_filtered (" '%s', an alias for the", alias->name);      printf_filtered (" command '");    if (prefix_cmd)    printf_filtered ("%s", prefix_cmd->prefixname);    printf_filtered ("%s", cmd->name);  if (alias && (cmd->flags & CMD_DEPRECATED))    printf_filtered ("' (%s) is deprecated.\n", alias->name);  else    printf_filtered ("' is deprecated.\n");     /* if it is only the alias that is deprecated, we want to indicate the     new alias, otherwise we'll indicate the new command */  if (alias && !(cmd->flags & CMD_DEPRECATED))    {      if (alias->replacement)      printf_filtered ("Use '%s'.\n\n", alias->replacement);      else      printf_filtered ("No alternative known.\n\n");     }    else    {      if (cmd->replacement)      printf_filtered ("Use '%s'.\n\n", cmd->replacement);      else      printf_filtered ("No alternative known.\n\n");    }  /* We've warned you, now we'll keep quiet */  if (alias)    alias->flags &= ~DEPRECATED_WARN_USER;    cmd->flags &= ~DEPRECATED_WARN_USER;}/* Look up the contents of LINE as a command in the command list 'cmdlist'.    Return 1 on success, 0 on failure.      If LINE refers to an alias, *alias will point to that alias.      If LINE is a postfix command (i.e. one that is preceeded by a prefix   command) set *prefix_cmd.      Set *cmd to point to the command LINE indicates.      If any of *alias, *prefix_cmd, or *cmd cannot be determined or do not    exist, they are NULL when we return.   */intlookup_cmd_composition (char *text,                      struct cmd_list_element **alias,                      struct cmd_list_element **prefix_cmd,                       struct cmd_list_element **cmd){  char *p, *command;  int len, tmp, nfound;  struct cmd_list_element *cur_list;  struct cmd_list_element *prev_cmd;  *alias = NULL;  *prefix_cmd = NULL;  *cmd = NULL;    cur_list = cmdlist;    while (1)    {       /* Go through as many command lists as we need to        to find the command TEXT refers to. */            prev_cmd = *cmd;            while (*text == ' ' || *text == '\t')      (text)++;            /* Treating underscores as part of command words is important       so that "set args_foo()" doesn't get interpreted as       "set args _foo()".  */      /* NOTE: cagney/2003-02-13 The `tui_active' was previously	 `tui_version'.  */      for (p = text;         *p && (isalnum (*p) || *p == '-' || *p == '_' ||#if defined(TUI)                (tui_active &&                 (*p == '+' || *p == '<' || *p == '>' || *p == '$')) ||#endif                (xdb_commands && (*p == '!' || *p == '/' || *p == '?')));         p++)      ;            /* If nothing but whitespace, return.  */      if (p == text)      return 0;            len = p - text;            /* text and p now bracket the first command word to lookup (and       it's length is len).  We copy this into a local temporary */            command = (char *) alloca (len + 1);      for (tmp = 0; tmp < len; tmp++)      {        char x = text[tmp];        command[tmp] = x;      }      command[len] = '\0';            /* Look it up.  */      *cmd = 0;      nfound = 0;      *cmd = find_cmd (command, len, cur_list, 1, &nfound);            /* We didn't find the command in the entered case, so lower case it       and search again.      */      if (!*cmd || nfound == 0)      {        for (tmp = 0; tmp < len; tmp++)          {            char x = command[tmp];            command[tmp] = isupper (x) ? tolower (x) : x;          }        *cmd = find_cmd (command, len, cur_list, 1, &nfound);      }            if (*cmd == (struct cmd_list_element *) -1)      {        return 0;              /* ambiguous */      }            if (*cmd == NULL)      return 0;                /* nothing found */      else      {        if ((*cmd)->cmd_pointer)          {            /* cmd was actually an alias, we note that an alias was used                (by assigning *alais) and we set *cmd.              */            *alias = *cmd;            *cmd = (*cmd)->cmd_pointer;          }        *prefix_cmd = prev_cmd;      }      if ((*cmd)->prefixlist)      cur_list = *(*cmd)->prefixlist;      else      return 1;            text = p;    }}/* Helper function for SYMBOL_COMPLETION_FUNCTION.  *//* Return a vector of char pointers which point to the different   possible completions in LIST of TEXT.     WORD points in the same buffer as TEXT, and completions should be   returned relative to this position.  For example, suppose TEXT is "foo"   and we want to complete to "foobar".  If WORD is "oo", return   "oobar"; if WORD is "baz/foo", return "baz/foobar".  */char **complete_on_cmdlist (struct cmd_list_element *list, char *text, char *word){  struct cmd_list_element *ptr;  char **matchlist;  int sizeof_matchlist;  int matches;  int textlen = strlen (text);  sizeof_matchlist = 10;  matchlist = (char **) xmalloc (sizeof_matchlist * sizeof (char *));  matches = 0;  for (ptr = list; ptr; ptr = ptr->next)    if (!strncmp (ptr->name, text, textlen)	&& !ptr->abbrev_flag	&& (ptr->func	    || ptr->prefixlist))      {	if (matches == sizeof_matchlist)	  {	    sizeof_matchlist *= 2;	    matchlist = (char **) xrealloc ((char *) matchlist,					    (sizeof_matchlist					     * sizeof (char *)));	  }	matchlist[matches] = (char *)	  xmalloc (strlen (word) + strlen (ptr->name) + 1);	if (word == text)	  strcpy (matchlist[matches], ptr->name);	else if (word > text)	  {	    /* Return some portion of ptr->name.  */	    strcpy (matchlist[matches], ptr->name + (word - text));	  }	else	  {	    /* Return some of text plus ptr->name.  */	    strncpy (matchlist[matches], word, text - word);	    matchlist[matches][text - word] = '\0';	    strcat (matchlist[matches], ptr->name);	  }	++matches;      }  if (matches == 0)    {      xfree (matchlist);      matchlist = 0;    }  else    {      matchlist = (char **) xrealloc ((char *) matchlist, ((matches + 1)							* sizeof (char *)));      matchlist[matches] = (char *) 0;    }  return matchlist;}/* Helper function for SYMBOL_COMPLETION_FUNCTION.  *//* Return a vector of char pointers which point to the different   possible completions in CMD of TEXT.     WORD points in the same buffer as TEXT, and completions should be   returned relative to this position.  For example, suppose TEXT is "foo"   and we want to complete to "foobar".  If WORD is "oo", return   "oobar"; if WORD is "baz/foo", return "baz/foobar".  */char **complete_on_enum (const char *enumlist[],		  char *text,		  char *word){  char **matchlist;  int sizeof_matchlist;  int matches;  int textlen = strlen (text);  int i;  const char *name;  sizeof_matchlist = 10;  matchlist = (char **) xmalloc (sizeof_matchlist * sizeof (char *));  matches = 0;  for (i = 0; (name = enumlist[i]) != NULL; i++)    if (strncmp (name, text, textlen) == 0)      {	if (matches == sizeof_matchlist)	  {	    sizeof_matchlist *= 2;	    matchlist = (char **) xrealloc ((char *) matchlist,					    (sizeof_matchlist					     * sizeof (char *)));	  }	matchlist[matches] = (char *)	  xmalloc (strlen (word) + strlen (name) + 1);	if (word == text)	  strcpy (matchlist[matches], name);	else if (word > text)	  {	    /* Return some portion of name.  */	    strcpy (matchlist[matches], name + (word - text));	  }	else	  {	    /* Return some of text plus name.  */	    strncpy (matchlist[matches], word, text - word);	    matchlist[matches][text - word] = '\0';	    strcat (matchlist[matches], name);	  }	++matches;      }  if (matches == 0)    {      xfree (matchlist);      matchlist = 0;    }  else    {      matchlist = (char **) xrealloc ((char *) matchlist, ((matches + 1)							* sizeof (char *)));      matchlist[matches] = (char *) 0;    }  return matchlist;}/* check function pointer */intcmd_func_p (struct cmd_list_element *cmd){  return (cmd->func != NULL);}/* call the command function */voidcmd_func (struct cmd_list_element *cmd, char *args, int from_tty){  if (cmd_func_p (cmd))    (*cmd->func) (cmd, args, from_tty);  else    error ("Invalid command");}

⌨️ 快捷键说明

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