int main(int argc, char *argv[]) { int o; opterr = 0; while ((o = getopt(argc, argv, "h")) != -1) switch (o) { case 'h': Help(); exit(0); /* prepinac s jednym parametrom case 'p': printf("Output: '%s': parameter prepinaca -p\n", optarg); exit(0); */ case '?': default: fprintf(stderr, "Error: '%c': nespravny prepinac\n", optopt); exit(1); } argc -= optind; argv += optind; if (argc == 0) SearchDir("."); else { while ( argc > 0 ) { SearchDir(argv[0]); argv++; argc--; } } }
void main(int argc, char *argv[]) { int i; int o; opterr = 0; while ((o = getopt(argc, argv, "h")) != -1) // prehladavanie vst. arg. switch (o) { case 'h': // argument bol -h Help(); exit(0); case '?': default: fprintf(stderr, "Error: '%c': nespravny prepinac\n", optopt); exit(1); } argc -= optind; argv += optind; if(!argc) // aspon retazec mal byt zadany { fprintf(stderr,"Error: chyba retazec\n"); exit(1); } if(argc==1) // iba retazec zadany, hladame v adresari . SearchDir(".",argv[0]); else // zadane aj mena adresarov, tak cez vsetky for(i=0;i<argc-1;i++) SearchDir(argv[i],argv[argc-1]); }
void* FindInProjectDlg::SearchThread::Entry() { while (1) { // Wait for signal that we should start search m_isWaiting = true; wxMutexLocker lock(m_condMutex); m_startSearchCond.Wait(); m_isWaiting = false; if (m_stopSearch) { while (1) { if (TestDestroy()) break; Sleep(100); } } m_isSearching = true; SearchInfo si; PrepareSearchInfo(si, m_pattern, m_matchCase); ProjectInfoHandler infoHandler; infoHandler.SetRoot(m_path); // Write the html header for output m_outputCrit.Enter(); m_output = wxT("<head><style type=\"text/css\">#match {background-color: yellow}</style></head>"); m_outputCrit.Leave(); SearchDir(m_path, si, infoHandler); m_isSearching = false; } return NULL; }
void CSampleRunner::SearchDir( const char* filename, const char* tag/*= IZ_NULL*/) { HANDLE hFind; WIN32_FIND_DATA fd; hFind = FindFirstFile(filename, &fd); if (hFind == INVALID_HANDLE_VALUE) { return; } do { std::string file(fd.cFileName); if (file.compare("SampleRunner") == 0 || file.compare("SampleRunner.exe") == 0 || file.compare("Bin") == 0) { continue; } if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { if (file.compare(".") == 0 || file.compare("..") == 0) { continue; } std::string path(BASE_DIR); path.append(file.c_str()); path.append("\\*.exe"); SearchDir(path.c_str(), file.c_str()); } else if (file.find(".exe", 0) != std::string::npos) { ExeInfo info; info.tag = tag; info.path.append(BASE_DIR); info.path.append(tag); info.path.append("\\"); info.path.append(file.c_str()); if (m_InfoList.size() == 0) { m_InfoList.push_back(std::vector<ExeInfo>()); } else if (m_InfoList[m_ColumnIdx].size() >= Range) { m_InfoList.push_back(std::vector<ExeInfo>()); m_ColumnIdx++; } m_InfoList[m_ColumnIdx].push_back(info); m_InfoNum++; } } while (FindNextFile(hFind, &fd)); }
void ClassBuffer::Search (const char* path) { struct stat filestats; if (IsADirectory(path, filestats)) { if (_recursive) { SearchDirs(path); } else { SearchDir(path); } } else if (HeaderFile(path) || (_CPlusPlusFiles && CPlusPlusFile(path))) { SearchFile(path, filestats); } }
// 初期化. IZ_BOOL CSampleRunner::InitInternal( izanagi::IMemoryAllocator* allocator, izanagi::graph::CGraphicsDevice* device, izanagi::sample::CSampleCamera& camera) { m_Allocator = allocator; SearchDir(BASE_DIR"*"); m_ColumnIdx = 0; m_RowIdx = 0; return IZ_TRUE; }
void SearchDir (char *adr) { int test; DIR *dp; struct dirent *dir; char newname[200]; struct stat buf; if ((dp=opendir(adr))==NULL) { fprintf(stderr,"Error: 'Chyba pri citani adresara %s %d '\n",adr,errno); return; } while((dir=readdir(dp)) != NULL) { if ( dir ->d_ino == 0) continue; if ( (strcmp (dir -> d_name, ".") == 0) || (strcmp (dir-> d_name, "..") == 0)) continue; sprintf(newname,"%s/%s",adr,dir->d_name); stat(newname,&buf); if (((buf.st_mode & S_IRWXU) & S_IRUSR) == 0) { fprintf(stderr,"Error: nemozem citat %s\n",dir->d_name); continue; } if ( S_ISDIR(buf.st_mode)) { SearchDir(newname); continue; } if ( !S_ISREG(buf.st_mode)) continue; test = Testuj(newname); switch (test) { case -1: fprintf(stderr,"Error: nemozem otestovat %s\n",newname); continue; case 0: continue; default: fprintf(stdout,"Output: '%s'\n",newname); } } }
void SearchThread::SearchDir(const wxString& path, const SearchInfo& si, ProjectInfoHandler& infoHandler) { MMapBuffer buf; wxFileName filepath; vector<FileMatch> matches; wxArrayString dirs; wxArrayString filenames; infoHandler.GetDirAndFileLists(path, dirs, filenames); for (size_t f = 0; f < filenames.size(); ++f) { if (!m_isSearching) return; m_outputCrit.Enter(); m_currentPath = path + filenames[f]; m_outputCrit.Leave(); filepath = m_currentPath; // Map the file to memory buf.Open(filepath); if (!buf.IsMapped()) { wxLogDebug(wxT(" Mapping failed!")); continue; } // Search the file DoSearch(buf, si, matches); if (matches.empty()) continue; // Show matches WriteResult(buf, filepath, matches); matches.clear(); } for (size_t d = 0; d < dirs.size(); ++d) { const wxString dirpath = path + dirs[d] + wxFILE_SEP_PATH; SearchDir(dirpath, si, infoHandler); } }
void SearchDir(char *dirname,char *pattern) // prehladavanie adresara { DIR *dp; struct dirent *dir; char path[PATH_MAX]; int count; struct stat filestat; if((dp = opendir(dirname))==NULL) // pokus o otvorenie adresara { fprintf(stderr,"Error: '%s': chyba pri otvarani adresara\n",dirname); return; } while((dir=readdir(dp)) != NULL) // citame adresar { // toto nie je potrebne // if(dir->d_ino == 0) // nic tak ideme dalej // continue; strcpy(path,dirname); // poskladame meno suboru if(dirname[strlen(dirname)-1] != '/') // nie je tam slash strcat(path,"/"); // tak ho pridame strcat(path,dir->d_name); if(lstat(path,&filestat) != 0) {// zistime typ suboru fprintf(stderr,"Error: '%s': chyba pri lstat\n",dirname); continue; } // adresare . aa .. if((strcmp(dir->d_name,".")==0)||(strcmp(dir->d_name,"..")==0)) continue; // nefunguje // if(!(S_IRUSR & (filestat.st_mode & S_IFMT))) // toto by uz malo, ale // testuje len prava vlastnika // suboru if(!(S_IRUSR & (filestat.st_mode & S_IRWXU))) { fprintf(stderr,"Error: '%s': nemozem citat subor\n",dir->d_name); continue; } if(S_ISDIR(filestat.st_mode)) // adresar, vnorime sa { SearchDir(path,pattern); continue; } if(!S_ISREG(filestat.st_mode)) // reguler. subor continue; count = PrintCount(path,pattern); // zistime pocet if(count >= 0) printf("%s > %d\n",path,count); else fprintf(stderr,"Error: '%s': nemozem zistit pocet vyskytov\n",path); } closedir(dp); }