Mercurial > hg > Applications > Grep
changeset 232:1a34e702776a
add fileread.cc
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 19 Jan 2016 13:16:35 +0900 |
parents | d67649929e96 |
children | 6d0a0126ddda |
files | regexParser/fileread.cc regexParser/fileread.h regexParser/grepWalk.cc regexParser/grepWalk.h regexParser/main.cc regexParser/regexParser.h regexParser/sequentialSearch.cc regexParser/sequentialSearch.h |
diffstat | 8 files changed, 72 insertions(+), 52 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/regexParser/fileread.cc Tue Jan 19 13:16:35 2016 +0900 @@ -0,0 +1,40 @@ +#include <stdio.h> +#include <string.h> +#include <unistd.h> +#include <fcntl.h> +#include <sys/stat.h> +#include <sys/mman.h> + +#include "sequentialSearch.h" +#include "fileread.h" + +st_mmap_t createSt_mmap(char* filename,int fd) { + st_mmap_t st_mmap; + int map = MAP_PRIVATE; + struct stat sb; + if ((fd=open(filename,O_RDONLY,0666))==0) { + perror(""); + fprintf(stderr,"can't open %s\n",filename); + } + + if (fstat(fd,&sb)) { + perror(""); + fprintf(stderr,"can't fstat %s\n",filename); + } + st_mmap.size = sb.st_size; + unsigned char *file_mmap = (unsigned char*)mmap(NULL,st_mmap.size,PROT_WRITE|PROT_READ,map,fd,(off_t)0); + if (file_mmap == NULL) { + perror(""); + fprintf(stderr,"cannot mmap %s\n",filename); + } + st_mmap.file_mmap = file_mmap; + return st_mmap; +} + +Buffer createBuffer(st_mmap_t st_mmap) { + Buffer buff; + buff.buff = buff.buffptr = buff.matchBegin = st_mmap.file_mmap; + buff.buffend = buff.buff + st_mmap.size; + return buff; +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/regexParser/fileread.h Tue Jan 19 13:16:35 2016 +0900 @@ -0,0 +1,4 @@ +#include "regexParser.h" + +extern st_mmap_t createSt_mmap(char* filename, int fd); +extern Buffer createBuffer(st_mmap_t st_mmap);
--- a/regexParser/grepWalk.cc Tue Jan 19 12:54:11 2016 +0900 +++ b/regexParser/grepWalk.cc Tue Jan 19 13:16:35 2016 +0900 @@ -1,9 +1,7 @@ #include <stdio.h> -#include "regexParser.h" -#include "sequentialSearch.h" #include "grepWalk.h" -void grepWalk(TransitionGeneratorPtr tg) { +void grepWalk(TransitionGeneratorPtr tg, Buffer buff) { }
--- a/regexParser/grepWalk.h Tue Jan 19 12:54:11 2016 +0900 +++ b/regexParser/grepWalk.h Tue Jan 19 13:16:35 2016 +0900 @@ -1,1 +1,4 @@ -extern void grepWalk(TransitionGeneratorPtr tg); +#include "regexParser.h" +#include "sequentialSearch.h" + +extern void grepWalk(TransitionGeneratorPtr tg, Buffer buff);
--- a/regexParser/main.cc Tue Jan 19 12:54:11 2016 +0900 +++ b/regexParser/main.cc Tue Jan 19 13:16:35 2016 +0900 @@ -5,12 +5,14 @@ #include "subsetConstruction.h" #include "node.h" #include "grepWalk.h" +#include "fileread.h" int main(int argc, char **argv) { bool generate = true; bool subset = false; bool generateSequentialSearch = false; + char *filename; RegexInfo ri; ri.stateNumber = 1; @@ -23,6 +25,8 @@ subset = true; } else if (strcmp(argv[i],"-seq") == 0) { generateSequentialSearch = true; + } else if (strcmp(argv[i],"-file") == 0) { + filename = argv[i+1]; i++; } } if (!ri.ptr) return 0; @@ -49,6 +53,11 @@ } } - grepWalk(tgv.tg); + if (filename != NULL) { + int fd = 0; + st_mmap_t st_mmap = createSt_mmap(filename,fd); + Buffer buff = createBuffer(st_mmap); + grepWalk(tgv.tg,buff); + } return 0; }
--- a/regexParser/regexParser.h Tue Jan 19 12:54:11 2016 +0900 +++ b/regexParser/regexParser.h Tue Jan 19 13:16:35 2016 +0900 @@ -106,6 +106,18 @@ unsigned char *tokenValue; int stateNumber; } RegexInfo, *RegexInfoPtr; + +typedef struct buffer { + unsigned char *buff; + unsigned char *buffptr; + unsigned char *buffend; + unsigned char *matchBegin; +} Buffer, *BufferPtr; + +typedef struct { + unsigned char* file_mmap; + off_t size; +} st_mmap_t; #endif extern NodePtr createNode(RegexInfoPtr ri,unsigned char type,CharClassPtr cc, NodePtr left, NodePtr right);
--- a/regexParser/sequentialSearch.cc Tue Jan 19 12:54:11 2016 +0900 +++ b/regexParser/sequentialSearch.cc Tue Jan 19 13:16:35 2016 +0900 @@ -5,7 +5,7 @@ #include <sys/stat.h> #include <sys/mman.h> -#include "sequentialSearch.h" +#include "fileread.h" void state1(Buffer buff); @@ -20,36 +20,6 @@ stateSkip(buff); } -st_mmap_t createSt_mmap(char* filename,int fd) { - st_mmap_t st_mmap; - int map = MAP_PRIVATE; - struct stat sb; - if ((fd=open(filename,O_RDONLY,0666))==0) { - perror(""); - fprintf(stderr,"can't open %s\n",filename); - } - - if (fstat(fd,&sb)) { - perror(""); - fprintf(stderr,"can't fstat %s\n",filename); - } - st_mmap.size = sb.st_size; - unsigned char *file_mmap = (unsigned char*)mmap(NULL,st_mmap.size,PROT_WRITE|PROT_READ,map,fd,(off_t)0); - if (file_mmap == NULL) { - perror(""); - fprintf(stderr,"cannot mmap %s\n",filename); - } - st_mmap.file_mmap = file_mmap; - return st_mmap; -} - -Buffer createBuffer(st_mmap_t st_mmap) { - Buffer buff; - buff.buff = buff.buffptr = buff.matchBegin = st_mmap.file_mmap; - buff.buffend = buff.buff + st_mmap.size; - return buff; -} - #include "state.cc" int main(int argc, char **argv) { char *filename;
--- a/regexParser/sequentialSearch.h Tue Jan 19 12:54:11 2016 +0900 +++ b/regexParser/sequentialSearch.h Tue Jan 19 13:16:35 2016 +0900 @@ -1,16 +0,0 @@ -#include <sys/types.h> - -typedef struct buffer { - unsigned char *buff; - unsigned char *buffptr; - unsigned char *buffend; - unsigned char *matchBegin; -} Buffer, *BufferPtr; - -typedef struct { - unsigned char* file_mmap; - off_t size; -} st_mmap_t; - -extern st_mmap_t createSt_mmap(char* filename, int fd); -extern Buffer createBuffer(st_mmap_t st_mmap);