/* HTS_Model_clear: free pdfs and trees */ static void HTS_Model_clear(HTS_Model * model) { int i, j; HTS_Question *question, *next_question; HTS_Tree *tree, *next_tree; for (question = model->question; question; question = next_question) { next_question = question->next; HTS_Question_clear(question); HTS_free(question); } for (tree = model->tree; tree; tree = next_tree) { next_tree = tree->next; HTS_Tree_clear(tree); HTS_free(tree); } if (model->pdf) { for (i = 2; i <= model->ntree + 1; i++) { for (j = 1; j <= model->npdf[i]; j++) { HTS_free(model->pdf[i][j]); } model->pdf[i]++; HTS_free(model->pdf[i]); } model->pdf += 2; HTS_free(model->pdf); } if (model->npdf) { model->npdf += 2; HTS_free(model->npdf); } HTS_Model_initialize(model); }
/* HTS_Question_load: Load questions from file */ static HTS_Boolean HTS_Question_load(HTS_Question * question, HTS_File * fp) { char buff[HTS_MAXBUFLEN]; HTS_Pattern *pattern, *last_pattern; if (question == NULL || fp == NULL) return FALSE; /* get question name */ if (HTS_get_pattern_token(fp, buff) == FALSE) return FALSE; question->string = HTS_strdup(buff); question->head = NULL; /* get pattern list */ if (HTS_get_pattern_token(fp, buff) == FALSE) { free(question->string); question->string = NULL; return FALSE; } last_pattern = NULL; if (strcmp(buff, "{") == 0) { while (1) { if (HTS_get_pattern_token(fp, buff) == FALSE) { HTS_Question_clear(question); return FALSE; } pattern = (HTS_Pattern *) HTS_calloc(1, sizeof(HTS_Pattern)); if (question->head) last_pattern->next = pattern; else /* first time */ question->head = pattern; pattern->string = HTS_strdup(buff); pattern->next = NULL; if (HTS_get_pattern_token(fp, buff) == FALSE) { HTS_Question_clear(question); return FALSE; } if (!strcmp(buff, "}")) break; last_pattern = pattern; } } return TRUE; }