Jim Park's Unicode NSIS merging - Step 1 : switch to TCHARs where relevant.

Compiler output is identical before & after this step

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/branches/wizou@6036 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
wizou 2010-03-24 17:22:56 +00:00
parent 4e48722b63
commit 752d7d239a
209 changed files with 9698 additions and 7658 deletions

View file

@ -1,3 +1,5 @@
// Unicode support by Jim Park -- 08/22/2007
#include <windows.h>
#include <nsis/pluginapi.h> // nsis plugin
#include "MyMath.h"
@ -15,12 +17,12 @@ int UserVarsCount, UserFuncsCount;
UserVar UserVars[MAX_USER_VARS];
UserFunc UserFuncs[MAX_USER_FUNCS];
void PrintTree(ExpressionItem *root, char *str);
void ParseString(char *&sp, ExpressionItem* &itemplace);
void PrintTree(ExpressionItem *root, TCHAR *str);
void ParseString(TCHAR *&sp, ExpressionItem* &itemplace);
void CleanupItems(ExpressionItem* &itemplace);
void PlaceVariable(char *&vb, ParseInfo *pi);
void PlaceVariable(TCHAR *&vb, ParseInfo *pi);
void PlaceNewItem(char *&vb, ParseInfo *pi, int precedence)
void PlaceNewItem(TCHAR *&vb, ParseInfo *pi, int precedence)
{
ExpressionItem *newroot;
PlaceVariable(vb, pi);
@ -56,12 +58,12 @@ void PlaceNewItem(char *&vb, ParseInfo *pi, int precedence)
#define NSIS_VARS_STACK 25
#define NSIS_VARS_NSTACK 26
typedef char smallstr[2];
const smallstr NSISVariablesNames[NSIS_VARS_COUNT] = {{'r','0'}, {'r','1'}, {'r','2'}, {'r','3'}, {'r','4'}, {'r','5'}, {'r','6'}, {'r','7'}, {'r','8'}, {'r','9'},
{'R','0'}, {'R','1'}, {'R','2'}, {'R','3'}, {'R','4'}, {'R','5'}, {'R','6'}, {'R','7'}, {'R','8'}, {'R','9'},
{'C','L'}, {'I','D'}, {'O','D'}, {'E','D'}, {'L','G'}, {'S',0}, {'N','S'}};
typedef TCHAR smallstr[2];
const smallstr NSISVariablesNames[NSIS_VARS_COUNT] = {{_T('r'),_T('0')}, {_T('r'),_T('1')}, {_T('r'),_T('2')}, {_T('r'),_T('3')}, {_T('r'),_T('4')}, {_T('r'),_T('5')}, {_T('r'),_T('6')}, {_T('r'),_T('7')}, {_T('r'),_T('8')}, {_T('r'),_T('9')},
{_T('R'),_T('0')}, {_T('R'),_T('1')}, {_T('R'),_T('2')}, {_T('R'),_T('3')}, {_T('R'),_T('4')}, {_T('R'),_T('5')}, {_T('R'),_T('6')}, {_T('R'),_T('7')}, {_T('R'),_T('8')}, {_T('R'),_T('9')},
{_T('C'),_T('L')}, {_T('I'),_T('D')}, {_T('O'),_T('D')}, {_T('E'),_T('D')}, {_T('L'),_T('G')}, {_T('S'),0}, {_T('N'),_T('S')}};
ExpressionItem *FindVariable(char *varname)
ExpressionItem *FindVariable(TCHAR *varname)
{
int i;
@ -98,7 +100,7 @@ ExpressionItem *FindVariable(char *varname)
return item;
}
void PlaceVariable(char *&vb, ParseInfo *pi)
void PlaceVariable(TCHAR *&vb, ParseInfo *pi)
{
if (vb <= pi->valbuf) return;
*vb = 0;
@ -112,43 +114,43 @@ typedef double (*math_di)(double, int*);
#define MATHFUNCNUM 29
const MathFunction MathFunctions[MATHFUNCNUM] = {
{{'s','i','n'}, ITF_MATH1 >> 8, sin},
{{'s','n','h'}, ITF_MATH1 >> 8, sinh},
{{'a','s','n'}, ITF_MATH1 >> 8, asin},
{{'c','o','s'}, ITF_MATH1 >> 8, cos},
{{'c','s','h'}, ITF_MATH1 >> 8, cosh},
{{'a','c','s'}, ITF_MATH1 >> 8, acos},
{{'t','a','n'}, ITF_MATH1 >> 8, tan},
{{'t','n','h'}, ITF_MATH1 >> 8, tanh},
{{'a','t','n'}, ITF_MATH1 >> 8, atan},
{{'a','b','s'}, ITF_MATH1 >> 8, fabs},
{{'l','n',0}, ITF_MATH1 >> 8, log},
{{'l','o','g'}, ITF_MATH1 >> 8, log10},
{{'e','x','p'}, ITF_MATH1 >> 8, exp},
{{'s','q','t'}, ITF_MATH1 >> 8, sqrt},
{{'c','e','l'}, ITF_MATH1 >> 8, ceil},
{{'f','l','r'}, ITF_MATH1 >> 8, floor},
{{_T('s'),_T('i'),_T('n')}, ITF_MATH1 >> 8, sin},
{{_T('s'),_T('n'),_T('h')}, ITF_MATH1 >> 8, sinh},
{{_T('a'),_T('s'),_T('n')}, ITF_MATH1 >> 8, asin},
{{_T('c'),_T('o'),_T('s')}, ITF_MATH1 >> 8, cos},
{{_T('c'),_T('s'),_T('h')}, ITF_MATH1 >> 8, cosh},
{{_T('a'),_T('c'),_T('s')}, ITF_MATH1 >> 8, acos},
{{_T('t'),_T('a'),_T('n')}, ITF_MATH1 >> 8, tan},
{{_T('t'),_T('n'),_T('h')}, ITF_MATH1 >> 8, tanh},
{{_T('a'),_T('t'),_T('n')}, ITF_MATH1 >> 8, atan},
{{_T('a'),_T('b'),_T('s')}, ITF_MATH1 >> 8, fabs},
{{_T('l'),_T('n'),0}, ITF_MATH1 >> 8, log},
{{_T('l'),_T('o'),_T('g')}, ITF_MATH1 >> 8, log10},
{{_T('e'),_T('x'),_T('p')}, ITF_MATH1 >> 8, exp},
{{_T('s'),_T('q'),_T('t')}, ITF_MATH1 >> 8, sqrt},
{{_T('c'),_T('e'),_T('l')}, ITF_MATH1 >> 8, ceil},
{{_T('f'),_T('l'),_T('r')}, ITF_MATH1 >> 8, floor},
{{'a','t','2'}, ITF_MATH2 >> 8, (Math1FuncPtr)(math_d2)atan2},
{{'p','o','w'}, ITF_MATH2 >> 8, (Math1FuncPtr)(math_d2)pow},
{{'f','m','d'}, ITF_MATH2 >> 8, (Math1FuncPtr)(math_d2)fmod},
{{_T('a'),_T('t'),_T('2')}, ITF_MATH2 >> 8, (Math1FuncPtr)(math_d2)atan2},
{{_T('p'),_T('o'),_T('w')}, ITF_MATH2 >> 8, (Math1FuncPtr)(math_d2)pow},
{{_T('f'),_T('m'),_T('d')}, ITF_MATH2 >> 8, (Math1FuncPtr)(math_d2)fmod},
// type conversions
{{'i',0,0}, ITF_TYPE >> 8, (Math1FuncPtr)ITC_INT},
{{'s',0,0}, ITF_TYPE >> 8, (Math1FuncPtr)ITC_STRING},
{{'f',0,0}, ITF_TYPE >> 8, (Math1FuncPtr)ITC_FLOAT},
{{'a',0,0}, ITF_TYPE >> 8, (Math1FuncPtr)ITC_ARRAY},
{{_T('i'),0,0}, ITF_TYPE >> 8, (Math1FuncPtr)ITC_INT},
{{_T('s'),0,0}, ITF_TYPE >> 8, (Math1FuncPtr)ITC_STRING},
{{_T('f'),0,0}, ITF_TYPE >> 8, (Math1FuncPtr)ITC_FLOAT},
{{_T('a'),0,0}, ITF_TYPE >> 8, (Math1FuncPtr)ITC_ARRAY},
#define ITFT_CARRAY_ID 23
{{'c','a',0}, ITF_TYPE >> 8, (Math1FuncPtr)ITC_ARRAY},
{{'f','f',0}, ITF_TYPE >> 8, (Math1FuncPtr)FTT_FLOATF},
{{'l',0,0}, ITF_TYPE >> 8, (Math1FuncPtr)FTT_LEN},
{{'c',0,0}, ITF_TYPE >> 8, (Math1FuncPtr)FTT_CHAR},
{{_T('c'),_T('a'),0}, ITF_TYPE >> 8, (Math1FuncPtr)ITC_ARRAY},
{{_T('f'),_T('f'),0}, ITF_TYPE >> 8, (Math1FuncPtr)FTT_FLOATF},
{{_T('l'),0,0}, ITF_TYPE >> 8, (Math1FuncPtr)FTT_LEN},
{{_T('c'),0,0}, ITF_TYPE >> 8, (Math1FuncPtr)FTT_CHAR},
{{'f','e','x'}, ITF_MATH2 >> 8, (Math1FuncPtr)(math_di)frexp},
{{'m','d','f'}, ITF_MATH2 >> 8, (Math1FuncPtr)(math_ddp)modf},
{{_T('f'),_T('e'),_T('x')}, ITF_MATH2 >> 8, (Math1FuncPtr)(math_di)frexp},
{{_T('m'),_T('d'),_T('f')}, ITF_MATH2 >> 8, (Math1FuncPtr)(math_ddp)modf},
};
void PlaceFunction(char *&vb, char *&sp, ParseInfo *pi, int redefine)
void PlaceFunction(TCHAR *&vb, TCHAR *&sp, ParseInfo *pi, int redefine)
{
int i;
ExpressionItem *item = pi->item = AllocItem();
@ -163,7 +165,7 @@ void PlaceFunction(char *&vb, char *&sp, ParseInfo *pi, int redefine)
// get first argument
sp++;
ParseString(sp, *((ExpressionItem **)(&item->param1)));
if (*sp == ',')
if (*sp == _T(','))
{
// get second argument
sp++;
@ -185,7 +187,7 @@ void PlaceFunction(char *&vb, char *&sp, ParseInfo *pi, int redefine)
item->type = IT_FUNCTION | ITF_USER | i;
// get arguments list
ExpressionItem **newplace = ((ExpressionItem **)(&pi->item->param1));
while (*sp != ')')
while (*sp != _T(')'))
{
*newplace = AllocItem();
(*newplace)->type = IT_EXPRESSION;
@ -203,7 +205,7 @@ void PlaceFunction(char *&vb, char *&sp, ParseInfo *pi, int redefine)
// it's user function define
int flags = 0;
char buffer[128], *buf = buffer;
TCHAR buffer[128], *buf = buffer;
// workaround for redefine flag - if the function already present,
// it will be cleared and redefined
@ -219,10 +221,10 @@ void PlaceFunction(char *&vb, char *&sp, ParseInfo *pi, int redefine)
sp++;
switch (*sp)
{
case ' ':
case _T(' '):
break;
case ',':
case ')':
case _T(','):
case _T(')'):
if (buf > buffer)
{
*buf = 0;
@ -234,7 +236,7 @@ void PlaceFunction(char *&vb, char *&sp, ParseInfo *pi, int redefine)
flags <<= 1;
}
break;
case '&':
case _T('&'):
flags |= 1;
break;
default:
@ -242,7 +244,7 @@ void PlaceFunction(char *&vb, char *&sp, ParseInfo *pi, int redefine)
break;
}
}
while (*sp != ')');
while (*sp != _T(')'));
// prepare flag for fast analisys
for (i = 0; i < f->varsnum; i++)
@ -253,7 +255,7 @@ void PlaceFunction(char *&vb, char *&sp, ParseInfo *pi, int redefine)
}
// find nearest round bracket - function body
while (*sp != '(' && *sp) sp++;
while (*sp != _T('(') && *sp) sp++;
if (!*sp)
return;
sp++;
@ -265,17 +267,17 @@ void PlaceFunction(char *&vb, char *&sp, ParseInfo *pi, int redefine)
#ifdef _DEBUG
// dump function (in debug mode)
char place[1024];
wsprintf(place, "function %s(", f->name);
TCHAR place[1024];
wsprintf(place, _T("function %s("), f->name);
flags = f->varflags;
for (i = 0; i < f->varsnum; i++)
{
if (flags&1) lstrcat(place, "&");
if (flags&1) lstrcat(place, _T("&"));
lstrcat(place, UserVars[f->vars[i]].name);
if (i < f->varsnum-1) lstrcat(place, ", ");
if (i < f->varsnum-1) lstrcat(place, _T(", "));
flags >>= 1;
}
lstrcat(place, ")");
lstrcat(place, _T(")"));
PrintTree(f->root, place);
#endif
}
@ -290,7 +292,7 @@ void PlaceFunction(char *&vb, char *&sp, ParseInfo *pi, int redefine)
#define PO_USESPRE 0x40 // operator will use pre operand
#define PO_USESPOST 0x80 // operator will use post operan
void PlaceOp(char *&vb, int type, int precedence, ParseInfo *pi)
void PlaceOp(TCHAR *&vb, int type, int precedence, ParseInfo *pi)
{
PlaceVariable(vb, pi);
if ((type & PO_UNARYPRE) && (!pi->item))
@ -332,54 +334,54 @@ void PlaceOp(char *&vb, int type, int precedence, ParseInfo *pi)
const OpStruct Operators[OPSNUM] =
{
// three byte ops
{{'>','>','='}, 14, ITO_SHR | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST},
{{'<','<','='}, 14, ITO_SHL | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST},
{{_T('>'),_T('>'),_T('=')}, 14, ITO_SHR | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST},
{{_T('<'),_T('<'),_T('=')}, 14, ITO_SHL | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST},
// two byte ops
// !!! don't forget to change Set Operator Precedence !!!
{"-=", 14, ITO_MINUS | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST},
{"+=", 14, ITO_PLUS | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST},
{"/=", 14, ITO_DIV | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST},
{"*=", 14, ITO_MUL | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST},
{"|=", 14, ITO_OR | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST},
{"&=", 14, ITO_AND | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST},
{"^=", 14, ITO_XOR | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST},
{"%=", 14, ITO_MOD | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST},
{"--", 2, ITO_DEC | PO_POSTNONCONST | PO_PRENONCONST | PO_UNARYPRE | PO_UNARYPOST | PO_SET | PO_USESPRE | PO_USESPOST},
{"++", 2, ITO_INC | PO_POSTNONCONST | PO_PRENONCONST | PO_UNARYPRE | PO_UNARYPOST | PO_SET | PO_USESPRE | PO_USESPOST},
{">>", 6, ITO_SHR | PO_USESPRE | PO_USESPOST},
{"<<", 6, ITO_SHL | PO_USESPRE | PO_USESPOST},
{_T("-="), 14, ITO_MINUS | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST},
{_T("+="), 14, ITO_PLUS | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST},
{_T("/="), 14, ITO_DIV | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST},
{_T("*="), 14, ITO_MUL | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST},
{_T("|="), 14, ITO_OR | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST},
{_T("&="), 14, ITO_AND | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST},
{_T("^="), 14, ITO_XOR | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST},
{_T("%="), 14, ITO_MOD | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST},
{_T("--"), 2, ITO_DEC | PO_POSTNONCONST | PO_PRENONCONST | PO_UNARYPRE | PO_UNARYPOST | PO_SET | PO_USESPRE | PO_USESPOST},
{_T("++"), 2, ITO_INC | PO_POSTNONCONST | PO_PRENONCONST | PO_UNARYPRE | PO_UNARYPOST | PO_SET | PO_USESPRE | PO_USESPOST},
{_T(">>"), 6, ITO_SHR | PO_USESPRE | PO_USESPOST},
{_T("<<"), 6, ITO_SHL | PO_USESPRE | PO_USESPOST},
// logical
{"&&", 12, ITO_LAND | PO_USESPRE | PO_USESPOST},
{"||", 13, ITO_LOR | PO_USESPRE | PO_USESPOST},
{_T("&&"), 12, ITO_LAND | PO_USESPRE | PO_USESPOST},
{_T("||"), 13, ITO_LOR | PO_USESPRE | PO_USESPOST},
// comparisons
{"<=", 7, ITO_LE | PO_USESPRE | PO_USESPOST},
{"=<", 7, ITO_LE | PO_USESPRE | PO_USESPOST},
{">=", 7, ITO_GE | PO_USESPRE | PO_USESPOST},
{"=>", 7, ITO_GE | PO_USESPRE | PO_USESPOST},
{"!=", 8, ITO_NE | PO_USESPRE | PO_USESPOST},
{"==", 8, ITO_EQ | PO_USESPRE | PO_USESPOST},
{_T("<="), 7, ITO_LE | PO_USESPRE | PO_USESPOST},
{_T("=<"), 7, ITO_LE | PO_USESPRE | PO_USESPOST},
{_T(">="), 7, ITO_GE | PO_USESPRE | PO_USESPOST},
{_T("=>"), 7, ITO_GE | PO_USESPRE | PO_USESPOST},
{_T("!="), 8, ITO_NE | PO_USESPRE | PO_USESPOST},
{_T("=="), 8, ITO_EQ | PO_USESPRE | PO_USESPOST},
// single byte ops
// !!! don't forget to change Set Operator Precedence !!!
{"=", 14, ITO_SET | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPOST},
{"+", 5, ITO_PLUS | PO_USESPRE | PO_USESPOST},
{"-", 5, ITO_MINUS | PO_USESPRE | PO_USESPOST | PO_UNARYPRE},
{"*", 4, ITO_MUL | PO_USESPRE | PO_USESPOST | PO_UNARYPRE},
{"/", 4, ITO_DIV | PO_USESPRE | PO_USESPOST},
{"%", 4, ITO_MOD | PO_USESPRE | PO_USESPOST},
{"<", 7, ITO_LS | PO_USESPRE | PO_USESPOST},
{">", 7, ITO_GR | PO_USESPRE | PO_USESPOST},
{"&", 9, ITO_AND | PO_USESPRE | PO_USESPOST | PO_UNARYPRE},
{"|", 11, ITO_OR | PO_USESPRE | PO_USESPOST},
{"^", 10, ITO_XOR | PO_USESPRE | PO_USESPOST},
{"~", 3, ITO_NOT | PO_USESPOST | PO_UNARYPRE},
{"!", 3, ITO_LNOT |PO_USESPOST | PO_UNARYPRE}
{_T("="), 14, ITO_SET | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPOST},
{_T("+"), 5, ITO_PLUS | PO_USESPRE | PO_USESPOST},
{_T("-"), 5, ITO_MINUS | PO_USESPRE | PO_USESPOST | PO_UNARYPRE},
{_T("*"), 4, ITO_MUL | PO_USESPRE | PO_USESPOST | PO_UNARYPRE},
{_T("/"), 4, ITO_DIV | PO_USESPRE | PO_USESPOST},
{_T("%"), 4, ITO_MOD | PO_USESPRE | PO_USESPOST},
{_T("<"), 7, ITO_LS | PO_USESPRE | PO_USESPOST},
{_T(">"), 7, ITO_GR | PO_USESPRE | PO_USESPOST},
{_T("&"), 9, ITO_AND | PO_USESPRE | PO_USESPOST | PO_UNARYPRE},
{_T("|"), 11, ITO_OR | PO_USESPRE | PO_USESPOST},
{_T("^"), 10, ITO_XOR | PO_USESPRE | PO_USESPOST},
{_T("~"), 3, ITO_NOT | PO_USESPOST | PO_UNARYPRE},
{_T("!"), 3, ITO_LNOT |PO_USESPOST | PO_UNARYPRE}
};
void CheckForOperator(char *&sp, char *&vb, ParseInfo *pi)
void CheckForOperator(TCHAR *&sp, TCHAR *&vb, ParseInfo *pi)
{
for (int op = 0; op < OPSNUM; op++)
{
@ -397,44 +399,44 @@ void CheckForOperator(char *&sp, char *&vb, ParseInfo *pi)
}
}
void ParseString(char *&sp, ExpressionItem* &itemplace)
void ParseString(TCHAR *&sp, ExpressionItem* &itemplace)
{
ParseInfo pi = {0, NULL, NULL, &itemplace, &itemplace};
int redefine = 0;
char *vb = pi.valbuf;
TCHAR *vb = pi.valbuf;
// cycle until current expression end
while ((*sp != 0) && (*sp != ')') && (*sp != '}') &&
(*sp != ']') && (*sp != ','))
while ((*sp != 0) && (*sp != _T(')')) && (*sp != _T('}')) &&
(*sp != _T(']')) && (*sp != _T(',')))
{
int processed = 1;
switch (*sp)
{
case ' ':
case '\t':
case _T(' '):
case _T('\t'):
sp++;
break;
case ';':
case _T(';'):
// expression delimeter
PlaceNewItem(vb, &pi, 255);
if (*pi.root) pi.SetupNewRoot = 1;
sp++;
break;
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
case _T('0'): case _T('1'): case _T('2'): case _T('3'): case _T('4'):
case _T('5'): case _T('6'): case _T('7'): case _T('8'): case _T('9'):
// variable & function names could contain numbers as non first chars
if (vb > pi.valbuf)
{
processed = FALSE;
break;
}
case '\'': case '\"': case '`':
case _T('\''): case _T('\"'): case _T('`'):
// constant meet
pi.item = AllocItem();
StringToItem(sp, pi.item, STI_STRING | STI_FLOAT | STI_INT);
break;
case '(': // start of function or expression
case _T('('): // start of function or expression
if (vb > pi.valbuf)
{
// thats function
@ -444,14 +446,14 @@ void ParseString(char *&sp, ExpressionItem* &itemplace)
// expression
sp++;
ParseString(sp, pi.item);
if (*sp == ')') sp++;
if (*sp == _T(')')) sp++;
}
redefine = 0;
break;
case '#': // start of one of logical expresions
case _T('#'): // start of one of logical expresions
sp++;
if ((*sp != '[') && (*sp != '{'))
if ((*sp != _T('[')) && (*sp != _T('{')))
{
// function redefine flag
redefine = 1;
@ -460,14 +462,14 @@ void ParseString(char *&sp, ExpressionItem* &itemplace)
{
pi.item = AllocItem();
// IF or WHILE
pi.item->type = ((*sp == '[')?(IT_LOGIC | ITL_IF):(IT_LOGIC | ITL_WHILE));
pi.item->type = ((*sp == _T('['))?(IT_LOGIC | ITL_IF):(IT_LOGIC | ITL_WHILE));
// first expr - logic statement
sp++;
ParseString(sp, *((ExpressionItem **)(&pi.item->param1)));
// ok, second expr - then, third - else statement.. others???
ExpressionItem **newplace = ((ExpressionItem **)(&pi.item->param2));
while (*sp == ',')
while (*sp == _T(','))
{
*newplace = AllocItem();
(*newplace)->type = IT_EXPRESSION;
@ -479,14 +481,14 @@ void ParseString(char *&sp, ExpressionItem* &itemplace)
sp++;
break;
case '[':
case _T('['):
{
// thats array access
PlaceOp(vb, IT_ARRAY | ITA_ACCESS | PO_UNARYPOST, 1, &pi);
sp++;
// item index
ParseString(sp, *(ExpressionItem **)&(pi.item->param2));
if (*sp == ',')
if (*sp == _T(','))
{
// two indexes - string access
ExpressionItem *it = AllocItem();
@ -502,7 +504,7 @@ void ParseString(char *&sp, ExpressionItem* &itemplace)
}
break;
case '{': // start of array define
case _T('{'): // start of array define
{
// array define - constists of array copy operator and array define itself
@ -516,7 +518,7 @@ void ParseString(char *&sp, ExpressionItem* &itemplace)
ArrayDesc *ad = *((ArrayDesc**)&(ai->param1));
// parse array initializers
while (*sp != '}')
while (*sp != _T('}'))
{
sp++;
ParseString(sp, ad->array[ad->count]);
@ -527,9 +529,9 @@ void ParseString(char *&sp, ExpressionItem* &itemplace)
sp++;
}
break;
case '-': case '+': case '<': case '=': case '>':
case '/': case '*': case '~': case '^': case '!':
case '&': case '|': case '%':
case _T('-'): case _T('+'): case _T('<'): case _T('='): case _T('>'):
case _T('/'): case _T('*'): case _T('~'): case _T('^'): case _T('!'):
case _T('&'): case _T('|'): case _T('%'):
CheckForOperator(sp, vb, &pi);
break;
@ -594,8 +596,8 @@ void CleanupItems(ExpressionItem* &itemplace)
#ifdef _DEBUG
HANDLE myfile;
char *opsnames[] = {"", "-", "+", "<<", ">>", "*", "/", "=", "&&", "||", "++", "--",
"=<", ">=", "!=", "==", "<", ">", "&", "%", "|", "^", "~", "!"};
TCHAR *opsnames[] = {_T(""), _T("-"), _T("+"), _T("<<"), _T(">>"), _T("*"), _T("/"), _T("="), _T("&&"), _T("||"), _T("++"), _T("--"),
_T("=<"), _T(">="), _T("!="), _T("=="), _T("<"), _T(">"), _T("&"), _T("%"), _T("|"), _T("^"), _T("~"), _T("!")};
void PrintNode(int index, int spaces, ExpressionItem* itemplace)
{
@ -605,7 +607,7 @@ void PrintNode(int index, int spaces, ExpressionItem* itemplace)
do
{
DWORD wrote;
char buffer[1024], *place = buffer;
TCHAR buffer[1024], *place = buffer;
for (int k = 0; k < spaces; k++)
*(place++) = 32;
*place = 0;
@ -613,100 +615,100 @@ void PrintNode(int index, int spaces, ExpressionItem* itemplace)
switch (item->type & ITEMTYPE)
{
case IT_EXPRESSION:
wsprintf(place, "Expression Place-Holder ");
wsprintf(place, _T("Expression Place-Holder "));
break;
case IT_CONST:
switch (item->type & ITEMSUBTYPE)
{
case ITC_STRING:
wsprintf(place, "String: \"%s\"", (char *) item->param1);
wsprintf(place, _T("String: \"%s\""), (TCHAR *) item->param1);
break;
case ITC_INT:
wsprintf(place, "Int: ");
wsprintf(place, _T("Int: "));
itoa64(*((__int64*)&(item->param1)), place+5);
break;
case ITC_FLOAT:
wsprintf(place, "Float: ");
wsprintf(place, _T("Float: "));
FloatFormat(place+7, *((double*)&(item->param1)), 6);
break;
case ITC_ARRAY:
ArrayDesc *ad = (ArrayDesc*) item->param1;
wsprintf(place, "Array, ptr %08X, size %d, count %d, references %d",
wsprintf(place, _T("Array, ptr %08X, size %d, count %d, references %d"),
ad->array, ad->size, ad->count, ad->references);
break;
}
strcat(place, " ");
_tcscat(place, _T(" "));
break;
case IT_OPERATOR:
wsprintf(place, "Op: %s%s ", opsnames[(item->type & ITEMSUBTYPE) >> 8], (item->type & PO_SET)?("(=)"):(""));
wsprintf(place, _T("Op: %s%s "), opsnames[(item->type & ITEMSUBTYPE) >> 8], (item->type & PO_SET)?(_T("(=)")):(_T("")));
break;
case IT_VARIABLE:
switch (item->type & ITEMSUBTYPE)
{
case ITV_NSIS:
{
char buffer[128];
TCHAR buffer[128];
buffer[0] = NSISVariablesNames[item->type & ITEMOPTIONS][0];
buffer[1] = NSISVariablesNames[item->type & ITEMOPTIONS][1];
buffer[2] = 0;
wsprintf(place, "Var: %s (%d) ",
wsprintf(place, _T("Var: %s (%d) "),
buffer,
item->type & ITEMOPTIONS);
}
break;
case ITV_USER:
wsprintf(place, "Var: %s (%d) ", UserVars[item->type & ITEMOPTIONS].name, item->type & ITEMOPTIONS);
wsprintf(place, _T("Var: %s (%d) "), UserVars[item->type & ITEMOPTIONS].name, item->type & ITEMOPTIONS);
break;
case ITV_STACK:
wsprintf(place, "Plugin Stack ");
wsprintf(place, _T("Plugin Stack "));
break;
case ITV_NSTACK:
wsprintf(place, "NSIS Stack ");
wsprintf(place, _T("NSIS Stack "));
break;
}
break;
case IT_LOGIC:
if ((item->type & ITEMSUBTYPE) == ITL_IF)
wsprintf(place, "IF ");
wsprintf(place, _T("IF "));
else
wsprintf(place, "WHILE ");
wsprintf(place, _T("WHILE "));
break;
case IT_FUNCTION:
if (((item->type & ITEMSUBTYPE) == ITF_MATH1) ||
((item->type & ITEMSUBTYPE) == ITF_MATH2) ||
((item->type & ITEMSUBTYPE) == ITF_TYPE))
{
char buffer[128];
TCHAR buffer[128];
buffer[0] = (MathFunctions[item->type &ITEMOPTIONS].name)[0];
buffer[1] = (MathFunctions[item->type &ITEMOPTIONS].name)[1];
buffer[2] = (MathFunctions[item->type &ITEMOPTIONS].name)[2];
buffer[3] = 0;
wsprintf(place, "Built-In Function %s() [%d] ",
wsprintf(place, _T("Built-In Function %s() [%d] "),
buffer,
item->type &ITEMOPTIONS);
}
else
{
UserFunc *f = &(UserFuncs[item->type & ITEMOPTIONS]);
wsprintf(place, "User Function: %s(", f->name);
wsprintf(place, _T("User Function: %s("), f->name);
int flags = f->varflags;
for (int i = 0; i < f->varsnum; i++)
{
if (flags&1) lstrcat(place, "&");
if (flags&1) lstrcat(place, _T("&"));
lstrcat(place, UserVars[f->vars[i]].name);
if (i < f->varsnum-1) lstrcat(place, ", ");
if (i < f->varsnum-1) lstrcat(place, _T(", "));
flags >>= 1;
}
lstrcat(place, ") ");
lstrcat(place, _T(") "));
}
break;
case IT_ARRAY:
wsprintf(place, "Array access [] ");
wsprintf(place, _T("Array access [] "));
break;
}
place += lstrlen(place);
wsprintf(place, "Addr: %08X Type: %08X Next: %08X Param1: %08X Param2: %08X", item, item->type, item->next, item->param1, item->param2);
lstrcat(place, "\n");
wsprintf(place, _T("Addr: %08X Type: %08X Next: %08X Param1: %08X Param2: %08X"), item, item->type, item->next, item->param1, item->param2);
lstrcat(place, _T("\n"));
WriteFile(myfile, buffer, lstrlen(buffer), &wrote, NULL);
if (((item->type & ITEMTYPE) != IT_CONST) && ((item->type & (ITEMTYPE|ITEMSUBTYPE)) != (IT_VARIABLE|ITV_ARRITEM)))
{
@ -719,13 +721,13 @@ void PrintNode(int index, int spaces, ExpressionItem* itemplace)
show = 1;
if (show)
{
wsprintf(place, "Sub1:\n");
wsprintf(place, _T("Sub1:\n"));
WriteFile(myfile, buffer, lstrlen(buffer), &wrote, NULL);
}
PrintNode(1, spaces + 4, *((ExpressionItem**) &item->param1));
if (show)
{
wsprintf(place, "Sub2:\n");
wsprintf(place, _T("Sub2:\n"));
WriteFile(myfile, buffer, lstrlen(buffer), &wrote, NULL);
}
PrintNode(2, spaces + 4, *((ExpressionItem**) &item->param2));
@ -743,12 +745,12 @@ void PrintNode(int index, int spaces, ExpressionItem* itemplace)
} while (item != NULL);
}
void PrintTree(ExpressionItem *root, char *str)
void PrintTree(ExpressionItem *root, TCHAR *str)
{
myfile = CreateFile("d:\\math.debug", GENERIC_ALL, FILE_SHARE_READ, NULL, OPEN_ALWAYS, 0, 0);
myfile = CreateFile(_T("d:\\math.debug"), GENERIC_ALL, FILE_SHARE_READ, NULL, OPEN_ALWAYS, 0, 0);
SetFilePointer(myfile, 0, NULL, FILE_END);
char buffer[1024]; DWORD wrote;
wsprintf(buffer, "New tree for \'%s\'\n", str);
TCHAR buffer[1024]; DWORD wrote;
wsprintf(buffer, _T("New tree for \'%s\'\n"), str);
WriteFile(myfile, buffer, lstrlen(buffer), &wrote, NULL);
PrintNode(0, 4, root);
@ -776,7 +778,7 @@ void CopyArray(ExpressionItem *&item)
void ItemToType(ExpressionItem* &item, int type)
{
char *buffer, *bp;
TCHAR *buffer, *bp;
if (item == NULL) return;
int itemt = item->type & ITEMTYPE, oldtype = item->type & ITEMSUBTYPE;
@ -796,7 +798,7 @@ void ItemToType(ExpressionItem* &item, int type)
*((double *)&(item->param1)) = (double) *((__int64 *)&(item->param1));
else
{
bp = buffer = (char*) item->param1;
bp = buffer = (TCHAR*) item->param1;
StringToItem(buffer, item, STI_FLOAT);
dbgGlobalFree(bp);
}
@ -806,7 +808,7 @@ void ItemToType(ExpressionItem* &item, int type)
*((__int64 *)&(item->param1)) = (__int64) *((double *)&(item->param1));
else
{
bp = buffer = (char*) item->param1;
bp = buffer = (TCHAR*) item->param1;
StringToItem(buffer, item, STI_INT);
dbgGlobalFree(bp);
}
@ -814,7 +816,7 @@ void ItemToType(ExpressionItem* &item, int type)
case ITC_ARRAY:
if (oldtype == ITC_STRING)
{
char *buf = (char*) item->param1;
TCHAR *buf = (TCHAR*) item->param1;
int len = lstrlen(buf)+1;
ExpressionItem *ni = AllocArray(lstrlen(buf)+1);
ArrayDesc *ad = (ArrayDesc*) ni->param1;
@ -843,7 +845,7 @@ void SaveResult(ExpressionItem *var, ExpressionItem *result)
case ITV_NSIS:
{
// store string result direct to NSIS variable
char *ptr = g_variables + varindex*g_stringsize;
TCHAR *ptr = g_variables + varindex*g_stringsize;
ItemToString(ptr, result);
}
break;
@ -869,7 +871,7 @@ void SaveResult(ExpressionItem *var, ExpressionItem *result)
break;
case ITV_NSTACK:
{
char *buf = AllocString();
TCHAR *buf = AllocString();
ItemToString(buf, result);
pushstring(buf);
dbgGlobalFree(buf);
@ -912,7 +914,7 @@ void RunTree(ExpressionItem *from, ExpressionItem* &result, int options)
{
// nsis
result = AllocItem();
char *variable = getuservariable(ioptions);
TCHAR *variable = getuservariable(ioptions);
StringToItem(variable, result, options);
}
break;
@ -947,7 +949,7 @@ void RunTree(ExpressionItem *from, ExpressionItem* &result, int options)
case ITV_NSTACK:
{
// NSIS stack
char buffer[1024], *buf = buffer;
TCHAR buffer[1024], *buf = buffer;
result = AllocItem();
popstring(buffer);
StringToItem(buf, result, options);
@ -1111,8 +1113,8 @@ void RunTree(ExpressionItem *from, ExpressionItem* &result, int options)
case ITC_STRING:
{
int ir = -666;
char *i1 = (item1)?((char*)item1->param1):(NULL);
char *i2 = (item2)?((char*)item2->param1):(NULL);
TCHAR *i1 = (item1)?((TCHAR*)item1->param1):(NULL);
TCHAR *i2 = (item2)?((TCHAR*)item2->param1):(NULL);
int sc = (i1 && i2)?(lstrcmp(i1, i2)):((i1)?(1):((i2)?(-1):(0)));
switch (subtype)
@ -1277,7 +1279,7 @@ void RunTree(ExpressionItem *from, ExpressionItem* &result, int options)
result = AllocItem();
result->type = IT_CONST | ITC_STRING;
result->param1 = (EIPARAM) AllocString();
FloatFormat((char*) result->param1, value, format);
FloatFormat((TCHAR*) result->param1, value, format);
CleanupItems(arg1); CleanupItems(arg2);
} else if (newtype == FTT_LEN)
{
@ -1297,7 +1299,7 @@ void RunTree(ExpressionItem *from, ExpressionItem* &result, int options)
if ((result->type & (ITEMTYPE|ITEMSUBTYPE)) == (IT_CONST|ITC_STRING))
{
// ok, that's string
int len = lstrlen((char*)result->param1);
int len = lstrlen((TCHAR*)result->param1);
dbgGlobalFree((HGLOBAL) result->param1);
*((__int64*)&(result->param1)) = (__int64) len;
result->type = IT_CONST | ITC_INT;
@ -1309,7 +1311,7 @@ void RunTree(ExpressionItem *from, ExpressionItem* &result, int options)
if ((result->type & (ITEMTYPE|ITEMSUBTYPE)) == (IT_CONST|ITC_STRING))
{
// ok, that's string - convert first char to int
int chr = (*((char*)result->param1)) & 0xFF;
int chr = (*((TCHAR*)result->param1)) & 0xFF;
dbgGlobalFree((HGLOBAL) result->param1);
*((__int64*)&(result->param1)) = (__int64) chr;
result->type = IT_CONST | ITC_INT;
@ -1320,8 +1322,8 @@ void RunTree(ExpressionItem *from, ExpressionItem* &result, int options)
// ok, that's int - convert to new string (char+0)
int chr = (int) (*((__int64*)&(result->param1))) & 0xFF;
result->param1 = (EIPARAM) AllocString();
*((char*)result->param1) = (char) chr;
*((char*)(result->param1+1)) = (char) 0;
*((TCHAR*)result->param1) = (TCHAR) chr;
*((TCHAR*)(result->param1+1)) = (TCHAR) 0;
result->type = IT_CONST | ITC_STRING;
break;
} else CleanupItems(result);
@ -1380,7 +1382,7 @@ void RunTree(ExpressionItem *from, ExpressionItem* &result, int options)
if ((aritem->type & (ITEMTYPE|ITEMSUBTYPE)) == (IT_CONST | ITC_STRING))
{
// argument is string
char *str = (char*)(aritem->param1);
TCHAR *str = (TCHAR*)(aritem->param1);
int len = lstrlen(str);
// have we two indexes or one?
if ((*((ExpressionItem **) &(item->param2)))->type != IT_EXPRESSION)
@ -1428,7 +1430,7 @@ void RunTree(ExpressionItem *from, ExpressionItem* &result, int options)
if (pos2 >= len) pos2 = len-1;
// copy string part
char* lpos = str + (pos2-pos1);
TCHAR* lpos = str + (pos2-pos1);
while (str <= lpos)
{
*str = *(str + pos1);
@ -1490,11 +1492,11 @@ HINSTANCE g_hInstance;
extern "C"
void __declspec(dllexport) Script(HWND hwndParent, int string_size,
char *variables, stack_t **stacktop,
TCHAR *variables, stack_t **stacktop,
extra_parameters *extra)
{
EXDLL_INIT();
char *buffer = AllocString(), *buf = buffer;
TCHAR *buffer = AllocString(), *buf = buffer;
ExpressionItem *root = NULL; // root of current tree
// keep loaded to save user defined variables
@ -1552,7 +1554,7 @@ void CleanAll(int init)
}
}
extern "C" BOOL WINAPI DllMain(HINSTANCE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
BOOL WINAPI DllMain(HINSTANCE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
{
g_hInstance = hInst;
CleanAll(ul_reason_for_call == DLL_PROCESS_ATTACH);

View file

@ -1,3 +1,5 @@
// Unicode support by Jim Park -- 08/22/2007
#pragma once
#include <nsis/pluginapi.h> // nsis plugin
@ -23,7 +25,7 @@ HGLOBAL watchGlobalAlloc(UINT Flags, UINT size);
#endif
char *AllocString();
TCHAR *AllocString();
ExpressionItem *AllocItem();
ExpressionItem *AllocArray(int size);
ExpressionItem *CopyItem(ExpressionItem *item, int NeedConst = 0);

View file

@ -1,10 +1,12 @@
// Unicode support by Jim Park -- 08/22/2007
#include <windows.h>
#include <stdio.h>
#include "MyMath.h"
#include "Math.h"
// Converts String to Int (Dec, Hex) or Float value
void StringToItem(char *&s, ExpressionItem *item, int options)
void StringToItem(TCHAR *&s, ExpressionItem *item, int options)
{
item->type = IT_CONST | ITC_INT;
__int64 &v=*((__int64*)&(item->param1));
@ -14,19 +16,19 @@ void StringToItem(char *&s, ExpressionItem *item, int options)
if (!s) return;
// String-value
if ((((options & (STI_FLOAT | STI_INT)) == 0) || *s == '\'' || *s == '\"' || *s == '`' ||
((*s != '+') && (*s != '-') && ((*s < '0') || (*s > '9'))))
if ((((options & (STI_FLOAT | STI_INT)) == 0) || *s == _T('\'') || *s == _T('\"') || *s == _T('`') ||
((*s != _T('+')) && (*s != _T('-')) && ((*s < _T('0')) || (*s > _T('9')))))
&& (options & STI_STRING))
{
// end of string char
char eol = 0;
if (*s == '\'' || *s == '\"' || *s == '`') eol = *s;
TCHAR eol = 0;
if (*s == _T('\'') || *s == _T('\"') || *s == _T('`')) eol = *s;
else s--;
item->type = IT_CONST | ITC_STRING;
// allocate memory buffer for string
char *sp;
sp = *((char**)&(item->param1)) = AllocString();
TCHAR *sp;
sp = *((TCHAR**)&(item->param1)) = AllocString();
while (*(++s) && (*s != eol))
{
*(sp++) = *s;
@ -36,18 +38,18 @@ void StringToItem(char *&s, ExpressionItem *item, int options)
} else
{
// strip leading spaces and tabs
while ((*s == ' ') || (*s == '\t')) s++;
while ((*s == _T(' ')) || (*s == _T('\t'))) s++;
// Hex-value
if ((options & STI_INT) && *s == '0' && (s[1] == 'x' || s[1] == 'X'))
if ((options & STI_INT) && *s == _T('0') && (s[1] == _T('x') || s[1] == _T('X')))
{
s++;
while (*(s+1) == '0') *s++;
while (*(s+1) == _T('0')) *s++;
for (;;)
{
int c=*(++s);
if (c >= '0' && c <= '9') c-='0';
else if (c >= 'a' && c <= 'f') c-='a'-10;
else if (c >= 'A' && c <= 'F') c-='A'-10;
if (c >= _T('0') && c <= _T('9')) c-=_T('0');
else if (c >= _T('a') && c <= _T('f')) c-=_T('a')-10;
else if (c >= _T('A') && c <= _T('F')) c-=_T('A')-10;
else break;
v<<=4;
v+=c;
@ -57,13 +59,13 @@ void StringToItem(char *&s, ExpressionItem *item, int options)
else
{
int sign=0, numsignif = 0;
if (*s == '-') sign++; else s--;
while (*(s+1) == '0') *s++;
if (*s == _T('-')) sign++; else s--;
while (*(s+1) == _T('0')) *s++;
for (;;)
{
int c=*(++s) - '0'; numsignif++;
int c=*(++s) - _T('0'); numsignif++;
if ((options & STI_FLOAT) &&
((c == ('e'-'0')) || (c==('E'-'0')) || (c==('.'-'0'))
((c == (_T('e')-_T('0'))) || (c==(_T('E')-_T('0'))) || (c==(_T('.')-_T('0')))
|| (numsignif > 18)))
{
// Switch to floating point conversion rountine
@ -74,16 +76,16 @@ void StringToItem(char *&s, ExpressionItem *item, int options)
while ((c >= 0) && (c <= 9))
{
d = d*10.0 + (double) c;
c=*(++s) - '0';
c=*(++s) - _T('0');
}
// sub-decimal part
if (c == ('.'-'0'))
if (c == (_T('.')-_T('0')))
{
double pwr = 1.0, dec = 0.0;
for (;;)
{
c=*(++s) - '0';
c=*(++s) - _T('0');
if ((c < 0) || (c > 9)) break;
dec = dec*10.0 + (double) c;
pwr *= 10.0;
@ -91,19 +93,19 @@ void StringToItem(char *&s, ExpressionItem *item, int options)
d += dec/pwr;
}
// exponental part
if ((c == ('E'-'0')) || (c == ('e'-'0')))
if ((c == (_T('E')-_T('0'))) || (c == (_T('e')-_T('0'))))
{
int expc = 0, esign = 0;
s++;
// detect exponential sign
if ((*s == '+') || (*s == '-'))
esign = (*s == '-');
if ((*s == _T('+')) || (*s == _T('-')))
esign = (*s == _T('-'));
else s--;
// detect exp value
for (;;)
{
c=*(++s) - '0';
c=*(++s) - _T('0');
if ((c < 0) || (c > 9)) break;
expc = expc*10 + c;
}
@ -139,7 +141,7 @@ void StringToItem(char *&s, ExpressionItem *item, int options)
}
}
void ItemToString(char *sbuf, ExpressionItem *item)
void ItemToString(TCHAR *sbuf, ExpressionItem *item)
{
if ((item == NULL) || ((item->type & ITEMTYPE) != IT_CONST))
{
@ -151,7 +153,7 @@ void ItemToString(char *sbuf, ExpressionItem *item)
{
case ITC_STRING:
{
char *ptr = *((char**)&(item->param1));
TCHAR *ptr = *((TCHAR**)&(item->param1));
while (*(sbuf++) = *(ptr++));
}
break;
@ -161,7 +163,7 @@ void ItemToString(char *sbuf, ExpressionItem *item)
for (int index = 0; index < ad->count; index++)
if ((ad->array[index]) &&
((ad->array[index]->type & (ITEMTYPE|ITEMSUBTYPE)) == (IT_CONST | ITC_INT)))
if ((*(sbuf++) = (char) *((__int64*)&(ad->array[index]->param1))) == 0)
if ((*(sbuf++) = (TCHAR) *((__int64*)&(ad->array[index]->param1))) == 0)
break;
}
break;
@ -174,21 +176,21 @@ void ItemToString(char *sbuf, ExpressionItem *item)
}
}
void itoa64(__int64 i, char *buffer)
void itoa64(__int64 i, TCHAR *buffer)
{
char buf[128], *b = buf;
TCHAR buf[128], *b = buf;
if (i < 0)
{
*(buffer++) = '-';
*(buffer++) = _T('-');
i = -i;
}
if (i == 0) *(buffer++) = '0';
if (i == 0) *(buffer++) = _T('0');
else
{
while (i > 0)
{
*(b++) = '0' + ((char) (i%10));
*(b++) = _T('0') + ((TCHAR) (i%10));
i /= 10;
}
while (b > buf) *(buffer++) = *(--b);
@ -196,12 +198,12 @@ void itoa64(__int64 i, char *buffer)
*buffer = 0;
}
#define POS_INFINITY "#INF"
#define NEG_INFINITY "-#INF"
#define POS_INFINITY _T("#INF")
#define NEG_INFINITY _T("-#INF")
void FloatFormat(char *s, double value, int options)
void FloatFormat(TCHAR *s, double value, int options)
{
char format[128];
TCHAR format[128];
int prec = options & 0xF;
*s = 0;
@ -217,25 +219,25 @@ void FloatFormat(char *s, double value, int options)
if (options & FF_NOEXP)
{
sprintf(format, "%%.%df", prec);
_stprintf(format, _T("%%.%df"), prec);
}
else if (options & FF_EXP)
{
sprintf(format, "%%.%de", prec);
_stprintf(format, _T("%%.%de"), prec);
}
else if (options & FF_LEXP)
{
sprintf(format, "%%.%dE", prec);
_stprintf(format, _T("%%.%dE"), prec);
}
else
{
sprintf(format, "%%.%dg", prec);
_stprintf(format, _T("%%.%dg"), prec);
}
sprintf(s, format, value);
_stprintf(s, format, value);
}
int lstrcmpn(char *s1, const char *s2, int chars)
int lstrcmpn(TCHAR *s1, const TCHAR *s2, int chars)
{
while ((chars > 0) && (*s1) && (*s2) && (*(s1) == *(s2))) chars--, s1++, s2++;
if ((chars == 0) || (*s1 == *s2)) return 0;

View file

@ -1,3 +1,5 @@
// Unicode support by Jim Park -- 08/22/2007
#pragma once
#include <math.h>
@ -97,13 +99,13 @@ typedef struct __ParseInfo
ExpressionItem *OpsStack;
ExpressionItem **place;
ExpressionItem **root;
char valbuf[108];
TCHAR valbuf[108];
} ParseInfo;
#define OPERATOR_SET_PRECEDENCE 14
typedef struct __OpStruct
{
char name[3];
TCHAR name[3];
unsigned char precedence;
unsigned short int type;
} OpStruct;
@ -111,16 +113,16 @@ typedef struct __OpStruct
#define MAX_USER_VARS 256
typedef struct __UserVar
{
char name[28];
TCHAR name[28];
ExpressionItem *item;
} UserVar;
#define MAX_USER_FUNCS 256
typedef struct __UserFunc
{
char name[20];
unsigned char vars[31];
unsigned char varsnum;
TCHAR name[20];
unsigned char vars[31]; // only used for indexing
unsigned char varsnum; // number of vars < 256
unsigned int varflags;
ExpressionItem *root;
} UserFunc;
@ -140,7 +142,7 @@ typedef double (*Math2dFuncPtr)(double arg, double *arg2);
typedef struct __MathFunction
{
char name[3];
TCHAR name[3];
unsigned char type;
Math1FuncPtr fptr;
} MathFunction;
@ -159,8 +161,8 @@ typedef struct __MathFunction
#define RTO_PREFFEREDTYPE 0xFF00
void RunTree(ExpressionItem *from, ExpressionItem* &result, int type);
void StringToItem(char *&sbuf, ExpressionItem *item, int options);
void ItemToString(char *sbuf, ExpressionItem *item);
void FloatFormat(char *sbuf, double value, int options);
void itoa64(__int64 i, char *buffer);
int lstrcmpn(char *s1, const char *s2, int chars);
void StringToItem(TCHAR *&sbuf, ExpressionItem *item, int options);
void ItemToString(TCHAR *sbuf, ExpressionItem *item);
void FloatFormat(TCHAR *sbuf, double value, int options);
void itoa64(__int64 i, TCHAR *buffer);
int lstrcmpn(TCHAR *s1, const TCHAR *s2, int chars);

View file

@ -1,3 +1,5 @@
// Unicode support by Jim Park -- 08/22/2007
#include <windows.h>
#include "MyMath.h"
#include "Math.h"
@ -28,15 +30,15 @@ void watchGlobal()
for (int i = 0; i < blocksnum; i++)
if (blocks[i] != NULL)
{
_RPT2(_CRT_WARN, "Memory leak %d at %8X\n", i, blocks[i]);
_RPT2(_CRT_WARN, _T("Memory leak %d at %8X\n"), i, blocks[i]);
}
}
#endif
char *AllocString()
TCHAR *AllocString()
{
return (char*) dbgGlobalAlloc(GPTR,g_stringsize);
return (TCHAR*) dbgGlobalAlloc(GPTR,g_stringsize*sizeof(TCHAR));
}
ExpressionItem *AllocItem()
@ -82,7 +84,7 @@ ExpressionItem *CopyItem(ExpressionItem *citem, int NeedConst)
if ((item->type & (ITEMTYPE | ITEMSUBTYPE)) == (IT_CONST | ITC_STRING))
{
item->param1 = (EIPARAM) AllocString();
lstrcpy((LPSTR) item->param1, (LPSTR) citem->param1);
lstrcpy((LPTSTR) item->param1, (LPTSTR) citem->param1);
} else if (((item->type & (ITEMTYPE | ITEMSUBTYPE)) == (IT_CONST | ITC_ARRAY))
||
((item->type & (ITEMTYPE | ITEMSUBTYPE)) == (IT_VARIABLE | ITV_ARRITEM)))