2002-09-21 20:59:13 +00:00
|
|
|
#include "stdafx.h"
|
|
|
|
#include "Plugin.h"
|
2002-10-31 14:41:46 +00:00
|
|
|
#include "Buffers.h"
|
2002-09-21 20:59:13 +00:00
|
|
|
#include "System.h"
|
|
|
|
|
|
|
|
HWND g_hwndParent;
|
|
|
|
int g_stringsize;
|
|
|
|
stack_t **g_stacktop;
|
|
|
|
char *g_variables;
|
|
|
|
|
2002-10-23 17:53:09 +00:00
|
|
|
char *AllocString()
|
2002-09-21 20:59:13 +00:00
|
|
|
{
|
2002-10-23 17:53:09 +00:00
|
|
|
return (char*) GlobalAlloc(GPTR,g_stringsize);
|
|
|
|
}
|
|
|
|
|
|
|
|
char *AllocStr(char *str)
|
|
|
|
{
|
|
|
|
return lstrcpy(AllocString(), str);
|
|
|
|
}
|
|
|
|
|
|
|
|
char* popstring()
|
|
|
|
{
|
|
|
|
char *str;
|
2002-09-21 20:59:13 +00:00
|
|
|
stack_t *th;
|
2002-10-23 17:53:09 +00:00
|
|
|
|
|
|
|
if (!g_stacktop || !*g_stacktop) return NULL;
|
2002-09-21 20:59:13 +00:00
|
|
|
th=(*g_stacktop);
|
2002-10-23 17:53:09 +00:00
|
|
|
|
|
|
|
str = AllocString();
|
2002-09-21 20:59:13 +00:00
|
|
|
lstrcpy(str,th->text);
|
2002-10-23 17:53:09 +00:00
|
|
|
|
2002-09-21 20:59:13 +00:00
|
|
|
*g_stacktop = th->next;
|
|
|
|
GlobalFree((HGLOBAL)th);
|
2002-10-23 17:53:09 +00:00
|
|
|
return str;
|
2002-09-21 20:59:13 +00:00
|
|
|
}
|
|
|
|
|
2002-10-23 17:53:09 +00:00
|
|
|
char *pushstring(char *str)
|
2002-09-21 20:59:13 +00:00
|
|
|
{
|
|
|
|
stack_t *th;
|
2002-10-23 17:53:09 +00:00
|
|
|
if (!g_stacktop) return str;
|
2002-09-21 20:59:13 +00:00
|
|
|
th=(stack_t*)GlobalAlloc(GPTR,sizeof(stack_t)+g_stringsize);
|
|
|
|
lstrcpyn(th->text,str,g_stringsize);
|
|
|
|
th->next=*g_stacktop;
|
|
|
|
*g_stacktop=th;
|
2002-10-23 17:53:09 +00:00
|
|
|
return str;
|
2002-09-21 20:59:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char *getuservariable(int varnum)
|
|
|
|
{
|
2002-10-23 17:53:09 +00:00
|
|
|
if (varnum < 0 || varnum >= __INST_LAST) return AllocString();
|
|
|
|
return AllocStr(g_variables+varnum*g_stringsize);
|
2002-09-21 20:59:13 +00:00
|
|
|
}
|
|
|
|
|
2002-10-31 14:41:46 +00:00
|
|
|
char *setuservariable(int varnum, char *var)
|
2002-09-21 20:59:13 +00:00
|
|
|
{
|
|
|
|
if (var != NULL && varnum >= 0 && varnum < __INST_LAST) {
|
|
|
|
lstrcpy (g_variables + varnum*g_stringsize, var);
|
|
|
|
}
|
2002-10-31 14:41:46 +00:00
|
|
|
return var;
|
2002-09-21 20:59:13 +00:00
|
|
|
}
|
|
|
|
|
2002-10-23 17:53:09 +00:00
|
|
|
// Updated for int64 and simple bitwise operations
|
|
|
|
__int64 myatoi(char *s)
|
2002-09-21 20:59:13 +00:00
|
|
|
{
|
2002-10-23 17:53:09 +00:00
|
|
|
__int64 v=0;
|
|
|
|
// Check for right input
|
|
|
|
if (!s) return 0;
|
2002-09-21 20:59:13 +00:00
|
|
|
if (*s == '0' && (s[1] == 'x' || s[1] == 'X'))
|
|
|
|
{
|
2002-10-23 17:53:09 +00:00
|
|
|
s++;
|
2002-09-21 20:59:13 +00:00
|
|
|
for (;;)
|
|
|
|
{
|
2002-10-23 17:53:09 +00:00
|
|
|
int c=*(++s);
|
2002-09-21 20:59:13 +00:00
|
|
|
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;
|
|
|
|
else break;
|
|
|
|
v<<=4;
|
|
|
|
v+=c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (*s == '0' && s[1] <= '7' && s[1] >= '0')
|
|
|
|
{
|
|
|
|
for (;;)
|
|
|
|
{
|
2002-10-23 17:53:09 +00:00
|
|
|
int c=*(++s);
|
2002-09-21 20:59:13 +00:00
|
|
|
if (c >= '0' && c <= '7') c-='0';
|
|
|
|
else break;
|
|
|
|
v<<=3;
|
|
|
|
v+=c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int sign=0;
|
2002-10-23 17:53:09 +00:00
|
|
|
if (*s == '-') sign++; else s--;
|
2002-09-21 20:59:13 +00:00
|
|
|
for (;;)
|
|
|
|
{
|
2002-10-23 17:53:09 +00:00
|
|
|
int c=*(++s) - '0';
|
2002-09-21 20:59:13 +00:00
|
|
|
if (c < 0 || c > 9) break;
|
|
|
|
v*=10;
|
|
|
|
v+=c;
|
|
|
|
}
|
2002-10-23 17:53:09 +00:00
|
|
|
if (sign) v = -v;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Support for simple ORed expressions
|
|
|
|
if (*s == '|')
|
|
|
|
{
|
|
|
|
v |= myatoi(s+1);
|
2002-09-21 20:59:13 +00:00
|
|
|
}
|
2002-10-23 17:53:09 +00:00
|
|
|
|
|
|
|
return v;
|
2002-09-21 20:59:13 +00:00
|
|
|
}
|
|
|
|
|
2002-10-23 17:53:09 +00:00
|
|
|
void myitoa64(__int64 i, char *buffer)
|
2002-09-21 20:59:13 +00:00
|
|
|
{
|
2002-10-23 17:53:09 +00:00
|
|
|
char buf[128], *b = buf;
|
|
|
|
|
|
|
|
if (i < 0)
|
|
|
|
{
|
|
|
|
*(buffer++) = '-';
|
|
|
|
i = -i;
|
|
|
|
}
|
2002-10-31 14:41:46 +00:00
|
|
|
if (i == 0) *(buffer++) = '0';
|
|
|
|
else
|
2002-10-23 17:53:09 +00:00
|
|
|
{
|
2002-10-31 14:41:46 +00:00
|
|
|
while (i > 0)
|
|
|
|
{
|
|
|
|
*(b++) = '0' + ((char) (i%10));
|
|
|
|
i /= 10;
|
|
|
|
}
|
|
|
|
while (b > buf) *(buffer++) = *(--b);
|
2002-10-23 17:53:09 +00:00
|
|
|
}
|
|
|
|
*buffer = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int popint()
|
|
|
|
{
|
|
|
|
int value;
|
|
|
|
char *str;
|
|
|
|
if ((str = popstring()) == NULL) return -1;
|
|
|
|
value = (int) myatoi(str);
|
|
|
|
GlobalFree(str);
|
|
|
|
return value;
|
2002-09-21 20:59:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void pushint(int value)
|
|
|
|
{
|
|
|
|
char buffer[1024];
|
|
|
|
wsprintf(buffer, "%d", value);
|
|
|
|
pushstring(buffer);
|
|
|
|
}
|
|
|
|
|
2002-10-31 14:41:46 +00:00
|
|
|
char *copymem(char *output, char *input, int size)
|
|
|
|
{
|
|
|
|
char *out = output;
|
|
|
|
if ((input != NULL) && (output != NULL))
|
|
|
|
while (size-- > 0) *(out++) = *(input++);
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
HANDLE GlobalCopy(HANDLE Old)
|
|
|
|
{
|
|
|
|
SIZE_T size = GlobalSize(Old);
|
|
|
|
return copymem(GlobalAlloc(GPTR, size), Old, (int) size);
|
|
|
|
}
|
|
|
|
|
2008-11-29 22:03:33 +00:00
|
|
|
UINT_PTR NSISCallback(UINT msg)
|
|
|
|
{
|
|
|
|
return (UINT_PTR) NULL;
|
|
|
|
}
|
|
|
|
|
2002-09-21 20:59:13 +00:00
|
|
|
#ifdef _DEBUG
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
}
|
2007-06-10 16:45:45 +00:00
|
|
|
#endif
|