void SaveISISNexus::sample() { NXmakegroup(handle, "sample", "NXsample"); NXopengroup(handle, "sample", "NXsample"); saveChar("name", m_isisRaw->spb.e_name, 40); saveFloat("height", &m_isisRaw->spb.e_height, 1); saveFloat("width", &m_isisRaw->spb.e_width, 1); saveFloat("thickness", &m_isisRaw->spb.e_thick, 1); saveString("id", " "); float tmp(0.0); saveFloat("distance", &tmp, 1); std::string shape[] = {"cylinder", "flat plate", "HRPD slab", "unknown"}; int i = m_isisRaw->spb.e_geom - 1; if (i < 0 || i > 3) i = 3; saveString("shape", shape[i]); std::string type[] = {"sample+can", "empty can", "vanadium", "absorber", "nothing", "sample, no can", "unknown"}; i = m_isisRaw->spb.e_type - 1; if (i < 0 || i > 6) i = 6; saveString("type", type[i]); NXclosegroup(handle); // sample }
void SaveISISNexus::dae() { NXmakegroup(handle, "dae", "IXdae"); NXopengroup(handle, "dae", "IXdae"); saveString("detector_table_file", " "); saveString("spectra_table_file", " "); saveString("wiring_table_file", " "); saveIntOpen("period_index", m_isisRaw->t_pmap, nper); NXgetdataID(handle, &period_index_link); close(); NXmakegroup(handle, "time_channels_1", "IXtime_channels"); NXopengroup(handle, "time_channels_1", "IXtime_channels"); boost::scoped_array<float> timeChannels(new float[ntc + 1]); m_isisRaw->getTimeChannels(timeChannels.get(), ntc + 1); saveFloatOpen("time_of_flight", timeChannels.get(), ntc + 1); putAttr("axis", 1); putAttr("primary", 1); putAttr("units", "microseconds"); NXgetdataID(handle, &time_of_flight_link); close(); saveIntOpen("time_of_flight_raw", m_isisRaw->t_tcb1, ntc + 1); putAttr("units", "pulses"); putAttr("frequency", "32 MHz"); NXgetdataID(handle, &time_of_flight_raw_link); close(); NXclosegroup(handle); // time_channels_1 NXclosegroup(handle); // dae }
void saveGame(string sav = savename) { if(!P.arms) { deleteGame(); return; } savefile = fopen(sav.c_str(), "wb"); error = !savefile; if(error) return; P.saveformat = SAVEFORMAT; P.version = VERSION; stats.whistSize = size(pinfo.whist); P.stairqueue = size(stairqueue); save(P); save(stats); save(playerpos); save(topx); save(topy); saveString(pinfo.charname); saveString(pinfo.username); if(P.twinsNamed) saveString(pinfo.twin[0]), saveString(pinfo.twin[1]); int set = 0; for(int i=0; i<MAXARMS; i++) if(wpn[i]) set |= (1<<i); save(set); for(int i=0; i<MAXARMS; i++) if(wpn[i]) wpn[i]->csave(); if(true) { int trollsize = size(pinfo.trollwpn); save(trollsize); for(int i=0; i<trollsize; i++) save(pinfo.trollkey[i]); for(int i=0; i<trollsize; i++) pinfo.trollwpn[i]->csave(); } for(int i=0; i<P.stairqueue; i++) stairqueue[i]->csave(); for(int i=0; i<stats.whistSize; i++) save(pinfo.whistAt[i]), pinfo.whist[i]->csave(); for(int y=0; y<SY; y++) for(int x=0; x<SX; x++) { cell& c(M.m[y][x]); #define ITEMMASK (1<<24) if(c.it) c.mushrooms |= ITEMMASK; save(c.type), save(c.mushrooms), save(c.dead), save(c.explored); if(c.it) c.it->csave(); c.mushrooms &= ~ITEMMASK; } int32_t i = hydras.size(); save(i); for(int i=0; i<size(hydras); i++) hydras[i]->csave(); fclose(savefile); }
void ServerLoginChallengePacket::serializeInternal(char *buffer) const { char *buf = buffer; saveString(buf, m_salt); buf += 4 + m_salt.length(); saveString(buf, m_random); }
/** * Write instrument/source group */ void SaveISISNexus::source() { NXmakegroup(handle, "source", "NXsource"); NXopengroup(handle, "source", "NXsource"); saveString("name", "ISIS"); saveString("probe", "neutrons"); saveString("type", "Pulsed Neutron Source"); NXclosegroup(handle); }
// write id:value, unless value is empty, in which case we erase the id void writeMacro(char *id) { eraseentry(id); // we need to know the macro value length to allocate space for it // we don't realistically have enough buffer space handy to parse it into // so this is a two-pass operation: first we measure the text, then on // the second pass we stuff it into the eeprom // // measure length of macro value // we get here with inchar = first char of macro and fetchptr one past that // char *fetchmark = --fetchptr; // back up and mark first char of macro text primec(); // re-prime expval = 0; // zero the count parsestring(&countByte); // now expval is the macro value length if (!expval) return; // empty string? we're done int addr = findhole(strlen(id) + expval + 2); // longjmps on fail if (addr >= 0) { saveString(addr, id); // reset parse context fetchptr = fetchmark; primec(); expval = addr + strlen(id) + 1; // set up address for saveByte parsestring(&saveByte); saveByte(0); } }
VECiphertext Buyer::makeEscrow() { // now set up the verifiable encryption VEProver prover(pk); return prover.verifiableEncrypt(coin.getEndorsementCom(), endorsement, coin.getCashGroup(), saveString(*contract), pk->hashAlg, stat); }
FEMessage* FEInitiator::barter(const vector<EncBuffer*>& ctextR, const vector<hash_t>& ptHashR, const vector<hash_t>& ptHashI) { if (ctextR.empty()) throw CashException(CashException::CE_FE_ERROR, "[FEInitiator::barter] No responder ciphertext given"); if (ptHashR.empty()) throw CashException(CashException::CE_FE_ERROR, "[FEInitiator::barter] No initiator plaintext hash given"); ctextB = ctextR; // create contract createContract(); // compute hashes hash_t ptHashMerkleI = Hash::hash(ptHashI, verifiablePK->hashAlg, verifiablePK->hashKey, Hash::TYPE_MERKLE); hash_t ptHashMerkleR = Hash::hash(ptHashR, verifiablePK->hashAlg, verifiablePK->hashKey, Hash::TYPE_MERKLE); hash_t ctHashMerkleI = Hash::hash(ctextA, verifiablePK->hashAlg, verifiablePK->hashKey, Hash::TYPE_MERKLE); hash_t ctHashMerkleR = Hash::hash(ctextB, verifiablePK->hashAlg, verifiablePK->hashKey, Hash::TYPE_MERKLE); // set the contract contract->setPTHashA(ptHashMerkleI); contract->setCTHashA(ctHashMerkleI); contract->setPTHashB(ptHashMerkleR); contract->setCTHashB(ctHashMerkleR); contract->setEncAlgA(ctextA[0]->encAlg); contract->setEncAlgB(ctextB[0]->encAlg); contract->setPTHashBlocksB(ptHashR.size()); contract->setCTHashBlocksB(ctextR.size()); // optimization: if all ciphertexts have the same key, just output one key // shortcut: if two ciphertexts have the same key, assume all have // the same key vector<ZZ> keys; if (ctextA.size() > 1 && ctextA[0]->key == ctextA[1]->key) keys.push_back(ZZFromBytes(ctextA[0]->key)); else { for (unsigned i = 0; i < ctextA.size(); i++) { keys.push_back(ZZFromBytes(ctextA[i]->key)); } } // now set up signature and escrow VEProver prover(regularPK); // label is the multicontract string label = saveString(*contract); vector<ZZ> escrow = prover.encrypt(keys, label, regularPK->hashAlg, stat); // need to sign on the escrow using our signature key string escrowStr = CommonFunctions::vecToString(escrow); /* TODO: When we use RSA enc as escrow, we should also sign the contract */ string sig = Signature::sign(*signKey, escrowStr, regularPK->hashAlg); // now output the escrow, signature, and contract (label) return new FEMessage(escrow, sig, *contract); }
void saveLPOModel( std::ostream & os, const std::shared_ptr<LPOModel> & p ) { std::string name = modelName( p ); if(!name.size()) throw std::invalid_argument("Failed to save LPOModel!"); saveString( os, name ); p->save( os ); }
bool CCDictionarySaver::saveDictionary(CCDictionary* pDict, xmlNodePtr node) { do { xmlNodePtr dict_node = xmlNewNode(NULL, DICT_NODE_DICT); CC_BREAK_IF(!dict_node); CC_BREAK_IF(!xmlAddChild(node, dict_node)); CCDictElement* pElem; CCDICT_FOREACH(pDict, pElem) { saveKey(pElem->getStrKey(), dict_node); CCObject* obj = pElem->getObject(); if (dynamic_cast<CCString*>(obj)) { CCString* s = dynamic_cast<CCString*>(obj); CC_BREAK_IF(!saveString(s->getCString(), dict_node)); } else if (dynamic_cast<CCDictionary*>(obj)) { CC_BREAK_IF(!saveDictionary(dynamic_cast<CCDictionary*>(obj), dict_node)); } else if (dynamic_cast<CCArray*>(obj)) { CC_BREAK_IF(!saveArray(dynamic_cast<CCArray*>(obj), dict_node)); } } return true; } while (false);
bool CCDictionarySaver::saveArray(CCArray* pArray, xmlNodePtr node) { do { xmlNodePtr array_node = xmlNewNode(NULL, DICT_NODE_ARRAY); CC_BREAK_IF(!array_node); CC_BREAK_IF(!xmlAddChild(node, array_node)); CCObject* obj; CCARRAY_FOREACH(pArray, obj) { if (dynamic_cast<CCString*>(obj)) { CCString* s = dynamic_cast<CCString*>(obj); CC_BREAK_IF(!saveString(s->getCString(), array_node)); } else if (dynamic_cast<CCDictionary*>(obj)) { CC_BREAK_IF(!saveDictionary(dynamic_cast<CCDictionary*>(obj), array_node)); } else if (dynamic_cast<CCArray*>(obj)) { CC_BREAK_IF(!saveArray(dynamic_cast<CCArray*>(obj), array_node)); } } return true; } while (false); return false; }
// IObjectSerializable STDMETHODIMP CPDPath::Serialize(/*[in]*/ IArchive* ar, IArchiveElement* node) { _bstr_t d = saveString(); node->putData(_variant_t(d)); return S_OK; }
void Bank::run(){ acceptor = new TCPAcceptor(10000, "127.0.0.1"); if (acceptor->start() == 0) { while (1) { std::cout<<"Bank is open"<<std::endl; stream = acceptor->accept(); if (stream != NULL) { /* This is exactly what it is done in the test file of cashlib. For more information, see cashlib documentation */ while(!keyReceived || !commitReceived){ mr->readMsg(stream); } int walletSize = 100, coinDenom = 512; CommonFunctions::setZKPDir("../cashlib/src/ZKP/examples"); BankWithdrawTool* bwTool = bankTool->getWithdrawTool(peerKey, walletSize, coinDenom); bwTool->computeFullCommitment(peerCommitment); ZZ bankPart = bwTool->getBankContribution(); string bps = saveString(bankPart); message* mbps = new message(9, bps); mbps->writeMsg(stream); while(!idpReceived || !clpReceived){ mr->readMsg(stream); } ProofMessage* pm = bwTool->sign(&idProof, &clProof); string ps = saveString(pm); message* mps = new message(12, ps); mps->writeMsg(stream); } stream = NULL; keyReceived = false; commitReceived = false; idpReceived = false; clpReceived = false; } } }
Magic3D::XMLElement* Magic3D::Object::save(XMLElement* root) { if (root) { saveString(root, M3D_OBJECT_XML_NAME, getName()); saveString(root, M3D_OBJECT_XML_SCRIPT, getScript()); saveString(root, M3D_OBJECT_XML_PARENT, getParent() ? getParent()->getName().c_str() : M3D_XML_NULL); saveString(root, M3D_OBJECT_XML_PARENT_BONE, getParentBone() ? getParentBone()->getName().c_str() : M3D_XML_NULL); saveBool(root, M3D_OBJECT_XML_PARENT_POSITION, isParentPosition()); saveBool(root, M3D_OBJECT_XML_PARENT_ROTATION, isParentRotation()); saveBool(root, M3D_OBJECT_XML_PARENT_SCALE, isParentScale()); saveInt(root, M3D_OBJECT_XML_RENDER, getRender()); saveInt(root, M3D_OBJECT_XML_TYPE, getType()); saveInt(root, M3D_OBJECT_XML_FLAG, getFlag()); saveInt(root, M3D_OBJECT_XML_BILLBOARD, getBillboard()); saveBool(root, M3D_OBJECT_XML_ENABLED, isEnabled()); saveBool(root, M3D_OBJECT_XML_VISIBLE, isVisible()); saveBool(root, M3D_OBJECT_XML_ZORDER, isZOrder()); saveBool(root, M3D_OBJECT_XML_PICK, isPickable()); saveVector3(root, M3D_OBJECT_XML_POSITION, getPosition()); saveVector4(root, M3D_OBJECT_XML_ROTATION, Vector4(getRotation())); saveVector3(root, M3D_OBJECT_XML_SCALE, getScale()); saveBool(root, M3D_OBJECT_XML_SCRIPTED, isScripted()); std::vector<Mesh*>::const_iterator it_m = meshes.begin(); while (it_m != meshes.end()) { Mesh* mesh = *it_m++; XMLElement* meshtXML = root->GetDocument()->NewElement( M3D_MESH_XML ); meshtXML->SetAttribute("materials", (int)mesh->getMaterials()->size()); root->LinkEndChild( meshtXML ); mesh->save(meshtXML); } PhysicsObject::save(root); } return root; }
Magic3D::XMLElement* Magic3D::TextData::save(XMLElement* root) { if (root) { saveString(root, M3D_TEXT_XML_TEXT, text); if (font) { saveString(root, M3D_TEXT_XML_FONT, font->getName()); } else { saveString(root, M3D_TEXT_XML_FONT, M3D_DEFAULT_FONT); } saveInt(root, M3D_TEXT_XML_ALIGNMENT, textAlignment); saveColorRGBA(root, M3D_TEXT_XML_COLOR, textColor); saveFloat(root, M3D_TEXT_XML_SIZE, textSize); } return root; }
Magic3D::XMLElement* Magic3D::ObjectInstance::save(XMLElement* root) { if (root) { saveString(root, M3D_OBJECT_INSTANCE_NAME, instance ? instance->getName() : M3D_XML_NULL); saveBool(root, M3D_OBJECT_INSTANCE_SPAWN, spawnOnLoad); Object::save(root); } return root; }
int Fujimap::save(const char* index){ ofstream ofs(index); if (!ofs){ what_ << "cannot open " << index << endl; return -1; } uint64_t code2valSize = static_cast<uint64_t>(code2val_.size()); ofs.write((const char*)(&code2valSize), sizeof(uint64_t)); for (uint64_t i = 0; i < code2valSize; ++i){ saveString(code2val_[i], ofs); } ofs.write((const char*)(&seed_), sizeof(seed_)); ofs.write((const char*)(&fpLen_), sizeof(fpLen_)); ofs.write((const char*)(&tmpN_), sizeof(tmpN_)); uint64_t tmpEdgeSize = static_cast<uint64_t>(tmpEdges_.size()); ofs.write((const char*)(&tmpEdgeSize), sizeof(tmpEdgeSize)); for (map<string, uint64_t>::const_iterator it = tmpEdges_.begin(); it != tmpEdges_.end(); ++it){ saveString(it->first, ofs); ofs.write((const char*)(&it->second), sizeof(it->second)); } uint64_t fbs_Size = static_cast<uint64_t>(fbs_.size()); ofs.write((const char*)(&fbs_Size), sizeof(fbs_Size)); for (size_t i = 0; i < fbs_.size(); ++i){ uint64_t fbs_InSize = fbs_[i].size(); ofs.write((const char*)(&fbs_InSize), sizeof(fbs_InSize)); for (size_t j = 0; j < fbs_[i].size(); ++j){ fbs_[i][j].save(ofs); } } if (!ofs){ what_ << "write error " << index << endl; return -1; } return 0; }
macroTableEntryType * buildMacroTableEntry(stringType *name) { macroTableEntryType *result; result = typeAlloc(macroTableEntryType); result->macroName = saveString(name); result->nextMacro = NULL; result->arguments = NULL; result->body = NULL; return(result); }
int lexStringConstant(void) { char *stringPtr; char c; stringPtr = stringBuffer; while (((c = getStringCharacter(input))!='"' && c!='\n' && c!=EOF) || escaped) *stringPtr++ = c; *stringPtr = '\0'; if (c=='\n' || c==EOF) error(UNCLOSED_STRING_CONSTANT_ERROR); yylval = (int)saveString(stringBuffer); return(TextString); }
/////////////////////////////////////////////////// // operate the message void operator() (MsgPair& m) { if (m.second.isACK()) { if (m.second.isBinary()) ch.log("Binary message ["+ m.second.fileName() +"] is acknowledged by receiver!"); else ch.log("String message is acknowledged by receiver!"); } else if (m.second.isBinary()) { std::string path = saveBinary(m.second); ch.log("File ["+ m.second.fileName() +"] is received and saved to ["+ path +"]!"); } else { std::string str = saveString(m.second); ch.log("String ["+ str +"] is received!"); conductTask(m); // see if there is any work to do } }
symbolTableEntryType * buildSymbolTableEntry(stringType *name, symbolUsageKindType usage) { symbolTableEntryType *result; result = typeAlloc(symbolTableEntryType); result->symbolName = saveString(name); result->nextSymbol = NULL; result->context = typeAlloc(symbolInContextType); result->referenceCount = 0; dupValue(result->context->value, UndefinedValue); result->context->attributes = 0; result->context->referenceCount = 0; result->context->usage = usage; result->context->pushedContexts = NULL; result->context->environmentNumber = GLOBAL_ENVIRONMENT_NUMBER; return(result); }
statementType * buildFunctionStatement(stringType *name, argumentDefinitionListType *arguments, blockType *body) { functionStatementBodyType *result; symbolTableEntryType *testSymbol; testSymbol = lookupOrEnterSymbol(name, FUNCTION_SYMBOL); if (testSymbol->context->usage != FUNCTION_SYMBOL && testSymbol-> context->usage != UNKNOWN_FUNCTION_SYMBOL) { error(SYMBOL_ALREADY_THERE_ERROR, symbName(testSymbol)); return(NULL); } result = typeAlloc(functionStatementBodyType); result->functionName = saveString(name); result->theArguments = arguments; result->theBlock = body; return(newStatement(FUNCTION_STATEMENT, (statementBodyType) result)); }
Magic3D::XMLElement* Magic3D::Model::save(XMLElement* root) { Object::save(root); if (root) { XMLElement* model = root->GetDocument()->NewElement(M3D_MODEL_XML); root->LinkEndChild(model); saveString(model, M3D_MODEL_XML_FILE, getFileName()); if (getSkeleton()) { getSkeleton()->save(model); } } return root; }
void GingaUser::saveTo(int fd) { string genre; if (userGenre == 'f') { genre = "f"; } else { genre = "m"; } saveString(fd, "|| ="); saveString(fd, itos(userId)); saveString(fd, userName); saveString(fd, userPasswd); saveString(fd, itos(userAge)); saveString(fd, userLocation); saveString(fd, genre); }
int main(int argc, char ** argv) { if (argc < 4) { printf("need four file names: type, input, output"); return EXIT_FAILURE; } if (strcmp(argv[1], "i") == 0) /* sort integers */ { int numInteger = 0; int * arrInteger = NULL; arrInteger = readInteger(argv[2], & numInteger); if (numInteger == 0) { return EXIT_FAILURE; } printInteger(arrInteger, numInteger); sortInteger(arrInteger, numInteger); printInteger(arrInteger, numInteger); saveInteger(argv[3], arrInteger, numInteger); freeInteger(arrInteger, numInteger); return EXIT_SUCCESS; } if (strcmp(argv[1], "s") == 0) /* sort strings */ { int numString = 0; char * * arrString = NULL; arrString = readString(argv[2], & numString); if (numString == 0) { return EXIT_FAILURE; } printString(arrString, numString); sortString(arrString, numString); printString(arrString, numString); saveString(argv[3], arrString, numString); freeString(arrString, numString); return EXIT_SUCCESS; } /* unknown type */ return EXIT_FAILURE; }
bool UCreatureAnimationAssetFactory::ImportSourceFile(UCreatureAnimationAsset *forAsset) const { const FString &creatureFilename = forAsset->GetCreatureFilename(); if (forAsset == nullptr || creatureFilename.IsEmpty()) { return false; } FString readString; if (!FFileHelper::LoadFileToString(readString, *creatureFilename, 0)) { return false; } #ifdef CREATURE_USE_COMPRESS_JSON // Run compression routine std::string saveString(TCHAR_TO_UTF8(*readString)); forAsset->CreatureZipBinary.Reset(); FArchiveSaveCompressedProxy Compressor = FArchiveSaveCompressedProxy(forAsset->CreatureZipBinary, ECompressionFlags::COMPRESS_ZLIB); TArray<uint8> writeData; writeData.SetNumUninitialized(saveString.length() + 1); for (size_t i = 0; i < saveString.length(); i++) { writeData[i] = saveString.c_str()[i]; } writeData[writeData.Num() - 1] = '\0'; Compressor << writeData; Compressor.Flush(); #else // Just use the uncompressed string forAsset->CreatureRawJSONString = readString; #endif forAsset->GatherAnimationData(); return true; }
void LocalHighscores::save() { //! @todo: sort highscores. string s = saveString(); string usefilename = m_filename; #if defined(ARK2D_ANDROID) bool useoldref = (m_filename.substr(0,7).compare("assets/") == 0); if (useoldref) { usefilename = m_filename.substr(7, string::npos); } #endif bool success = FileUtil::file_put_contents(usefilename, s); if (success) { std::cout << "saved local highscores" << std::endl; } else { std::cout << "could not save local highscores" << std::endl; } }
int lexIdentifier(char c) { int hashValue; snarfAlphanumericString(c, nameBuffer); hashValue = hashString(nameBuffer); if (yylval = lookupOpcode(nameBuffer, hashValue)) return(Opcode); else if (yylval = lookupKeyword(nameBuffer, hashValue)) return(yylval); else if ((yylval = lookupConditionCode(nameBuffer, hashValue)) != (int)NOT_FOUND_COND) return(ConditionCode); else if (yylval = lookupMacroName(nameBuffer, hashValue)) return(MacroName); else { yylval = (int) saveString(nameBuffer); return(Identifier); } }
/////////////////////////////////////////////////// // conduct specific task based on message content void conductTask(MsgPair msg) { std::string instr = saveString(msg.second); // we have two types of instructions here if (instr=="Task#1") { ch.log("Instruction received! Calculation the ultimate answer to the universe.."); ::Sleep(3000); // just sleep for 3 sec ch.log("Calculation finished!"); // send a message back Message m; m.fromString("Task#1 Answer: The ultimate answer to the universe is 42"); // return the ultimate answer to the universe ch.send(msg.first, m); } else if (instr=="Task#2") { ch.log("Instruction received! Calculation the ultimate question to the universe.."); ::Sleep(3000); ch.log("Calculation finished!"); Message m; m.fromString("Task#2 Answer: The ultimate question to the universe is 'How many roads must a man walk down?'"); // return the final question to the universe ch.send(msg.first, m); } }
// Parse and store a function definition // void cmd_function(void) { char id[IDLEN+1]; // buffer for id getsym(); // eat "function", get putative id if ((sym != s_undef) && (sym != s_script_eeprom) && (sym != s_script_progmem) && (sym != s_script_file)) unexpected(M_id); strncpy(id, idbuf, IDLEN+1); // save id string through value parse eraseentry(id); getsym(); // eat the id, move on to '{' if (sym != s_lcurly) expected(s_lcurly); // measure the macro text using skipstatement // fetchptr is on the character after '{' // // BUG: This is broken for file scripts char *startmark = (char *) fetchptr; // mark first char of macro text void skipstatement(void); skipstatement(); // gobble it up without executing it char *endmark = (char *) fetchptr; // and note the char past '}' // endmark is past the closing '}' - back up and find it do { --endmark; } while ((endmark > startmark) && (*endmark != '}')); int idlen = strlen(id); int addr = findhole(idlen + (endmark-startmark) + 2); // longjmps on fail if (addr >= 0) { saveString(addr, id); // write the id and its terminator addr += idlen + 1; // advance to payload offset while (startmark < endmark) eewrite(addr++, *startmark++); eewrite(addr, 0); } msgpl(M_saved); }