Exemplo n.º 1
0
/**
 * Load a view file and do lexographical parsing
 *
 * Returns pointer to last token, or NULL if an error occured.
 * If an error occured 'ei' will be filled with data
 */
token_t *
glw_view_load1(glw_root_t *gr, rstr_t *url, errorinfo_t *ei, token_t *prev,
               int may_unlock)
{
  token_t *last;
  char errbuf[256];

  rstr_t *p = fa_absolute_path(url, prev->file);

  if(may_unlock)
    glw_unlock(gr);

  buf_t *b = fa_load(rstr_get(p),
                     FA_LOAD_VPATHS(gr->gr_vpaths),
                     FA_LOAD_ERRBUF(errbuf, sizeof(errbuf)),
                     NULL);

  if(may_unlock)
    glw_lock(gr);

  if(b == NULL) {
    snprintf(ei->error, sizeof(ei->error), "Unable to open \"%s\" -- %s",
	     rstr_get(p), errbuf);
    snprintf(ei->file,  sizeof(ei->file),  "%s", rstr_get(prev->file));
    ei->line = prev->line;
    rstr_release(p);
    return NULL;
  }

  last = glw_view_lexer(gr, buf_cstr(b), ei, p, prev);
  buf_release(b);
  rstr_release(p);
  return last;
}
Exemplo n.º 2
0
static int
set_alt(glw_view_eval_context_t *ec, const token_attrib_t *a,
	struct token *t)
{
  glw_t *w = ec->w;

  rstr_t *r;

  switch(t->type) {
  default:
    if(w->glw_class->gc_set_alt != NULL)
      w->glw_class->gc_set_alt(w, NULL);
    return 0;

  case TOKEN_RSTRING:
    r = t->t_rstring;
    break;
  case TOKEN_LINK:
    r = t->t_link_rurl;
    break;
  }

  r = fa_absolute_path(r, t->file);

  if(w->glw_class->gc_set_alt != NULL)
    w->glw_class->gc_set_alt(w, r);
  rstr_release(r);
  return 0;
}
Exemplo n.º 3
0
static int
set_path(glw_view_eval_context_t *ec, const token_attrib_t *a,
	 struct token *t)
{
  glw_t *w = ec->w;

  rstr_t *r;

  void (*fn)(glw_t *w, rstr_t *r) = a->fn;

  switch(t->type) {
  case TOKEN_VOID:
    fn(w, NULL);
    return 0;

  case TOKEN_RSTRING:
  case TOKEN_LINK:
    r = t->t_rstring;
    break;

  default:
    return glw_view_seterr(ec->ei, t, 
			    "Attribute '%s' expects a string or scalar not %s",
			   a->name, token2name(t));
  }

  r = fa_absolute_path(r, t->file);
  fn(w, r);
  rstr_release(r);
  return 0;
}
Exemplo n.º 4
0
static int
set_fs(glw_view_eval_context_t *ec, const token_attrib_t *a,
       struct token *t)
{
  rstr_t *str;

  if(t->type == TOKEN_RSTRING)
    str = t->t_rstring;
  else
    str = NULL;

  str = str ? fa_absolute_path(str, t->file) : NULL;

  if(ec->w->glw_class->gc_set_fs != NULL)
    ec->w->glw_class->gc_set_fs(ec->w, str);
  rstr_release(str);
  return 0;
}
Exemplo n.º 5
0
static int
set_source(glw_view_eval_context_t *ec, const token_attrib_t *a,
	   struct token *t)
{
  glw_t *w = ec->w;

  rstr_t *r;

  switch(t->type) {
  default:
    if(w->glw_class->gc_set_source != NULL)
      w->glw_class->gc_set_source(w, NULL);
    return 0;

  case TOKEN_VECTOR:
    if(w->glw_class->gc_set_sources != NULL)
      w->glw_class->gc_set_sources(w, build_rstr_vector(t));
    return 0;

  case TOKEN_RSTRING:
    r = t->t_rstring;
    break;
  case TOKEN_LINK:
    r = t->t_link_rurl;
    break;
  }

  r = fa_absolute_path(r, t->file);

  if(w->glw_class->gc_set_source != NULL)
    w->glw_class->gc_set_source(w, r);

  glw_need_refresh(w->glw_root, 0);
  rstr_release(r);
  return 0;
}
Exemplo n.º 6
0
/**
 * Load a file using the 'glw_rawloader' method
 *
 * Returns pointer to last token, or NULL if an error occured.
 * If an error occured 'ei' will be filled with data
 *
 */
token_t *
glw_view_load1(glw_root_t *gr, rstr_t *url, errorinfo_t *ei, token_t *prev)
{
  char *src;
  token_t *last;
  char errbuf[256];

  rstr_t *p = fa_absolute_path(url, prev->file);
  src = fa_load(rstr_get(p), NULL, gr->gr_vpaths, 
		errbuf, sizeof(errbuf), NULL, 0, NULL, NULL);
  if(src == NULL) {
    snprintf(ei->error, sizeof(ei->error), "Unable to open \"%s\" -- %s",
	     rstr_get(p), errbuf);
    snprintf(ei->file,  sizeof(ei->file),  "%s", rstr_get(prev->file));
    ei->line = prev->line;
    rstr_release(p);
    return NULL;
  }

  last = lexer(gr, src, ei, p, prev);
  free(src);
  rstr_release(p);
  return last;
}