Skip to content
Low-level programming · Higher-level thinking
Login Register
Forum / Requests and Feedback

get entire line

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

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

get entire line

Hi

sometimes i need get the entire current line before i will pares it so i made this

function but it does not work.

function GetFullLine()
{
   global char line[2048];
   
   H_strcpy(@line,Ziron_GetStringValue()); 
   eax = Ziron_IsNextLineBreak(); 
   while(eax)
    { 
      eax = Ziron_PeekNextToken(); 
      eax = Ziron_GetStringValue();
      H_strjoin(@line,eax,' ');  
      eax = Ziron_IsNextLineBreak(); 
    }
   eax = @line; 
}

any suggestion please.

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

Replies

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

i have made this , but if i want to pares from start as usual , i think you can add

a push/pop function to save the current position of compilation.

function GetFullLine()
{
   global char line[2048];
   
   H_strcpy(@line,Ziron_GetStringValue());
   H_strcat(@line,' ');   
   eax = Ziron_IsNextLineBreak(); 
   while(!eax)
    { 
      //eax = Ziron_PeekNextToken(); 
      eax = Ziron_getNextToken();
      eax = Ziron_GetStringValue();
      H_strjoin(@line,eax,' ');  
      eax = Ziron_IsNextLineBreak(); 
    }
   eax = @line; 
}

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

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

get access violation with this plugin

//******************************************************//
//                                                      //
//                 Mov Plugin                           //
//                                                      //
//               By Emil Halim                          //
//                 7 / 11 / 2011                        //
//                                                      //
//******************************************************//

program WIN32DLL 'Mov PLUGIN';

#include 'zirplug/framework.zir';

//////////////////////////////

const strLoaded = 'Mov plugin has loaded!';

//////////////////////////////
function H_strlen(char* str)
{
  Eax = nil;
  Ebx = str;
  while(char[Ebx] != 0)
   {
     Ebx++;
     Eax++;
   }
}

function  H_strcpy(Dword dst,src)
{ 
  Eax = dst; 
  Edx = src; 
  push Eax;
  BL =  [Edx]; 
  while ( BL != 0)  
   { 
      [Eax] = BL; 
      Eax++; Edx++; 
      BL =  [Edx]; 
   }  
  [Eax] = 0;
  pop Eax;
} 

function H_strcat(Dword dst,src) 
{ 
  Eax = dst; 
  Edx = src;
  push Eax;
  while (byte [Eax] != 0) { Eax++; } 
  while (byte [Edx] != 0)  
   { 
      BL =  [Edx]; 
      [Eax] = BL;  
      Edx++; Eax++; 
   } 
  [Eax] = 0;
  pop Eax;
} 

inline procedure  H_strjoin(;)
{
  $temp = 1;
  $to = $argc - 1;  
  $repeat $to:	
     H_strcat($arg[0],$arg[$temp]);  
  $temp++;
  $end
}

inline procedure Ziron_ExecuteF(m_st)
{
   Ziron_Execute($m_st,H_strlen($m_st));
}

function GetFullLine()
{
   global char line[2048];
   
   H_strcpy(@line,Ziron_GetStringValue());
   H_strcat(@line,' ');   
   eax = Ziron_IsNextLineBreak(); 
   while(!eax)
    { 
      //eax = Ziron_PeekNextToken(); 
      eax = Ziron_getNextToken();
      eax = Ziron_GetStringValue();
      H_strjoin(@line,eax,' ');  
      eax = Ziron_IsNextLineBreak(); 
    }
   H_strcat(@line,';');    
   eax = @line; 
}

//
// event_mov()
// return false to allow the assembler to process this keyword internally.
// return true to tell the assembler this keyword has been processed.
//
function event_mov() {
    uses edi;
    char buf[2048];
    Dword Len;
    
    pointer  pt;
    pt =  GetFullLine();
    Ziron_ShowMessage(pt);
    
     Len = H_strlen(pt);    
     eax = Ziron_Execute(pt,Len);
     if (eax == false) {
          Ziron_FatalError('Dim plugin is not compatible with this version of Ziron');
          return true;
      }       
   return true;
}

function InitPlugin(pointer pGetF) {
	Ziron_LoadAll(pGetF); //use framework utility function to load all

	//register our keyword
	Ziron_RegisterKeyword('mov', @event_mov);
	
	return strLoaded;
}

entry function DLLMain(DWord iDLL; DWord iReason; Pointer iResult) {
  if (iReason == DLL_PROCESS_ATTACH) {
    return true;
  }

  return false;
}

exports InitPlugin;

and here the test program

program WIN32CUI 'mov plugin test';

#include 'console.zir';

mov eax,10; 
print('eax = ', eax:int, '\r\n');

wait_key(nil);
ExitProcess(0);

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

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

i got this strange output from this function

function event_mov() {
	uses edi;
	char buf[2048];
    Dword Len;
    
    pointer  pt;
    pt =  GetFullLine();
    Ziron_ShowMessage(pt);
    return true;
}

results

Ziron Compiler 1.1.27.5 Copyright (C) 2011. OverHertz Ltd. All rights reserved. PlugSys: Emit plugin has loaded! PlugSys: Mov plugin has loaded! PlugSys: mov eax , value PlugSys: mov edi , lpBuffer PlugSys: mov [expression] , 30 PlugSys: mov [expression] , - PlugSys: mov ecx , 3435973837 PlugSys: mov esi , edi PlugSys: mov ebx , eax PlugSys: mov eax , edx PlugSys: mov [expression] , bl PlugSys: mov [expression] , 0 PlugSys: mov al , [expression] PlugSys: mov ah , [expression] PlugSys: mov [expression] , al PlugSys: mov [expression] , ah PlugSys: mov eax , 0 PlugSys: mov eax , 10 ; Compile OK - 201

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

Colin admin
Posts
928
Threads
49
Location
Bulgaria

The internal handler of instructions is very complex, expressions are handled separately and can not be returned via GetStringValue - i would add an extra function for this problem, however i plan to change the internal handler over the next few releases, so it would not be a good idea.

[expression] is basically anything that is inside [] with registers.. e.g.

[edx+ecx+5]

GetStringValue will return [expression], anyways i know a solution, i will add an extra function ExtractLine, which can extract the line from the current position.

Colin admin
Posts
928
Threads
49
Location
Bulgaria

implemented, and now your function could be changed like so:

function GetFullLine() {
   global char line[2048];
   global int32 linelen;
   
   linelen = Ziron_ExtractLine(@line, 2048);
   eax = @line;
}

function event_mov() {
	uses edi;
	char buf[2048];
    Dword Len;
    
    eax = GetFullLine();
	Ziron_ShowMessage(eax);
	
	return false;
}
Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

ok i have got that latest ver 27.6

have this error when update GetFullLine as you made.

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

Colin admin
Posts
928
Threads
49
Location
Bulgaria

sorry seems i didnt update the include file - i've re-updated the package.