From 3b5dfde38c8e67cac1ed71a3dff59d44c59b74bf Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sun, 8 Jun 2008 10:22:37 +0000 Subject: [PATCH] 2008-06-08 12:14 UTC+0100 Viktor Szakats (harbour.01 syenar hu) * contrib/hbmysql/tmysql.prg * contrib/hbmysql/mysql.c * contrib/hbmysql/mysql.ch * contrib/hbtpathy/telepath.ch * contrib/hbtpathy/tplinux.c * contrib/hbtpathy/tpwin32.c * contrib/hbtpathy/tpos2.c * contrib/hbtpathy/tpcommon.c * contrib/hbmsql/msql.h * contrib/hbmsql/msql.ch * contrib/hbmsql/msql.c * contrib/hbfbird/firebird.c * contrib/hbfbird/tests/test.prg * contrib/hbapollo/apollo.c * contrib/hbmisc/hb_f.c * General code cleanup, formatting, minor optimizations, Harbour API usage cleanup, ANSI comments. ! Several minor fixes to Firebird interface code, but it still doesn't seem to work, and the code is very unclear, partly because of the strange/unsafe Firebird API. ! Firebird test.prg fixes: Variable name typos, undeclared vars, hard-coded paths. * contrib/hbfbird/make_b32.bat * contrib/hbfbird/make_vc.bat * Fixed location where .libs are looked for. [TOMERGE RC1] * contrib/hbcurl/hbcurl.c % Minor cleanups. [TOMERGE RC1] --- harbour/ChangeLog | 33 + harbour/contrib/hbapollo/apollo.c | 148 ++-- harbour/contrib/hbcurl/hbcurl.c | 86 +- harbour/contrib/hbfbird/firebird.c | 1081 +++++++++++------------- harbour/contrib/hbfbird/make_b32.bat | 2 +- harbour/contrib/hbfbird/make_vc.bat | 2 +- harbour/contrib/hbfbird/tests/test.prg | 137 +-- harbour/contrib/hbmisc/hb_f.c | 2 +- harbour/contrib/hbmsql/msql.c | 233 ++--- harbour/contrib/hbmsql/msql.ch | 14 +- harbour/contrib/hbmsql/msql.h | 2 +- harbour/contrib/hbmysql/mysql.c | 144 ++-- harbour/contrib/hbmysql/mysql.ch | 26 +- harbour/contrib/hbmysql/tmysql.prg | 51 +- harbour/contrib/hbtpathy/telepath.ch | 117 ++- harbour/contrib/hbtpathy/tpcommon.c | 25 +- harbour/contrib/hbtpathy/tplinux.c | 216 ++--- harbour/contrib/hbtpathy/tpos2.c | 183 ++-- harbour/contrib/hbtpathy/tpwin32.c | 83 +- 19 files changed, 1110 insertions(+), 1475 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index dafc735496..b51020d70d 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,39 @@ 2008-12-31 13:59 UTC+0100 Foo Bar */ +2008-06-08 12:14 UTC+0100 Viktor Szakats (harbour.01 syenar hu) + * contrib/hbmysql/tmysql.prg + * contrib/hbmysql/mysql.c + * contrib/hbmysql/mysql.ch + * contrib/hbtpathy/telepath.ch + * contrib/hbtpathy/tplinux.c + * contrib/hbtpathy/tpwin32.c + * contrib/hbtpathy/tpos2.c + * contrib/hbtpathy/tpcommon.c + * contrib/hbmsql/msql.h + * contrib/hbmsql/msql.ch + * contrib/hbmsql/msql.c + * contrib/hbfbird/firebird.c + * contrib/hbfbird/tests/test.prg + * contrib/hbapollo/apollo.c + * contrib/hbmisc/hb_f.c + * General code cleanup, formatting, minor optimizations, + Harbour API usage cleanup, ANSI comments. + ! Several minor fixes to Firebird interface code, but it + still doesn't seem to work, and the code is very unclear, + partly because of the strange/unsafe Firebird API. + ! Firebird test.prg fixes: Variable name typos, undeclared + vars, hard-coded paths. + + * contrib/hbfbird/make_b32.bat + * contrib/hbfbird/make_vc.bat + * Fixed location where .libs are looked for. + [TOMERGE RC1] + + * contrib/hbcurl/hbcurl.c + % Minor cleanups. + [TOMERGE RC1] + 2008-06-07 15:32 UTC+0800 Pritpal Bedi (pritpal@vouchcac.com * harbour/source/rtl/gtwvt/gtwvt.c * harbour/source/rtl/gtwvt/gtwvt.h diff --git a/harbour/contrib/hbapollo/apollo.c b/harbour/contrib/hbapollo/apollo.c index 4f5fbf7b38..08ab6be52b 100644 --- a/harbour/contrib/hbapollo/apollo.c +++ b/harbour/contrib/hbapollo/apollo.c @@ -73,7 +73,7 @@ * --------------------------------------------------*/ HB_FUNC( SX_APPENDBLANK ) { - sx_AppendBlank( ); + sx_AppendBlank(); } @@ -82,7 +82,7 @@ HB_FUNC( SX_APPENDBLANK ) * --------------------------------------------------*/ HB_FUNC( SX_CLOSE ) { - sx_Close( ) ; + sx_Close(); } @@ -91,7 +91,7 @@ HB_FUNC( SX_CLOSE ) * --------------------------------------------------*/ HB_FUNC( SX_COMMIT ) { - sx_Commit( ); + sx_Commit(); } @@ -101,7 +101,7 @@ HB_FUNC( SX_COMMIT ) * --------------------------------------------------*/ HB_FUNC( SX_CREATEEXEC ) { - sx_CreateExec( ); + sx_CreateExec(); } @@ -123,11 +123,11 @@ HB_FUNC( SX_CREATEFIELD ) * --------------------------------------------------*/ HB_FUNC( SX_CREATENEW ) { - hb_retni( - sx_CreateNew( ( PBYTE ) hb_parc( 1 ), /* Field name */ - ( PBYTE ) hb_parc( 2 ), /* Alias */ - hb_parni( 3 ), /* RDE Type */ - hb_parni( 4 ) ) ); /* The maximum number of fields to be added to the file structure */ + hb_retni( + sx_CreateNew( ( PBYTE ) hb_parc( 1 ), /* Field name */ + ( PBYTE ) hb_parc( 2 ), /* Alias */ + hb_parni( 3 ), /* RDE Type */ + hb_parni( 4 ) ) ); /* The maximum number of fields to be added to the file structure */ } @@ -136,7 +136,7 @@ HB_FUNC( SX_CREATENEW ) * --------------------------------------------------*/ HB_FUNC( SX_EOF ) { - hb_retl( sx_Eof( ) ); + hb_retl( sx_Eof() ); } @@ -148,8 +148,7 @@ HB_FUNC( SX_EOF ) * --------------------------------------------------*/ HB_FUNC( SX_GETDATEJULIAN ) { - hb_retni( - sx_GetDateJulian( ( PBYTE ) hb_parc( 1 ) ) ); /* Field name */ + hb_retni( sx_GetDateJulian( ( PBYTE ) hb_parc( 1 ) ) ); /* Field name */ } @@ -159,8 +158,7 @@ HB_FUNC( SX_GETDATEJULIAN ) * --------------------------------------------------*/ HB_FUNC( SX_GETLOGICAL ) { - hb_retl( - sx_GetLogical( ( PBYTE ) hb_parc( 1 ) ) ); /* Field name */ + hb_retl( sx_GetLogical( ( PBYTE ) hb_parc( 1 ) ) ); /* Field name */ } @@ -169,8 +167,7 @@ HB_FUNC( SX_GETLOGICAL ) * --------------------------------------------------*/ HB_FUNC( SX_GETSTRING ) { - hb_retc( - ( char * )sx_GetString( ( PBYTE ) hb_parc( 1 ) ) ); /* Field name */ + hb_retc( ( char * ) sx_GetString( ( PBYTE ) hb_parc( 1 ) ) ); /* Field name */ } @@ -179,8 +176,7 @@ HB_FUNC( SX_GETSTRING ) * --------------------------------------------------*/ HB_FUNC( SX_GETVARIANT ) { - hb_retc( - ( char * )sx_GetVariant( ( PBYTE ) hb_parc( 1 ) ) ); /* Field name */ + hb_retc( ( char * ) sx_GetVariant( ( PBYTE ) hb_parc( 1 ) ) ); /* Field name */ } @@ -189,7 +185,7 @@ HB_FUNC( SX_GETVARIANT ) * --------------------------------------------------*/ HB_FUNC( SX_GO ) { - sx_Go( hb_parni( 1 ) ); /* The record number to go */ + sx_Go( hb_parni( 1 ) ); /* The record number to go */ } @@ -198,7 +194,7 @@ HB_FUNC( SX_GO ) * --------------------------------------------------*/ HB_FUNC( SX_GOBOTTOM ) { - sx_GoBottom( ) ; + sx_GoBottom(); } @@ -207,7 +203,7 @@ HB_FUNC( SX_GOBOTTOM ) * --------------------------------------------------*/ HB_FUNC( SX_GOTOP ) { - sx_GoTop( ) ; + sx_GoTop(); } @@ -216,13 +212,13 @@ HB_FUNC( SX_GOTOP ) * --------------------------------------------------*/ HB_FUNC( SX_INDEXTAG ) { - hb_retni( - sx_IndexTag( ( PBYTE ) hb_parc( 1 ), /* Field name */ - ( PBYTE ) hb_parc( 2 ), /* Tag name */ - ( PBYTE ) hb_parc( 3 ), /* Index expression as a string */ - hb_parni( 4 ), /* Option (0=Standard) (1=Unique) (2=Roll-Your-Own) */ - hb_parl( 5 ), /* True for a descend index */ - ( PBYTE ) hb_parc( 6) ) ); /* Condition */ + hb_retni( + sx_IndexTag( ( PBYTE ) hb_parc( 1 ), /* Field name */ + ( PBYTE ) hb_parc( 2 ), /* Tag name */ + ( PBYTE ) hb_parc( 3 ), /* Index expression as a string */ + hb_parni( 4 ), /* Option (0=Standard) (1=Unique) (2=Roll-Your-Own) */ + hb_parl( 5 ), /* True for a descend index */ + ( PBYTE ) hb_parc( 6) ) ); /* Condition */ } @@ -231,8 +227,7 @@ HB_FUNC( SX_INDEXTAG ) * --------------------------------------------------*/ HB_FUNC( SX_RECCOUNT ) { - hb_retni( - sx_RecCount( ) ); + hb_retni( sx_RecCount() ); } @@ -241,8 +236,7 @@ HB_FUNC( SX_RECCOUNT ) * --------------------------------------------------*/ HB_FUNC( SX_RECNO ) { - hb_retni( - sx_RecNo( ) ); + hb_retni( sx_RecNo() ); } @@ -251,7 +245,7 @@ HB_FUNC( SX_RECNO ) * --------------------------------------------------*/ HB_FUNC( SX_REINDEX ) { - sx_Reindex( ); + sx_Reindex(); } @@ -260,28 +254,26 @@ HB_FUNC( SX_REINDEX ) * --------------------------------------------------*/ HB_FUNC( SX_REPLACE ) { - -switch ( hb_parni( 2 ) ) -{ - case R_INTEGER : - case R_JULIAN : sx_Replace( ( PBYTE ) hb_parc( 1 ), hb_parni( 2 ), ( void * ) hb_parni( 3) ) ; break; - case R_LOGICAL : sx_Replace( ( PBYTE ) hb_parc( 1 ), hb_parni( 2 ), ( void * ) hb_parni( 3) ) ; break; /* TODO: somthing is wrong here... */ - case R_LONG : sx_Replace( ( PBYTE ) hb_parc( 1 ), hb_parni( 2 ), ( void * ) hb_parnl( 3) ) ; break; - case R_DOUBLE : - { - double d = hb_parnd( 3 ); - sx_Replace( ( PBYTE ) hb_parc( 1 ), hb_parni( 2 ), ( void * ) &d ); - break; - } - case R_CHAR : - case R_DATESTR : - case R_MEMO : - case R_BITMAP : - case R_BLOBFILE: - case R_BLOBPTR : sx_Replace( ( PBYTE ) hb_parc( 1 ), hb_parni( 2 ), ( void * ) hb_parc( 3) ) ; break; - default: sx_Replace( ( PBYTE ) hb_parc( 1 ), hb_parni( 2 ), ( void * ) hb_parc( 3) ); -} - + switch( hb_parni( 2 ) ) + { + case R_INTEGER : + case R_JULIAN : sx_Replace( ( PBYTE ) hb_parc( 1 ), hb_parni( 2 ), ( void * ) hb_parni( 3) ); break; + case R_LOGICAL : sx_Replace( ( PBYTE ) hb_parc( 1 ), hb_parni( 2 ), ( void * ) hb_parni( 3) ); break; /* TODO: somthing is wrong here... */ + case R_LONG : sx_Replace( ( PBYTE ) hb_parc( 1 ), hb_parni( 2 ), ( void * ) hb_parnl( 3) ); break; + case R_DOUBLE : + { + double d = hb_parnd( 3 ); + sx_Replace( ( PBYTE ) hb_parc( 1 ), hb_parni( 2 ), ( void * ) &d ); + break; + } + case R_CHAR : + case R_DATESTR : + case R_MEMO : + case R_BITMAP : + case R_BLOBFILE: + case R_BLOBPTR : sx_Replace( ( PBYTE ) hb_parc( 1 ), hb_parni( 2 ), ( void * ) hb_parc( 3) ); break; + default: sx_Replace( ( PBYTE ) hb_parc( 1 ), hb_parni( 2 ), ( void * ) hb_parc( 3) ); + } } @@ -290,7 +282,7 @@ switch ( hb_parni( 2 ) ) * --------------------------------------------------*/ HB_FUNC( SX_RLOCK ) { - sx_Rlock( hb_parni( 1 ) ); /* The physical record number of the record to be locked. */ + sx_Rlock( hb_parni( 1 ) ); /* The physical record number of the record to be locked. */ } @@ -299,8 +291,7 @@ HB_FUNC( SX_RLOCK ) * --------------------------------------------------*/ HB_FUNC( SX_SEEK ) { - hb_retl( - sx_Seek( ( PBYTE ) hb_parc( 1 ) ) ); /* The value to search for as a string */ + hb_retl( sx_Seek( ( PBYTE ) hb_parc( 1 ) ) ); /* The value to search for as a string */ } @@ -310,8 +301,7 @@ HB_FUNC( SX_SEEK ) * --------------------------------------------------*/ HB_FUNC( SX_SELECT ) { - hb_retni( - sx_Seek( ( PBYTE ) hb_parc( 1 ) ) ); /* The work area number returned when the file was opened. */ + hb_retni( sx_Seek( ( PBYTE ) hb_parc( 1 ) ) ); /* The work area number returned when the file was opened. */ } @@ -323,8 +313,8 @@ HB_FUNC( SX_SELECT ) * --------------------------------------------------*/ HB_FUNC( SX_SETCENTURY ) { - sx_SetCentury( hb_parl( 1 ) ); /* If True, the century digits will be returned. - * If False, they will not. */ + sx_SetCentury( hb_parl( 1 ) ); /* If True, the century digits will be returned. + * If False, they will not. */ } @@ -334,8 +324,8 @@ HB_FUNC( SX_SETCENTURY ) * --------------------------------------------------*/ HB_FUNC( SX_SETDATEFORMAT ) { - sx_SetDateFormat( hb_parni( 1 ) ); /* If True, the century digits will be returned. - * If False, they will not. */ + sx_SetDateFormat( hb_parni( 1 ) ); /* If True, the century digits will be returned. + * If False, they will not. */ } @@ -344,8 +334,8 @@ HB_FUNC( SX_SETDATEFORMAT ) * --------------------------------------------------*/ HB_FUNC( SX_SETMEMOBLOCKSIZE ) { - sx_SetMemoBlockSize( hb_parni( 1 ) ); /* The new default block size. - * The size must be a value from 1 through 1024. */ + sx_SetMemoBlockSize( hb_parni( 1 ) ); /* The new default block size. + * The size must be a value from 1 through 1024. */ } /* -----------------20/01/2002 13:33----------------- @@ -354,8 +344,7 @@ HB_FUNC( SX_SETMEMOBLOCKSIZE ) * --------------------------------------------------*/ HB_FUNC( SX_SETORDER ) { - hb_retni( - sx_SetOrder( hb_parni( 1 ) ) ); /* Selects an existing order as the controlling index order. */ + hb_retni( sx_SetOrder( hb_parni( 1 ) ) ); /* Selects an existing order as the controlling index order. */ } @@ -364,7 +353,7 @@ HB_FUNC( SX_SETORDER ) * --------------------------------------------------*/ HB_FUNC( SX_SETSOFTSEEK ) { - sx_SetSoftSeek( hb_parl( 1 ) ); /* True to set softseek ON */ + sx_SetSoftSeek( hb_parl( 1 ) ); /* True to set softseek ON */ } @@ -373,7 +362,7 @@ HB_FUNC( SX_SETSOFTSEEK ) * --------------------------------------------------*/ HB_FUNC( SX_SKIP ) { - sx_Skip( hb_parni( 1 ) ); /* Number of records to skip */ + sx_Skip( hb_parni( 1 ) ); /* Number of records to skip */ } @@ -383,16 +372,16 @@ HB_FUNC( SX_SKIP ) * --------------------------------------------------*/ HB_FUNC( SX_SYSPROP ) { - int i = hb_parni( 2 ); - hb_retni( - sx_SysProp( hb_parni( 1 ), /* One of the predefined constant values. See Apollo.ch */ - ( void * ) &i )); + int i = hb_parni( 2 ); + hb_retni( + sx_SysProp( hb_parni( 1 ), /* One of the predefined constant values. See Apollo.ch */ + ( void * ) &i )); } /* HB_FUNC( SX_DISABLEAUTOOPEN ) { - int i = 1; - sx_SysProp( 1013, ( void * ) &i ); + int i = 1; + sx_SysProp( 1013, ( void * ) &i ); } */ @@ -403,7 +392,7 @@ HB_FUNC( SX_DISABLEAUTOOPEN ) * --------------------------------------------------*/ HB_FUNC( SX_USE ) { - hb_retni( + hb_retni( sx_Use( ( PBYTE ) hb_parc( 1 ), /* Filename */ ( PBYTE ) hb_parc( 2 ), /* Alias */ hb_parni( 3 ), /* OpenMode */ @@ -416,8 +405,7 @@ HB_FUNC( SX_USE ) * --------------------------------------------------*/ HB_FUNC( SX_VERSION ) { - hb_retc( - ( char * ) sx_Version() ); + hb_retc( ( char * ) sx_Version() ); } @@ -426,7 +414,7 @@ HB_FUNC( SX_VERSION ) * --------------------------------------------------*/ HB_FUNC( SX_ZAP ) { - sx_Zap( ); + sx_Zap(); } diff --git a/harbour/contrib/hbcurl/hbcurl.c b/harbour/contrib/hbcurl/hbcurl.c index 5d508a663f..01206a2f36 100644 --- a/harbour/contrib/hbcurl/hbcurl.c +++ b/harbour/contrib/hbcurl/hbcurl.c @@ -379,56 +379,50 @@ static void hb_curl_buff_dl_free( PHB_CURL hb_curl ) static void PHB_CURL_free( PHB_CURL hb_curl, BOOL bFree ) { - if( hb_curl->curl ) + curl_easy_setopt( hb_curl->curl, CURLOPT_READFUNCTION, NULL ); + curl_easy_setopt( hb_curl->curl, CURLOPT_READDATA, NULL ); + curl_easy_setopt( hb_curl->curl, CURLOPT_WRITEFUNCTION, NULL ); + curl_easy_setopt( hb_curl->curl, CURLOPT_WRITEDATA, NULL ); + curl_easy_setopt( hb_curl->curl, CURLOPT_PROGRESSFUNCTION, NULL ); + curl_easy_setopt( hb_curl->curl, CURLOPT_PROGRESSDATA, NULL ); + + /* Some extra safety. Set these to NULL, before freeing their pointers. */ + curl_easy_setopt( hb_curl->curl, CURLOPT_HTTPPOST, NULL ); + curl_easy_setopt( hb_curl->curl, CURLOPT_HTTPHEADER, NULL ); + curl_easy_setopt( hb_curl->curl, CURLOPT_HTTP200ALIASES, NULL ); + curl_easy_setopt( hb_curl->curl, CURLOPT_QUOTE, NULL ); + curl_easy_setopt( hb_curl->curl, CURLOPT_POSTQUOTE, NULL ); + curl_easy_setopt( hb_curl->curl, CURLOPT_PREQUOTE, NULL ); + curl_easy_setopt( hb_curl->curl, CURLOPT_TELNETOPTIONS, NULL ); + + hb_curl_form_free( &hb_curl->pHTTPPOST_First ); + hb_curl_form_free( &hb_curl->pHTTPPOST_Last ); + hb_curl_slist_free( &hb_curl->pHTTPHEADER ); + hb_curl_slist_free( &hb_curl->pHTTP200ALIASES ); + hb_curl_slist_free( &hb_curl->pQUOTE ); + hb_curl_slist_free( &hb_curl->pPOSTQUOTE ); + hb_curl_slist_free( &hb_curl->pPREQUOTE ); + hb_curl_slist_free( &hb_curl->pTELNETOPTIONS ); + + hb_curl_file_ul_free( hb_curl ); + hb_curl_file_dl_free( hb_curl ); + + hb_curl_buff_ul_free( hb_curl ); + hb_curl_buff_dl_free( hb_curl ); + + if( hb_curl->pProgressBlock ) { - curl_easy_setopt( hb_curl->curl, CURLOPT_READFUNCTION, NULL ); - curl_easy_setopt( hb_curl->curl, CURLOPT_READDATA, NULL ); - curl_easy_setopt( hb_curl->curl, CURLOPT_WRITEFUNCTION, NULL ); - curl_easy_setopt( hb_curl->curl, CURLOPT_WRITEDATA, NULL ); - curl_easy_setopt( hb_curl->curl, CURLOPT_PROGRESSFUNCTION, NULL ); - curl_easy_setopt( hb_curl->curl, CURLOPT_PROGRESSDATA, NULL ); - - /* Some extra safety. Set these to NULL, before freeing their pointers. */ - curl_easy_setopt( hb_curl->curl, CURLOPT_HTTPPOST, NULL ); - curl_easy_setopt( hb_curl->curl, CURLOPT_HTTPHEADER, NULL ); - curl_easy_setopt( hb_curl->curl, CURLOPT_HTTP200ALIASES, NULL ); - curl_easy_setopt( hb_curl->curl, CURLOPT_QUOTE, NULL ); - curl_easy_setopt( hb_curl->curl, CURLOPT_POSTQUOTE, NULL ); - curl_easy_setopt( hb_curl->curl, CURLOPT_PREQUOTE, NULL ); - curl_easy_setopt( hb_curl->curl, CURLOPT_TELNETOPTIONS, NULL ); - - hb_curl_form_free( &hb_curl->pHTTPPOST_First ); - hb_curl_form_free( &hb_curl->pHTTPPOST_Last ); - hb_curl_slist_free( &hb_curl->pHTTPHEADER ); - hb_curl_slist_free( &hb_curl->pHTTP200ALIASES ); - hb_curl_slist_free( &hb_curl->pQUOTE ); - hb_curl_slist_free( &hb_curl->pPOSTQUOTE ); - hb_curl_slist_free( &hb_curl->pPREQUOTE ); - hb_curl_slist_free( &hb_curl->pTELNETOPTIONS ); - - hb_curl_file_ul_free( hb_curl ); - hb_curl_file_dl_free( hb_curl ); - - hb_curl_buff_ul_free( hb_curl ); - hb_curl_buff_dl_free( hb_curl ); - - if( hb_curl->pProgressBlock ) - { - hb_itemRelease( hb_curl->pProgressBlock ); - hb_curl->pProgressBlock = NULL; - } - - if( bFree ) - { - curl_easy_cleanup( hb_curl->curl ); - hb_curl->curl = NULL; - } - else - curl_easy_reset( hb_curl->curl ); + hb_itemRelease( hb_curl->pProgressBlock ); + hb_curl->pProgressBlock = NULL; } if( bFree ) + { + curl_easy_cleanup( hb_curl->curl ); hb_xfree( hb_curl ); + } + else + curl_easy_reset( hb_curl->curl ); } /* NOTE: Will create a new one. If 'from' is specified, the new one @@ -1347,7 +1341,7 @@ HB_FUNC( CURL_EASY_DL_BUFF_GET ) #define HB_CURL_INFO_TYPE_SLIST 5 #define HB_CURL_EASY_GETINFO( hb_curl, n, p ) \ - ( ( hb_curl && hb_curl->curl ) ? curl_easy_getinfo( hb_curl->curl, n, p ) : ( CURLcode ) HB_CURLE_ERROR ) + ( hb_curl ? curl_easy_getinfo( hb_curl->curl, n, p ) : ( CURLcode ) HB_CURLE_ERROR ) /* NOTE: curl_easy_getinfo( curl, x, @nError ) -> xValue */ HB_FUNC( CURL_EASY_GETINFO ) diff --git a/harbour/contrib/hbfbird/firebird.c b/harbour/contrib/hbfbird/firebird.c index 381ba06887..0d7a407342 100644 --- a/harbour/contrib/hbfbird/firebird.c +++ b/harbour/contrib/hbfbird/firebird.c @@ -53,8 +53,6 @@ */ #include -#include -#include #include #define HB_OS_WIN_32_USED @@ -69,661 +67,600 @@ #define MAX_LEN 256 #define MAX_BUFFER 1024 -#define ERREXIT(status) { hb_retnl(isc_sqlcode(status)); return; } +#define ERREXIT( status ) { hb_retnl( isc_sqlcode( status ) ); return; } #ifndef ISC_INT64_FORMAT - -#if (defined(_MSC_VER) && defined(WIN32)) || (defined(__BORLANDC__) && defined(__WIN32__)) -#define ISC_INT64_FORMAT "I64" -#else -#define ISC_INT64_FORMAT "ll" -#endif + #if (defined(_MSC_VER) && defined(WIN32)) || (defined(__BORLANDC__) && defined(__WIN32__)) + #define ISC_INT64_FORMAT "I64" + #else + #define ISC_INT64_FORMAT "ll" + #endif #endif -HB_FUNC(FBCREATEDB) +HB_FUNC( FBCREATEDB ) { - isc_db_handle newdb = NULL; - isc_tr_handle trans = NULL; - long status[ 20 ]; - char create_db[ MAX_BUFFER ]; + if( hb_pcount() == 6 ) + { + isc_db_handle newdb = NULL; + isc_tr_handle trans = NULL; + ISC_STATUS status[ 20 ]; + char create_db[ MAX_BUFFER ]; - char *db_name; - char *user; - char *pass; - char *charset; - int page; - int dialect; + char * db_name = hb_parcx( 1 ); + char * user = hb_parcx( 2 ); + char * pass = hb_parcx( 3 ); + int page = hb_parni( 4 ); + char * charset = hb_parcx( 5 ); + int dialect = hb_parni( 6 ); + + snprintf( create_db, sizeof( create_db ), + "CREATE DATABASE '%s' USER '%s' PASSWORD '%s' PAGE_SIZE = %i DEFAULT CHARACTER SET %s", + db_name, user, pass, page, charset ); + + if( isc_dsql_execute_immediate( status, &newdb, &trans, 0, create_db, dialect, NULL ) ) + hb_retnl( isc_sqlcode( status ) ); + else + hb_retnl( 1 ); + } + else + hb_retnl( 0 ); +} - if (hb_pcount() != 6) - { - hb_retni(0); - return; - } +HB_FUNC( FBCONNECT ) +{ + ISC_STATUS status[ MAX_FIELDS ]; + isc_db_handle db = NULL; + char * db_connect = hb_parcx( 1 ); + char * user = hb_parcx( 2 ); + char * passwd = hb_parcx( 3 ); + char dpb[ 128 ]; + int i = 0; + int len; - db_name = hb_parcx(1); - user = hb_parcx(2); - pass = hb_parcx(3); - page = hb_parni(4); - charset = hb_parcx(5); - dialect = hb_parni(6); + /* TOFIX: Possible buffer overflow. Use snprintf(). */ + dpb[ i++ ] = isc_dpb_version1; + dpb[ i++ ] = isc_dpb_user_name; + len = strlen( user ); + dpb[ i++ ] = ( char ) len; + strncpy( &( dpb[ i ] ), user, len ); + i += len; + dpb[ i++ ] = isc_dpb_password; + len = strlen( passwd ); + dpb[ i++ ] = len; + strncpy( &( dpb[ i ] ), passwd, len ); + i += len; - snprintf(create_db, sizeof( create_db ), - "CREATE DATABASE '%s' USER '%s' PASSWORD '%s' PAGE_SIZE = %i DEFAULT CHARACTER SET %s", - db_name, user, pass, page, charset ); - - if (isc_dsql_execute_immediate(status, &newdb, &trans, 0, create_db, dialect, NULL)) - ERREXIT(status); - - hb_retni(1); + if( isc_attach_database( status, 0, db_connect, &db, i, dpb ) ) + hb_retnl( isc_sqlcode( status ) ); + else + hb_retptr( ( void * ) db ); } -HB_FUNC(FBCONNECT) +HB_FUNC( FBCLOSE ) { - ISC_STATUS status[MAX_FIELDS]; - isc_db_handle db = NULL; - char *db_connect = NULL; - char *user = NULL; - char *passwd = NULL; - char dpb[128]; - int i = 0, len; + isc_db_handle db = ( isc_db_handle ) hb_parptr( 1 ); + ISC_STATUS status[ 20 ]; - PHB_ITEM db_handle; - - if (hb_parinfo(1)) - db_connect = hb_parcx(1); - - if (hb_parinfo(2)) - user = hb_parcx(2); - - if (hb_parinfo(3)) - passwd = hb_parcx(3); - - dpb[i++] = isc_dpb_version1; - - dpb[i++] = isc_dpb_user_name; - len = strlen(user); - dpb[i++] = (char) len; - strncpy(&(dpb[i]), user, len); - i += len; - - dpb[i++] = isc_dpb_password; - len = strlen (passwd); - dpb[i++] = len; - strncpy(&(dpb[i]), passwd, len); - i += len; - - if ( isc_attach_database ( status, 0, db_connect, &db, i, dpb ) ) - ERREXIT(status); - - db_handle = hb_itemPutPtr( NULL, ( void * ) db ); - hb_itemReturnRelease(db_handle); + if( isc_detach_database( status, &db ) ) + hb_retnl( isc_sqlcode( status ) ); + else + hb_retnl( 1 ); } -HB_FUNC(FBCLOSE) +HB_FUNC( FBERROR ) { - isc_db_handle db = NULL; - long status[20]; + char msg[ MAX_BUFFER ]; - db = ( isc_db_handle ) hb_itemGetPtr( hb_param( 1, HB_IT_POINTER ) ); + isc_sql_interprete( hb_parni( 1 ) /* sqlcode */, + msg, + sizeof( msg ) ); - if ( isc_detach_database ( status, &db ) ) - ERREXIT(status); - - hb_retnl(1); + hb_retc( msg ); } - -HB_FUNC(FBERROR) +HB_FUNC( FBSTARTTRANSACTION ) { - int sqlcode; - char msg[MAX_BUFFER]; + isc_db_handle db = ( isc_db_handle ) hb_parptr( 1 ); + isc_tr_handle trans = NULL; + ISC_STATUS status[ MAX_FIELDS ]; - sqlcode = hb_parni(1); - - isc_sql_interprete(sqlcode, msg, 512); - - hb_retc(msg); + if( isc_start_transaction( status, &trans, 1, &db, 0, NULL ) ) + hb_retnl( isc_sqlcode( status ) ); + else + hb_retptr( ( void * ) trans ); } -HB_FUNC(FBSTARTTRANSACTION) +HB_FUNC( FBCOMMIT ) { - isc_db_handle db = NULL; - isc_tr_handle trans = NULL; - long status[MAX_FIELDS]; + isc_tr_handle trans = ( isc_db_handle ) hb_parptr( 1 ); + ISC_STATUS status[ MAX_FIELDS ]; - PHB_ITEM var; - - db = ( isc_db_handle ) hb_itemGetPtr( hb_param( 1, HB_IT_POINTER ) ); - - if (isc_start_transaction(status, &trans, 1, &db, 0, NULL)) - ERREXIT(status); - - var = hb_itemPutPtr( NULL, ( void * ) trans ); - hb_itemReturnRelease(var); + if( isc_commit_transaction( status, &trans ) ) + hb_retnl( isc_sqlcode( status ) ); + else + hb_retnl( 1 ); } - -HB_FUNC(FBCOMMIT) +HB_FUNC( FBROLLBACK ) { - isc_tr_handle trans = NULL; - long status[MAX_FIELDS]; + isc_tr_handle trans = ( isc_db_handle ) hb_parptr( 1 ); + ISC_STATUS status[ MAX_FIELDS ]; - trans = ( isc_db_handle ) hb_itemGetPtr( hb_param( 1, HB_IT_POINTER ) ); - - if (isc_commit_transaction(status, &trans)) - ERREXIT(status); - - trans = NULL; - hb_retnl(1); + if( isc_rollback_transaction( status, &trans ) ) + hb_retnl( isc_sqlcode( status ) ); + else + hb_retnl( 1 ); } -HB_FUNC(FBROLLBACK) +HB_FUNC( FBEXECUTE ) { - isc_tr_handle trans = NULL; - long status[MAX_FIELDS]; + isc_db_handle db = ( isc_db_handle ) hb_parptr( 1 ); + isc_tr_handle trans = NULL; + char * exec_str = hb_parcx( 2 ); + ISC_STATUS status[ 20 ]; + ISC_STATUS status_rollback[ 20 ]; + int dialect = hb_parni( 3 ); - trans = ( isc_db_handle ) hb_itemGetPtr( hb_param( 1, HB_IT_POINTER ) ); + if( ISPOINTER( 4 ) ) + { + trans = ( isc_tr_handle ) hb_parptr( 4 ); + } + else + { + if( isc_start_transaction( status, &trans, 1, &db, 0, NULL ) ) + { + hb_retnl( isc_sqlcode( status ) ); + return; + } + } - if (isc_rollback_transaction(status, &trans)) - ERREXIT(status); + if( isc_dsql_execute_immediate( status, &db, &trans, 0, exec_str, dialect, NULL ) ) + { + if( ! ISPOINTER( 4 ) ) + isc_rollback_transaction( status_rollback, &trans ); - trans = NULL; - hb_retnl(1); + hb_retnl( isc_sqlcode( status ) ); + return; + } + + if( ! ISPOINTER( 4 ) ) + { + if( isc_commit_transaction( status, &trans ) ) + { + hb_retnl( isc_sqlcode( status ) ); + return; + } + } + + hb_retnl( 1 ); } - -HB_FUNC(FBEXECUTE) +HB_FUNC( FBQUERY ) { - isc_db_handle db = NULL; - isc_tr_handle trans = NULL; - char *exec_str; - long status[20]; - long status_rollback[20]; - int dialect; + isc_db_handle db = ( isc_db_handle ) hb_parptr( 1 ); + isc_tr_handle trans = NULL; + ISC_STATUS status[ MAX_FIELDS ]; + XSQLDA * sqlda; + isc_stmt_handle stmt = NULL; + XSQLVAR * var; - db = ( isc_db_handle ) hb_itemGetPtr( hb_param( 1, HB_IT_POINTER ) ); - exec_str = hb_parcx(2); - dialect = hb_parni(3); + char sel_str[ MAX_LEN ]; + int dialect = ISNUM( 3 ) ? hb_parni( 3 ) : DIALECT; + int n; + int i; + int dtype; + int num_cols; - if (hb_parinfo(4)) { - trans = (isc_tr_handle) hb_itemGetPtr( hb_param( 4, HB_IT_POINTER ) ); - } else { - if ( isc_start_transaction ( status, &trans, 1, &db, 0, NULL ) ) - ERREXIT(status); - } + PHB_ITEM qry_handle; + PHB_ITEM aTemp; + PHB_ITEM aNew; - if (isc_dsql_execute_immediate(status, &db, &trans, 0, exec_str, dialect, NULL)) { - if (! hb_parinfo(4)) - isc_rollback_transaction ( status_rollback, &trans ); + strncpy( sel_str, hb_parcx( 2 ), sizeof( sel_str ) ); - ERREXIT(status); - } + if( ISPOINTER( 4 ) ) + { + trans = ( isc_tr_handle ) hb_parptr( 4 ); + } + else if( isc_start_transaction( status, &trans, 1, &db, 0, NULL ) ) + { + ERREXIT( status ); + } - if (!hb_parinfo(4)) - if ( isc_commit_transaction ( status, &trans ) ) - ERREXIT(status); + /* Allocate an output SQLDA. Just to check number of columns */ + sqlda = ( XSQLDA * ) hb_xgrab( XSQLDA_LENGTH ( 1 ) ); + sqlda->sqln = 1; + sqlda->version = 1; - hb_retnl(1); + /* Allocate a statement */ + if( isc_dsql_allocate_statement( status, &db, &stmt ) ) + { + ERREXIT( status ); + } + + /* Prepare the statement. */ + if( isc_dsql_prepare( status, &trans, &stmt, 0, sel_str, dialect, sqlda ) ) + { + ERREXIT( status ); + } + + /* Describe sql contents */ + if( isc_dsql_describe( status, &stmt, dialect, sqlda ) ) + { + ERREXIT( status ); + } + + num_cols = sqlda->sqld; + aNew = hb_itemArrayNew( num_cols ); + + /* Relocate necessary number of columns */ + if( sqlda->sqld > sqlda->sqln ) + { + hb_xfree( sqlda ); + n = sqlda->sqld; + sqlda = ( XSQLDA * ) hb_xgrab( XSQLDA_LENGTH( n ) ); + sqlda->sqln = n; + sqlda->version = 1; + + if( isc_dsql_describe( status, &stmt, dialect, sqlda ) ) + { + ERREXIT( status ); + } + } + + for( i = 0, var = sqlda->sqlvar; i < sqlda->sqld; i++, var++ ) + { + dtype = ( var->sqltype & ~1 ); + switch( dtype ) + { + case SQL_VARYING: + var->sqltype = SQL_TEXT; + var->sqldata = ( char * ) hb_xgrab( sizeof ( char ) * var->sqllen + 2 ); + break; + case SQL_TEXT: + var->sqldata = ( char * ) hb_xgrab( sizeof ( char ) * var->sqllen + 2 ); + break; + case SQL_LONG: + var->sqltype = SQL_LONG; + var->sqldata = ( char * ) hb_xgrab( sizeof ( long ) ); + break; + default: + var->sqldata = ( char * ) hb_xgrab( sizeof ( char ) * var->sqllen ); + break; + } + + if( var->sqltype & 1 ) + var->sqlind = ( short * ) hb_xgrab( sizeof ( short ) ); + + aTemp = hb_itemArrayNew( 5 ); + + hb_arraySetC( aTemp, 1, sqlda->sqlvar[ i ].sqlname ); + hb_arraySetNL( aTemp, 2, ( long ) dtype ); + hb_arraySetNL( aTemp, 3, sqlda->sqlvar[ i ].sqllen ); + hb_arraySetNL( aTemp, 4, sqlda->sqlvar[ i ].sqlscale ); + hb_arraySetC( aTemp, 5, sqlda->sqlvar[ i ].relname ); + + hb_itemArrayPut( aNew, i+1, aTemp ); + + hb_itemRelease( aTemp ); + } + + if( ! sqlda->sqld ) + { + /* Execute and commit non-select querys */ + if( isc_dsql_execute( status, &trans, &stmt, dialect, NULL ) ) + { + ERREXIT( status ); + } + } + else + { + if( isc_dsql_execute( status, &trans, &stmt, dialect, sqlda ) ) + { + ERREXIT( status ); + } + } + + qry_handle = hb_itemArrayNew( 6 ); + + hb_arraySetPtr( qry_handle, 1, ( void * ) stmt ); + hb_arraySetPtr( qry_handle, 2, ( void * ) sqlda ); + + if( ! ISPOINTER( 4 ) ) + hb_arraySetPtr( qry_handle, 3, ( void * ) trans ); + + hb_arraySetNL( qry_handle, 4, ( long ) num_cols ); + hb_arraySetNL( qry_handle, 5, ( long ) dialect ); + hb_arraySet( qry_handle, 6, aNew ); + + hb_itemReturnRelease( qry_handle ); + hb_itemRelease( aNew ); } -HB_FUNC(FBQUERY) +HB_FUNC( FBFETCH ) { - isc_db_handle db = NULL; - isc_tr_handle trans = NULL; - ISC_STATUS status[MAX_FIELDS]; - XSQLDA ISC_FAR * sqlda; - isc_stmt_handle stmt = NULL; - XSQLVAR *var; + if( ISARRAY( 1 ) ) + { + PHB_ITEM aParam = hb_param( 1, HB_IT_ARRAY ); - char sel_str[MAX_LEN]; - int dialect; - int n, i, dtype; - int num_cols; + isc_stmt_handle stmt = ( isc_stmt_handle ) hb_itemGetPtr( hb_itemArrayGet( aParam, 1 ) ); + ISC_STATUS status[ MAX_FIELDS ]; + XSQLDA * sqlda = ( XSQLDA * ) hb_itemGetPtr( hb_itemArrayGet( aParam, 2 ) ); + int dialect = hb_itemGetNI( hb_itemArrayGet( aParam, 5 ) ); + long fetch_stat; - PHB_ITEM qry_handle; - PHB_ITEM temp; - PHB_ITEM aTemp; - PHB_ITEM aNew; + /* TOFIX */ + fetch_stat = isc_dsql_fetch( status, &stmt, dialect, sqlda ); - PHB_ITEM itemSqlname; - PHB_ITEM itemSqltype; - PHB_ITEM itemSqllen ; - PHB_ITEM itemSqlscale; - PHB_ITEM itemRelname; + if( fetch_stat != 100L ) + { + ERREXIT( status ); + } + } - db = ( isc_db_handle ) hb_itemGetPtr( hb_param( 1, HB_IT_POINTER ) ); - strcpy(sel_str, hb_parcx(2)); - - if (hb_parinfo(3)) { - dialect = hb_parni(3); - } else { - dialect = DIALECT; - } - - if (hb_parinfo(4)) { - trans = (isc_tr_handle) hb_itemGetPtr( hb_param( 4, HB_IT_POINTER ) ); - - } else if ( isc_start_transaction ( status, &trans, 1, &db, 0, NULL ) ) - ERREXIT(status); - - // Allocate an output SQLDA. Just to check number of columns - sqlda = ( XSQLDA * ) hb_xgrab( XSQLDA_LENGTH ( 1 ) ); - sqlda->sqln = 1; - sqlda->version = 1; - - // Allocate a statement - if (isc_dsql_allocate_statement(status, &db, &stmt)) - ERREXIT(status); - - // Prepare the statement. - if (isc_dsql_prepare(status, &trans, &stmt, 0, sel_str, dialect, sqlda)) - ERREXIT(status); - - // Describe sql contents - if (isc_dsql_describe(status, &stmt, dialect, sqlda)) - ERREXIT(status); - - num_cols = sqlda->sqld; - aNew = hb_itemArrayNew( num_cols ); - - // Relocate necessary number of columns - if ( sqlda->sqld > sqlda->sqln ) { - hb_xfree( sqlda ); - n = sqlda->sqld; - sqlda = ( XSQLDA * ) hb_xgrab( XSQLDA_LENGTH ( n ) ); - sqlda->sqln = n; - sqlda->version = 1; - - if (isc_dsql_describe(status, &stmt, dialect, sqlda)) - ERREXIT(status); - } - - for ( i = 0, var = sqlda->sqlvar; i < sqlda->sqld; i++, var++ ) { - dtype = ( var->sqltype & ~1 ); - switch ( dtype ) { - case SQL_VARYING: - var->sqltype = SQL_TEXT; - var->sqldata = ( char * ) hb_xgrab( sizeof ( char ) * var->sqllen + 2 ); - break; - case SQL_TEXT: - var->sqldata = ( char * ) hb_xgrab( sizeof ( char ) * var->sqllen + 2 ); - break; - case SQL_LONG: - var->sqltype = SQL_LONG; - var->sqldata = ( char * ) hb_xgrab( sizeof ( long ) ); - break; - default: - var->sqldata = ( char * ) hb_xgrab( sizeof ( char ) * var->sqllen ); - break; - } - if ( var->sqltype & 1 ) { - var->sqlind = ( short * ) hb_xgrab( sizeof ( short ) ); - } - - aTemp = hb_itemArrayNew( 5 ); - - itemSqlname = hb_itemPutC( NULL, sqlda->sqlvar[i].sqlname ); - hb_itemArrayPut( aTemp, 1, itemSqlname ); - - itemSqltype = hb_itemPutNL( NULL, (long)dtype ); - hb_itemArrayPut( aTemp, 2, itemSqltype ); - - itemSqllen = hb_itemPutNL( NULL, sqlda->sqlvar[i].sqllen ); - hb_itemArrayPut( aTemp, 3, itemSqllen ); - - itemSqlscale = hb_itemPutNL( NULL, sqlda->sqlvar[i].sqlscale ); - hb_itemArrayPut( aTemp, 4, itemSqlscale ); - - itemRelname = hb_itemPutC( NULL, sqlda->sqlvar[i].relname ); - hb_itemArrayPut( aTemp, 5, itemRelname ); - - hb_itemRelease( itemSqlname ); - hb_itemRelease( itemSqltype ); - hb_itemRelease( itemSqllen ); - hb_itemRelease( itemSqlscale ); - hb_itemRelease( itemRelname ); - - hb_itemArrayPut( aNew, i+1, aTemp ); - hb_itemRelease( aTemp ); - } - - if ( !sqlda->sqld ) { - // Execute and commit non-select querys - if ( isc_dsql_execute ( status, &trans, &stmt, dialect, NULL ) ) - ERREXIT(status); - - } else { - if ( isc_dsql_execute ( status, &trans, &stmt, dialect, sqlda ) ) - ERREXIT(status); - } - - qry_handle = hb_itemArrayNew(6); - - temp = hb_itemPutPtr( NULL, ( void * ) stmt ); - hb_arraySet(qry_handle, 1, temp); - hb_itemRelease(temp); - - temp = hb_itemPutPtr( NULL, ( void * ) sqlda ); - hb_arraySet(qry_handle, 2, temp); - hb_itemRelease(temp); - - if (! hb_parinfo(4)) - { - temp = hb_itemPutPtr( NULL, ( void * ) trans ); - hb_arraySet(qry_handle, 3, temp); - hb_itemRelease(temp); - } - - temp = hb_itemPutNL(NULL, (long) num_cols); - hb_arraySet(qry_handle, 4, temp); - hb_itemRelease(temp); - - temp = hb_itemPutNL(NULL, (long) dialect); - hb_arraySet(qry_handle, 5, temp); - hb_itemRelease(temp); - - hb_arraySet(qry_handle, 6, aNew); - - hb_itemReturnRelease(qry_handle); - hb_itemRelease(aNew); + hb_retnl( 0 ); } - -HB_FUNC(FBFETCH) +HB_FUNC( FBFREE ) { - isc_stmt_handle stmt = NULL; - ISC_STATUS status[MAX_FIELDS]; - XSQLDA ISC_FAR * sqlda; - long fetch_stat; - int dialect; + if( ISARRAY( 1 ) ) + { + PHB_ITEM aParam = hb_param( 1, HB_IT_ARRAY ); - PHB_ITEM aParam; + isc_stmt_handle stmt = ( isc_stmt_handle ) hb_itemGetPtr( hb_itemArrayGet( aParam, 1 ) ); + XSQLDA * sqlda = ( XSQLDA * ) hb_itemGetPtr( hb_itemArrayGet( aParam, 2 ) ); + isc_tr_handle trans = ( isc_tr_handle ) hb_itemGetPtr( hb_itemArrayGet( aParam, 3 ) ); + ISC_STATUS status[ MAX_FIELDS ]; - if (ISARRAY( 1 ) ) - { - aParam = hb_param(1,HB_IT_ARRAY); + if( isc_dsql_free_statement( status, &stmt, DSQL_drop ) ) + { + ERREXIT( status ); + } - stmt = ( isc_stmt_handle ) hb_itemGetPtr(hb_itemArrayGet( aParam, 1 )); - sqlda = ( XSQLDA ISC_FAR * ) hb_itemGetPtr(hb_itemArrayGet( aParam, 2 )); - dialect = hb_itemGetNI(hb_itemArrayGet( aParam, 5 )); + if( trans ) + { + if( isc_commit_transaction( status, &trans ) ) + { + ERREXIT( status ); + } + } - fetch_stat = isc_dsql_fetch(status, &stmt, dialect, sqlda); + /* TOFIX: Freeing pointer received as parameter? We should at least set the item NULL. */ + if( sqlda ) + hb_xfree( sqlda ); - if (fetch_stat != 100L) - ERREXIT(status); - - } - hb_retnl(fetch_stat); + hb_retnl( 1 ); + } + else + hb_retnl( 0 ); } - -HB_FUNC(FBFREE) +HB_FUNC( FBGETDATA ) { - isc_stmt_handle stmt = NULL; - isc_tr_handle trans = NULL; - ISC_STATUS status[MAX_FIELDS]; - XSQLDA ISC_FAR * sqlda; + PHB_ITEM aParam = hb_param( 1, HB_IT_ARRAY ); - PHB_ITEM aParam; + int pos = hb_parni( 2 ) - 1; + short dtype; + char data[ MAX_BUFFER ]; + char date_s[ 25 ]; - if (ISARRAY( 1 ) ) - { - aParam = hb_param(1,HB_IT_ARRAY); + struct tm times; + XSQLVAR * var; + XSQLDA * sqlda = ( XSQLDA * ) hb_itemGetPtr( hb_itemArrayGet( aParam, 2 ) ); + ISC_STATUS status[ MAX_FIELDS ]; + ISC_QUAD * blob_id; - stmt = ( isc_stmt_handle ) hb_itemGetPtr(hb_itemArrayGet( aParam, 1 )); - sqlda = ( XSQLDA ISC_FAR * ) hb_itemGetPtr(hb_itemArrayGet( aParam, 2 )); - trans = ( isc_tr_handle ) hb_itemGetPtr( hb_itemArrayGet( aParam, 3 )); + if( ( pos + 1 ) > sqlda->sqln ) + { + ERREXIT( status ); + } - if (isc_dsql_free_statement(status, &stmt, DSQL_drop)) - ERREXIT(status); + var = sqlda->sqlvar + pos; + dtype = var->sqltype & ~1; - if (trans) - if (isc_commit_transaction(status, &trans)) - ERREXIT(status); + if( ( var->sqltype & 1 ) && ( *var->sqlind < 0 ) ) + { + /* null field */ + hb_ret(); + } + else + { + switch( dtype ) + { + case SQL_TEXT: + case SQL_VARYING: + hb_retclen( var->sqldata, var->sqllen ); + break; - if ( sqlda ) - hb_xfree( sqlda ); + case SQL_TIMESTAMP: + isc_decode_timestamp ( ( ISC_TIMESTAMP * ) var->sqldata, × ); + snprintf( date_s, sizeof( date_s ), "%04d-%02d-%02d %02d:%02d:%02d.%04lu", + times.tm_year + 1900, + times.tm_mon + 1, + times.tm_mday, + times.tm_hour, + times.tm_min, + times.tm_sec, + ( ( ISC_TIMESTAMP * ) var->sqldata )->timestamp_time % 10000 ); + snprintf( data, sizeof( data ), "%*s ", 24, date_s ); - hb_retnl(1); - } - else - hb_retnl(0); + hb_retc( data ); + break; + case SQL_TYPE_DATE: + isc_decode_sql_date( ( ISC_DATE * ) var->sqldata, × ); + snprintf( date_s, sizeof( date_s ), "%04d-%02d-%02d", times.tm_year + 1900, times.tm_mon + 1, times.tm_mday ); + snprintf( data, sizeof( data ), "%*s ", 8, date_s ); + + hb_retc( data ); + break; + + case SQL_TYPE_TIME: + isc_decode_sql_time ( ( ISC_TIME * ) var->sqldata, × ); + snprintf( date_s, sizeof( date_s ), "%02d:%02d:%02d.%04lu", + times.tm_hour, + times.tm_min, + times.tm_sec, ( *( ( ISC_TIME * ) var->sqldata ) ) % 10000 ); + snprintf( data, sizeof( data ), "%*s ", 13, date_s ); + + hb_retc( data ); + break; + + case SQL_BLOB: + blob_id = ( ISC_QUAD * ) var->sqldata; + hb_retptr( ( void * ) blob_id ); + break; + + case SQL_SHORT: + case SQL_LONG: + case SQL_INT64: + { + ISC_INT64 value; + short field_width; + short dscale; + + switch( dtype ) + { + case SQL_SHORT: + value = ( ISC_INT64 ) *( short * ) var->sqldata; + field_width = 6; + break; + + case SQL_LONG: + value = ( ISC_INT64 ) *( long * ) var->sqldata; + field_width = 11; + break; + + case SQL_INT64: + value = ( ISC_INT64 ) *( ISC_INT64 * ) var->sqldata; + field_width = 21; + break; + } + + dscale = var->sqlscale; + + if( dscale < 0 ) + { + ISC_INT64 tens = 1; + short i; + + for( i = 0; i > dscale; i-- ) + tens *= 10; + + if( value >= 0 ) + snprintf( data, sizeof( data ), "%*" ISC_INT64_FORMAT "d.%0*" ISC_INT64_FORMAT "d", + field_width - 1 + dscale, + ( ISC_INT64 ) value / tens, + -dscale, + ( ISC_INT64 ) value % tens); + else if( ( value / tens ) != 0 ) + snprintf( data, sizeof( data ), "%*" ISC_INT64_FORMAT "d.%0*" ISC_INT64_FORMAT "d", + field_width - 1 + dscale, + ( ISC_INT64 ) ( value / tens ), + -dscale, + ( ISC_INT64 ) -( value % tens ) ); + else + snprintf( data, sizeof( data ), "%*s.%0*" ISC_INT64_FORMAT "d", + field_width - 1 + dscale, + "-0", + -dscale, + ( ISC_INT64 ) -( value % tens ) ); + } + else if( dscale ) + snprintf( data, sizeof( data ), "%*" ISC_INT64_FORMAT "d%0*d", field_width, ( ISC_INT64 ) value, dscale, 0 ); + else + snprintf( data, sizeof( data ), "%*" ISC_INT64_FORMAT "d", field_width, ( ISC_INT64 ) value ); + } + + hb_retc( data ); + break; + + case SQL_FLOAT: + snprintf( data, sizeof( data ), "%15g ", *( float * ) ( var->sqldata ) ); + hb_retc( data ); + break; + + case SQL_DOUBLE: + snprintf( data, sizeof( data ), "%24f ", *( double * ) ( var->sqldata ) ); + hb_retc( data ); + break; + + default: + hb_ret(); + break; + } + } } - -HB_FUNC(FBGETDATA) +HB_FUNC( FBGETBLOB ) { - int pos; - short dtype; - char data[MAX_BUFFER], *p; - char date_s[25]; + ISC_STATUS status[ MAX_FIELDS ]; + isc_db_handle db = ( isc_db_handle ) hb_parptr( 1 ); + isc_tr_handle trans = NULL; + isc_blob_handle blob_handle = NULL; + short blob_seg_len; + char blob_segment[ 512 ]; + ISC_QUAD * blob_id = ( ISC_QUAD * ) hb_parptr( 2 ); + char p[ MAX_BUFFER ]; + long blob_stat; - struct tm times; - XSQLVAR *var; - XSQLDA ISC_FAR * sqlda; - ISC_STATUS status[MAX_FIELDS]; - ISC_QUAD *blob_id; + PHB_ITEM temp; + PHB_ITEM aNew; - PHB_ITEM aParam; - PHB_ITEM temp; + if( ISPOINTER( 3 ) ) + { + trans = ( isc_tr_handle ) hb_parptr( 3 ); + } + else + { + if( isc_start_transaction( status, &trans, 1, &db, 0, NULL ) ) + { + ERREXIT( status ); + } + } - aParam = hb_param(1,HB_IT_ARRAY); + if( isc_open_blob2( status, &db, &trans, &blob_handle, blob_id, 0, NULL ) ) + { + ERREXIT( status ); + } - sqlda = ( XSQLDA ISC_FAR * ) hb_itemGetPtr(hb_itemArrayGet( aParam, 2 )); - pos = (int) hb_parnl(2); + /* Get blob segments and their lengths and print each segment. */ + blob_stat = isc_get_segment( status, &blob_handle, + ( unsigned short * ) &blob_seg_len, + sizeof( blob_segment ), blob_segment ); - pos--; + if( blob_stat == 0 || status[ 1 ] == isc_segment ) + aNew = hb_itemArrayNew( 0 ); - if ( ( pos + 1 ) > sqlda->sqln ) - ERREXIT(status); + while( blob_stat == 0 || status[ 1 ] == isc_segment ) + { + /* p = ( char * ) hb_xgrab( blob_seg_len + 1 ); */ + snprintf( p, sizeof( p ), "%*.*s", blob_seg_len, blob_seg_len, blob_segment ); - var = sqlda->sqlvar; + temp = hb_itemPutC( NULL, p ); + hb_arrayAdd( aNew, temp ); + hb_itemRelease( temp ); - var += pos; + /* hb_xfree(p); */ + blob_stat = isc_get_segment( status, &blob_handle, + ( unsigned short * ) &blob_seg_len, + sizeof( blob_segment ), blob_segment ); + } - dtype = var->sqltype & ~1; - p = data; + if( isc_close_blob( status, &blob_handle ) ) + { + hb_itemRelease( aNew ); + ERREXIT( status ); + } - if ( ( var->sqltype & 1 ) && ( *var->sqlind < 0 ) ) { - /* null field */ - hb_ret(); + if( ! ISPOINTER( 3 ) ) + { + if( isc_commit_transaction( status, &trans ) ) + { + ERREXIT( status ); + } + } - } else { - switch ( dtype ) { - case SQL_TEXT: - case SQL_VARYING: - hb_retclen( var->sqldata, var->sqllen ); - break; - - case SQL_TIMESTAMP: - isc_decode_timestamp ( ( ISC_TIMESTAMP ISC_FAR * ) var->sqldata, × ); - snprintf( date_s, sizeof( date_s ), "%04d-%02d-%02d %02d:%02d:%02d.%04lu", - times.tm_year + 1900, - times.tm_mon + 1, - times.tm_mday, - times.tm_hour, - times.tm_min, - times.tm_sec, - ( ( ISC_TIMESTAMP * ) var->sqldata )->timestamp_time % 10000 ); - snprintf( p, sizeof( data ), "%*s ", 24, date_s ); - - hb_retc(p); - break; - - case SQL_TYPE_DATE: - isc_decode_sql_date ( ( ISC_DATE ISC_FAR * ) var->sqldata, × ); - snprintf( date_s, sizeof( date_s ), "%04d-%02d-%02d", times.tm_year + 1900, times.tm_mon + 1, times.tm_mday ); - snprintf( p, sizeof( data ), "%*s ", 8, date_s ); - - hb_retc(p); - break; - - case SQL_TYPE_TIME: - isc_decode_sql_time ( ( ISC_TIME ISC_FAR * ) var->sqldata, × ); - snprintf( date_s, sizeof( date_s ), "%02d:%02d:%02d.%04lu", - times.tm_hour, - times.tm_min, - times.tm_sec, ( *( ( ISC_TIME * ) var->sqldata ) ) % 10000 ); - snprintf( p, sizeof( data ), "%*s ", 13, date_s ); - - hb_retc(p); - break; - - case SQL_BLOB: - - blob_id = ( ISC_QUAD * ) var->sqldata; - - temp = hb_itemPutPtr( NULL, ( void * ) blob_id ); - hb_itemReturnRelease(temp); - - break; - - case SQL_SHORT: - case SQL_LONG: - case SQL_INT64: - { - ISC_INT64 value; - short field_width; - short dscale; - switch (dtype) - { - case SQL_SHORT: - value = (ISC_INT64) *(short ISC_FAR *) var->sqldata; - field_width = 6; - break; - - case SQL_LONG: - value = (ISC_INT64) *(long ISC_FAR *) var->sqldata; - field_width = 11; - break; - - case SQL_INT64: - value = (ISC_INT64) *(ISC_INT64 ISC_FAR *) var->sqldata; - field_width = 21; - break; - } - - dscale = var->sqlscale; - - if (dscale < 0) - { - ISC_INT64 tens; - short i; - - tens = 1; - for (i = 0; i > dscale; i--) - tens *= 10; - - if (value >= 0) - snprintf(p, sizeof( data ), "%*" ISC_INT64_FORMAT "d.%0*" ISC_INT64_FORMAT "d", - field_width - 1 + dscale, - (ISC_INT64) value / tens, - -dscale, - (ISC_INT64) value % tens); - - else if ((value / tens) != 0) - snprintf(p, sizeof( data ), "%*" ISC_INT64_FORMAT "d.%0*" ISC_INT64_FORMAT "d", - field_width - 1 + dscale, - (ISC_INT64) (value / tens), - -dscale, - (ISC_INT64) -(value % tens)); - - else - snprintf(p, sizeof( data ), "%*s.%0*" ISC_INT64_FORMAT "d", - field_width - 1 + dscale, - "-0", - -dscale, - (ISC_INT64) -(value % tens)); - } - else if (dscale) - snprintf(p, sizeof( data ), "%*" ISC_INT64_FORMAT "d%0*d", field_width, (ISC_INT64) value, dscale, 0); - else - snprintf(p, sizeof( data ), "%*" ISC_INT64_FORMAT "d", field_width, (ISC_INT64) value); - }; - hb_retc(p); - break; - - case SQL_FLOAT: - snprintf(p, sizeof( data ), "%15g ", *(float ISC_FAR *) (var->sqldata)); - hb_retc(p); - break; - - case SQL_DOUBLE: - snprintf(p, sizeof( data ), "%24f ", *(double ISC_FAR *) (var->sqldata)); - hb_retc(p); - break; - - default: - hb_ret(); - break; - } - } -} - - -HB_FUNC(FBGETBLOB) -{ - ISC_STATUS status[MAX_FIELDS]; - isc_db_handle db = NULL; - isc_tr_handle trans = NULL; - isc_blob_handle blob_handle = NULL; - short blob_seg_len; - char blob_segment[ 512 ]; - ISC_QUAD *blob_id; - char p[MAX_BUFFER]; - long blob_stat; - - PHB_ITEM temp; - PHB_ITEM aNew; - - db = ( isc_db_handle ) hb_itemGetPtr( hb_param( 1, HB_IT_POINTER ) ); - blob_id = ( ISC_QUAD * ) hb_itemGetPtr( hb_param( 2, HB_IT_POINTER ) ); - - if (hb_parinfo(3)) { - trans = (isc_tr_handle) hb_itemGetPtr( hb_param( 3, HB_IT_POINTER ) ); - } else { - if ( isc_start_transaction ( status, &trans, 1, &db, 0, NULL ) ) { - ERREXIT(status); - } - } - - if (isc_open_blob2(status, &db, &trans, &blob_handle, blob_id, 0, NULL)) - ERREXIT(status); - - // Get blob segments and their lengths and print each segment. - blob_stat = isc_get_segment(status, &blob_handle, - (unsigned short ISC_FAR *) &blob_seg_len, - sizeof(blob_segment), blob_segment); - - if (blob_stat == 0 || status[1] == isc_segment) - aNew = hb_itemArrayNew( 0 ); - - while (blob_stat == 0 || status[1] == isc_segment) - { - //p = ( char * ) hb_xgrab( blob_seg_len + 1 ); - snprintf( p, sizeof( p ), "%*.*s", blob_seg_len, blob_seg_len, blob_segment); - - temp = hb_itemPutC( NULL, p ); - hb_arrayAdd( aNew, temp ) ; - hb_itemRelease(temp); - - //hb_xfree(p); - blob_stat = isc_get_segment(status, &blob_handle, - (unsigned short ISC_FAR *)&blob_seg_len, - sizeof(blob_segment), blob_segment); - } - - if (isc_close_blob(status, &blob_handle)) { - hb_itemRelease(aNew); - ERREXIT(status); - } - - if (!hb_parinfo(3)) - if ( isc_commit_transaction ( status, &trans ) ) - ERREXIT(status); - - hb_itemReturnRelease(aNew); + hb_itemReturnRelease( aNew ); } diff --git a/harbour/contrib/hbfbird/make_b32.bat b/harbour/contrib/hbfbird/make_b32.bat index bf51a3134f..5ba5fee5da 100644 --- a/harbour/contrib/hbfbird/make_b32.bat +++ b/harbour/contrib/hbfbird/make_b32.bat @@ -40,7 +40,7 @@ if "%1" == "INSTALL" goto POST_INSTALL :POST_BUILD rem Use supplied .lib file. - if not exist ..\..\lib\%_HB_CC_NAME%\%_HB_DLL_NAME%.lib copy "%HB_DIR_FIREBIRD%\%_HB_DLL_NAME%_bor.lib" ..\..\lib\%_HB_CC_NAME%\%_HB_DLL_NAME%.lib > nul + if not exist ..\..\lib\%_HB_CC_NAME%\%_HB_DLL_NAME%.lib copy "%HB_DIR_FIREBIRD%\lib\%_HB_DLL_NAME%_bor.lib" ..\..\lib\%_HB_CC_NAME%\%_HB_DLL_NAME%.lib > nul goto POST_EXIT :POST_CLEAN diff --git a/harbour/contrib/hbfbird/make_vc.bat b/harbour/contrib/hbfbird/make_vc.bat index ae6eb7954d..3c3c5ec733 100644 --- a/harbour/contrib/hbfbird/make_vc.bat +++ b/harbour/contrib/hbfbird/make_vc.bat @@ -40,7 +40,7 @@ if "%1" == "INSTALL" goto POST_INSTALL :POST_BUILD rem Use supplied .lib file. - if not exist ..\..\lib\%_HB_CC_NAME%\%_HB_DLL_NAME%.lib copy "%HB_DIR_FIREBIRD%\%_HB_DLL_NAME%_ms.lib" ..\..\lib\%_HB_CC_NAME%\%_HB_DLL_NAME%.lib > nul + if not exist ..\..\lib\%_HB_CC_NAME%\%_HB_DLL_NAME%.lib copy "%HB_DIR_FIREBIRD%\lib\%_HB_DLL_NAME%_ms.lib" ..\..\lib\%_HB_CC_NAME%\%_HB_DLL_NAME%.lib > nul goto POST_EXIT :POST_CLEAN diff --git a/harbour/contrib/hbfbird/tests/test.prg b/harbour/contrib/hbfbird/tests/test.prg index b520df4702..68f41815d0 100644 --- a/harbour/contrib/hbfbird/tests/test.prg +++ b/harbour/contrib/hbfbird/tests/test.prg @@ -5,73 +5,78 @@ #include "common.ch" Function Main() + LOCAL cDir, cName + LOCAL cDBName + LOCAL nDialect := 1 - nDialect := 1 - - if File('test.gdb') - FErase('test.gdb') - end - - ? FBCreateDB('test.gdb','sysdba', 'masterkey', 1024, 'ASCII', nDialect ) - - - /* Connect rdbms */ - db := FBConnect("127.0.0.1:d:\firebird\test\test.gdb", "sysdba", "masterkey") - - if ISNUMBER(db) - ? 'Error' - quit - end - - ? FBExecute(db, 'sldjfs;ldjs;djf', dialect) - - ? FBClose(db) - - trans := FBStartTransaction(db) - qry := FBQuery(db, 'create table teste (code smallint)', dialect, trans) - FBCommit(trans) - - - ? "Status Execute: ", FBExecute( db, 'insert into customer(customer) values ("test 1")', dialect, trans) - - ? "Status no Rollback: ", FBRollback(trans) - - trans := FBStartTransaction(db) - ? "Status Execute: ", FBExecute( db, 'insert into customer(customer) values ("test 2")', dialect, trans ) - ? "Status commit: ", FBCommit(trans) - - - ? "Status Execute: ", FBExecute( db, 'insert into customer(customer) values ("test 3")', dialect ) - - // FIX WINDOWS GPF BELOW - - qry := FBQuery(db, "SELECT * FROM sales", dialect) - - num_cols := qry[4] - columns := qry[6] - - For x := 1 to num_cols - ? x, "> " - For y := 1 to len(columns[x]) - ?? columns[x,y], ' ' - Next - Next - - ? '---' - - do while (fetch_stat := FBFetch(qry)) == 0 - ? fetch_stat - for x := 1 to num_cols - ?? FBGetData(qry,x), ', ' - next - end - - ? 'Fetch code:', fetch_stat - - ? "Status Free sql: ", FBFree(qry) + LOCAL trans, qry + hb_FNameSplit( hb_argv( 0 ), @cDir, @cName, NIL ) + cDBName := hb_FNameMerge( cDir, cName, ".gdb" ) - /* Close connection with rdbms */ - ? "Status Fechar Database: ", FBClose(db) + if File( cDBName ) + FErase( cDBName ) + endif + + ? FBCreateDB(cDBName, 'sysdba', 'masterkey', 1024, 'ASCII', nDialect ) + + /* Connect rdbms */ + db := FBConnect("127.0.0.1:" + cDBName, "sysdba", "masterkey") + + if ISNUMBER(db) + ? 'Error' + quit + endif + + ? FBExecute(db, 'sldjfs;ldjs;djf', nDialect) + + ? FBClose(db) + + trans := FBStartTransaction(db) + qry := FBQuery(db, 'create table teste (code smallint)', nDialect, trans) + FBCommit(trans) + + + ? "Status Execute: ", FBExecute( db, 'insert into customer(customer) values ("test 1")', nDialect, trans) + + ? "Status no Rollback: ", FBRollback(trans) + + trans := FBStartTransaction(db) + ? "Status Execute: ", FBExecute( db, 'insert into customer(customer) values ("test 2")', nDialect, trans ) + ? "Status commit: ", FBCommit(trans) + + + ? "Status Execute: ", FBExecute( db, 'insert into customer(customer) values ("test 3")', nDialect ) + + // FIX WINDOWS GPF BELOW + + qry := FBQuery(db, "SELECT * FROM sales", nDialect) + + num_cols := qry[4] + columns := qry[6] + + For x := 1 to num_cols + ? x, "> " + For y := 1 to len(columns[x]) + ?? columns[x,y], ' ' + Next + Next + + ? '---' + + do while (fetch_stat := FBFetch(qry)) == 0 + ? fetch_stat + for x := 1 to num_cols + ?? FBGetData(qry,x), ', ' + next + enddo + + ? 'Fetch code:', fetch_stat + + ? "Status Free sql: ", FBFree(qry) + + + /* Close connection with rdbms */ + ? "Status Fechar Database: ", FBClose(db) - Return Nil + Return Nil diff --git a/harbour/contrib/hbmisc/hb_f.c b/harbour/contrib/hbmisc/hb_f.c index e0d6a874e8..92cc42e1a7 100644 --- a/harbour/contrib/hbmisc/hb_f.c +++ b/harbour/contrib/hbmisc/hb_f.c @@ -50,7 +50,7 @@ * */ -/* please run $(HARBOUR)\tests\testhbf.prg for testing */ +/* please run tests\testhbf.prg for testing */ #include "hbapifs.h" diff --git a/harbour/contrib/hbmsql/msql.c b/harbour/contrib/hbmsql/msql.c index aac86e9084..8d3b438b36 100644 --- a/harbour/contrib/hbmsql/msql.c +++ b/harbour/contrib/hbmsql/msql.c @@ -2,7 +2,6 @@ * $Id$ */ - /* * Harbour Project source code: * mSQL DBMS low level (client api) interface code. @@ -54,193 +53,131 @@ #include "hbapi.h" #include "hbapiitm.h" -#ifdef HB_OS_WIN_32 +#if defined( HB_OS_WIN_32 ) && !defined( _OS_WIN32 ) /* This is needed by msql.h to indicate the platform. */ #define _OS_WIN32 #endif #include "msql.h" -HB_FUNC(MSQLCONNEC) /* int msqlConnect(char *) */ +HB_FUNC( MSQLCONNEC ) /* int msqlConnect(char *) */ { - hb_retni(msqlConnect(hb_parc(1))); + hb_retni( msqlConnect( hb_parc( 1 ) ) ); } - -HB_FUNC(MSQLCLOSE) /* void msqlClose(int) */ +HB_FUNC( MSQLCLOSE ) /* void msqlClose(int) */ { - msqlClose(hb_parni(1)); + msqlClose( hb_parni( 1 ) ); } - -HB_FUNC(MSQLSELECT) /* int msqlSelectDB(int, char *) */ +HB_FUNC( MSQLSELECT ) /* int msqlSelectDB(int, char *) */ { - hb_retni(msqlSelectDB(hb_parni(1), hb_parc(2))); + hb_retni( msqlSelectDB( hb_parni( 1 ), hb_parc( 2 ) ) ); } - -HB_FUNC(MSQLQUERY) /* int msqlQuery(int, char *) */ +HB_FUNC( MSQLQUERY ) /* int msqlQuery(int, char *) */ { - hb_retni(msqlQuery(hb_parni(1), hb_parc(2))); + hb_retni( msqlQuery( hb_parni( 1 ), hb_parc( 2 ) ) ); } - -HB_FUNC(MSQLSTORER) /* m_result *msqlStoreResult() */ +HB_FUNC( MSQLSTORER ) /* m_result *msqlStoreResult() */ { - hb_retnl((long) msqlStoreResult()); + hb_retptr( ( void * ) msqlStoreResult() ); } - -HB_FUNC(MSQLFREER) /* void msqlFreeResult(m_result *) */ +HB_FUNC( MSQLFREER ) /* void msqlFreeResult(m_result *) */ { - msqlFreeResult((m_result *)hb_parnl(1)); + msqlFreeResult( ( m_result * ) hb_parptr( 1 ) ); } - /* NOTE: need number of retrieved fields */ -HB_FUNC(MSQLFETCHR) /* m_row msqlFetchRow(m_result *, int) */ +HB_FUNC( MSQLFETCHR ) /* m_row msqlFetchRow(m_result *, int) */ { - m_result *mresult = (m_result *)hb_parnl(1); - int num_fields = hb_parnl(2); - - PHB_ITEM aRow = hb_itemArrayNew(num_fields); - PHB_ITEM temp; - m_row mrow; + m_result * mresult = ( m_result * ) hb_parptr( 1 ); + int num_fields = hb_parnl( 2 ); + PHB_ITEM aRow = hb_itemArrayNew( num_fields ); + m_row mrow = msqlFetchRow( mresult ); int i; - mrow = msqlFetchRow(mresult); + for( i = 0; i < num_fields; i++ ) + hb_itemArrayPut( aRow, i + 1, mrow[ i ] ); - for (i = 0; i < num_fields; i++) { - - /* if field is not empty */ - if (mrow[i] != NULL) { - temp = hb_itemPutC(NULL, mrow[i]); - } else { - temp = hb_itemPutC(NULL, ""); - } - - hb_itemArrayPut(aRow, i + 1, temp); - hb_itemRelease(temp); - } - hb_itemReturnRelease(aRow); + hb_itemReturnRelease( aRow ); +} + +HB_FUNC( MSQLDATASE ) /* void msqlDataSeek(m_result *, int) */ +{ + msqlDataSeek( ( m_result * ) hb_parptr( 1 ), hb_parni( 2 ) ); } - -HB_FUNC(MSQLDATASE) /* void msqlDataSeek(m_result *, int) */ +HB_FUNC( MSQLNUMROW ) /* int msqlNumRows(m_result *) */ { - msqlDataSeek((m_result *)hb_parnl(1), hb_parni(2)); + hb_retni( msqlNumRows( ( ( m_result * ) hb_parptr( 1 ) ) ) ); } - -HB_FUNC(MSQLNUMROW) /* int msqlNumRows(m_result *) */ +HB_FUNC( MSQLFETCHF ) /* m_field *msqlFetchField(m_result *) */ { - hb_retni(msqlNumRows(((m_result *)hb_parnl(1)))); -} + m_field * mfield = msqlFetchField( ( m_result * ) hb_parptr( 1 ) ); + PHB_ITEM aField = hb_itemArrayNew( 5 ); /* NOTE: m_field structure of mSQL 2.x has 5 members */ - -HB_FUNC(MSQLFETCHF) /* m_field *msqlFetchField(m_result *) */ -{ - /* NOTE: m_field structure of mSQL 2.x has 5 members */ - PHB_ITEM aField = hb_itemArrayNew(5); - - PHB_ITEM temp; - m_field *mfield; - - mfield = msqlFetchField((m_result *)hb_parnl(1)); - if (!(mfield == NULL)) { - temp = hb_itemPutC(NULL, mfield->name); - hb_itemArrayPut(aField, 1, temp); - hb_itemRelease(temp); - temp = hb_itemPutC(NULL, mfield->table); - hb_itemArrayPut(aField, 2, temp); - hb_itemRelease(temp); - temp = hb_itemPutNL(NULL, mfield->type); - hb_itemArrayPut(aField, 3, temp); - hb_itemRelease(temp); - temp = hb_itemPutNL(NULL, mfield->length); - hb_itemArrayPut(aField, 4, temp); - hb_itemRelease(temp); - temp = hb_itemPutNL(NULL, mfield->flags); - hb_itemArrayPut(aField, 5, temp); - hb_itemRelease(temp); - } - hb_itemReturnRelease(aField); -} - - -HB_FUNC(MSQLFIELDS) /* void msqlFieldSeek(m_result *, int) */ -{ - msqlFieldSeek((m_result *)hb_parnl(1), hb_parni(2)); -} - - -HB_FUNC(MSQLNUMFIE) /* int msqlNumFields(m_result *) */ -{ - hb_retni(msqlNumFields(((m_result *)hb_parnl(1)))); -} - - -HB_FUNC(MSQLLISTFI) /* m_result *msqlListFields(int, char *); */ -{ - hb_retnl((long) msqlListFields(hb_parni(1), hb_parc(2))); -} - - -HB_FUNC(MSQLGETERR) /* char *msqlGetErrMsg(char *); */ -{ - hb_retc(msqlGetErrMsg(NULL)); -} - - -HB_FUNC(MSQLLISTDB) /* m_result * msqlListDBs(int); */ -{ - int sock = hb_parnl(1); - m_result *mresult; - m_row mrow; - long nr, i; - PHB_ITEM aDBs; - PHB_ITEM temp; - - mresult = msqlListDBs(sock); - nr = msqlNumRows(mresult); - aDBs = hb_itemArrayNew(nr); - - for (i = 0; i < nr; i++) { - mrow = msqlFetchRow(mresult); - temp = hb_itemPutC(NULL, mrow[0]); - - hb_itemArrayPut(aDBs, i + 1, temp); - hb_itemRelease(temp); + if( mfield ) + { + hb_arraySetC( aField, 1, mfield->name ); + hb_arraySetC( aField, 2, mfield->table ); + hb_arraySetNL( aField, 3, mfield->type ); + hb_arraySetNL( aField, 4, mfield->length ); + hb_arraySetNL( aField, 5, mfield->flags ); } - msqlFreeResult(mresult); - hb_itemReturnRelease(aDBs); + hb_itemReturnRelease( aField ); } - -HB_FUNC(MSQLLISTTA) /* m_result * msqlListTables(int); */ +HB_FUNC( MSQLFIELDS ) /* void msqlFieldSeek(m_result *, int) */ { - int sock = hb_parnl(1); - m_result *mresult; - m_row mrow; - long nr, i; - PHB_ITEM aTables; - PHB_ITEM temp; - - mresult = msqlListTables(sock); - nr = msqlNumRows(mresult); - aTables = hb_itemArrayNew(nr); - - for (i = 0; i < nr; i++) { - - mrow = msqlFetchRow(mresult); - temp = hb_itemPutC(NULL, mrow[0]); - - hb_itemArrayPut(aTables, i + 1, temp); - hb_itemRelease(temp); - } - - msqlFreeResult(mresult); - hb_itemReturnRelease(aTables); + msqlFieldSeek( ( m_result * ) hb_parptr( 1 ), hb_parni( 2 ) ); } +HB_FUNC( MSQLNUMFIE ) /* int msqlNumFields(m_result *) */ +{ + hb_retni( msqlNumFields( ( ( m_result * ) hb_parptr( 1 ) ) ) ); +} + +HB_FUNC( MSQLLISTFI ) /* m_result *msqlListFields(int, char *); */ +{ + hb_retptr( ( void * ) msqlListFields( hb_parni( 1 ), hb_parc( 2 ) ) ); +} + +HB_FUNC( MSQLGETERR ) /* char *msqlGetErrMsg(char *); */ +{ + hb_retc( msqlGetErrMsg( NULL ) ); +} + +HB_FUNC( MSQLLISTDB ) /* m_result * msqlListDBs(int); */ +{ + int sock = hb_parnl( 1 ); + m_result * mresult = msqlListDBs( sock ); + long nr = msqlNumRows( mresult ); + PHB_ITEM aDBs = hb_itemArrayNew( nr ); + long i; + + for( i = 0; i < nr; i++ ) + hb_arraySetC( aDBs, i + 1, msqlFetchRow( mresult )[ 0 ] ); + + msqlFreeResult( mresult ); + hb_itemReturnRelease( aDBs ); +} + +HB_FUNC( MSQLLISTTA ) /* m_result * msqlListTables(int); */ +{ + int sock = hb_parnl( 1 ); + m_result * mresult = msqlListTables( sock ); + long nr = msqlNumRows( mresult ); + PHB_ITEM aTables = hb_itemArrayNew( nr ); + long i; + + for( i = 0; i < nr; i++ ) + hb_arraySetC( aTables, i + 1, msqlFetchRow( mresult )[ 0 ] ); + + msqlFreeResult( mresult ); + hb_itemReturnRelease( aTables ); +} diff --git a/harbour/contrib/hbmsql/msql.ch b/harbour/contrib/hbmsql/msql.ch index a3082481b0..cc63c77cbc 100644 --- a/harbour/contrib/hbmsql/msql.ch +++ b/harbour/contrib/hbmsql/msql.ch @@ -2,7 +2,6 @@ * $Id$ */ - /* * Harbour Project source code: * mSQL DBMS defines @@ -52,8 +51,7 @@ * */ - -// mSQL fields type +/* mSQL fields type */ #define MSQL_INT_TYPE 1 #define MSQL_CHAR_TYPE 2 #define MSQL_REAL_TYPE 3 @@ -62,7 +60,7 @@ #define MSQL_TEXT_TYPE 6 #define MSQL_DATE_TYPE 7 -// NOTE: UINT is used to map clipper logical values to mSQL tables, so 0 == .F., 1 == .T. +/* NOTE: UINT is used to map clipper logical values to mSQL tables, so 0 == .F., 1 == .T. */ #define MSQL_UINT_TYPE 8 #define MSQL_MONEY_TYPE 9 #define MSQL_TIME_TYPE 10 @@ -71,14 +69,10 @@ #define MSQL_SYSVAR_TYPE 254 #define MSQL_ANY_TYPE 255 - - -// mSQL field structure item number (C level structure is translated -// to a clipper array) - +/* mSQL field structure item number + (C level structure is translated to a clipper array) */ #define MSQL_FS_NAME 1 #define MSQL_FS_TABLE 2 #define MSQL_FS_TYPE 3 #define MSQL_FS_LENGTH 4 #define MSQL_FS_FLAGS 5 - diff --git a/harbour/contrib/hbmsql/msql.h b/harbour/contrib/hbmsql/msql.h index 927222bcad..f5b14291e4 100644 --- a/harbour/contrib/hbmsql/msql.h +++ b/harbour/contrib/hbmsql/msql.h @@ -54,7 +54,7 @@ #endif -#if (defined(__STDC__) || defined(__cplusplus) || defined(__BORLANDC__) || defined(_MSC_VER)) +#if defined(__STDC__) || defined(__cplusplus) || defined(__BORLANDC__) || defined(_MSC_VER) # define __ANSI_PROTO(x) x #else # define __ANSI_PROTO(x) () diff --git a/harbour/contrib/hbmysql/mysql.c b/harbour/contrib/hbmysql/mysql.c index d9935e83fd..c4305a2dea 100644 --- a/harbour/contrib/hbmysql/mysql.c +++ b/harbour/contrib/hbmysql/mysql.c @@ -73,35 +73,32 @@ #include #include - /* NOTE: OS/2 EMX port of MySQL needs libmysqlclient.a from 3.21.33b build which has st and mt - versions of client library. I'm using ST version since harbour is single threaded. You need - also .h files from same distribution -*/ + versions of client library. I'm using ST version since harbour is single threaded. + You need also .h files from same distribution. */ +/* TODO: Use hb_retptrGC() */ - -HB_FUNC( SQLVERSION ) /* long mysql_get_server_version(MYSQL *) */ +HB_FUNC( SQLVERSION ) /* long mysql_get_server_version( MYSQL * ) */ { - hb_retnl( (long) mysql_get_server_version((MYSQL *)hb_parptr(1)) ); + hb_retnl( ( long ) mysql_get_server_version( ( MYSQL * ) hb_parptr( 1 ) ) ); } - HB_FUNC( SQLCONNECT ) /* MYSQL *mysql_real_connect(MYSQL*, char * host, char * user, char * password, char * db, uint port, char *, uint flags) */ { - MYSQL * mysql; - const char *szHost=hb_parc(1); - const char *szUser=hb_parc(2); - const char *szPass=hb_parc(3); + const char * szHost = hb_parc( 1 ); + const char * szUser = hb_parc( 2 ); + const char * szPass = hb_parc( 3 ); #if MYSQL_VERSION_ID > 32200 - unsigned int port = ISNUM( 4 ) ? ( unsigned int ) hb_parni(4) : MYSQL_PORT; - unsigned int flags = ISNUM( 5 ) ? ( unsigned int ) hb_parni(5) : 0; + MYSQL * mysql; + unsigned int port = ISNUM( 4 ) ? ( unsigned int ) hb_parni( 4 ) : MYSQL_PORT; + unsigned int flags = ISNUM( 5 ) ? ( unsigned int ) hb_parni( 5 ) : 0; + if( ( mysql = mysql_init( ( MYSQL * ) NULL ) ) ) + { /* from 3.22.x of MySQL there is a new parameter in mysql_real_connect() call, that is char * db which is not used here */ - if( ( mysql = mysql_init((MYSQL*) 0) ) != NULL ) - { if( mysql_real_connect( mysql, szHost, szUser, szPass, 0, port, NULL, flags ) ) hb_retptr( ( void * ) mysql ); else @@ -113,61 +110,53 @@ HB_FUNC( SQLCONNECT ) /* MYSQL *mysql_real_connect(MYSQL*, char * host, char * u else hb_retptr( NULL ); #else - mysql = mysql_real_connect( NULL, szHost, szUser, szPass, 0, NULL, 0 ); - hb_retptr( ( void * ) mysql); + hb_retptr( ( void * ) mysql_real_connect( NULL, szHost, szUser, szPass, 0, NULL, 0 ) ); #endif } - HB_FUNC( SQLCLOSE ) /* void mysql_close(MYSQL *mysql) */ { - mysql_close((MYSQL *)hb_parptr(1)); + mysql_close( ( MYSQL * ) hb_parptr( 1 ) ); } - HB_FUNC( SQLCOMMIT ) /* bool mysql_commit(MYSQL *mysql) */ { - hb_retnl((long) mysql_commit((MYSQL *)hb_parptr(1))); + hb_retnl( ( long ) mysql_commit( ( MYSQL * ) hb_parptr( 1 ) ) ); } - HB_FUNC( SQLROLLBACK ) /* bool mysql_rollback(MYSQL *mysql) */ { - hb_retnl((long) mysql_rollback((MYSQL *)hb_parptr(1))); + hb_retnl( ( long ) mysql_rollback( ( MYSQL * ) hb_parptr( 1 ) ) ); } - HB_FUNC( SQLSELECTD ) /* int mysql_select_db(MYSQL *, char *) */ { - hb_retnl((long) mysql_select_db((MYSQL *)hb_parptr(1), (const char *)hb_parc(2) )); + hb_retnl( ( long ) mysql_select_db( ( MYSQL * ) hb_parptr( 1 ), ( const char * ) hb_parc( 2 ) ) ); } - HB_FUNC( SQLQUERY ) /* int mysql_query(MYSQL *, char *) */ { - hb_retnl((long) mysql_query((MYSQL *)hb_parptr(1), hb_parc(2))); + hb_retnl( ( long ) mysql_query( ( MYSQL * ) hb_parptr( 1 ), hb_parc( 2 ) ) ); } - -HB_FUNC( SQLSTORER ) /* MYSQL_RES *mysql_store_result(MYSQL *) */ +HB_FUNC( SQLSTORER ) /* MYSQL_RES *mysql_store_result( MYSQL * ) */ { - hb_retptr((void *) mysql_store_result((MYSQL *)hb_parptr(1))); + hb_retptr( ( void * ) mysql_store_result( ( MYSQL * ) hb_parptr( 1 ) ) ); } -HB_FUNC( SQLUSERES ) /* MYSQL_RES *mysql_use_result(MYSQL *) */ +HB_FUNC( SQLUSERES ) /* MYSQL_RES *mysql_use_result( MYSQL * ) */ { - hb_retptr((void *) mysql_use_result((MYSQL *)hb_parptr(1))); + hb_retptr( ( void * ) mysql_use_result( ( MYSQL * ) hb_parptr( 1 ) ) ); } HB_FUNC( SQLFREER ) /* void mysql_free_result(MYSQL_RES *) */ { - mysql_free_result((MYSQL_RES *)hb_parptr(1)); + mysql_free_result( ( MYSQL_RES * ) hb_parptr( 1 ) ); } - HB_FUNC( SQLFETCHR ) /* MYSQL_ROW *mysql_fetch_row(MYSQL_RES *) */ { - MYSQL_RES *mresult = (MYSQL_RES *)hb_parptr( 1 ); + MYSQL_RES * mresult = ( MYSQL_RES * ) hb_parptr( 1 ); int num_fields = mysql_num_fields( mresult ); PHB_ITEM aRow = hb_itemArrayNew( num_fields ); MYSQL_ROW mrow = mysql_fetch_row( mresult ); @@ -176,36 +165,34 @@ HB_FUNC( SQLFETCHR ) /* MYSQL_ROW *mysql_fetch_row(MYSQL_RES *) */ { int i; for( i = 0; i < num_fields; i++ ) - hb_arraySetC( aRow, i + 1, mrow[i] ); + hb_arraySetC( aRow, i + 1, mrow[ i ] ); } + hb_itemReturnRelease( aRow ); } - HB_FUNC( SQLDATAS ) /* void mysql_data_seek(MYSQL_RES *, unsigned int) */ { - mysql_data_seek((MYSQL_RES *)hb_parptr(1), (unsigned int)hb_parni(2)); + mysql_data_seek( ( MYSQL_RES * ) hb_parptr( 1 ), ( unsigned int ) hb_parni( 2 ) ); } - HB_FUNC( SQLNROWS ) /* my_ulongulong mysql_num_rows(MYSQL_RES *) */ { - hb_retnint(mysql_num_rows(((MYSQL_RES *)hb_parptr(1)))); + hb_retnint( mysql_num_rows( ( ( MYSQL_RES * ) hb_parptr( 1 ) ) ) ); } - HB_FUNC( SQLFETCHF ) /* MYSQL_FIELD *mysql_fetch_field(MYSQL_RES *) */ { /* NOTE: field structure of MySQL has 8 members as of MySQL 3.22.x */ PHB_ITEM aField = hb_itemArrayNew( 8 ); - MYSQL_FIELD *mfield = mysql_fetch_field( (MYSQL_RES *)hb_parptr(1) ); + MYSQL_FIELD * mfield = mysql_fetch_field( ( MYSQL_RES * ) hb_parptr( 1 ) ); if( mfield ) { - hb_arraySetC( aField, 1, mfield->name ); - hb_arraySetC( aField, 2, mfield->table ); - hb_arraySetC( aField, 3, mfield->def ); - hb_arraySetNL( aField, 4, (long)mfield->type ); + hb_arraySetC( aField, 1, mfield->name ); + hb_arraySetC( aField, 2, mfield->table ); + hb_arraySetC( aField, 3, mfield->def ); + hb_arraySetNL( aField, 4, ( long ) mfield->type ); hb_arraySetNL( aField, 5, mfield->length ); hb_arraySetNL( aField, 6, mfield->max_length ); hb_arraySetNL( aField, 7, mfield->flags ); @@ -215,49 +202,47 @@ HB_FUNC( SQLFETCHF ) /* MYSQL_FIELD *mysql_fetch_field(MYSQL_RES *) */ hb_itemReturnRelease( aField ); } - HB_FUNC( SQLFSEEK ) /* MYSQL_FIELD_OFFSET mysql_field_seek(MYSQL_RES *, MYSQL_FIELD_OFFSET) */ { - mysql_field_seek((MYSQL_RES *)hb_parptr(1), (MYSQL_FIELD_OFFSET)hb_parni(2)); + mysql_field_seek( ( MYSQL_RES * ) hb_parptr( 1 ), ( MYSQL_FIELD_OFFSET ) hb_parni( 2 ) ); } - HB_FUNC( SQLNUMFI ) /* unsigned int mysql_num_fields(MYSQL_RES *) */ { - hb_retnl(mysql_num_fields(((MYSQL_RES *)hb_parptr(1)))); + hb_retnl( mysql_num_fields( ( ( MYSQL_RES * ) hb_parptr( 1 ) ) ) ); } #if MYSQL_VERSION_ID > 32200 -HB_FUNC( SQLFICOU ) /* unsigned int mysql_field_count(MYSQL *) */ + +HB_FUNC( SQLFICOU ) /* unsigned int mysql_field_count( MYSQL * ) */ { - hb_retnl(mysql_field_count(((MYSQL *)hb_parptr(1)))); + hb_retnl( mysql_field_count( ( ( MYSQL * ) hb_parptr( 1 ) ) ) ); } + #endif HB_FUNC( SQLLISTF ) /* MYSQL_RES *mysql_list_fields(MYSQL *, char *); */ { - hb_retnl((long) mysql_list_fields((MYSQL *)hb_parptr(1), hb_parc(2), NULL)); + hb_retnl( ( long ) mysql_list_fields( ( MYSQL * ) hb_parptr( 1 ), hb_parc( 2 ), NULL ) ); } - -HB_FUNC( SQLGETERR ) /* char *mysql_error(MYSQL *); */ +HB_FUNC( SQLGETERR ) /* char *mysql_error( MYSQL * ); */ { - hb_retc(mysql_error((MYSQL *)hb_parptr(1))); + hb_retc( mysql_error( ( MYSQL * ) hb_parptr( 1 ) ) ); } - HB_FUNC( SQLLISTDB ) /* MYSQL_RES * mysql_list_dbs(MYSQL *, char * wild); */ { - MYSQL * mysql = (MYSQL *)hb_parptr(1); + MYSQL * mysql = ( MYSQL * ) hb_parptr( 1 ); MYSQL_RES * mresult = mysql_list_dbs( mysql, NULL ); - long nr = (LONG) mysql_num_rows( mresult ); + long nr = ( long ) mysql_num_rows( mresult ); PHB_ITEM aDBs = hb_itemArrayNew( nr ); long i; for( i = 0; i < nr; i++ ) { MYSQL_ROW mrow = mysql_fetch_row( mresult ); - hb_arraySetC( aDBs, i + 1, mrow[0] ); + hb_arraySetC( aDBs, i + 1, mrow[ 0 ] ); } mysql_free_result( mresult ); @@ -265,20 +250,19 @@ HB_FUNC( SQLLISTDB ) /* MYSQL_RES * mysql_list_dbs(MYSQL *, char * wild); */ hb_itemReturnRelease( aDBs ); } - HB_FUNC( SQLLISTTBL ) /* MYSQL_RES * mysql_list_tables(MYSQL *, char * wild); */ { - MYSQL * mysql = (MYSQL *)hb_parptr(1); - char * cWild = hb_parc(2); + MYSQL * mysql = ( MYSQL * ) hb_parptr( 1 ); + char * cWild = hb_parc( 2 ); MYSQL_RES * mresult = mysql_list_tables( mysql, cWild ); - long nr = (LONG) mysql_num_rows(mresult); + long nr = ( long ) mysql_num_rows( mresult ); PHB_ITEM aTables = hb_itemArrayNew( nr ); long i; for( i = 0; i < nr; i++ ) { MYSQL_ROW mrow = mysql_fetch_row( mresult ); - hb_arraySetC( aTables, i + 1, mrow[0] ); + hb_arraySetC( aTables, i + 1, mrow[ 0 ] ); } mysql_free_result( mresult ); @@ -288,31 +272,31 @@ HB_FUNC( SQLLISTTBL ) /* MYSQL_RES * mysql_list_tables(MYSQL *, char * wild); */ /* returns bitwise and of first parameter with second */ HB_FUNC( SQLAND ) { - hb_retnl(hb_parnl(1) & hb_parnl(2)); + hb_retnl( hb_parnl( 1 ) & hb_parnl( 2 ) ); } HB_FUNC( SQLAFFROWS ) { - hb_retnl( (LONG) mysql_affected_rows( (MYSQL *)hb_parptr(1) ) ); + hb_retnl( ( long ) mysql_affected_rows( ( MYSQL * ) hb_parptr( 1 ) ) ); } HB_FUNC( SQLHOSTINFO ) { - hb_retc( mysql_get_host_info( (MYSQL *)hb_parptr(1) ) ); + hb_retc( mysql_get_host_info( ( MYSQL * ) hb_parptr( 1 ) ) ); } HB_FUNC( SQLSRVINFO ) { - hb_retc( mysql_get_server_info( (MYSQL *)hb_parptr(1) ) ); + hb_retc( mysql_get_server_info( ( MYSQL * ) hb_parptr( 1 ) ) ); } HB_FUNC( DATATOSQL ) { - const char *from=hb_parc(1); - int iSize = hb_parclen(1); - char *buffer = (char*)hb_xgrab( (iSize*2)+1 ); + const char * from = hb_parc( 1 ); + int iSize = hb_parclen( 1 ); + char * buffer = ( char * ) hb_xgrab( iSize * 2 + 1 ); iSize = mysql_escape_string( buffer, from, iSize ); - hb_retclen_buffer( (char*)buffer, iSize ); + hb_retclen_buffer( ( char * ) buffer, iSize ); } static char * filetoBuff( char * fname, int * size ) @@ -322,15 +306,15 @@ static char * filetoBuff( char * fname, int * size ) if( handle != FS_ERROR ) { - * size = ( int ) hb_fsSeek( handle, 0, FS_END ); - * size -= ( int ) hb_fsSeek( handle, 0, FS_SET ); + *size = ( int ) hb_fsSeek( handle, 0, FS_END ); + *size -= ( int ) hb_fsSeek( handle, 0, FS_SET ); buffer = ( char * ) hb_xgrab( * size + 1 ); - * size = hb_fsReadLarge( handle, ( BYTE * ) buffer, * size ); - buffer[ * size ] = '\0'; + *size = hb_fsReadLarge( handle, ( BYTE * ) buffer, *size ); + buffer[ *size ] = '\0'; hb_fsClose( handle ); } else - * size = NULL; + *size = NULL; return buffer; } @@ -338,7 +322,7 @@ static char * filetoBuff( char * fname, int * size ) HB_FUNC( FILETOSQLBINARY ) { int iSize; - char *from = filetoBuff( hb_parc(1), &iSize ); + char * from = filetoBuff( hb_parc( 1 ), &iSize ); if( from ) { diff --git a/harbour/contrib/hbmysql/mysql.ch b/harbour/contrib/hbmysql/mysql.ch index f3cb772e2f..f0e79ae349 100644 --- a/harbour/contrib/hbmysql/mysql.ch +++ b/harbour/contrib/hbmysql/mysql.ch @@ -2,7 +2,6 @@ * $Id$ */ - /* * Harbour Project source code: * MySQL DBMS defines @@ -52,12 +51,8 @@ * */ - - -// MySQL field types - -// NOTE: TINY is used to map clipper logical values to MySQL tables, so 0 == .F., 1 == .T. -#define MYSQL_TINY_TYPE 1 +/* MySQL field types */ +#define MYSQL_TINY_TYPE 1 /* NOTE: TINY is used to map clipper logical values to MySQL tables, so 0 == .F., 1 == .T. */ #define MYSQL_SHORT_TYPE 2 #define MYSQL_LONG_TYPE 3 #define MYSQL_FLOAT_TYPE 4 @@ -81,11 +76,8 @@ #define MYSQL_VAR_STRING_TYPE 253 #define MYSQL_STRING_TYPE 254 - - -// MySQL field structure item number (C level structure is translated -// to a clipper array) - +/* MySQL field structure item number + (C level structure is translated to a clipper array) */ #define MYSQL_FS_NAME 1 /* Name of column */ #define MYSQL_FS_TABLE 2 /* Table of column if column was a field */ #define MYSQL_FS_DEF 3 /* Default value (set by mysql_list_fields) */ @@ -95,9 +87,7 @@ #define MYSQL_FS_FLAGS 7 /* Div flags */ #define MYSQL_FS_DECIMALS 8 /* Number of decimals in field */ - -// MySQL field flags - +/* MySQL field flags */ #define NOT_NULL_FLAG 1 /* Field can't be NULL */ #define PRI_KEY_FLAG 2 /* Field is part of a primary key */ #define UNIQUE_KEY_FLAG 4 /* Field is part of a unique key */ @@ -113,7 +103,5 @@ #define PART_KEY_FLAG 16384 /* Intern; Part of some key */ #define GROUP_FLAG 32768 /* Intern group field */ - -// Extension to DBS_xxx defines to encompass NOT NULL fields, needed by indexes -#define DBS_NOTNULL 5 /* True if field has to be NOT NULL */ - +/* Extension to DBS_xxx defines to encompass NOT NULL fields, needed by indexes */ +#define DBS_NOTNULL 5 /* True if field has to be NOT NULL */ diff --git a/harbour/contrib/hbmysql/tmysql.prg b/harbour/contrib/hbmysql/tmysql.prg index a6f9b22ab7..ddbeb71177 100644 --- a/harbour/contrib/hbmysql/tmysql.prg +++ b/harbour/contrib/hbmysql/tmysql.prg @@ -116,13 +116,7 @@ return Self METHOD FieldGet(cnField) CLASS TMySQLRow - local nNum - - if ValType(cnField) == "C" - nNum := ::FieldPos(cnField) - else - nNum := cnField - endif + local nNum := iif( ISCHARACTER( cnField ), ::FieldPos(cnField), cnField ) if nNum > 0 .AND. nNum <= Len(::aRow) @@ -140,17 +134,10 @@ return nil METHOD FieldPut(cnField, Value) CLASS TMySQLRow - local nNum - - if ValType(cnField) == "C" - nNum := ::FieldPos(cnField) - else - nNum := cnField - endif + local nNum := iif( ISCHARACTER( cnField ), ::FieldPos(cnField), cnField ) if nNum > 0 .AND. nNum <= Len(::aRow) -//DAVID: if Valtype(Value) == Valtype(::aRow[nNum]) .OR. Empty(::aRow[nNum]) if Valtype(Value) == Valtype(::aRow[nNum]) .OR. ::aRow[nNum]==NIL // if it is a char field remove trailing spaces @@ -176,45 +163,20 @@ return nil // Given a field name returns it's position METHOD FieldPos(cFieldName) CLASS TMySQLRow - local cUpperName, nPos := 0 + local cUpperName := Upper(cFieldName) - cUpperName := Upper(cFieldName) - -//DAVID: nPos := AScan(::aFieldStruct, {|aItem| iif(Upper(aItem[MYSQL_FS_NAME]) == cUpperName, .T., .F.)}) - nPos := AScan(::aFieldStruct, {|aItem| (Upper(aItem[MYSQL_FS_NAME]) == cUpperName)}) - - /*while ++nPos <= Len(::aFieldStruct) - if Upper(::aFieldStruct[nPos][MYSQL_FS_NAME]) == cUpperName - exit - endif - enddo - - // I haven't found field name - if nPos > Len(::aFieldStruct) - nPos := 0 - endif*/ - -return nPos +return AScan(::aFieldStruct, {|aItem| (Upper(aItem[MYSQL_FS_NAME]) == cUpperName)}) // Returns name of field N METHOD FieldName(nNum) CLASS TMySQLRow - if nNum >=1 .AND. nNum <= Len(::aFieldStruct) - return ::aFieldStruct[nNum][MYSQL_FS_NAME] - endif - -return "" +return iif( nNum >=1 .AND. nNum <= Len(::aFieldStruct), ::aFieldStruct[nNum][MYSQL_FS_NAME], "" ) METHOD FieldLen(nNum) CLASS TMySQLRow - if nNum >=1 .AND. nNum <= Len(::aFieldStruct) - return ::aFieldStruct[nNum][MYSQL_FS_LENGTH] - endif - -//DAVID: return "" -return 0 +return iif( nNum >=1 .AND. nNum <= Len(::aFieldStruct), ::aFieldStruct[nNum][MYSQL_FS_LENGTH], 0 ) METHOD FieldDec(nNum) CLASS TMySQLRow @@ -227,7 +189,6 @@ METHOD FieldDec(nNum) CLASS TMySQLRow endif endif -//DAVID: return "" return 0 diff --git a/harbour/contrib/hbtpathy/telepath.ch b/harbour/contrib/hbtpathy/telepath.ch index 39a1664dee..8065e5beec 100644 --- a/harbour/contrib/hbtpathy/telepath.ch +++ b/harbour/contrib/hbtpathy/telepath.ch @@ -53,79 +53,74 @@ #define TP_MAXPORTS 8 -#define TPFP_NAME 1 // Structure of ports array +#define TPFP_NAME 1 // Structure of ports array #define TPFP_HANDLE 2 #define TPFP_BAUD 3 #define TPFP_DBITS 4 #define TPFP_PARITY 5 #define TPFP_SBITS 6 -#define TPFP_OC 7 // Open/Close Flag +#define TPFP_OC 7 // Open/Close Flag #define TPFP_INBUF 8 -#define TPFP_INBUF_SIZE 9 // Size of input buffer +#define TPFP_INBUF_SIZE 9 // Size of input buffer // Error code definitions +#define TE_PARAM -1 // Bad parameter +#define TE_NOPORT -2 // No such port +#define TE_CLOSED -3 // Port not open +#define TE_CONFL -4 // IRQ conflict +#define TE_TMOUT -5 // Timeout +#define TE_NDCD -6 // Lost DCD +#define TE_ESCAPE -7 // User escape +#define TE_LENGTH -8 // Length limit +#define TE_CANCEL -9 // Input canceled +#define TE_NOHDL -10 // Out of handles -#define TE_PARAM -1 // Bad parameter -#define TE_NOPORT -2 // No such port -#define TE_CLOSED -3 // Port not open -#define TE_CONFL -4 // IRQ conflict -#define TE_TMOUT -5 // Timeout -#define TE_NDCD -6 // Lost DCD -#define TE_ESCAPE -7 // User escape -#define TE_LENGTH -8 // Length limit -#define TE_CANCEL -9 // Input canceled -#define TE_NOHDL -10 // Out of handles +#define TE_UCANCEL -50 // Canceled by user +#define TE_RCANCEL -51 // Canceled by remote +#define TE_STARTTM -52 // Timeout waiting to start +#define TE_BLOCKTM -53 // Timeout waiting for block +#define TE_ACKTM -54 // Timeout waiting for acknowledge +#define TE_SENDTM -55 // Timeout waiting to send +#define TE_CLEARTM -56 // Timeout waiting for sender to stop +#define TE_NAK -57 // Negative acknowledge +#define TE_BADACK -58 // Bad acknowledge character +#define TE_BADBLK -59 // Bad block format +#define TE_LONGBLK -60 // Long block received +#define TE_ERRMAX -61 // Too many errors +#define TE_DUPBLK -62 // Duplicate block +#define TE_PROTO -63 // Protocol failure +#define TE_CKSUM -64 // Checksum error +#define TE_HDRTM -65 // Timeout waiting for Zmodem header -#define TE_UCANCEL -50 // Canceled by user -#define TE_RCANCEL -51 // Canceled by remote -#define TE_STARTTM -52 // Timeout waiting to start -#define TE_BLOCKTM -53 // Timeout waiting for block -#define TE_ACKTM -54 // Timeout waiting for acknowledge -#define TE_SENDTM -55 // Timeout waiting to send -#define TE_CLEARTM -56 // Timeout waiting for sender to stop -#define TE_NAK -57 // Negative acknowledge -#define TE_BADACK -58 // Bad acknowledge character -#define TE_BADBLK -59 // Bad block format -#define TE_LONGBLK -60 // Long block received -#define TE_ERRMAX -61 // Too many errors -#define TE_DUPBLK -62 // Duplicate block -#define TE_PROTO -63 // Protocol failure -#define TE_CKSUM -64 // Checksum error -#define TE_HDRTM -65 // Timeout waiting for Zmodem header - -#define TE_DISKFULL -100 // Disk full -#define TE_NOFILE -102 // File not found -#define TE_NOPATH -103 // Path not found -#define TE_MFILE -104 // Too many open files -#define TE_ACCESS -105 // Access denied +#define TE_DISKFULL -100 // Disk full +#define TE_NOFILE -102 // File not found +#define TE_NOPATH -103 // Path not found +#define TE_MFILE -104 // Too many open files +#define TE_ACCESS -105 // Access denied // File transfer status - -#define TXS_START 1 // Start of transfer -#define TXS_SFILE 2 // Start of file -#define TXS_NEWNAME 3 // File renamed -#define TXS_SDATA 4 // Start of file data -#define TXS_BLOCK 5 // End of block -#define TXS_ERROR 6 // Error -#define TXS_ABFILE 7 // Aborting file -#define TXS_ABORT 8 // Aborting transfer -#define TXS_WEND 9 // Waiting for end of file -#define TXS_EFILE 10 // End of file -#define TXS_END 11 // End of transfer - -#define TP_32MAGIC 558161692 - +#define TXS_START 1 // Start of transfer +#define TXS_SFILE 2 // Start of file +#define TXS_NEWNAME 3 // File renamed +#define TXS_SDATA 4 // Start of file data +#define TXS_BLOCK 5 // End of block +#define TXS_ERROR 6 // Error +#define TXS_ABFILE 7 // Aborting file +#define TXS_ABORT 8 // Aborting transfer +#define TXS_WEND 9 // Waiting for end of file +#define TXS_EFILE 10 // End of file +#define TXS_END 11 // End of transfer + +#define TP_32MAGIC 558161692 // Handshaking flags for tp_hshk() - -#define THS_RDSR 1 // Require DSR -#define THS_RCTS 2 // Require CTS -#define THS_RXOFF 4 // Respect XON/XOFF -#define THS_RDCD 8 // Require DCD -#define THS_ADTR 16 // Assert DTR -#define THS_CDTR 32 // Flow control with DTR -#define THS_ARTS 64 // Assert RTS -#define THS_CRTS 128 // Flow control with RTS -#define THS_SXOFF 256 // Send XON/XOFF - +#define THS_RDSR 1 // Require DSR +#define THS_RCTS 2 // Require CTS +#define THS_RXOFF 4 // Respect XON/XOFF +#define THS_RDCD 8 // Require DCD +#define THS_ADTR 16 // Assert DTR +#define THS_CDTR 32 // Flow control with DTR +#define THS_ARTS 64 // Assert RTS +#define THS_CRTS 128 // Flow control with RTS +#define THS_SXOFF 256 // Send XON/XOFF diff --git a/harbour/contrib/hbtpathy/tpcommon.c b/harbour/contrib/hbtpathy/tpcommon.c index c699e07b6f..3b96df7ec6 100644 --- a/harbour/contrib/hbtpathy/tpcommon.c +++ b/harbour/contrib/hbtpathy/tpcommon.c @@ -95,26 +95,22 @@ static unsigned short crctab[ 256 ] = { /* updcrc() macro by Pete Disdale */ -#define updcrc(cp, crc) ( ( crc << 8 ) ^ ( crctab[ ( ( crc >> 8 ) ^ cp ) & 0xFF ] ) ) - - -HB_FUNC( P_CRC16 ) { +#define updcrc( cp, crc ) ( ( crc << 8 ) ^ ( crctab[ ( ( crc >> 8 ) ^ cp ) & 0xFF ] ) ) +HB_FUNC( P_CRC16 ) +{ char *ptr = hb_parc( 1 ); int count = hb_parclen( 1 ); register unsigned short crc = 0; - while ( count-- > 0 ) { + while ( count-- > 0 ) crc = updcrc( *ptr++, crc ); - } /* swap Hi and Lo byte */ hb_retnl( ( crc >> 8 ) | ( ( crc << 8 ) & 0xFF00 ) ); } - - /* Taken from: contrib/unicode/hbcrc32.c * Harbour Unicode Support @@ -164,20 +160,17 @@ static ULONG crc32tbl[ 256 ] = { 0xB3667A2El,0xC4614AB8l,0x5D681B02l,0x2A6F2B94l,0xB40BBE37l,0xC30C8EA1l,0x5A05DF1Bl,0x2D02EF8Dl }; +#define updcrc32( cp, crc ) ( crc32tbl[ ( crc ^ cp ) & 0xff ] ^ ( crc >> 8 ) ) -#define updcrc32(cp, crc) ( crc32tbl[ ( crc ^ cp ) & 0xff ] ^ ( crc >> 8 ) ) - - -HB_FUNC( P_CRC32 ) { - - char *ptr = hb_parc( 1 ); +HB_FUNC( P_CRC32 ) +{ + char * ptr = hb_parc( 1 ); int count = hb_parclen( 1 ); register ULONG crc = CRC32INIT; - while ( count-- > 0 ) { + while( count-- > 0 ) crc = updcrc32( *ptr++, crc ); - } hb_retnl( crc ^ CRC32INIT ); } diff --git a/harbour/contrib/hbtpathy/tplinux.c b/harbour/contrib/hbtpathy/tplinux.c index 62c7ab76c8..5865db5f7d 100644 --- a/harbour/contrib/hbtpathy/tplinux.c +++ b/harbour/contrib/hbtpathy/tplinux.c @@ -68,21 +68,16 @@ #include /* POSIX terminal control definitions */ #include -HB_FUNC( P_OPEN ) { +HB_FUNC( P_OPEN ) +{ + int fd = open( hb_parcx( 1 ), O_RDWR | O_NOCTTY | O_NDELAY ); /* File descriptor for the port */ - int fd; /* File descriptor for the port */ - - fd = open( hb_parcx( 1 ), O_RDWR | O_NOCTTY | O_NDELAY ); - - if (fd != -1) { + if( fd != -1 ) fcntl( fd, F_SETFL, 0 ); - } hb_retnl( fd ); } - - /* p_InitPortSpeed( aPorts[ nPort, TPFP_HANDLE ] ,; aPorts[ nPort, TPFP_BAUD ] ,; @@ -90,90 +85,37 @@ p_InitPortSpeed( aPorts[ nPort, TPFP_HANDLE ] ,; aPorts[ nPort, TPFP_PARITY ] ,; aPorts[ nPort, TPFP_SBITS ] ) */ -HB_FUNC( P_INITPORTSPEED ) { - +HB_FUNC( P_INITPORTSPEED ) +{ struct termios options; int port = hb_parnl( 1 ); int baud = B300; - char *ptr = hb_parcx( 4 ); + char * ptr = hb_parcx( 4 ); int rc; tcgetattr( port, &options ); /* let's set baud rate */ - switch ( hb_parnl( 2 ) ) { - - case 0: - baud = B0; /* Drop line */ - break; - - case 50: - baud = B50; - break; - - case 75: - baud = B75; - break; - - case 110: - baud = B110; - break; - - case 150: - baud = B150; - break; - - case 200: - baud = B200; - break; - - case 300: - baud = B300; - break; - - case 600: - baud = B600; - break; - - case 1200: - baud = B1200; - break; - - case 1800: - baud = B1800; - break; - - case 2400: - baud = B2400; - break; - - case 4800: - baud = B4800; - break; - - case 9600: - baud = B9600; - break; - - case 19200: - baud = B19200; - break; - - case 38400: - baud = B38400; - break; - - case 57600: - baud = B57600; - break; - - case 115200: - baud = B115200; - break; - - case 230400: - baud = B230400; - break; + switch( hb_parnl( 2 ) ) + { + case 0: baud = B0; break; /* Drop line */ + case 50: baud = B50; break; + case 75: baud = B75; break; + case 110: baud = B110; break; + case 150: baud = B150; break; + case 200: baud = B200; break; + case 300: baud = B300; break; + case 600: baud = B600; break; + case 1200: baud = B1200; break; + case 1800: baud = B1800; break; + case 2400: baud = B2400; break; + case 4800: baud = B4800; break; + case 9600: baud = B9600; break; + case 19200: baud = B19200; break; + case 38400: baud = B38400; break; + case 57600: baud = B57600; break; + case 115200: baud = B115200; break; + case 230400: baud = B230400; break; } cfsetispeed( &options, baud ); @@ -189,23 +131,18 @@ HB_FUNC( P_INITPORTSPEED ) { options.c_cflag &= ~CSIZE; /* Data bits */ - if ( hb_parni( 3 ) == 8 ) { - + if( hb_parni( 3 ) == 8 ) options.c_cflag |= CS8; - - } else { - + else options.c_cflag |= CS7; - } /* Stop bits */ - if ( hb_parni( 5 ) == 1 ) { + if( hb_parni( 5 ) == 1 ) options.c_cflag &= ~CSTOPB; - } /* Parity, only No, Even, Odd supported */ - switch ( *ptr ) { - + switch ( *ptr ) + { case 'N': case 'n': options.c_cflag &= ~PARENB; @@ -230,7 +167,6 @@ HB_FUNC( P_INITPORTSPEED ) { break; } - /* Every read() call returns as soon as a char is available OR after 3 tenths of a second */ options.c_cc[ VMIN ] = 0; options.c_cc[ VTIME ] = 3; @@ -241,62 +177,42 @@ HB_FUNC( P_INITPORTSPEED ) { hb_retnl( rc ); } - - -HB_FUNC( P_READPORT ) { - - char Buffer[512]; +HB_FUNC( P_READPORT ) +{ + char Buffer[ 512 ]; int nRead = read( hb_parnl( 1 ), Buffer, sizeof( Buffer ) ); - if ( nRead < 0 ) - hb_retc( NULL ); - else - hb_retclen( Buffer, nRead ); + hb_retclen( nRead > 0 ? Buffer : NULL, nRead ); } - - -HB_FUNC( P_WRITEPORT ) { - +HB_FUNC( P_WRITEPORT ) +{ long n = write( hb_parnl( 1 ), hb_parcx( 2 ), hb_parclen( 2 ) ); - if ( n < 0 ) - hb_retnl( -1 ); - else - hb_retnl( n ); + hb_retnl( n < 0 ? -1 : n ); } - - -HB_FUNC( P_DRAIN ) { - +HB_FUNC( P_DRAIN ) +{ hb_retnl( tcdrain( hb_parnl( 1 ) ) ); - } - - -HB_FUNC( P_OUTFREE ) { +HB_FUNC( P_OUTFREE ) +{ /* APIRET rc; RXQUEUE rxqueue = { 0 }; - if ( ( rc = DosDevIOCtl( (HFILE) hb_parnl( 1 ), IOCTL_ASYNC, ASYNC_GETOUTQUECOUNT, - NULL, 0L, NULL, &rxqueue, sizeof(RXQUEUE), NULL ) ) == NO_ERROR ) { - + if ( ( rc = DosDevIOCtl( ( HFILE ) hb_parnl( 1 ), IOCTL_ASYNC, ASYNC_GETOUTQUECOUNT, + NULL, 0L, NULL, &rxqueue, sizeof( RXQUEUE ), NULL ) ) == NO_ERROR ) hb_retnl( rxqueue.cb - rxqueue.cch ); - - } else { - /* Put GetLastError() here, or better a second byref param? */ - hb_retnl( -1 ); - } - + else + hb_retnl( -1 ); /* Put GetLastError() here, or better a second byref param? */ */ } - -HB_FUNC( P_ISDCD ) { - +HB_FUNC( P_ISDCD ) +{ int status; if ( ioctl( hb_parnl( 1 ), TIOCMGET, &status ) == 0 ) @@ -305,10 +221,8 @@ HB_FUNC( P_ISDCD ) { hb_retl( FALSE ); } - - -HB_FUNC( P_ISRI ) { - +HB_FUNC( P_ISRI ) +{ int status; if ( ioctl( hb_parnl( 1 ), TIOCMGET, &status ) == 0 ) @@ -317,10 +231,8 @@ HB_FUNC( P_ISRI ) { hb_retl( FALSE ); } - - -HB_FUNC( P_ISDSR ) { - +HB_FUNC( P_ISDSR ) +{ int status; if ( ioctl( hb_parnl( 1 ), TIOCMGET, &status ) == 0 ) @@ -329,10 +241,8 @@ HB_FUNC( P_ISDSR ) { hb_retl( FALSE ); } - - -HB_FUNC( P_ISCTS ) { - +HB_FUNC( P_ISCTS ) +{ int status; if ( ioctl( hb_parnl( 1 ), TIOCMGET, &status ) == 0 ) @@ -341,7 +251,6 @@ HB_FUNC( P_ISCTS ) { hb_retl( FALSE ); } - HB_FUNC( P_CTRLCTS ) { struct termios options; @@ -353,20 +262,15 @@ HB_FUNC( P_CTRLCTS ) { tcgetattr( port, &options ); curvalue = ( options.c_cflag & CRTSCTS ) == CRTSCTS; - if ( newvalue == 0 ) { + if( newvalue == 0 ) options.c_cflag &= ~CRTSCTS; + else if( newvalue == 1 ) + options.c_cflag |= CRTSCTS; - } else { - if ( newvalue == 1 ) { - options.c_cflag |= CRTSCTS; - } - } - - if ( newvalue >= 0 ) { + if( newvalue >= 0 ) rc = tcsetattr( port, TCSAFLUSH, &options ); - } hb_retni( curvalue ? 1 : 0 ); - } + #endif /* HB_OS_UNIX */ diff --git a/harbour/contrib/hbtpathy/tpos2.c b/harbour/contrib/hbtpathy/tpos2.c index 1fa37d7ad0..62f302072b 100644 --- a/harbour/contrib/hbtpathy/tpos2.c +++ b/harbour/contrib/hbtpathy/tpos2.c @@ -65,21 +65,20 @@ #include -HB_FUNC( P_INITPORTSPEED ) { - +HB_FUNC( P_INITPORTSPEED ) +{ APIRET rc; LINECONTROL lctl; DCBINFO dcb; - USHORT Baud; - char *ptr = hb_parcx(4); + USHORT Baud = ( USHORT ) hb_parnl( 2 ); + char * ptr = hb_parcx( 4 ); - memset( &dcb, 0, sizeof(dcb) ); - memset( &lctl, 0, sizeof(lctl) ); - - Baud = (USHORT) hb_parnl(2); + memset( &dcb, 0, sizeof( dcb ) ); + memset( &lctl, 0, sizeof( lctl ) ); /* OS/2 has Mark and Space parity options */ - switch ( *ptr ) { + switch( *ptr ) + { case 'N': case 'n': lctl.bParity = 0; @@ -105,19 +104,12 @@ HB_FUNC( P_INITPORTSPEED ) { lctl.bStopBits = hb_parnl( 5 ) == 1 ? 0 : hb_parnl( 5 ); /* 1 == 1.5 stop bits only valid with 5 data bits */ lctl.fTransBreak = 0; - if ( DosDevIOCtl( (HFILE) hb_parnl( 1 ), IOCTL_ASYNC, ASYNC_SETBAUDRATE, &Baud, - sizeof(USHORT), NULL, NULL, 0L, NULL) != NO_ERROR ) { - - hb_retnl( -1 ); - - } else { - - if ( DosDevIOCtl( (HFILE) hb_parnl( 1 ), IOCTL_ASYNC, ASYNC_SETLINECTRL, - &lctl, sizeof(LINECONTROL), NULL, NULL, 0L, NULL) != NO_ERROR ) { - hb_retnl( -2 ); - - } else { - + if( DosDevIOCtl( ( HFILE ) hb_parnl( 1 ), IOCTL_ASYNC, ASYNC_SETBAUDRATE, &Baud, + sizeof( USHORT ), NULL, NULL, 0L, NULL ) == NO_ERROR ) + { + if( DosDevIOCtl( ( HFILE ) hb_parnl( 1 ), IOCTL_ASYNC, ASYNC_SETLINECTRL, + &lctl, sizeof( LINECONTROL ), NULL, NULL, 0L, NULL ) == NO_ERROR ) + { /* tp_ help says: on port open DTR ON (value 1) CTS OFF @@ -133,145 +125,96 @@ HB_FUNC( P_INITPORTSPEED ) { dcb.fbTimeout = MODE_NO_WRITE_TIMEOUT | MODE_NOWAIT_READ_TIMEOUT; - if ( DosDevIOCtl( (HFILE) hb_parnl( 1 ), IOCTL_ASYNC, ASYNC_SETDCBINFO, &dcb, - sizeof(DCBINFO), 0L, NULL, 0L, NULL) == NO_ERROR ) { - + if( DosDevIOCtl( ( HFILE ) hb_parnl( 1 ), IOCTL_ASYNC, ASYNC_SETDCBINFO, &dcb, + sizeof(DCBINFO), 0L, NULL, 0L, NULL ) == NO_ERROR ) hb_retnl( 0 ); - - } else { - + else hb_retnl( -3 ); - } } + else + hb_retnl( -2 ); } -} - - - -HB_FUNC( P_READPORT ) { - - char Buffer[512]; - ULONG nRead = 0; - APIRET rc; - - rc = DosRead( (HFILE) hb_parnl( 1 ), Buffer, 512, &nRead ); - - if ( rc == NO_ERROR ) { - hb_retclen( Buffer, nRead ); - } else { - hb_retclen( "", 0 ); - } - -} - - - -HB_FUNC( P_WRITEPORT ) { - - ULONG nWritten = 0; - APIRET rc; - - - rc = DosWrite( (HFILE) hb_parnl( 1 ), hb_parcx( 2 ), hb_parclen( 2 ), &nWritten ); - - if ( rc == NO_ERROR ) { - hb_retnl( nWritten ); - } else { - /* Put GetLastError() here, or better a second byref param? */ + else hb_retnl( -1 ); - } - } +HB_FUNC( P_READPORT ) +{ + char Buffer[ 512 ]; + ULONG nRead = 0; + APIRET rc = DosRead( ( HFILE ) hb_parnl( 1 ), Buffer, sizeof( Buffer ), &nRead ); + hb_retclen( rc == NO_ERROR ? Buffer : NULL, nRead ); +} -HB_FUNC( P_OUTFREE ) { +HB_FUNC( P_WRITEPORT ) +{ + ULONG nWritten = 0; + APIRET rc = DosWrite( ( HFILE ) hb_parnl( 1 ), hb_parcx( 2 ), hb_parclen( 2 ), &nWritten ); + hb_retnl( rc == NO_ERROR ? nWritten : -1 ); /* Put GetLastError() on error, or better a second byref param? */ +} + +HB_FUNC( P_OUTFREE ) +{ APIRET rc; RXQUEUE rxqueue = { 0 }; - if ( ( rc = DosDevIOCtl( (HFILE) hb_parnl( 1 ), IOCTL_ASYNC, ASYNC_GETOUTQUECOUNT, - NULL, 0L, NULL, &rxqueue, sizeof(RXQUEUE), NULL ) ) == NO_ERROR ) { - + if( ( rc = DosDevIOCtl( ( HFILE ) hb_parnl( 1 ), IOCTL_ASYNC, ASYNC_GETOUTQUECOUNT, + NULL, 0L, NULL, &rxqueue, sizeof(RXQUEUE), NULL ) ) == NO_ERROR ) hb_retnl( rxqueue.cb - rxqueue.cch ); - - } else { - /* Put GetLastError() here, or better a second byref param? */ - hb_retnl( -1 ); - } - + else + hb_retnl( -1 ); /* Put GetLastError() here, or better a second byref param? */ } - - -HB_FUNC( P_ISDCD ) { - +HB_FUNC( P_ISDCD ) +{ BYTE instat; /* if DosDevIOCtl() returns an error, return no DCD */ - if ( DosDevIOCtl( (HFILE) hb_parnl( 1 ), IOCTL_ASYNC, ASYNC_GETMODEMINPUT, - NULL, 0, NULL, &instat, sizeof(instat), NULL) == NO_ERROR ) { + if( DosDevIOCtl( ( HFILE ) hb_parnl( 1 ), IOCTL_ASYNC, ASYNC_GETMODEMINPUT, + NULL, 0, NULL, &instat, sizeof( instat ), NULL ) == NO_ERROR ) hb_retl( ( instat & DCD_ON ) == DCD_ON ); - - } else { - + else hb_retl( FALSE ); - } } - - -HB_FUNC( P_ISRI ) { - +HB_FUNC( P_ISRI ) +{ BYTE instat; - if ( DosDevIOCtl( (HFILE) hb_parnl( 1 ), IOCTL_ASYNC, ASYNC_GETMODEMINPUT, - NULL, 0, NULL, &instat, sizeof(instat), NULL) == NO_ERROR ) { + if( DosDevIOCtl( ( HFILE ) hb_parnl( 1 ), IOCTL_ASYNC, ASYNC_GETMODEMINPUT, + NULL, 0, NULL, &instat, sizeof( instat ), NULL ) == NO_ERROR ) hb_retl( ( instat & RI_ON ) == RI_ON ); - - } else { - + else hb_retl( FALSE ); - } } - - -HB_FUNC( P_ISDSR ) { - +HB_FUNC( P_ISDSR ) +{ BYTE instat; - if ( DosDevIOCtl( (HFILE) hb_parnl( 1 ), IOCTL_ASYNC, ASYNC_GETMODEMINPUT, - NULL, 0, NULL, &instat, sizeof(instat), NULL) == NO_ERROR ) { + if( DosDevIOCtl( ( HFILE ) hb_parnl( 1 ), IOCTL_ASYNC, ASYNC_GETMODEMINPUT, + NULL, 0, NULL, &instat, sizeof( instat ), NULL ) == NO_ERROR ) hb_retl( ( instat & DSR_ON ) == DSR_ON ); - - } else { - + else hb_retl( FALSE ); - } } - - -HB_FUNC( P_ISCTS ) { - +HB_FUNC( P_ISCTS ) +{ BYTE instat; - if ( DosDevIOCtl( (HFILE) hb_parnl( 1 ), IOCTL_ASYNC, ASYNC_GETMODEMINPUT, - NULL, 0, NULL, &instat, sizeof(instat), NULL) == NO_ERROR ) { + if( DosDevIOCtl( ( HFILE ) hb_parnl( 1 ), IOCTL_ASYNC, ASYNC_GETMODEMINPUT, + NULL, 0, NULL, &instat, sizeof( instat ), NULL ) == NO_ERROR ) hb_retl( ( instat & CTS_ON ) == CTS_ON ); - - } else { - + else hb_retl( FALSE ); - } } - - -HB_FUNC( P_CTRLCTS ) { - +HB_FUNC( P_CTRLCTS ) +{ hb_retni( 0 ); - } + #endif /* HB_OS_OS2 */ diff --git a/harbour/contrib/hbtpathy/tpwin32.c b/harbour/contrib/hbtpathy/tpwin32.c index 644dfbc854..d3b32931e5 100644 --- a/harbour/contrib/hbtpathy/tpwin32.c +++ b/harbour/contrib/hbtpathy/tpwin32.c @@ -64,21 +64,17 @@ HB_FUNC( P_INITPORTSPEED ) { DCB dcb; - char values[20]; + char values[ 20 ]; - FillMemory(&dcb, sizeof(dcb), 0); - dcb.DCBlength = sizeof(dcb); + FillMemory( &dcb, sizeof( dcb ), 0 ); + dcb.DCBlength = sizeof( dcb ); - snprintf(values, sizeof( values ), "%u,%1s,%1u,%1u", hb_parnl(2), hb_parcx(4), hb_parnl(3), hb_parnl(5)); + snprintf( values, sizeof( values ), "%u,%1s,%1u,%1u", hb_parnl( 2 ), hb_parcx( 4 ), hb_parnl( 3 ), hb_parnl( 5 ) ); - if ( ! BuildCommDCB(values, &dcb)) { - hb_retnl(-1); - - } else { - if ( ! SetCommState( (HANDLE) hb_parnl(1), &dcb) ) { - hb_retnl(-1); - - } else { + if( BuildCommDCB( values, &dcb ) ) + { + if( SetCommState( ( HANDLE ) hb_parnl( 1 ), &dcb ) ) + { COMMTIMEOUTS timeouts; /* read/write operations return immediatly */ @@ -88,49 +84,32 @@ HB_FUNC( P_INITPORTSPEED ) { timeouts.WriteTotalTimeoutMultiplier = 0; timeouts.WriteTotalTimeoutConstant = 0; - if ( SetCommTimeouts( (HANDLE) hb_parnl(1), &timeouts ) ) { - hb_retnl(0); - } else { - hb_retnl(-1); - } + hb_retnl( SetCommTimeouts( ( HANDLE ) hb_parnl( 1 ), &timeouts ) ? 0 : -1 ); } + else + hb_retnl( -1 ); } -} - - - -HB_FUNC( P_READPORT ) { - - char Buffer[512]; - DWORD nRead = 0; - BOOL bRet; - OVERLAPPED Overlapped = {0}; - - bRet = ReadFile( (HANDLE) hb_parnl( 1 ), Buffer, 512, &nRead, &Overlapped ); - - if ( bRet ) { - hb_retclen( Buffer, nRead ); - } else { - hb_retc( NULL ); - } -} - - - -HB_FUNC( P_WRITEPORT ) { - - DWORD nWritten = 0; - BOOL bRet; - OVERLAPPED Overlapped = {0}; - - bRet = WriteFile( (HANDLE) hb_parnl( 1 ), hb_parcx( 2 ), hb_parclen( 2 ), &nWritten, &Overlapped ); - - if ( bRet ) { - hb_retnl( nWritten ); - } else { - /* Put GetLastError() here, or better a second byref param? */ + else hb_retnl( -1 ); - } +} + +HB_FUNC( P_READPORT ) +{ + char Buffer[ 512 ]; + DWORD nRead = 0; + OVERLAPPED Overlapped = { 0 }; + BOOL bRet = ReadFile( ( HANDLE ) hb_parnl( 1 ), Buffer, sizeof( Buffer ), &nRead, &Overlapped ); + + hb_retclen( bRet ? Buffer : NULL, nRead ); +} + +HB_FUNC( P_WRITEPORT ) +{ + DWORD nWritten = 0; + OVERLAPPED Overlapped = { 0 }; + BOOL bRet = WriteFile( ( HANDLE ) hb_parnl( 1 ), hb_parcx( 2 ), hb_parclen( 2 ), &nWritten, &Overlapped ); + + hb_retnl( bRet ? nWritten : -1 ); /* Put GetLastError() on error, or better a second byref param? */ } #endif /* HB_OS_WIN_32 */