1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
/*
* AUTHOR
* N. Nielsen
*
* VERSION
* 2.1.2b
*
* LICENSE
* This software is in the public domain.
*
* The software is provided "as is", without warranty of any kind,
* express or implied, including but not limited to the warranties
* of merchantability, fitness for a particular purpose, and
* noninfringement. In no event shall the author(s) be liable for any
* claim, damages, or other liability, whether in an action of
* contract, tort, or otherwise, arising from, out of, or in connection
* with the software or the use or other dealings in the software.
*
* SUPPORT
* Send bug reports to: <nielsen@memberwebs.com>
*/
#ifndef __EXECUTE_H__20010618
#define __EXECUTE_H__20010618
#include "ops.h"
/* Allocate Locks, Memory and Variables in blocks this size */
#define BLOCK_SIZE 0x20
static const size_t kNoMatch = 0xFFFFFFFF;
static const size_t kInfinity = 0xFFFFFFFE;
/* Maximum amount of registers allowed */
#define MAX_REGS 10
/* =============================================================================
* MEMORY:
*/
typedef struct _memory
{
/* Internal structure */
struct mem
{
uint key;
uint value;
}
*thememory;
struct _memory* prev;
size_t alloc; /* amount allocated of above */
size_t cur; /* amount used */
}
memory;
bool memoryInit(memory* mem);
void memoryFree(memory* mem);
uint* memoryValue(memory* mem, uint key);
void memoryClearAll(memory* mem);
/* =============================================================================
* DATA:
*/
typedef struct _data
{
/* Internal structure */
struct dat
{
void* key;
void* value;
}
*thedata;
size_t alloc; /* amount allocated of above */
size_t cur; /* amount used */
}
data;
bool dataInit(data* dat);
void dataFree(data* dat);
void* dataGetValue(data* dat, void* key);
bool dataSetValue(data* dat, void* key, void* value);
void dataClearAll(data* dat);
/* ==========================================================================
* VARIABLES: Contains set of variables (and variable arrays) currently
* set. This is maintained across blocks.
*/
typedef struct _variables
{
/* Internal structure */
struct vari
{
char* name;
char* value;
}
*thevars;
size_t alloc; /* Amount allocated */
size_t cur; /* Amount used */
}
variables;
bool variablesInit(variables* vars);
void variablesFree(variables* vars);
bool variablesAdd(variables* vars, const char* name, const char* val);
bool variablesAddBytes(variables* vars, const char* name,
const char* val, size_t cnt);
bool variablesClear(variables* vars, const char* name);
bool variablesClearAll(variables* vars);
int variablesSubstitute(variables* vars, r_stream* stream, r_script* script,
char** pstr, bool mode);
bool variablesValidName(const char* name);
bool variablesHasVars(const char* string);
/* ======================================================================
* REPLACEMENT: A list of replacements to be written out.
*/
typedef struct _replacement
{
size_t beg; /* Beginning of text to be replaced */
size_t end; /* end ditto */
struct _replacement* next; /* next replacement in list */
char text[1]; /* Text to replace with (hangs of end) */
}
replacement;
/* Allocate a replacement for the given text. */
int replacementAlloc(r_stream* stream, const char* text, replacement** pprep);
/* Place replacement in the replacement list in the appropriate order */
void replacementAdd(replacement* repl, r_stream* stream);
/* Remove the first replacement in the replacement list and return */
replacement* replacementPop(replacement* repl);
/* Dump all replacements to stderr */
void replacementDump(r_stream* stream);
/* ======================================================================
* LOCKS: A list of locks to be checked against
*/
typedef struct _locks
{
/* Internal structure */
struct lock
{
size_t beg;
size_t end;
}
*thelocks;
size_t cur;
size_t alloc;
}
locks;
bool locksInit();
void locksFree();
bool locksAdd(locks* lcks, size_t beg, size_t end);
bool locksCheck(locks* lcks, r_stream* stream, size_t beg, size_t end);
#define locksClearAll(lcks) ((lcks)->cur = 0)
#define locksSize(lcks) ((lcks)->cur)
#define locksBeg(lcks, idx) ((lcks)->thelocks[idx].beg)
#define locksEnd(lcks, idx) ((lcks)->thelocks[idx].end)
bool isEscaped(const char* str, const char* posi);
#endif /* __EXECUTE_H__20010618 */
|