int main() { std::stringstream a_foldername; a_foldername.str( std::string() ); a_foldername.clear(); a_foldername << "calibrationData" << "/" << getDate() << "_" << getTime() << "/"; std::cout << "Folder: " << a_foldername.str() << std::endl; std::stringstream a_filename; a_filename.str( std::string() ); a_filename.clear(); a_filename << "pointsGen.csv"; std::cout << "File: " << a_filename.str() << std::endl; std::string a_filepath = writeFile( a_foldername.str(), a_filename.str() ); readFile( a_filepath ); return 0; }
bool LOCACC::deleteScreen(QTreeWidgetItem *currentItem) { QString screenId = currentItem->text(0); QJsonArray locArray = m_jsonMasterObj["locAccData"].toArray(); QJsonObject tempObj; for(int i = 0 ; i < locArray.count() ; i++) { tempObj = locArray.at(i).toObject(); if(tempObj["id"] == screenId) { locArray.removeAt(i); break; } } m_jsonMasterObj["locAccData"] = locArray; currentItem->parent()->removeChild(currentItem); emptyTreeWidget(currentItem); writeFile(); return true; }
int main(int argc, char* argv[]) { POINT** points = NULL; if(argc > 1) { points = readFile(argv[1]); if(points != NULL) { display(points,12); polygon(points, 12); display(points, 12); writeFile(points, 13, argv[1]); destroyPoint(points, 13); } } return 0; }
void GaussianBeamWindow::saveFile(const QString& path) { QSettings settings; QString fileName = path; QString dir = settings.value("GaussianBeamWindow/lastDirectory", "").toString(); if (fileName.isNull()) fileName = QFileDialog::getSaveFileName(this, tr("Save File"), dir, "*.xml"); if (fileName.isEmpty()) return; if (!fileName.endsWith(".xml")) fileName += ".xml"; if (writeFile(fileName)) { setCurrentFile(fileName); statusBar()->showMessage(tr("File") + " " + QFileInfo(fileName).fileName() + " " + tr("saved")); settings.setValue("GaussianBeamWindow/lastDirectory", QFileInfo(fileName).path()); } }
static void kTermWriteFile(char *name) { FILE f; unsigned char buffer[512] = "Let's write a file"; f=openFile(name,'w'); if(f.flags == FS_FILE_INVALID){ print("\r\nFile not found..."); closeFile(&f); return; } else if (f.flags== FS_DIRECTORY){ print("\r\n%s is a directory"); closeFile(&f); return; } if(writeFile(&f,buffer,19) > 0) print("Writing complete\r\n"); closeFile(&f); }
int ShibeTranslator::saveToFile(const QString &fileName) { QStringList resultList; resultList.append(getMapList(&buttonMap,"Button_")); resultList.append(getMapList(&labelMap,"Label_")); resultList.append(getMapList(&checkBoxMap,"CheckBox_")); resultList.append(getMapList(&groupBoxMap,"GroupBox_")); resultList.append(getMapList(&spinBoxMap,"SpinBox_")); resultList.append(getMapList(&stringMap,"String_")); if(resultList.isEmpty())return 1; resultList.sort(); QFile writeFile(fileName); if(writeFile.open(QIODevice::WriteOnly|QIODevice::Truncate)) { writeFile.write(QString(resultList.join("\r\n")+"\r\n").toUtf8()); writeFile.close(); return 0; } return 2; }
int main(int argc, const char * argv[]){ if (argc!=4) { std::cout<<"patch command parameter:\n oldFileName diffFileName outNewFileName\n"; return 0; } const char* oldFileName=argv[1]; const char* diffFileName=argv[2]; const char* outNewFileName=argv[3]; std::cout<<"old :\"" <<oldFileName<< "\"\ndiff:\""<<diffFileName<<"\"\nout :\""<<outNewFileName<<"\"\n"; clock_t time0=clock(); { std::vector<TByte> diffData; readFile(diffData,diffFileName); const TUInt diffFileDataSize=(TUInt)diffData.size(); TUInt kNewDataSizeSavedSize=-1; const hpatch_StreamPos_t _newFileDataSize=readSavedSize(diffData,&kNewDataSizeSavedSize); const TUInt newDataSize=(TUInt)_newFileDataSize; if (newDataSize!=_newFileDataSize) exit(1); std::vector<TByte> oldData; readFile(oldData,oldFileName); const TUInt oldDataSize=(TUInt)oldData.size(); std::vector<TByte> newData; newData.resize(newDataSize); TByte* newData_begin=0; if (!newData.empty()) newData_begin=&newData[0]; const TByte* oldData_begin=0; if (!oldData.empty()) oldData_begin=&oldData[0]; clock_t time1=clock(); if (!patch(newData_begin,newData_begin+newDataSize,oldData_begin,oldData_begin+oldDataSize, &diffData[0]+kNewDataSizeSavedSize, &diffData[0]+diffFileDataSize)){ std::cout<<" patch run error!!!\n"; exit(3); } clock_t time2=clock(); writeFile(newData,outNewFileName); std::cout<<" patch ok!\n"; std::cout<<"oldDataSize : "<<oldDataSize<<"\ndiffDataSize: "<<diffData.size()<<"\nnewDataSize : "<<newDataSize<<"\n"; std::cout<<"\npatch time:"<<(time2-time1)*(1000.0/CLOCKS_PER_SEC)<<" ms\n"; } clock_t time3=clock(); std::cout<<"all run time:"<<(time3-time0)*(1000.0/CLOCKS_PER_SEC)<<" ms\n"; return 0; }
/* * Create a file on the disk */ bool Directory::createFile(string path, string name, string &data) { if (!initialised) throw std::runtime_error("Directory not Initialised"); if (isPathNameLegal(path) && isNameLegal(name)) { // check the path is valid int directoryNode = directoryTree->getPathNode(path); if (directoryNode < 0) { cout << "path " << path << " is invalid" << endl; return false; } // cache the directory (path) if it is not already cached int directoryNodeCache = getCachedDirectory(directoryNode); // check the filename does not already exist if (cachedDirectory[directoryNodeCache]->cache.count(name) > 0) { cout << "file/Directory " << name << " already exists" << endl; freeCachedDirectory(directoryNodeCache); return false; } // create an INode int fileBlock = freeBlockList->getBlock(); int fileNode = iNodeList->writeNewINode(false,data.length(),fileBlock); iNodeList->lockINode(fileNode); // write the file if (!writeFile(fileNode,data)) { iNodeList->unLockINode(fileNode); freeCachedDirectory(directoryNodeCache); return false; } // add the file to the directory iNodeList->lockINode(directoryNode); cachedDirectory[directoryNodeCache]->cache.insert({name,fileNode}); // write the directory cachedDirectory[directoryNodeCache]->writeCachedDirectory(); iNodeList->unLockINode(directoryNode); iNodeList->unLockINode(fileNode); freeCachedDirectory(directoryNodeCache); return true; } else { cout << "Path or filename not legal" << endl; return false; } }
static void* alsa_audio_start(void *aux) { audio_fifo_t *af = aux; snd_pcm_t *h = NULL; int c; int cur_channels = 0; int cur_rate = 0; audio_fifo_data_t *afd; for (;;) { afd = audio_get(af); if (!h || cur_rate != afd->rate || cur_channels != afd->channels) { if (h) snd_pcm_close(h); cur_rate = afd->rate; cur_channels = afd->channels; h = alsa_open("default", cur_rate, cur_channels); if (!h) { fprintf(stderr, "Unable to open ALSA device (%d channels, %d Hz), dying\n", cur_channels, cur_rate); exit(1); } } c = snd_pcm_wait(h, 1000); if (c >= 0) c = snd_pcm_avail_update(h); if (c == -EPIPE) snd_pcm_prepare(h); snd_pcm_writei(h, afd->samples, afd->nsamples); writeFile( &afd->samples ); zfree(afd); } }
void Huffman::compressHuffmanToFile() { std::cout << "- Huffman Code Compressed To ASCII. Saved To A New File\n\n"; // shhh.. not yet really. But it's going to happen below. // pad the huffman code to create chunks of equal size (8-bits) - Reason... CPU reads min of a byte (8-bits) while (huffmanCode.size() % 8 != 0) { huffmanCode.append("0"); padding++; } std::string compressedCode; std::stringstream sstream(huffmanCode); std::bitset<8> byte; bool innerControl = true; // I got none. int i = 0; // this and the inner while loop is for the output of bit codes in 8 bit chunks std::cout << std::right << std::setw(15) << "Character"; std::cout << " | ASCII Code" << std::endl; while (sstream) { // this would add incorrect character at the end w/o the additional padding. Could've used .good() as well sstream >> byte; char c = char(byte.to_ulong()); compressedCode += c; std::cout << std::right << std::setw(11) << " "; // this is just to pad the space on the left hand side std::cout << c; while (innerControl) { std::cout << std::setw(15) << huffmanCode.substr(i, 8) << std::endl; i += 8; innerControl = false; } innerControl = true; } compressedCode.pop_back(); // this is to cut off the extra NUL (\0) at the end (Tip for whoever comes by this CA - Notepad++ points out NULs in text files) // write out the compressed code to file writeFile(compressedCode, "CompressedHuffman.txt"); std::cout << std::right << std::setw(6) << " " << "Output To File: " << compressedCode << "\n\n"; }
void DataManager::generateXmlFile(){ XmlTree dataTree; dataTree.setTag("QLT_Genome_Data"); dataTree.push_back(XmlTree("datapath","./data/exons/")); XmlTree datas("datasets",""); for(int i=0;i<23;i++){ XmlTree dataset("dataset",""); dataset.setAttribute("id", i); dataset.push_back( XmlTree("title","Chromosome "+toString(i+1)) ); dataset.push_back( XmlTree("map","exons."+toString(i+1)+".locations") ); dataset.push_back( XmlTree("bases","exons."+toString(i+1)+".bases") ); datas.push_back( dataset ); } dataTree.push_back( datas ); DataTargetPathRef f = writeFile( getAssetPath( "QLT_Genome_Data.xml" ), true ); dataTree.write( f ); }
void Module::genhdrfile() { OutBuffer hdrbufr; hdrbufr.doindent = 1; hdrbufr.printf("// D import file generated from '%s'", srcfile->toChars()); hdrbufr.writenl(); HdrGenState hgs; memset(&hgs, 0, sizeof(hgs)); hgs.hdrgen = 1; toCBuffer(&hdrbufr, &hgs); // Transfer image to file hdrfile->setbuffer(hdrbufr.data, hdrbufr.offset); hdrbufr.data = NULL; ensurePathToNameExists(Loc(), hdrfile->toChars()); writeFile(loc, hdrfile); }
int ShaderD3D::prepareSourceAndReturnOptions(std::stringstream *shaderSourceStream) { uncompile(); int additionalOptions = 0; const std::string &source = mData.getSource(); #if !defined(ANGLE_ENABLE_WINDOWS_STORE) if (gl::DebugAnnotationsActive()) { std::string sourcePath = getTempPath(); writeFile(sourcePath.c_str(), source.c_str(), source.length()); additionalOptions |= SH_LINE_DIRECTIVES | SH_SOURCE_PATH; *shaderSourceStream << sourcePath; } #endif *shaderSourceStream << source; return additionalOptions; }
static void writePeerCerts( CFArrayRef peerCerts, const char *fileBase) { CFIndex numCerts; SecCertificateRef certRef; CFIndex i; char fileName[100]; if(peerCerts == NULL) { return; } numCerts = CFArrayGetCount(peerCerts); for(i=0; i<numCerts; i++) { sprintf(fileName, "%s%02d.cer", fileBase, (int)i); certRef = (SecCertificateRef)CFArrayGetValueAtIndex(peerCerts, i); writeFile(fileName, SecCertificateGetBytePtr(certRef), SecCertificateGetLength(certRef)); } printf("...wrote %lu certs to fileBase %s\n", numCerts, fileBase); }
void saveFile(void) { int i, len; word *pTable; writeFile("dccs", 4); /* Signature */ writeFileShort(numKeys); /* Number of keys */ writeFileShort((short)(numKeys * C)); /* Number of vertices */ writeFileShort(PATLEN); /* Length of key part of entries */ writeFileShort(SYMLEN); /* Length of symbol part of entries */ /* Write out the tables T1 and T2, with their sig and byte lengths in front */ writeFile("T1", 2); /* "Signature" */ pTable = readT1(); len = PATLEN * 256; writeFileShort(len * sizeof(word)); for (i=0; i < len; i++) { writeFileShort(pTable[i]); } writeFile("T2", 2); pTable = readT2(); writeFileShort(len * sizeof(word)); for (i=0; i < len; i++) { writeFileShort(pTable[i]); } /* Write out g[] */ writeFile("gg", 2); /* "Signature" */ pTable = readG(); len = (short)(numKeys * C); writeFileShort(len * sizeof(word)); for (i=0; i < len; i++) { writeFileShort(pTable[i]); } /* Now the hash table itself */ writeFile("ht ", 2); /* "Signature" */ writeFileShort(numKeys * (SYMLEN + PATLEN + sizeof(word))); /* byte len */ for (i=0; i < numKeys; i++) { writeFile((char *)&keys[i], SYMLEN + PATLEN); } }
handleInterrupt21(int ax, int bx, int cx, int dx){ if(ax==0) printString(bx); if(ax==1) readString(bx); if(ax==2) readSector(bx,cx); if(ax==3) readfile(bx,cx); if(ax==4) executeProgram(bx,cx); if(ax==5) terminate(); if(ax==6) writeSector(bx,cx); if(ax==7) deleteFile(bx); if(ax==8) writeFile(bx,cx,dx); if(ax>=9) printString("Error"); }
void Module::gensymfile() { OutBuffer buf; HdrGenState hgs; //printf("Module::gensymfile()\n"); buf.printf("// Sym file generated from '%s'", srcfile->toChars()); buf.writenl(); for (size_t i = 0; i < members->dim; i++) { Dsymbol *s = (*members)[i]; s->toCBuffer(&buf, &hgs); } // Transfer image to file symfile->setbuffer(buf.data, buf.offset); buf.data = NULL; writeFile(loc, symfile); }
void implFFT(std::string name, InputCopy<double>* i, OutputCopy<double>* o, Parameters<double> conf) { auto input = new FileInput<double>("input_mono.wav", i, conf); auto output = new FileOutput<double>(o, conf); FFT_p<double> fft_m(new FFTWManager<double>(conf)); fft_m->setChannels((unsigned int) input->channels()); auto fft_i = new FFTInputProxy<double>(new RectWindow<double>, input, fft_m, conf); auto fft_o = new FFTOutputProxy<double>(output, fft_m, conf); BenchmarkManager manager(Input_p(fft_i), Output_p(fft_o), Benchmark_p(new Dummy<double>(conf))); manager.execute(); output->writeFile(("out_test_copy_fft_" + name + ".wav").c_str()); }
/*********************************************************** * DESCRIPTION: * Core function for writing data w/o using VB cache * (bulk load dictionary store inserts) ***********************************************************/ int DbFileOp::writeDBFileNoVBCache( IDBDataFile* pFile, const unsigned char* writeBuf, const int fbo, const int numOfBlock ) { #ifdef PROFILE // This function is only used by bulk load for dictionary store files, // so we log as such. Stats::startParseEvent(WE_STATS_WRITE_DCT); #endif for( int i = 0; i < numOfBlock; i++ ) { Stats::incIoBlockWrite(); RETURN_ON_ERROR( writeFile( pFile, writeBuf, BYTE_PER_BLOCK ) ); } #ifdef PROFILE Stats::stopParseEvent(WE_STATS_WRITE_DCT); #endif return NO_ERROR; }
int main(int argc, char *argv[]) { char *prefix; FILE *f; int size; if (argc != 4) { fprintf(stderr, "Argument error\n"); return -1; } f = fopen(argv[1], "w"); if (!f) { fprintf(stderr, "Failed to open %s: %s\n", argv[2], strerror(errno)); return -1; } size = atoi(argv[2]); prefix = argv[3]; writeFile(f, prefix, size); return 0; }
int Picture::WritePictureToTextFile() { ofstream writeFile(ImageFileName.c_str(),ios::out); writeFile.write(ImageFileName.c_str(), ImageFileName.size()); writeFile << "\r\n"; writeFile << NumOfRows << " " << RowLength; writeFile << "\r\n"; writeFile << "\r\n"; for(int i = 0;i<NumOfRows; i++) { vector<Pixel> row; for(int j=0;j<RowLength;j++) { writeFile << hex << setfill('0') << setw(2) << image[i][j].GetRed() << " " << setfill('0') << setw(2) << image[i][j].GetGreen() << " " << image[i][j].GetBlue() << " "; } writeFile<<"\r\n"; } writeFile.close(); }
/* * Appends a new system activity log message to the * end of the "log.txt" file. */ void logActivity(char *activity) { char message[2000]; time_t rawtime; struct tm * timeinfo; /* Obtain the current system time. */ time(&rawtime); timeinfo = localtime(&rawtime); message[0] = '\0'; /* Create the log message. */ strcat(message, "LOG - EM: "); strcat(message, activity); strcat(message, " - "); strcat(message, asctime(timeinfo)); /* Write the log message to the log file (log.txt). */ writeFile("../files/log.txt", message); }
void putfilelist (list_ref list, char *filename, int after) { FILE *input; if(after == 2) { input = fopen (filename, "w"); } else { input = fopen (filename, "r"); } if (input == NULL) { fflush (NULL); fprintf (stderr, "%s: %s: %s\n", Exec_Name, filename, strerror (errno)); fflush (NULL); Exit_Status = EXIT_FAILURE; } else { if(after == 2) { writeFile(list, input); } else { putFileinList(list, input, filename, after); } fclose (input); } }
bool WiiSave::saveToFile(const std::string& filepath, Uint8* macAddress, Uint32 ngId, Uint8* ngPriv, Uint8* ngSig, Uint32 ngKeyId) { m_writer = new BinaryWriter(filepath); m_writer->setAutoResizing(true); m_writer->setEndianess(Stream::BigEndian); writeBanner(); m_writer->writeUInt32(0x70); m_writer->writeUInt32(0x426B0001); m_writer->writeUInt32(ngId); // NG-ID m_writer->writeUInt32(m_files.size()); m_writer->writeUInt32(0); // Size of files; m_writer->seek(8); m_writer->writeUInt32(0); // totalSize m_writer->seek(64); m_writer->writeUInt64(m_banner->gameID()); m_writer->writeBytes((Int8*)macAddress, 6); m_writer->seek(2); // unknown; m_writer->seek(0x10); // padding; Uint32 totalSize = 0; for (std::map<std::string, WiiFile*>::const_iterator iter = m_files.begin(); iter != m_files.end(); ++iter) { totalSize += writeFile(iter->second); } int pos = m_writer->position(); // Write size data m_writer->seek(0xF0C0 + 0x10, Stream::Beginning); m_writer->writeUInt32(totalSize); m_writer->seek(0xF0C0 + 0x1C, Stream::Beginning); m_writer->writeUInt32(totalSize + 0x3c0); m_writer->seek(pos, Stream::Beginning); writeCerts(totalSize, ngId, ngPriv, ngSig, ngKeyId); m_writer->save(); return true; }
int main () { int n; double *x, *f, *g; printf ("\nEntreu les coordenades\n"); x = HGVM (&n); printf ("\nEntreu els valors de la funcio\n"); f = GVM (n); printf ("\nEntreu les derivades\n"); g = GVM (n); /* Obte el polinomi desitjat */ difdivherm (n, &x, &f, &g); /* Dibuixa el polinomi */ writeFile (2 * n, 1e-2, -2, 2, x, f); FV (x, n); FV (f, n); return 0; }
static int rt_digest(opParams *op) { int irtn; CSSM_DATA ptext; CSSM_DATA digest = {0, NULL}; CSSM_RETURN crtn; unsigned len; if((op->plainFileName == NULL) || (op->sigFileName == NULL)) { printf("***Need plainFileName and sigFileName to digest.\n"); return 1; } irtn = readFile(op->plainFileName, &ptext.Data, &len); if(irtn) { printf("***Error reading %s\n", op->plainFileName); return irtn; } ptext.Length = len; crtn = cspDigest(op->cspHand, op->alg, CSSM_FALSE, // mallocDigest - let CSP do it &ptext, &digest); if(crtn) { printError("cspDigest", crtn); return 1; } irtn = writeFile(op->sigFileName, digest.Data, digest.Length); if(irtn) { printf("***Error writing %s\n", op->sigFileName); } else if(!op->quiet){ printf("...wrote %lu bytes to %s\n", digest.Length, op->sigFileName); } free(ptext.Data); // allocd by readFile appFreeCssmData(&digest, CSSM_FALSE); // by CSP return irtn; }
bool LOCACC::updateElement(QStringList newElementData, QTreeWidgetItem *currentItem) { QString elementId = currentItem->text(0); QJsonArray jArray = m_jsonMasterObj["locAccData"].toArray(); QString parentScreen = currentItem->parent()->text(0); QJsonObject tempObj ; for(int i = 0 ; i < jArray.count() ; i++ ) { tempObj = jArray.at(i).toObject(); if(tempObj["id"] == parentScreen) { QJsonArray eleJArray = tempObj["elements"].toArray(); QJsonObject eleObject ; for(int j = 0 ; j < eleJArray.count() ; j++) { eleObject = eleJArray.at(j).toObject(); if(eleObject["id"] == elementId) { eleJArray.removeAt(j); if(elementExistance(newElementData,eleJArray)) { return false; } QJsonObject newEleJson = getElementJson(newElementData); newEleJson["messages"] = eleObject["messages"]; eleJArray.insert(j,newEleJson); tempObj["elements"] = eleJArray; jArray.replace(i,tempObj); break; } } } } m_jsonMasterObj["locAccData"] = jArray; currentItem->setText(0,newElementData.at(0)); writeFile(); return true; }
int main( int argc, char** argv ) { //// User's choice if ( argc == 1 ) { std::cout << "Usage: " << argv[0] << "<output> <inputFile1> <inputFile2> ..." << std::endl; std::cout << " - computes the difference of results between the" << std::endl; std::cout << " CPU version of the estimator and the GPU version" << std::endl; std::cout << " GPU file : positions are between [0;size]." << std::endl; std::cout << " CPU file : positions are between [0;2*size]" << std::endl; std::cout << " or [-size;size]." << std::endl; std::cout << " Error type : 1 is l_1, 2 is l_2, 3 is l_\\infty." << std::endl; std::cout << "Example:" << std::endl; std::cout << argv[ 0 ] << " file1.txt file2.txt 64 3" << std::endl; return 0; } std::string fileOutput = argc > 1 ? std::string( argv[ 1 ] ) : "file1.txt"; std::string fileInput = argc > 2 ? std::string( argv[ 2 ] ) : "file2.txt"; convertCPUtoKhalimsky predicateCPU; std::vector< std::pair<Position*, Curvatures*> > v_export; std::vector< std::pair<Position*, Value> > v_temp; loadFile2( fileInput, v_temp, predicateCPU ); writeVector(v_temp, v_export, 0 ); deleteVector2( v_temp ); for(int i = 3; i < argc; ++i) { fileInput = std::string( argv[ i ] ); loadFile2( fileInput, v_temp, predicateCPU ); writeVector(v_temp, v_export, i-2); deleteVector2( v_temp ); } writeFile( fileOutput, v_export ); deleteVector( v_export ); return 0; }
void CP25Control::createRFHeader() { unsigned char buffer[P25_HDR_FRAME_LENGTH_BYTES + 2U]; ::memset(buffer, 0x00U, P25_HDR_FRAME_LENGTH_BYTES + 2U); buffer[0U] = TAG_HEADER; buffer[1U] = 0x00U; // Add the sync CSync::addP25Sync(buffer + 2U); // Add the NID m_nid.encode(buffer + 2U, P25_DUID_HEADER); // Add the dummy header m_rfData.encodeHeader(buffer + 2U); // Add busy bits addBusyBits(buffer + 2U, P25_HDR_FRAME_LENGTH_BITS, false, true); m_rfFrames = 0U; m_rfErrs = 0U; m_rfBits = 1U; m_rfTimeout.start(); m_lastDUID = P25_DUID_HEADER; ::memset(m_rfLDU, 0x00U, P25_LDU_FRAME_LENGTH_BYTES); #if defined(DUMP_P25) openFile(); writeFile(buffer + 2U, buffer - 2U); #endif if (m_duplex) { buffer[0U] = TAG_HEADER; buffer[1U] = 0x00U; writeQueueRF(buffer, P25_HDR_FRAME_LENGTH_BYTES + 2U); } }
void Letterbox::openParticularFile(const QString &filename) { if (!filename.isEmpty()) { if (m_modified) { switch (askToSave()) { case 0: writeFile(); case 1: break; case 2: return; } } m_filename = filename; loadFile(); } }