const Texture TextureIO::loadTexture(const string &imgName) { string imgPath = searchFile(imgName); Mat img = imread(imgPath , -1); Texture ret; if(img.empty()) throw ImageLoadException(); //GLint maxSize; //glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxSize); //LOG_INFO<<"maximum texture size: "<< maxSize; #ifdef KINSKI_GLES if(img.channels() == 3) cv::cvtColor(img, img, CV_BGR2RGBA); #endif LOG_TRACE<<"loaded image '"<<searchFile(imgPath)<<"': "<<img.cols<<" x "<<img.rows<<" -- " <<img.channels()<<" channel(s)"; updateTexture(ret, img); return ret; }
/* rename/cut file */ int simple_rename(const char* from, const char* to){ // cari from dan to int idx_from, idx_to; try{ idx_from = searchFile(from); idx_to = searchFile(to); }catch(int e){ return e; } // jika from tidak ada, error if (idx_from < 0){ return -ENOENT; } // ganti nama from jadi to filesystem.files[idx_from].name = getPath(to); filesystem.writeFile(idx_from); // jika to sudah ada, hapus to if (idx_to >= 0){ returnFree(idx_to); } return 0; }
/* mknod, untuk membuat file */ int simple_mknod(const char *path, mode_t mode, dev_t dev){ // kalo filesystem sudah penuh, error over quota if (filesystem.available == 0){ return -EDQUOT; } // cari file int index; try{ index = searchFile(path); }catch(int e){ return e; } // kalo sudah ada, return error file already exist if (index >= 0){ return -EEXIST; } // alokasi slot baru index = nextFree(); // edit nama slot filesystem.files[index].name = getPath(path); filesystem.files[index].size = 0; // update data slot filesystem.writeFile(index); return 0; }
/* membaca file */ int simple_read(const char* path, char *buf, size_t size, off_t offset, struct fuse_file_info* fi){ // cari file int index; try{ index = searchFile(path); }catch(int e){ return e; } if (index < 0){ return -ENOENT; } int fsize = filesystem.files[index].size; if (offset >= fsize){ // jika titik awal pembacaan melebihi ukuran file // maka tidak ada data yg dibaca size = 0; }else{ // sesuaikan panjang pembacaan jika melebihi ukuran file if (offset + size > fsize){ size = fsize - offset; } // masukkan data ke buf filesystem.files[index].getContent(buf, size, offset); } // kembalikan jumlah byte yang berhasil dibaca return size; }
/* menulis file */ int simple_write(const char* path, const char *buf, size_t size, off_t offset, struct fuse_file_info* fi){ // cari file int index; try{ index = searchFile(path); }catch(int e){ return e; } if (index < 0){ return -ENOENT; } int fsize = filesystem.files[index].size; // jika penulisan akan menyebabkan ukuran file melebihi 100 byte, error file too big if (offset + size > 100){ return -EFBIG; } // tulis isi file filesystem.files[index].setContent(buf, size, offset); // jika penulisan akan menyebabkan ukuran bertambah, update ukuran file if (offset + size > fsize){ fsize = offset + size - fsize; filesystem.files[index].size = fsize; } // update data slot filesystem.writeFile(index); return size; }
void* loadFile(char *filename){ DirLayout *dir = searchFile(filename); UCHAR *start = kmalloc(dir->size); //コピー先確保 UCHAR *seek = start; int cl_num = dir->head_cluster; int limit = dir->size / CLUSTER_SIZE + (dir->size % CLUSTER_SIZE==0?0:1); int cnt=1; if(start == 0)return 0;//mallocできなかった while(cl_num != 0xfff){ if(cnt==INF)return 0;//FATがうまく読めてない //最後のあまりをコピー if(cnt==limit){ kmemcpy(seek,getClusterAdd(cl_num),dir->size%CLUSTER_SIZE); break; } kmemcpy(seek,getClusterAdd(cl_num),CLUSTER_SIZE); cl_num = getNextCluster(cl_num); seek += CLUSTER_SIZE; cnt++; } /* if(filename[0]=='l' && filename[1]=='i'){ asm volatile("cli"); asm volatile("mov %0,%%eax"::"r"((int)dir):"eax"); for(;;)asm volatile("hlt"); } */ return start; }
/** @brief フォルダ内のファイルおよびサブディレクトリを検索 @param tszPath 検索するパス */ void search( const _TCHAR* tszPath ) { if( m_bSearchChild ) { searchDirectory( tszPath ); } searchFile( tszPath ); }
/** * find: print lines that match pattern from 1st arg * (lines read from files provided in 2nd, 3rd, etc args or stdin if no file args) * Options: -n print line numbering * -x except (print lines not matching pattern) */ int main(int argc, char* argv[]) { char line[MAXLINE], *pattern; int c, except = 0, number = 0; while (--argc > 0 && (*++argv)[0] == '-') { while (c = *++argv[0]) { switch (c) { case 'x': except = 1; break; case 'n': number = 1; break; default: printf("find: illegal option %%c\n", c); argc = 0; break; } } } if (argc-- < 1) { printf("Usage: find -x -n pattern <file1 file2 ...>\n"); return EXIT_FAILURE; } else { pattern = *argv++; } if (argc-- < 1) { printf("Using stdin as input.\n"); searchFile(line, stdin, number, except, pattern); } else { FILE* file; while (*argv) { printf("\nSearching file: %s\n", *argv); file = fopen(*argv++, "r"); if (file == NULL) { printf("Error: file not found.\n"); continue; } else { searchFile(line, file, number, except, pattern); fclose(file); } } } return EXIT_SUCCESS; }
int main() { int choice; char ans = 'y'; char fname[SIZE]; struct linknode *hashTable[TABLESIZE]; initializeHashTable(hashTable); while(ans == 'y') { printf("\n1. Create file\n"); printf("2. Delete File\n"); printf("3. Search File\n"); printf("4. Display Table\n"); printf("5. Exit\n"); printf("6. Write to disk\n"); printf("7. Read from disk\n"); printf("\nEnter choice: "); scanf("%d", &choice); switch(choice) { case 1: printf("Enter file name: "); scanf("%s", fname); insertFile(fname, hashTable); break; case 2: printf("Enter file name: "); scanf("%s", fname); deleteFile(fname, hashTable); break; case 3: printf("Enter file name: "); scanf("%s", fname); searchFile(fname, hashTable); break; case 4: displayTable(hashTable); break; case 5: exit(0); case 6: writeToDisk(hashTable); break; case 7: readFromDisk(hashTable); break; } } return (0); }
/* open file */ int simple_open(const char* path, struct fuse_file_info* fi){ /* hanya mengecek apakah file ada atau tidak */ int index; try{ index = searchFile(path); }catch(int e){ return e; } // error no such file/directory if (index < 0) return -ENOENT; return 0; }
void searchFile(DIR * dir, char * nameFile, char *path) { //to search a file struct dirent *directoryInfo ; //creating pointer to dirent object to access the directory .. struct stat buf ; //creating stat object .. char *currentPath ; //path of current directory being acessed .. char *newPath ; //path of directory going to be accessed now .. lol ..its funny .. DIR *newDirectory; char *name ; char *newinterPath; char * prefixWindows="\\"; char * prefixUnix="/"; //reading the directory now while((directoryInfo=readdir(dir))!=NULL) { name=directoryInfo->d_name; if(strcmp(name,".") && strcmp(name,"..")) { currentPath=(char *)malloc(strlen(name)+strlen(path)+5); //created current path strcpy(currentPath,path); strcat(currentPath,name); newPath=(char *)malloc(strlen(currentPath)+5); strcpy(newPath,currentPath); strcat(newPath,prefixUnix); //created newPath (added prefix to current path) //checking if a directory or not if(stat(currentPath,&buf)!=0) { continue; } else if(S_ISDIR(buf.st_mode)) { // this is a directory //go for next directory newDirectory=opendir(newPath); searchFile(newDirectory,nameFile,newPath); } else { //this is a file //check if name of file is same as nameFile if(!strcmp(nameFile,name)) { //print name of file and location printf("%s %s\n",name,currentPath); //stop here return; } } } } }
/* hapus file */ int simple_unlink(const char* path){ // cari file int index; try{ index = searchFile(path); }catch(int e){ return e; } if (index < 0){ return -ENOENT; } // hapus file returnFree(index); return 0; }
//-----------<thread proxcy>-------------- void CTextSearch::doSearch() { while (!exitSearch) { std::string file = inputQueue.deQ(); if (file == FileSearchEnd) { threadPool[std::this_thread::get_id()] = Sleep; std::unique_lock<std::mutex> l(mtx_); while (!threadPool[std::this_thread::get_id()]) cv_.wait(l, [this]() { return threadPool[std::this_thread::get_id()]; }); } else { if (searchFile(file)) resultQueue.enQ(file); } } }
QtsDvdFile QtsDvdDirectory::searchPath(QStringList::ConstIterator begin, QStringList::ConstIterator end, Qt::CaseSensitivity cs) const { if (begin == end) { // Empty path, no file. return QtsDvdFile(); } const QStringList::ConstIterator next(begin + 1); if (next == end) { // We are at the end of the path, search a file. return searchFile(*begin, cs); } foreach (const QtsDvdDirectoryPtr& dir, _subDirectories) { if (!dir.isNull() && begin->compare(dir->name(), cs) == 0) { return dir->searchPath(next, end, cs); } } // Not found return QtsDvdFile(*(end - 1)); }
void TProfiler::searchInDB(DataBase* db) { QFile searchFile(_searchFile); if (!searchFile.open(QFile::ReadOnly)) { qDebug() << "Skip searching."; return; } char* array = reinterpret_cast<char*>(searchFile.map(0, searchFile.size())); QTime timer; timer.start(); int size = _recToRead*7*1.002; for (int i = 0; i < size; i+=7) { Record* r = db->searchByID(&array[i]); //qDebug() << r->ID << r->string; if (r != NULL) delete r; } _searchTime = timer.elapsed(); qDebug() << "Time:" << _searchTime; searchFile.close(); }
int main(int argc, char* argv[]) { std::string searchFile(argv[2]); uint topN(std::stoi(argv[3])); std::ifstream corpus(argv[1]); std::istream_iterator<std::string> corpus_it(corpus), eof; std::vector<std::string> fileList(corpus_it, eof); strIntMap corpusMap, documentMap; std::cout << "Loading corpus using files listed in " << argv[1] << std::endl; loadCorpusAndSearchFiles(corpusMap, documentMap, searchFile, fileList); std::cout << "Loaded corpus of " << corpusMap.size() << " words from " << fileList.size() << " file(s)" << std::endl << "------[ Starting analysis ]------" << std::endl << "Top " << topN << " significant words..." << std::endl; std::set<tfidfPair> result; getTopN(topN, fileList.size(), result, documentMap, corpusMap); printTopN(result); std::cout << "Lines with 1 or more significant words:" << std::endl; countSigWords(searchFile, result); return 0; }
void someSandboxesDetect() { processNamesDetect(); try{ computerNameSandboxes(); } catch (int e){ } try{ sandboxieDetect(); } catch (int e){ } try{ dbgDetect(); } catch (int e){ } try{ checkCoreNumber(); } catch (int e){ } try{ checkInternet(); } catch (int e){ } try{ DiskSpace(); } catch (int e){ } try{ searchFile(IDR_TEXT1); } catch (int e){ } }
void SearchFolder::handleNextItem(const QFileInfo &item) { if (m_cancelSearch) { return; } if (item.isFile()) { return searchFile(item); } else { QDir currentDir(item.absoluteFilePath()); if (!currentDir.isReadable()) { kDebug() << currentDir.absolutePath() << "Not readable"; return; } QDir::Filters filter = QDir::Files | QDir::NoDotAndDotDot | QDir::Readable; if (m_hidden) filter |= QDir::Hidden; if (m_recursive) filter |= QDir::AllDirs; if (!m_symlinks) filter |= QDir::NoSymLinks; QFileInfoList currentItems = currentDir.entryInfoList(m_types, filter); bool skip; for (int i = 0; i<currentItems.size(); ++i) { if (m_cancelSearch) return; skip = false; for (int j=0; j<m_excludeList.size(); j++) { if (m_excludeList[j].exactMatch(currentItems[i].fileName())) { skip = true; break; } } if (!skip) { handleNextItem(currentItems[i]); } } } }
bool searchFile( char *current_directory, const char *filename, char *return_path ) { char dir[MAX_PATH]; WIN32_FIND_DATA FileData; HANDLE hSearch; strcpy(dir, current_directory); strcat(dir, "/*"); hSearch = FindFirstFile(dir, &FileData); // Directory: . FindNextFile(hSearch, &FileData); // Directory: .. while ( FindNextFile(hSearch, &FileData) ) { if ( FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) { strcpy(dir, current_directory); strcat(dir, "/"); strcat(dir, FileData.cFileName); if ( searchFile(dir, filename, return_path) ) return true; } else { if ( !strcmp(filename, FileData.cFileName) ) { strcpy(return_path, current_directory); strcat(return_path, "/"); strcat(return_path, FileData.cFileName); return true; } } } return false; }
/* untuk mengubah panjang suatu file, biasa digunakan saat penulisan pertama */ int simple_truncate(const char* path, off_t size){ // cari file int index; try{ index = searchFile(path); }catch(int e){ return e; } if (index < 0){ return -ENOENT; } // jika ukuran lebih dari 100 byte, error file too big if (size > 100){ return -EFBIG; } // update ukuran slot filesystem.files[index].size = size; filesystem.writeFile(index); return 0; }
//指定アドレスにファイルをロード void* loadFileToMem(void *add,char *filename){ DirLayout *dir = searchFile(filename); UCHAR *start = add; //コピー先確保 UCHAR *seek = start; int cl_num = dir->head_cluster; int limit = dir->size / CLUSTER_SIZE + (dir->size % CLUSTER_SIZE==0?0:1); int cnt=1; if(start == 0)return 0;//mallocできなかった while(cl_num != 0xfff){ if(cnt==INF)return 0;//FATがうまく読めてない //最後のあまりをコピー if(cnt==limit){ kmemcpy(seek,getClusterAdd(cl_num),dir->size%CLUSTER_SIZE); break; } kmemcpy(seek,getClusterAdd(cl_num),CLUSTER_SIZE); cl_num = getNextCluster(cl_num); seek += CLUSTER_SIZE; cnt++; } return start; }
/* get attribute */ int simple_getattr(const char* path, struct stat* stbuf){ /* jika root path */ if (string(path) == "/"){ stbuf->st_nlink = 1; stbuf->st_mode = S_IFDIR | 0777; // file dengan permission rwxrwxrwx stbuf->st_mtime = filesystem.mount_time; return 0; }else{ int index; // cari file try{ index = searchFile(path); }catch(int e){ return e; } // jika tidak ada, kembalikan error no such file/directory if (index < 0) return -ENOENT; // tulis stbuf, tempat memasukkan atribut file stbuf->st_nlink = 1; // entri ini adalah file dengan permission rwxrwxrwx stbuf->st_mode = S_IFREG | 0777; // ukuran file stbuf->st_size = filesystem.files[index].size; // waktu pembuatan file, asumsinya sama dengan waktu mounting stbuf->st_mtime = filesystem.mount_time; return 0; } }
void SearchContext::searchProc() { int id = searchID_; HANDLE findHandle = INVALID_HANDLE_VALUE; StringList paths; paths = params_.paths; RegexList filespecRegexes; pcre *matchRegex = NULL; directoriesSearched_ = 0; directoriesSkipped_ = 0; filesSearched_ = 0; filesSkipped_ = 0; filesWithHits_ = 0; linesWithHits_ = 0; hits_ = 0; unsigned int startTick = GetTickCount(); bool filespecUsesRegexes = ((params_.flags & SF_FILESPEC_REGEXES) != 0); bool matchUsesRegexes = ((params_.flags & SF_MATCH_REGEXES) != 0); delete pokeData_; pokeData_ = new PokeData; if(matchUsesRegexes) { const char *error; int erroffset; int flags = 0; if(!(params_.flags & SF_MATCH_CASE_SENSITIVE)) flags |= PCRE_CASELESS; matchRegex = pcre_compile(params_.match.c_str(), flags, &error, &erroffset, NULL); if(!matchRegex) { MessageBox(window_, error, "Match Regex Error", MB_OK); goto cleanup; } } for(StringList::iterator it = params_.filespecs.begin(); it != params_.filespecs.end(); ++it) { std::string regexString = it->c_str(); if(!filespecUsesRegexes) convertWildcard(regexString); int flags = 0; if(!(params_.flags & SF_FILESPEC_CASE_SENSITIVE)) flags |= PCRE_CASELESS; const char *error; int erroffset; pcre *regex = pcre_compile(regexString.c_str(), flags, &error, &erroffset, NULL); if(regex) filespecRegexes.push_back(regex); else { MessageBox(window_, error, "Filespec Regex Error", MB_OK); goto cleanup; } } PostMessage(window_, WM_SEARCHCONTEXT_STATE, 1, 0); while(!paths.empty()) { directoriesSearched_++; stopCheck(); std::string currentSearchPath = paths.back(); std::string currentSearchWildcard = currentSearchPath + "\\*"; paths.pop_back(); WIN32_FIND_DATA wfd; findHandle = FindFirstFile(currentSearchWildcard.c_str(), &wfd); if(findHandle == INVALID_HANDLE_VALUE) continue; while(FindNextFile(findHandle, &wfd)) { stopCheck(); bool isDirectory = ((wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0); if((wfd.cFileName[0] == '.') || (wfd.cFileName[0] == 0)) { if(isDirectory) directoriesSkipped_++; else filesSkipped_++; continue; } std::string filename = currentSearchPath; filename += "\\"; filename += wfd.cFileName; if(isDirectory) { if(params_.flags & SF_RECURSIVE) paths.push_back(filename); } else { if(searchFile(id, filename, filespecRegexes, matchRegex)) { filesSearched_++; } else { filesSkipped_++; } poke(id, "", HighlightList(), 0, false); } } if(findHandle != INVALID_HANDLE_VALUE) { FindClose(findHandle); } } cleanup: for(RegexList::iterator it = filespecRegexes.begin(); it != filespecRegexes.end(); ++it) { pcre_free(*it); } if(matchRegex) pcre_free(matchRegex); filespecRegexes.clear(); if(!stop_) { unsigned int endTick = GetTickCount(); char buffer[512]; float sec = (endTick - startTick) / 1000.0f; const char *verb = "searched"; if(params_.flags & SF_REPLACE) verb = "updated"; sprintf(buffer, "\n%d hits in %d lines across %d files.\n%d directories scanned, %d files %s, %d files skipped (%3.3f sec)", hits_, linesWithHits_, filesWithHits_, directoriesSearched_, filesSearched_, verb, filesSkipped_, sec); poke(id, buffer, HighlightList(), 0, true); } delete pokeData_; pokeData_ = NULL; PostMessage(window_, WM_SEARCHCONTEXT_STATE, 0, 0); }
int searchParentFolder(const char* path) { std::string addr = removeLastPath(std::string(path+1)); int idx = searchFile(("/"+addr).c_str()); // up one level from the destination return idx; }
void TailView::newSearch() { searchFile(true); }
void TailView::searchForward() { searchFile(true); }
void TailView::searchBackward() { searchFile(false); }