comparison regexParser/sequentialSearch.cc @ 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 6ed6f385205e
comparison
equal deleted inserted replaced
231:d67649929e96 232:1a34e702776a
3 #include <unistd.h> 3 #include <unistd.h>
4 #include <fcntl.h> 4 #include <fcntl.h>
5 #include <sys/stat.h> 5 #include <sys/stat.h>
6 #include <sys/mman.h> 6 #include <sys/mman.h>
7 7
8 #include "sequentialSearch.h" 8 #include "fileread.h"
9 9
10 void state1(Buffer buff); 10 void state1(Buffer buff);
11 11
12 void stateSkip(Buffer buff) { 12 void stateSkip(Buffer buff) {
13 buff.matchBegin = buff.buffptr; 13 buff.matchBegin = buff.buffptr;
16 16
17 void stateMatch(Buffer buff) { 17 void stateMatch(Buffer buff) {
18 fwrite(buff.matchBegin,buff.buffptr-buff.matchBegin,1,stdout); 18 fwrite(buff.matchBegin,buff.buffptr-buff.matchBegin,1,stdout);
19 puts("\n"); 19 puts("\n");
20 stateSkip(buff); 20 stateSkip(buff);
21 }
22
23 st_mmap_t createSt_mmap(char* filename,int fd) {
24 st_mmap_t st_mmap;
25 int map = MAP_PRIVATE;
26 struct stat sb;
27 if ((fd=open(filename,O_RDONLY,0666))==0) {
28 perror("");
29 fprintf(stderr,"can't open %s\n",filename);
30 }
31
32 if (fstat(fd,&sb)) {
33 perror("");
34 fprintf(stderr,"can't fstat %s\n",filename);
35 }
36 st_mmap.size = sb.st_size;
37 unsigned char *file_mmap = (unsigned char*)mmap(NULL,st_mmap.size,PROT_WRITE|PROT_READ,map,fd,(off_t)0);
38 if (file_mmap == NULL) {
39 perror("");
40 fprintf(stderr,"cannot mmap %s\n",filename);
41 }
42 st_mmap.file_mmap = file_mmap;
43 return st_mmap;
44 }
45
46 Buffer createBuffer(st_mmap_t st_mmap) {
47 Buffer buff;
48 buff.buff = buff.buffptr = buff.matchBegin = st_mmap.file_mmap;
49 buff.buffend = buff.buff + st_mmap.size;
50 return buff;
51 } 21 }
52 22
53 #include "state.cc" 23 #include "state.cc"
54 int main(int argc, char **argv) { 24 int main(int argc, char **argv) {
55 char *filename; 25 char *filename;