// Ch19p2_TokenizerTester.cpp : Defines the entry point for the console application.
//
#include <io.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <conio.h>

#include "Ch19p1_ParticleEmitterTokenizer.h"

int main(int argc, char* argv[])
{
  if (argc < 2) {
    printf("usage: Ch19p2_TokenizerTester <scriptname>");
    return(-1);
  }

  int handle = open(argv[1], O_RDONLY | O_BINARY);
  if (handle == -1) { printf("can't open input file"); return(-2); }

  int len = filelength(handle);

  char *strScript = new char[len+1];

  memset(strScript, 0, len+1);
  read(handle, strScript, len);
  close(handle);
  printf("Input Script: \n%s\n\n", strScript);


  CParticleEmitterTokenizer tokenizer;

  printf("=====[ Tokens: ] ============================================\n");
  
  tokenizer.Tokenize(strScript);
  
  for (std::vector<CParticleEmitterToken>::iterator i = tokenizer.m_TokenVector.begin(); i != tokenizer.m_TokenVector.end(); i++) {
    CParticleEmitterToken &token = (*i);
    printf("Token - type: %20s, value: %s\n", token.TypeAsString().c_str(), token.m_strValue.c_str());

    
  }

	
  delete[] strScript;

  getch();

	return 0;
}

