示例#1
0
/* Parse an object - create a new root, and populate. */
SWITCH_DECLARE(cJSON *)cJSON_Parse(const char *value)
{
	cJSON *c=cJSON_New_Item();
	ep=0;
	if (!c) return 0;       /* memory fail */

	if (!parse_value(c,skip(value))) {cJSON_Delete(c);return 0;}
	return c;
}
示例#2
0
文件: cson.c 项目: AlanZheng/cson
/* Parse an object - create a new root, and populate. */
CSON *CSON_Parse(const char *value)
{
	CSON *c=CSON_New_Item();
	ep=0;
	if (!c) return 0;       /* memory fail */

	if (!parse_value(c,skip(value))) {CSON_Delete(c);return 0;}
	return c;
}
示例#3
0
Status ComplexQuery::parse_expression(const string& exp) {
  static const string OPCHAR = "=!<>";
  CHECK(!exp.empty());

  size_t op_pos = exp.find_first_of(OPCHAR);
  if (op_pos == string::npos) {
    return Status(-1, "Bad expression.");
  }
  size_t value_pos = exp.find_first_not_of(OPCHAR, op_pos);
  if (value_pos == string::npos) {
    return Status(-1, "Bad expression.");
  }
  string field = trim_copy(exp.substr(0, op_pos));
  string opstr = exp.substr(op_pos, value_pos - op_pos);
  string value = trim_copy(exp.substr(value_pos));

  int op = parse_cond_op(opstr);
  if (op < 0) {
    return Status(-1, "Bad operation.");
  }

  string tmp(value);
  Status status = parse_value(field, tmp, &value);
  if (!status.ok()) {
    LOG(ERROR) << status.message() << ":" << tmp;
    return status;
  }

  switch (op) {
    case LE:
      range_query_map_[field].upper = value;
      range_query_map_[field].upper_closed = true;
      break;
    case LT:
      range_query_map_[field].upper = value;
      range_query_map_[field].upper_closed = false;
      break;
    case GE:
      range_query_map_[field].lower = value;
      range_query_map_[field].lower_closed = true;
      break;
    case GT:
      range_query_map_[field].lower = value;
      range_query_map_[field].lower_closed = false;
      break;
    case EQ:
      range_query_map_[field].upper = value;
      range_query_map_[field].upper_closed = true;
      range_query_map_[field].lower = value;
      range_query_map_[field].lower_closed = true;
      break;
    default:
      LOG(ERROR) << "Unknown op code: " << opstr;
      return Status(-1, "Unknown op code.");
  }
  return Status::OK;
}
示例#4
0
static const char *parse_field(struct buffer *self, int tag)
{
	if (parse_tag(self) != tag) {
		next_tag(self);
		return NULL;
	}

	return parse_value(self);
}
示例#5
0
文件: nxjson.c 项目: debosvi/bozHMI
const nx_json *nx_json_parse(char *text, nx_json_unicode_encoder encoder) {
    nx_json js = { 0 };
    if (!parse_value(&js, 0, text, encoder)) {
        if (js.child)
            nx_json_free(js.child);
        return 0;
    }
    return js.child;
}
示例#6
0
static json_t *parse_dict(stream_t *stream, size_t flags,
                          json_error_t *error)
{
    int c;
    char *key;
    json_t *value;
    json_t *object = json_object();
    if(!object)
        return NULL;

    c = stream_getc(stream);
    assert(c == 'd');

    while (1) {
        c = stream_peek(stream);
        if (c == EOF) {
            error_set(error, stream, "unterminated dictionary");
            goto error;
        }
        if (c == 'e')
            break;

        key = parse_string(stream, flags, error);
        if (!key)
            goto error;

        if(flags & JSON_REJECT_DUPLICATES) {
            if(json_object_get(object, key)) {
                jsonp_free(key);
                error_set(error, stream, "duplicate object key");
                goto error;
            }
        }

        value = parse_value(stream, flags, error);
        if (!value) {
            jsonp_free(key);
            goto error;
        }

        if(json_object_set_nocheck(object, key, value)) {
            jsonp_free(key);
            json_decref(value);
            goto error;
        }

        json_decref(value);
        jsonp_free(key);
    }
    stream_getc(stream);
    return object;

error:
    json_decref(object);
    return NULL;
}
示例#7
0
文件: drbd.c 项目: Mindera/collectd
static int drbd_submit_fields (long int resource,
		char **fields, size_t fields_num)
{
	char plugin_instance[DATA_MAX_NAME_LEN];
	value_t values[fields_num];
	value_list_t vl = VALUE_LIST_INIT;
	size_t i;

	if (resource < 0)
	{
		WARNING ("drbd plugin: Unable to parse resource");
		return (EINVAL);
	}

	if (fields_num != drbd_names_num)
	{
		WARNING ("drbd plugin: Wrong number of fields for "
				 "r%ld statistics. Expected %zu, got %zu.",
				 resource, drbd_names_num, fields_num);
		return (EINVAL);
	}

	ssnprintf (plugin_instance, sizeof (plugin_instance), "r%ld",
			resource);

	for (i = 0; i < drbd_names_num; i++)
	{
		char *data;
		/* skip non numeric wo */
		if (strncmp(fields[i], "wo", 2) == 0)
			continue;
		data = strchr(fields[i], ':');
		if (data == NULL)
			return (EINVAL);
		(void) parse_value (++data, &values[i], DS_TYPE_DERIVE);
	}

	vl.values_len = 1;
	sstrncpy (vl.host, hostname_g, sizeof (vl.host));
	sstrncpy (vl.plugin, "drbd", sizeof (vl.plugin));
	sstrncpy (vl.plugin_instance, plugin_instance,
			sizeof (vl.plugin_instance));
	sstrncpy (vl.type, "drbd_resource", sizeof (vl.type));

	for (i = 0; i < fields_num; i++)
	{
		if (drbd_names[i] == NULL)
			continue;
		vl.values = values + i;
		sstrncpy (vl.type_instance, drbd_names[i],
				sizeof (vl.type_instance));
		plugin_dispatch_values (&vl);
	}

	return (0);
} /* drbd_submit_fields */
示例#8
0
Value *Parser::parse_struct() {
    StructSig *sig = parse_struct_sig();
    Struct *value = new Struct(sig);

    for (size_t i = 0; i < sig->num_members; ++i) {
        value->members[i] = parse_value();
    }

    return value;
}
示例#9
0
void Parser::parse_arg(Call *call, Mode mode) {
    unsigned index = read_uint();
    Value *value = parse_value(mode);
    if (value) {
        if (index >= call->args.size()) {
            call->args.resize(index + 1);
        }
        call->args[index].value = value;
    }
}
示例#10
0
/* Parse an object - create a new root, and populate. */
cJSON *cJSON_Parse(const char *value)
{
	cJSON *c=cJSON_New_Item();
	ep=0;
	if (!c) return 0;       /* memory fail */
	if (!parse_value(c,skip(value))) {cJSON_Delete(c);return 0;}
	
	//printf("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 264 \n");
	return c;
}
示例#11
0
文件: load.c 项目: derdewey/jansson
static json_t *parse_json(lex_t *lex, json_error_t *error)
{
    lex_scan(lex, error);
    if(lex->token != '[' && lex->token != '{') {
        error_set(error, lex, "'[' or '{' expected");
        return NULL;
    }

    return parse_value(lex, error);
}
示例#12
0
// parameter    = attribute "=" value
// attribute    = token
const char* parse_parameter(unsigned char** p)
{
	if (parse_token(p))
		return ERR;
	if (parse_char(p, '='))
		return ERR;
	if (parse_value(p))
		return ERR;
	return NULL;
}
示例#13
0
bool LogFileOutput::parse_options(const char* options, outputStream* errstream) {
  if (options == NULL || strlen(options) == 0) {
    return true;
  }
  bool success = true;
  char* opts = os::strdup_check_oom(options, mtLogging);

  char* comma_pos;
  char* pos = opts;
  do {
    comma_pos = strchr(pos, ',');
    if (comma_pos != NULL) {
      *comma_pos = '\0';
    }

    char* equals_pos = strchr(pos, '=');
    if (equals_pos == NULL) {
      success = false;
      break;
    }
    char* key = pos;
    char* value_str = equals_pos + 1;
    *equals_pos = '\0';

    if (strcmp(FileCountOptionKey, key) == 0) {
      size_t value = parse_value(value_str);
      if (value > MaxRotationFileCount) {
        errstream->print_cr("Invalid option: %s must be in range [0, %u]",
                            FileCountOptionKey,
                            MaxRotationFileCount);
        success = false;
        break;
      }
      _file_count = static_cast<uint>(value);
    } else if (strcmp(FileSizeOptionKey, key) == 0) {
      julong value;
      success = Arguments::atojulong(value_str, &value);
      if (!success || (value > SIZE_MAX)) {
        errstream->print_cr("Invalid option: %s must be in range [0, "
                            SIZE_FORMAT "]", FileSizeOptionKey, SIZE_MAX);
        success = false;
        break;
      }
      _rotate_size = static_cast<size_t>(value);
    } else {
      errstream->print_cr("Invalid option '%s' for log file output.", key);
      success = false;
      break;
    }
    pos = comma_pos + 1;
  } while (comma_pos != NULL);

  os::free(opts);
  return success;
}
示例#14
0
/* Build an array from input text. */
static const char *parse_array(cJSON *item,const char *value) {
    cJSON *child;
    if (*value!='[')	{
        ep=value;    /* not an array! */
        return 0;
    }

    item->type=cJSON_Array;
    value=skip(value+1);
    if (*value==']') {
        return value+1;    /* empty array. */
    }

    item->child=child=cJSON_New_Item();
    if (!item->child) {
        return 0;    /* memory fail */
    }
    value=skip(parse_value(child,skip(value)));	/* skip any spacing, get the value. */
    if (!value) {
        return 0;
    }

    while (*value==',') {
        cJSON *new_item;
        if (!(new_item=cJSON_New_Item())) {
            return 0;    /* memory fail */
        }
        child->next=new_item;
        new_item->prev=child;
        child=new_item;
        value=skip(parse_value(child,skip(value+1)));
        if (!value) {
            return 0;    /* memory fail */
        }
    }

    if (*value==']') {
        return value+1;    /* end of array */
    }
    ep=value;
    return 0;	/* malformed. */
}
示例#15
0
static const char *parse_field_promisc(struct buffer *self, int *tag)
{
	*tag = parse_tag(self);

	if (!(*tag)) {
		next_tag(self);
		return NULL;
	}

	return parse_value(self);
}
示例#16
0
static void v_lisu_lisl(char *str, MNEMONIC *mne) {

    unsigned long operand;

    programlabel();
    parse_value(str, &operand);
    if (operand > 7) {
        f8err(ERROR_VALUE_MUST_BE_LT_8, mne->name, str, false);
    }
    emit_opcode1(mne->opcode[0] | (operand & 7));
}
示例#17
0
文件: protocol.c 项目: kergma/lascar
void parse_values(char *buf, size_t buflen, int *pos, hash *h)
{
	value_descriptor d;
	void *v;
	size_t vl;
	while (parse_value(buf, buflen, pos, &d, &v, &vl))
	{
		struct hash_item i={d.f, d.t, v};
		(*h)[d.k]=i;
	};
}
示例#18
0
文件: table.c 项目: collectd/collectd
static int tbl_result_dispatch(tbl_t *tbl, tbl_result_t *res, char **fields,
                               size_t fields_num) {
  value_list_t vl = VALUE_LIST_INIT;
  value_t values[res->values_num];

  assert(res->ds);
  assert(res->values_num == res->ds->ds_num);

  for (size_t i = 0; i < res->values_num; ++i) {
    assert(res->values[i] < fields_num);
    char *value = fields[res->values[i]];
    if (parse_value(value, &values[i], res->ds->ds[i].type) != 0)
      return -1;
  }

  vl.values = values;
  vl.values_len = STATIC_ARRAY_SIZE(values);

  sstrncpy(vl.plugin, (tbl->plugin_name != NULL) ? tbl->plugin_name : "table",
           sizeof(vl.plugin));
  sstrncpy(vl.plugin_instance, tbl->instance, sizeof(vl.plugin_instance));
  sstrncpy(vl.type, res->type, sizeof(vl.type));

  if (res->instances_num == 0) {
    if (res->instance_prefix)
      sstrncpy(vl.type_instance, res->instance_prefix,
               sizeof(vl.type_instance));
  } else {
    char *instances[res->instances_num];
    char instances_str[DATA_MAX_NAME_LEN];

    for (size_t i = 0; i < res->instances_num; ++i) {
      assert(res->instances[i] < fields_num);
      instances[i] = fields[res->instances[i]];
    }

    strjoin(instances_str, sizeof(instances_str), instances,
            STATIC_ARRAY_SIZE(instances), "-");
    instances_str[sizeof(instances_str) - 1] = '\0';

    int r;
    if (res->instance_prefix == NULL)
      r = snprintf(vl.type_instance, sizeof(vl.type_instance), "%s",
                   instances_str);
    else
      r = snprintf(vl.type_instance, sizeof(vl.type_instance), "%s-%s",
                   res->instance_prefix, instances_str);
    if ((size_t)r >= sizeof(vl.type_instance))
      log_warn("Truncated type instance: %s.", vl.type_instance);
  }

  plugin_dispatch_values(&vl);
  return 0;
} /* tbl_result_dispatch */
示例#19
0
static void v_lis(char *str, MNEMONIC *mne) {

    unsigned long operand;

    programlabel();
    parse_value(str, &operand);
    if (operand > 15) {
        f8err(ERROR_VALUE_MUST_BE_LT_10, mne->name, str, false);
    }
    emit_opcode1(0x70 | (operand & 15));
}
示例#20
0
/*
 * handles instructions that take a word operand:
 * dci, jmp, pi
 */
static void v_wordop(char *str, MNEMONIC *mne) {

    unsigned long value;

    programlabel();
    parse_value(str, &value);
    if (value > 0xffff) {
        f8err(ERROR_VALUE_MUST_BE_LT_10000, mne->name, str, false);
    }
    emit_opcode3(mne->opcode[0], (value >> 8) & 0xff, value & 0xff);
}
示例#21
0
/*
 * handles instructions that take a byte operand:
 * ai, ci, in, li, ni, oi, out, xi
 */
static void v_byteop(char *str, MNEMONIC *mne) {

    unsigned long value;

    programlabel();
    parse_value(str, &value);
    if (value > 0xff) {
        f8err(ERROR_ADDRESS_MUST_BE_LT_100, mne->name, str, false);
    }
    emit_opcode2(mne->opcode[0], value & 0xff);
}
示例#22
0
文件: json.cpp 项目: PowerKiller/code
/// Internal: Build an object from the text.
static const char *parse_object(JSON *item, const char *value)
{
    JSON *child;
    if(*value!='{') { ep = value; return 0; }    // not an object!

    item->type = JSON_OBJECT;
    value = skip(value+1);
    if(*value=='}') return value+1;    // empty array.

    item->firstchild = child = new JSON();
    child->parent = item;

    value = skip(parse_string(child, skip(value)));
    if(!value) return 0;
    child->name = child->valuestring;
    child->valuestring = NULL;

    if(*value!=':') { ep = value; return 0; }    // fail!
    value = skip(parse_value(child, skip(value+1)));    // skip any spacing, get the value.
    if(!value) return 0;

    while (*value==',')
    {
        JSON *new_item = new JSON();
        new_item->parent = item;
        child->next = new_item;
        new_item->prev = child; child = new_item;

        value = skip(parse_string(child, skip(value+1)));
        if(!value) return 0;
        child->name = child->valuestring;
        child->valuestring = NULL;

        if(*value!=':') { ep = value; return 0; }    // fail!
        value = skip(parse_value( child, skip(value+1)));    // skip any spacing, get the value.
        if(!value) return 0;
    }

    if(*value=='}') return value+1;    // end of array
    ep = value; return 0;    // malformed.
}
示例#23
0
double parse_value_optional(struct file_info *input, char *prefix,
                            double default_value) {
    //printf("in function: %s\n",__FUNCTION__);

    assert(input);
    char **buf = &input->pos;

    if (!*buf || isdelimiter(**buf))
        return default_value;
    else
        return parse_value(input,prefix,"value");
}
示例#24
0
文件: 7a.c 项目: 7shi/Betelgeuse
void parse_mbr(enum Op op)
{
    enum Regs ra, rb;
    uint64_t hint;
    enum Token token = read_token();
    if (op == Ret && (token == EndL || token == EndF))
        assemble_mbr(op, Zero, RA, 1);
    else if (get_reg(&ra, token, 0)
        && read_sign(",") && read_sign("(") && read_reg(&rb, 0) && read_sign(")")
        && read_sign(",") && parse_value(&hint))
        assemble_mbr(op, ra, rb, (int)hint);
}
示例#25
0
static void v_bf_bt(char *str, MNEMONIC *mne) {

    int ncommas;
    int cindex;
    int i;
    char *op1;
    char *op2;
    unsigned long value;

    /* a valid operand string must contain exactly one comma. find it. */
    ncommas = 0;
    cindex = 0;
    for (i=0; str[i]; i++) {
        if (',' == str[i]) {
        ncommas++;
        cindex = i;
        }
    }
    if (1 != ncommas) {
        f8err(ERROR_SYNTAX_ERROR, mne->name, str, false);
        return;
    }

    /* extract operands */
    str[cindex] = 0;
    op1 = str;
    op2 = &str[cindex+1];

    /* parse first operand*/
    if (parse_value(op1, &value)) {
        /* unresolved expression, reserve space */
        emit_opcode2(0, 0);
        return;
    }

    /* check first operand */
    str[cindex] = ',';		/* restore operand string */
    if ('f' == mne->name[1]) {
        /* bf */
        if (value > 15) {
            f8err(ERROR_VALUE_MUST_BE_LT_10, mne->name, str, false);
            value &= 15;
        }
    } else {
        /* bt */
        if (value > 7) {
            f8err(ERROR_VALUE_MUST_BE_LT_8, mne->name, str, false);
            value &= 7;
        }
    }

    generate_branch(mne->opcode[0] | value, op2);
}
示例#26
0
/* parses: string "=" value */
static gboolean parse_result(struct gdb_mi_result *result, const gchar **p)
{
	result->var = parse_string(p);
	while (g_ascii_isspace(**p)) (*p)++;
	if (**p == '=')
	{
		(*p)++;
		while (g_ascii_isspace(**p)) (*p)++;
		result->val = parse_value(p);
	}
	return result->var && result->val;
}
示例#27
0
int parse_object(const char** input, JzonValue* output, bool root_object, JzonAllocator* allocator)
{
	if (current(input) == '{')
next(input);
	else if (!root_object)
		return -1;

		output->is_object = true;

		// Empty object.
		if (current(input) == '}')
		{
			output->size = 0;
			return 0;
		}

		Array object_values = { 0 };

		while (current(input))
		{
			JzonKeyValuePair* pair = (JzonKeyValuePair*)allocator->allocate(sizeof(JzonKeyValuePair));
			skip_whitespace(input);
			char* key = parse_keyname(input, allocator);
			skip_whitespace(input);

			if (key == NULL || current(input) != ':')
				return -1;

			next(input);
			JzonValue* value = (JzonValue*)allocator->allocate(sizeof(JzonValue));
			memset(value, 0, sizeof(JzonValue));
			int error = parse_value(input, value, allocator);

			if (error != 0)
				return error;

			pair->key = key;
			pair->key_hash = hash_str(key);
			pair->value = value;
			arr_insert(&object_values, pair, find_object_pair_insertion_index((JzonKeyValuePair**)object_values.arr, object_values.size, pair->key_hash), allocator);
			skip_whitespace(input);

			if (current(input) == '}')
			{
				next(input);
				break;
			}
		}

		output->size = object_values.size;
		output->object_values = (JzonKeyValuePair**)object_values.arr;
		return 0;
}
示例#28
0
/* Parse all the labels for the VAR_CNT variables in VARS and add
   the specified labels to those variables.  */
static int
get_label (struct lexer *lexer, struct variable **vars, size_t var_cnt,
           const char *dict_encoding)
{
  /* Parse all the labels and add them to the variables. */
  do
    {
      enum { MAX_LABEL_LEN = 255 };
      int width = var_get_width (vars[0]);
      union value value;
      struct string label;
      size_t trunc_len;
      size_t i;

      /* Set value. */
      value_init (&value, width);
      if (!parse_value (lexer, &value, vars[0]))
        {
          value_destroy (&value, width);
          return 0;
        }
      lex_match (lexer, T_COMMA);

      /* Set label. */
      if (lex_token (lexer) != T_ID && !lex_force_string (lexer))
        {
          value_destroy (&value, width);
          return 0;
        }

      ds_init_substring (&label, lex_tokss (lexer));

      trunc_len = utf8_encoding_trunc_len (ds_cstr (&label), dict_encoding,
                                           MAX_LABEL_LEN);
      if (ds_length (&label) > trunc_len)
	{
	  msg (SW, _("Truncating value label to %d bytes."), MAX_LABEL_LEN);
	  ds_truncate (&label, trunc_len);
	}

      for (i = 0; i < var_cnt; i++)
        var_replace_value_label (vars[i], &value, ds_cstr (&label));

      ds_destroy (&label);
      value_destroy (&value, width);

      lex_get (lexer);
      lex_match (lexer, T_COMMA);
    }
  while (lex_token (lexer) != T_SLASH && lex_token (lexer) != T_ENDCMD);

  return 1;
}
示例#29
0
bool t_cuesheet_index_list::from_infos(file_info const & p_in,double p_base)
{
	double pregap;
	bool found = false;
	if (!parse_value(p_in.info_get("pregap"),pregap)) pregap = 0;
	else found = true;
	m_positions[0] = p_base - pregap;
	m_positions[1] = p_base;
	for(unsigned n=2;n<count;n++)
	{
		char namebuffer[16];
		sprintf_s(namebuffer,"index %02u",n);
		double temp;
		if (parse_value(p_in.info_get(namebuffer),temp)) {
			m_positions[n] = temp + p_base; found = true;
		} else {
			m_positions[n] = 0;
		}
	}
	return found;	
}
示例#30
0
static int
parse_pair(heim_dict_t dict, struct parse_ctx *ctx)
{
    heim_string_t key;
    heim_object_t value;

    if (white_spaces(ctx))
	return -1;

    if (*ctx->p == '}')
	return 0;

    key = parse_string(ctx);
    if (key == NULL)
	return -1;

    if (white_spaces(ctx))
	return -1;

    if (*ctx->p != ':') {
	heim_release(key);
	return -1;
    }

    ctx->p += 1;

    if (white_spaces(ctx)) {
	heim_release(key);
	return -1;
    }

    value = parse_value(ctx);
    if (value == NULL) {
	heim_release(key);
	return -1;
    }
    heim_dict_set_value(dict, key, value);
    heim_release(key);
    heim_release(value);

    if (white_spaces(ctx))
	return -1;

    if (*ctx->p == '}') {
	ctx->p++;
	return 0;
    } else if (*ctx->p == ',') {
	ctx->p++;
	return 1;
    }
    return -1;
}