Memowrit Question
Memowrit Question
How can i exclude chr(26) (ESC character) from the end when i use memowrit?
Regards
A.S.K
Regards
A.S.K
-
- Posts: 54
- Joined: Fri Oct 21, 2005 10:45 am
- Location: Russia, Moscow
- Contact:
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
Thank you for your answer but as i can see inside the memofile.c (witch create memowrit) the code: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.
#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
-
- Posts: 54
- Joined: Fri Oct 21, 2005 10:45 am
- Location: Russia, Moscow
- Contact:
I think you mean this code :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..
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
-
- Posts: 54
- Joined: Fri Oct 21, 2005 10:45 am
- Location: Russia, Moscow
- Contact:
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()?I think you mean this code :
if( hb_parinfo(0) == 3 && ISLOG( 3 ) )
bWriteEof = hb_parl( 3 );
As you can see bellow the sample is simple but still ...Vladimir Grigoriev wrote: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()?I think you mean this code :
if( hb_parinfo(0) == 3 && ISLOG( 3 ) )
bWriteEof = hb_parl( 3 );
Thank you anyway
Regards
A.S.K
#include "fivewin.ch"
function main()
memowrit("cc.txt","ask",.f.)
return ""
-
- Posts: 54
- Joined: Fri Oct 21, 2005 10:45 am
- Location: Russia, Moscow
- Contact:
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?
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 .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?
Regards
A.S.K
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
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
-
- Posts: 54
- Joined: Fri Oct 21, 2005 10:45 am
- Location: Russia, Moscow
- Contact:
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 );
}
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 );
}
-
- Posts: 54
- Joined: Fri Oct 21, 2005 10:45 am
- Location: Russia, Moscow
- Contact: