Example #1
0
int main(int argc, char *argv[]) {
    if(argc < 3)
        return usage(argv);

    int c;
    int is_se{0};
    char out_mode[4] = "wb";
    opts_t opts;
    while((c = getopt(argc, argv, "m:l:h?sSn")) > -1) {
        switch(c) {
        case 'm': opts.min_trimmed_len = (uint32_t)atoi(optarg); break;
        case 'l': out_mode[2] = *optarg; break;
        case 's': is_se = 1; break;
        case 'S': sprintf(out_mode, "w"); break;
        case 'n': opts.skip_all_ns = 1; break;
        case 'h': case '?': return usage(argv, EXIT_SUCCESS);
        }
    }

    if(argc - 2 != optind) LOG_EXIT("Required: precisely two positional arguments (in bam, out bam).\n");

    dlib::BamHandle inHandle(argv[optind]);
    dlib::BamHandle outHandle(argv[optind + 1], inHandle.header, out_mode);
    is_se ? dlib::abstract_single_iter(inHandle.fp, inHandle.header, outHandle.fp, &trim_ns, (void *)&opts)
          : dlib::abstract_pair_iter(inHandle.fp, inHandle.header, outHandle.fp, &pe_trim_ns, (void *)&opts);
    return EXIT_SUCCESS;
}
int main( int argc, char **argv ) {
	if ( argc <= 1 ) {
		return EXIT_FAILURE;
	}

	// Read the word list file
	std::ifstream dictFile("/var/tmp/twl06.txt");
	std::vector<std::string> dictWordVector;
	dictWordVector.reserve(178691);
	std::string line; 
	if (dictFile.is_open()) {
		while (! dictFile.eof() ) {               
			std::getline (dictFile,line);
			trim(line);
			std::transform(line.begin(), line.end(), line.begin(), ::tolower);
			dictWordVector.push_back(line);
		}
		dictFile.close();
	} else {
		return EXIT_FAILURE;
	}

	BkTree *pDictionary = new BkTree();
	std::vector<std::string>::const_iterator itr;
	for ( itr = dictWordVector.begin(); itr != dictWordVector.end(); ++itr) {
		pDictionary->insert(*itr);
	}

	std::ifstream inHandle(argv[1]);
	std::vector<std::string> wordVector;
	while (getline(inHandle, line, '\n')) {                     
		std::istringstream iss(line);
		std::copy( std::istream_iterator<std::string>(iss), 
				std::istream_iterator<std::string>(),  
				std::back_inserter<std::vector<std::string> >(wordVector));    
	}
	inHandle.close();

	std::vector<std::string>::iterator wVecIter;
	int totalDistance = 0;
	for ( wVecIter = wordVector.begin(); wVecIter != wordVector.end(); ++wVecIter ) {
		int startDistance = 0;
		while ( true ) {
			int result = pDictionary->getWithinDistance( *wVecIter, startDistance );
			if ( result != 0 ) {
				totalDistance += startDistance;
				break;
			}
			startDistance++;
		}
	}
	std::cout << totalDistance << std::endl;
	delete pDictionary;
	return EXIT_SUCCESS;
}
Example #3
0
exp bool CopyIn(const char* source, const char* dest) {
    DirectoryEntry* entry = 0;
    char* buffer = new char[bpb->bytesPerSector];

    // Open file we're copying in
    std::ifstream inHandle(source, std::ios::in | std::ios::binary | std::ios::ate);
    if (!inHandle.is_open()) {
        LastError("CopyIn", "Failed to open source file");
        return false;
    }

    // Get size of source file
    size_t inLength = (size_t)inHandle.tellg();
    inHandle.seekg(std::ios::beg);

    // Convert the filename into DOS8.3 format
    char* dosName = new char[12];
    ToDos83Name(dest, dosName);

    // Check if entry exists, if so, overwrite it
    entry = FindEntry(dosName, &directory);
    if (entry) {
        // Delete file
        Delete(dest);

        // Undelete entry
        entry->name[0] = dosName[0];
    }

    // Create the directory entry
    if (!entry) {
        // Didn't delete file, make it
        entry = MakeEntry(dosName, ATTRIB_ARCHIVE, inLength, &directory);
        if (!entry) {
            LastError("CopyIn", "Failed to create directory entry");
            delete[] dosName;
            delete[] buffer;
            return false;
        }
    }
    else {
        // Deleted file, find it
        entry = FindEntry(dosName, &directory);
        if (!entry) {
            LastError("CopyIn", "Somehow a file that was just undeleted can't be found...");
            delete[] dosName;
            delete[] buffer;
            return false;
        }

        UpdateEntry(entry, 0, inLength);
    }

    // Write entry to disk
    DirectoryWrite(&directory);

    // Update FAT and then load each cluster and write it while updating the FAT
    FatEntry fatEntry;
    fatEntry.buffer = new char[bpb->bytesPerSector];
    fatEntry.cluster = GetClusterFromEntry(entry);
    fatEntry.sector = GetFATSector(fatEntry.cluster);
    ReadSector(fatEntry.buffer, fatEntry.sector);

    UpdateFAT(&fatEntry, FindFreeCluster());

    // Write to disk
    for (size_t i = 0; i < inLength; i += bpb->bytesPerSector) {
        memset(buffer, 0, bpb->bytesPerSector);
        if (!(i % bpb->bytesPerSector))
            inHandle.read(buffer, bpb->bytesPerSector);
        else
            inHandle.read(buffer, i % bpb->bytesPerSector);

        WriteCluster(&fatEntry, buffer);
    }

    delete[] dosName;
    delete[] buffer;
    delete[] fatEntry.buffer;

    inHandle.close();

    return true;
}