Skip to content
Low-level programming · Higher-level thinking
Login Register
Forum / Plugins

PlugIn Example in C

A community discussion post from the original code:zIRON forum.

Replies

Colin admin
Posts
928
Threads
49
Location
Bulgaria

first problem i see is that you are using edi without protecting the contents...

procedure FileEntry(DWord handle; char* strCode) 
{
    int32 len = H_strlen(strCode);
    if(len > 0)
     {
       pointer mem = H_GetTmpMem(len); //allocate memory
       char tmp[1024];
       edi = strGetLine(strCode, @tmp);
       while(edi > 0)
        {    
           H_strcat(mem,@tmp);          
           edi = strGetLine(edi, @tmp);
        }
       if(Ziron_SetFileBuffer(handle, mem ,H_strlen(mem)) == false)
        {
          Ziron_FatalError('error when set File Buffer');
       }  
     }
}

I have made some further updates to Ziron which i will upload too.

Colin admin
Posts
928
Threads
49
Location
Bulgaria

i have updated the beta and it works OK

procedure FileEntry(DWord handle; char* strCode) {
	uses edi;

	edi = strLen(strCode);
	if (eax > 0) {
		char* mem = new edi;
		char tmp[2048];
		
		edi = strGetLine(strCode, @tmp);
		while(edi <> 0) {    
			H_strJoin(mem, @tmp);
			edi = strGetLine(edi, @tmp);
		}
		if (Ziron_SetFileBuffer(handle, mem, strLen(mem)) == false) {
			Ziron_FatalError('error when set File Buffer');
		}
		
		delete mem;
	}
}

used this code to test, but note that because you are not added newlines, some lines will become messed up due to comments.. everything is put onto 1 line...

you have 2 options, add newlines after each actual line, or 2... delete new lines as they are processed.

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

i have downloaded the beta ,and test you new code.

it keeps printing source code then crashed, BTW i did not see any commend to print the lines

of the code in your last FileEntry but ziron print them.

http://www.freewebs.com/ogremagic/index.htm

Colin admin
Posts
928
Threads
49
Location
Bulgaria

sorry that was some old debug code, i've removed it in latest beta, as for crash i suggest you check other parts of your code, step by step add bit at a time to find where it crashes.

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

oh , plugin compiled okay , when test it with any code ziron crashed.

here is the log file

Ziron Compiler 1.1.29.3 Copyright (C) 2011. OverHertz Ltd. All rights reserved. -------------------------------------------- 12/9/2011 10:02:06 PM -------------------------------------------- PlugSys: Emit plugin has loaded! PlugSys: test plugin has loaded!

and the editor print that

Exception EInOutError in module Ziron.exe at 000C2248

http://www.freewebs.com/ogremagic/index.htm

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt
procedure FileEntry(DWord handle; char* strCode) {
  uses edi;
  
  edi = strLen(strCode);
  if (eax > 0) {
    char* mem = new edi;
    char tmp[2048];
    
    edi = strGetLine(strCode, @tmp);
    while(edi <> 0) {    
      H_strJoin(mem, @tmp,'\r\n');
      Ziron_ShowMessage(@tmp);
      edi = strGetLine(edi, @tmp);
    }
    if (Ziron_SetFileBuffer(handle, mem, strLen(mem)) == false) {
      Ziron_FatalError('error when set File Buffer');
    }
    
    delete mem;
  }
  Ziron_ShowMessage('Ended');  // this does not printed ,crashed before came here
}

http://www.freewebs.com/ogremagic/index.htm

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt
procedure FileEntry(DWord handle; char* strCode) {
  uses edi;
  
  edi = strLen(strCode);
  if (eax > 0) {
    char* mem = new edi;
    char tmp[2048];
    
    edi = strGetLine(strCode, @tmp);
    while(edi <> 0) {    
      H_strJoin(mem, @tmp,'\r\n');
      Ziron_ShowMessage(@tmp);
      edi = strGetLine(edi, @tmp);
    }
    Ziron_ShowMessage('test here'); // works well when added this line
    if (Ziron_SetFileBuffer(handle, mem, strLen(mem)) == false) {
      Ziron_FatalError('error when set File Buffer');
    }
    
    delete mem;
  }
  Ziron_ShowMessage('Ended');
}

http://www.freewebs.com/ogremagic/index.htm

Colin admin
Posts
928
Threads
49
Location
Bulgaria

check if there is enough storage allocated

  edi = strLen(strCode);
  edi += 1024; //if it works with this let me know,.
  if (eax > 0) {
    char* mem = new edi;