#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/stat.h>

typedef void *MY_HANDLE;

#if !UNIX
#include <io.h>
#endif

typedef DWORD unsigned4[4]; 

extern BYTE key_map[256];

extern BYTE key_oposit[126];
                  /* temporal */
extern DWORD  gl_read;            

                  /* others */
extern DWORD  MEMORY_C, MEMORY_c256, MEMORY_V, MEMORY_S, MEMORY_STemp;
extern DWORD  MEMORY_tr, BLOCKS, PROGRAM_L, PROGRAM_F;
extern DWORD  DEF_F, FUNC_F, READY_LISTS;
extern DWORD  FUNCTOR_L, NEW_OBJ, SALAM, EKLER, OBJ_STORE, STRING_STORE;
extern DWORD  STACK2, BUDA3, BUDA_S2;
extern int    BUDA3_UP;

extern DWORD  ch_set, default_char;
extern DWORD c_black, c_red, c_green, c_blue, c_violet, c_output;
extern char  string[L_BUFER+2], string2[L_BUFER+2];
extern BYTE MyCallback1[2*BUFFERS];
extern DWORD  status_fl, ii, f_end, len, Trace, main_h1;
extern DWORD  Definition[DEFINITIONS], ret_fl, Wait, Wait_d, ObjectStore_br;

#if 1
extern MY_HANDLE hOper, hOpPr, hOpType, hOpMin, Hbuf_sub, hArray, hArType, hArPos, hAddInfo; 
extern MY_HANDLE Hatom_buf, Hvar_field, hReadStack, hLeft, hRight, Hbuf1, Hbuf2;
extern MY_HANDLE Hbufu1, Hbufu2, Hbufu3, Hbufu4, Hbufu5, Hbufu6, Hbufu7, Hst_buf;
extern MY_HANDLE Hbuf_3, Hbuf_4, Hbuf_5, Hbuf_6, Hbuf_7, Hbuf_8, Hlist, Hglobal, Hglobal2, Hst_buf_num;
#endif
                  /* Operators */
extern DWORD  oper_br, *Oper, *OpPr, *OpType, *OpMin;
 
                  /* buffers - CREATE */
extern DWORD  br_buf2, *bufu1, *bufu2, *bufu3, *bufu4; 
extern DWORD  *bufu5, *bufu6, *bufu7, *st_buf;

                  /* buffers - READ */
extern DWORD  i_poin, bufu[BUFFERS], *buf_sub, *Array, *ArType, *ArPos, *AddInfo;
extern DWORD  read_br, newline_br, error, warn_br;
extern BYTE   *atom_buf, *var_field;
extern DWORD  *ReadStack, *Left, *Right, *buf1, *buf2;

                  /* buffers - CALL */
extern DWORD  term_1, term_2, buda_br, a1, br_buf1, RedLine;
extern DWORD  *buf_3, *buf_4, *buf_5, *buf_6, *buf_7, *buf_8;
extern int    buda_br_up; 
                 
                  /* CREATE */
extern DWORD  sv_c, sv_v, sv_tr, sv_sub, sv_subv;
extern DWORD  sv_c_old, sv_v_old, sv_sub_old;
extern DWORD  sv_subT, sv_StStore, sv_NewObj, sv_blocks, sv_blocks2;

extern DWORD  *list, list_br, *global, *global2, global_br, global_br2, GLOBAL_max;
extern DWORD  p1, StepOver, tt, tt_sub, *st_buf_num;

                  /* MAIN ARRAYS */ 
#if 1
extern MY_HANDLE  hTemp, hFunctors, hProgram, hProg_Obj, hAtoms, hProg_fild, hD_field, hF_field, hReadyLists;
extern MY_HANDLE  hDurty, hStack, hBuda1, hNewObj, hProgram2, hProgTail, hPointers;
extern MY_HANDLE  hBuda2, hLink, hUfil_c1, hUfil_c2, hUfil_vs, hBlocks, hBlocks_val, hBlocks_next;
extern MY_HANDLE  hChfil_c, hChfil_v, hSubsti, hSubstiT, hCh_tree;
extern MY_HANDLE  hStringStore, hNewObj1, hNewObj2, hObjectStore, hMtree, hSalam, hEkler;
#endif
extern DWORD *Functors, *Program, *Program2, *ProgTail, *Pointers;
extern DWORD *Prog_Obj, *Atoms, *Prog_fild, *D_field, *F_field, *ReadyLists;
extern DWORD *Ufil_c1, *Ufil_c2, *Ufil_vs;
extern DWORD *Buda1, *Buda2, *NewObj, *Stack, *Link; 
extern DWORD *Blocks, *Salam, *Ekler, *Durty, *ObjectStore;
extern WORD *Blocks_val, *Blocks_next, *Ch_tree, *Chfil_v, *Substi, *SubstiT, *NewObj2;
extern BYTE *Chfil_c, *NewObj1, *StringStore;
extern unsigned4 *Mtree;

extern DWORD p_fild_br, df_min_p, df_pointer, ff_pointer, program_br1, program_br2, program_br;
extern DWORD ekler_br, stack_br, lSteps_br, Corection, my_gl, my_gl2, func_br, func_in_ADD;
extern WORD  Steps_br;

/*
 *  External variable declarations
 */
#if !CONSOLE
extern char *StandardString;
extern LONG styleDefault;   /* default child creation state       */
extern char szChild[];      /* class of child             */
extern char szSearch[];     /* search string              */
extern char *szDriver;      /* name of printer driver         */
extern char szPropertyName[];   /* filename property for dialog box   */
extern int iPrinter;        /* level of printing capability       */
extern BOOL fCase;      /* searches case sensitive        */
extern DWORD cFonts;     /* number of fonts enumerated         */

extern HMENU MainMenu;
extern HPEN hPen, hSavePen, hMyRedPen, hMyBluePen;
extern HBRUSH hbrGreen, hbrGrey, hBrush, hSaveBrush;
extern HFONT hFont, hSaveFont;
extern CFont InfoFont;
extern CHARFORMAT cf_blue, cf_red, cf_black, cf_green, *pFontMask;
extern DWORD  synt_color[LAST_COLOR+1];
extern SIZE Screen;
extern CString ProgramPath;
extern CString TempStr, TempStr2;

extern CString RegName, RegFrom, RegProdID, RegPassword;
#endif

// Proof Tree
extern DWORD open_br, open_start, j_start, k_old;

//system lists and containers
extern DWORD the_free_list, the_free_container;

/*  externally declared functions
 */
extern inline DWORD CreateArray(DWORD);
extern BOOL MitiGlobalAlloc(void);
extern void MitiLock(void);
extern void MitiUnlock(void);
extern inline DWORD make_call(DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD);
extern unsigned char *sp_base64_enc(unsigned char *input, int ilen);
extern unsigned char *base64_dec(unsigned char *input, int ilen);
extern int sp_fgets(char *dest, int len, FILE *in);
extern int sp_fgets_fixlen(char *dest, int len, FILE *in);
extern void sp_fprintf(FILE *out, char *src, int count);
extern WORD MAP_CP[CHAR_SETS][128];
extern char Char_Sets[CHAR_SETS+1][32];
extern char Char_Sets_Short[CHAR_SETS+1][13];
extern int readUTF8(const unsigned char *src, DWORD *code);
extern int unicodeToUTF8(unsigned code, unsigned char *result);
extern int char_set(DWORD, DWORD, DWORD);
extern DWORD ChangeCharset(DWORD, DWORD, unsigned char *, unsigned char *, DWORD *, DWORD, DWORD LimitTo=L_BUFER);
extern void put_in_f(DWORD, DWORD, DWORD, DWORD);
extern unsigned correct_list(DWORD, DWORD);
extern unsigned correct_F_field(void);
extern unsigned correct_ReadyLists(DWORD ncArgs);
extern unsigned correct_MEM_S(void);
extern unsigned correct_MEM_STemp(int);
extern unsigned correct_BLOCKS(void);
extern unsigned correct_PROG_F(void);
extern unsigned correct_SALAM(void);
extern unsigned correct_EKLER(void);
extern unsigned correct_OBJ_ST(void);
extern unsigned correct_STR_ST(void);
extern unsigned correct_GLOB_max(void);
extern unsigned correct_FUNCTOR(void);
extern unsigned correct_Stack(void);
extern unsigned correct_LINK(void);
extern unsigned correct_BUDA(void);
extern unsigned correct_BUDA_UP(void);
extern unsigned correct_MEM_tr(void);
extern unsigned correct_NEW_OBJ(void);
extern unsigned correct_PROG_L(void);
extern unsigned correct_MEM_V(void);
extern unsigned correct_MEM_C(void);
#if PROF==2
extern void MakeExe(int);
#endif
extern void close_object(DWORD);
extern void Add_op(DWORD, DWORD, DWORD, DWORD);
extern void Delete_op(DWORD, DWORD, DWORD, DWORD, DWORD);
extern DWORD creat_p( DWORD, DWORD, DWORD, DWORD, DWORD);
extern DWORD registrate( DWORD, DWORD);
extern DWORD Unregister( DWORD, DWORD);
extern DWORD read_n(DWORD *, DWORD);
extern DWORD write_p(DWORD, DWORD, DWORD);
extern DWORD call(DWORD);
extern DWORD execute(DWORD, DWORD, DWORD);
extern void compile(int);
extern int load_exe(int);
extern void assert(DWORD, DWORD);
extern void Warning(DWORD, DWORD, DWORD, DWORD);
