#include "libscl.h"
using namespace scl;
using namespace std;

int main()
{
  const INTEGER lim = 80;
  
  vector<string> v0;

  v0.push_back
    ("Now is the time for all good men to come to the aid of their party");
  v0.push_back
    ("Now is the time for all good men to come to the aid of their party");
  v0.push_back("Now is the time for all good men to come to the aid");
  v0.push_back("of their party.");
  v0.push_back("The quick brown fox jumped over the lazy dogs.");
  v0.push_back("How now brown cow.");

  //v0[0][5] = '\0';  // This should trigger an error

  vecstrbuf vsb0(v0,lim);

  char* c = vsb0.get_ptr();
  for (INTEGER i=1; i<=vsb0.get_rows(); ++i) {
    for (INTEGER j=1; j<=vsb0.get_cols()+1; ++j) {
      cout << ((*c == '\0' || *c == '\n') ? '#' : *c);
      ++c;
    }
    cout << '\n';
  }
  cout << '\n';

  vecstrbuf vsb1;
  vsb1.resize(vsb0.get_rows(),vsb0.get_cols());
  char* c0 = vsb0.get_ptr();
  char* c1 = vsb1.get_ptr();
  char* top = c0 + vsb0.size();
  while (c0 < top) *c1++ = *c0++;

  vector<string> v1 = vsb1.get_vec();

  vector<string>::const_iterator itr=v1.begin();
  while (itr != v1.end()) cout << *itr++ << '\n';
  cout << '\n';

  vecstrbuf vsb2(v1);

  c = vsb2.get_ptr();
  for (INTEGER i=1; i<=vsb2.get_rows(); ++i) {
    for (INTEGER j=1; j<=vsb2.get_cols()+1; ++j) {
      cout << ((*c == '\0' || *c == '\n') ? '#' : *c);
      ++c;
    }
    cout << '\n';
  }
  cout << '\n';

  vecstrbuf vsb3 = vsb2;

  c = vsb3.get_ptr();
  for (INTEGER i=1; i<=vsb3.get_rows(); ++i) {
    for (INTEGER j=1; j<=vsb3.get_cols()+1; ++j) {
      cout << ((*c == '\0' || *c == '\n') ? '#' : *c);
      ++c;
    }
    cout << '\n';
  }
  cout << '\n';

  vecstrbuf vsb4(vsb3.get_rows(),vsb3.get_cols());
  char* c3 = vsb3.get_ptr();
  char* c4 = vsb4.get_ptr();
  top = c3 + vsb3.size();
  while (c3 < top) *c4++ = *c3++;

  c = vsb4.get_ptr();
  for (INTEGER i=1; i<=vsb4.get_rows(); ++i) {
    for (INTEGER j=1; j<=vsb4.get_cols()+1; ++j) {
      cout << ((*c == '\0' || *c == '\n') ? '#' : *c);
      ++c;
    }
    cout << '\n';
  }
  cout << '\n';
  return 0;
}
