Page 1 of 1
Memowrit Question
Posted: Tue Apr 11, 2006 12:21 pm
by ask
How can i exclude chr(26) (ESC character) from the end when i use memowrit?
Regards
A.S.K
Posted: Tue Apr 11, 2006 4:01 pm
by Vladimir Grigoriev
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.
Memowrit
Posted: Wed Apr 12, 2006 8:25 am
by ask
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.
Thank you for your answer but as i can see inside the memofile.c (witch create memowrit) the code:
#if ! defined(OS_UNIX_COMPATIBLE)
{
if( bWriteEof ) /* if true, then write EOF */
{
BYTE byEOF = HB_CHAR_EOF;
hb_fsWrite( fhnd, &byEOF, sizeof( BYTE ) );
}
}
#endif
does something about the problem but i can understand what .If someone can explain please
Regards
A.S.K
Posted: Wed Apr 12, 2006 9:47 am
by Vladimir Grigoriev
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..
Posted: Wed Apr 12, 2006 10:06 am
by ask
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 );
But i have xharbour 0.99.60 and fhw 2.7 and
memowrit(<file>,<text>,.f.) still writes ESC character at the end
Regards
A.S.K
Posted: Wed Apr 12, 2006 10:15 am
by Vladimir Grigoriev
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()?
Posted: Wed Apr 12, 2006 10:19 am
by ask
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()?
As you can see bellow the sample is simple but still ...
Thank you anyway
Regards
A.S.K
#include "fivewin.ch"
function main()
memowrit("cc.txt","ask",.f.)
return ""
Posted: Wed Apr 12, 2006 10:30 am
by Vladimir Grigoriev
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?
Posted: Wed Apr 12, 2006 10:36 am
by ask
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?
The file is 4bytes .I use edit from dos to see it too. I don't know why it does not working .
Regards
A.S.K
Posted: Wed Apr 12, 2006 10:47 am
by ask
I changed my code to the bellow code and now works perfectly.This means that i probably have old xharbour
Regards
A.S.K
#include "fivewin.ch"
function main()
memowrit("cc.txt","ask",.f.)
return ""
#pragma BEGINDUMP
#include <hbapi.h>
#include <hbapiitm.h>
#include "hbapifs.h"
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 );
}
#pragma ENDDUMP
Posted: Wed Apr 12, 2006 11:09 am
by Vladimir Grigoriev
Ops! You are writing about xHarbour but the code for MEMOWRITE() discussed is from Harbour!
I have looked through xHarbour source code for MEMOWRITE() and indeed it has not the third parameter. So xHarbour MEMOWRITE() always writes EOF character! The code from xHarbour is below
HB_FUNC( MEMOWRIT )
{
PHB_ITEM pFileName = hb_param( 1, HB_IT_STRING );
PHB_ITEM pString = hb_param( 2, HB_IT_STRING );
BOOL bRetVal = FALSE;
if( pFileName && pString )
{
FHANDLE fhnd = hb_fsCreate( ( BYTE * ) pFileName->item.asString.value, FC_NORMAL );
if( fhnd != FS_ERROR )
{
ULONG ulSize = pString->item.asString.length;
bRetVal = ( hb_fsWriteLarge( fhnd, ( BYTE * ) pString->item.asString.value, 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)
{
BYTE byEOF = HB_CHAR_EOF;
hb_fsWrite( fhnd, &byEOF, sizeof( BYTE ) );
}
#endif
hb_fsClose( fhnd );
}
}
hb_retl( bRetVal );
}
Posted: Wed Apr 12, 2006 11:32 am
by Vladimir Grigoriev
I have pointed out incompatibility of MEMOWRITE() functions between Harbour and xHarbour on xHarbour forum.
Posted: Wed Apr 12, 2006 1:18 pm
by ask
Vladimir Grigoriev wrote:I have pointed out incompatibility of MEMOWRITE() functions between Harbour and xHarbour on xHarbour forum.
Thank you very much for all your help Vladimir
Regards
A.S.K
Posted: Sun Nov 09, 2008 8:43 pm
by Otto
Incompatibility of MEMOWRITE is still there
Regards,
Otto