From 763ccea5613a23a9fb07ec020d04a0850343bfeb Mon Sep 17 00:00:00 2001 From: "David G. Holm" Date: Tue, 29 Jul 2003 02:01:25 +0000 Subject: [PATCH] See ChangeLog entry 2003-07-28 22:00 UTC-0400 David G. Holm --- harbour/ChangeLog | 12 ++++++++++++ harbour/include/hbset.h | 6 ++++-- harbour/include/set.ch | 3 ++- harbour/source/pp/pptable.c | 3 ++- harbour/source/rtl/dbdelim.prg | 7 +++++-- harbour/source/rtl/dbsdf.prg | 5 ++++- harbour/source/rtl/set.c | 36 ++++++++++++++++++++++------------ 7 files changed, 52 insertions(+), 20 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 9e2360eba7..5ebf5b23dd 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,18 @@ 2002-12-01 23:12 UTC+0100 Foo Bar */ +2003-07-28 22:00 UTC-0400 David G. Holm + * include/hbset.h + * include/set.ch + * source/pp/pptable.c + * source/rtl/dbdelim.prg + * source/rtl/dbsdf.prg + * source/rtl/set.c + + New SET value named _SET_EOF. Defaults to FALSE on UN*X, but defaults + to TRUE on everything else. If set to FALSE, then CHR(26) does not get + written when using COPY TO DELIMITED, COPY TO SDF, or when closing any + of the various text files that are created using various SET values. + 2003-07-21 11:10 UTC-0300 Antonio Carlos Pantaglione * source/rtl/transfrm.c ! Fixed the problem with @E and negative numbers. diff --git a/harbour/include/hbset.h b/harbour/include/hbset.h index 0381a8e91c..ffad3f135f 100644 --- a/harbour/include/hbset.h +++ b/harbour/include/hbset.h @@ -6,7 +6,7 @@ * Harbour Project source code: * Header file for the Set API * - * Copyright 1999 David G. Holm + * Copyright 1999-2003 David G. Holm * www - http://www.harbour-project.org * * This program is free software; you can redistribute it and/or modify @@ -127,7 +127,8 @@ typedef enum HB_SET_IDLEREPEAT = 101, HB_SET_FILECASE = 102, HB_SET_DIRCASE = 103, - HB_SET_DIRSEPARATOR = 104 + HB_SET_DIRSEPARATOR = 104, + HB_SET_EOF = 105 } HB_set_enum; @@ -158,6 +159,7 @@ typedef struct char * HB_SET_DELIMCHARS; BOOL HB_SET_DELIMITERS; char * HB_SET_DEVICE; + BOOL HB_SET_EOF; int HB_SET_EPOCH; BOOL HB_SET_ESCAPE; HB_inkey_enum HB_SET_EVENTMASK; diff --git a/harbour/include/set.ch b/harbour/include/set.ch index 06608f2458..a063b32593 100644 --- a/harbour/include/set.ch +++ b/harbour/include/set.ch @@ -6,7 +6,7 @@ * Harbour Project source code: * Header file for SET() function * - * Copyright 1999 David G. Holm + * Copyright 1999-2003 David G. Holm * www - http://www.harbour-project.org * * This program is free software; you can redistribute it and/or modify @@ -119,6 +119,7 @@ #define _SET_FILECASE 102 /* Harbour extension */ #define _SET_DIRCASE 103 /* Harbour extension */ #define _SET_DIRSEPARATOR 104 /* Harbour extension */ +#define _SET_EOF 105 /* Harbour extension */ #define HB_SET_BASE 100 #define HB_SET_COUNT 2 diff --git a/harbour/source/pp/pptable.c b/harbour/source/pp/pptable.c index c25a888b50..a566d1a415 100644 --- a/harbour/source/pp/pptable.c +++ b/harbour/source/pp/pptable.c @@ -124,6 +124,7 @@ void hb_pp_Table( void ) static DEFINES sD___53 = {"_SET_FILECASE",NULL,-1,"102", &sD___52 }; static DEFINES sD___54 = {"_SET_DIRCASE",NULL,-1,"103", &sD___53 }; static DEFINES sD___55 = {"_SET_DIRSEPARATOR",NULL,-1,"104", &sD___54 }; + static DEFINES sD___56 = {"_SET_EOF",NULL,-1,"105", &sD___55 }; static COMMANDS sC___1 = {0,"NOTE","\1A30",NULL,NULL }; static COMMANDS sC___2 = {0,"DO","WHILE \1A00","while \1A00",&sC___1 }; @@ -433,7 +434,7 @@ void hb_pp_Table( void ) static COMMANDS sC___249 = {0,"SET","DIRSEPARATOR \1A30","Set(_SET_DIRSEPARATOR, \1A10 )",&sC___248 }; static COMMANDS sC___250 = {0,"SET","DIRSEPARATOR ( \1A00 )","Set(_SET_DIRSEPARATOR, \1A00 )",&sC___249 }; - hb_pp_topDefine = &sD___55; + hb_pp_topDefine = &sD___56; hb_pp_topCommand = &sC___250; hb_pp_topTranslate = NULL; } diff --git a/harbour/source/rtl/dbdelim.prg b/harbour/source/rtl/dbdelim.prg index edfa72309f..32c44047be 100644 --- a/harbour/source/rtl/dbdelim.prg +++ b/harbour/source/rtl/dbdelim.prg @@ -7,7 +7,7 @@ * Copies the contents of a database to a delimited text file. * Appends the contents of a delimited text file to a database. * - * Copyright 2001-2002 David G. Holm + * Copyright 2001-2003 David G. Holm * www - http://www.harbour-project.org * APPEND FROM code submitted by Marco Braida * @@ -55,6 +55,7 @@ #include "hbcommon.ch" #include "fileio.ch" #include "error.ch" +#include "set.ch" HB_FILE_VER( "$Id$" ) @@ -193,7 +194,9 @@ local lcisonoeol END IF SKIP END WHILE - AppendEOF( handle ) + IF SET(_SET_EOF) + AppendEOF( handle ) + END IF FCLOSE( handle ) END IF ELSE diff --git a/harbour/source/rtl/dbsdf.prg b/harbour/source/rtl/dbsdf.prg index 0699397032..d64115692f 100644 --- a/harbour/source/rtl/dbsdf.prg +++ b/harbour/source/rtl/dbsdf.prg @@ -54,6 +54,7 @@ #include "hbcommon.ch" #include "fileio.ch" #include "error.ch" +#include "set.ch" HB_FILE_VER( "$Id$" ) @@ -156,7 +157,9 @@ PROCEDURE __dbSDF( lExport, cFile, aFields, bFor, bWhile, nNext, nRecord, lRest END IF SKIP END WHILE - AppendEOF( handle ) + IF SET(_SET_EOF) + AppendEOF( handle ) + END IF FCLOSE( handle ) END IF ELSE diff --git a/harbour/source/rtl/set.c b/harbour/source/rtl/set.c index 7cc3fb32bc..98383c9203 100644 --- a/harbour/source/rtl/set.c +++ b/harbour/source/rtl/set.c @@ -6,7 +6,7 @@ * Harbour Project source code: * Set functions * - * Copyright 1999-2001 David G. Holm + * Copyright 1999-2003 David G. Holm * www - http://www.harbour-project.org * * This program is free software; you can redistribute it and/or modify @@ -213,9 +213,10 @@ static void close_text( FHANDLE handle ) /* Close the file handle without disrupting the current user file error value */ USHORT user_ferror = hb_fsError(); - #if ! defined(OS_UNIX_COMPATIBLE) + if( hb_set.HB_SET_EOF ) + { hb_fsWrite( handle, ( BYTE * ) "\x1A", 1 ); - #endif + } hb_fsClose( handle ); hb_fsSetError( user_ferror ); } @@ -275,28 +276,28 @@ static FHANDLE open_handle( char * file_name, BOOL bAppend, char * def_ext, HB_s handle = hb_fsOpen( ( BYTE * ) path, FO_READWRITE | FO_DENYWRITE ); if( handle != FS_ERROR ) { /* Position to EOF */ - #if ! defined(OS_UNIX_COMPATIBLE) - /* Non-Unix needs special binary vs. text file handling */ + /* Special binary vs. text file handling - even for UN*X, now + that there's an HB_SET_EOF flag. */ if( set_specifier == HB_SET_PRINTFILE ) - { /* PRINTFILE is binary and needs no special handling. */ - #endif + { /* PRINTFILE is always binary and needs no special handling. */ hb_fsSeek( handle, 0, FS_END ); - #if ! defined(OS_UNIX_COMPATIBLE) } else { /* All other files are text files and may have an EOF - ('\x1A') character at the end (non-UNIX only). */ + ('\x1A') character at the end (both UN*X and non-UN*X, + now that theres an HB_SET_EOF flag). */ char cEOF = '\0'; hb_fsSeek( handle, -1, FS_END ); /* Position to last char. */ hb_fsRead( handle, ( BYTE * ) &cEOF, 1 ); /* Read the last char. */ if( cEOF == '\x1A' ) /* If it's an EOF, */ + { hb_fsSeek( handle, -1, FS_END ); /* Then write over it. */ + } } - #endif - } - } + } + } else bCreate = TRUE; /* Otherwise create a new file. */ - } + } else bCreate = TRUE; /* Always create a new file for overwrite mode. */ if( bCreate ) @@ -592,6 +593,10 @@ HB_FUNC( SET ) hb_set.hb_set_printhan = open_handle( hb_set.HB_SET_PRINTFILE, FALSE, ".prn", HB_SET_PRINTFILE ); } break; + case HB_SET_EOF : + hb_retl( hb_set.HB_SET_EOF ); + if( args > 1 ) hb_set.HB_SET_EOF = set_logical( pArg2 ); + break; case HB_SET_EPOCH : hb_retni( hb_set.HB_SET_EPOCH ); if( args > 1 ) @@ -906,6 +911,11 @@ void hb_setInitialize( void ) hb_set.HB_SET_DELIMITERS = FALSE; hb_set.HB_SET_DEVICE = ( char * ) hb_xgrab( 7 ); memcpy( hb_set.HB_SET_DEVICE, "SCREEN", 7 ); +#if defined(OS_UNIX_COMPATIBLE) + hb_set.HB_SET_EOF = FALSE; +#else + hb_set.HB_SET_EOF = TRUE; +#endif hb_set.HB_SET_EPOCH = 1900; hb_set.HB_SET_ESCAPE = TRUE; hb_set.HB_SET_EVENTMASK = INKEY_KEYBOARD;