Mercurial > hg > Applications > Grep
comparison regexParser/sequentialSearch.cc @ 227:8be58af605da
fix getNext()
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 15 Jan 2016 19:11:35 +0900 |
parents | b4022ba23de5 |
children | 2081b9d6a179 |
comparison
equal
deleted
inserted
replaced
226:b4022ba23de5 | 227:8be58af605da |
---|---|
5 #include <sys/stat.h> | 5 #include <sys/stat.h> |
6 #include <sys/mman.h> | 6 #include <sys/mman.h> |
7 #include <sys/types.h> | 7 #include <sys/types.h> |
8 | 8 |
9 typedef struct bufferList { | 9 typedef struct bufferList { |
10 unsigned char buff; | 10 unsigned char *buff; |
11 unsigned char buffptr; | 11 unsigned char *buffptr; |
12 unsigned char buffend; | 12 unsigned char *buffend; |
13 unsigned char matchBegin; | 13 unsigned char *matchBegin; |
14 } BufferList, *BufferListPtr; | 14 } BufferList, *BufferListPtr; |
15 | 15 |
16 typedef struct { | 16 typedef struct { |
17 caddr_t file_mmap; | 17 caddr_t file_mmap; |
18 off_t size; | 18 off_t size; |
19 } st_mmap_t; | 19 } st_mmap_t; |
20 | |
21 void state1(BufferList buff); | |
22 | |
23 void stateSkip(BufferList buff) { | |
24 buff.matchBegin = buff.buffptr; | |
25 state1(buff); | |
26 } | |
27 | |
28 void stateMatch(BufferList buff) { | |
29 fwrite(buff.matchBegin,buff.buffptr-buff.matchBegin,1,stdout); | |
30 puts("\n"); | |
31 stateSkip(buff); | |
32 } | |
20 | 33 |
21 #include "state.cc" | 34 #include "state.cc" |
22 int main(int argc, char **argv) { | 35 int main(int argc, char **argv) { |
23 char *filename; | 36 char *filename; |
24 for (int i = 1; i < argc; i++) { | 37 for (int i = 1; i < argc; i++) { |
30 int map = MAP_PRIVATE; | 43 int map = MAP_PRIVATE; |
31 st_mmap_t st_mmap; | 44 st_mmap_t st_mmap; |
32 struct stat sb; | 45 struct stat sb; |
33 int fd; | 46 int fd; |
34 if ((fd=open(filename,O_RDONLY,0666))==0) { | 47 if ((fd=open(filename,O_RDONLY,0666))==0) { |
48 perror(""); | |
35 fprintf(stderr,"can't open %s\n",filename); | 49 fprintf(stderr,"can't open %s\n",filename); |
36 } | 50 } |
37 | 51 |
38 if (fstat(fd,&sb)) { | 52 if (fstat(fd,&sb)) { |
53 perror(""); | |
39 fprintf(stderr,"can't fstat %s\n",filename); | 54 fprintf(stderr,"can't fstat %s\n",filename); |
40 } | 55 } |
41 st_mmap.size = sb.st_size; | 56 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); | 57 unsigned char *file_mmap = (unsigned char*)mmap(NULL,st_mmap.size,PROT_WRITE|PROT_READ,map,fd,(off_t)0); |
58 if (file_mmap == NULL) { | |
59 perror(""); | |
60 fprintf(stderr,"cannot mmap %s\n",filename); | |
61 } | |
43 | 62 |
44 BufferList buff; | 63 BufferList buff; |
45 buff.buff = buff.buffptr = buff.matchBegin = file_mmap; | 64 buff.buff = buff.buffptr = buff.matchBegin = file_mmap; |
46 buff.buffend = buff.buff + st_mmap.size; | 65 buff.buffend = buff.buff + st_mmap.size; |
47 stateSkip(buff); | 66 stateSkip(buff); |