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

Modify dia and parser.

parent 58f46941
No preview for this file type
......@@ -6,10 +6,18 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string>
#include <string_view>
#include <iostream>
#include <vector>
#define TODO 0
#define RUNNING 1
#define FAILED 2
#define DONE 3
using namespace::std;
......@@ -17,37 +25,39 @@ using namespace::std;
struct Parser{
vector<string_view> chunks;
vector<int> states;
size_t index;
Parser(char** argv){
Parser(string input_file, string sentinel) : index(0){
struct stat sfd;
int fd;
char* mmfile;
size_t size;
size_t pos = 0;
size_t chunk_size;
char* mmfile;
fd = open(argv[1], O_RDONLY);
fd = open(input_file.c_str(), O_RDONLY);
fstat(fd,&sfd);
size = sfd.st_size;
mmfile = (char *)mmap(NULL, size, PROT_READ, MAP_PRIVATE | MAP_DENYWRITE, fd, 0);
mmfile = static_cast<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);
states.push_back(TODO);
chunks.push_back(chunk);
pos += chunk_size;
}
chunks.shrink_to_fit();
states.shrink_to_fit();
}
~Parser(){
//munmap(mmfile, size);
}
string_view get_chunk(size_t i){
......@@ -59,9 +69,10 @@ struct Parser{
/*
int main(int argc, char** argv){
Parser* P = new Parser(argv);
cout << P->get_chunk(4);
Parser* P = new Parser(string(argv[1]), string(">"));
cout << P->get_chunk(0);
delete(P);
}
*/
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