X-Git-Url: http://sigaev.ru/git/gitweb.cgi?p=ftsbench.git;a=blobdiff_plain;f=finnegan.c;fp=finnegan.c;h=18630bc3f34ea4b5562b5953fde291acbeb493c2;hp=efb0a5a1d4e404f5c13d5de632fb47e34793fa39;hb=1e58e6abeab12d724c3d3a8a67394a38324767a3;hpb=963707b86d1b7c29ce3c62fbb11eebbc4de04dd7 diff --git a/finnegan.c b/finnegan.c index efb0a5a..18630bc 100644 --- a/finnegan.c +++ b/finnegan.c @@ -60,10 +60,9 @@ no_newline(char *filename) FILE *fp; int c , cnt = 0; - if ((fp = fopen(filename, "r")) == NULL) { - fprintf(stderr,"Cannot open %s\n", filename); - exit(1); - } + if ((fp = fopen(filename, "r")) == NULL) + fatal("Cannot open %s\n", filename); + while ((c = getc(fp)) != EOF) if (c == '\n') cnt += 1; @@ -79,22 +78,18 @@ build_word_array(char *filename) FILE *fp; int i , temp_cfreq = 0; - if ((fp = fopen(filename, "r")) == NULL) { - fprintf(stderr,"Cannot open %s\n", filename); - exit(1); - } + if ((fp = fopen(filename, "r")) == NULL) + fatal("Cannot open %s\n", filename); + a = (struct word_info *)malloc(no_of_words * sizeof(struct word_info)); - if (!a) { - fprintf(stderr,"Can't allocate %d bytes\n", no_of_words * sizeof(struct word_info)); - exit(1); - } + if (!a) + fatal("Can't allocate %d bytes\n", no_of_words * sizeof(struct word_info)); + for (i = 0; i < no_of_words; i++) { fscanf(fp, "%s", buf); /* store word in temporary buffer */ a[i].word = strdup(buf); - if (!a[i].word) { - fprintf(stderr,"strdup failed\n"); - exit(1); - } + if (!a[i].word) + fatal("strdup failed\n"); fscanf(fp, "%d", &a[i].freq); a[i].word_len = strlen(a[i].word); a[i].cum_freq = temp_cfreq; @@ -112,11 +107,12 @@ build_doc_array(char *filename) FILE *fp; int i , temp_cfreq = 0; - if ((fp = fopen(filename, "r")) == NULL) { - fprintf(stderr,"Cannot open %s\n", filename); - exit(1); - } + if ((fp = fopen(filename, "r")) == NULL) + fatal("Cannot open %s\n", filename); + d = (struct doc_info *)malloc(no_of_docs * sizeof(struct doc_info)); + if ( !d ) + fatal("Can't allocate %d bytes\n", no_of_docs * sizeof(struct doc_info)); for (i = 0; i < no_of_docs; i++) { fscanf(fp, "%d", &d[i].doc_len); fscanf(fp, "%d", &d[i].doc_freq); @@ -230,10 +226,8 @@ generate_querywords() { void finnegan_init(char *lex_file, char *doc_file, int quiet) { - if ( isInited ) { - fprintf(stderr,"finnegan is already inited\n"); - exit(1); - } + if ( isInited ) + fatal("finnegan is already inited\n"); if (!quiet) { printf("Initialize text generator with:\n");