/************************************************************************
       -= SEER - C-Scripting engine v 0.92a =-
State      : under implementation
Author     : Przemyslaw Podsiadly
             email: ppodsiad@elka.pw.edu.pl
             WWW:   http://home.elka.pw.edu.pl/~ppodsiad
File:test.c
Desc:testing program
************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "seer.h"

void Test1(){
		  printf("test 1 worked\n");
		  return;
}

void Test2(char *buf){
		  printf("test 2 worked: %s\n", buf);
		  return;
}

void Init()
{
//************************ Special *************************
//************************ STDIO ***************************
 scAdd_Internal_Header("stdio",
 "import int printf(char *,...);\n"
 "import int sprintf(char*,char *,...);\n"
 "import int scanf(char *,...);\n"
 "import int getchar();\n"
 "import int strcpy(char *,char *);\n"
 "import int strcmp(char *,char *);\n"
 "import int strtol(char *,char **,int);\n"
 "import int atoi(char *);\n"
 "import double atof(char *);\n"
 "import unsigned int strtoul(char *,char **,int);\n"
 "import double strtod(char *,char **);\n"
 "import char *strdup(char *);\n"
 "import void* malloc(int);\n"
 "import void free(void *);\n"
 "import void Test1(void);\n"
 "import void Test2(char *);\n"
 );
 scAddExtSym(printf);
 scAddExtSym(sprintf);
 scAddExtSym(scanf);
 scAddExtSym(getchar);
 scAddExtSym(strcpy);
 scAddExtSym(strcmp);
 scAddExtSym(strdup);
 scAddExtSym(strtoul);
 scAddExtSym(strtol);
 scAddExtSym(strtod);
 scAddExtSym(atoi);
 scAddExtSym(atof);
 scAddExtSym(malloc);
 scAddExtSym(free);

 scAddExtSym(Test1);
 scAddExtSym(Test2);
}



/******************************************************************/
int main() {
 	scScript s;
	scInstance *i=NULL;
	char buf[512], line[256];

	printf("**********SeeR v.%s****(%s)**********************\n",SeeR_VERSION_STR,SeeR_DATE_STR);
	Init();
	printf(">>");
	while (gets(line) != NULL){
		sprintf(buf, "#include stdio\nexport main;\n"
						 "int main(){\n%s\nreturn(0);}", line);
		printf("\nCompiling...\n");
		s=scCompile_Text(buf);
		if (scErrorNo) printf("Error %d: %s\n", scErrorNo, scErrorMsg);
		printf("Creating...\n");
		i=scCreate_Instance(s,"");
		if (scErrorNo) printf("Error %d: %s\n", scErrorNo, scErrorMsg);
		printf("Starting...\n");
		scStart_Instance(i);
		if (scErrorNo) printf("Error %d: %s\n", scErrorNo, scErrorMsg);
 		//scCall_Instance(i,scGet_Symbol(i,"main"));
		scFree_Instance(i);
		if (scErrorNo) printf("Error %d: %s\n", scErrorNo, scErrorMsg);
		free(s);
		printf("\n>>");
	}
	return 0;
}

