#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <assert.h>
#include "int32.h"

#ifndef unix
#include <stdarg.h>
#endif

#ifdef __TURBOC__
#else
#define farcalloc calloc
#define farfree free
#endif

#ifdef DJ                       /* a.r. */
#define clrscr ScreenClear
#endif

#ifdef EMXOS2                   /* a.r. */
#define delline v_delline
#define clreol  v_clreol
#define putch   v_putc
#define cputs   v_puts
#endif

#define gprint printf
#define myfree free
#define true (!false)
#define false 0

struct s_range {int col,row,c1,r1,c2,r2,colfirst; };
typedef struct s_range RANGE;

int isnumber(char *s);
char *range_int(char *s, int *v);
int swapint(int *a, int *b);
int find_mkey(char *cp, int *idx);
extern int gle_debug;
typedef char (*(*TOKENS)[500]);
typedef unsigned char uchar;
typedef double dbl;
char *unquote(char *s);
char *gledir(char *s);
int cmd_load(char *fname, char *range, int ntok);
int cmd_load_line(int x, int y, char *inbuff);
int cmd_save(char *fname, char *range, char *format, int ntok);
int set_missing(int x, int y);
int set_scell(int x, int y, char *s);
int clear_cell(int x, int y);
int get_cellboth(int x, int y, double *v, char **s);
int strcpydecimal(char *dest, char *src, int wid, int dpoints);
int strcpywidth(char *dest, char *src, int wid);
int set_outwidth(char *s);
double vcell(int x, int y);
int get_cell(int x, int y, double *v);
int range_def(char *s, RANGE *r);
int evaluate(char *exp, double *v);
int var_find_rc(int *idx, int *var, int *nd, int c);
int eval_setxy(int x, int y);
int var_getstr(int v, char *s);
int sub_clear(void);
int setdstr(char **s, char *in);
int alloc_temp(int n);
int gle_abort(char *s);
int d_tidyup(void);
int text_inkey(void);
int ncpy(char *d, char *s, int n);
int token_space(void);
#ifndef unix
void wprintf(va_list arg_list, ...);
void fner(va_list arg_list, ...);
void printmess(va_list arg_list, ...);
#endif
char *sdup(char *s);
/* void myfree(void *p); */
void myfrees(void *p, char *s);
void *myallocn(int32 nitems,int32 size);
void *myalloc(int32 size);
void *myallocz(int32 size);
int showpcode(int32 *p);
int add_fn(char *pcode, int *plen, int i);
int add_i(char *pcode,int *plen,int32 i);
int add_f(char *pcode,int *plen,double f);
int add_pcode(char *pcode,int *plen,char *fcode,int *flen);
int add_string(char *pcode, int *plen, char *s);
#ifndef __TURBOC__
#ifndef __GNUC__ /* a.r. */
char *strdup(char *);
#endif
#endif
int add_var(char *pcode,int *plen,int i);
char *eval_str(int32 *pcode,int *plen);
char *find_non_space(char *cp);
char *find_term(char *cp);
char *un_quote(char *ct);
int eval(int32 *pcode,int *cp,double *oval,char *ostr,int *otyp);
int find_un(char *cp, int *idx,int *ret,int *np,int **plist);
int isnumber(char *s);
int lastchar(char *s, char c);
int mystrcpy(char **d,char *s);
int polish(char *expr,char *pcode,int *plen,int *rtype);
int scheck(int v);
int spop(int v);
int spush(int v);
int stack_op(char *pcode, int *plen, int stk[] ,int stkp[], int *nstk,  int i, int p);
int token(char *lin,char *tok[],int *ntok,char *outbuff);
int var_add(char *name,int *idx,int *type)    /* Add a variable to the list */;
int var_find(char *name,int *idx,int *type)    /* Find a variable in the list */;
int var_findadd(char *name,int *idx,int *type)    /* Add a variable to the list */;
int var_get(int jj, double *v);
int var_nlocal(int *l);
int var_set(int jj, double v);
int var_setstr(int jj, char *s);
int xy_polar(double dx,double dy,double *radius,double *angle);

int sub_clear(void);
int sub_def(char *s);
int sub_call(int idx,double *pval,char **pstr,int *npm);
int sub_find(char *s,int *idx,int *zret, int *np, int **plist);
int sub_get_startend(int idx, int *ss, int *ee);
int sub_param(int idx,char *s);
int sub_set_return(double d);
int sub_set_startend(int idx, int ss, int ee);

void refresh(void);
void show_cell(int x, int y);
void show_ifcell(int x, int y);
char *scell(int x, int y);
void scr_norm(void);
void fner_clear(void);
void show_cellwide(int x, int y);
int do_command(char *cmd);
int read_command(int *cmd,char *ans,char *ques);
int do_arrow(int k);
int hi_cell(int x,int y);
int fix_cur(void);
int window_norm(void);
int scr_menuhi(void);
int gotocell(int x, int y);
int scr_grey(void);
int scr_savexy(void);
int scr_inv(void);
int scr_restorexy(void);
int read_str(int *cmd, char *s);
int scr_refresh(void);
int scr_right(int i);
int scr_left(int i);
int set_cell(int x, int y, double d);
