Register | Login
Forum Index > Plugins > Ziron_GetStringValue Eaxmple
Author Message
Pages: 1 2 3
Admin
Site Admin

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[324] - posted: 2011-11-04 21:39:59
can you confirm your strcat function is working correctly?

Download Ziron
Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.
Emil_halim
Ziron Beta Tester

avatar

(send private message)

Posts: 639
Topics: 104

Location:
Alex, Egypt
[325] - posted: 2011-11-04 21:46:54

yes , H_strcpy is okay , but H_strcat crashed.




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

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[326] - posted: 2011-11-04 22:16:06
here is a the new strAppend function that will be added to the new string.zir file, most str functions will be moved to that file

Code:
//
// Copyright (c) OverHertz Ltd
//
function strAppend(char* buf; char* str; DWord buflen) {
  uses ecx edi esi;  
  
  ecx = xor;
  edi = buf;
  not ecx
  al = xor;
  repne scasb
  not ecx  
  lea ecx, [ecx-1]
  edi--;
  
  eax = str;
  while (char[eax] != 0) { eax++; }
  eax++;
  sub eax, str
  xchg ecx, eax
  add ecx, eax
  
  if (ecx => buflen) {
    return false;
  }
    
  sub ecx, eax
  esi = str;
  rep movsb  

  eax = true;
}


very simple usage:

you pass your buffer, the string you want to append, and the maximum buffer length, the function will return false on failure and true on success.

e.g.

Code:
char buf[25];

strlcpy(@buf, 'This', 4);
strAppend(@buf, ' is a test', 25);

eax = strAppend(@buf, ' and i need to know it works!', 25);
//you dont need to check it if you don't need to, it just won't append the string
if (eax == false) {
  print('strAppend failed\r\n');
}

print('My String: "', @buf, '"\r\n');


the output will be:
Code:
strAppend failed
This is a test


Download Ziron
Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.
Emil_halim
Ziron Beta Tester

avatar

(send private message)

Posts: 639
Topics: 104

Location:
Alex, Egypt
[327] - posted: 2011-11-04 22:32:01

very strange , the same error
Code:
function event_Dim() {
  uses edi;  
    char var[255];  
    char buf[1024]; 
       
    eax = Ziron_ExpectNextToken(zirIdent);
  if (eax == -1) {
    Ziron_FatalError('Expected Variable Name');
    return true;
  }
    
  H_strcpy(@var,Ziron_GetStringValue()); 
    Ziron_ShowMessage(@var);
         
    eax = Ziron_ExpectNextToken(zirAs);
  if (eax == -1) {
    Ziron_FatalError('Expected as Keyword');
    return true;
  }
  
  eax = Ziron_ExpectNextToken(zirDATA_TYPE);
  if (eax == -1) {
    Ziron_FatalError('Expected data type');
    return true;
  }
  edi = Ziron_GetTypeSize();
  
  eax =  Ziron_GetStringValue();
    Ziron_ShowMessage(eax);
/*    
    H_strcat(@buf,eax); 
    H_strcat(@buf,' ');  
    H_strcat(@buf,@var);
    H_strcat(@buf,';');  
    H_strcat(@buf,'\r\n'); 
*/    
    strAppend(@buf,eax,1023);
    if (eax == false) {
        Ziron_FatalError('strAppend failed\r\n');
     }
    strAppend(@buf,' ',1023);
    if (eax == false) {
        Ziron_FatalError('strAppend failed\r\n');
     }
    strAppend(@buf,@var,1023);
    if (eax == false) {
        Ziron_FatalError('strAppend failed\r\n');
     }
    strAppend(@buf,';',1023);
    if (eax == false) {
        Ziron_FatalError('strAppend failed\r\n');
     }
    strAppend(@buf,'\r\n',1023);
    if (eax == false) {
        Ziron_FatalError('strAppend failed\r\n');
     }
    
  Ziron_ShowMessage(@buf);
  return true;
}


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

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[328] - posted: 2011-11-04 22:35:44
i will try compile your function and give it a shot, does it give any error without any string appending?

Download Ziron
Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.
Emil_halim
Ziron Beta Tester

avatar

(send private message)

Posts: 639
Topics: 104

Location:
Alex, Egypt
[329] - posted: 2011-11-04 22:38:14


no , only access violation.

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

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[330] - posted: 2011-11-04 22:44:46
lol i see problem

Code:
    eax =  Ziron_GetStringValue();
    Ziron_ShowMessage(eax);


Ziron_ShowMessage is changing eax value, just remove the call to Ziron_ShowMessage(eax) smile

1 other thing, you should initialize buf in case it is filled with junk.

Code:
    char buf[1024]; 
  
    buf = 0; //make sure buf is initialized otherwise it may be filled with junk


Download Ziron
Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.
Emil_halim
Ziron Beta Tester

avatar

(send private message)

Posts: 639
Topics: 104

Location:
Alex, Egypt
[331] - posted: 2011-11-04 22:48:42

oh , what a logical error.....

anyway thank you very much for you good supports.



http://www.freewebs.com/ogremagic/index.htm
Pages: 1 2 3
create new reply


Quick reply:

Message:



Currently Active Users:
There are currently 14 user(s) online. 0 member(s) and 14 guest(s)
Most users ever online was 1046, January 28, 2022, 2:08 pm.


Statistics:
Threads: 225 | Posts: 1848 | Members: 51 | Active Members: 51
Welcome to our newest member, yecate
const Copyright = '2011-2024 © OverHertz Ltd. All rights reserved.';
Web development by OverHertz Ltd