// file: ts_question_0.cc
//

// isip include files
//
#include "tie_state.h"
#include "tie_state_constants.h"

// method: read_questions_cc
//
// arguments:
//    int_4& num_questions: (output) number of questions
//    Question** questions: (output) Pointers to all the questions
//    FILE* fpq: (input)  file pointer to membership file  
// 
// return: a logical_1 showing status
//
// this methods reads questions
//
logical_1 read_questions_cc(int_4& num_questions_a, Question**& questions_a,
			    FILE* fpq_a) { 
	  
  // variables to read data
  //
  char_1* tmp = new char_1[ISIP_MAX_STRING_LENGTH];
  char_1* attr = new char_1[ISIP_MAX_STRING_LENGTH];

  // dummy variables
  //
  int_4 i;
    
  char_1** attributes = new char_1*[TS_NUM_QUESTIONS];
  logical_1* direction = new logical_1[TS_NUM_QUESTIONS]; 

  for(i = 0;i < TS_NUM_QUESTIONS;i++) {
    attributes[i] = new char_1[TS_QUE_LENGTH];
  }  
  
  // read data from file
  //
  while (fscanf(fpq_a, "%s", tmp) != EOF) {
    
    // ignore comment lines
    //
    if (tmp[0] == (char_1)'#') {
      
      // do nothing
      //
      fscanf(fpq_a, "%[^\n]", tmp);
      fscanf(fpq_a, "%[\n]", tmp);
    }

    else {
      
      fscanf(fpq_a, "%s", attr);
      strcpy((char*)attributes[num_questions_a], (char*)attr);     
      if(strcmp("L", (char*)tmp)==0) {	
	direction[num_questions_a] = ISIP_TRUE;   // ISIP_TRUE for left	
      }
      
      else {	
	direction[num_questions_a] = 0;   // ISIP_FALSE stands for right
      }
      num_questions_a += 1;

      // don't need other information on this line
      //
      fscanf(fpq_a, "%[^\n]", tmp);
      fscanf(fpq_a, "%[\n]", tmp);
      
    }
  }
    
  questions_a = new Question*[num_questions_a];    
  
  for(i = 0; i < num_questions_a; i++) {
    questions_a[i]= new Question(); 
    questions_a[i]->set_attribute_cc(attributes[i]);
    questions_a[i]->set_direction_cc(direction[i]);
  }  

  for(i = 0; i < TS_NUM_QUESTIONS; i++) {
    delete [] attributes[i];
  }
  delete [] attributes;
  delete [] direction;
    
  delete [] tmp;
  delete [] attr;

  // exit gracefully
  //
  return ISIP_TRUE;  
}

