std::unique_ptr<File> Extractor::readFile() { auto fileName = readFileName(); readFileTimestamp(); readFileOwnerId(); readFileGroupId(); readFileMode(); auto fileSize = readFileSize(); readUntilEndOfFileHeader(); auto fileContent = readFileContent(fileSize); return std::make_unique<StringFile>(fileContent, fileName); }
//---------------------------------------------------------------------------------- Gnuplot::Gnuplot() : mGnuPipe(NULL), mTerminal("X11"), mStyle("lines"), mCurrentWindowNumber(0), mMaxCommandSize(4096) { const std::string fileName = readFileName(); if (fileExists(fileName)==false) { std::cout << "\nGnuplot location was not found" << "\nTherefore, change the line in 'GnuplotLocation.txt" << "\nto your Gnuplot location.\n"; exit(1); } mGnuPipe = popen((fileName+" -persist").c_str(),"w"); if (mGnuPipe==NULL) assert(!"Couldn't open connection to gnuplot"); setLineStyles(); addWindow(); changeWindow(0); }
void Store::askFileNames() { fileNames[0] = readFileName("Insert the customers' file: "); fileNames[1] = readFileName("Insert the products' file: "); fileNames[2] = readFileName("Insert the transactions' file: "); }
StarDict::StarDict( const char *filename ) { ifoFileName = filename; idxFileName = filename; idxFileName.replace( idxFileName.size() - 4, 4, ".idx" ); dictFileName = filename; dictFileName.replace( dictFileName.size() - 4, 4, ".dict" ); // Ifo file file.open( ifoFileName.c_str() ); if( !file.is_open() ) { m_isOk = false; return; } // Read the ifo file string ifoline; while( !file.eof() ) { getline( file, ifoline ); if( ifoline.find( "=" ) == string::npos ) continue; if( ifoline.find( '\n' ) != string::npos ) ifoline.erase( ifoline.size() - 1 ); if( ifoline.find( "version=" ) != string::npos ) m_version = ifoline.substr( 8 ); if( ifoline.find( "bookname=" ) != string::npos ) m_bookname = ifoline.substr( 9 ); if( ifoline.find( "sametypesequence=" ) != string::npos ) m_sametypesequence = ifoline.substr( 17 ); if( ifoline.find( "idxfilesize=" ) != string::npos ) m_idxfilesize = atoi( ifoline.substr( 12 ).c_str() ); if( ifoline.find( "wordcount=" ) != string::npos ) m_wordcount = atoi( ifoline.substr( 10 ).c_str() ); if( ifoline.find( "author=" ) != string::npos ) m_author = ifoline.substr( 7 ); if( ifoline.find( "email=" ) != string::npos ) m_email = ifoline.substr( 6 ); if( ifoline.find( "website=" ) != string::npos ) m_website = ifoline.substr( 8 ); if( ifoline.find( "description=" ) != string::npos ) m_description = ifoline.substr( 12 ); if( ifoline.find( "date=" ) != string::npos ) m_date = ifoline.substr( 5 ); } file.close(); if( m_sametypesequence != "m" ) { // This class only support sametypesequence == "m" for now m_isOk = false; //cout << "Dictionary not loaded. Stardict plugin supports only sametypesequence == \"m\"" << endl; return; } // Index file // it should be on the same directory that ifo file file.open( idxFileName.c_str() ); if( !file.is_open() ) { idxFileName += ".gz"; file.open( idxFileName.c_str() ); if( !file.is_open() ) { m_isOk = false; return; } isIdxCompressed = true; file.close(); }else{ isIdxCompressed = false; file.close(); } // Definition file (.dict) // it should be on the same directory that index file // Checks if the definition file is compressed or not file.open( dictFileName.c_str() ); if( !file.is_open() ) { dictFileName += ".dz"; file.open( dictFileName.c_str() ); if( !file.is_open() ) { m_isOk = false; return; } // The definition file is compressed (.dict.dz) // Read the header isCompressed = true; char header[12]; file.readsome( header, 12 ); if( header[0] != '\x1f' || header[1] != '\x8b' ) //ID1 = 31 (0x1f, \037) ID2 = 139 (0x8b, \213) { m_isOk = false; return; } //header[2] // COMPRESSION FTEXT = header[3] & 1; FHCRC = header[3] & 2; m_extraField = header[3] & 4; m_hasName = header[3] & 8; FCOMMENT = header[3] & 16; m_mtime = (unsigned char)header[4] | (unsigned char)header[5] << 8 + (unsigned char)header[6] << 16 + (unsigned char)header[7] << 24; //header[8] // Compression type //header[9] // Operating System // If has extra field, read it if( m_extraField ) { XLEN = (unsigned char)header[10] | (unsigned char)header[11] << 8; readExtraField(); } // If has name of decompressed file, read it if( m_hasName ) { readFileName(); } // If has a comment field, read it if( FCOMMENT ) { readFileName(); } // If has a CRC field, read it if( FHCRC ) { *crc16[0] = file.get(); *crc16[1] = file.get(); } // Get the current position // This is start position of the chunks of compressed data offset = file.tellg(); file.close(); }else{ isCompressed = false; file.close(); } m_isOk = true; }
int main() { FILE * fin = NULL; char fn[MAX], input[MAX], word[MAX]; int choice = 0; int sentSize = 5; int aSize, nSize, vSize, pSize; char ** articles = NULL; char ** nouns = NULL; char ** verbs = NULL; char ** preps = NULL; char ** sentence = NULL; srand(time(NULL)); readFileName(fn); openFile(fn, fin, &aSize, &nSize, &vSize, &pSize); articles = fillArray(fn,"article", articles, aSize, fin); nouns = fillArray(fn,"noun", nouns, aSize, fin); verbs = fillArray(fn,"verb", verbs, aSize, fin); preps = fillArray(fn,"preposition", preps, aSize, fin); displayAmounts(aSize, nSize, vSize, pSize); sortStringArray(articles, aSize); sortStringArray(nouns, nSize); sortStringArray(verbs, vSize); sortStringArray(preps, pSize); do { choice = menu(); if(choice == 1) { sentence = createSentence(articles, nouns, verbs, preps, aSize, nSize, vSize, pSize); printArray2D(sentence,sentSize); }// end choice == 1 else if(choice == 2) { displayAllWords(articles, nouns, verbs, preps, aSize, nSize, vSize, pSize); }// end choice == 2 else if(choice == 3) { whichArray(input); whatWord(word); if(strcmp(input,"ARTICLES") == 0) addWord(articles, word, &aSize); else if(strcmp(input,"NOUNS") == 0) addWord(nouns, word, &nSize); else if(strcmp(input,"VERBS") == 0) addWord(verbs, word, &vSize); else if(strcmp(input,"PREPOSITIONS") == 0) addWord(preps, word, &pSize); }// end choice == 3 else if(choice == 4) { whichArray(input); whatWord(word); if(strcmp(input,"ARTICLES") == 0) removeWord(articles, word, &aSize); else if(strcmp(input,"NOUNS") == 0) removeWord(nouns, word, &nSize); else if(strcmp(input,"VERBS") == 0) removeWord(verbs, word, &vSize); else if(strcmp(input,"PREPOSITIONS") == 0) removeWord(preps, word, &pSize); }// end choice == 4 else if(choice == 5) { displayTogetherSorted(articles, nouns, verbs, preps, aSize, nSize, vSize, pSize); }// end choice == 5 }while(choice != 6); return 0; }
// main int main(int argc, const char* argv[]) { // welcome message printf("--- Welcome to Jon's Neighbor-Join & 2-Approximation! ---\n\n"); // predeclared filename char* filename; Input* ipt = NULL; if (DEBUG_INPUT) // set up the path filename = "/Users/jonfast/Desktop/phylogeny.txt"; else // read the file name filename = readFileName(); clock_t start, end; // experiment // i is the number of taxa // j is the number of base pairs for (int j = 0; j < 1; j++) { // setup and fill the input structures if (INPUT_RANDOM) getInput(filename, 1000, &ipt); else getTestInput(language, 300, j, &ipt); // summarize input if appropriate if (PRINT) summarizeInput(ipt); // free filename if input is standard if (!DEBUG_INPUT) free(filename); start = clock(); // setup the graph container StarGraphContainer* containerStar = NULL; createStarContainer(&containerStar, ipt); // calculate the neighbor join tree calculateNeighborJoin(containerStar, &hammingDistance); // print a summary if (PRINT) { summarizeStarContainer(containerStar); } // stop the clock and check result end = clock(); printf("%2.4f\n", (double) (end - start) / CLOCKS_PER_SEC); } start = clock(); /* // now try the two approximation GraphContainer* container = NULL; createCliqueContainer(&container, ipt); Leaf* someLeaf = NULL; twoApproximation(container, &someLeaf); if (PRINT) printTree(someLeaf); end = clock(); printf("2-Approximation Running Time: %2.4f\n", (double) (end - start) / CLOCKS_PER_SEC); // done, destroy all (non-freed) objects destroyInput(ipt); destroyContainer(container); // all done printf("Done!\n"); return 0; */ }