Exemple #1
0
/* HTS_Tree_load: Load trees */
static void HTS_Tree_load(HTS_Tree * tree, FILE * fp, HTS_Question * question)
{
   char buff[HTS_MAXBUFLEN];
   HTS_Node *node, *last_node;

   HTS_get_pattern_token(fp, buff);
   node = (HTS_Node *) HTS_calloc(1, sizeof(HTS_Node));
   node->index = 0;
   tree->root = last_node = node;

   if (strcmp(buff, "{") == 0) {
      while (HTS_get_pattern_token(fp, buff), strcmp(buff, "}") != 0) {
         node = HTS_Node_find(last_node, atoi(buff));
         HTS_get_pattern_token(fp, buff);       /* load question at this node */

         node->quest = HTS_Question_find_question(question, buff);
         node->yes = (HTS_Node *) HTS_calloc(1, sizeof(HTS_Node));
         node->no = (HTS_Node *) HTS_calloc(1, sizeof(HTS_Node));

         HTS_get_pattern_token(fp, buff);
         if (HTS_is_num(buff))
            node->no->index = atoi(buff);
         else
            node->no->pdf = HTS_name2num(buff);
         node->no->next = last_node;
         last_node = node->no;

         HTS_get_pattern_token(fp, buff);
         if (HTS_is_num(buff))
            node->yes->index = atoi(buff);
         else
            node->yes->pdf = HTS_name2num(buff);
         node->yes->next = last_node;
         last_node = node->yes;
      }
   } else {
      node->pdf = HTS_name2num(buff);
   }
}
Exemple #2
0
/* HTS_Tree_load: Load trees */
static HTS_Boolean HTS_Tree_load(HTS_Tree * tree, HTS_File * fp, HTS_Question * question)
{
   char buff[HTS_MAXBUFLEN];
   HTS_Node *node, *last_node;

   if (tree == NULL || fp == NULL)
      return FALSE;

   if (HTS_get_pattern_token(fp, buff) == FALSE) {
      HTS_Tree_clear(tree);
      return FALSE;
   }
   node = (HTS_Node *) HTS_calloc(1, sizeof(HTS_Node));
   node->index = 0;
   tree->root = last_node = node;

   if (strcmp(buff, "{") == 0) {
      while (HTS_get_pattern_token(fp, buff) == TRUE && strcmp(buff, "}") != 0) {
         node = HTS_Node_find(last_node, atoi(buff));
         if (node == NULL) {
            HTS_Tree_clear(tree);
            return FALSE;
         }
         if (HTS_get_pattern_token(fp, buff) == FALSE) {
            HTS_Tree_clear(tree);
            return FALSE;
         }
         node->quest = HTS_Question_find_question(question, buff);
         if (node->quest == NULL) {
            HTS_Tree_clear(tree);
            return FALSE;
         }
         node->yes = (HTS_Node *) HTS_calloc(1, sizeof(HTS_Node));
         node->no = (HTS_Node *) HTS_calloc(1, sizeof(HTS_Node));

         if (HTS_get_pattern_token(fp, buff) == FALSE) {
            node->quest = NULL;
            free(node->yes);
            free(node->no);
            HTS_Tree_clear(tree);
            return FALSE;
         }
         if (HTS_is_num(buff))
            node->no->index = atoi(buff);
         else
            node->no->pdf = HTS_name2num(buff);
         node->no->next = last_node;
         last_node = node->no;

         if (HTS_get_pattern_token(fp, buff) == FALSE) {
            node->quest = NULL;
            free(node->yes);
            free(node->no);
            HTS_Tree_clear(tree);
            return FALSE;
         }
         if (HTS_is_num(buff))
            node->yes->index = atoi(buff);
         else
            node->yes->pdf = HTS_name2num(buff);
         node->yes->next = last_node;
         last_node = node->yes;
      }
   } else {
      node->pdf = HTS_name2num(buff);
   }

   return TRUE;
}