// // BinaryTokenNTS::WriteKeyInt // void BinaryTokenNTS::WriteKeyInt(std::ostream *out, char const *key, bigsint val) { WriteStr(out, key); WriteStr(out, "="); WriteInt(out, val); WriteStr(out, ";"); }
/* Writes full header */ static void WriteHeader(LPIT8 it8, FILE *fp) { LPKEYVALUE p; WriteStr(fp, it8->SheetType); WriteStr(fp, "\n"); for (p = it8->HeaderList; (p != NULL); p = p->Next) { if (!IsAvailableOnList(it8-> ValidKeywords, p->Keyword, NULL)) { WriteStr(fp, "KEYWORD\t\""); WriteStr(fp, p->Keyword); WriteStr(fp, "\"\n"); } WriteStr(fp, p->Keyword); if (p->Value) { WriteStr(fp, "\t\""); WriteStr(fp, p->Value); WriteStr(fp, "\""); } WriteStr (fp, "\n"); } }
// // BinaryTokenNTS::WriteKeyStr // void BinaryTokenNTS::WriteKeyStr(std::ostream *out, char const *key, std::string const &val) { WriteStr(out, key); WriteStr(out, "="); WriteStr(out, val); WriteStr(out, ";"); }
/* sava_data (C->S) */ EdpPacket* PacketSavedataSimpleString(const int8_t* dst_devid, const int8_t* input) { EdpPacket* pkg = NULL; uint32 remainlen = 0; uint32 input_len = 0; pkg = NewBuffer(); input_len = strlen((const char *)input); /* msg type */ WriteByte(pkg, SAVEDATA); if (dst_devid) { /* remain len */ remainlen = 1 + (2 + strlen((const char *)dst_devid)) + 1 + (2 + input_len); WriteRemainlen(pkg, remainlen); /* translate address flag */ WriteByte(pkg, 0x80); /* dst devid */ WriteStr(pkg, dst_devid); } else { /* remain len */ remainlen = 1 + 1 + (2 + input_len); WriteRemainlen(pkg, remainlen); /* translate address flag */ WriteByte(pkg, 0x00); } /* json flag */ WriteByte(pkg, kTypeString); /* json */ WriteStr(pkg, input); return pkg; }
/* connect1 (C->S): devid + apikey */ EdpPacket* PacketConnect1(const int8_t* devid, const int8_t* auth_key) { uint32_t remainlen; EdpPacket* pkg = NewBuffer(); if(pkg == NULL) { return NULL; } /* msg type */ WriteByte(pkg, CONNREQ); /* remain len */ remainlen = (2 + 3) + 1 + 1 + 2 + (2 + strlen((const char *)devid)) + (2 + strlen((const char *)auth_key)); WriteRemainlen(pkg, remainlen); /* protocol desc */ WriteStr(pkg, PROTOCOL_NAME); /* protocol version */ WriteByte(pkg, PROTOCOL_VERSION); /* connect flag */ WriteByte(pkg, 0x40); /* keep time */ WriteUint16(pkg, 0x0080); /* DEVID */ WriteStr(pkg, devid); /* auth key */ WriteStr(pkg, auth_key); return pkg; }
/* connect2 (C->S): userid + auth_info */ EdpPacket* PacketConnect2(const int8_t* userid, const int8_t* auth_info) { EdpPacket* pkg = NULL; uint32_t remainlen; pkg = NewBuffer(); /* msg type */ WriteByte(pkg, CONNREQ); /* remain len */ remainlen = (2 + 3) + 1 + 1 + 2 + 2 + (2 + strlen((const char *)userid)) + (2 + strlen((const char *)auth_info)); WriteRemainlen(pkg, remainlen); /* protocol desc */ WriteStr(pkg, PROTOCOL_NAME); /* protocol version */ WriteByte(pkg, PROTOCOL_VERSION); /* connect flag */ WriteByte(pkg, 0xC0); /* keep time */ WriteUint16(pkg, 0x0080); /* devid */ WriteByte(pkg, 0x00); WriteByte(pkg, 0x00); /* USERID */ WriteStr(pkg, userid); /* auth info */ WriteStr(pkg, auth_info); return pkg; }
static void _WriteExtraToc(ArchiveHandle *AH, TocEntry *te) { lclTocEntry *ctx = (lclTocEntry *) te->formatData; if (ctx->filename) WriteStr(AH, ctx->filename); else WriteStr(AH, ""); }
/* sava_data bin (C->S) */ EdpPacket* PacketSavedataBin(const char* dst_devid, cJSON* desc_obj, uint8* bin_data, uint32 bin_len) { EdpPacket* pkg; uint32 remainlen; /* check arguments */ char* desc_out = cJSON_Print(desc_obj); uint32 desc_len = mystrlen(desc_out); if (desc_len > (0x01 << 16) || bin_len > (3 * (0x01 << 20)) /* desc < 2^16 && bin_len < 3M*/ || cJSON_GetObjectItem(desc_obj, "ds_id") == 0) /* desc_obj MUST has ds_id */ { hx_free(desc_out); return 0; } pkg = NewBuffer(); /* msg type */ WriteByte(pkg, SAVEDATA); if (dst_devid) { /* remain len */ remainlen = 1+(2+mystrlen(dst_devid))+1+(2+desc_len)+(4+bin_len); WriteRemainlen(pkg, remainlen); /* translate address flag */ WriteByte(pkg, 0x80); /* dst devid */ WriteStr(pkg, dst_devid); } else { /* remain len */ remainlen = 1+1+(2+desc_len)+(4+bin_len); WriteRemainlen(pkg, remainlen); /* translate address flag */ WriteByte(pkg, 0x00); } /* bin flag */ WriteByte(pkg, 0x02); /* desc */ WriteStr(pkg, desc_out); hx_free(desc_out); /* bin data */ WriteUint32(pkg, bin_len); WriteBytes(pkg, bin_data, bin_len); return pkg; }
BOOL nsOutlookMail::WriteMimeBoundary( nsIOutputStream *pDest, CMapiMessage *pMsg, BOOL terminate) { BOOL bResult = WriteStr( pDest, "--"); if (bResult) bResult = WriteStr( pDest, pMsg->GetMimeBoundary()); if (terminate && bResult) bResult = WriteStr( pDest, "--"); if (bResult) bResult = WriteStr( pDest, "\x0D\x0A"); return( bResult); }
// // BinaryTokenNTS::WriteFunction // void BinaryTokenNTS::WriteFunction(std::ostream *out, ObjectData::Function const &f) { if(f.externDef) return; WriteStr(out, "function"); WriteStr(out, f.name); WriteStr(out, "{"); WriteKeyInt(out, "argCount", f.argCount); WriteKeyStr(out, "label", f.label); WriteKeyInt(out, "regCount", f.varCount - f.argCount); WriteKeyInt(out, "retCount", f.retCount); WriteStr(out, "}"); }
void Service_Menu(void) { uchar MenuItem; Flags |= (1 << calibrate); for (MenuItem = 0; MenuItem < 5; MenuItem++) { CalValue[MenuItem].Max = 0x0000; CalValue[MenuItem].Min = 0xFFFF; } MenuItem = 0; ClrAllDisp(); WriteStr(servmenu[0].menustr); for (;;) { switch (ScanCode) { case 0x7E: // Enter ScanCode = 0; SetCursDisp(0,15); put_char('*'); servmenu[MenuItem].func(); WriteStr(servmenu[MenuItem].menustr); break; case 0xBE: // + ScanCode = 0; if (MenuItem == (maxMenuItem - 1)) MenuItem = 0; else MenuItem++; ClrStrDisp(0); WriteStr(servmenu[MenuItem].menustr); break; case 0xDE: // - ScanCode = 0; if (MenuItem == 0) MenuItem = maxMenuItem - 1; else MenuItem --; ClrStrDisp(0); WriteStr(servmenu[MenuItem].menustr); break; case 0xEE: // Esc ScanCode = 0; ClrAllDisp(); Flags &= ~(1 << calibrate); return; } } }
BOOL nsOutlookMail::WriteMimeMsgHeader( nsIOutputStream *pDest, CMapiMessage *pMsg) { BOOL bResult = TRUE; if (!pMsg->HasMimeVersion()) bResult = WriteStr( pDest, "MIME-Version: 1.0\x0D\x0A"); pMsg->GenerateBoundary(); if (bResult) bResult = WriteStr( pDest, "Content-type: multipart/mixed; boundary=\""); if (bResult) bResult = WriteStr( pDest, pMsg->GetMimeBoundary()); if (bResult) bResult = WriteStr( pDest, "\"\x0D\x0A"); return( bResult); }
int main(int argc, char * args[]) { // Parameter checking if (argc != 3) { WriteStr("Please enter two parameters - cp src dst"); return 0; } // Open the source // A little RAII { FileWrapper src(args[1], GENERIC_READ, OPEN_EXISTING); if (GetLastError() == ERROR_FILE_NOT_FOUND) { WriteStr("Could not find file!"); return 0; } // Open destination file FileWrapper dst(args[2], GENERIC_WRITE, CREATE_ALWAYS); DWORD numberofbytesread; DWORD numberofbyteswritten; char buffer[20]; // Stream the file instead of reading it into memory while(true) { // The buffer parameter is a void pointer which means it can take anything - in this case we just use a char array // http://msdn.microsoft.com/en-us/library/windows/desktop/aa365467(v=vs.85).aspx ReadFile(src.getHandle(), buffer, 20, &numberofbytesread, NULL); // http://stackoverflow.com/questions/12655120/readfile-function-from-win32-api if (numberofbytesread == 0) break; WriteFile(dst.getHandle(), buffer, numberofbytesread, &numberofbyteswritten, NULL); } } std::vector<wchar_t> wstr; std::string x = args[1]; wstr.resize(x.size() + 1); size_t convertedChars = 0; mbstowcs_s(&convertedChars, &wstr[0], x.size() + 1, x.c_str(), _TRUNCATE); return 0; }
/* Writes the data format */ static void WriteDataFormat(FILE *fp, LPIT8 it8) { int i, nSamples; if (!it8 -> DataFormat) return; WriteStr(fp, "BEGIN_DATA_FORMAT\n"); nSamples = atoi(cmsxIT8GetProperty(it8, "NUMBER_OF_FIELDS")); for (i = 0; i < nSamples; i++) { WriteStr(fp, it8->DataFormat[i]); WriteStr(fp, (char*)((i == (nSamples-1)) ? "\n" : "\t")); // C->C++ : cast } WriteStr (fp, "END_DATA_FORMAT\n"); }
EdpPacket* PacketSavedataBinStr(const int8_t* dst_devid, const int8_t* desc_str, const uint8_t* bin_data, uint32_t bin_len) { EdpPacket* pkg = NULL; uint32_t remainlen = 0; uint32_t desc_len = 0; /* check arguments */ desc_len = strlen((const char *)desc_str); if (desc_len > (0x01 << 16) || bin_len > (3 * (0x01 << 20))) { /* desc < 2^16 && bin_len < 3M*/ return 0; } pkg = NewBuffer(); /* msg type */ WriteByte(pkg, SAVEDATA); if (dst_devid) { /* remain len */ remainlen = 1 + (2 + strlen((const char *)dst_devid)) + 1 + (2 + desc_len) + (4 + bin_len); WriteRemainlen(pkg, remainlen); /* translate address flag */ WriteByte(pkg, 0x80); /* dst devid */ WriteStr(pkg, dst_devid); } else { /* remain len */ remainlen = 1 + 1 + (2 + desc_len) + (4 + bin_len); WriteRemainlen(pkg, remainlen); /* translate address flag */ WriteByte(pkg, 0x00); } /* bin flag */ WriteByte(pkg, 0x02); /* desc */ WriteStr(pkg, desc_str); /* bin data */ WriteUint32(pkg, bin_len); WriteBytes(pkg, bin_data, bin_len); return pkg; }
static void WriteIndexEntry (const ObjData* O) /* Write one index entry */ { /* Module name/flags/MTime/start/size */ WriteStr (NewLib, O->Name); Write16 (NewLib, O->Flags & ~OBJ_HAVEDATA); Write32 (NewLib, O->MTime); Write32 (NewLib, O->Start); Write32 (NewLib, O->Size); }
static void BuildInfoMsg() { aInfoMsgSize = sizeof(SERVERBROWSE_INFO); mem_copy(aInfoMsg, SERVERBROWSE_INFO, aInfoMsgSize); WriteInt(-1); WriteStr(pVersion); WriteStr(pServerName); WriteStr(pMap); WriteInt(GameType); WriteInt(Flags); WriteInt(Progression); WriteInt(NumPlayers); WriteInt(MaxPlayers); for(int i = 0; i < NumPlayers; i++) { WriteStr(PlayerNames[i]); WriteInt(PlayerScores[i]); } }
/* sava_data (C->S) */ EdpPacket* PacketSavedataJson(const int8_t* dst_devid, cJSON* json_obj, int32_t type) { EdpPacket* pkg = NULL; uint32_t remainlen = 0; int8_t* json_out = NULL; uint32_t json_len = 0; pkg = NewBuffer(); json_out =(int8_t *) cJSON_Print(json_obj); json_len = strlen((const char *)json_out); /* msg type */ WriteByte(pkg, SAVEDATA); if (dst_devid) { /* remain len */ remainlen = 1 + (2 + strlen((const char *)dst_devid)) + 1 + (2 + json_len); WriteRemainlen(pkg, remainlen); /* translate address flag */ WriteByte(pkg, 0x80); /* dst devid */ WriteStr(pkg, dst_devid); } else { /* remain len */ remainlen = 1 + 1 + (2 + json_len); WriteRemainlen(pkg, remainlen); /* translate address flag */ WriteByte(pkg, 0x00); } /* json flag */ WriteByte(pkg, type); /* json */ WriteStr(pkg, json_out); printf("%s \n", json_out); free(json_out); return pkg; }
/* sava_data (C->S) */ EdpPacket* PacketSavedataJson(const char* dst_devid, cJSON* json_obj, int type) { EdpPacket* pkg = NewBuffer(); uint32 remainlen = 0; char* json_out = cJSON_Print(json_obj); uint32 json_len = mystrlen(json_out); //printjson(json_obj);//_hx_printf("json type=%d,c=0x%X,p=0x%X n=0x%X",json_obj->type,json_obj->child,json_obj->prev,json_obj->next); //return 0; /* msg type */ WriteByte(pkg, SAVEDATA); if (dst_devid) { /* remain len */ remainlen = 1+(2+mystrlen(dst_devid))+1+(2+json_len); WriteRemainlen(pkg, remainlen); /* translate address flag */ WriteByte(pkg, 0x80); /* dst devid */ WriteStr(pkg, dst_devid); } else { /* remain len */ remainlen = 1+1+(2+json_len); WriteRemainlen(pkg, remainlen); /* translate address flag */ WriteByte(pkg, 0x00); } /* json flag */ WriteByte(pkg, type); /* json */ WriteStr(pkg, json_out); hx_free(json_out); return pkg; }
/* Writes data array */ static void WriteData(FILE *fp, LPIT8 it8) { int i, j; if (!it8->Data) return; WriteStr (fp, "BEGIN_DATA\n"); it8->nPatches = atoi(cmsxIT8GetProperty(it8, "NUMBER_OF_SETS")); for (i = 0; i < it8-> nPatches; i++) { for (j = 0; j < it8->nSamples; j++) { char *ptr = it8->Data[i*it8->nSamples+j]; WriteStr(fp, (char*)((ptr == NULL) ? "0.00" : ptr)); // C->C++ : cast WriteStr(fp, (char*)((j == (it8->nSamples-1)) ? "\n" : "\t")); // C->C++ : cast } } WriteStr (fp, "END_DATA\n"); }
/* push_data (C->S) */ EdpPacket* PacketPushdata(const char* dst_devid, const char* data, uint32 data_len) { EdpPacket* pkg = NewBuffer(); uint32 remainlen; /* msg type */ WriteByte(pkg, PUSHDATA); /* remain len */ remainlen = (2+mystrlen(dst_devid))+data_len; WriteRemainlen(pkg, remainlen); /* dst devid */ WriteStr(pkg, dst_devid); /* data */ WriteBytes(pkg, data, data_len); return pkg; }
void CStream::WriteInt(int nValue) { //int nLen = 0; //const char* sString = NSFastIntToString::GetString(fabs(nValue), nLen); //if (sString) //{ // if (nValue < 0) // WriteChar('-'); // Write((const BYTE*)sString, nLen); //} //else //{ char pBuffer[32]; memset(pBuffer, 0x00, 32); ItoA(pBuffer, nValue, pBuffer + 31); return WriteStr(pBuffer); //} }
void RegionIO::SaveData(ostream &output) { int i=0; double *d=new double [7+NumIntPar]; output<<" Pos Pressure Dencity Energy Velocity \n"; while (i<NumPnt) { i++; d[1]=Pos [i]; d[2]=Pressure[i]*1e-5; d[3]=Dencity [i]; d[5]=Velocity[i]; d[4]=Energy [i]; if (NumIntPar>0) MemoryMove(IntPar[i],&d[6],sizeof(double)*NumIntPar); WriteStr(output,&d[0],5+NumIntPar); } delete d; };
// // BinaryTokenNTS::WriteStatic // void BinaryTokenNTS::WriteStatic(std::ostream *out, ObjectData::Static const &s) { if(s.externDef) return; WriteStr(out, "data"); WriteStr(out, s.name); WriteInt(out, s.size); if(!s.init.data.empty()) { auto itr = s.init.data.begin(), end = s.init.data.end(); WriteStr(out, "("); (*itr++)->writeNTS0(out); while(itr != end) WriteStr(out, ","), (*itr++)->writeNTS0(out); WriteStr(out, ")"); } else WriteStr(out, ";"); }
void WriteStr(int iValue) { TCHAR sz[200]; wsprintf(sz,"iValue = %d",iValue); WriteStr(sz); }
// // BinaryTokenNTS::WriteAll // void BinaryTokenNTS::WriteAll(std::ostream *out, std::vector<BinaryTokenNTS> const &tokens) { // Header. WriteStr(out, "MC_NTS0"); WriteStr(out, "CODEDEFS"); WriteStr(out, ""); // Variable data. ObjectData::Static::Iterate(WriteStatic, out); ObjectData::String::Iterate(WriteString, out); // Function data. ObjectData::Function::Iterate(WriteFunction, out); // Instruction data. WriteStr(out, "code"); WriteStr(out, ""); WriteStr(out, "{"); for(auto const &token : tokens) { // Labels. for(auto const &label : token.labels) { WriteStr(out, "label"); WriteStr(out, "("); WriteStr(out, label); WriteStr(out, ")"); } WriteStr(out, token.code); WriteStr(out, "("); if(!token.args.empty()) { token.args[0]->writeNTS0(out); for(auto itr = token.args.begin() + 1, end = token.args.end(); itr != end; ++itr) WriteStr(out, ","), (*itr)->writeNTS0(out); } WriteStr(out, ")"); } WriteStr(out, "}"); }
static void WriteInt(int i) { char aBuf[64]; str_format(aBuf, sizeof(aBuf), "%d", i); WriteStr(aBuf); }
// // BinaryTokenNTS::WriteString // void BinaryTokenNTS::WriteString(std::ostream *out, ObjectData::String const &s) { if(s.names.empty()) return; biguint bytes = s.string.size() + 1; biguint words = (bytes + 3) / 4; // Convert the string into words. std::vector<biguint> data(words, 0); for(auto i = s.string.size(); i--;) data[i / 4] |= static_cast<biguint>(s.string[i] & 0xFF) << (i % 4 * 8); // Add the string as a data. WriteStr(out, "data"); WriteStr(out, s.names[0] + '_'); WriteInt(out, words); WriteStr(out, "("); { auto itr = data.begin(), end = data.end(); WriteInt(out, *itr++); while(itr != end) WriteStr(out, ","), WriteInt(out, *itr++); } WriteStr(out, ")"); // Define the actual name as the byte-oriented address. WriteStr(out, "define"); WriteStr(out, s.names[0]); WriteStr(out, "="); WriteStr(out, "*"); WriteStr(out, '$' + s.names[0] + '_'); WriteStr(out, "4"); WriteStr(out, ";"); }
bool PacketManager::WriteStr(const char *str){ return WriteStr(str,strlen(str)); }
void WriteStr(DWORD iValue) { TCHAR sz[200]; wsprintf(sz,"iValue = %ld",iValue); WriteStr(sz); }