FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Memowrit Question
Posts: 99
Joined: Wed Nov 02, 2005 10:40 AM
Memowrit Question
Posted: Tue Apr 11, 2006 12:21 PM

How can i exclude chr(26) (ESC character) from the end when i use memowrit?

Regards
A.S.K

Posts: 54
Joined: Fri Oct 21, 2005 10:45 AM
Memowrit Question
Posted: Tue Apr 11, 2006 04:01 PM

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. :o

Posts: 99
Joined: Wed Nov 02, 2005 10:40 AM
Memowrit
Posted: Wed Apr 12, 2006 08:25 AM
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
Posts: 54
Joined: Fri Oct 21, 2005 10:45 AM
Memowrit Question
Posted: Wed Apr 12, 2006 09:47 AM

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..

Posts: 99
Joined: Wed Nov 02, 2005 10:40 AM
Memowrit Question
Posted: Wed Apr 12, 2006 10:06 AM
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
Posts: 54
Joined: Fri Oct 21, 2005 10:45 AM
Memowrit Question
Posted: Wed Apr 12, 2006 10:15 AM
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()?
Posts: 99
Joined: Wed Nov 02, 2005 10:40 AM
Memowrit Question
Posted: Wed Apr 12, 2006 10:19 AM
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 ""
Posts: 54
Joined: Fri Oct 21, 2005 10:45 AM
Memowrit Question
Posted: Wed Apr 12, 2006 10:30 AM

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?

Posts: 99
Joined: Wed Nov 02, 2005 10:40 AM
Memowrit Question
Posted: Wed Apr 12, 2006 10:36 AM
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
Posts: 99
Joined: Wed Nov 02, 2005 10:40 AM
Memowrit Question
Posted: Wed Apr 12, 2006 10:47 AM

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, &amp;byEOF, sizeof( BYTE ) );
        }
     }
     #endif

     hb_fsClose( fhnd );
  }

}

hb_retl( bRetVal );
}

pragma ENDDUMP

Posts: 54
Joined: Fri Oct 21, 2005 10:45 AM
Memowrit Question
Posted: Wed Apr 12, 2006 11:09 AM
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 );
}
Posts: 54
Joined: Fri Oct 21, 2005 10:45 AM
Memowrit Question
Posted: Wed Apr 12, 2006 11:32 AM

I have pointed out incompatibility of MEMOWRITE() functions between Harbour and xHarbour on xHarbour forum. :o

Posts: 99
Joined: Wed Nov 02, 2005 10:40 AM
Memowrit Question
Posted: Wed Apr 12, 2006 01:18 PM
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
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Memowrit Question
Posted: Sun Nov 09, 2008 08:43 PM

Incompatibility of MEMOWRITE is still there
Regards,
Otto

Continue the discussion