// baseballReadFileTest2.cc   P. Conrad for CISC220, 06J

// Try reading all lines of the file.  Make sure we don't seg fault.
// We don't do anything with the data in this version--we just try passing
// each line to the constructor, and then recycle the memory.

// See license and copyright statement at bottom of file


#include <iostream>
#include <fstream>
using std::cout;
using std::cerr;
using std::endl;
using std::ifstream;

#include "runTests.h"

#include "baseballMaster.h"

int main(int argc, char *argv[])
{
  // check command line arguments

  if (argc!=2)
    {
      cerr << "Usage: " << argv[0] << " filename " << endl;
      exit(1);
    }
 
  // open the data file, and check for error on open

  ifstream inf(argv[1],std::ios::in);
  if (!inf)
    {
      cerr << "Error: can't open " << argv[1] << endl;
      exit(2);
    }

  // declare input buffer for reading from file

  const int bufsize = 2048;
  char buffer[bufsize];

  // skip over headings
  // if we have eof immediately, then we must have an empty file

  inf.getline(buffer,bufsize); 
  if (inf.eof() )
    {
      cerr << "File " << argv[1] << " was empty!" << endl;
      exit(3);
    }

  // now read the actual data

  inf.getline(buffer,bufsize); // try to read first line of real data
  while (!inf.eof() )
    {
      // test the constructor

      BaseballMaster_C *p  = new BaseballMaster_C(buffer);
      
      // Test the destructor.  Later, this is where we'll add the item
      // into the linked list, instead of deleting it immediately.

      delete p; 
      
      // try to read next line of data

      inf.getline(buffer,bufsize); 
    }

  return 0;

}



// COPYRIGHT NOTICE:

// This code corresponds to the data layout of the Lahmann Database,
// which is copyrighted by Sean Lahmann.  The data and formats here
// are used by special permission of Sean Lahmann, granted to Phill 
// Conrad for use in Computer Science courses at the University of 
// Delaware.  You must obtain permission from Sean Lahmann to use this
// data and/or data format for any other purpose.  For more details,
// visit www.baseball1.com

