#include "ppl.hh"
#include <fstream>
#include <iostream>

using namespace std;
using namespace Parma_Polyhedra_Library;

void
open(fstream& s, const char* path, ios_base::openmode mode) {
  s.open(path, mode);
  if (!s) {
    cerr << "Cannot open `" << path << "'";
    if (mode == ios_base::in)
      cerr << " for reading";
    else if (mode == ios_base::out)
      cerr << " for writing";
    else if (mode == ios_base::in | ios_base::out)
      cerr << " for reading/writing";
    cerr << endl;
    exit(1);
  }
}

void
close(fstream& s) {
  if (s)
    s.close();
}

static const char* my_file = "ppl-sampleh8-half.dat";
static const char* my_file_out = "ppl-sampleh8-half.out";

int
main() {
  fstream f;
  open(f, my_file, ios_base::in);
  C_Polyhedron ph;
  ph.ascii_load(f);
  close(f);

  // Make sure the polyhedron read is well-formed.
  if (!ph.OK())
    abort();

  ph.generators();

  open(f, my_file_out, ios_base::out);
  ph.ascii_dump(f);
  close(f);

  return 0;
}
