can you confirm your strcat function is working correctly?
Replies
yes , H_strcpy is okay , but H_strcat crashed.
http://www.freewebs.com/ogremagic/index.htm
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
//
// 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.
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:
strAppend failed
This is a test
very strange , the same error
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
i will try compile your function and give it a shot, does it give any error without any string appending?
lol i see problem
eax = Ziron_GetStringValue();
Ziron_ShowMessage(eax);
Ziron_ShowMessage is changing eax value, just remove the call to Ziron_ShowMessage(eax) ;)
1 other thing, you should initialize buf in case it is filled with junk.
char buf[1024];
buf = 0; //make sure buf is initialized otherwise it may be filled with junk
oh , what a logical error.....
anyway thank you very much for you good supports.
http://www.freewebs.com/ogremagic/index.htm