#define plugin
Hi all
here is a quick and simple pluging that manipulate a c_like #define statement.
i was converting a h file header and i 've wrote this plugin instead of converting.
may be it will help someone .
//******************************************************//
// //
// Ziron Plugin //
// Define (Define.zir) //
// //
// by Emil halim 16/5/2012 //
// //
//******************************************************//
plugins off;
program WIN32DLL 'Define PLUGIN';
#include 'zirplug/framework.zir';
//////////////////////////////
const strLoaded = 'define plugin has loaded!';
//////////////////////////////
function H_strcpy(Dword dst,src)
{
uses edx ebx;
Eax = dst;
Edx = src;
push Eax;
BL = char[Edx];
while ( BL != 0)
{
char[Eax] = BL;
Eax++; Edx++;
BL = char[Edx];
}
char[Eax] = 0;
pop Eax;
}
function H_strcat(Dword dst,src)
{
uses edx ebx;
Eax = dst;
Edx = src;
push Eax;
while (byte[Eax] != 0) { Eax++; }
while (byte[Edx] != 0)
{
BL = char[Edx];
char[Eax] = BL;
Edx++; Eax++;
}
char[Eax] = 0;
pop Eax;
}
inline procedure H_strjoin(;)
{
$temp = 1;
$to = $argc - 1;
$repeat $to:
H_strcat($arg[0],$arg[$temp]);
$temp++;
$end
}
function event_Define()
{
uses edi esi ecx ebx;
char buf[2048];
char idnt[255];
char val[255];
eax = Ziron_ExtractLine(@buf,2047);
Ziron_ShowMessage(@buf);
eax = Ziron_ExpectNextToken(zirIdent);
if (eax == -1) {
Ziron_FatalError('Expected identfire Name');
return true;
}
H_strcpy(@idnt, Ziron_GetStringValue());
eax = Ziron_GetNextToken();
if( eax == zirHexadecimal)
{
H_strcpy(@val, '0x');
H_strcat(@val, Ziron_GetStringValue());
}
else
{
H_strcpy(@val, Ziron_GetStringValue());
}
buf=0;
H_strjoin(@buf ,'const ', @idnt, ' = ', @val , ';');
Ziron_ShowMessage(@buf);
Ziron_Exec(@buf);
return true;
}
procedure FileEntry(DWord handle; char* strCode) {
uses edi;
eax = strOffset(strCode, '#define');
while (char[eax] <> 0) {
char[eax] = "_";
eax = strOffset(eax, '#define');
}
}
function InitPlugin(pointer pGetF) {
Ziron_LoadAll(pGetF); //use framework utility function to load all
//register our keyword
Ziron_RegisterKeyword('_define', @event_Define);
return strLoaded;
}
procedure UnloadPlugin()
{
}
entry function DLLMain(DWord iDLL; DWord iReason; Pointer iResult) {
if (iReason == DLL_PROCESS_ATTACH) {
return true;
}
return false;
}
exports InitPlugin, UnloadPlugin, FileEntry;
have fun.
http://www.freewebs.com/ogremagic/index.htm