diff options
Diffstat (limited to 'lib/execute.h')
-rw-r--r-- | lib/execute.h | 179 |
1 files changed, 179 insertions, 0 deletions
diff --git a/lib/execute.h b/lib/execute.h new file mode 100644 index 0000000..b3cbb40 --- /dev/null +++ b/lib/execute.h @@ -0,0 +1,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 */ |