Пример #1
0
static int
parsepair(Parser *p, JSON *parent, JSON **kprev, JSON **vprev)
{
	must(*p->s == '"');
	must(parsestring(p, parent, kprev));
	skipws(p);
	must(consume(p, ":"));
	skipws(p);
	must(parsevalue(p, parent, vprev));
	return 1;
}
Пример #2
0
static int
parsearray(Parser *p, JSON *parent, JSON **prev)
{
	JSON *v = inititem(p, parent, prev, '[');
	must(consume(p, "["));
	skipws(p);
	if (*p->s != ']') {
		JSON *aprev = nil;
		must(parsevalue(p, v, &aprev));
		for (skipws(p); *p->s == ','; skipws(p)) {
			p->s++; // consume ,
			skipws(p);
			must(parsevalue(p, v, &aprev));
		}
	}
	must(consume(p, "]"));
	if (v) {
		v->end = p->s;
	}
	return 1;
}
Пример #3
0
static int trytypetag (struct rnndb *db, char *file, xmlNode *node, struct rnntypeinfo *ti) {
	if (!strcmp(node->name, "value")) {
		struct rnnvalue *val = parsevalue(db, file, node);
		if (val)
			ADDARRAY(ti->vals, val);
		return 1;
	} else if (!strcmp(node->name, "bitfield")) {
		struct rnnbitfield *bf = parsebitfield(db, file, node);
		if (bf)
			ADDARRAY(ti->bitfields, bf);
		return 1;
	}
	return 0;
}
Пример #4
0
/*------------------------------------------------------------------------
 * parseset - parse the words from the input line for a set operation
 *------------------------------------------------------------------------
 */
LOCAL int
parseset(
    struct req_desc	*rqdp,
    int			stdout)
{
	struct snbentry	*bl;
	char 		*word;

	for (getword(&word); *word != NULLCH; getword(&word)) {
		if ((bl = parseoid(&word)) == (struct snbentry *) SYSERR)
			return SYSERR;
		if (rqdp->bindlf) {
			bl->sb_prev = rqdp->bindle;
			rqdp->bindle = rqdp->bindle->sb_next = bl;
		} else
			rqdp->bindlf = rqdp->bindle = bl;
		if (parsevalue(&word, bl) == SYSERR) {
			fprintf(stdout, "bad syntax\n");
			return SYSERR;
		}
	}
	return OK;
}
int
gst_gl_shadervariables_parse (GstGLShader * shader, char *variables,
    int (*_setvariable) (GstGLShader * shader,
        struct gst_gl_shadervariable_desc * v))
{
  char *p = 0;
  char *p0;
  char *e;
  char e1 = 0;
  char *t = 0;
  char *varname;
  char *vartype;
  char *varvalue;
  int arraysize = 0;
  char *saveptr = variables;
  int line = 1;
  char *lim;
  int i;
  int len;
  struct gst_gl_shadervariable_desc ret;

  if (!_setvariable) {
    _setvariable = gst_gl_shadervariable_set;
  }

  if (!variables)
    return 0;

  p0 = variables;
  trimright (p0, " \t\n");
  lim = variables + strlen (variables);
  e = strchr (p0, ';');
  while (p0 < lim) {

    if (!e) {
      if (p0[0])
        goto parse_error;
      break;
    }

    e1 = e[1];
    e[1] = 0;
    p = g_strdup (p0);
    e[1] = e1;

    trimright (p, " \t");
    trimleft (p, " \t\n");

    t = strtok_r (p, " \t", &saveptr);
    if (!t)
      goto parse_error;
    trimleft (t, " \t");
    trimright (t, " \t\n");

    if (t[0]) {

      if (!strcmp (t, "const")) {
        t = strtok_r (0, " \t", &saveptr);
        if (!t)
          goto parse_error;
        trimleft (t, " \t");
        if (!t[0])
          goto parse_error;
      }
      // parse data type
      for (i = 0; i < _datatypecount; ++i) {
        if (!strcmp (t, gst_gl_shadervariable_datatype[i])) {
          ret.type = (gst_gl_shadervariable_datatypeindex) i;
          break;
        }
      }
      if (i == _datatypecount)
        goto parse_error;

      vartype = g_strdup (t);
      GST_INFO ("vartype : '%s'\n", vartype);

      trimleft (saveptr, " \t");
      t = saveptr;
      if (*saveptr == '=')
        goto parse_error;

      // parse variable name and array size
      t = parsename (&varname, &arraysize, &saveptr);
      if (t)
        goto parse_error;

      trimright (varname, " \t");
      GST_INFO ("varname : '%s'\n", varname);
      GST_INFO ("arraysize : %d\n", arraysize);

      // check type cast after assignement operator
      t = strtok_r (0, "(", &saveptr);
      if (!t)
        goto parse_error;
      trimleft (t, " \t");
      trimright (t, " \t");

      if (arraysize) {
        char *s = g_malloc (strlen (vartype) + 32);
        sprintf (s, "%s[%d]", vartype, arraysize);
        if (strcmp (t, s)) {
          g_free (s);
          goto parse_error;
        }
      } else {
        if (strcmp (t, vartype))
          goto parse_error;
      }

      // extract variable value
      t = strtok_r (0, ";", &saveptr);
      if (!t)
        goto parse_error;
      trimleft (t, " \t");
      trimright (t, " \t");

      if (!t[0])
        goto parse_error;
      if (*(saveptr - 2) != ')')
        goto parse_error;
      *(saveptr - 2) = 0;
      if (!t[0])
        goto parse_error;

      varvalue = g_strdup (t);
      GST_INFO ("value: %s\n\n", varvalue);

      t = saveptr;
      if (t[0])
        goto parse_error;

      // parse variable value
      len = strlen (varvalue);
      ret.name = varname;
      ret.arraysize = arraysize;
      t = parsevalue (varvalue, saveptr, &ret);
      if (t) {
        t -= len;
        goto parse_error;
      }
      // set variable value
      _setvariable (shader, &ret);

      fflush (0);
    }
    // Tell me why we cannot free(p) whithout segfault.
    //g_free(p);
    p0 = e + 1;
    ++line;
    e = strchr (p0, ';');
  }

  return 0;

parse_error:
  if (!t) {
    t = saveptr;
  }
  if (!e) {
    t = p = p0;
  } else {
    e[1] = 0;
    trimleft (p0, " \t\n");
    GST_ERROR ("\n%s", p0);
    e[1] = e1;
  }
  GST_ERROR ("parse error on line %d, position %ld (%s)", line, (glong) (t - p),
      t);
  return -1;
}
Пример #6
0
static void parseenum(struct rnndb *db, char *file, xmlNode *node) {
	xmlAttr *attr = node->properties;
	char *name = 0;
	int isinline = 0;
	int bare = 0;
	char *prefixstr = 0;
	char *varsetstr = 0;
	char *variantsstr = 0;
	int i;
	while (attr) {
		if (!strcmp(attr->name, "name")) {
			name = getattrib(db, file, node->line, attr);
		} else if (!strcmp(attr->name, "bare")) {
			bare = getboolattrib(db, file, node->line, attr);
		} else if (!strcmp(attr->name, "inline")) {
			isinline = getboolattrib(db, file, node->line, attr);
		} else if (!strcmp(attr->name, "prefix")) {
			prefixstr = strdup(getattrib(db, file, node->line, attr));
		} else if (!strcmp(attr->name, "varset")) {
			varsetstr = strdup(getattrib(db, file, node->line, attr));
		} else if (!strcmp(attr->name, "variants")) {
			variantsstr = strdup(getattrib(db, file, node->line, attr));
		} else {
			fprintf (stderr, "%s:%d: wrong attribute \"%s\" for enum\n", file, node->line, attr->name);
			db->estatus = 1;
		}
		attr = attr->next;
	}
	if (!name) {
		fprintf (stderr, "%s:%d: nameless enum\n", file, node->line);
		db->estatus = 1;
		return;
	}
	struct rnnenum *cur = 0;
	for (i = 0; i < db->enumsnum; i++)
		if (!strcmp(db->enums[i]->name, name)) {
			cur = db->enums[i];
			break;
		}
	if (cur) {
		if (strdiff(cur->varinfo.prefixstr, prefixstr) ||
				strdiff(cur->varinfo.varsetstr, varsetstr) ||
				strdiff(cur->varinfo.variantsstr, variantsstr) ||
				cur->isinline != isinline || cur->bare != bare) {
			fprintf (stderr, "%s:%d: merge fail for enum %s\n", file, node->line, node->name);
			db->estatus = 1;
		}
	} else {
		cur = calloc(sizeof *cur, 1);
		cur->name = strdup(name);
		cur->isinline = isinline;
		cur->bare = bare;
		cur->varinfo.prefixstr = prefixstr;
		cur->varinfo.varsetstr = varsetstr;
		cur->varinfo.variantsstr = variantsstr;
		cur->file = file;
		ADDARRAY(db->enums, cur);
	}
	xmlNode *chain = node->children;
	while (chain) {
		if (chain->type != XML_ELEMENT_NODE) {
		} else if (!strcmp(chain->name, "value")) {
			struct rnnvalue *val = parsevalue(db, file, chain);
			if (val)
				ADDARRAY(cur->vals, val);
		} else if (!trytop(db, file, chain) && !trydoc(db, file, chain)) {
			fprintf (stderr, "%s:%d: wrong tag in enum: <%s>\n", file, chain->line, chain->name);
			db->estatus = 1;
		}
		chain = chain->next;
	}
}