Commit 28170238 authored by GUYOT DOMINIQUE's avatar GUYOT DOMINIQUE
Browse files

Initial def of struct parser

parent 2bf683a9
...@@ -7,22 +7,60 @@ ...@@ -7,22 +7,60 @@
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
#include <string_view> #include <string_view>
#include <iostream>
#include <vector>
using namespace::std;
int main(int argc, char** argv){ struct Parser{
struct stat sfd;
int fd; vector<string_view> chunks;
size_t size;
char* mmfile;
int i;
fd = open(argv[1], O_RDONLY);
fstat(fd,&sfd);
size = sfd.st_size;
mmfile = (char *)mmap(NULL, size, PROT_READ, MAP_PRIVATE | MAP_DENYWRITE, fd, 0);
close(fd);
Parser(char** argv){
struct stat sfd;
int fd;
size_t size;
size_t pos = 0;
size_t chunk_size;
char* mmfile;
fd = open(argv[1], O_RDONLY);
fstat(fd,&sfd);
size = sfd.st_size;
mmfile = (char *)mmap(NULL, size, PROT_READ, MAP_PRIVATE | MAP_DENYWRITE, fd, 0);
close(fd);
string_view mapview(mmfile,size);
string_view sentinel(">");
string_view chunk;
while(pos < mapview.size()){
pos = mapview.find(sentinel, pos);
chunk_size = mapview.find(sentinel, pos + sentinel.size()) - pos;
chunk = mapview.substr(pos, chunk_size);
chunks.push_back(chunk);
pos += chunk_size;
}
chunks.shrink_to_fit();
}
~Parser(){
}
string_view get_chunk(size_t i){
return(chunks[i]);
}
};
int main(int argc, char** argv){
Parser* P = new Parser(argv);
cout << P->get_chunk(4);
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment