diff options
author | dianshi <dianshi@main.lv> | 2020-05-10 12:53:03 +0100 |
---|---|---|
committer | dianshi <dianshi@main.lv> | 2020-05-10 12:53:03 +0100 |
commit | a571b8c92b0ec149f7691e786671ac5939cbf3c5 (patch) | |
tree | 3d6e215584477cf08151d3ed7025663fbad2d5b8 /main.c | |
parent | 54da7a3169200cba754b176383ee35bf75401429 (diff) | |
download | MATCH-2-master.tar.gz MATCH-2-master.zip |
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 93 |
1 files changed, 90 insertions, 3 deletions
@@ -64,6 +64,8 @@ typedef struct match_params { char *fname; char *match_str; + int match_len; + int buf_size; int verbose; } match_params; @@ -73,17 +75,102 @@ void helper( char *progname ) printf("Usage: %s [OPTS]\n\n" " -f - input file\n" " -m - match string\n" + //" -b - set buffer size to read\n" " -v - more extra info in output\n" "Version: 0.0.1 \n" "\n" , progname); } -int main(int argc, const char *argv[]) +int main(int argc, char **argv) { - + int c; + int i; + int fd; + int text_len; + int ret; + + char *text = NULL; + + //search + rol_hash_isearch search; + + //parametrs + match_params mp; + + memset(&mp,0,sizeof(match_params)); + + while ( (c = getopt(argc, argv, "f:m:b:v")) != -1 ) + { + switch(c) + { + case 'f': + mp.fname = optarg; + break; + case 'm': + mp.match_str = optarg; + mp.match_len = strlen(optarg); + break; + case 'b': + mp.buf_size = atoi(optarg); + break; + case 'v': + mp.verbose = 1; + break; + default: + helper( argv[0] ); + exit(1); + } + } + + if (argc<2) + { + helper(argv[0]); + return -1; + } + + + if (mp.fname == NULL) + { + printf("Set filename\n"); + return -1; + } + + if (mp.match_str == NULL) + { + printf("Set search string\n"); + return -1; + } + + fd = file_open( mp.fname ); + if (fd<0) + { + printf("Couldnt open file %s\n", mp.fname); + + return -1; + } + + text_len = lseek(fd,0,SEEK_END); + lseek(fd, 0,SEEK_SET); + text = malloc(text_len); + //printf("Read %d bytes\n",read(fd,text,text_len)); + + ret = read(fd, text, text_len); + if (mp.verbose) + { + printf("Read %d bytes\n",ret); + } + + + rlsi_hash_init( &search, 10, 13); + while ((i = rlsi_hash_search(&search, mp.match_str, mp.match_len, text, text_len)) == 1) + { + //printf("Found smth %d\n",rlsi_hash_get(&search)); + printf("%d\n",rlsi_hash_get(&search)); + } + + file_close( fd ); - return 0; }
\ No newline at end of file |