Beispiel #1
0
static char *
variable_append (const char *name, unsigned int length,
                 const struct variable_set_list *set)
{
  const struct variable *v;
  char *buf = 0;

  /* If there's nothing left to check, return the empty buffer.  */
  if (!set)
    return initialize_variable_output ();

  /* Try to find the variable in this variable set.  */
  v = lookup_variable_in_set (name, length, set->set);

  /* If there isn't one, look to see if there's one in a set above us.  */
  if (!v)
    return variable_append (name, length, set->next);

  /* If this variable type is append, first get any upper values.
     If not, initialize the buffer.  */
  if (v->append)
    buf = variable_append (name, length, set->next);
  else
    buf = initialize_variable_output ();

  /* Append this value to the buffer, and return it.
     If we already have a value, first add a space.  */
  if (buf > variable_buffer)
    buf = variable_buffer_output (buf, " ", 1);
#ifdef CONFIG_WITH_VALUE_LENGTH
  assert (v->value_length == strlen (v->value));
#endif

  /* Either expand it or copy it, depending.  */
  if (! v->recursive)
#ifdef CONFIG_WITH_VALUE_LENGTH
    return variable_buffer_output (buf, v->value, v->value_length);
#else
    return variable_buffer_output (buf, v->value, strlen (v->value));
#endif

#ifdef CONFIG_WITH_VALUE_LENGTH
  variable_expand_string_2 (buf, v->value, v->value_length, &buf);
  return buf;
#else
  buf = variable_expand_string (buf, v->value, strlen (v->value));
  return (buf + strlen (buf));
#endif
}
Beispiel #2
0
/*! Show a expression. Set "expand" to 1 if you want variable
   definitions inside the displayed value expanded.
*/
bool
dbg_cmd_show_exp (char *psz_varname, bool expand) 
{
  if (!psz_varname || 0==strlen(psz_varname)) {
    printf(_("You need to supply a variable name.\n"));
    return false;
  } else {
    variable_t *p_v;
    variable_set_t *p_set = NULL;
    variable_set_list_t *p_file_vars = NULL;
    if (p_stack && p_stack->p_target && p_stack->p_target->name) {
      const char *psz_target = p_stack->p_target->name;
      file_t *p_target = lookup_file (psz_target);
      if (p_target) {
	initialize_file_variables (p_target, 0);
	set_file_variables (p_target);
	p_file_vars = p_target->variables;
	p_set = p_file_vars->set;
      }
    }
    if (p_set) {
      p_v = lookup_variable_in_set(psz_varname, strlen(psz_varname), p_set);
      if (!p_v) 
	/* May be a global variable. */
	p_v = lookup_variable (psz_varname, strlen (psz_varname));
    } else {
      p_v = lookup_variable (psz_varname, strlen (psz_varname));
    }
    if (p_v) {
      if (expand) {
	print_variable_expand(p_v);
      } else
	print_variable(p_v);
    } else {
      if (expand)
	printf("%s\n", variable_expand_set(psz_varname, p_file_vars));
      else {
	try_without_dollar(psz_varname);
	return false;
      }
    }
  }
  return true;
}
Beispiel #3
0
static char *
variable_append (const char *name, unsigned int length,
                 const struct variable_set_list *set, int local)
{
    const struct variable *v;
    char *buf = 0;
    /* If this set is local and the next is not a parent, then next is local.  */
    int nextlocal = local && set->next_is_parent == 0;

    /* If there's nothing left to check, return the empty buffer.  */
    if (!set)
        return initialize_variable_output ();

    /* Try to find the variable in this variable set.  */
    v = lookup_variable_in_set (name, length, set->set);

    /* If there isn't one, or this one is private, try the set above us.  */
    if (!v || (!local && v->private_var))
        return variable_append (name, length, set->next, nextlocal);

    /* If this variable type is append, first get any upper values.
       If not, initialize the buffer.  */
    if (v->append)
        buf = variable_append (name, length, set->next, nextlocal);
    else
        buf = initialize_variable_output ();

    /* Append this value to the buffer, and return it.
       If we already have a value, first add a space.  */
    if (buf > variable_buffer)
        buf = variable_buffer_output (buf, " ", 1);

    /* Either expand it or copy it, depending.  */
    if (! v->recursive)
        return variable_buffer_output (buf, v->value, strlen (v->value));

    buf = variable_expand_string (buf, v->value, strlen (v->value));
    return (buf + strlen (buf));
}