summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c93
1 files changed, 90 insertions, 3 deletions
diff --git a/main.c b/main.c
index dc57337..9ab58fe 100644
--- a/main.c
+++ b/main.c
@@ -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