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, 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");