void print(json_value *value, int ident = 0) { IDENT(ident); if (value->name) printf("\"%s\" = ", value->name); switch(value->type) { case JSON_NULL: printf("null\n"); break; case JSON_OBJECT: case JSON_ARRAY: printf(value->type == JSON_OBJECT ? "{\n" : "[\n"); for (json_value *it = value->first_child; it; it = it->next_sibling) { print(it, ident + 1); } IDENT(ident); printf(value->type == JSON_OBJECT ? "}\n" : "]\n"); break; case JSON_STRING: printf("\"%s\"\n", value->string_value); break; case JSON_INT: printf("%d\n", value->int_value); break; case JSON_FLOAT: printf("%f\n", value->float_value); break; case JSON_BOOL: printf(value->int_value ? "true\n" : "false\n"); break; } }
static void parse_array(int indent, json_obj_t * array){ if(array->type != JSON_ARRAY){ printf("%d: unexpected type %d\n", __LINE__, array->type); return; } json_obj_t * item = array->children; while(item != NULL){ switch(item->type){ case JSON_STRING: printf("%*s%.*s\n", IDENT(indent), "", item->length, item->str); break; case JSON_PRIMITIVE: printf("%*s%.*s\n", IDENT(indent), "", item->length, item->str); break; case JSON_OBJECT: parse_object(indent, item); break; default: printf("%d: unexpected type %d in array\n", __LINE__, item->type); return; } item = item->next_sibling; } }
bool CG3DBinaryLoader::ReadTable() { if (m_CurrFP->m_Ident != IDENT('T','A','B','L')) return Error("File does not have correct table section"); m_CurrTable = new BinaryTable(); m_CurrFile->AddRef(); m_CurrTable->m_Files.push_back(m_CurrFile); m_CurrTable->m_Header.m_Ident = m_CurrFP->ReadUInt16(); m_CurrTable->m_Header.m_Num = m_CurrFP->ReadUInt16(); m_CurrTable->m_Header.m_Flags = (BinaryTableFlags)m_CurrFP->ReadUInt32(); m_CurrTable->m_Entries = new BinaryEntry[m_CurrTable->m_Header.m_Num]; for (int i=0; i<m_CurrTable->m_Header.m_Num; i++) { m_CurrTable->m_Entries[i].m_FileOffset = m_CurrFP->ReadUInt32(); m_CurrTable->m_Entries[i].m_File = m_CurrFile; m_CurrTable->m_Entries[i].m_Ptr = NULL; } std::vector<std::string> strings; if ((m_CurrTable->m_Header.m_Flags & BINARY_HAS_EXPORT) == BINARY_HAS_EXPORT) { ReadStringTable(strings, m_CurrTable->m_Header.m_Num); } s_Mgr->UpdateTable(m_CurrTable, strings); return true; }
static void parse_key_value(int indent, json_obj_t * kv){ if(kv->type != JSON_KEY_VALUE_PAIR){ printf("%d: unexpected type %d\n", __LINE__, kv->type); return; } json_obj_t * key = kv->children; json_obj_t * value = kv->children->next_sibling; printf("%*s%.*s",IDENT(indent), "", key->length, key->str); switch(value->type){ case JSON_STRING: printf(" -> %.*s\n", value->length, value->str); break; case JSON_PRIMITIVE: printf(" -> %.*s\n", value->length, value->str); break; case JSON_OBJECT: printf("\n"); parse_object(indent + 1, value); printf("\n"); break; case JSON_ARRAY: printf("\n"); parse_array(indent + 1, value); printf("\n"); break; default: printf("%d: unexpected type %d in array\n", __LINE__, value->type); return; } }
void pretty_print(env_t *env, VALUE v, int i) { if (VALUE_IS_ERROR(v)) { printf("<error>\n"); } else if (IS_LIST(v)) { printf("(\n"); int j; for (j = 0; j < list_len(v); j++) { indent(i + 1); pretty_print(env, list_get(v, j), i + 1); } indent(i); printf(")\n"); } else { if (VALUE_IS_INT(v)) { printf("%lld\n", INTVAL(v)); } else if (VALUE_IS_BOOL(v)) { printf("#%c\n", BOOLVAL(v) ? 't' : 'f'); } else if (VALUE_IS_NIL(v)) { printf("#nil\n"); } else if (VALUE_IS_IDENT(v)) { printf("%s\n", intern_table_get_str(&env->intern, IDENT(v))); } else if (VALUE_IS_ATOM(v)) { printf(":%s\n", intern_table_get_str(&env->intern, ATOM(v))); } else if (IS_STRING(v)) { printf("\"%s\"\n", string_chars(v)); } else { printf("<unknown %p>\n", v); } } }
CG3DBinaryLoader::CG3DBinaryLoader(CG3DGraphics* graphics) : m_CurrFP(NULL), m_Graphics(graphics) { if (s_Mgr == NULL) { s_Mgr = new CG3DBinaryManager(); s_Mgr->SetWeakPtr((CG3DRefCount**)&s_Mgr); } s_Mgr->AddRef(); AddHandler(IDENT('T','E','X','T'),new TextureHandler()); AddHandler(IDENT('E','F','C','T'),new EffectHandler()); AddHandler(IDENT('M','A','T',' '),new MaterialHandler()); AddHandler(IDENT('M','O','D','L'),new ModelHandler()); AddHandler(IDENT('S','C','E','N'),new SceneHandler()); AddHandler(IDENT('G','O','B',' '),new GOBHandler()); AddModuleHandler("scene.simple",new SimpleSceneHandler()); AddModuleHandler("dummy",new DummyModuleHandler()); AddModuleHandler("model",new ModelModuleHandler()); AddModuleHandler("camera",new CameraModuleHandler()); AddModuleHandler("frameM",new FrameMModuleHandler()); AddModuleHandler("framePRS",new FramePRSModuleHandler()); AddModuleHandler("framePQS",new FramePQSModuleHandler()); AddModuleHandler("frameIdent",new FrameIdentModuleHandler()); }
bool CG3DBinaryLoader::ReadImport() { OpenFile(m_CurrFile, m_CurrFile->m_Header.m_Import); if (m_CurrFP->m_Ident != IDENT('I','M','P','T')) return Error("File does not have correct import section"); int num = m_CurrFP->ReadInt32(); ReadStringTable(m_CurrFile->m_Import, num); CloseFile(); return true; }
bool CG3DBinaryLoader::InitFile(const char* filename) { m_CurrFile = new BinaryFile(filename); OpenFile(m_CurrFile, 0); if (!m_CurrFP->IsLoaded()) return Error("Cannot find file"); if (m_CurrFP->m_Ident == IDENT('W','D','3','G')) return Error("This platform is big endian, contact the developers!"); else if (m_CurrFP->m_Ident != IDENT('G','3','D','W')) return Error("File does not have the correct header"); m_CurrFile->m_Header.m_Version = m_CurrFP->ReadUInt16(); m_CurrFile->m_Header.m_Num = m_CurrFP->ReadUInt16(); m_CurrFile->m_Header.m_Table = m_CurrFP->ReadUInt32(); m_CurrFile->m_Header.m_Import = m_CurrFP->ReadUInt32(); m_CurrFile->m_Header.m_Reloc = m_CurrFP->ReadUInt32(); if (m_CurrFile->m_Header.m_Import != 0) if (!ReadImport()) return false; OpenFile(m_CurrFile, m_CurrFile->m_Header.m_Table); for (int i=0; i<m_CurrFile->m_Header.m_Num; i++) { if (!ReadTable()) return false; if (!NextFile()) return Error("failed to find all tables"); } CloseFile(); m_CurrFile->Release(); return true; }