How can i exclude chr(26) (ESC character) from the end when i use memowrit?
Regards
A.S.K
How can i exclude chr(26) (ESC character) from the end when i use memowrit?
Regards
A.S.K
In Clipper MEMOWRITE() is nothing more than sequence of the functions fopen(), fwrite(), fclose(). The only thing MEMOWRITE() does itself is appending EOF character. Though I don't use Harbour but I think the same is justly for Harbour. So you can use fopen(), fwrite(), fclose() functions by youself instead of MEMOWRITE(). Though it is better to know what will say Harbour guru. ![]()
Vladimir Grigoriev wrote:In Clipper MEMOWRITE() is nothing more than sequence of the functions fopen(), fwrite(), fclose(). The only thing MEMOWRITE() does itself is appending EOF character. Though I don't use Harbour but I think the same is justly for Harbour. So you can use fopen(), fwrite(), fclose() functions by youself instead of MEMOWRITE(). Though it is better to know what will say Harbour guru.
As I have understood the new function MEMOWRITE() has three parameters. The third parameter of type Logical specifies either to write EOF character ( .T. by default) or not (.F.).
So you should specify MEMOWRITE() function with three parameters and the third parameter should be specified as .F..
Vladimir Grigoriev wrote:As I have understood the new function MEMOWRITE() has three parameters. The third parameter of type Logical specifies either to write EOF character ( .T. by default) or not (.F.).
So you should specify MEMOWRITE() function with three parameters and the third parameter should be specified as .F..
I think you mean this code :
if( hb_parinfo(0) == 3 && ISLOG( 3 ) )
bWriteEof = hb_parl( 3 );
Vladimir Grigoriev wrote:I think you mean this code :
if( hb_parinfo(0) == 3 && ISLOG( 3 ) )
bWriteEof = hb_parl( 3 );
Yes I have meant this code above. So maybe there is a bug in your Harbour build or there is another idea. What about your string data <text> contains EOF character itself? Can you test last character of your data before you will write on a disk it with MEMOWRITE()?
Unfortunately I can not test your code as I have not Harbour. From the source code of memofile.c one should conclude that MEMOWRITE() will work correctly i.e. it will write into file without EOF character if the third parameter will be set to .F..
By the way how do you determine that EOF character does present in you file? What is the file size of cc.txt?
Vladimir Grigoriev wrote:Unfortunately I can not test your code as I have not Harbour. From the source code of memofile.c one should conclude that MEMOWRITE() will work correctly i.e. it will write into file without EOF character if the third parameter will be set to .F..
By the way how do you determine that EOF character does present in you file? What is the file size of cc.txt?
I changed my code to the bellow code and now works perfectly.This means that i probably have old xharbour
Regards
A.S.K
function main()
memowrit("cc.txt","ask",.f.)
return ""
HB_FUNC( MEMOWRIT )
{
PHB_ITEM pFileName = hb_param( 1, HB_IT_STRING );
PHB_ITEM pString = hb_param( 2, HB_IT_STRING );
BOOL bWriteEof = TRUE; / write Eof !, by default is .T. /
BOOL bRetVal = FALSE;
if( hb_parinfo(0) == 3 && ISLOG( 3 ) )
bWriteEof = hb_parl( 3 );
if( pFileName && pString )
{
FHANDLE fhnd = hb_fsCreate( ( BYTE * ) hb_itemGetCPtr( pFileName ), FC_NORMAL );
if( fhnd != FS_ERROR )
{
ULONG ulSize = hb_itemGetCLen( pString );
bRetVal = ( hb_fsWriteLarge( fhnd, ( BYTE * ) hb_itemGetCPtr( pString ), ulSize ) == ulSize );
/* NOTE: CA-Clipper will add the EOF even if the write failed. [vszakats] */
/* NOTE: CA-Clipper will not return .F. when the EOF could not be written. [vszakats] */
#if ! defined(OS_UNIX_COMPATIBLE)
{
if( bWriteEof ) /* if true, then write EOF */
{
BYTE byEOF = HB_CHAR_EOF;
hb_fsWrite( fhnd, &byEOF, sizeof( BYTE ) );
}
}
#endif
hb_fsClose( fhnd );
}
}
hb_retl( bRetVal );
}
I have pointed out incompatibility of MEMOWRITE() functions between Harbour and xHarbour on xHarbour forum. ![]()
Vladimir Grigoriev wrote:I have pointed out incompatibility of MEMOWRITE() functions between Harbour and xHarbour on xHarbour forum.
Incompatibility of MEMOWRITE is still there
Regards,
Otto