Beispiel #1
0
char*
get_expression_docstring (expression_db_t *edb)
{
    mathmap_t *mathmap;
    char *expression;

    g_assert(edb->kind == EXPRESSION_DB_EXPRESSION);

    if (edb->v.expression.docstring != NULL)
	return edb->v.expression.docstring;

    expression = read_expression(edb->v.expression.path);
    if (expression == NULL)
	return NULL;

    mathmap = parse_mathmap(expression);
    if (mathmap == NULL)
	return NULL;

    g_free(expression);

    g_assert(mathmap->main_filter != NULL);
    if (mathmap->main_filter->v.mathmap.decl->docstring != NULL)
	edb->v.expression.docstring = g_strdup(mathmap->main_filter->v.mathmap.decl->docstring);
    else
	edb->v.expression.docstring = g_strdup("");

    free_mathmap(mathmap);

    return edb->v.expression.docstring;
}
Beispiel #2
0
static grub_err_t
read_property (struct parsebuf *p)
{
  char *name;

  /* Read the property name.  */
  name = read_identifier (p);
  if (! name)
    {
      advance_to_next_line (p);
      return grub_errno;
    }

  /* Skip whitespace before separator.  */
  skip_whitespace (p);

  /* Read separator.  */
  if (read_char (p) != ':')
    {
      grub_error (GRUB_ERR_IO,
                  "%s:%d:%d missing separator after property name `%s'",
                  p->filename, p->line_num, p->col_num, name);
      goto done;
    }

  /* Skip whitespace after separator.  */
  skip_whitespace (p);

  /* Get the value based on its type.  */
  if (peek_char (p) == '"')
    {
      /* String value (e.g., '"My string"').  */
      char *value = read_expression (p);
      if (! value)
        {
          grub_error (GRUB_ERR_IO, "%s:%d:%d missing property value",
                      p->filename, p->line_num, p->col_num);
          goto done;
        }
      /* If theme_set_string results in an error, grub_errno will be returned
         below.  */
      theme_set_string (p->view, name, value, p->theme_dir,
                        p->filename, p->line_num, p->col_num);
      grub_free (value);
    }
  else
    {
      grub_error (GRUB_ERR_IO,
                  "%s:%d:%d property value invalid; "
                  "enclose literal values in quotes (\")",
                  p->filename, p->line_num, p->col_num);
      goto done;
    }

done:
  grub_free (name);
  return grub_errno;
}
Beispiel #3
0
static mathmap_t*
fetch_expression_mathmap (expression_db_t *expr, designer_design_type_t *design_type)
{
    switch (expr->kind)
    {
	case EXPRESSION_DB_EXPRESSION :
	    if (expr->v.expression.mathmap == NULL)
	    {
		char *source = read_expression(expr->v.expression.path);

		if (source == NULL)
		    return NULL;

		expr->v.expression.mathmap = parse_mathmap(source);

		g_free(source);
	    }
	    return expr->v.expression.mathmap;

	case EXPRESSION_DB_DESIGN :
	    if (expr->v.design.mathmap == NULL)
	    {
		designer_design_t *design = designer_load_design(design_type, expr->v.design.path,
								 NULL, NULL, NULL, NULL);
		char *source;

		if (design == NULL)
		    return NULL;

		if (design->root == NULL)
		{
		    designer_free_design(design);
		    return NULL;
		}

		source = make_filter_source_from_design(design, NULL);

		expr->v.design.mathmap = parse_mathmap(source);

		g_free(source);
		designer_free_design(design);
	    }
	    return expr->v.design.mathmap;

	default :
	    g_assert_not_reached();
    }
}
Beispiel #4
0
void repl(FILE *input, environment_t **env, int interactive) {
  int check = 0;

  do {
  	if (check == 0 && interactive < 2) {
  	  printf("evaluate> ");
  	}

  	expression_t *ptr = read_expression(input);

  	if (ptr != NULL) {
  	  //print_expression(ptr); printf(" = "); print_expression(evaluate_expression(ptr, env)); printf("\n");
	  print_expression(evaluate_expression(ptr, env)); printf("\n");

  	  if (check != 0) {
  		check = 0;
  	  }
  	} else {
  	  check = 1;
  	}
  } while (1);
}
Beispiel #5
0
/* Read a GUI object specification from the theme file.
   Any components created will be added to the GUI container PARENT.  */
static grub_err_t
read_object (struct parsebuf *p, grub_gui_container_t parent)
{
  grub_video_rect_t bounds;

  char *name;
  name = read_identifier (p);
  if (! name)
    goto cleanup;

  grub_gui_component_t component = 0;
  if (grub_strcmp (name, "label") == 0)
    {
      component = grub_gui_label_new ();
    }
  else if (grub_strcmp (name, "image") == 0)
    {
      component = grub_gui_image_new ();
    }
  else if (grub_strcmp (name, "vbox") == 0)
    {
      component = (grub_gui_component_t) grub_gui_vbox_new ();
    }
  else if (grub_strcmp (name, "hbox") == 0)
    {
      component = (grub_gui_component_t) grub_gui_hbox_new ();
    }
  else if (grub_strcmp (name, "canvas") == 0)
    {
      component = (grub_gui_component_t) grub_gui_canvas_new ();
    }
  else if (grub_strcmp (name, "progress_bar") == 0)
    {
      component = grub_gui_progress_bar_new ();
    }
  else if (grub_strcmp (name, "circular_progress") == 0)
    {
      component = grub_gui_circular_progress_new ();
    }
  else if (grub_strcmp (name, "boot_menu") == 0)
    {
      component = grub_gui_list_new ();
    }
  else
    {
      /* Unknown type.  */
      grub_error (GRUB_ERR_IO, "%s:%d:%d unknown object type `%s'",
                  p->filename, p->line_num, p->col_num, name);
      goto cleanup;
    }

  if (! component)
    goto cleanup;

  /* Inform the component about the theme so it can find its resources.  */
  component->ops->set_property (component, "theme_dir", p->theme_dir);
  component->ops->set_property (component, "theme_path", p->filename);

  /* Add the component as a child of PARENT.  */
  bounds.x = 0;
  bounds.y = 0;
  bounds.width = -1;
  bounds.height = -1;
  component->ops->set_bounds (component, &bounds);
  parent->ops->add (parent, component);

  skip_whitespace (p);
  if (read_char (p) != '{')
    {
      grub_error (GRUB_ERR_IO,
                  "%s:%d:%d expected `{' after object type name `%s'",
                  p->filename, p->line_num, p->col_num, name);
      goto cleanup;
    }

  while (has_more (p))
    {
      skip_whitespace (p);

      /* Check whether the end has been encountered.  */
      if (peek_char (p) == '}')
        {
          /* Skip the closing brace.  */
          read_char (p);
          break;
        }

      if (peek_char (p) == '#')
        {
          /* Skip comments.  */
          advance_to_next_line (p);
          continue;
        }

      if (peek_char (p) == '+')
        {
          /* Skip the '+'.  */
          read_char (p);

          /* Check whether this component is a container.  */
          if (component->ops->is_instance (component, "container"))
            {
              /* Read the sub-object recursively and add it as a child.  */
              if (read_object (p, (grub_gui_container_t) component) != 0)
                goto cleanup;
              /* After reading the sub-object, resume parsing, expecting
                 another property assignment or sub-object definition.  */
              continue;
            }
          else
            {
              grub_error (GRUB_ERR_IO,
                          "%s:%d:%d attempted to add object to non-container",
                          p->filename, p->line_num, p->col_num);
              goto cleanup;
            }
        }

      char *property;
      property = read_identifier (p);
      if (! property)
        {
          grub_error (GRUB_ERR_IO, "%s:%d:%d identifier expected in theme file",
                      p->filename, p->line_num, p->col_num);
          goto cleanup;
        }

      skip_whitespace (p);
      if (read_char (p) != '=')
        {
          grub_error (GRUB_ERR_IO,
                      "%s:%d:%d expected `=' after property name `%s'",
                      p->filename, p->line_num, p->col_num, property);
          grub_free (property);
          goto cleanup;
        }
      skip_whitespace (p);

      char *value;
      value = read_expression (p);
      if (! value)
        {
          grub_free (property);
          goto cleanup;
        }

      /* Handle the property value.  */
      if (grub_strcmp (property, "left") == 0)
	parse_proportional_spec (value, &component->x, &component->xfrac);
      else if (grub_strcmp (property, "top") == 0)
	parse_proportional_spec (value, &component->y, &component->yfrac);
      else if (grub_strcmp (property, "width") == 0)
	parse_proportional_spec (value, &component->w, &component->wfrac);
      else if (grub_strcmp (property, "height") == 0)
	parse_proportional_spec (value, &component->h, &component->hfrac);
      else
	/* General property handling.  */
	component->ops->set_property (component, property, value);

      grub_free (value);
      grub_free (property);
      if (grub_errno != GRUB_ERR_NONE)
        goto cleanup;
    }

cleanup:
  grub_free (name);
  return grub_errno;
}