From 2db500ed1ce70484d818ba34a04d425b46497dc3 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sun, 22 Nov 2009 11:53:05 +0000 Subject: [PATCH] 2009-11-22 12:43 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) * contrib/hbwin/win_prn2.c + PRINTFILERAW(): Changed to use Harbour File I/O API instead of Windows one to read from a disk file. * More variable name / macro usage cleanup. ! TOFIX: PRINTFILERAW() has suspicious code aiming to delete Chr( 26 ) from input files. In current implementation it can strip Chr( 26 ) even from inside the file if the file is larger than read buffer, which means it will corrupt input and may cause wrong output to be printed (f.e. if that Chr( 26 ) is part of a printer control char sequence). * INSTALL + Added linux/clang to the target mix. --- harbour/ChangeLog | 19 ++++++++++++++-- harbour/INSTALL | 4 +++- harbour/contrib/hbwin/win_prn2.c | 39 ++++++++++++++++---------------- 3 files changed, 39 insertions(+), 23 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 4fdf61e9e6..f543701747 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,22 @@ past entries belonging to author(s): Viktor Szakats. */ +2009-11-22 12:43 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) + * contrib/hbwin/win_prn2.c + + PRINTFILERAW(): Changed to use Harbour File I/O API instead + of Windows one to read from a disk file. + * More variable name / macro usage cleanup. + + ! TOFIX: PRINTFILERAW() has suspicious code aiming to delete + Chr( 26 ) from input files. In current implementation it can + strip Chr( 26 ) even from inside the file if the file is + larger than read buffer, which means it will corrupt input + and may cause wrong output to be printed (f.e. if that Chr( 26 ) + is part of a printer control char sequence). + + * INSTALL + + Added linux/clang to the target mix. + 2009-11-22 12:38 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + harbour/config/linux/clang.mk + added support for CLANG in LINUX builds @@ -33,12 +49,11 @@ TOFIX: now it compiles in Linux and OS2 builds but it still does not work - 2009-11-22 12:29 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) * contrib/hbwin/win_prn2.c * Variables renamed to reflect their types. * Further cleanups. - + Added TOFIX to use Harbour IO instead of win to read a disk file. + + Added TOFIX to use Harbour IO instead of win to read a disk file. [DONE] * Changed to use HB_SIZE instead of ULONG for string lengths/sizes. + Added HB_SIZE casts to silence 64-bit warnings (to two places). diff --git a/harbour/INSTALL b/harbour/INSTALL index 4406451ee4..cb459bbada 100644 --- a/harbour/INSTALL +++ b/harbour/INSTALL @@ -413,6 +413,7 @@ HARBOUR linux ----- gcc - GNU C + clang - Clang compiler frontend watcom - Open Watcom C++ icc - Intel(R) C/C++ sunpro - Sun Studio C/C++ @@ -420,8 +421,8 @@ HARBOUR darwin ------ gcc - GNU C - icc - Intel(R) C/C++ clang - Clang compiler frontend + icc - Intel(R) C/C++ bsd --- @@ -1138,6 +1139,7 @@ HARBOUR x os2 -> dos/watcom x86 x os2 -> linux/watcom x86 linux -> linux/gcc (CPU cross-builds possible) + linux -> linux/clang (CPU cross-builds possible) linux -> linux/icc (CPU cross-builds possible: x86, x86-64, ia64) linux -> linux/sunpro (CPU cross-builds possible: x86, x86-64) x linux -> wce/mingwarm arm diff --git a/harbour/contrib/hbwin/win_prn2.c b/harbour/contrib/hbwin/win_prn2.c index 1b37a37e1d..1f769ea7c5 100644 --- a/harbour/contrib/hbwin/win_prn2.c +++ b/harbour/contrib/hbwin/win_prn2.c @@ -64,6 +64,7 @@ #define HB_OS_WIN_USED #include "hbapi.h" +#include "hbapifs.h" #include "hbapiitm.h" #define _ENUMPRN_FLAGS_ ( PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS ) @@ -192,7 +193,6 @@ static BOOL hb_GetDefaultPrinter( char * pszPrinterName, HB_SIZE * pulBufferSize { /* This option should never be required but is included because of this article - http://support.microsoft.com/kb/246772/en-us This option will not enumerate any network printers. @@ -210,20 +210,20 @@ static BOOL hb_GetDefaultPrinter( char * pszPrinterName, HB_SIZE * pulBufferSize { if( dwNeeded ) { - PRINTER_INFO_2 * ppi2 = ( PRINTER_INFO_2 * ) hb_xgrab( dwNeeded ); + PRINTER_INFO_2 * pPrinterInfo = ( PRINTER_INFO_2 * ) hb_xgrab( dwNeeded ); - if( EnumPrinters( PRINTER_ENUM_DEFAULT, NULL, 2, ( LPBYTE ) ppi2, dwNeeded, &dwNeeded, &dwReturned ) && dwReturned ) + if( EnumPrinters( PRINTER_ENUM_DEFAULT, NULL, 2, ( LPBYTE ) pPrinterInfo, dwNeeded, &dwNeeded, &dwReturned ) && dwReturned ) { - DWORD dwSize = ( DWORD ) lstrlen( ppi2->pPrinterName ); + DWORD dwSize = ( DWORD ) lstrlen( pPrinterInfo->pPrinterName ); if( dwSize && dwSize < *pulBufferSize ) { - HB_TCHAR_GETFROM( pszPrinterName, ppi2->pPrinterName, lstrlen( ppi2->pPrinterName ) ); + HB_TCHAR_GETFROM( pszPrinterName, pPrinterInfo->pPrinterName, lstrlen( pPrinterInfo->pPrinterName ) ); *pulBufferSize = dwSize + 1; bResult = TRUE; } } - hb_xfree( ppi2 ); + hb_xfree( pPrinterInfo ); } } } @@ -425,8 +425,6 @@ HB_FUNC( PRINTERPORTTONAME ) hb_retc_null(); } -#define BIG_PRINT_BUFFER ( 1024 * 32 ) - static int hb_PrintFileRaw( const char * pszPrinterName, const char * pszFileName, const char * pszDocName ) { HANDLE hPrinter; @@ -444,26 +442,27 @@ static int hb_PrintFileRaw( const char * pszPrinterName, const char * pszFileNam { if( StartPagePrinter( hPrinter ) != 0 ) { - LPTSTR lpFileName = HB_TCHAR_CONVTO( pszFileName ); - /* TOFIX: Use Harbour FS API */ - HANDLE hFile = CreateFile( lpFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ); + HB_FHANDLE fhnd = hb_fsOpen( pszFileName, FO_READ | FO_SHARED ); - HB_TCHAR_FREE( lpFileName ); - - if( hFile != INVALID_HANDLE_VALUE ) + if( fhnd != FS_ERROR ) { - BYTE printBuffer[ BIG_PRINT_BUFFER ]; - DWORD nRead, nWritten = 0; + BYTE pbyBuffer[ 32 * 1024 ]; + DWORD nWritten = 0; + USHORT nRead; - while( ReadFile( hFile, printBuffer, sizeof( printBuffer ), &nRead, NULL ) && nRead > 0 ) + while( ( nRead = hb_fsRead( fhnd, pbyBuffer, sizeof( pbyBuffer ) ) ) > 0 ) { - if( printBuffer[ nRead - 1 ] == 26 ) + /* TOFIX: This check seems wrong for any input files + larger than our read buffer, in such case it + will strip Chr( 26 ) from inside the file, which + means it will corrupt it. [vszakats] */ + if( pbyBuffer[ nRead - 1 ] == 26 ) nRead--; /* Skip the EOF() character */ - WritePrinter( hPrinter, printBuffer, nRead, &nWritten ); + WritePrinter( hPrinter, pbyBuffer, nRead, &nWritten ); } iResult = 1; - CloseHandle( hFile ); + hb_fsClose( fhnd ); } else iResult = -6;