Mercurial > hg > Applications > Grep
diff regexParser/sequentialSearch.cc @ 226:b4022ba23de5
add sequentialSearch
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 15 Jan 2016 17:53:11 +0900 |
parents | |
children | 8be58af605da |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/regexParser/sequentialSearch.cc Fri Jan 15 17:53:11 2016 +0900 @@ -0,0 +1,50 @@ +#include <stdio.h> +#include <string.h> +#include <unistd.h> +#include <fcntl.h> +#include <sys/stat.h> +#include <sys/mman.h> +#include <sys/types.h> + +typedef struct bufferList { + unsigned char buff; + unsigned char buffptr; + unsigned char buffend; + unsigned char matchBegin; +} BufferList, *BufferListPtr; + +typedef struct { + caddr_t file_mmap; + off_t size; +} st_mmap_t; + +#include "state.cc" +int main(int argc, char **argv) { + char *filename; + for (int i = 1; i < argc; i++) { + if (strcmp(argv[i],"-file") == 0) { + filename = argv[i+1]; i++; + } + } + + int map = MAP_PRIVATE; + st_mmap_t st_mmap; + struct stat sb; + int fd; + if ((fd=open(filename,O_RDONLY,0666))==0) { + fprintf(stderr,"can't open %s\n",filename); + } + + if (fstat(fd,&sb)) { + fprintf(stderr,"can't fstat %s\n",filename); + } + st_mmap.size = sb.st_size; + unsigned char *file_mmap = mmap(NULL,st_mmap.size,PROT_WRITE|PROT_READ,map,fd,(off_t)0); + + BufferList buff; + buff.buff = buff.buffptr = buff.matchBegin = file_mmap; + buff.buffend = buff.buff + st_mmap.size; + stateSkip(buff); + close(fd); + return 0; +}