comparison 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
comparison
equal deleted inserted replaced
225:0c28ff35b4f0 226:b4022ba23de5
1 #include <stdio.h>
2 #include <string.h>
3 #include <unistd.h>
4 #include <fcntl.h>
5 #include <sys/stat.h>
6 #include <sys/mman.h>
7 #include <sys/types.h>
8
9 typedef struct bufferList {
10 unsigned char buff;
11 unsigned char buffptr;
12 unsigned char buffend;
13 unsigned char matchBegin;
14 } BufferList, *BufferListPtr;
15
16 typedef struct {
17 caddr_t file_mmap;
18 off_t size;
19 } st_mmap_t;
20
21 #include "state.cc"
22 int main(int argc, char **argv) {
23 char *filename;
24 for (int i = 1; i < argc; i++) {
25 if (strcmp(argv[i],"-file") == 0) {
26 filename = argv[i+1]; i++;
27 }
28 }
29
30 int map = MAP_PRIVATE;
31 st_mmap_t st_mmap;
32 struct stat sb;
33 int fd;
34 if ((fd=open(filename,O_RDONLY,0666))==0) {
35 fprintf(stderr,"can't open %s\n",filename);
36 }
37
38 if (fstat(fd,&sb)) {
39 fprintf(stderr,"can't fstat %s\n",filename);
40 }
41 st_mmap.size = sb.st_size;
42 unsigned char *file_mmap = mmap(NULL,st_mmap.size,PROT_WRITE|PROT_READ,map,fd,(off_t)0);
43
44 BufferList buff;
45 buff.buff = buff.buffptr = buff.matchBegin = file_mmap;
46 buff.buffend = buff.buff + st_mmap.size;
47 stateSkip(buff);
48 close(fd);
49 return 0;
50 }