Beispiel #1
0
static	void
PutApplication(
	ProcessNode	*node)
{
	char *buf;
	int i;

ENTER_FUNC;
	rb_funcall(node_info,rb_intern("clear"),0);
	if		(  node->mcprec  !=  NULL  ) {
		buf = xmalloc(JSON_SizeValue(RubyConv,node->mcprec->value));
		JSON_PackValue(RubyConv,buf,node->mcprec->value);
		rb_hash_aset(node_info,rb_str_new2("mcp"),rb_str_new2(buf));
		xfree(buf);
	}
	if		(  node->linkrec  !=  NULL  ) {
		buf = xmalloc(JSON_SizeValue(RubyConv,node->linkrec->value));
		JSON_PackValue(RubyConv,buf,node->linkrec->value);
		rb_hash_aset(node_info,rb_str_new2("link"),rb_str_new2(buf));
		xfree(buf);
	}
	if		(  node->sparec  !=  NULL  ) {
		buf = xmalloc(JSON_SizeValue(RubyConv,node->sparec->value));
		JSON_PackValue(RubyConv,buf,node->sparec->value);
		rb_hash_aset(node_info,rb_str_new2("spa"),rb_str_new2(buf));
		xfree(buf);
	}
	for	( i = 0; i < node->cWindow ; i ++ ) {
		if		(  node->scrrec[i]  !=  NULL  ) {
			buf = xmalloc(JSON_SizeValue(RubyConv,node->scrrec[i]->value));
			JSON_PackValue(RubyConv,buf,node->scrrec[i]->value);
			rb_hash_aset(node_info,rb_str_new2(node->scrrec[i]->name),rb_str_new2(buf));
			xfree(buf);
		}
	}
LEAVE_FUNC;
}
Beispiel #2
0
int main(int argc, char *argv[]) {
  ValueStruct *value, *v;
  size_t size;
  char *buf;

  RecParserInit();
  value = RecParseValueMem(recdef, NULL);

  InitializeValue(value);
  v = GetRecordItem(value, "command");
  SetValueString(v, "a\"a\\a/a\ba\fa\na\ra\ta", NULL);
  v = GetItemLongName(value, "record1[0].col1");
  SetValueString(v, "bbbb", NULL);
  v = GetItemLongName(value, "record1[0].record2.col21");
  SetValueString(v, "cccc", NULL);
  v = GetItemLongName(value, "int1");
  SetValueInteger(v, 10);
  v = GetItemLongName(value, "int2");
  SetValueInteger(v, 20);
  v = GetItemLongName(value, "double1");
  SetValueFloat(v, -3.2);

  fprintf(stderr, "\n---- JSON_PackValue\n");
  size = JSON_SizeValue(NULL, value);
  fprintf(stderr, "size:%ld\n", size);
  buf = malloc(size + 1);
  memset(buf, 0, size + 1);
  JSON_PackValue(NULL, buf, value);
  fprintf(stderr, "[%s]\nsize:%ld\n", buf, strlen(buf));

  fprintf(stderr, "\n---- JSON_UnPackValue 1\n");
  JSON_UnPackValue(NULL, buf, value);
  DumpValueStruct(value);
  free(buf);

  fprintf(stderr, "\n---- JSON_UnPackValue 2\n");
  JSON_UnPackValue(NULL, "{\"int1\":1000,\"int2\":2000}", value);
  DumpValueStruct(value);

  /* ommit */
  fprintf(stderr, "\n-------------------\n");
  fprintf(stderr, "ommit\n");
  fprintf(stderr, "-------------------\n\n");

  InitializeValue(value);
  v = GetRecordItem(value, "command");
  SetValueString(v, "a\"a\\a/a\ba\fa\na\ra\ta", NULL);
  v = GetItemLongName(value, "record1[0].col1");
  SetValueString(v, "bbbb", NULL);
  v = GetItemLongName(value, "record1[0].record2.col21");
  SetValueString(v, "cccc", NULL);
  v = GetItemLongName(value, "int1");
  SetValueInteger(v, 10);
  v = GetItemLongName(value, "int2");
  SetValueInteger(v, 20);
  v = GetItemLongName(value, "record3[1].record4[1].vc41");
  SetValueString(v, "vc41", NULL);

  fprintf(stderr, "\n---- JSON_PackValueOmmit\n");
  size = JSON_SizeValueOmmit(NULL, value);
  fprintf(stderr, "size:%ld\n", size);
  buf = malloc(size + 1);
  memset(buf, 0, size + 1);
  JSON_PackValueOmmit(NULL, buf, value);
  fprintf(stderr, "size:%ld [%s]\n", strlen(buf), buf);
  free(buf);

  fprintf(stderr, "\n---- JSON_UnPackValueOmmit\n");
  JSON_UnPackValueOmmit(NULL, "{\"int1\":1000,\"int2\":2000}", value);
  DumpValueStruct(value);

  fprintf(stderr, "\n---- JSON_UnPackValueOmmit 2\n");
  JSON_UnPackValueOmmit(
      NULL,
      "{\"int1\":1234,\"int2\":5678,\"bool1\":false,\"double1\":3.141592}",
      value);
  DumpValueStruct(value);

  fprintf(stderr, "\n---- JSON_UnPackValueOmmit 3\n");
  JSON_UnPackValueOmmit(
      NULL,
      "{\"int1\":1000,\"command\":\"moge\",\"record1\":[{\"col1\":\"muge\","
      "\"record2\":{\"col21\":\"gage\"}},{},{\"col2\":\"nuge\"}],\"record3\":[{"
      "},{\"record4\":[{},{\"vc41\":\"vc41\"}]}]}",
      value);
  DumpValueStruct(value);

  InitializeValue(value);
  fprintf(stderr, "\n---- test\n");
  JSON_UnPackValueOmmit(NULL,
                        "{\"int1\":10,\"int0\":[0,1,2,3,0,5,0,6],\"bool1\":"
                        "false,\"arg1\":\"hogehoge\"}",
                        value);
  size = JSON_SizeValueOmmit(NULL, value);
  fprintf(stderr, "size:%ld\n", size);
  buf = malloc(size);
  memset(buf, 0, size);
  JSON_PackValueOmmit(NULL, buf, value);
  fprintf(stderr, "size:%d %s\n", (int)strlen(buf), buf);
  free(buf);

  fprintf(stderr, "\n\n\n\n\n\n---- JSON_PackValueOmmitString\n");

  InitializeValue(value);
  v = GetRecordItem(value, "command");
  SetValueString(v, "a\"a\\a/a\ba\fa\na\ra\ta", NULL);
  v = GetItemLongName(value, "record1[0].col1");
  SetValueString(v, "bbbb", NULL);
#if 0
  v = GetItemLongName(value,"record1[0].record2.col21");
  SetValueString(v,"cccc",NULL);
#endif
  v = GetItemLongName(value, "int1");
  SetValueInteger(v, 10);
  v = GetItemLongName(value, "int2");
  SetValueInteger(v, 20);
  v = GetItemLongName(value, "record3[1].record4[1].vc41");
  SetValueString(v, "vc41", NULL);

  DumpValueStruct(value);

  size = JSON_SizeValueOmmitString(NULL, value);
  fprintf(stderr, "size:%ld\n", size);
  buf = malloc(size + 1);
  memset(buf, 0, size + 1);
  JSON_PackValueOmmitString(NULL, buf, value);
  fprintf(stderr, "size:%ld [%s]\n", strlen(buf), buf);
  free(buf);

  return 0;
}