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