void PullOutMatchedReads(struct tree *t, FILE *fastq, FILE *out) { int location = 0; int write = 0; char *line = NULL; size_t length; ssize_t read; struct split_data *idFirst; struct split_data *idLast; char *tmp; char *s; long long int id = 0; int i = 0; while ((read = getline(&line, &length, fastq)) != -1) { if (location == 0) { idFirst = (struct split_data*)malloc(sizeof(struct split_data)); idLast = (struct split_data*)malloc(sizeof(struct split_data)); idFirst = splitData(line, " "); idLast = splitData((idFirst->tokenize)[0], ":"); s = (char *)malloc(100*sizeof(char)); (idLast->tokenize)[idLast->elements-2] = PadWithZeros((idLast->tokenize)[idLast->elements-2]); (idLast->tokenize)[idLast->elements-1] = PadWithZeros((idLast->tokenize)[idLast->elements-1]); sprintf(s, "%s%s%s%s", (idLast->tokenize)[1], (idLast->tokenize)[idLast->elements-3], (idLast->tokenize)[idLast->elements-2], (idLast->tokenize)[idLast->elements-1]); id = strtoll(s, &tmp, 0); write = Lookup(t->root, id); location++; for (i = 0; i < idFirst->elements; i++) { free((idFirst->tokenize)[i]); } free((idFirst->tokenize)); free(idFirst); for (i = 0; i < idLast->elements; i++) { free((idLast->tokenize)[i]); } free((idLast->tokenize)); free(idLast); free(s); } else if (location == 3) { location = 0; } else { location++; } if (write) { fprintf(out, "%s", line); } } }
void DiveThroughFixrank(struct tree *t, FILE *fixrank, char *taxlevel, char *name) { char *line = NULL; size_t length; ssize_t read; char *s; char *tmp; long long int id; struct split_data *nameSearch = (struct split_data*)malloc(sizeof(struct split_data)); struct split_data *idFirst = (struct split_data*)malloc(sizeof(struct split_data)); struct split_data *idLast = (struct split_data*)malloc(sizeof(struct split_data)); int i = 0; /*Read the entire file*/ while ((read = getline(&line, &length, fixrank)) != -1) { nameSearch = splitData(line, "\t"); for (i = 0; i < nameSearch->elements; i++) { /*if there is a match, the next should be taxlevel*/ if (strcmp(name, (nameSearch->tokenize)[i]) == 0) { if (strcmp(taxlevel, (nameSearch->tokenize)[i+1]) == 0) { idLast = splitData((nameSearch->tokenize)[0], "|"); idFirst = splitData((idLast->tokenize)[0], ":"); s = (char *)malloc(100*sizeof(char)); (idFirst->tokenize)[5] = PadWithZeros((idFirst->tokenize)[5]); (idFirst->tokenize)[6] = PadWithZeros((idFirst->tokenize)[6]); sprintf(s, "%s%s%s%s", (idFirst->tokenize)[1], (idFirst->tokenize)[4], (idFirst->tokenize)[5], (idFirst->tokenize)[6]); id = strtoll(s, &tmp, 0); free(s); AddNode(&(t->root), id); (t->count)++; } free((nameSearch->tokenize)[i]); } } } //printf("%d\n", (t->count)); }
bool CTarArchive::FillHeader(const std::string& filename, posix_header& header) { bool Ret = false; #if defined DEBUG && defined VERBOSE std::cout << i8n("[DBG]File header for ") << filename << " :" << '\n'; #endif struct stat Info; memset(&header, 0, 512); //Try to stat file. if(stat(filename.c_str(), &Info) == -1) { std::cout << i8n("[WNG] Cannot stat file: ") << filename.c_str() << i8n(" so I skip it !") << '\n'; Ret = false; } else { std::string l_name(filename); #if defined WIN32 // No UID or GID support for Windows - Hack it up. strncpy(header.mode, "0100777", 8); strncpy(header.uid, "0000000", 8); strncpy(header.gid, "0000000", 8); #else int Mode = 0; //Never reached ? if(!(Info.st_mode & S_IFREG)) { // Not a normal file. Let's archive it anyway, but warn the user. std::cout << i8n("[WNG] Archiving non-ordinary file (Linked or Device file?)") << '\n'; } // Add the normal file bit. Mode += 100000; // Find out the file permissions. if(Info.st_mode & TUREAD) Mode += 400; if(Info.st_mode & TUWRITE) Mode += 200; if(Info.st_mode & TUEXEC) Mode += 100; if(Info.st_mode & TGREAD) Mode += 40; if(Info.st_mode & TGWRITE) Mode += 20; if(Info.st_mode & TGEXEC) Mode += 10; if(Info.st_mode & TOREAD) Mode += 4; if(Info.st_mode & TOWRITE) Mode += 2; if(Info.st_mode & TOEXEC) Mode += 1; std::string Modestr(itos(Mode)); Modestr = PadWithZeros(Modestr, 8); strncpy(header.mode, Modestr.c_str(), 8); //UID std::string l_uid(DecToOct(Info.st_uid)); l_uid = PadWithZeros(l_uid, 8); strncpy(header.uid, l_uid.c_str(), 8); //GID std::string l_gid(DecToOct(Info.st_gid)); l_gid = PadWithZeros(l_gid, 8); strncpy(header.gid, l_gid.c_str(), 8); // File Size. std::string Size = DecToOct(Info.st_size); Size = PadWithZeros(Size, 12); strncpy(header.size, Size.c_str(), 12); // Time of modification std::string l_mtime = DecToOct(time(0)); l_mtime = PadWithZeros(l_mtime, 12); strncpy(header.mtime, l_mtime.c_str(), 12); // Type of file. header.typeflag = REGTYPE; if (S_ISLNK(Info.st_mode)) header.typeflag = SYMTYPE; else { if (S_ISDIR(Info.st_mode)) { header.typeflag = DIRTYPE; l_name += "/"; } } strncpy(header.name, l_name.c_str(), 100); strncpy(header.linkname, "", 100); // Magic strncpy(header.magic, TMAGIC, TMAGLEN); strncpy(header.version, TVERSION, TVERSLEN); // Windows again, let's cheat. #if defined WIN32 strncpy(header.uname, "root", 32); strncpy(header.gname, "root", 32); #else passwd* l_pwdFileInfo = getpwuid(Info.st_uid); group* l_grpFileInfo = getgrgid(Info.st_gid); if(!l_pwdFileInfo || !l_grpFileInfo) { // No entry. Let's fake it. strncpy(header.uname, header.uid, 32); strncpy(header.gname, header.gid, 32); } else { strncpy(header.uname, l_pwdFileInfo->pw_name, 32); strncpy(header.gname, l_grpFileInfo->gr_name, 32); } #endif // Skip devminor and devmajor. strncpy(header.devmajor, "", 8); strncpy(header.devminor, "", 8); // Fill the prefix. strncpy(header.prefix, "", 167); // Initialize our pointer. char* l_startheaderPtr = reinterpret_cast<char*>(&header); char* lheaderPtr ; int l_checksum = 0; // Find the checksum. for(lheaderPtr = l_startheaderPtr; (lheaderPtr - l_startheaderPtr) < 512; ++lheaderPtr) l_checksum += static_cast<int>(*lheaderPtr); // Add 256 (2^8) l_checksum += 256; // Get it to Octal. std::string l_checksumstr = DecToOct(l_checksum); l_checksumstr = PadWithZeros(l_checksumstr, 8); strncpy(header.chksum, l_checksumstr.c_str(), 8); #if defined DEBUG && defined VERBOSE Log::CLog::Instance()->Log(__FILE__, __LINE__, "Mode (8bytes) : ", header.mode, true); Log::CLog::Instance()->Log(__FILE__, __LINE__, "UID (8b) : ", header.uid, true); Log::CLog::Instance()->Log(__FILE__, __LINE__, "GID (8b) : ", header.gid, true); Log::CLog::Instance()->Log(__FILE__, __LINE__, "Size (12b) : ", header.size, true); Log::CLog::Instance()->Log(__FILE__, __LINE__, "Time (12b) : ", header.mtime, true); Log::CLog::Instance()->Log(__FILE__, __LINE__, "Checksum : ", header.chksum, true); #endif #endif Ret=true; } return Ret; }