// Like 'search', but do in parallel across 2 nodes with 2 threads each int psearch(uint8_t *str, int len, const unsigned char *hash) { if (len <= BLOCKLEN) { search_args a = { {0}, len, 0, len, hash }; strcpy((char*)a.str, (char*)str); search(&a); return found; } // Iterate over blocks, searching 4 blocks at a time in parallel int done = 0; do { int i; search_args a[nthreads]; for (i = 0; i < nthreads; i++) { strcpy((char*)a[i].str, (char*)str); //cprintf("forking child to check '%s'\n", str); a[i].len = len; a[i].lo = 0; a[i].hi = BLOCKLEN; a[i].hash = hash; bench_fork(i, search, &a[i]); done |= incstr(str, BLOCKLEN, len); } for (i = 0; i < nthreads; i++) bench_join(i); // collect results if (found) return 1; } while (!done); return 0; // no match at this string length }
//--------------------------------------- void FRDialog::replace() { QString s = ""; //holds list of errors bool er = false; if (ui->LEReplace -> text().isEmpty()) { s.append(tr("- Please enter a replace text.\n")); er = true; } if (er) { QMessageBox::critical(this, tr("Replace error"), s); } else { // файлы найдены // получаем список файлов // открываем файлы и делаем QString.replace for (int row = 0; row < ui->tableFiles->rowCount(); row++) { QString namebook = ui->tableFiles->item(row,0)->text(); // namebook = bookfiles.at(bookfiles.indexOf(namebook)); // qDebug() << " at = " << "" << " index = " << ui->cBBook->findText(namebook) // << " bookfiles = " << bookfiles // << " namebook = " << namebook; namebook = bookfiles.at(ui->cBBook->findText(namebook)); QString namechapter = incstr(QString(ui->tableFiles->item(row,1)->text()) .remove(tr("Chapter ")) , GL_LENGT_ITEM_STRING, "_"); // составляем путь до файла QString filepath = Config::configuration()->CurPrjDir() + "/book_" + namebook+ "_chapter_" + namechapter +".htm"; // заменяем в файлах // qDebug() << " filepath = " << filepath; replaceTextOfFile(filepath, ui->LEFind->text(), ui->LEReplace->text()); } } }
// Search all strings of length 'len' for one that hashes to 'hash'. void * search(void *args) { search_args *a = args; assert(a->lo < a->hi); assert(a->hi <= a->len); //cprintf("searching strings starting from '%s'\n", a->str); do { unsigned char h[16]; //cprintf("checking '%s'\n", a->str); MD5_CTX ctx; MD5Init(&ctx); MD5Update(&ctx, a->str, a->len); MD5Final(h, &ctx); if (memcmp(h, a->hash, 16) == 0) { strcpy(out, (char*)a->str); found = 1; return NULL; } } while (!incstr(a->str, a->lo, a->hi)); return NULL; }
//--------------------------------------- void FRDialog::find() { QString s = ""; //holds list of errors bool er = false; if (ui->LEFind -> text().isEmpty()) { s.append(tr("- Please enter a find text.\n")); er = true; } if (er) { QMessageBox::critical(this, tr("Find error"), s); } else { ui->tableFiles->setRowCount(0); QString fileName = ""; QString text = ui->LEFind->text(); QString correctName; if (ui->cBBook->currentIndex() == 0) correctName = ""; if (ui->cBBook->currentIndex() != 0) { if (ui->cBChapter->currentIndex() == 0) { QString namebook = bookfiles.at(ui->cBBook->currentIndex()); correctName = "book_" + namebook; } else { QString namebook = bookfiles.at(ui->cBBook->currentIndex()); QString namechapter = ui->cBChapter->currentText(); namechapter .remove(tr("Chapter ")); namechapter = incstr(namechapter,GL_LENGT_ITEM_STRING, "_"); correctName = "book_"+namebook+"_chapter_"+namechapter; } } currentDir = Config::configuration()->CurPrjDir();/*QDir(correctName);*/ QStringList files1; if (fileName.isEmpty()) fileName = "*"; files1 = currentDir.entryList(QStringList(fileName), QDir::Files | QDir::NoSymLinks); QStringList files; if (!correctName.isEmpty()) { for (int i = 0; i < files1.size(); i++) { if(files1.at(i).indexOf(correctName) != -1) { files << files1.at(i); } } } else { files = files1; } if (!text.isEmpty()) files = findFiles(files, text); QStringList bookList = files; QStringList chapterList = files; updateItemforTable(bookList, chapterList); // qDebug() << "booklist = " << bookList // << " chapterlist = " << chapterList // << " bookfiles = " << bookfiles; showFiles(bookList, chapterList); } }