static void GetApplication( ProcessNode *node) { int i; VALUE obj; ENTER_FUNC; if ( node->mcprec != NULL ) { obj = rb_hash_aref(node_info,rb_str_new2("mcp")); if (!NIL_P(obj)) { JSON_UnPackValue(RubyConv,StringValueCStr(obj),node->mcprec->value); } } if ( node->linkrec != NULL ) { obj = rb_hash_aref(node_info,rb_str_new2("link")); if (!NIL_P(obj)) { JSON_UnPackValue(RubyConv,StringValueCStr(obj),node->linkrec->value); } } if ( node->sparec != NULL ) { obj = rb_hash_aref(node_info,rb_str_new2("spa")); if (!NIL_P(obj)) { JSON_UnPackValue(RubyConv,StringValueCStr(obj),node->sparec->value); } } for ( i = 0; i < node->cWindow ; i ++ ) { if ( node->scrrec[i] != NULL ) { obj = rb_hash_aref(node_info,rb_str_new2(node->scrrec[i]->name)); if (!NIL_P(obj)) { JSON_UnPackValue(RubyConv,StringValueCStr(obj),node->scrrec[i]->value); } } } LEAVE_FUNC; }
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; }