/* start at reimplementing bubbler
   Copyright (C) 1992-2000 Michigan State University

   The CAPA system is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License as
   published by the Free Software Foundation; either version 2 of the
   License, or (at your option) any later version.

   The CAPA system is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public
   License along with the CAPA system; see the file COPYING.  If not,
   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.

   As a special exception, you have permission to link this program
   with the TtH/TtM library and distribute executables, as long as you
   follow the requirements of the GNU GPL in regard to all of the
   software in the executable aside from TtH/TtM.
*/

#include <iostream.h>

void initScreen()
{
  printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
  printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
  printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
  printf("Welcome to Bubbler, the Automated CAPA grader.\n");
  printf("By: Guy Albertelli II\n");
  printf("Version 0.10.00\n\n\n");
}

void getClassInfo(char* class,int* setId)
{
  printf("What is the class name?");
  scanf("%s",class);

  printf("What is the SetId?");
  scanf("%d",setId);
}

/*errr Guy this all needs some major thought put into it*/
void openOutputFile(filename[80], Questions questions[MAXQUEST],char* class,
		    int setId,char problem)
{
  FILE *outputFile=fopen(filename,"r+");

  /*File already exists*/
  if (outputFile != NULL)
    {
      rewind(outputFile);
      /*read in the first line with problem description etc.*/
      fscanf(outputFile,"%s",buf);
    }
  
  /*File doesn't exist or is empty*/
  if (outputFile==NULL || buf[0]=='\0')
    {
      outputFile=fopen(filename,"w+");
      if (outputFile==NULL)
	{
	  fprintf(stderr,"Unable to open the output file %s",filename);
	  exit(10);
	}
      fprintf(outputFile,"%s %d ",class,setId);
      for(i=0;i<numQuestions;i++)
        {
          fprintf(outputFile,"%c%d",questions[i].type,questions[i].points);
        }
      fprintf(outputFile,"\n");
    }
  else
    {
      rewind(outputFile);
      fscanf(outputFile,"%s %d %s",outputFileClass,outputFileSetId,
	     outputFileQuestions);      
    }
}
/* see comment above*/
void getProblemInfo(Question questions[MAXQUEST],char* class,
		    int setId,Flags* flags,FILE** outputFile)
{
  char filename[80],buf[1024];

  sprintf(filename,"bubbler.output.%d",setId);
  outputFile=fopen(filename,"r+");
  
  printf("Should I compare the class name and SetId with each paper?(y or n)");
  scanf("%s",clear);
  if (clear[0]=='N' || clear[0]=='n')
    flags->CompareClassName=0;
  else
    flags->CompareClassName=1;

  printf("Should the PIN be checked? (y or n)");
  scanf("%s",clear);
  if (clear[0]=='N' || clear[0]=='n')
    flags->CheckPIN=0
  else
    {
      CheckPIN=1;
      printf("Should we run in Anonymous mode?");
      scanf("%s",clear);
      if (clear[0]=='N' || clear[0]=='n')
	Anon=0;
      else
	Anon=1;
    }  
}

int main(void)
{
  initScreen();
  getClassInfo();
  getProblemInfo();
  setupScantron();
  processForms();
  closeScantron();
  return 0;
}
