extern void testEtagsInvocation (void) { char* const execName = eStrdup (getExecutableName ()); char* const etags = eStrdup (ETAGS); #ifdef CASE_INSENSITIVE_FILENAMES toLowerString (execName); toLowerString (etags); #endif if (strstr (execName, etags) != NULL) { verbose ("Running in etags mode\n"); setEtagsMode (); } }
// cleanWord() // Requires: std::string reference // Returns: None // Trims end of line characters, leading spaces, and trailing spaces // from the passed string reference. After that, it transforms the // word to lower case for consistent matching. void cleanWord(std::string &s) { // Small chance of getting empty string, so don't check here every time. trimEndOfLine(s); trimLeadingWhitespace(s); trimTrailingWhitespace(s); toLowerString(s); }
bool compareStringWildcard(std::string source, std::string mod, bool ignCase) { for (auto iter = mod.begin(); iter != mod.end();) { auto next = iter + 1; if (*iter == '*' && next != mod.end() && *next == '*') { iter = mod.erase(iter); continue; } iter++; } if (ignCase) { mod = toLowerString(mod); source = toLowerString(source); } std::vector<std::pair<std::string::size_type, std::string::size_type>> stk; stk.reserve(10); stk.push_back(std::make_pair(0, 0)); return compareStringWildcard(stk, source, mod) != 0; }
string Util::get_file_signature(string file_path) { int fd; long file_size = 0; char file_size_char[FILESIZE_CHARLEN]; // 文件大小 struct stat file_info; const char* file_path_char = file_path.c_str(); string file_signature; char md5_result[MD5SUM_CHARLEN]; char buf[READ_BLOCK]; if( stat(file_path_char, &file_info) != -1) { /** S_ISREG是否是一个常规文件. S_ISLNK(st_mode):是否是一个连接. S_ISDIR是否是一个目录. S_ISCHR是否是一个字符设备. S_ISBLK是否是一个块设备. S_ISFIFO是否是一个FIFO文件. S_ISSOCK是否是一个SOCKET文件. */ if(S_ISREG(file_info.st_mode)) { file_size = (long)file_info.st_size; sprintf(file_size_char, "%ld ", file_size); } else { file_signature = file_path; file_signature.append(" is not a regular file"); return file_signature; } } else { return strerror(errno); } fd = open(file_path_char, O_RDONLY); if(file_size <= SMALL_FILE) { get_md5sum(fd, file_size, md5_result, buf); strncat(md5_result, "_", 2); file_signature = md5_result; file_signature.append(file_size_char); } else { get_md5sum(fd, FILE_BLOCK, md5_result, buf); strncat(md5_result, "_", 2); file_signature = md5_result; lseek(fd, file_size / 2, SEEK_SET); get_md5sum(fd, FILE_BLOCK, md5_result, buf); strncat(md5_result, "_", 2); file_signature.append(md5_result); lseek(fd, -FILE_BLOCK , SEEK_END); get_md5sum(fd, FILE_BLOCK, md5_result, buf); strncat(md5_result, "_", 2); file_signature.append(md5_result); file_signature.append(file_size_char); } close(fd); toLowerString(file_signature); return file_signature; }
int main(int argc, char *argv[]) { if (argc != 2) { std::cout << "Please specify exactly one parameter, the filename, if necessary with the full path." << std::endl; system("PAUSE"); return 1; } std::string curFilePath = argv[1]; // kompletter Dateiname mit Pfad std::string curFileName = curFilePath.substr( curFilePath.find_last_of("\\") + 1 ); // nur Dateiname std::cout << "Working real hard ..." << std::endl << std::endl; #ifdef WIN32 // für die Perfomancemessung long long frequency, startTime, stopTime; double timeTaken, timeScale; bool counterAvailable = false; // falls vorhanden den richtig schnellen timer if ( QueryPerformanceFrequency( (LARGE_INTEGER*) &frequency) ) { counterAvailable = true; timeScale = 1.0/frequency; QueryPerformanceCounter( (LARGE_INTEGER*) &startTime); } else { // sonst den "langsamen" (auflösung 1ms) startTime = GetTickCount(); timeScale = 0.001; } #endif cWoerterbuch *myWoerterbuch = new cWoerterbuch(); cIndexer *myIndexer = new cIndexer(myWoerterbuch); int myLoadResult = myIndexer->loadFile(argv[1]); #ifdef WIN32 if (counterAvailable) { QueryPerformanceCounter( (LARGE_INTEGER*) &stopTime); } else { stopTime = GetTickCount(); } timeTaken = ( stopTime - startTime ) * timeScale; #else double timeTaken = 0; #endif if (myLoadResult < 0) return -1; std::cout << "It took " << timeTaken << " seconds to index " << curFileName << std::endl; std::cout << "I found " << myWoerterbuch->wordCount << " unique Words in a total of " << myIndexer->totalwords << " Words." << std::endl; std::cout << "I had " << myWoerterbuch->collisions << " Collisions." << std::endl; while (true) { std::cout << std::endl; std::cout << "The following commands are available:" << std::endl << "\"getCount WORD\" to view how many times i found WORD" << std::endl << "\"printit\" to print the entire hashtable in format $HASH : $WORD." << std::endl << "\"exit\" to quit the program (this will discard the index!)" << std::endl << std::endl; std::cout << "my master? > "; std::string inString; char inBuffer[255]; std::cin.getline(inBuffer,256); inString = inBuffer; toLowerString(inString); std::string command = inString.substr( 0, inString.find_first_of(' ') ); std::string commandParam = inString.substr( inString.find_first_of(' ')+1,inString.length() ); if (command == "exit") { break; } if (command == "getcount") { std::cout << std::endl << "I found \"" << commandParam << "\" " << myWoerterbuch->getCount(commandParam) << " Times." << std::endl; continue; } if (command == "printit") { myWoerterbuch->printall(); continue; } std::cout << "Sorry, i couldn't understand that command" << std::endl; } delete(myWoerterbuch); delete(myIndexer); return 0; }