示例#1
0
文件: macro.c 项目: bminor/bash
/* Set up to read subsequent input from STRING.
   STRING is free ()'ed when we are done with it. */
void
_rl_with_macro_input (char *string)
{
  if (macro_level > MAX_MACRO_LEVEL)
    {
      _rl_errmsg ("maximum macro execution nesting level exceeded");
      _rl_abort_internal ();
      return;
    }

#if 0
  if (rl_executing_macro)		/* XXX - later */
#endif
    _rl_push_executing_macro ();
  rl_executing_macro = string;
  executing_macro_index = 0;
  RL_SETSTATE(RL_STATE_MACROINPUT);
}
示例#2
0
void _rl_parse_colors()
{
#if defined (COLOR_SUPPORT)
  const char *p;		/* Pointer to character being parsed */
  char *buf;			/* color_buf buffer pointer */
  int state;			/* State of parser */
  int ind_no;			/* Indicator number */
  char label[3];		/* Indicator label */
  COLOR_EXT_TYPE *ext;		/* Extension we are working on */

  p = sh_get_env_value ("LS_COLORS");
  if (p == 0 || *p == '\0')
    {
      _rl_color_ext_list = NULL;
      return;
    }

  ext = NULL;
  strcpy (label, "??");

  /* This is an overly conservative estimate, but any possible
     LS_COLORS string will *not* generate a color_buf longer than
     itself, so it is a safe way of allocating a buffer in
     advance.  */
  buf = color_buf = savestring (p);

  state = 1;
  while (state > 0)
    {
      switch (state)
        {
        case 1:		/* First label character */
          switch (*p)
            {
            case ':':
              ++p;
              break;

            case '*':
              /* Allocate new extension block and add to head of
                 linked list (this way a later definition will
                 override an earlier one, which can be useful for
                 having terminal-specific defs override global).  */

              ext = (COLOR_EXT_TYPE *)xmalloc (sizeof *ext);
              ext->next = _rl_color_ext_list;
              _rl_color_ext_list = ext;

              ++p;
              ext->ext.string = buf;

              state = (get_funky_string (&buf, &p, true, &ext->ext.len)
                       ? 4 : -1);
              break;

            case '\0':
              state = 0;	/* Done! */
              break;

            default:	/* Assume it is file type label */
              label[0] = *(p++);
              state = 2;
              break;
            }
          break;

        case 2:		/* Second label character */
          if (*p)
            {
              label[1] = *(p++);
              state = 3;
            }
          else
            state = -1;	/* Error */
          break;

        case 3:		/* Equal sign after indicator label */
          state = -1;	/* Assume failure...  */
          if (*(p++) == '=')/* It *should* be...  */
            {
              for (ind_no = 0; indicator_name[ind_no] != NULL; ++ind_no)
                {
                  if (STREQ (label, indicator_name[ind_no]))
                    {
                      _rl_color_indicator[ind_no].string = buf;
                      state = (get_funky_string (&buf, &p, false,
                                                 &_rl_color_indicator[ind_no].len)
                               ? 1 : -1);
                      break;
                    }
                }
              if (state == -1)
		{
                  _rl_errmsg ("LS_COLORS: unrecognized prefix: %s", label);
                  /* recover from an unrecognized prefix */
                  while (p && *p && *p != ':')
		    p++;
		  if (p && *p == ':')
		    state = 1;
		  else if (p && *p == 0)
		    state = 0;
		}
            }
          break;

        case 4:		/* Equal sign after *.ext */
          if (*(p++) == '=')
            {
              ext->seq.string = buf;
              state = (get_funky_string (&buf, &p, false, &ext->seq.len)
                       ? 1 : -1);
            }
          else
            state = -1;
          /* XXX - recover here as with an unrecognized prefix? */
          if (state == -1 && ext->ext.string)
	    _rl_errmsg ("LS_COLORS: syntax error: %s", ext->ext.string);
          break;
        }
    }

  if (state < 0)
    {
      COLOR_EXT_TYPE *e;
      COLOR_EXT_TYPE *e2;

      _rl_errmsg ("unparsable value for LS_COLORS environment variable");
      free (color_buf);
      for (e = _rl_color_ext_list; e != NULL; /* empty */)
        {
          e2 = e;
          e = e->next;
          free (e2);
        }
      _rl_color_ext_list = NULL;
      _rl_colored_stats = 0;	/* can't have colored stats without colors */
    }
#else /* !COLOR_SUPPORT */
  ;
#endif /* !COLOR_SUPPORT */
}