* further distributed without the permission of J. Zobel.
*/
+/*
+ * Cleanup and nonsignificant changes by teodor <teodor@sigaev.ru>
+ */
#include <stdio.h>
#include <stdlib.h>
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;
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;
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);
void
-finnegan_init(char *lex_file, char *doc_file) {
- if ( isInited ) {
- fprintf(stderr,"finnegan is already inited\n");
- exit(1);
+finnegan_init(char *lex_file, char *doc_file, int quiet) {
+ if ( isInited )
+ fatal("finnegan is already inited\n");
+
+ if (!quiet) {
+ printf("Initialize text generator with:\n");
+ printf("\tfile '%s' - lexeme's distribution\n", lex_file);
+ printf("\tfile '%s' - length's distribution\n", doc_file);
}
-
- printf("Initialize text generator with:\n");
- printf("\tfile '%s' - lexeme's distribution\n", lex_file);
- printf("\tfile '%s' - length's distribution\n", doc_file);
srnd(INITIAL_SEED);
no_of_words = no_newline(lex_file);
no_of_docs = no_newline(doc_file);