bool dictionary::initdict(FILE * fpin) { if(fpin) { return readStrings(fpin) && readLeaves(fpin) && readNodes(fpin); } return false; }
// Reads the input file into memory returning 1 if it // was read unsuccessfully, otherwise 0. DataSetInitStatus readFile(char* fileName) { DataSetInitStatus status = DATA_SET_INIT_STATUS_SUCCESS; FILE *inputFilePtr; // Open the file and hold on to the pointer. inputFilePtr = fopen(fileName, "rb"); // If the file didn't open return -1. if (inputFilePtr == NULL) { return DATA_SET_INIT_STATUS_FILE_NOT_FOUND; } // Read the various data segments if the version is // one we can read. status = readVersion(inputFilePtr); if (status != DATA_SET_INIT_STATUS_SUCCESS) { fclose(inputFilePtr); return status; } status = readCopyright(inputFilePtr); if (status != DATA_SET_INIT_STATUS_SUCCESS) { fclose(inputFilePtr); return status; } status = readStrings(inputFilePtr); if (status != DATA_SET_INIT_STATUS_SUCCESS) { fclose(inputFilePtr); return status; } status = readProperties(inputFilePtr); if (status != DATA_SET_INIT_STATUS_SUCCESS) { fclose(inputFilePtr); return status; } status = readDevices(inputFilePtr); if (status != DATA_SET_INIT_STATUS_SUCCESS) { fclose(inputFilePtr); return status; } status = readLookupList(inputFilePtr); if (status != DATA_SET_INIT_STATUS_SUCCESS) { fclose(inputFilePtr); return status; } status = readNodes(inputFilePtr); if (status != DATA_SET_INIT_STATUS_SUCCESS) { fclose(inputFilePtr); return status; } fclose(inputFilePtr); return status; }
int TLKFile::init(int n) { if(n == -1) n = initstages; if((n > 0) && !inited[0] && readHeader()) return errcode; if((n > 1) && !inited[1] && readTable()) return errcode; if((n > 2) && !inited[2] && readStrings()) return errcode; if((n > 3) && !inited[3]) { close(); inited.set(3); } return errcode = 0; }
void Model_KotOR::load(ParserContext &ctx) { if (ctx.mdl->readUint32LE() != 0) throw Common::Exception("Unsupported KotOR ASCII MDL"); uint32 sizeModelData = ctx.mdl->readUint32LE(); uint32 sizeRawData = ctx.mdl->readUint32LE(); ctx.offModelData = 12; ctx.offRawData = ctx.offModelData + sizeModelData; ctx.mdl->skip(8); // Function pointers _name = Common::readStringFixed(*ctx.mdl, Common::kEncodingASCII, 32); uint32 nodeHeadPointer = ctx.mdl->readUint32LE(); uint32 nodeCount = ctx.mdl->readUint32LE(); ctx.mdl->skip(24 + 4); // Unknown + Reference count uint8 type = ctx.mdl->readByte(); ctx.mdl->skip(3 + 2); // Padding + Unknown uint8 classification = ctx.mdl->readByte(); uint8 fogged = ctx.mdl->readByte(); ctx.mdl->skip(4); // Unknown ctx.mdl->skip(12); // TODO: Animation Header Pointer Array ctx.mdl->skip(4); // Parent model pointer float boundingMin[3], boundingMax[3]; boundingMin[0] = ctx.mdl->readIEEEFloatLE(); boundingMin[1] = ctx.mdl->readIEEEFloatLE(); boundingMin[2] = ctx.mdl->readIEEEFloatLE(); boundingMax[0] = ctx.mdl->readIEEEFloatLE(); boundingMax[1] = ctx.mdl->readIEEEFloatLE(); boundingMax[2] = ctx.mdl->readIEEEFloatLE(); float radius = ctx.mdl->readIEEEFloatLE(); float scale = ctx.mdl->readIEEEFloatLE(); Common::UString superModelName = Common::readStringFixed(*ctx.mdl, Common::kEncodingASCII, 32); ctx.mdl->skip(4); // Root node pointer again ctx.mdl->skip(12); // Unknown uint32 nameOffset, nameCount; readArrayDef(*ctx.mdl, nameOffset, nameCount); std::vector<uint32> nameOffsets; readArray(*ctx.mdl, ctx.offModelData + nameOffset, nameCount, nameOffsets); readStrings(*ctx.mdl, nameOffsets, ctx.offModelData, ctx.names); newState(ctx); ModelNode_KotOR *rootNode = new ModelNode_KotOR(*this); ctx.nodes.push_back(rootNode); ctx.mdl->seek(ctx.offModelData + nodeHeadPointer); rootNode->load(ctx); addState(ctx); }
static void execute (const char *msg) { struct sockaddr_un remote; socklen_t len; unsigned int s, s2; std::string path = getenv ("HOME"); path += "/.config/mazinger/launcher"; if (path.length() >= sizeof remote.sun_path) { alert ("Cannot create socket %s. Length exceeds limit (%d)", path.c_str(), sizeof remote.sun_path); return; } // Crear socket s = socket(AF_UNIX, SOCK_STREAM, 0); if (s >= 0) { remote.sun_family = AF_UNIX; /* local is declared before socket() ^ */ strcpy(remote.sun_path, path.c_str()); len = strlen(remote.sun_path) + sizeof(remote.sun_family); if (connect (s, (struct sockaddr *)&remote, len) == 0) { send (s, msg, strlen(msg)+1, 0); std::string type; std::string content; readStrings(s, type, content); printf ("Type =%s\nContent=%s\n", type.c_str(), content.c_str()); if ( type == "ERROR") { alert ("Error: %s", content.c_str()); } else if (type == "URL") { close (s); if (fork () == 0) { execlp("xdg-open", "xdg-open", content.c_str(), NULL); } } else if (type == "MZN") { MZNEvaluateJS(content.c_str()); } else { char ach[20]; std::string ext = type; std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower); std::string file ; file = "/var/tmp/mazinger"; file += msg; file += "."; file += ext; printf ("Creando archivo %s\n", file.c_str()); FILE *f = fopen (file.c_str(), "w"); if (f != NULL) { fwrite(content.c_str(), content.length(), 1, f); fclose (f); if (fork () == 0) { execlp("xdg-open", "xdg-open", file.c_str(), NULL); } } } } else { alert ("Cannot locate mazinger session manager"); } close (s); } }