blob: 1f1bf9360a197093c2eb0f67b0ef10bec96e5a94 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001#ifndef _h_EJINTERNAL
2#define _h_EJINTERNAL 1
3
4#include <ctype.h>
5#include <stdarg.h>
6#include <stdlib.h>
7
8#ifdef CE
9#ifndef UEMF
10 #include <io.h>
11#endif
12#endif
13
14#ifdef LYNX
15 #include <unistd.h>
16#endif
17
18#ifdef QNX4
19 #include <dirent.h>
20#endif
21
22#ifdef UEMF
23 #include "uemf.h"
24#else
25 #include <param.h>
26 #include <stat.h>
27 #include "basic/basicInternal.h"
28 #include "emf/emfInternal.h"
29#endif
30
31#include "ej.h"
32
33#define EJ_OFFSET 1
34#define EJ_MAX_RECURSE 100
35
36#define EJ_INC 110
37#define EJ_SCRIPT_INC 1023
38
39
40
41#define TOK_ERR -1
42#define TOK_LPAREN 1
43#define TOK_RPAREN 2
44#define TOK_IF 3
45#define TOK_ELSE 4
46#define TOK_LBRACE 5
47#define TOK_RBRACE 6
48#define TOK_LOGICAL 7
49#define TOK_EXPR 8
50#define TOK_SEMI 9
51#define TOK_LITERAL 10
52#define TOK_FUNCTION 11
53#define TOK_NEWLINE 12
54#define TOK_ID 13
55#define TOK_EOF 14
56#define TOK_COMMA 15
57#define TOK_VAR 16
58#define TOK_ASSIGNMENT 17
59#define TOK_FOR 18
60#define TOK_INC_DEC 19
61#define TOK_RETURN 20
62
63#define COND_AND 1
64#define COND_OR 2
65#define COND_NOT 3
66
67#define EXPR_LESS 1
68#define EXPR_LESSEQ 2
69#define EXPR_GREATER 3
70#define EXPR_GREATEREQ 4
71#define EXPR_EQ 5
72#define EXPR_NOTEQ 6
73#define EXPR_PLUS 7
74#define EXPR_MINUS 8
75#define EXPR_DIV 9
76#define EXPR_MOD 10
77#define EXPR_LSHIFT 11
78#define EXPR_RSHIFT 12
79#define EXPR_MUL 13
80#define EXPR_ASSIGNMENT 14
81#define EXPR_INC 15
82#define EXPR_DEC 16
83#define EXPR_BOOL_COMP 17
84
85
86#define STATE_ERR -1
87#define STATE_EOF 1
88#define STATE_COND 2
89#define STATE_COND_DONE 3
90#define STATE_RELEXP 4
91#define STATE_RELEXP_DONE 5
92#define STATE_EXPR 6
93#define STATE_EXPR_DONE 7
94#define STATE_STMT 8
95#define STATE_STMT_DONE 9
96#define STATE_STMT_BLOCK_DONE 10
97#define STATE_ARG_LIST 11
98#define STATE_ARG_LIST_DONE 12
99#define STATE_DEC_LIST 16
100#define STATE_DEC_LIST_DONE 17
101#define STATE_DEC 18
102#define STATE_DEC_DONE 19
103#define STATE_RET 20
104#define STATE_BEGIN STATE_STMT
105
106#define FLAGS_EXE 0x1
107#define FLAGS_VARIABLES 0x2
108#define FLAGS_FUNCTIONS 0x4
109
110
111typedef struct {
112 char_t *fname;
113 char_t **args;
114 int nArgs; /* Number of args */
115} ejfunc_t;
116
117typedef struct ejEval {
118 ringq_t tokbuf;
119 ringq_t script; /* Input script for parsing */
120 char_t *putBackToken;
121 int putBackTokenId;
122 char_t *line;
123 int lineLength;
124 int lineNumber;
125 int lineColumn;
126} ejinput_t;
127
128typedef struct ej {
129 ejinput_t *input;
130 sym_fd_t functions;
131 sym_fd_t *variables;
132 int variableMax;
133 ejfunc_t *func;
134 char_t *result;
135 char_t *error;
136 char_t *token;
137 int tid; /* Current token id */
138 int eid; /* Halloc handle */
139 int flags;
140 int userHandle; /* User defined handle */
141} ej_t;
142
143extern int ejOpenBlock(int eid);
144extern int ejCloseBlock(int eid, int vid);
145extern char_t *ejEvalBlock(int eid, char_t *script, char_t **emsg);
146#ifndef __NO_EJ_FILE
147extern char_t *ejEvalFile(int eid, char_t *path, char_t **emsg);
148#endif
149extern int ejRemoveGlobalFunction(int eid, char_t *name);
150extern void *ejGetGlobalFunction(int eid, char_t *name);
151extern int ejSetGlobalFunctionDirect(sym_fd_t functions, char_t *name,
152 int (*fn)(int eid, void *handle, int argc, char_t **argv));
153extern void ejError(ej_t* ep, char_t* fmt, ...);
154extern void ejSetUserHandle(int eid, int handle);
155extern int ejGetUserHandle(int eid);
156extern int ejGetLineNumber(int eid);
157extern char_t *ejGetResult(int eid);
158extern void ejSetLocalVar(int eid, char_t *var, char_t *value);
159extern void ejSetGlobalVar(int eid, char_t *var, char_t *value);
160
161extern int ejLexOpen(ej_t* ep);
162extern void ejLexClose(ej_t* ep);
163extern int ejLexOpenScript(ej_t* ep, char_t *script);
164extern void ejLexCloseScript(ej_t* ep);
165extern void ejLexSaveInputState(ej_t* ep, ejinput_t* state);
166extern void ejLexFreeInputState(ej_t* ep, ejinput_t* state);
167extern void ejLexRestoreInputState(ej_t* ep, ejinput_t* state);
168extern int ejLexGetToken(ej_t* ep, int state);
169extern void ejLexPutbackToken(ej_t* ep, int tid, char_t *string);
170
171extern int ejEmfDbRead(int eid, void *handle, int argc, char_t **argv);
172extern int ejEmfDbReadKeyed(int eid, void *handle, int argc, char_t **argv);
173extern int ejEmfDbTableGetNrow(int eid, void *handle, int argc, char_t **argv);
174extern int ejEmfDbDeleteRow(int eid, void *handle, int argc, char_t **argv);
175extern int ejEmfTrace(int eid, void *handle, int argc, char_t **argv);
176extern int ejEmfDbWrite(int eid, void *handle, int argc, char_t **argv);
177extern int ejEmfDbCollectTable(int eid, void *handle, int argc, char_t **argv);
178
179extern sym_fd_t ejGetVariableTable(int eid);
180extern sym_fd_t ejGetFunctionTable(int eid);
181
182extern int ejEmfOpen(int eid);
183extern void ejEmfClose(int eid);
184#endif /* _h_EJINTERNAL */
185