/* MasC interpreter/compiler
   (Master Assembly Script Container)
   written by Jared Bruni
   
   After reading Writing Compilers and Interpreters A approach using C++ by Ronald Mak
   and the Dragon Book
   code completly re-written but using concepts teached in this book
*/

// text input structure function implementations


#include "textin.h"

// initalize the text input structure
void initText_in(const char *source_name, struct text_in *ti)
{
     unsigned long len = 0, cnt = 0;
     ti->pfile = fopen(source_name, "rwb");
     if(!ti->pfile)
     {
                  printError("Error file not found.\n");
                  Abort();
     } 
     
     fseek(ti->pfile, 0, SEEK_END);
     len = ftell(ti->pfile);
     rewind(ti->pfile);
     ti->buff = (char*) malloc ( sizeof(char) * (len + 3));
     
     while(!feof(ti->pfile))
     {
                 ti->buff[cnt++] = fgetc(ti->pfile);
     }
     
     ti->buff[cnt] = 0;    
     fclose(ti->pfile);    
}

// free the text input structure
void freeText_in(struct text_in *ti)
{
     free(ti->buff);
}

// sun sun sun here we come
