#include "libscl.h"

using namespace std;
using namespace scl;

// Better style due to pipelining

int main(int argc, char** argp, char** envp)
{

 // A better way, vectors are discussed in Chapter 3.

  vector<string> arguments;

  char** ptr = argp;
  char** top = argp + argc;
  while (ptr < top) arguments.push_back(*ptr++);

  vector<string> environment;

  ptr = envp;
  while (*ptr) environment.push_back(*ptr++);

  ofstream fout;
  fout.open("arg.txt");
  if (fout) {

    vector<string>::size_type i = 0;
    while (i != arguments.size()) fout << arguments[i++] << '\n';
    fout << '\n';

    fout.close(); fout.clear();
  }
  else {
    error("Error, cannot open fout");
  }

  fout.open("env.txt");
  if (fout) {

    vector<string>::size_type i = 0;
    while (i != environment.size()) fout << environment[i++] << '\n';

    fout.close(); fout.clear();
  }
  else {
    error("Error, cannot open fout");
  }
  return 0;
}
