1 | /* |
---|
2 | * ejIntrn.h -- Ejscript(TM) header |
---|
3 | * |
---|
4 | * Copyright (c) GoAhead Software, Inc., 1992-2000 |
---|
5 | * |
---|
6 | * See the file "license.txt" for information on usage and redistribution |
---|
7 | * |
---|
8 | * $Id$ |
---|
9 | */ |
---|
10 | |
---|
11 | #ifndef _h_EJINTERNAL |
---|
12 | #define _h_EJINTERNAL 1 |
---|
13 | |
---|
14 | /******************************** Description *********************************/ |
---|
15 | |
---|
16 | /* |
---|
17 | * GoAhead Ejscript(TM) header. This defines the Ejscript API and internal |
---|
18 | * structures. |
---|
19 | */ |
---|
20 | |
---|
21 | /********************************* Includes ***********************************/ |
---|
22 | |
---|
23 | #include <ctype.h> |
---|
24 | #include <stdarg.h> |
---|
25 | #include <stdlib.h> |
---|
26 | |
---|
27 | #ifdef CE |
---|
28 | #ifndef UEMF |
---|
29 | #include <io.h> |
---|
30 | #endif |
---|
31 | #endif |
---|
32 | |
---|
33 | #ifdef LYNX |
---|
34 | #include <unistd.h> |
---|
35 | #endif |
---|
36 | |
---|
37 | #ifdef QNX4 |
---|
38 | #include <dirent.h> |
---|
39 | #endif |
---|
40 | |
---|
41 | #ifdef UEMF |
---|
42 | #include "uemf.h" |
---|
43 | #else |
---|
44 | #include <param.h> |
---|
45 | #include <stat.h> |
---|
46 | #include "basic/basicInternal.h" |
---|
47 | #include "emf/emfInternal.h" |
---|
48 | #endif |
---|
49 | |
---|
50 | #include "ej.h" |
---|
51 | |
---|
52 | /********************************** Defines ***********************************/ |
---|
53 | /* |
---|
54 | * Constants |
---|
55 | */ |
---|
56 | #define EJ_INC 110 /* Growth for tags/tokens */ |
---|
57 | #define EJ_SCRIPT_INC 1023 /* Growth for ej scripts */ |
---|
58 | #define EJ_OFFSET 1 /* hAlloc doesn't like 0 entries */ |
---|
59 | #define EJ_MAX_RECURSE 100 /* Sanity for maximum recursion */ |
---|
60 | |
---|
61 | /* |
---|
62 | * Ejscript Lexical analyser tokens |
---|
63 | */ |
---|
64 | #define TOK_ERR -1 /* Any error */ |
---|
65 | #define TOK_LPAREN 1 /* ( */ |
---|
66 | #define TOK_RPAREN 2 /* ) */ |
---|
67 | #define TOK_IF 3 /* if */ |
---|
68 | #define TOK_ELSE 4 /* else */ |
---|
69 | #define TOK_LBRACE 5 /* { */ |
---|
70 | #define TOK_RBRACE 6 /* } */ |
---|
71 | #define TOK_LOGICAL 7 /* ||, &&, ! */ |
---|
72 | #define TOK_EXPR 8 /* +, -, /, % */ |
---|
73 | #define TOK_SEMI 9 /* ; */ |
---|
74 | #define TOK_LITERAL 10 /* literal string */ |
---|
75 | #define TOK_FUNCTION 11 /* function name */ |
---|
76 | #define TOK_NEWLINE 12 /* newline white space */ |
---|
77 | #define TOK_ID 13 /* function name */ |
---|
78 | #define TOK_EOF 14 /* End of script */ |
---|
79 | #define TOK_COMMA 15 /* Comma */ |
---|
80 | #define TOK_VAR 16 /* var */ |
---|
81 | #define TOK_ASSIGNMENT 17 /* = */ |
---|
82 | #define TOK_FOR 18 /* for */ |
---|
83 | #define TOK_INC_DEC 19 /* ++, -- */ |
---|
84 | #define TOK_RETURN 20 /* return */ |
---|
85 | |
---|
86 | /* |
---|
87 | * Expression operators |
---|
88 | */ |
---|
89 | #define EXPR_LESS 1 /* < */ |
---|
90 | #define EXPR_LESSEQ 2 /* <= */ |
---|
91 | #define EXPR_GREATER 3 /* > */ |
---|
92 | #define EXPR_GREATEREQ 4 /* >= */ |
---|
93 | #define EXPR_EQ 5 /* == */ |
---|
94 | #define EXPR_NOTEQ 6 /* != */ |
---|
95 | #define EXPR_PLUS 7 /* + */ |
---|
96 | #define EXPR_MINUS 8 /* - */ |
---|
97 | #define EXPR_DIV 9 /* / */ |
---|
98 | #define EXPR_MOD 10 /* % */ |
---|
99 | #define EXPR_LSHIFT 11 /* << */ |
---|
100 | #define EXPR_RSHIFT 12 /* >> */ |
---|
101 | #define EXPR_MUL 13 /* * */ |
---|
102 | #define EXPR_ASSIGNMENT 14 /* = */ |
---|
103 | #define EXPR_INC 15 /* ++ */ |
---|
104 | #define EXPR_DEC 16 /* -- */ |
---|
105 | #define EXPR_BOOL_COMP 17 /* ! */ |
---|
106 | /* |
---|
107 | * Conditional operators |
---|
108 | */ |
---|
109 | #define COND_AND 1 /* && */ |
---|
110 | #define COND_OR 2 /* || */ |
---|
111 | #define COND_NOT 3 /* ! */ |
---|
112 | |
---|
113 | /* |
---|
114 | * States |
---|
115 | */ |
---|
116 | #define STATE_ERR -1 /* Error state */ |
---|
117 | #define STATE_EOF 1 /* End of file */ |
---|
118 | #define STATE_COND 2 /* Parsing a "(conditional)" stmt */ |
---|
119 | #define STATE_COND_DONE 3 |
---|
120 | #define STATE_RELEXP 4 /* Parsing a relational expr */ |
---|
121 | #define STATE_RELEXP_DONE 5 |
---|
122 | #define STATE_EXPR 6 /* Parsing an expression */ |
---|
123 | #define STATE_EXPR_DONE 7 |
---|
124 | #define STATE_STMT 8 /* Parsing General statement */ |
---|
125 | #define STATE_STMT_DONE 9 |
---|
126 | #define STATE_STMT_BLOCK_DONE 10 /* End of block "}" */ |
---|
127 | #define STATE_ARG_LIST 11 /* Function arg list */ |
---|
128 | #define STATE_ARG_LIST_DONE 12 |
---|
129 | #define STATE_DEC_LIST 16 /* Declaration list */ |
---|
130 | #define STATE_DEC_LIST_DONE 17 |
---|
131 | #define STATE_DEC 18 |
---|
132 | #define STATE_DEC_DONE 19 |
---|
133 | |
---|
134 | #define STATE_RET 20 /* Return statement */ |
---|
135 | |
---|
136 | #define STATE_BEGIN STATE_STMT |
---|
137 | |
---|
138 | /* |
---|
139 | * Flags. Used in ej_t and as parameter to parse() |
---|
140 | */ |
---|
141 | #define FLAGS_EXE 0x1 /* Execute statements */ |
---|
142 | #define FLAGS_VARIABLES 0x2 /* Allocated variables store */ |
---|
143 | #define FLAGS_FUNCTIONS 0x4 /* Allocated function store */ |
---|
144 | |
---|
145 | /* |
---|
146 | * Function call structure |
---|
147 | */ |
---|
148 | typedef struct { |
---|
149 | char_t *fname; /* Function name */ |
---|
150 | char_t **args; /* Args for function (halloc) */ |
---|
151 | int nArgs; /* Number of args */ |
---|
152 | } ejfunc_t; |
---|
153 | |
---|
154 | /* |
---|
155 | * EJ evaluation block structure |
---|
156 | */ |
---|
157 | typedef struct ejEval { |
---|
158 | ringq_t tokbuf; /* Current token */ |
---|
159 | ringq_t script; /* Input script for parsing */ |
---|
160 | char_t *putBackToken; /* Putback token string */ |
---|
161 | int putBackTokenId; /* Putback token ID */ |
---|
162 | char_t *line; /* Current line */ |
---|
163 | int lineLength; /* Current line length */ |
---|
164 | int lineNumber; /* Parse line number */ |
---|
165 | int lineColumn; /* Column in line */ |
---|
166 | } ejinput_t; |
---|
167 | |
---|
168 | /* |
---|
169 | * Per Ejscript session structure |
---|
170 | */ |
---|
171 | typedef struct ej { |
---|
172 | ejinput_t *input; /* Input evaluation block */ |
---|
173 | sym_fd_t functions; /* Symbol table for functions */ |
---|
174 | sym_fd_t *variables; /* hAlloc list of variables */ |
---|
175 | int variableMax; /* Number of entries */ |
---|
176 | ejfunc_t *func; /* Current function */ |
---|
177 | char_t *result; /* Current expression result */ |
---|
178 | char_t *error; /* Error message */ |
---|
179 | char_t *token; /* Pointer to token string */ |
---|
180 | int tid; /* Current token id */ |
---|
181 | int eid; /* Halloc handle */ |
---|
182 | int flags; /* Flags */ |
---|
183 | int userHandle; /* User defined handle */ |
---|
184 | } ej_t; |
---|
185 | |
---|
186 | /******************************** Prototypes **********************************/ |
---|
187 | |
---|
188 | extern int ejOpenBlock(int eid); |
---|
189 | extern int ejCloseBlock(int eid, int vid); |
---|
190 | extern char_t *ejEvalBlock(int eid, char_t *script, char_t **emsg); |
---|
191 | #ifndef __NO_EJ_FILE |
---|
192 | extern char_t *ejEvalFile(int eid, char_t *path, char_t **emsg); |
---|
193 | #endif |
---|
194 | extern int ejRemoveGlobalFunction(int eid, char_t *name); |
---|
195 | extern void *ejGetGlobalFunction(int eid, char_t *name); |
---|
196 | extern int ejSetGlobalFunctionDirect(sym_fd_t functions, char_t *name, |
---|
197 | int (*fn)(int eid, void *handle, int argc, char_t **argv)); |
---|
198 | extern void ejError(ej_t* ep, char_t* fmt, ...); |
---|
199 | extern void ejSetUserHandle(int eid, int handle); |
---|
200 | extern int ejGetUserHandle(int eid); |
---|
201 | extern int ejGetLineNumber(int eid); |
---|
202 | extern char_t *ejGetResult(int eid); |
---|
203 | extern void ejSetLocalVar(int eid, char_t *var, char_t *value); |
---|
204 | extern void ejSetGlobalVar(int eid, char_t *var, char_t *value); |
---|
205 | |
---|
206 | extern int ejLexOpen(ej_t* ep); |
---|
207 | extern void ejLexClose(ej_t* ep); |
---|
208 | extern int ejLexOpenScript(ej_t* ep, char_t *script); |
---|
209 | extern void ejLexCloseScript(ej_t* ep); |
---|
210 | extern void ejLexSaveInputState(ej_t* ep, ejinput_t* state); |
---|
211 | extern void ejLexFreeInputState(ej_t* ep, ejinput_t* state); |
---|
212 | extern void ejLexRestoreInputState(ej_t* ep, ejinput_t* state); |
---|
213 | extern int ejLexGetToken(ej_t* ep, int state); |
---|
214 | extern void ejLexPutbackToken(ej_t* ep, int tid, char_t *string); |
---|
215 | |
---|
216 | extern sym_fd_t ejGetVariableTable(int eid); |
---|
217 | extern sym_fd_t ejGetFunctionTable(int eid); |
---|
218 | |
---|
219 | extern int ejEmfOpen(int eid); |
---|
220 | extern void ejEmfClose(int eid); |
---|
221 | |
---|
222 | extern int ejEmfDbRead(int eid, void *handle, int argc, char_t **argv); |
---|
223 | extern int ejEmfDbReadKeyed(int eid, void *handle, int argc, char_t **argv); |
---|
224 | extern int ejEmfDbTableGetNrow(int eid, void *handle, int argc, char_t **argv); |
---|
225 | extern int ejEmfDbDeleteRow(int eid, void *handle, int argc, char_t **argv); |
---|
226 | extern int ejEmfTrace(int eid, void *handle, int argc, char_t **argv); |
---|
227 | extern int ejEmfDbWrite(int eid, void *handle, int argc, char_t **argv); |
---|
228 | extern int ejEmfDbCollectTable(int eid, void *handle, int argc, char_t **argv); |
---|
229 | |
---|
230 | #endif /* _h_EJINTERNAL */ |
---|