#ifndef __MASCDLL_H_
#define __MASCDLL_H_

#include<stdio.h>
#include<string.h>

#define max_string_size 256*4

enum var_type {
     tVAR_STR, tVAR_INT, tVAR_FLOAT, tVAR_CSTR,tVAR_CINT,tVAR_CFLOAT,tVAR_LABEL,tVAR_NONE, vRES,tVAR_CALL
};

struct symNode {
       char *str;
       short sym_tab;
       int line;
       float value;
       char str_value[max_string_size];
       struct symNode *next; 
       enum var_type vtype;   
};

struct symTbl {
       struct symNode root;
       struct symNode *tail;
       int node_count;
       int sym_tab;
};

struct Stack {
       float stack[max_string_size]; // allow exactly 256*4 instruction pointers / items in the stack
       int stack_ptr;     
};

struct StrStack { 
      char str[20][256];
      int stack_ptr;   
};

struct Token {
       char code;
       char *text;
       int line;
       float value;
       enum var_type vtype;
	   char num_text[25];
	   int callback;
};

struct BackEnd {
       char obj_name[256];
       int incp,inc_len,ince;    
       struct Stack st;
	   struct Stack ist;
	   struct Stack the_stack;
       struct StrStack str_st;
       struct symTbl g_stable;
	   int reg[8];
};


int __stdcall masc_run(const char *source, struct BackEnd *ptr);
int __stdcall masc_stop(struct BackEnd *ptr);
int __stdcall masc_callback ( int (__stdcall *cfunc)(const char *proc_name, struct BackEnd *bend, struct Token *ptr_tok) );
int __stdcall masc_call(int bend_offset,const char *proc_name);
struct BackEnd* __stdcall masc_getbend(int offset);


struct symNode *Search(struct symNode *root, const char *str)
{ 
	struct symNode *head = root;
	while(head != 0)
	{
		if(head->str != 0)
			if(strcmp(head->str,str) == 0) 
				return head;
			else
				head = head->next;

	} 

	return head;
}

char *print_FixString(char *str)
{
	char *sptr = str;
	if(str == 0)
		return 0;
	if(sptr[0] == '\"') 
		sptr++;
	if(sptr[strlen(sptr)-1] == '\"') 
		sptr[strlen(sptr)-1] = 0;

	return sptr;
}

#endif
