| 1 |
// Unicode support by Jim Park -- 08/22/2007 |
| 2 |
|
| 3 |
#pragma once |
| 4 |
|
| 5 |
#include <math.h> |
| 6 |
#include <float.h> |
| 7 |
#include <nsis/nsis_tchar.h> |
| 8 |
|
| 9 |
#define DEFAULT_ARRAY_SIZE 1024 |
| 10 |
|
| 11 |
#define ITEMTYPE 0xFF0000 |
| 12 |
// items classes |
| 13 |
#define IT_CONST 0x000000 |
| 14 |
#define IT_EXPRESSION 0x010000 |
| 15 |
#define IT_OPERATOR 0x020000 |
| 16 |
#define IT_VARIABLE 0x030000 |
| 17 |
#define IT_LOGIC 0x040000 // flow control items |
| 18 |
#define IT_FUNCTION 0x050000 |
| 19 |
#define IT_ARRAY 0x060000 // array operation |
| 20 |
|
| 21 |
#define ITEMSUBTYPE 0x00FF00 |
| 22 |
// const items |
| 23 |
#define ITC_STRING 0x000100 |
| 24 |
#define ITC_FLOAT 0x000200 |
| 25 |
#define ITC_INT 0x000400 |
| 26 |
#define ITC_ARRAY 0x000800 |
| 27 |
#define ITC_UNKNOWN 0x001000 |
| 28 |
|
| 29 |
// type function |
| 30 |
#define FTT_FLOATF (ITC_UNKNOWN << 0) |
| 31 |
#define FTT_LEN (ITC_UNKNOWN << 1) |
| 32 |
#define FTT_CHAR (ITC_UNKNOWN << 2) |
| 33 |
|
| 34 |
// additional option - for "ca" function |
| 35 |
#define ITFA_COPY 0x000001 |
| 36 |
|
| 37 |
// ops items |
| 38 |
#define ITO_MINUS 0x000100 |
| 39 |
#define ITO_PLUS 0x000200 |
| 40 |
#define ITO_SHL 0x000300 |
| 41 |
#define ITO_SHR 0x000400 |
| 42 |
#define ITO_MUL 0x000500 |
| 43 |
#define ITO_DIV 0x000600 |
| 44 |
#define ITO_SET 0x000700 |
| 45 |
#define ITO_LAND 0x000800 |
| 46 |
#define ITO_LOR 0x000900 |
| 47 |
#define ITO_INC 0x000A00 |
| 48 |
#define ITO_DEC 0x000B00 |
| 49 |
#define ITO_LE 0x000C00 |
| 50 |
#define ITO_GE 0x000D00 |
| 51 |
#define ITO_NE 0x000E00 |
| 52 |
#define ITO_EQ 0x000F00 |
| 53 |
#define ITO_LS 0x001000 |
| 54 |
#define ITO_GR 0x001100 |
| 55 |
#define ITO_AND 0x001200 |
| 56 |
#define ITO_MOD 0x001300 |
| 57 |
#define ITO_OR 0x001400 |
| 58 |
#define ITO_XOR 0x001500 |
| 59 |
#define ITO_NOT 0x001600 |
| 60 |
#define ITO_LNOT 0x001700 |
| 61 |
|
| 62 |
// variables sub-types |
| 63 |
#define ITV_NSIS 0x000100 |
| 64 |
#define ITV_USER 0x000200 |
| 65 |
#define ITV_ARRITEM 0x000400 |
| 66 |
#define ITV_STACK 0x000800 // plugin specific stack |
| 67 |
#define ITV_NSTACK 0x001000 // nsis stack |
| 68 |
|
| 69 |
// logic sub-types |
| 70 |
#define ITL_IF 0x000100 |
| 71 |
#define ITL_WHILE 0x000200 |
| 72 |
|
| 73 |
// function sub-types |
| 74 |
#define ITF_MATH1 0x000100 |
| 75 |
#define ITF_MATH2 0x000200 |
| 76 |
#define ITF_TYPE 0x000300 |
| 77 |
#define ITF_USER 0x000400 |
| 78 |
|
| 79 |
// array items sub-types |
| 80 |
#define ITA_ACCESS 0x000000 |
| 81 |
|
| 82 |
#define ITEMOPTIONS 0x0000FF |
| 83 |
|
| 84 |
// 16 bytes structure |
| 85 |
typedef struct __ExpressionItem ExpressionItem; |
| 86 |
//#define EIPARAM int |
| 87 |
#define EIPARAM ExpressionItem* |
| 88 |
typedef struct __ExpressionItem |
| 89 |
{ |
| 90 |
int type; |
| 91 |
EIPARAM param1; |
| 92 |
EIPARAM param2; |
| 93 |
ExpressionItem *next; |
| 94 |
} ExpressionItem; |
| 95 |
|
| 96 |
typedef struct __ParseInfo |
| 97 |
{ |
| 98 |
int SetupNewRoot; |
| 99 |
ExpressionItem *item; |
| 100 |
ExpressionItem *OpsStack; |
| 101 |
ExpressionItem **place; |
| 102 |
ExpressionItem **root; |
| 103 |
TCHAR valbuf[108]; |
| 104 |
} ParseInfo; |
| 105 |
|
| 106 |
#define OPERATOR_SET_PRECEDENCE 14 |
| 107 |
typedef struct __OpStruct |
| 108 |
{ |
| 109 |
TCHAR name[3]; |
| 110 |
unsigned char precedence; |
| 111 |
unsigned short int type; |
| 112 |
} OpStruct; |
| 113 |
|
| 114 |
#define MAX_USER_VARS 256 |
| 115 |
typedef struct __UserVar |
| 116 |
{ |
| 117 |
TCHAR name[28]; |
| 118 |
ExpressionItem *item; |
| 119 |
} UserVar; |
| 120 |
|
| 121 |
#define MAX_USER_FUNCS 256 |
| 122 |
typedef struct __UserFunc |
| 123 |
{ |
| 124 |
TCHAR name[20]; |
| 125 |
unsigned char vars[31]; // only used for indexing |
| 126 |
unsigned char varsnum; // number of vars < 256 |
| 127 |
unsigned int varflags; |
| 128 |
ExpressionItem *root; |
| 129 |
} UserFunc; |
| 130 |
|
| 131 |
typedef struct __ArrayDesc |
| 132 |
{ |
| 133 |
ExpressionItem **array; |
| 134 |
int size; // size of allocated items pool |
| 135 |
int count; // max number of item accessed |
| 136 |
int references; // array will be killed at CleanupItems only when references == 0 |
| 137 |
} ArrayDesc; |
| 138 |
|
| 139 |
typedef double (*Math1FuncPtr)(double arg); |
| 140 |
typedef double (*Math2FuncPtr)(double arg, double arg2); |
| 141 |
typedef double (*Math2iFuncPtr)(double arg, int *arg2); |
| 142 |
typedef double (*Math2dFuncPtr)(double arg, double *arg2); |
| 143 |
|
| 144 |
typedef struct __MathFunction |
| 145 |
{ |
| 146 |
TCHAR name[3]; |
| 147 |
unsigned char type; |
| 148 |
Math1FuncPtr fptr; |
| 149 |
} MathFunction; |
| 150 |
|
| 151 |
#define STI_STRING 0x0100 |
| 152 |
#define STI_FLOAT 0x0200 |
| 153 |
#define STI_INT 0x0400 |
| 154 |
|
| 155 |
#define FF_DEFAULT 0x00 // uses default mode: if available noexp, else exp |
| 156 |
#define FF_NOEXP 0x10 // uses noexp mode |
| 157 |
#define FF_EXP 0x20 // uses exp mode (small e) |
| 158 |
#define FF_LEXP 0x40 // uses exp mode (large E) |
| 159 |
|
| 160 |
// RunTree options |
| 161 |
#define RTO_NEEDCONST 0x0001 |
| 162 |
#define RTO_PREFFEREDTYPE 0xFF00 |
| 163 |
void RunTree(ExpressionItem *from, ExpressionItem* &result, int type); |
| 164 |
|
| 165 |
void StringToItem(TCHAR *&sbuf, ExpressionItem *item, int options); |
| 166 |
void ItemToString(TCHAR *sbuf, ExpressionItem *item); |
| 167 |
void FloatFormat(TCHAR *sbuf, double value, int options); |
| 168 |
void itoa64(__int64 i, TCHAR *buffer); |
| 169 |
int lstrcmpn(TCHAR *s1, const TCHAR *s2, int chars); |