48 lines
1.3 KiB
C++
48 lines
1.3 KiB
C++
#include <iostream>
|
|
#include <fstream>
|
|
#include <cstring>
|
|
#include <unistd.h>
|
|
#include <signal.h>
|
|
#include <chrono>
|
|
|
|
using namespace std;
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
auto startmain = chrono::high_resolution_clock::now();
|
|
if(argc != 5)
|
|
{
|
|
cout <<"usage: ./partitioner.out <path-to-file> <pattern> <search-start-position> <search-end-position>\nprovided arguments:\n";
|
|
for(int i = 0; i < argc; i++)
|
|
cout << argv[i] << "\n";
|
|
return -1;
|
|
}
|
|
|
|
char *file_to_search_in = argv[1];
|
|
char *pattern_to_search_for = argv[2];
|
|
int len = sizeof(pattern_to_search_for);
|
|
int search_start_position = atoi(argv[3]);
|
|
int search_end_position = atoi(argv[4]);
|
|
int find = 0;
|
|
pid_t pid = getpid();
|
|
ifstream file(file_to_search_in, ios::binary);
|
|
int len2 = search_end_position - search_start_position;
|
|
string buffer;
|
|
buffer.resize(len2);
|
|
file.seekg(search_start_position);
|
|
file.read(&buffer[0], len2);
|
|
//TODO
|
|
auto a = buffer.find(pattern_to_search_for);
|
|
if(a != string::npos) {
|
|
cout << "[" << pid << "]" << " found at" << " " << a + search_start_position << endl;
|
|
}
|
|
else {
|
|
cout << "[" << pid << "]" << " didn't find\n";
|
|
}
|
|
|
|
auto endmain = std::chrono::high_resolution_clock::now();
|
|
chrono::duration<double> mainduration = endmain - startmain;
|
|
cout << mainduration.count() << endl;
|
|
return 0;
|
|
}
|