[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User]
Here is a Harbour (xBase/Clipper) implementation:

Harbour contribution module 'xhb' (Extended Harbour functions): contrib/xhb/tfile.prg. Defines classes: TCgiFile. This file provides legacy compatibility functions

[Assistant]
#include "hbclass.ch"
#include "fileio.ch"
#include "cgi.ch"

#translate FPOS( <f> ) => FSeek( <f>, 0, FS_RELATIVE )

CREATE CLASS TCgiFile

   VAR Buffer INIT ""
   VAR Name INIT ""
   VAR Handle
   VAR FileSize INIT 0
   VAR BytesRead INIT 0
   VAR cPage INIT ""
   VAR nPage INIT 0
   VAR nPageSize INIT 1024
   VAR nRecord INIT 0

   METHOD New( cName )

   METHOD Open( nMode )

   METHOD Close() INLINE FClose( ::Handle ), ;
      ::Handle := -999

   METHOD Rename( c ) INLINE FRename( ::File, c ) == 0

   METHOD Erase() INLINE FErase( ::File ) == 0

   METHOD Exists() INLINE hb_FileExists( ::File )

   METHOD Error() INLINE FError() != 0

   METHOD Tell() INLINE FSeek( ::handle, 0, FS_RELATIVE )

   METHOD Pointer() INLINE FPOS( ::handle )

   METHOD ReadStr( n ) INLINE ::Buffer := ;
      FReadStr( ::Handle, n )
   METHOD Write( c, n ) INLINE FWrite( ::Handle, c, n )

   METHOD WriteByte( nByte )

   METHOD WriteInt( nInt )

   METHOD WriteLong( nLong )

   METHOD GetBuffer() INLINE ::Buffer

   METHOD GoTop() INLINE FSeek( ::Handle, 0 )

   METHOD GoBottom() INLINE FSeek( ::Handle, 0, FS_END )

   METHOD Bof() INLINE( FPOS( ::Handle ) == 0 )

   METHOD Eof() INLINE FPOS( ::Handle ) == ::FileSize

   METHOD Seek( n, o ) INLINE FSeek( ::Handle, n, o )

   METHOD Create( nAttr )

   METHOD Size()

   METHOD _Read( nSize, cBuff )

   METHOD ReadAhead( nSize, cBuff )

   METHOD ReadLine( nSize )

   METHOD PrevLine( nBytes )

   METHOD ReadByte()

   METHOD ReadInt()

   METHOD ReadLong()

   METHOD Goto( nLine )

   METHOD Skip( nLines )

   METHOD MaxPages( nPageSize )

   METHOD PrevPage( nBytes )

   METHOD NextPage( nBytes )

ENDCLASS

METHOD New( cName ) CLASS TCgiFile

   ::Name      := cName
   ::Buffer    := ""
   ::Handle    := 0
   ::FileSize  := 0
   ::BytesRead := 0
   ::cPage     := ""
   ::nPage     := 0
   ::nPageSize := 1024
   ::nRecord   := 0

   RETURN Self

METHOD Open( nMode ) CLASS TCgiFile

   __defaultNIL( @nMode, FO_EXCLUSIVE )
   ::Handle := FOpen( ::Name, nMode )
   IF ::Handle != F_ERROR
      ::Size()
   ENDIF

   RETURN ::Handle != F_ERROR

METHOD Create( nAttr ) CLASS TCgiFile

   LOCAL nSuccess

   __defaultNIL( @nAttr, 0 )
   nSuccess := FCreate( ::Name, nAttr )
   ::Handle := nSuccess

   RETURN nSuccess != F_ERROR

METHOD Size() CLASS TCgiFile

   LOCAL nCurrent
   LOCAL nLength

   nCurrent := FPOS( ::Handle )
   nLength  := FSeek( ::Handle, 0, FS_END )

   FSeek( ::Handle, nCurrent )
   ::FileSize := nLength

   RETURN nLength

METHOD _Read( nSize, cBuff ) CLASS TCgiFile

   __defaultNIL( @nSize, 1024 )
   __defaultNIL( @cBuff, Space( nSize ) )

   ::BytesRead := FRead( ::Handle, @cBuff, nSize )
   ::Buffer    := cBuff

   RETURN cBuff

METHOD ReadAhead( nSize, cBuff ) CLASS TCgiFile

   LOCAL nCurrent

   __defaultNIL( @nSize, 1024 )
   __defaultNIL( @cBuff, Space( nSize ) )

   nCurrent := FPOS( ::Handle )

   ::BytesRead := FRead( ::Handle, @cBuff, nSize )

   FSeek( ::Handle, nCurrent )

   RETURN cBuff

METHOD Readline( nSize ) CLASS TCgiFile

   LOCAL cString
   LOCAL nCurrent
   LOCAL nCr

   __defaultNIL( @nSize, 1024 )

   IF nSize <= 0
      RETURN ""
   ENDIF

   nCurrent := FSeek( ::Handle, 0, FS_RELATIVE )
   cString  := FReadStr( ::Handle, nSize )
   nCr      := At( Chr( 13 ), cString )

   FSeek( ::Handle, nCurrent, FS_SET )
   FSeek( ::Handle, nCr + 1, FS_RELATIVE )

   ::Buffer := SubStr( cString, 1, nCr - 1 )
   ::nRecord++

   RETURN ::Buffer

METHOD ReadByte() CLASS TCgiFile

   LOCAL nBytes
   LOCAL cBuff  := Space( 1 )

   nBytes := FRead( ::Handle, @cBuff, hb_BLen( cBuff ) )

   RETURN iif( nBytes > 0, Asc( cBuff ), -1 )

METHOD ReadInt() CLASS TCgiFile

   LOCAL nBytes
   LOCAL cBuff  := Space( 2 )

   nBytes := FRead( ::Handle, @cBuff, hb_BLen( cBuff ) )

   RETURN iif( nBytes > 0, Bin2I( cBuff ), -1 )

METHOD ReadLong() CLASS TCgiFile

   LOCAL nBytes
   LOCAL cBuff  := Space( 4 )

   nBytes := FRead( ::Handle, @cBuff, hb_BLen( cBuff ) )

   RETURN iif( nBytes > 0, Bin2L( cBuff ), -1 )

METHOD WriteByte( nByte ) CLASS TCgiFile

   LOCAL lSuccess := ( FWrite( ::nHandle, hb_BCode( nByte ), 1 ) == 1 )

   RETURN lSuccess

METHOD WriteInt( nInt ) CLASS TCgiFile

   LOCAL lSuccess := ( FWrite( ::nHandle, I2Bin( nInt ), 2 ) == 2 )

   RETURN lSuccess

METHOD WriteLong( nLong ) CLASS TCgiFile

   LOCAL lSuccess := ( FWrite( ::nHandle, L2Bin( nLong ), 4 ) == 4 )

   RETURN lSuccess

METHOD Goto( nLine ) CLASS TCgiFile

   LOCAL nCount := 1
   LOCAL nPos   := FPOS( ::Handle )

   ::GoTop()

   IF nLine < 0
      RETURN nPos
   ELSEIF nLine == 0
      nLine     := 1
      ::nRecord := 1
      ::GoTop()
      RETURN nPos
   ENDIF

   WHILE ! ::Eof()

      ::ReadLine()

      IF nCount == nLine
         EXIT
      ENDIF

      nCount++
   ENDDO

   RETURN nPos

METHOD Skip( nLines ) CLASS TCgiFile

   LOCAL nCount := 0
   LOCAL nPos   := FPOS( ::Handle )

   __defaultNIL( @nLines, 1 )

   IF nLines <= 0

      RETURN nPos

   ENDIF

   WHILE ! ::Eof()

      IF nCount == nLines
         EXIT
      ENDIF

      ::ReadLine()
      nCount++
   ENDDO

   RETURN nPos

METHOD MaxPages( nPageSize ) CLASS TCgiFile

   __defaultNIL( @nPageSize, ::nPageSize )

   RETURN ::Size() / nPageSize

METHOD PrevPage( nBytes ) CLASS TCgiFile

   __defaultNIL( @nBytes, 1024 )

   IF nBytes <= 0
      RETURN ""
   ENDIF

   IF ! ::Bof()
      FSeek( ::Handle, - nBytes, FS_RELATIVE )
      ::cPage := FReadStr( ::Handle, nBytes )
      FSeek( ::Handle, - nBytes, FS_RELATIVE )
      ::nPage --
   ENDIF

   RETURN ::cPage

METHOD NextPage( nBytes ) CLASS TCgiFile

   __defaultNIL( @nBytes, 1024 )

   IF nBytes <= 0
      RETURN ""
   ENDIF

   IF ! ::Eof()
      ::cPage := FReadStr( ::Handle, nBytes )
      ::nPage++
   ENDIF

   RETURN ::cPage

METHOD PrevLine( nBytes ) CLASS TCgiFile

   LOCAL fHandle    := ::Handle
   LOCAL nOrigPos   := FPOS( fHandle )
   LOCAL nMaxRead
   LOCAL nNewPos
   LOCAL lMoved
   LOCAL cBuff
   LOCAL nWhereCrLf
   LOCAL nPrev
   LOCAL cTemp

   __defaultNIL( @nBytes, 256 )

   IF nOrigPos == 0

      lMoved := .F.

   ELSE

      lMoved := .T.

      FSeek( fHandle, -2, FS_RELATIVE )
      cTemp := Space( 2 )
      FRead( fHandle, @cTemp, hb_BLen( cTemp ) )

      IF cTemp == CRLF()
         FSeek( fHandle, -2, FS_RELATIVE )
      ENDIF

      nMaxRead := Min( nBytes, FPOS( fHandle ) )

      cBuff   := Space( nMaxRead )
      nNewPos := FSeek( fHandle, -nMaxRead, FS_RELATIVE )
      FRead( fHandle, @cBuff, nMaxRead )
      nWhereCrLf := RAt( CRLF(), cBuff )
      IF nWhereCrLf == 0

         nPrev    := nNewPos
         ::Buffer := cBuff

      ELSE

         nPrev    := nNewPos + nWhereCrLf + 1
         ::Buffer := SubStr( cBuff, nWhereCrLf + 2 )

      ENDIF

      FSeek( fHandle, nPrev, FS_SET )

   ENDIF

   RETURN iif( lMoved, ::Buffer, "" )


[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User] Implement this Harbour module: Harbour contribution module 'hbzebra' (Barcode generation library): contrib/hbzebra/tests/cairo.prg. Provides functions: hb_zebra_draw_cairo. Contains procedures: Main, DrawBarcode. This file provides graphics and image processing capabilities

[Assistant]
#require "hbzebra"
#require "hbcairo"

PROCEDURE Main()

   LOCAL hCairo, hSurface

   hSurface := cairo_pdf_surface_create( hb_FNameExtSet( __FILE__, ".pdf" ), 567, 794 )

   hCairo := cairo_create( hSurface )
   cairo_set_source_rgb( hCairo, 1.0, 1.0, 1.0 )
   cairo_paint( hCairo )
   cairo_select_font_face( hCairo, "sans-serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL )
   cairo_set_font_size( hCairo, 10 )
   cairo_set_source_rgb( hCairo, 0, 0, 0 )

   DrawBarcode( hCairo,  20,   1, "EAN13",      "477012345678" )
   DrawBarcode( hCairo,  40,   1, "EAN8",       "1234567" )
   DrawBarcode( hCairo,  60,   1, "UPCA",       "01234567891" )
   DrawBarcode( hCairo,  80,   1, "UPCE",       "123456" )
   DrawBarcode( hCairo, 100,   1, "CODE39",     "ABC123" )
   DrawBarcode( hCairo, 120,   1, "CODE39",     "ABC123", HB_ZEBRA_FLAG_CHECKSUM )
   DrawBarcode( hCairo, 140, 0.5, "CODE39",     "ABC123", HB_ZEBRA_FLAG_CHECKSUM + HB_ZEBRA_FLAG_WIDE2_5 )
   DrawBarcode( hCairo, 160,   1, "CODE39",     "ABC123", HB_ZEBRA_FLAG_CHECKSUM + HB_ZEBRA_FLAG_WIDE3 )
   DrawBarcode( hCairo, 180,   1, "ITF",        "1234", HB_ZEBRA_FLAG_WIDE3 )
   DrawBarcode( hCairo, 200,   1, "ITF",        "12345678901", HB_ZEBRA_FLAG_CHECKSUM )
   DrawBarcode( hCairo, 220,   1, "MSI",        "1234" )
   DrawBarcode( hCairo, 240,   1, "MSI",        "1234", HB_ZEBRA_FLAG_CHECKSUM + HB_ZEBRA_FLAG_WIDE3 )
   DrawBarcode( hCairo, 260,   1, "MSI",        "1234567", HB_ZEBRA_FLAG_CHECKSUM )
   DrawBarcode( hCairo, 280,   1, "CODABAR",    "40156", HB_ZEBRA_FLAG_WIDE3 )
   DrawBarcode( hCairo, 300,   1, "CODABAR",    "-1234", HB_ZEBRA_FLAG_WIDE3 )
   DrawBarcode( hCairo, 320,   1, "CODE93",     "ABC-123" )
   DrawBarcode( hCairo, 340,   1, "CODE93",     "TEST93" )
   DrawBarcode( hCairo, 360,   1, "CODE11",     "12", HB_ZEBRA_FLAG_WIDE3 )
   DrawBarcode( hCairo, 380,   1, "CODE11",     "1234567890", HB_ZEBRA_FLAG_CHECKSUM + HB_ZEBRA_FLAG_WIDE3 )
   DrawBarcode( hCairo, 400,   1, "CODE128",    "Code 128" )
   DrawBarcode( hCairo, 420,   1, "CODE128",    "61300073570004616" )
   DrawBarcode( hCairo, 440,   1, "CODE128",    "Wikipedia" )
   DrawBarcode( hCairo, 460,   1, "PDF417",     "Hello, World of Harbour!!! It's 2D barcode PDF417 :)" )
   DrawBarcode( hCairo, 540,   1, "DATAMATRIX", "Hello, World of Harbour!!! It's 2D barcode DataMatrix :)" )
   DrawBarcode( hCairo, 580,   1, "QRCODE",     "https:
   cairo_destroy( hCairo )
   cairo_surface_write_to_png( hSurface, hb_FNameExtSet( __FILE__, ".png" ) )
   cairo_surface_destroy( hSurface )

   RETURN

PROCEDURE DrawBarcode( hCairo, nY, nLineWidth, cType, cCode, nFlags )

   LOCAL hZebra, nLineHeight, cTxt

   SWITCH cType
   CASE "EAN13"      ; hZebra := hb_zebra_create_ean13( cCode, nFlags )   ; EXIT
   CASE "EAN8"       ; hZebra := hb_zebra_create_ean8( cCode, nFlags )    ; EXIT
   CASE "UPCA"       ; hZebra := hb_zebra_create_upca( cCode, nFlags )    ; EXIT
   CASE "UPCE"       ; hZebra := hb_zebra_create_upce( cCode, nFlags )    ; EXIT
   CASE "CODE39"     ; hZebra := hb_zebra_create_code39( cCode, nFlags )  ; EXIT
   CASE "ITF"        ; hZebra := hb_zebra_create_itf( cCode, nFlags )     ; EXIT
   CASE "MSI"        ; hZebra := hb_zebra_create_msi( cCode, nFlags )     ; EXIT
   CASE "CODABAR"    ; hZebra := hb_zebra_create_codabar( cCode, nFlags ) ; EXIT
   CASE "CODE93"     ; hZebra := hb_zebra_create_code93( cCode, nFlags )  ; EXIT
   CASE "CODE11"     ; hZebra := hb_zebra_create_code11( cCode, nFlags )  ; EXIT
   CASE "CODE128"    ; hZebra := hb_zebra_create_code128( cCode, nFlags ) ; EXIT
   CASE "PDF417"     ; hZebra := hb_zebra_create_pdf417( cCode, nFlags ); nLineHeight := nLineWidth
   CASE "DATAMATRIX" ; hZebra := hb_zebra_create_datamatrix( cCode, nFlags ); nLineHeight := nLineWidth ; EXIT
   CASE "QRCODE"     ; hZebra := hb_zebra_create_qrcode( cCode, nFlags ); nLineHeight := nLineWidth ; EXIT
   ENDSWITCH
   IF hZebra != NIL
      IF hb_zebra_geterror( hZebra ) == 0
         IF Empty( nLineHeight )
            nLineHeight := 16
         ENDIF
         cairo_move_to( hCairo, 40, nY + 13 )
         cairo_show_text( hCairo, cType )
         IF Len( cTxt := hb_zebra_getcode( hZebra ) ) < 20
            cairo_move_to( hCairo, 100, nY + 13 )
            cairo_show_text( hCairo, cTxt )
         ENDIF
         hb_zebra_draw_cairo( hZebra, hCairo, 220, nY, nLineWidth, nLineHeight )
      ELSE
         ? "Type", cType, "Code", cCode, "Error", hb_zebra_geterror( hZebra )
      ENDIF
      hb_zebra_destroy( hZebra )
   ELSE
      ? "Invalid barcode type", cType
   ENDIF

   RETURN

STATIC FUNCTION hb_zebra_draw_cairo( hZebra, hCairo, ... )

   IF hb_zebra_geterror( hZebra ) != 0
      RETURN HB_ZEBRA_ERROR_INVALIDZEBRA
   ENDIF

   cairo_save( hCairo )
   hb_zebra_draw( hZebra, {| x, y, w, h | cairo_rectangle( hCairo, x, y, w, h ) }, ... )
   cairo_fill( hCairo )
   cairo_restore( hCairo )

   RETURN 0


[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User] Write Harbour functions: hb_osPathSeparator, hb_osNewLine, hb_OEMToANSI. Harbour contribution module 'xhb' (Extended Harbour functions): contrib/xhb/xhbdepr.prg. Provides 6 functions including: hb_osPathSeparator, hb_osNewLine, hb_OEMToANSI, hb_PCodeVer, hb_BuildDate. This file provides legacy compatibility functions

[Assistant]
#ifndef HB_LEGACY_LEVEL4

#include "hbver.ch"

FUNCTION hb_osPathSeparator()
   RETURN hb_ps()

FUNCTION hb_osNewLine()
   RETURN hb_eol()

FUNCTION hb_OEMToANSI( s )
#if defined( __PLATFORM__WINDOWS )
   RETURN win_OEMToANSI( s )
#else
   RETURN s
#endif

FUNCTION hb_PCodeVer()
   RETURN hb_Version( HB_VERSION_PCODE_VER_STR )

FUNCTION hb_BuildDate()
   RETURN hb_Version( HB_VERSION_BUILD_DATE_STR )

FUNCTION hb_regexMatch( ... )
   RETURN iif( HB_ISLOGICAL( hb_PValue( 5 ) ) .AND. hb_PValue( 5 ), ;
      hb_regexLike( ... ), ;
      hb_regexHas( ... ) )

#endif

#endif


[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User] Generate Harbour code for: Harbour test program: tests/byref.prg. Contains 5 procedures. This test file tests specific function APIs

[Assistant]
PROCEDURE Main()

   STATIC s_x := 10

   LOCAL x := 0

   ? "Managing LOCAL variables by reference"
   ? "In main before ref1 x=", x
   ref1( @x )
   ? " In main after ref1 x=", x

   ? "Managing STATIC variables by reference"
   ? "In main before ref1 s=", s_x
   ref1( @s_x )
   ? " In main after ref1 s=", s_x

   RETURN

PROCEDURE ref1( x )

   x++
   ? " In ref1 before ref2 =", x
   Ref2( @x )
   ? " In ref1 after ref2 =", x

   RETURN

PROCEDURE ref2( x )

   x++
   ? "  In ref2 before ref3 =", x
   Ref3( @x )
   ? "  In ref2 after ref3 =", x

   RETURN

PROCEDURE ref3( x )

   STATIC s_a

   x++
   ? "   In ref3 before ref4 =", x
   s_a := { x, x }
   Ref4( @s_a )
   ? "   In ref3 after ref4 =", x

   RETURN

PROCEDURE ref4( a )

   a[ 1 ]++
   ? "    In ref4 =", a[ 1 ]

   RETURN


[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User] Create Harbour OOP classes for the functionality described: Harbour contribution module 'hbtip' (Internet protocol utilities (FTP, HTTP, SMTP, POP3)): contrib/hbtip/log.prg. Defines classes: TIPLog. This file provides network protocol implementations

[Assistant]
#include "hbclass.ch"

#include "fileio.ch"

CREATE CLASS TIPLog

   METHOD New( cFileName )
   METHOD Add( cMsg )
   METHOD Close()
   METHOD Clear()

   PROTECTED:

   VAR cFileName
   VAR hFile     INIT NIL

ENDCLASS

METHOD New( cFileName ) CLASS TIPLog

   hb_default( @cFileName, "hbtip" )

   IF Set( _SET_DEFEXTENSIONS )
      cFileName := hb_FNameExtSetDef( cFileName, ".log" )
   ENDIF

   ::cFileName := cFileName

   RETURN Self

METHOD Add( cMsg ) CLASS TIPLog

   LOCAL cDir, cName, cExt
   LOCAL n

   IF ::hFile == NIL

      hb_FNameSplit( ::cFileName, @cDir, @cName, @cExt )

      n := 1
      DO WHILE ( ::hFile := hb_vfOpen( hb_FNameMerge( cDir, cName + "-" + hb_ntos( n++ ), cExt ), FO_CREAT + FO_EXCL + FO_WRITE ) ) == NIL .AND. ;
         FError() != 3
      ENDDO
   ENDIF

   IF ::hFile != NIL
      RETURN hb_vfWrite( ::hFile, cMsg ) == hb_BLen( cMsg )
   ENDIF

   RETURN .F.

METHOD Close() CLASS TIPLog

   LOCAL lRetVal

   IF ::hFile != NIL
      lRetVal := hb_vfClose( ::hFile )
      ::hFile := NIL
      RETURN lRetVal
   ENDIF

   RETURN .F.

METHOD Clear() CLASS TIPLog
   RETURN ::Close() .AND. hb_vfErase( ::cFileName ) != F_ERROR


[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User] Implement these Harbour functions: Harbour contribution module 'hbsms' (SMS sending via modem): contrib/hbsms/sms.prg. Provides 14 functions including: port_send, port_rece, sms_Send, sms_ReceiveAll, smsctx_New. This file provides utility functions

[Assistant]
STATIC FUNCTION port_send( h, s )
   RETURN hb_comSend( h, s )

STATIC FUNCTION port_rece( h, n, t )

   LOCAL cString

   hb_default( @n, 64 )
   hb_default( @t, 5 )

   cString := Space( n )

   hb_comRecv( h, @cString,, t )

   RETURN cString

FUNCTION sms_Send( cPort, cPhoneNo, cText, lNotification, cPIN )

   LOCAL smsctx
   LOCAL nRetVal

   IF ! Empty( smsctx := smsctx_New( cPort ) )
      smsctx_PIN( smsctx, cPIN )
      nRetVal := smsctx_Send( smsctx, cPhoneNo, cText, lNotification )
      smsctx_Close( smsctx )
   ELSE
      nRetVal := -99
   ENDIF

   RETURN nRetVal

FUNCTION sms_ReceiveAll( cPort, cPIN )

   LOCAL smsctx
   LOCAL aRetVal

   IF ! Empty( smsctx := smsctx_New( cPort ) )
      smsctx_PIN( smsctx, cPIN )
      aRetVal := smsctx_Receive( smsctx )
      smsctx_Close( smsctx )
   ELSE
      aRetVal := NIL
   ENDIF

   RETURN aRetVal

#define _SMSCTX_xHnd          1
#define _SMSCTX_cPIN          2
#define _SMSCTX_cPrevName     3
#define _SMSCTX_MAX_          3

FUNCTION smsctx_New( xPort )

   LOCAL smsctx[ _SMSCTX_MAX_ ]

   IF HB_ISNUMERIC( xPort )
      smsctx[ _SMSCTX_xHnd ] := xPort
      smsctx[ _SMSCTX_cPrevName ] := NIL
   ELSEIF HB_ISSTRING( xPort )
      smsctx[ _SMSCTX_xHnd ] := 1
      smsctx[ _SMSCTX_cPrevName ] := hb_comGetDevice( smsctx[ _SMSCTX_xHnd ] )
      hb_comSetDevice( smsctx[ _SMSCTX_xHnd ], xPort )
   ELSE
      smsctx[ _SMSCTX_xHnd ] := NIL
   ENDIF

   IF smsctx[ _SMSCTX_xHnd ] != NIL
      IF hb_comOpen( smsctx[ _SMSCTX_xHnd ] )
         IF hb_comInit( smsctx[ _SMSCTX_xHnd ], 9600, "N", 8, 1 )
            RETURN smsctx
         ELSE
            hb_comClose( smsctx[ _SMSCTX_xHnd ] )
         ENDIF
      ENDIF
   ENDIF

   RETURN NIL

FUNCTION smsctx_Close( smsctx )

   IF ! HB_ISARRAY( smsctx ) .OR. Len( smsctx ) != _SMSCTX_MAX_
      RETURN .F.
   ENDIF

   IF ! hb_comClose( smsctx[ _SMSCTX_xHnd ] )
      RETURN .F.
   ENDIF

   IF smsctx[ _SMSCTX_cPrevName ] != NIL
      hb_comSetDevice( smsctx[ _SMSCTX_xHnd ], smsctx[ _SMSCTX_cPrevName ] )
   ENDIF

   RETURN .T.

FUNCTION smsctx_Send( smsctx, cPhoneNo, cText, lNotification )

   LOCAL tmp

   IF ! HB_ISARRAY( smsctx ) .OR. Len( smsctx ) != _SMSCTX_MAX_
      RETURN -1
   ENDIF

   port_send( smsctx[ _SMSCTX_xHnd ], "ATE0V1Q0" + Chr( 13 ) )
   IF IsOK( port_rece( smsctx[ _SMSCTX_xHnd ] ) )

      port_send( smsctx[ _SMSCTX_xHnd ], "AT+CMGF=1" + Chr( 13 ) )
      IF StripCRLF( port_rece( smsctx[ _SMSCTX_xHnd ] ) ) == "OK"

         IF ! Empty( smsctx[ _SMSCTX_cPIN ] )
            port_send( smsctx[ _SMSCTX_xHnd ], 'AT+CPIN="' + smsctx[ _SMSCTX_cPIN ] + '"' + Chr( 13 ) )
            IF !( StripCRLF( port_rece( smsctx[ _SMSCTX_xHnd ] ) ) == "OK" )
               RETURN -5
            ENDIF
         ENDIF

         port_send( smsctx[ _SMSCTX_xHnd ], "AT+CMGF=1" + Chr( 13 ) )
         IF StripCRLF( port_rece( smsctx[ _SMSCTX_xHnd ] ) ) == "OK"

            IF HB_ISLOGICAL( lNotification )
               port_send( smsctx[ _SMSCTX_xHnd ], "AT+CSMP?" + Chr( 13 ) )
               tmp := GetLines( port_rece( smsctx[ _SMSCTX_xHnd ] ) )
               IF Len( tmp ) < 2
                  RETURN -6
               ENDIF
               IF !( ATail( tmp ) == "OK" )
                  RETURN -7
               ENDIF
               IF !( Left( tmp[ 1 ], Len( "+CSMP: " ) ) == "+CSMP: " )
                  RETURN -8
               ENDIF
               tmp := GetList( SubStr( tmp[ 1 ], Len( "+CSMP: " ) + 1 ) )
               IF Len( tmp ) > 1
                  IF lNotification
                     tmp[ 1 ] := hb_ntos( hb_bitSet( Val( tmp[ 1 ] ), 5 ) )
                  ELSE
                     tmp[ 1 ] := hb_ntos( hb_bitReset( Val( tmp[ 1 ] ), 5 ) )
                  ENDIF
                  port_send( smsctx[ _SMSCTX_xHnd ], "AT+CSMP=" + MakeList( tmp ) + Chr( 13 ) )
                  IF !( StripCRLF( port_rece( smsctx[ _SMSCTX_xHnd ] ) ) == "OK" )
                     RETURN -9
                  ENDIF
               ENDIF
            ENDIF

            port_send( smsctx[ _SMSCTX_xHnd ], 'AT+CMGS="' + cPhoneNo + '"' + Chr( 13 ) )
            IF StripCRLF( port_rece( smsctx[ _SMSCTX_xHnd ] ) ) == "> "
               port_send( smsctx[ _SMSCTX_xHnd ], StrTran( cText, Chr( 13 ) ) + Chr( 26 ) )
               tmp := StripCRLF( port_rece( smsctx[ _SMSCTX_xHnd ] ) )
               IF Left( tmp, Len( "+CMGS: " ) ) == "+CMGS: "
                  RETURN 0
               ELSE
                  RETURN -10
               ENDIF
            ELSE
               RETURN -11
            ENDIF
         ELSE
            RETURN -12
         ENDIF
      ELSE
         RETURN -4
      ENDIF
   ELSE
      RETURN -3
   ENDIF

   RETURN -2

FUNCTION smsctx_Receive( smsctx )

   IF ! HB_ISARRAY( smsctx ) .OR. Len( smsctx ) != _SMSCTX_MAX_
      RETURN NIL
   ENDIF

   RETURN {}

FUNCTION smsctx_PIN( smsctx, cPIN )

   LOCAL cOldValue

   IF ! HB_ISARRAY( smsctx ) .OR. Len( smsctx ) != _SMSCTX_MAX_
      RETURN NIL
   ENDIF

   cOldValue := smsctx[ _SMSCTX_cPIN ]
   IF cPIN == NIL .OR. ( HB_ISSTRING( cPIN ) .AND. Len( cPIN ) == 4 )
      smsctx[ _SMSCTX_cPIN ] := cPIN
   ENDIF

   RETURN cOldValue

STATIC FUNCTION StripCRLF( cString )
   RETURN StrTran( cString, Chr( 13 ) + Chr( 10 ) )

STATIC FUNCTION IsOK( cString )

   LOCAL tmp := GetLines( cString )

   RETURN ! Empty( tmp ) .AND. ATail( tmp ) == "OK"

STATIC FUNCTION GetLines( cString )

   LOCAL aLine := {}
   LOCAL tmp

   IF Left( cString, 2 ) == Chr( 13 ) + Chr( 10 )
      cString := SubStr( cString, Len( Chr( 13 ) + Chr( 10 ) ) + 1 )
   ENDIF
   IF Right( cString, 2 ) == Chr( 13 ) + Chr( 10 )
      cString := hb_StrShrink( cString, Len( Chr( 13 ) + Chr( 10 ) ) )
   ENDIF

   FOR EACH tmp IN hb_ATokens( StrTran( cString, Chr( 13 ) ), Chr( 10 ) )
      AAdd( aLine, tmp )
   NEXT

   RETURN aLine

STATIC FUNCTION GetList( cString )

   LOCAL aList := {}
   LOCAL tmp

   FOR EACH tmp IN hb_ATokens( cString, "," )
      AAdd( aList, tmp )
   NEXT

   RETURN aList

STATIC FUNCTION MakeList( aList )

   LOCAL cString := ""
   LOCAL tmp

   FOR EACH tmp IN aList
      cString += tmp + ","
   NEXT

   RETURN hb_StrShrink( cString, Len( "," ) )


[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User] Generate Harbour code for: Harbour contribution module 'hbnf' (NanForum Toolkit - legacy Clipper compatibility functions): contrib/hbnf/tests/miltime.prg. Contains procedures: Main. This file provides legacy compatibility functions

[Assistant]
#require "hbnf"

PROCEDURE Main()

   CLS
   ? "am-pm"
   ? ft_Civ2Mil( " 5:40 pm" )
   ? ft_Civ2Mil( "05:40 pm" )
   ? ft_Civ2Mil( " 5:40 PM" )
   ? ft_Civ2Mil( " 5:40 am" )
   ? ft_Civ2Mil( "05:40 am" )
   ? ft_Civ2Mil( " 5:40 AM" )
   ?
   Inkey( 0 )
   CLS
   ? "noon-midnight"
   ? ft_Civ2Mil( "12:00 m" )
   ? ft_Civ2Mil( "12:00 M" )
   ? ft_Civ2Mil( "12:00 m" )
   ? ft_Civ2Mil( "12:00 n" )
   ? ft_Civ2Mil( "12:00 N" )
   ? ft_Civ2Mil( "12:00 n" )
   ?
   Inkey( 0 )
   CLS
   ? "errors in noon-midnight"
   ? ft_Civ2Mil( "12:01 n" )
   ? ft_Civ2Mil( "22:00 n" )
   ? ft_Civ2Mil( "12:01 m" )
   ? ft_Civ2Mil( "22:00 n" )
   ?
   ? "sys to mil"
   ? Time()
   ? ft_Sys2Mil()

   RETURN


[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User] Write a Harbour program with procedures: Main, test. Harbour contribution module 'hbsqlit3' (SQLite3 database client library): contrib/hbsqlit3/tests/metadata.prg. Contains procedures: Main, test. This file handles database operations

[Assistant]
#require "hbsqlit3"

PROCEDURE Main()

   LOCAL lCreateIfNotExist := .F.
   LOCAL db := sqlite3_open( "new.s3db", lCreateIfNotExist )

   IF ! Empty( db )
      test( db )
   ENDIF

   RETURN

PROCEDURE test( db )

   IF sqlite3_exec( db, "SELECT * FROM t1" ) == SQLITE_OK
      ? "TABLE t1"

#ifdef SQLITE_ENABLE_COLUMN_METADATA
      ? "Column name :                id"
      ? "Declared data type:         ", sqlite3_table_column_metadata( db,, "t1", "id" )[ 1 ]
      ? "Collation sequence name:    ", sqlite3_table_column_metadata( db,, "t1", "id" )[ 2 ]
      ? "NOT NULL constraint exists: ", sqlite3_table_column_metadata( db,, "t1", "id" )[ 3 ]
      ? "Column is part of PK:       ", sqlite3_table_column_metadata( db,, "t1", "id" )[ 4 ]
      ? "Column is auto-increment:   ", sqlite3_table_column_metadata( db,, "t1", "id" )[ 5 ]

      ? "Column name :                name"
      ? "Declared data type:         ", sqlite3_table_column_metadata( db,, "t1", "name" )[ 1 ]
      ? "Collation sequence name:    ", sqlite3_table_column_metadata( db,, "t1", "name" )[ 2 ]
      ? "NOT NULL constraint exists: ", sqlite3_table_column_metadata( db,, "t1", "name" )[ 3 ]
      ? "Column is part of PK:       ", sqlite3_table_column_metadata( db,, "t1", "name" )[ 4 ]
      ? "Column is auto-increment:   ", sqlite3_table_column_metadata( db,, "t1", "name" )[ 5 ]
#endif

      sqlite3_sleep( 3000 )
   ENDIF

   RETURN


[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User] Implement this Harbour module: Harbour test program: tests/initexit.prg. Contains procedures: Main, initStatics. This test file tests specific function APIs

[Assistant]
STATIC s_static_var_accessed_in_INIT_function := 10000.15
MEMVAR p_initStatics

PROCEDURE Main()

   STATIC s_static_var := "MAIN()"

   ? "Hello from:", s_static_var
   s_static_var_accessed_in_INIT_function++
   ? "global static=", s_static_var_accessed_in_INIT_function

   ? "PUBLIC variable created in INIT PROCEDURE=", p_initStatics

   RETURN

INIT FUNCTION SecondOne()

   STATIC s_static_var := "SECOND()"

   ? "Hello from:", s_static_var
   s_static_var_accessed_in_INIT_function++
   ? "global static=", s_static_var_accessed_in_INIT_function

   RETURN NIL

INIT FUNCTION Third()

   STATIC s_static_var := "THIRD()"

   ? "Hello from:", s_static_var
   s_static_var_accessed_in_INIT_function++
   ? "global static=", s_static_var_accessed_in_INIT_function

   RETURN NIL

EXIT FUNCTION Fifth()

   STATIC s_static_var := "FIFTH()"

   ? "Hello from:", s_static_var
   s_static_var_accessed_in_INIT_function--
   ? "global static=", s_static_var_accessed_in_INIT_function

   RETURN NIL

EXIT FUNCTION Sixth()

   STATIC s_static_var := "SIXTH()"

   ? "Hello from:", s_static_var
   s_static_var_accessed_in_INIT_function--
   ? "global static=", s_static_var_accessed_in_INIT_function

   RETURN NIL

INIT PROCEDURE initStatics()

   PUBLIC p_initStatics := "P_INITSTATICS"

   RETURN


[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User] Implement this Harbour module: Harbour header file: include/hbextern.ch. Defines constants: HB_EXTERN_CH_, __HBEXTERN__HARBOUR__REQUEST. Defines Harbour internal constants and macros

[Assistant]
#ifndef HB_EXTERN_CH_
#define HB_EXTERN_CH_

#define __HBEXTERN__HARBOUR__REQUEST
#include "harbour.hbx"

#include "hbextcdp.ch"
#include "hbextlng.ch"

#endif


[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User] Generate Harbour code for: Harbour contribution module 'hbnf' (NanForum Toolkit - legacy Clipper compatibility functions): contrib/hbnf/tests/clrsel.prg. Contains procedures: Main. This file provides legacy compatibility functions

[Assistant]
#require "hbnf"

#include "setcurs.ch"

PROCEDURE Main( cVidMode )

   LOCAL nRowOri := Row()
   LOCAL nColOri := Col()
   LOCAL aEnvOri := ft_SaveSets()
   LOCAL cScrOri := SaveScreen( 0, 0, MaxRow(), MaxCol() )
   LOCAL lColour
   LOCAL aClrs

   Set( _SET_DATEFORMAT, "yyyy-mm-dd" )

   __defaultNIL( @cVidMode, "" )

   NoSnow( ( "NOSNOW" $ Upper( cVidMode ) ) )
   IF "VGA" $ Upper( cVidMode )
      SetMode( 50, 80 )
   ENDIF
   IF "EGA" $ Upper( cVidMode )
      SetMode( 43, 80 )
   ENDIF
   lColour := iif( "MONO" $ Upper( cVidMode ), .F., IsColor() )

   SET SCOREBOARD OFF
   SetCursor( SC_NONE )
   SetBlink( .F. )

   aClrs := { ;
      { "Desktop",        "N/BG",                          "D", hb_UTF8ToStrBox( "░" ) }, ;
      { "Title",          "N/W",                           "T" }, ;
      { "Top Menu",       "N/BG,N/W,W+/BG,W+/N,GR+/N",     "M" }, ;
      { "Sub Menu",       "W+/N*,GR+/N*,GR+/N*,W+/R,G+/R", "M" }, ;
      { "Standard Gets",  "W/B,  W+/N,,, W/N",             "G" }, ;
      { "Nested Gets",    "N/BG, W+/N,,, W/N",             "G" }, ;
      { "Help",           "N/G,  W+/N,,, W/N",             "W" }, ;
      { "Error Messages", "W+/R*,N/GR*,,,N/R*",            "W" }, ;
      { "Database Query", "N/BG, N/GR*,,,N+/BG",           "B" }, ;
      { "Pick List",      "N/GR*,W+/B,,, BG/GR*",          "A" } }

   aClrs := ft_ClrSel( aClrs, lColour )

   HB_SYMBOL_UNUSED( aClrs )

   ft_RestSets( aEnvOri )
   RestScreen( 0, 0, MaxRow(), MaxCol(), cScrOri )
   SetPos( nRowOri, nColOri )
   SetBlink( .F. )

   RETURN


[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User] Implement the following Harbour classes: Character, Numeric, Array. Harbour contribution module 'xhb' (Extended Harbour functions): contrib/xhb/xhbcomp.prg. Defines classes: Character, Numeric, Array, Hash, Block. Contains procedures: xhb_Init. This file provides legacy compatibility functions

[Assistant]
#include "hbclass.ch"

ANNOUNCE XHB_LIB

#xcommand OPTIONAL INHERIT <!className!> =>                 ;
            IF hb_IsFunction( <"className"> )              ;;
               AAdd( oClass:asSuper, @__<className>() )    ;;
            ENDIF

INIT PROCEDURE xhb_Init()

   ASSOCIATE CLASS _Character    WITH TYPE Character
   ASSOCIATE CLASS _Numeric      WITH TYPE Numeric
   ASSOCIATE CLASS _Array        WITH TYPE Array
   ASSOCIATE CLASS _Hash         WITH TYPE Hash
   ASSOCIATE CLASS _Block        WITH TYPE Block

   RETURN

CREATE CLASS Character FUNCTION _Character

   OPTIONAL INHERIT HBCharacter
   OPERATOR "[]" FUNCTION xhb_Index()
   OPERATOR "+"  FUNCTION xhb_Plus()
   OPERATOR "-"  FUNCTION xhb_Minus()
   OPERATOR "*"  FUNCTION xhb_Mult()
   OPERATOR "/"  FUNCTION xhb_Div()
   OPERATOR "%"  FUNCTION xhb_Mod()
   OPERATOR "^"  FUNCTION xhb_Pow()
   OPERATOR "++" FUNCTION xhb_Inc()
   OPERATOR "--" FUNCTION xhb_Dec()

   OPERATOR "==" FUNCTION xhb_EEqual()
   OPERATOR "="  FUNCTION xhb_Equal()
   OPERATOR "<>" FUNCTION xhb_NotEqual()
   OPERATOR "<"  FUNCTION xhb_Less()
   OPERATOR "<=" FUNCTION xhb_LessEq()
   OPERATOR ">"  FUNCTION xhb_Greater()
   OPERATOR ">=" FUNCTION xhb_GreaterEq()

ENDCLASS

CREATE CLASS Numeric FUNCTION _Numeric

   OPTIONAL INHERIT HBNumeric
   OPERATOR "+"  FUNCTION xhb_Plus()
   OPERATOR "-"  FUNCTION xhb_Minus()
   OPERATOR "*"  FUNCTION xhb_Mult()
   OPERATOR "/"  FUNCTION xhb_Div()
   OPERATOR "%"  FUNCTION xhb_Mod()
   OPERATOR "^"  FUNCTION xhb_Pow()
   OPERATOR "++" FUNCTION xhb_Inc()
   OPERATOR "--" FUNCTION xhb_Dec()

   OPERATOR "==" FUNCTION xhb_EEqual()
   OPERATOR "="  FUNCTION xhb_Equal()
   OPERATOR "<>" FUNCTION xhb_NotEqual()
   OPERATOR "<"  FUNCTION xhb_Less()
   OPERATOR "<=" FUNCTION xhb_LessEq()
   OPERATOR ">"  FUNCTION xhb_Greater()
   OPERATOR ">=" FUNCTION xhb_GreaterEq()

ENDCLASS

CREATE CLASS Array FUNCTION _Array

   OPTIONAL INHERIT HBArray
   OPERATOR "[]" FUNCTION xhb_Index()
   OPERATOR "$$" FUNCTION xhb_Include()

ENDCLASS

CREATE CLASS Hash INHERIT __HBHash FUNCTION _Hash

   OPTIONAL INHERIT HBHash
   ON ERROR FUNCTION xhb_HashError()
   OPERATOR "+"  FUNCTION xhb_Plus()
   OPERATOR "-"  FUNCTION xhb_Minus()
   OPERATOR "$$" FUNCTION xhb_Include()
   OPERATOR "="  FUNCTION xhb_Equal()
   OPERATOR "<>" FUNCTION xhb_NotEqual()

ENDCLASS

CREATE CLASS Block FUNCTION _Block

   OPTIONAL INHERIT HBBlock
   OPERATOR "==" FUNCTION xhb_EEqual()

ENDCLASS


[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User] Generate Harbour code for: Harbour test program: tests/inherit.prg. Provides 10 functions including: TEmpty, TOnTop, TTextFile, New, RUN. Contains procedures: Main. This test file tests object-oriented programming features

[Assistant]
#include "fileio.ch"

PROCEDURE Main()

   LOCAL oFrom
   LOCAL oTo
   LOCAL cOut

   oFrom := TOnTop()   :New( __FILE__, "R" )
   oTo   := TTextFile():New( hb_FNameExtSet( __FILE__, ".out" ), "W" )

   ? "What's in oFrom"
   ? hb_ValToExp( { oFrom, __objGetMethodList( oFrom ) } )

   ?
   ? "What's in oFrom:TEmpty"
   ? hb_ValToExp( { oFrom:TEmpty, __objGetMethodList( oFrom:TEmpty ) } )

   ?
   ? "Let's call Run() from TEmpty:"
   oFrom:TEmpty:Run()

   ?
   ? "Let's call a method from TEmpty and one from TOnTop"
   oFrom:Set( "Done !" )
   oFrom:Say( "Out" )

   ?
   ? "Basic copy loop using the default Run() from TTextFile"
   DO WHILE ! oFrom:lEoF
      cOut := oFrom:Run()
      ? cOut
      oTo:Run( cOut )
   ENDDO
   oFrom:Dispose()
   oTo:Dispose()

   RETURN

FUNCTION TEmpty()

   STATIC oEmpty

   IF oEmpty == NIL
      oEmpty := HBClass():New( "TEmpty" )

      oEmpty:AddInline( "New", {| Self | Self } )

      oEmpty:AddInline( "Run", {|| QOut( "Run !" ) } )
      oEmpty:AddInline( "Set", {| Self, xParam | ::Out := xParam } )
      oEmpty:AddData( "Out", "Hi there" )
      oEmpty:AddVirtual( "Dispose" )

      oEmpty:Create()
   ENDIF

   RETURN oEmpty:Instance()

FUNCTION TOnTop()

   STATIC oOnTop

   IF oOnTop == NIL
      oOnTop := HBClass():New( "TOnTop", "TTextFile" )
      oOnTop:AddInline( "Say", {| Self, cArg | QOut( __objSendMsg( Self, cArg ) ) } )
      oOnTop:Create()
   ENDIF

   RETURN oOnTop:Instance()

FUNCTION TTextFile()

   STATIC oFile

   IF oFile == NIL
      oFile := HBClass():New( "TTextFile", "TEmpty" )

      oFile:AddData( "cFileName"  )
      oFile:AddData( "hFile"      )
      oFile:AddData( "nLine"      )
      oFile:AddData( "nError"     )
      oFile:AddData( "lEoF"       )
      oFile:AddData( "cBlock"     )
      oFile:AddData( "nBlockSize" )
      oFile:AddData( "cMode"      )

      oFile:AddMethod( "New"    , @New()     )
      oFile:AddMethod( "Run"    , @Run()     )
      oFile:AddMethod( "Dispose", @Dispose() )
      oFile:AddMethod( "Read"   , @Read()    )
      oFile:AddMethod( "WriteLn", @WriteLn() )
      oFile:AddMethod( "Write"  , @Write()   )
      oFile:AddMethod( "Goto"   , @Goto()    )

      oFile:Create()
   ENDIF

   RETURN oFile:Instance()

FUNCTION New( cFileName, cMode, nBlock )

   LOCAL Self := QSelf()

   hb_default( @cMode, "R" )
   hb_default( @nBlock, 4096 )

   ::nLine     := 0
   ::lEoF      := .F.
   ::cBlock    := ""
   ::cFileName := cFileName
   ::cMode     := cMode

   IF ::cMode == "R"
      ::hFile := FOpen( cFileName )
   ELSEIF ::cMode == "W"
      ::hFile := FCreate( cFileName )
   ELSE
      ? "DosFile Init: Unknown file mode:", ::cMode
   ENDIF

   ::nError := FError()
   IF ::nError != 0
      ::lEoF := .T.
      ? "Error ", ::nError
   ENDIF
   ::nBlockSize := nBlock

   RETURN Self

FUNCTION RUN( xTxt, lCRLF )

   LOCAL Self := QSelf()
   LOCAL xRet

   IF ::cMode == "R"
      xRet := ::Read()
   ELSE
      xRet := ::WriteLn( xTxt, lCRLF )
   ENDIF

   RETURN xRet

FUNCTION Dispose()

   LOCAL Self := QSelf()

   ::cBlock := NIL
   IF ::hFile != F_ERROR
      IF ! FClose( ::hFile )
         ::nError := FError()
         ? "Dos Error closing ", ::cFileName, " Code ", ::nError
      ENDIF
   ENDIF

   RETURN Self

FUNCTION READ()

   LOCAL Self := QSelf()
   LOCAL cRet := ""
   LOCAL cBlock
   LOCAL nCrPos
   LOCAL nEoFPos

   IF ::hFile == F_ERROR
      ? "DosFile:Read : No file open"
   ELSEIF !( ::cMode == "R" )
      ? "File ", ::cFileName, " not open for reading"
   ELSEIF ! ::lEoF

      IF Len( ::cBlock ) == 0
         cBlock := FReadStr( ::hFile, ::nBlockSize )
         IF Len( cBlock ) == 0
            ::nError := FError()
            ::lEoF   := .T.
         ELSE
            ::cBlock := cBlock
         ENDIF
      ENDIF

      IF ! ::lEoF
         ::nLine++
         nCRPos := At( Chr( 10 ), ::cBlock )
         IF nCRPos != 0
            cRet     := SubStr( ::cBlock, 1, nCRPos - 1 )
            ::cBlock := SubStr( ::cBlock, nCRPos + 1 )
         ELSE
            cRet     := ::cBlock
            ::cBlock := ""
            cRet     += ::Read()
            IF ! ::lEoF
               ::nLine--
            ENDIF
         ENDIF
         nEoFPos := hb_BAt( Chr( 26 ), cRet )
         IF nEoFPos != 0
            cRet   := hb_BSubStr( cRet, 1, nEoFPos - 1 )
            ::lEoF := .T.
         ENDIF
         cRet := StrTran( cRet, Chr( 13 ) )
      ENDIF
   ENDIF

   RETURN cRet

FUNCTION WriteLn( xTxt, lCRLF )

   LOCAL Self := QSelf()
   LOCAL cBlock

   IF ::hFile == F_ERROR
      ? "DosFile:Write : No file open"
   ELSEIF !( ::cMode == "W" )
      ? "File ", ::cFileName, " not opened for writing"
   ELSE
      hb_default( @lCRLF, .T. )
      cBlock := hb_ValToExp( xTxt )
      IF lCRLF
         cBlock += hb_eol()
      ENDIF
      FWrite( ::hFile, cBlock, Len( cBlock ) )
      IF FError() != 0
         ::nError := FError()
      ENDIF
      ::nLine := ::nLine + 1
   ENDIF

   RETURN Self

FUNCTION Write( xTxt )

   LOCAL Self := QSelf()

   RETURN ::WriteLn( xTxt, .F. )

STATIC FUNCTION GOTO( nLine )

   LOCAL Self   := QSelf()
   LOCAL nWhere := 1

   IF Empty( ::hFile )
      ? "DosFile:Goto : No file open"
   ELSEIF !( ::cMode == "R" )
      ? "File ", ::cFileName, " not open for reading"
   ELSE
      ::lEoF   := .F.
      ::nLine  := 0
      ::cBlock := ""
      FSeek( ::hFile, 0 )
      DO WHILE ! ::lEoF .AND. nWhere < nLine
         nWhere++
         ::Read()
      ENDDO
   ENDIF

   RETURN ! ::lEoF


[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User] Create Harbour preprocessor definitions: Harbour contribution module 'hbmagic' (): contrib/hbmagic/tests/hbmagit.prg. Contains procedures: Main. This file implements security and encryption functions

[Assistant]
#require "hbmagic"

#xcommand T( <(title)>, <(subject)> ) => ;
   magic_setflags( hMagic, MAGIC_NONE ) ;;
   OutStd( hb_StrFormat( <title> + ": t: [%s] ", magic_buffer( hMagic, <subject> ) ) ) ;;
   magic_setflags( hMagic, MAGIC_MIME_TYPE ) ;;
   OutStd( hb_StrFormat( "m: [%s]", magic_buffer( hMagic, <subject> ) ) + hb_eol() )

PROCEDURE Main()

   LOCAL cJpeg, cPng, cGif, cElf, cExe, cCom, cText
   LOCAL hMagic

   cJpeg := hb_base64Decode( ;
      "/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEB" + ;
      "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/2wBDAQEBAQEBAQEBAQEBAQEBAQEBAQEB" + ;
      "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/wAARCAABAAEDASIA" + ;
      "AhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQA" + ;
      "AAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3" + ;
      "ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWm" + ;
      "p6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEA" + ;
      "AwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSEx" + ;
      "BhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElK" + ;
      "U1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3" + ;
      "uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD+/iii" + ;
      "igD/2Q==" )

   cPng := hb_base64Decode( ;
      "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAAAXNSR0IArs4c6QAAAAxJREFUCNdj" + ;
      "+P

   cGif := hb_base64Decode( ;
      "R0lGODdhAQABAIAAAP

   cElf := hb_base64Decode( ;
      "f0VMRgIBAQAAAAAAAAAAAAIAPgABAAAA4CZAAAAAAAA=" )

   cExe := hb_base64Decode( ;
      "TVpAAAEAAAAGAAAA

   cCom := hb_base64Decode( ;
      "6fEAUE1PREUvVyBWZXJzaW9uIENoZWNrIFV0aWxpdHk=" )

   cText := hb_base64Decode( ;
      "H4sICONj7UwCA3Rlc3QAjVFba8IwGH3vr/ioDFosE4YM5qUQayaKtfWyh22M0qZpjWsbMSnz5y+p" + ;
      "MjcfhoEcksN3LiFGi1WkqFMKJuFlyat7sjWNC7lNyjhn5IoVrNwXlPGGNlpHLY2rFDYWDCzJZEFt" + ;
      "11FHUSc7SqTtgg1DF/oG/KzGNhJUZkWcCwu2viYc8NFk6kWLYIGVpv9bEdRyLVM1mURCHp75oYyl" + ;
      "ymviXGiD2QPZg/c78QGmc/ZP6iyjh4v74NxIF7KvA/6v5E99HG1ewxt7meWpy41V2lpOeWGpi2GE" + ;
      "q8DD45cVBj9mlaUYlTMPPDQHMtvT3AESVhonLFOIiwaPVKHHy8vwKatRNzroDXVOEgv62E0p4Sm1" + ;
      "/vwKgNl52nW6CC3Xn2+zVY5GaInRGo2mCI07D1+jMUJYczdtU72rb3wD2wEd8GQCAAA=" )

   hMagic := magic_open()
   IF Empty( hMagic ) .OR. magic_load( hMagic ) != 0
      OutStd( "magic_open()/magic_load() failed" + hb_eol() )
      QUIT
   ENDIF

   T( "JPEG Image", cJpeg )
   T( "PNG Image", cPng )
   T( "GIF Image", cGif )
   T( "ELF binary", cElf )
   T( "EXE binary", cExe )
   T( "COM binary", cCom )
   T( "Short buffer", " " )
   T( "Empty buffer", "" )
   T( "Null buffer", NIL )
   T( "Compressed data", cText )
   cText := hb_ZUncompress( cText )
   T( "Plain text", cText )

   OutStd( "hb_magic_simple(): t: [" + hb_magic_simple( hb_argv( 0 ), MAGIC_NONE ) + "] " + ;
      "m: [" + hb_magic_simple( hb_argv( 0 ), MAGIC_MIME_TYPE ) + "]" + hb_eol() )

   RETURN


[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User] Generate Harbour code for: Harbour contribution module 'hbnf' (NanForum Toolkit - legacy Clipper compatibility functions): contrib/hbnf/tests/aemaxlen.prg. Contains procedures: Main. This file provides legacy compatibility functions

[Assistant]
#require "hbnf"

PROCEDURE Main()

   LOCAL var0, myarray1 := Directory()

   CLS
   ? "TEST TO DEMONSTRATE EXAMPLES OF FT_AEMAXLEN"
   ?
   ? "myarray1 := Directory()"
   ?
   var0 := ft_AEMaxLen( myarray1 )
   ? PadR( "ft_AEMaxLen( myarray1 ) ->", 30 )
   ?? var0
   ?
   var0 := ft_AEMaxLen( myarray1, 2 )
   ? PadR( "ft_AEMaxLen( myarray1, 2 ) ->", 30 )
   ?? var0
   ?
   var0 := ft_AEMaxLen( myarray1, 3 )
   ? PadR( "ft_AEMaxLen( myarray1, 3 ) ->", 30 )
   ?? var0
   ?
   var0 := ft_AEMaxLen( ATail( myarray1 ) )
   ? PadR( "ft_AEMaxLen( ATail( myarray1 ) ) ->", 30 )
   ?? var0
   ?

   RETURN


[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User] Define Harbour macros and constants: Harbour header file: extras/hbvpdf/hbvpdf.ch. Defines 10 constants including: HBVPDF_CH, NORMAL, BOLD, ITALIC, BOLDITALIC. Defines file I/O constants

[Assistant]
#ifndef HBVPDF_CH
#define HBVPDF_CH

#define NORMAL        0
#define BOLD          1
#define ITALIC        2
#define BOLDITALIC    3

#define BOOKLEVEL     1
#define BOOKTITLE     2
#define BOOKPARENT    3
#define BOOKPREV      4
#define BOOKNEXT      5
#define BOOKFIRST     6
#define BOOKLAST      7
#define BOOKCOUNT     8
#define BOOKPAGE      9
#define BOOKCOORD     10

#define FONTNAME      1
#define FONTSIZE      2
#define LPI           3
#define PAGESIZE      4
#define PAGEORIENT    5
#define PAGEX         6
#define PAGEY         7
#define REPORTWIDTH   8
#define REPORTPAGE    9
#define REPORTLINE    10
#define FONTNAMEPREV  11
#define FONTSIZEPREV  12
#define PAGEBUFFER    13
#define REPORTOBJ     14
#define DOCLEN        15
#define TYPE1         16
#define MARGINS       17
#define HEADEREDIT    18
#define NEXTOBJ       19
#define PDFTOP        20
#define PDFLEFT       21
#define PDFBOTTOM     22
#define HANDLE        23
#define PAGES         24
#define REFS          25
#define BOOKMARK      26
#define HEADER        27
#define FONTS         28
#define IMAGES        29
#define PAGEIMAGES    30
#define PAGEFONTS     31
#define FONTWIDTH     32
#define OPTIMIZE      33
#define PDFCPI        34
#define PARAMLEN      34

#define ALIGN_LEFT    1
#define ALIGN_CENTER  2
#define ALIGN_RIGHT   3
#define ALIGN_JUSTIFY 4

#define IMAGE_WIDTH   1
#define IMAGE_HEIGHT  2
#define IMAGE_XRES    3
#define IMAGE_YRES    4
#define IMAGE_BITS    5
#define IMAGE_FROM    6
#define IMAGE_LENGTH  7
#define IMAGE_SPACE   8

#define BYTE          1
#define ASCII         2
#define SHORT         3
#define LONG          4
#define RATIONAL      5
#define SBYTE         6
#define UNDEFINED     7
#define SSHORT        8
#define SLONG         9
#define SRATIONAL     10
#define FLOAT         11
#define DOUBLE        12

#define pdf_ALICEBLUE            "F0F8FF"
#define pdf_ANTIQUEWHITE         "FAEBD7"
#define pdf_AQUA                 "00FFFF"
#define pdf_AQUAMARINE           "7FFFD4"
#define pdf_AZURE                "F0FFFF"
#define pdf_BEIGE                "F5F5DC"
#define pdf_BISQUE               "FFE4C4"
#define pdf_BLACK                "000000"
#define pdf_BLANCHEDALMOND       "FFEBCD"
#define pdf_BLUE                 "0000FF"
#define pdf_BLUEVIOLET           "8A2BE2"
#define pdf_BROWN                "A52A2A"
#define pdf_BURLYWOOD            "DEB887"
#define pdf_CADETBLUE            "5F9EA0"
#define pdf_CHARTREUSE           "7FFF00"
#define pdf_CHOCOLATE            "D2691E"
#define pdf_CORAL                "FF7F50"
#define pdf_CORNFLOWERBLUE       "6495ED"
#define pdf_CORNSILK             "FFF8DC"
#define pdf_CRIMSON              "DC143C"
#define pdf_CYAN                 "00FFFF"
#define pdf_DARKBLUE             "00008B"
#define pdf_DARKCYAN             "008B8B"
#define pdf_DARKGOLDENROD        "B8860B"
#define pdf_DARKGRAY             "A9A9A9"
#define pdf_DARKGREEN            "006400"
#define pdf_DARKKHAKI            "BDB76B"
#define pdf_DARKMAGENTA          "8B008B"
#define pdf_DARKOLIVEGREEN       "556B2F"
#define pdf_DARKORANGE           "FF8C00"
#define pdf_DARKORCHID           "9932CC"
#define pdf_DARKRED              "8B0000"
#define pdf_DARKSALMON           "E9967A"
#define pdf_DARKSEAGREEN         "8FBC8F"
#define pdf_DARKSLATEBLUE        "483D8B"
#define pdf_DARKSLATEGRAY        "2F4F4F"
#define pdf_DARKTURQUOISE        "00CED1"
#define pdf_DARKVIOLET           "9400D3"
#define pdf_DEEPPINK             "FF1493"
#define pdf_DEEPSKYBLUE          "00BFFF"
#define pdf_DIMGRAY              "696969"
#define pdf_DODGERBLUE           "1E90FF"
#define pdf_FIREBRICK            "B22222"
#define pdf_FLORALWHITE          "FFFAF0"
#define pdf_FORESTGREEN          "228B22"
#define pdf_FUCHSIA              "FF00FF"
#define pdf_GAINSBORO            "DCDCDC"
#define pdf_GHOSTWHITE           "F8F8FF"
#define pdf_GOLD                 "FFD700"
#define pdf_GOLDENROD            "DAA520"
#define pdf_GRAY                 "808080"
#define pdf_GREEN                "008000"
#define pdf_GREENYELLOW          "ADFF2F"
#define pdf_HONEYDEW             "F0FFF0"
#define pdf_HOTPINK              "FF69B4"
#define pdf_INDIANRED            "CD5C5C"
#define pdf_INDIGO               "4B0082"
#define pdf_IVORY                "FFFFF0"
#define pdf_KHAKI                "F0E68C"
#define pdf_LAVENDER             "E6E6FA"
#define pdf_LAVENDERBLUSH        "FFF0F5"
#define pdf_LAWNGREEN            "7CFC00"
#define pdf_LEMONCHIFFON         "FFFACD"
#define pdf_LIGHTBLUE            "ADD8E6"
#define pdf_LIGHTCORAL           "F08080"
#define pdf_LIGHTCYAN            "E0FFFF"
#define pdf_LIGHTGOLDENRODYELLOW "FAFAD2"
#define pdf_LIGHTGREEN           "90EE90"
#define pdf_LIGHTGREY            "D3D3D3"
#define pdf_LIGHTPINK            "FFB6C1"
#define pdf_LIGHTSALMON          "FFA07A"
#define pdf_LIGHTSEAGREEN        "20B2AA"
#define pdf_LIGHTSKYBLUE         "87CEFA"
#define pdf_LIGHTSLATEGRAY       "778899"
#define pdf_LIGHTSTEELBLUE       "B0C4DE"
#define pdf_LIGHTYELLOW          "FFFFE0"
#define pdf_LIME                 "00FF00"
#define pdf_LIMEGREEN            "32CD32"
#define pdf_LINEN                "FAF0E6"
#define pdf_MAGENTA              "FF00FF"
#define pdf_MAROON               "800000"
#define pdf_MEDIUMAQUAMARINE     "66CDAA"
#define pdf_MEDIUMBLUE           "0000CD"
#define pdf_MEDIUMORCHID         "BA55D3"
#define pdf_MEDIUMPURPLE         "9370DB"
#define pdf_MEDIUMSEAGREEN       "3CB371"
#define pdf_MEDIUMSLATEBLUE      "7B68EE"
#define pdf_MEDIUMSPRINGGREEN    "00FA9A"
#define pdf_MEDIUMTURQUOISE      "48D1CC"
#define pdf_MEDIUMVIOLETRED      "C71585"
#define pdf_MIDNIGHTBLUE         "191970"
#define pdf_MINTCREAM            "F5FFFA"
#define pdf_MISTYROSE            "FFE4E1"
#define pdf_MOCCASIN             "FFE4B5"
#define pdf_NAVAJOWHITE          "FFDEAD"
#define pdf_NAVY                 "000080"
#define pdf_OLDLACE              "FDF5E6"
#define pdf_OLIVE                "808000"
#define pdf_OLIVEDRAB            "6B8E23"
#define pdf_ORANGE               "FFA500"
#define pdf_ORANGERED            "FF4500"
#define pdf_ORCHID               "DA70D6"
#define pdf_PALEGOLDENROD        "EEE8AA"
#define pdf_PALEGREEN            "98FB98"
#define pdf_PALETURQUOISE        "AFEEEE"
#define pdf_PALEVIOLETRED        "DB7093"
#define pdf_PAPAYAWHIP           "FFEFD5"
#define pdf_PEACHPUFF            "FFDAB9"
#define pdf_PERU                 "CD853F"
#define pdf_PINK                 "FFC0CB"
#define pdf_PLUM                 "DDADDD"
#define pdf_POWDERBLUE           "B0E0E6"
#define pdf_PURPLE               "800080"
#define pdf_RED                  "FF0000"
#define pdf_ROSYBROWN            "BC8F8F"
#define pdf_ROYALBLUE            "4169E1"
#define pdf_SADDLEBROWN          "8B4513"
#define pdf_SALMON               "FA8072"
#define pdf_SANDYBROWN           "F4A460"
#define pdf_SEAGREEN             "2E8B57"
#define pdf_SEASHELL             "FFF5EE"
#define pdf_SIENNA               "A0522D"
#define pdf_SILVER               "C0C0C0"
#define pdf_SKYBLUE              "87CEEB"
#define pdf_SLATEBLUE            "6A5ACD"
#define pdf_SLATEGRAY            "708090"
#define pdf_SNOW                 "FFFAFA"
#define pdf_SPRINGGREEN          "00FF7F"
#define pdf_STEELBLUE            "4682B4"
#define pdf_TAN                  "D2B48C"
#define pdf_TEAL                 "008080"
#define pdf_THISTLE              "D8BFD8"
#define pdf_TOMATO               "FF6347"
#define pdf_TURQUOISE            "40E0D0"
#define pdf_VIOLET               "EE82EE"
#define pdf_WHEAT                "F5DEB3"
#define pdf_WHITE                "FFFFFF"
#define pdf_WHITESMOKE           "F5F5F5"
#define pdf_YELLOW               "FFFF00"
#define pdf_YELLOWGREEN          "9ACD32"

#endif


[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User]
Write the following Harbour (xBase/Clipper) code:

Harbour contribution module 'hbcurl' (libcurl wrapper for HTTP/FTP/SMTP operations): contrib/hbcurl/tests/ftp_uldl.prg. Provides functions: CurGet. Contains procedures: Main, CurSet. This file provides network protocol implementations

[Assistant]
#require "hbcurl"

#include "fileio.ch"

#define UPLOAD_FILE_AS      "test_ul.bin"
#define RENAME_FILE_TO      "test_ul_renamed.bin"
#define REMOTE_URL          "ftp:
#define REMOTE_URL_DEL      "ftp:
#define REMOTE_URL_MEM      "ftp:

PROCEDURE Main( cDL, cUL )

   LOCAL curl
   LOCAL info
   LOCAL tmp
   LOCAL tmp1
   LOCAL f
   LOCAL a

   LOCAL lVerbose := .F.

   ? curl_version()
   ? curl_getdate( "Sun, 1 Jun 2008 02:10:58 +0200" )

   info := curl_version_info()

   FOR tmp := 1 TO Len( info )
      IF tmp == 8
         ? tmp, ""
         FOR tmp1 := 1 TO Len( info[ 8 ] )
            ?? info[ 8 ][ tmp1 ] + " "
         NEXT
      ELSE
         ? tmp, info[ tmp ]
      ENDIF
   NEXT

   ? "Press key..."
   Inkey( 0 )

   ? "INIT:", curl_global_init()

   IF ! Empty( curl := curl_easy_init() )

      ? "ESCAPE:", tmp := curl_easy_escape( curl, "http:
      ? "UNESCAPE:", curl_easy_unescape( curl, tmp )

      ? "Press key..."
      Inkey( 0 )

      hb_default( @cUL, __FILE__ )

      ? curl_easy_setopt( curl, HB_CURLOPT_UPLOAD )
      ? curl_easy_setopt( curl, HB_CURLOPT_URL, REMOTE_URL )
      ? curl_easy_setopt( curl, HB_CURLOPT_UL_FILE_SETUP, cUL )
      ? curl_easy_setopt( curl, HB_CURLOPT_INFILESIZE, hb_FSize( cUL ) ), hb_FSize( cUL )
      ? curl_easy_setopt( curl, HB_CURLOPT_PROGRESSBLOCK, {| nPos, nLen | a := CurGet(), hb_DispOutAt( 10, 10, Str( ( nPos / nLen ) * 100, 6, 2 ) + "%" ), CurSet( a ) } )
      ? curl_easy_setopt( curl, HB_CURLOPT_NOPROGRESS, 0 )
      ? curl_easy_setopt( curl, HB_CURLOPT_POSTQUOTE, { "RNFR " + UPLOAD_FILE_AS, "RNTO " + RENAME_FILE_TO } )
      ? curl_easy_setopt( curl, HB_CURLOPT_VERBOSE, lVerbose )

      ? "UPLOAD FILE:", curl_easy_perform( curl )

      ? curl_easy_getinfo( curl, HB_CURLINFO_EFFECTIVE_URL )
      ? curl_easy_getinfo( curl, HB_CURLINFO_TOTAL_TIME )

      info := curl_easy_getinfo( curl, HB_CURLINFO_SSL_ENGINES, @tmp )
      ? "SSL ENGINES: ", tmp, Len( info )
      FOR tmp := 1 TO Len( info )
         ?? info[ tmp ] + " "
      NEXT

      curl_easy_reset( curl )

      ? "Press key..."
      Inkey( 0 )

      ? curl_easy_setopt( curl, HB_CURLOPT_UPLOAD )
      ? curl_easy_setopt( curl, HB_CURLOPT_UL_NULL_SETUP )
      ? curl_easy_setopt( curl, HB_CURLOPT_URL, REMOTE_URL_DEL )
      ? curl_easy_setopt( curl, HB_CURLOPT_NOPROGRESS )
      ? curl_easy_setopt( curl, HB_CURLOPT_POSTQUOTE, { "DELE " + RENAME_FILE_TO } )
      ? curl_easy_setopt( curl, HB_CURLOPT_VERBOSE, lVerbose )

      ? "DELETE FILE:", curl_easy_perform( curl )

      curl_easy_reset( curl )

      ? "Press key..."
      Inkey( 0 )

      tmp := "This will be the content of the file"

      ? curl_easy_setopt( curl, HB_CURLOPT_UPLOAD )
      ? curl_easy_setopt( curl, HB_CURLOPT_URL, REMOTE_URL_MEM )
      ? curl_easy_setopt( curl, HB_CURLOPT_UL_BUFF_SETUP, tmp )
      ? curl_easy_setopt( curl, HB_CURLOPT_INFILESIZE, Len( tmp ) ), Len( tmp )
      ? curl_easy_setopt( curl, HB_CURLOPT_PROGRESSBLOCK, {| nPos, nLen | a := CurGet(), hb_DispOutAt( 10, 10, Str( ( nPos / nLen ) * 100, 6, 2 ) + "%" ), CurSet( a ) } )
      ? curl_easy_setopt( curl, HB_CURLOPT_NOPROGRESS, 0 )
      ? curl_easy_setopt( curl, HB_CURLOPT_VERBOSE, lVerbose )

      ? "UPLOAD FILE FROM MEMORY:", curl_easy_perform( curl )

      ? curl_easy_getinfo( curl, HB_CURLINFO_EFFECTIVE_URL )
      ? curl_easy_getinfo( curl, HB_CURLINFO_TOTAL_TIME )

      curl_easy_reset( curl )

      ? "Press key..."
      Inkey( 0 )

      hb_default( @cDL, "ftp:

      ? curl_easy_setopt( curl, HB_CURLOPT_DOWNLOAD )
      ? curl_easy_setopt( curl, HB_CURLOPT_URL, cDL )

      ? curl_easy_setopt( curl, HB_CURLOPT_DL_FILE_SETUP, "test_dl.bin" )
      ? curl_easy_setopt( curl, HB_CURLOPT_PROGRESSBLOCK, {| nPos, nLen | a := CurGet(), hb_DispOutAt( 11, 10, Str( ( nPos / nLen ) * 100, 6, 2 ) + "%" ), CurSet( a ) } )
      ? curl_easy_setopt( curl, HB_CURLOPT_NOPROGRESS, 0 )
      ? curl_easy_setopt( curl, HB_CURLOPT_VERBOSE, lVerbose )

      ? "DOWNLOAD FILE:", curl_easy_perform( curl )

      curl_easy_reset( curl )

      ? "Press key..."
      Inkey( 0 )

      ? curl_easy_setopt( curl, HB_CURLOPT_DOWNLOAD )
      ? curl_easy_setopt( curl, HB_CURLOPT_URL, cDL )

      ? curl_easy_setopt( curl, HB_CURLOPT_DL_BUFF_SETUP )
      ? curl_easy_setopt( curl, HB_CURLOPT_PROGRESSBLOCK, {| nPos, nLen | a := CurGet(), hb_DispOutAt( 11, 10, Str( ( nPos / nLen ) * 100, 6, 2 ) + "%" ), CurSet( a ) } )
      ? curl_easy_setopt( curl, HB_CURLOPT_NOPROGRESS, 0 )
      ? curl_easy_setopt( curl, HB_CURLOPT_VERBOSE, lVerbose )

      ? "DOWNLOAD FILE TO MEM:", curl_easy_perform( curl )

      tmp := "test_dlm.bin"
      ? "WRITING TO FILE: ", tmp
      f := FCreate( tmp, FC_NORMAL )
      IF f != F_ERROR
         FWrite( f, curl_easy_dl_buff_get( curl ) )
         FClose( f )
      ENDIF

      curl_easy_reset( curl )

      ? "Press key..."
      Inkey( 0 )

      hb_default( @cDL, "ftp:

      ? curl_easy_setopt( curl, HB_CURLOPT_DOWNLOAD )
      ? curl_easy_setopt( curl, HB_CURLOPT_DIRLISTONLY )
      ? curl_easy_setopt( curl, HB_CURLOPT_URL, cDL )

      ? curl_easy_setopt( curl, HB_CURLOPT_DL_BUFF_SETUP )
      ? curl_easy_setopt( curl, HB_CURLOPT_PROGRESSBLOCK, {| nPos, nLen | a := CurGet(), hb_DispOutAt( 11, 10, Str( ( nPos / nLen ) * 100, 6, 2 ) + "%" ), CurSet( a ) } )
      ? curl_easy_setopt( curl, HB_CURLOPT_NOPROGRESS, 0 )
      ? curl_easy_setopt( curl, HB_CURLOPT_VERBOSE, lVerbose )

      ? "DOWNLOAD DIRLIST TO STRING:", curl_easy_perform( curl )

      ? "RESULT 1: " + curl_easy_dl_buff_get( curl )
      ? curl_easy_setopt( curl, HB_CURLOPT_DL_BUFF_GET, @tmp )
      ? "RESULT 2: " + tmp

      curl_easy_cleanup( curl )

   ENDIF

   curl_global_cleanup()

   RETURN

STATIC FUNCTION CurGet()
   RETURN { Row(), Col() }

STATIC PROCEDURE CurSet( a )

   SetPos( a[ 1 ], a[ 2 ] )

   RETURN


[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User] Generate Harbour code for: Harbour test program: tests/cls.prg. Defines classes: Test. Contains procedures: Main. This test file tests specific function APIs

[Assistant]
#include "hbclass.ch"

PROCEDURE Main()

   LOCAL o

   CLS

   o := Test()

   o:Another( "Hello" )

   o:Another := 5

   RETURN

CREATE CLASS Test

   ON ERROR MyErrorManager( uParam1 )

ENDCLASS

METHOD MyErrorManager( uParam1 ) CLASS Test

   IF PCount() > 0
      Alert( uParam1 )
   ENDIF

   Alert( __GetMessage() )

   RETURN NIL


[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User] Write a Harbour program with procedures: Main, my_goto. Harbour contribution module 'hbnf' (NanForum Toolkit - legacy Clipper compatibility functions): contrib/hbnf/tests/fttext.prg. Contains procedures: Main, my_goto. This file provides legacy compatibility functions

[Assistant]
#require "hbnf"

#include "fileio.ch"

PROCEDURE Main( cFile )

   hb_default( @cFile, __FILE__ )

   IF ft_FUse( cFile, FO_READ ) > 1

      DO WHILE ! ft_FEof()
         ? "line " + Str( ft_FRecNo(), 2 ) + " " + ft_FReadLn()
         ft_FSkip( 1 )
      ENDDO
      ?
      my_goto( 18 )
      my_goto( 2 )

      ft_FGoBot()
      ?
      ? "after ft_FGoBot() now in line # " + hb_ntos( ft_FRecNo() )

      ft_FGoTop()
      ?
      ? "after ft_FGoTop() now in line # " + hb_ntos( ft_FRecNo() )

      ?
      ? "ft_FLastRe() = " + hb_ntos( ft_FLastRe() )

      ft_FUse()
   ENDIF

   RETURN

STATIC PROCEDURE my_goto( n_go )

   ft_FGoto( n_go )
   ?
   ? "after ft_FGoto( " + hb_ntos( n_go ) + " )"
   ? "line " + hb_ntos( ft_FRecNo() ) + " is " + LTrim( ft_FReadLn() )

   RETURN


[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User]
Here is a Harbour (xBase/Clipper) implementation:

Harbour Runtime Library file: src/debug/dbgtmenu.prg. Defines classes: HBDbMenu. This file provides utility functions

[Assistant]
#pragma -b-

#define HB_CLS_NOTOBJECT
#include "hbclass.ch"

#include "hbmemvar.ch"

#include "box.ch"
#include "inkey.ch"
#include "setcurs.ch"

CREATE CLASS HBDbMenu

   METHOD aMenus SETGET

   VAR nTop
   VAR nLeft
   VAR nBottom
   VAR nRight
   VAR aItems
   VAR cClrHilite
   VAR cClrHotKey
   VAR cClrHotFocus
   VAR cClrPopup
   VAR nOpenPopup
   VAR lPopup
   VAR cBackImage

   METHOD New()
   METHOD AddItem( oMenuItem )
   METHOD Build()
   METHOD ClosePopup( nPopup )
   METHOD CLOSE() INLINE ::ClosePopup( ::nOpenPopup ), ::nOpenPopup := 0
   METHOD DeHilite()
   METHOD DISPLAY()
   METHOD EvalAction()
   METHOD GetHotKeyPos( cKey )
   METHOD GetItemByIdent( uIdent )
   METHOD GetItemOrdByCoors( nRow, nCol )
   METHOD GoBottom()
   METHOD GoDown() INLINE ::aItems[ ::nOpenPopup ]:bAction:GoRight()
   METHOD GoLeft()
   METHOD GoRight()
   METHOD GoTop()
   METHOD GoUp() INLINE ::aItems[ ::nOpenPopup ]:bAction:GoLeft()
   METHOD IsOpen() INLINE ::nOpenPopup != 0
   METHOD LoadColors()
   METHOD ProcessKey( nKey )
   METHOD Refresh()
   METHOD ShowPopup( nPopup )

ENDCLASS

METHOD aMenus( xNewVal ) CLASS HBDbMenu

   THREAD STATIC t_aMenus

   IF PCount() > 0
      t_aMenus := xNewVal
   ENDIF

   RETURN t_aMenus

METHOD New() CLASS HBDbMenu

   IF ::aMenus == NIL
      ::aMenus := {}
      ::lPopup := .F.
   ELSE
      ::lPopup := .T.
   ENDIF

   ::nTop         := 0
   ::nLeft        := 0
   ::nBottom      := 0
   ::nRight       := 0
   ::aItems       := {}
   ::LoadColors()
   ::nOpenPopup   := 0

   AAdd( ::aMenus, Self )

   RETURN Self

METHOD AddItem( oMenuItem ) CLASS HBDbMenu

   LOCAL oLastMenu := ATail( ::aMenus )
   LOCAL oLastMenuItem

   IF oLastMenu:lPopup
      oMenuItem:nRow := Len( oLastMenu:aItems )
      oMenuItem:nCol := oLastMenu:nLeft + 1
   ELSE
      oMenuItem:nRow := 0
      IF Len( oLastMenu:aItems ) > 0
         oLastMenuItem := ATail( oLastMenu:aItems )
         oMenuItem:nCol := oLastMenuItem:nCol + ;
            Len( StrTran( oLastMenuItem:cPrompt, "~" ) )
      ELSE
         oMenuItem:nCol := 0
      ENDIF
   ENDIF

   AAdd( ATail( ::aMenus ):aItems, oMenuItem )

   RETURN oMenuItem

METHOD PROCEDURE Build() CLASS HBDbMenu

   LOCAL nPos := 0
   LOCAL oMenuItem

   IF Len( ::aMenus ) == 1
      FOR EACH oMenuItem IN ::aItems
         oMenuItem:nRow := 0
         oMenuItem:nCol := nPos
         nPos += Len( StrTran( oMenuItem:cPrompt, "~" ) )
      NEXT
   ELSE
      oMenuItem := ATail( ::aMenus[ Len( ::aMenus ) - 1 ]:aItems )
      ::nTop    := oMenuItem:nRow + 1
      ::nLeft   := oMenuItem:nCol
      nPos := ::nLeft
      FOR EACH oMenuItem IN ::aItems
         oMenuItem:nRow := ::nTop + oMenuItem:__enumIndex()
         oMenuItem:nCol := ::nLeft + 1
         nPos := Max( nPos, ::nLeft + Len( StrTran( oMenuItem:cPrompt, "~" ) ) + 1 )
      NEXT
      ::nRight  := nPos + 1
      ::nBottom := ::nTop + Len( ::aItems ) + 1
      FOR EACH oMenuItem IN ::aItems
         IF ! hb_LeftEq( oMenuItem:cPrompt, "-" )
            oMenuItem:cPrompt := " " + PadR( oMenuItem:cPrompt, ::nRight - ::nLeft - 1 )
         ENDIF
      NEXT
      ATail( ::aMenus[ Len( ::aMenus ) - 1 ]:aItems ):bAction := ATail( ::aMenus )
      ::aMenus := ASize( ::aMenus, Len( ::aMenus ) - 1 )
   ENDIF

   RETURN

METHOD PROCEDURE ClosePopup( nPopup ) CLASS HBDbMenu

   LOCAL oPopup

   IF nPopup != 0
      oPopup := ::aItems[ nPopup ]:bAction
      IF HB_ISOBJECT( oPopup )
         __dbgRestScreen( oPopup:nTop, oPopup:nLeft, ;
                          oPopup:nBottom + 1, oPopup:nRight + 2, ;
                          oPopup:cBackImage )
         oPopup:cBackImage := NIL
      ENDIF
      ::aItems[ nPopup ]:Display( ::cClrPopup, ::cClrHotKey )
   ENDIF

   RETURN

METHOD PROCEDURE DeHilite() CLASS HBDbMenu

   LOCAL oMenuItem := ::aItems[ ::nOpenPopup ]

   oMenuItem:Display( ::cClrPopup, ::cClrHotKey )

   RETURN

METHOD PROCEDURE Display() CLASS HBDbMenu

   LOCAL oMenuItem

   IF ::lPopup
      ::cBackImage := __dbgSaveScreen( ::nTop, ::nLeft, ::nBottom + 1, ::nRight + 2 )
      hb_DispBox( ::nTop, ::nLeft, ::nBottom, ::nRight, HB_B_SINGLE_UNI, ::cClrPopup )
      hb_Shadow( ::nTop, ::nLeft, ::nBottom, ::nRight )
   ELSE
      hb_Scroll( 0, 0, 0, MaxCol(),,, ::cClrPopup )
   ENDIF

   FOR EACH oMenuItem IN ::aItems
      IF oMenuItem:cPrompt == "-"
         hb_DispOutAtBox( oMenuItem:nRow, ::nLeft, ;
            hb_UTF8ToStrBox( "├" + Replicate( "─", ::nRight - ::nLeft - 1 ) + "┤" ), ::cClrPopup )
      ELSE
         oMenuItem:Display( ::cClrPopup, ::cClrHotKey )
      ENDIF
   NEXT

   RETURN

METHOD PROCEDURE EvalAction() CLASS HBDbMenu

   LOCAL oPopup := ::aItems[ ::nOpenPopup ]:bAction
   LOCAL oMenuItem := oPopup:aItems[ oPopup:nOpenPopup ]

   IF oMenuItem:bAction != NIL
      ::Close()
      Eval( oMenuItem:bAction, oMenuItem )
   ENDIF

   RETURN

METHOD GetHotKeyPos( cKey ) CLASS HBDbMenu

   LOCAL oMenuItem

   FOR EACH oMenuItem IN ::aItems
      IF Upper( SubStr( oMenuItem:cPrompt, ;
         At( "~", oMenuItem:cPrompt ) + 1, 1 ) ) == cKey
         RETURN oMenuItem:__enumIndex()
      ENDIF
   NEXT

   RETURN 0

METHOD GetItemOrdByCoors( nRow, nCol ) CLASS HBDbMenu

   LOCAL oMenuItem

   FOR EACH oMenuItem IN ::aItems
      IF oMenuItem:nRow == nRow .AND. nCol >= oMenuItem:nCol .AND. ;
         nCol <= oMenuItem:nCol + Len( oMenuItem:cPrompt ) - 2
         RETURN oMenuItem:__enumIndex()
      ENDIF
   NEXT

   RETURN 0

METHOD GetItemByIdent( uIdent ) CLASS HBDbMenu

   LOCAL oMenuItem
   LOCAL oItem

   FOR EACH oMenuItem IN ::aItems
      IF HB_ISOBJECT( oMenuItem:bAction )
         IF ( oItem := oMenuItem:bAction:GetItemByIdent( uIdent ) ) != NIL
            RETURN oItem
         ENDIF
      ELSEIF ValType( oMenuItem:Ident ) == ValType( uIdent ) .AND. ;
         oMenuItem:Ident == uIdent
         RETURN oMenuItem
      ENDIF
   NEXT

   RETURN NIL

METHOD PROCEDURE GoBottom() CLASS HBDbMenu

   LOCAL oPopup

   IF ::IsOpen()
      oPopup := ::aItems[ ::nOpenPopup ]:bAction
      oPopup:DeHilite()
      oPopup:ShowPopup( Len( oPopup:aItems ) )
   ENDIF

   RETURN

METHOD PROCEDURE GoLeft() CLASS HBDbMenu

   LOCAL oMenuItem := ::aItems[ ::nOpenPopup ]

   IF ::nOpenPopup != 0
      IF ::lPopup
         oMenuItem:Display( ::cClrPopup, ::CClrHotKey )
      ELSE
         ::ClosePopup( ::nOpenPopup )
      ENDIF
      IF ::nOpenPopup > 1
         --::nOpenPopup
         DO WHILE ::nOpenPopup > 1 .AND. ;
            hb_LeftEq( ::aItems[ ::nOpenPopup ]:cPrompt, "-" )
            --::nOpenPopup
         ENDDO
         ::ShowPopup( ::nOpenPopup )
      ELSE
         ::ShowPopup( ::nOpenPopup := Len( ::aItems ) )
      ENDIF
   ENDIF

   RETURN

METHOD PROCEDURE GoRight() CLASS HBDbMenu

   LOCAL oMenuItem := ::aItems[ ::nOpenPopup ]

   IF ::nOpenPopup != 0
      IF ::lPopup
         oMenuItem:Display( ::cClrPopup, ::cClrHotKey )
      ELSE
         ::ClosePopup( ::nOpenPopup )
      ENDIF
      IF ::nOpenPopup < Len( ::aItems )
         ++::nOpenPopup
         DO WHILE ::nOpenPopup < Len( ::aItems ) .AND. ;
            hb_LeftEq( ::aItems[ ::nOpenPopup ]:cPrompt, "-" )
            ++::nOpenPopup
         ENDDO
         ::ShowPopup( ::nOpenPopup )
      ELSE
         ::ShowPopup( ::nOpenPopup := 1 )
      ENDIF
   ENDIF

   RETURN

METHOD PROCEDURE GoTop() CLASS HBDbMenu

   LOCAL oPopup

   IF ::IsOpen()
      oPopup := ::aItems[ ::nOpenPopup ]:bAction
      oPopup:DeHilite()
      oPopup:ShowPopup( 1 )
   ENDIF

   RETURN

METHOD PROCEDURE LoadColors() CLASS HBDbMenu

   LOCAL aColors := __dbgColors()
   LOCAL oMenuItem

   ::cClrPopup    := aColors[  8 ]
   ::cClrHotKey   := aColors[  9 ]
   ::cClrHilite   := aColors[ 10 ]
   ::cClrHotFocus := aColors[ 11 ]

   FOR EACH oMenuItem IN ::aItems
      IF HB_ISOBJECT( oMenuItem:bAction )
         oMenuItem:bAction:LoadColors()
      ENDIF
   NEXT

   RETURN


[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User] Generate Harbour code for: Harbour contribution module 'hbpgsql' (PostgreSQL database client library): contrib/hbpgsql/tests/stress.prg. Contains procedures: Main. This file handles database operations

[Assistant]
#require "hbpgsql"

PROCEDURE Main( cHost, cDatabase, cUser, cPass )

   LOCAL conn, res, i, x

   LOCAL cQuery

   CLS

   ? "Connecting..."
   conn := PQconnectdb( ;
      "dbname = '" + hb_defaultValue( cDatabase, "postgres" ) + "' " + ;
      "host = '" + hb_defaultValue( cHost, "localhost" ) + "' " + ;
      "user = '" + hb_defaultValue( cUser, hb_UserName() ) + "' " + ;
      "password = '" + hb_defaultValue( cPass, "" ) + "' " + ;
      "port = 5432" )

   ? PQstatus( conn ), PQerrorMessage( conn )

   IF PQstatus( conn ) != CONNECTION_OK
      RETURN
   ENDIF

   ? "Dropping table..."

   PQexec( conn, "DROP TABLE test" )

   ? "Creating test table..."
   cQuery := ;
      "CREATE TABLE test(" + ;
      "   Code integer not null primary key," + ;
      "   dept Integer," + ;
      "   Name Varchar(40)," + ;
      "   Sales boolean," + ;
      "   Tax Float4," + ;
      "   Salary Double Precision," + ;
      "   Budget Numeric(12,2)," + ;
      "   Discount Numeric(5,2)," + ;
      "   Creation Date," + ;
      "   Description text )"

   PQexec( conn, cQuery )
   PQexec( conn, "SELECT code, dept, name, sales, salary, creation FROM test" )
   PQexec( conn, "BEGIN" )

   ?
   FOR i := 1 TO 10000
      @ 15, 0 SAY "Inserting values... " + hb_ntos( i )

      cQuery := "INSERT INTO test(code, dept, name, sales, salary, creation) " + ;
         "VALUES( " + hb_ntos( i ) + "," + hb_ntos( i + 1 ) + ", 'DEPARTMENT NAME " + StrZero( i ) + "', 'y', " + hb_ntos( 300.49 + i ) + ", '2003-12-28' )"

      PQexec( conn, cQuery )

      IF i % 100 == 0
         ? PQexec( conn, "COMMIT" )
         ? PQexec( conn, "BEGIN" )
      ENDIF
   NEXT

   FOR i := 5000 TO 7000
      @ 16, 0 SAY "Deleting values... " + hb_ntos( i )

      cQuery := "DELETE FROM test WHERE code = " + hb_ntos( i )
      PQexec( conn, cQuery )

      IF i % 100 == 0
         PQexec( conn, "COMMIT" )
         PQexec( conn, "BEGIN" )
      ENDIF
   NEXT

   FOR i := 2000 TO 3000
      @ 17, 0 SAY "Updating values... " + hb_ntos( i )

      cQuery := "UPDATE FROM test SET salary = 400 WHERE code = " + hb_ntos( i )
      PQexec( conn, cQuery )

      IF i % 100 == 0
         PQexec( conn, "COMMIT" )
         PQexec( conn, "BEGIN" )
      ENDIF
   NEXT

   res := PQexec( conn, "SELECT sum(salary) as sum_salary FROM test WHERE code between 1 and 4000" )

   IF PQresultStatus( res ) == PGRES_TUPLES_OK
      @ 18, 0 SAY "Sum values... " + PQgetvalue( res, 1, 1 )
   ENDIF

   x := 0
   FOR i := 1 TO 4000
      res := PQexec( conn, "SELECT salary FROM test WHERE code = " + hb_ntos( i ) )

      IF PQresultStatus( res ) == PGRES_TUPLES_OK
         x += Val( PQgetvalue( res, 1, 1 ) )

         @ 19, 0 SAY "Sum values... " + hb_ntos( x )
      ENDIF
   NEXT

   ? "Closing..."

   RETURN


[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User]
Write the following Harbour (xBase/Clipper) code:

Harbour contribution module 'hbct' (CA-Tools compatibility library): contrib/hbct/tests/charrll.prg. Contains procedures: Main. This file provides legacy compatibility functions

[Assistant]
#ifdef __HARBOUR__
#require "hbct"
#else
#define hb_ntos( n ) LTrim( Str( n ) )
#define hb_BChar( n ) Chr( n )
#endif

PROCEDURE Main()

   LOCAL ni, cStr

   ctinit()

   ? "Begin test of CharRll()"
   ?

   ? "Simple tests:"
   ? '  CharRll( hb_BChar( 1 ) + hb_BChar(  2 ) + hb_BChar(  4 ) + hb_BChar(  8 ) + hb_BChar(  16 ) + hb_BChar( 32 ) + hb_BChar( 64 ) + hb_BChar( 128 ), 3 ) =='
   ? '           hb_BChar( 8 ) + hb_BChar( 16 ) + hb_BChar( 32 ) + hb_BChar( 64 ) + hb_BChar( 128 ) + hb_BChar(  1 ) + hb_BChar(  2 ) + hb_BChar(   4 ) ? -->'

   ? '          '
   cStr := CharRll( hb_BChar( 1 ) + hb_BChar( 2 ) + hb_BChar( 4 ) + hb_BChar( 8 ) + hb_BChar( 16 ) + hb_BChar( 32 ) + hb_BChar( 64 ) + hb_BChar( 128 ), 3 )
   FOR ni := 1 TO Len( cStr )
      ?? "hb_BChar( " + hb_ntos( Asc( SubStr( cStr, ni, 1 ) ) ) + " )"
      IF ni < Len( cStr )
         ?? " + "
      ENDIF
   NEXT
   ?

   ? "End test of CharRll()"
   ?

   ctexit()

   RETURN


[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User] Generate Harbour code for: Harbour contribution module 'hbgd' (Graphics drawing library (GD)): contrib/hbgd/tests/gdclass.prg. Contains procedures: Main. This file provides graphics and image processing capabilities

[Assistant]
#require "hbgd"

#define IMAGES_IN  "imgs_in" + hb_ps()
#define IMAGES_OUT "imgs_out" + hb_ps()

PROCEDURE Main()

   LOCAL black, blue, red, green, cyan, gray
   LOCAL color
   LOCAL oI, oI2, oI3, oI4, nThick, n, nSecs
   LOCAL oI5
   LOCAL oB

   oI := GDImage():Create( 200, 200 )

   oI2 := GDImage():LoadFromJpeg( IMAGES_IN + "conv_tst.jpg" )
   oI5 := GDImage():LoadFromJpeg( IMAGES_IN + "conv_tst.jpg" )

   black := oI:SetColor( 0, 0, 0 )
   blue  := oI:SetColor( 0, 0, 255 )
   red   := oI:SetColor( 255, 0, 0 )
   green := oI:SetColor( 0, 255, 0 )
   cyan  := oI:SetColor( 0, 255, 255 )

   oI:Rectangle( 0, 0, 199, 199, .T., cyan )
   oI:Rectangle( 0, 0, 199, 199, , black )

   oI:SetColor( blue )

   oI:SetPixel( 50, 5 )

   oI:Line( 0, 0, 199, 199, blue )
   oI:DashedLine( 0, 199, 199, 0, blue )
   nThick := oI:SetThickness( 5 )
   oI:Line( 50, 150, 100, 150 )
   oI:SetThickness( nThick )

   oI:AddStyle( red )
   oI:AddStyle( red )
   oI:AddStyle( red )
   oI:AddStyle( gdTransparent )
   oI:AddStyle( gdTransparent )
   oI:AddStyle( gdTransparent )
   oI:SetStyle()
   oI:Line( 50, 180, 100, 180, gdStyled )

   oI:ResetStyles()
   oI:AddStyle( black )
   oI:AddStyle( gdTransparent )
   oI:SetStyle()
   oI:Line( 50, 185, 100, 185, gdStyled )

   oI:AddPoint( 10, 10 )
   oI:AddPoint( 70, 10 )
   oI:AddPoint( 80, 60 )
   oI:Polygon()

   oI:ResetPoints()
   oI:AddPoint( 160, 180 )
   oI:AddPoint( 170, 110 )
   oI:AddPoint( 150, 160 )
   oI:Polygon( , .T., green )

   oI:Arc( 50, 50, 40, 40, 30, 190, , red )
   oI:Circle( 50, 150, 45, .T., green )
   oI:Ellipse( 120, 120, 50, 20, , green )

   oI:SetFontLarge()
   ? "Font Dims", oI:GetFontWidth(), oI:GetFontHeight()
   oI:SetColor( black )
   oI:Say( 0, 0, "Test" )
   oI:Say( 0, 15, "P" )
   oI:Say( 0, 30, "W" )

   oI:SayVertical( 70, 90, "Test" )
   oI:SayVertical( 70, 15, "P" )
   oI:SayVertical( 70, 30, "W" )

   oI:SayFreeType( 20, 30, "Test", "arial", 24, 15 )
   oI:SayFreeType( 40, 70, "Test2" )

   oI:SetClippingArea( 25, 25, 75, 75 )

   color := oI:GetPixel( oI:Width() / 2, oI:Height() / 2 )
   ? "Pixel Color is: ", color
   ? "RGB Values: ", oI:Red( color ), oI:Green( color ), oI:Blue( color )
   ? "Alpha Value: ",  oI:Alpha( color )

   oI:SavePng( IMAGES_OUT + "rect.png" )
   oI2:SavePng( IMAGES_OUT + "test.png" )
   oI2:SaveJpeg( IMAGES_OUT + "test.jpg" )
   oI2:SaveGif( IMAGES_OUT + "test.gif" )

   nSecs := Seconds()
   ? "start copy zoomed"
   oI3 := oI2:CopyZoomed( 150 )
   ? "end", Seconds() - nSecs
   nSecs := Seconds()
   ? "start save"
   oI3:SaveJpeg( IMAGES_OUT + "zoom.jpg" )
   ? "end", Seconds() - nSecs

   nSecs := Seconds()
   ? "start clone and zoom"
   oI2:Clone():Zoom( 200 )
   ? "end", Seconds() - nSecs

   nSecs := Seconds()
   ? "start clone"
   oI4 := oI5:Clone()
   ? "end", Seconds() - nSecs

   nSecs := Seconds()
   ? "start zoom"
   oI4:Zoom( 200 )
   ? "end", Seconds() - nSecs

   gray := oI4:SetColor( 30, 30, 30 )
   blue := oI4:SetColor( 0, 0, 200 )

#if defined( __PLATFORM__UNIX )
   oI4:SayFreeType( oI4:CenterWidth(), oI4:CenterHeight(), "GD power", "arib____", 40, 45 )
#else
   nSecs := Seconds()
   ? "start write"
   FOR n := 0 TO 350 STEP 10
      oI4:SayFreeType( oI4:CenterWidth(), oI4:CenterHeight(), "             GD Font Power", "arial", 20, n )
   NEXT
   ? "end", Seconds() - nSecs
   oI4:SetTransparent( blue )
   oI4:SayFreeType( oI4:CenterWidth() - 4, oI4:CenterHeight() + 4, "GD", "verdana", 70, n, gray )
   oI4:SayFreeType( oI4:CenterWidth(), oI4:CenterHeight(), "GD", "verdana", 70, n, blue )
#endif
   oI4:SaveJpeg( IMAGES_OUT + "writing.jpg" )

   oI4 := oI2:Clone()

   nSecs := Seconds()
   ? "start rotate outside"
   oI2:Rotate( 45 )
   ? "end", Seconds() - nSecs
   oI2:SaveJpeg( IMAGES_OUT + "rotateout.jpg" )

   nSecs := Seconds()
   ? "start rotate inside"
   oI4:RotateInside( 45 )
   ? "end", Seconds() - nSecs

   oI4:SaveJpeg( IMAGES_OUT + "rotatein.jpg" )

   oI5:Zoom( 40 )

   blue := oI5:SetColor( 0, 0, 200 )
   oI5:SayFreeType( oI5:CenterWidth(), oI5:CenterHeight(), "GD", "verdana", 20, 0, blue )
   oI5:SaveJpeg( IMAGES_OUT + "gd_zoom.jpg" )

   oI5 := GDChart():New( 400, 400 )

   blue  := oI5:SetColor( 0, 0, 200 )
   gray  := oI5:SetColor( 30, 30, 30 )
   green := oI5:SetColor( 0, 250, 0 )
   red   := oI5:SetColor( 250, 0, 0 )

   oB := GDImage():LoadFromGif( IMAGES_IN + "harbour.gif" )
   oB:Zoom( 15 )

   oI5:AddDef( "FONTPITCH", "GIANT" )

   oI5:SetData( { ;
      { "LABEL" => "One"  , "VALUE" => 10, "COLOR"  => blue , "FILLED" => .T., "EXTRUDE" => 40 }, ;
      { "LABEL" => "Two"  , "VALUE" => 35, "COLOR"  => gray , "FILLED" => .T., "FONT" => { "NAME" => "Verdana", "PITCH" => 12, "ANGLE" => 0, "COLOR" => red }  }, ;
      { "LABEL" => "Three", "VALUE" => 55, "COLOR"  => green, "FILLED" => .T. }, ;
      { "LABEL" => "Four" , "VALUE" => 55, "FILLED" => .T.  , "TILE"   => oB }, ;
      { "LABEL" => "Five" , "VALUE" => 55, "COLOR"  => red  , "FILLED" => .T., "EXTRUDE" => 20 }, ;
      { "LABEL" => "Six"  , "VALUE" => 55, "FILLED" => .T.  , "TILE"   => oB }, ;
      { "LABEL" => "Seven", "VALUE" => 55, "FILLED" => .T.  , "COLOR"  => green } ;
      } )

   oI5:PieChart()

   oI5:SaveJpeg( IMAGES_OUT + "pie.jpg" )

   oI5 := GDChart():New( 640, 480 )

   blue  := oI5:SetColor( 0, 0, 200 )
   gray  := oI5:SetColor( 30, 30, 30 )
   green := oI5:SetColor( 0, 250, 0 )
   red   := oI5:SetColor( 250, 0, 0 )

   oB := GDImage():LoadFromJpeg( IMAGES_IN + "conv_tst.jpg" )
   oB:Zoom( 15 )

   oI5:AddDef( "AXISPICT", "@E 999999" )
   oI5:AddDef( "FONTPITCH", "GIANT" )
   oI5:AddDef( "COLOR", blue )

   oI5:SetData( { ;
      { "LABEL" => "One", "VALUE" => 10, "COLOR" => blue, "FILLED" => .T., "EXTRUDE" => 40 }, ;
      { "LABEL" => "Two", "VALUE" => 35, "COLOR" => gray, "FILLED" => .T., "FONT" => { "NAME" => "Verdana", "PITCH" => 12, "ANGLE" => 0, "COLOR" => red }  }, ;
      { "LABEL" => "Three", "VALUE" => 55, "COLOR" => green, "FILLED" => .T. }, ;
      { "LABEL" => "Four", "VALUE" => 65, "FILLED" => .T., "TILE" => oB }, ;
      { "LABEL" => "Five", "VALUE" => 34, "FILLED" => .T., "COLOR" => green }, ;
      { "LABEL" => "Six", "VALUE" => 100 }, ;
      { "LABEL" => "Seven", "VALUE" => 0, "FILLED" => .T., "COLOR" => red }, ;
      { "LABEL" => "Eight", "VALUE" => 0 }, ;
      { "LABEL" => "Nine", "VALUE" => 0, "COLOR" => blue, "FILLED" => .T. } ;
      } )

   oI5:Clone():VerticalBarChart():SaveJpeg( IMAGES_OUT + "vertbars.jpg" )

   oI5:Clone():HorizontalBarChart():SaveJpeg( IMAGES_OUT + "horzbars.jpg" )

   oI5:LineChart()
   oI5:SaveJpeg( IMAGES_OUT + "hystogrm.jpg" )

   ?
   ? "Look at " + IMAGES_OUT + " folder for output images"
   ?

   RETURN


[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User]
Here is a Harbour (xBase/Clipper) implementation:

Harbour source file: src/rdd/hbsix/sxini.prg. Provides functions: _sx_INIlogical, _sx_IniInit, sx_IniHeader. This file implements core Record Driver Driver functionality

[Assistant]
#include "dbinfo.ch"

#include "hbhash.ch"
#include "hbsxdef.ch"

#define HB_SIX_SECTION "SXKEYWORDS"

MEMVAR SxIniInfo

STATIC FUNCTION _sx_INIlogical( cVal )

   SWITCH Upper( cVal )
   CASE ".T."
   CASE "TRUE"
   CASE "YES"
   CASE "ON"
      RETURN .T.
   CASE ".F."
   CASE "FALSE"
   CASE "NO"
   CASE "OFF"
      RETURN .F.
   ENDSWITCH

   RETURN NIL

FUNCTION _sx_IniInit( nArea )

   LOCAL xShared, xReadOnly, xAlias, xTrigger
   LOCAL hIni, item, sect, h, a

   IF hb_LeftEq( Type( "SxIniInfo" ), "U" )
      PUBLIC SxIniInfo := { => }
      hb_HCaseMatch( SxIniInfo, .F. )
      hb_HAutoAdd( SxIniInfo, HB_HAUTOADD_ASSIGN )
   ENDIF

   IF nArea == NIL
      RETURN .F.
   ENDIF

   hIni := hb_iniRead( hb_FNameExtSet( ( nArea )->( dbInfo( DBI_FULLPATH ) ), ".ini" ), .F.,, .F. )

   IF ! Empty( hIni )
      IF HB_SIX_SECTION $ hIni
         FOR EACH item IN hIni[ HB_SIX_SECTION ]
            SWITCH item:__enumKey()
            CASE "SHARED"
               xShared := _sx_INIlogical( item )
               EXIT
            CASE "READONLY"
               xReadOnly := _sx_INIlogical( item )
               EXIT
            CASE "ALIAS"
               xAlias := item
               EXIT
            CASE "TRIGGER"
               xTrigger := item
               EXIT
            ENDSWITCH
         NEXT
         IF xTrigger != NIL
            ( nArea )->( sx_SetTrigger( TRIGGER_INSTALL, xTrigger ) )
         ENDIF
         _sxOpenInit( nArea, xShared, xReadOnly, xAlias )
      ENDIF

      FOR EACH item IN hIni
         IF HB_ISHASH( item )
            sect := Array( Len( item ) )
            FOR EACH h, a IN item, sect
               a := { h:__enumKey(), h }
            NEXT
            item := sect
         ENDIF
      NEXT

      SxIniInfo[ nArea ] := hIni

   ENDIF

   RETURN .F.

FUNCTION sx_IniHeader( cHeaderName, nArea )

   IF nArea == NIL
      nArea := Select()
   ENDIF

   IF nArea $ SxIniInfo .AND. ;
      cHeaderName $ SxIniInfo[ nArea ]
      RETURN SxIniInfo[ nArea ][ cHeaderName ]
   ENDIF

   RETURN {}


[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User] Implement this Harbour module: Harbour test program: tests/codebloc.prg. Provides functions: MyEval, DetachLocal, RetBlock. Contains procedures: Main, OtherTest, AnotherTest. This test file tests specific function APIs

[Assistant]
#ifndef __HARBOUR__
#include "clipper.ch"
#endif

PROCEDURE Main()

   LOCAL B := "this will never print"
   LOCAL a := {| b, c | OutStd( "I am a codeblock" + b + c ) }
   LOCAL d
   LOCAL de
   LOCAL ar := { 1, 2 }
   LOCAL YY, X
   LOCAL x1, x2

   HB_SYMBOL_UNUSED( b )

   OutStd( "this should print first" )
   OutStd( hb_eol() )

   Eval( a, " with parameters", " ... and it works!" )
   OutStd( hb_eol() )

   d := "with access to local variables"

   a := {| b, c | OutStd( "I am a second codeblock " + d + b + ;
      iif( c == NIL, " empty second parameter ", c ) ), OutStd( hb_eol() ), "WITH return value" }
   Eval( a, ", codeblock parameters" )
   OutStd( hb_eol() )

   Eval( a, ", codeblock parameters ", "and with second parameter" )
   OutStd( hb_eol() )

   OutStd( MyEval( a ) )
   OutStd( hb_eol() )

   OtherTest( a )
   OutStd( hb_eol() )

   AnotherTest( a, "==> Another " )
   OutStd( hb_eol() )

   a := {| c | iif( c == NIL, {| a | "First " + a }, {| a | "Second " + a } ) }
   a := Eval( a )
   OutStd( hb_eol() )
   OutStd( Eval( a, "codeblock created in a codeblock" ) )
   OutStd( hb_eol() )

   OutStd( ar[ 1 ] )
   OutStd( hb_eol() )
   a := {|| ar[ 1 ]++ }
   Eval( a )
   OutStd( ar[ 1 ] )
   OutStd( hb_eol() )

   yy := 5
   x  := {| xx | OutStd( hb_ntos( xx ) ), OutStd( "+" ), OutStd( hb_ntos( yy ) ), OutStd( "=" ), xx + yy }
   OutStd( Eval( x, 1 ) )
   OutStd( hb_eol() )
   OutStd( Eval( x, 1, 2 ) )

   QOut( Eval( RetBlock(), 5 ) )

   OutStd( hb_eol() )

   OutStd( "Trying to use detached variable ..." )
   OutStd( hb_eol() )
   x1 := 5
   x2 := 6
   de := DetachLocal( x1, x2 )
   OutStd( Eval( de ) )

   OutStd( hb_eol() )
   x1 := 10
   x2 := 11
   QOut( Eval( de ) )
   de := DetachLocal( x1, x2 )
   QOut( Eval( de ) )

   RETURN

STATIC FUNCTION MyEval( bCodeBlock )

   LOCAL D := "this is another variable"

   RETURN Eval( bCodeBlock, " from ", "MyEval Function" )

STATIC PROCEDURE OtherTest( cblock )

   LOCAL cb

   cb := {| a, b | Eval( cblock, a, b ) }

   Eval( cb, "--> with nested ", "EVAL" )

   RETURN

STATIC PROCEDURE AnotherTest( cb, a )

   OutStd( Eval( cb, a ) )
   OutStd( hb_eol() )
   OutStd( Eval( cb, a, "again and again" ) )
   OutStd( hb_eol() )

   RETURN

STATIC FUNCTION DetachLocal( x, y )

   LOCAL z := x + y
   LOCAL cb := {|| QOut( "z=x+y=" ), QOut( z ), QOut( "x*x=" ), QOut( x * x ), QOut( "x*x+z=" ), x
   b := "bug "
   Eval( a )

   RETURN

STATIC FUNCTION RetBlock()
   RETURN {| x | x


[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User]
Here is a Harbour (xBase/Clipper) implementation:

Harbour test program: tests/dyn.prg. Contains procedures: Main. This test file tests specific function APIs

[Assistant]
#include "simpleio.ch"

#include "hbdyn.ch"

#define _ISOK_( a, b ) iif( a == b, "OK", "WRONG" )

PROCEDURE Main()
   LOCAL cFileName
   LOCAL a, b

#if defined( __ARCH64BIT__ )
   cFileName := "test_x64.dll"
#else
   cFileName := "test_x86.dll"
#endif

   ? "-", cFileName
   a := 567.89               ; ? ">", a, b := hb_DynCall( { "TESTD" , cFileName, hb_bitOr( HB_DYN_CTYPE_DOUBLE         , HB_DYN_CALLCONV_CDECL ), HB_DYN_CTYPE_DOUBLE         }, a ), _ISOK_( a, b )
   a := 567.89               ; ? ">", a, b := hb_DynCall( { "TESTF" , cFileName, hb_bitOr( HB_DYN_CTYPE_FLOAT          , HB_DYN_CALLCONV_CDECL ), HB_DYN_CTYPE_FLOAT          }, a ), _ISOK_( a, b )
   a := -( 2 ^  7 )          ; ? ">", a, b := hb_DynCall( { "TESTC" , cFileName, hb_bitOr( HB_DYN_CTYPE_CHAR           , HB_DYN_CALLCONV_CDECL ), HB_DYN_CTYPE_CHAR           }, a ), _ISOK_( a, b )
   a :=  ( 2 ^  8 ) - 1      ; ? ">", a, b := hb_DynCall( { "TESTUC", cFileName, hb_bitOr( HB_DYN_CTYPE_CHAR_UNSIGNED  , HB_DYN_CALLCONV_CDECL ), HB_DYN_CTYPE_CHAR_UNSIGNED  }, a ), _ISOK_( a, b )
   a := -( 2 ^ 15 )          ; ? ">", a, b := hb_DynCall( { "TESTS" , cFileName, hb_bitOr( HB_DYN_CTYPE_SHORT          , HB_DYN_CALLCONV_CDECL ), HB_DYN_CTYPE_SHORT          }, a ), _ISOK_( a, b )
   a :=  ( 2 ^ 16 ) - 1      ; ? ">", a, b := hb_DynCall( { "TESTUS", cFileName, hb_bitOr( HB_DYN_CTYPE_SHORT_UNSIGNED , HB_DYN_CALLCONV_CDECL ), HB_DYN_CTYPE_SHORT_UNSIGNED }, a ), _ISOK_( a, b )
   a := -( 2 ^ 31 )          ; ? ">", a, b := hb_DynCall( { "TESTI" , cFileName, hb_bitOr( HB_DYN_CTYPE_INT            , HB_DYN_CALLCONV_CDECL ), HB_DYN_CTYPE_INT            }, a ), _ISOK_( a, b )
   a :=  ( 2 ^ 32 ) - 1      ; ? ">", a, b := hb_DynCall( { "TESTUI", cFileName, hb_bitOr( HB_DYN_CTYPE_INT_UNSIGNED   , HB_DYN_CALLCONV_CDECL ), HB_DYN_CTYPE_INT_UNSIGNED   }, a ), _ISOK_( a, b )
   a := -( 2 ^ 31 )          ; ? ">", a, b := hb_DynCall( { "TESTL" , cFileName, hb_bitOr( HB_DYN_CTYPE_LONG           , HB_DYN_CALLCONV_CDECL ), HB_DYN_CTYPE_LONG           }, a ), _ISOK_( a, b )
   a :=  ( 2 ^ 32 ) - 1      ; ? ">", a, b := hb_DynCall( { "TESTUL", cFileName, hb_bitOr( HB_DYN_CTYPE_LONG_UNSIGNED  , HB_DYN_CALLCONV_CDECL ), HB_DYN_CTYPE_LONG_UNSIGNED  }, a ), _ISOK_( a, b )
   a := -( 2 ^ 63 )          ; ? ">", a, b := hb_DynCall( { "TEST6" , cFileName, hb_bitOr( HB_DYN_CTYPE_LLONG          , HB_DYN_CALLCONV_CDECL ), HB_DYN_CTYPE_LLONG          }, a ), _ISOK_( a, b )
   a := 18446744073709600000 ; ? ">", a, b := hb_DynCall( { "TESTU6", cFileName, hb_bitOr( HB_DYN_CTYPE_LLONG_UNSIGNED , HB_DYN_CALLCONV_CDECL ), HB_DYN_CTYPE_LLONG_UNSIGNED }, a ), _ISOK_( a, b )
   a := "hello world!"       ; ? ">", a, b := hb_DynCall( { "TESTST", cFileName, hb_bitOr( HB_DYN_CTYPE_CHAR_PTR       , HB_DYN_CALLCONV_CDECL )                              }, a ), _ISOK_( a, b )
   ? "=="

   a := "hello world!"       ; ? ">", a, hb_DynCall( { "TESTST", cFileName, hb_bitOr( HB_DYN_CTYPE_CHAR_PTR , HB_DYN_CALLCONV_CDECL, HB_DYN_ENC_RAW ), hb_bitOr( HB_DYN_CTYPE_CHAR_PTR, HB_DYN_ENC_RAW ) }, a )

   RETURN


[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User] Generate Harbour code for: Harbour contribution module 'gtwvg' (): contrib/gtwvg/tests/_xbp.prg. Provides functions: ResizeDialogXbp. Contains procedures: demoxbp. This file provides platform-specific functionality

[Assistant]
#include "inkey.ch"
#include "hbgtinfo.ch"
#include "hbver.ch"

#define MUSIC_WAITON          {800, 1600}

PROCEDURE demoxbp()

   LOCAL oCrt, oTBar, oSBar, oStatic, oCom, oXbp, oTree, oItem1, oItem2
   LOCAL oListBox, oCheck, oRadio, oStatic2, oMLE, oAddr
   LOCAL oPanel, oPanel1, oPanel2, cText, cNavigate, oDA
   LOCAL cVarA  := "Test A", cVarB := "Test B"
   LOCAL aState := { "not selected", "selected", "undefined" }
   LOCAL aParts := {}

   oCrt := WvgDialog():new( , , { 30, 30 }, { 900, 600 }, , .T. )
   oCrt:closable := .T.
   oCrt:icon := GetResource( "vr_1.ico" )
   oCrt:create()

   oCrt:setFontCompoundName( "12.Courier italic" )

   oDA := oCrt:drawingArea

   ActiveXBuildMenuXbp( oCrt, @oStatic, @oStatic2 )

   oTBar := ActiveXBuildToolBarXbp( oDA )

   oSBar   := WvgStatusBar():new( oCrt ):create( , , , , , .T. )
   oSBar:panelClick := {| oPanel | wvg_MessageBox( , oPanel:caption ) }
   oPanel  := oSBar:getItem( 1 )
   oPanel:caption := "My Root Panel"
   oPanel1 := oSBar:addItem()
   oPanel1:caption := "Ready"
   oPanel2 := oSBar:addItem()
   oPanel2:caption := "Click on any part!"

   oStatic := WvgStatic():new( oDA )
   oStatic:type    := WVGSTATIC_TYPE_TEXT
   oStatic:options := WVGSTATIC_TEXT_CENTER
   oStatic:caption := Chr( 13 ) + "Implemented   Xbase++ Parts"

   oStatic:create( , , { 0, oTBar:currentSize()[ 2 ] + 3 }, { 120, oCrt:currentSize()[ 2 ] - ;
      oTBar:currentSize()[ 2 ] - oSBar:currentSize()[ 2 ] - 4 }, , .T. )
   oStatic:setColorBG( RGB( 200, 200, 200 ) )

   oListBox := WvgListBox():new()
   oListBox:create( oStatic, , { 5, 55 }, { 107, 380 } )

   oListBox:setColorFG( RGB( 218, 61, 34 ) )

   AAdd( aParts, "XbpDialog"         )
   AAdd( aParts, "XbpMenuBar"        )
   AAdd( aParts, "XbpToolBar"        )
   AAdd( aParts, "XbpToolBarButton"  )
   AAdd( aParts, "XbpStatusBar"      )
   AAdd( aParts, "XbpStatic"         )
   AAdd( aParts, "XbpTreeView"       )
   AAdd( aParts, "XbpTreeViewItem"   )
   AAdd( aParts, "XbpActiveXControl" )
   AAdd( aParts, "XbpListBox"        )
   AAdd( aParts, "XbpPushButton"     )
   AAdd( aParts, "XbpCheckBox"       )
   AAdd( aParts, "XbpRadioButton"    )
   AAdd( aParts, "Xbp3State"         )
   AAdd( aParts, "XbpSLE"            )
   AAdd( aParts, "XbpMLE"            )
   AAdd( aParts, "XbpHTMLViewer"     )
   AAdd( aParts, "XbpSysWindow"      )
   AAdd( aParts, "XbpFontDialog"     )
   AAdd( aParts, "XbpFont"           )
   AAdd( aParts, "-------------"     )
   AAdd( aParts, "DataRef"           )

   AEval( aParts, {| e | oListBox:addItem( e ) } )
   oListBox:itemSelected := {|| wvg_MessageBox( , oListBox:getCurItem() ) }
   oListBox:setData( 3 )

   oXbp := WvgPushButton():new( oStatic )
   oXbp:caption := "Hide"
   oXbp:create( , , { 20, 440 }, { 80, 30 } )
   oXbp:activate := {|| oStatic:hide(), oCrt:sendMessage( WM_SIZE, 0, 0 ) }

   oTree := WvgTreeView():new( oDA, , { oCrt:currentSize()[ 1 ] - 160, oTBar:currentSize()[ 2 ] + 3 }, ;
      { 160, oCrt:currentSize()[ 2 ] - ;
      oTBar:currentSize()[ 2 ] - oSBar:currentSize()[ 2 ] - 4 }, , .T. )
   oTree:hasLines   := .T.
   oTree:hasButtons := .T.
   oTree:alwaysShowSelection := .T.
   oTree:create()
   oTree:setColorBG( RGB( 120, 15, 240 ) )
   oTree:setColorFG( RGB( 15, 240, 120 ) )
   oTree:itemSelected := {| oItem | iif( oItem != NIL, wvg_MessageBox( , oItem:caption ), NIL ) }

   oItem1 := oTree:rootItem:addItem( "First level A" )

   oTree:rootItem:addItem( "First level B" )

   oItem2 := oItem1:addItem( "Second level A" )
   oItem1:addItem( "Second level B" )

   oItem2:addItem( "Third level A" )
   oItem2:addItem( "Third level B" )
   oItem2:addItem( "Third level C" )

   oTree:setData( oItem2 )

   hb_gtInfo( HB_GTI_WINTITLE, "http:
   oCom:create()
   oCom:Navigate( hb_Version( HB_VERSION_URL_BASE ) )

   oAddr := WvgSLE():new()
   oAddr:bufferLength := 500
   oAddr:border       := .T.
   cNavigate          := hb_Version( HB_VERSION_URL_BASE )
   oAddr:dataLink     := {| x | iif( x == NIL, cNavigate, cNavigate := x ) }
   oAddr:setColorFG( RGB( 0, 0, 255   ) )
   oAddr:setColorBG( RGB( 0, 255, 255 ) )
   oAddr:create( oDA, , { 120, oTBar:currentSize()[ 2 ] }, { 500, 20 }, , .T. )
   oAddr:setData()
   oAddr:killInputFocus := {| m1, m2, oS | m1 := m1, m2 := m2, oS:getData(), oCom:navigate( cNavigate ) }

   oStatic2 := WvgStatic():New( oDA, , { 150, 150 }, { 500, 310 }, , .F. )
   oStatic2:exStyle += WS_EX_WINDOWEDGE
   oStatic2:create()
   oStatic2:setColorBG( RGB( 175, 175, 175 ) )

   oXbp := WvgPushButton():new( oStatic2 )
   oXbp:caption     := "Hide"
   oXbp:caption     := "Hide"
   oXbp:create( , , { 430, 275 }, { 60, 25 } )
   oXbp:activate    := {|| oStatic2:hide(), oCrt:sendMessage( WM_SIZE, 0, 0 ) }

   oRadio := WvgRadioButton():new( oStatic2, , { 10, 10 }, { 100, 15 } )
   oRadio:caption   := "Com 1"
   oRadio:selection := .T.
   oRadio:selected  := {| m1, m2, obj | m1 := m1, m2 := m2, wvg_MessageBox( , obj:caption + iif( obj:selection, "< S >", "< N >" ) ) }
   oRadio:create()

   oRadio := WvgRadioButton():new( oStatic2, , { 10, 35 }, { 100, 15 } )
   oRadio:caption   := "Com 2"
   oRadio:create()

   oCheck := WvgCheckBox():New( oStatic2, , { 10, 70 }, { 100, 15 }, , .T. )
   oCheck:caption   := "Checkbox A"
   oCheck:create()
   oCheck:selected  := {| m1, m2, o | m1 := m1, m2 := m2, wvg_MessageBox( , iif( o:getData(), "I am selected", "I am not selected" ) ) }

   oXbp  := Wvg3State():new()
   oXbp:caption := "3 State A"
   oXbp:create( oStatic2, , { 10, 100 }, { 100, 15 } )

   oXbp:selected := {| m1, m2, oBtn | m2 := m2, oBtn := oBtn, oPanel1:caption := "3State A [" + aState[ m1 + 1 ] + "]" }

   oXbp  := Wvg3State():new( oStatic2, , { 10, 125 }, { 100, 15 } )
   oXbp:caption := "3 State B"
   oXbp:create( oStatic2 )

   oXbp:selected := {| m1, m2, oBtn | m1 := m1, m2 := m2, wvg_MessageBox( , "3State B", aState[ oBtn:getData() + 1 ] ) }

   oXbp                := WvgSLE():new()
   oXbp:autoTab        := .T.
   oXbp:bufferLength   := 20

   oXbp:dataLink       := {| x | iif( x == NIL, cVarA, cVarA := x ) }
   oXbp:create( oStatic2, , { 10, 170 }, { 150, 20 } )
   oXbp:setData()

   oXbp:killInputFocus := {| x, y, oSLE | x := x, y := y, oSLE:getData(), oPanel:caption := "cVarA =" + cVarA }

   oXbp                := WvgSLE():new( , , { 10, 200 }, { 150, 20 } )
   oXbp:tabStop        := .T.
   oXbp:bufferLength   := 15
   oXbp:dataLink       := {| x | iif( x == NIL, cVarB, cVarB := x ) }
   oXbp:create( oStatic2 )
   oXbp:setData()
   oXbp:killInputFocus := {| x, y, oSLE | x := x, y := y, oSLE:getData(), oPanel:caption := "cVarB =" + cVarB }

   cText   := hb_MemoRead( GetResource( __FILE__ ) )

   oMLE    := WvgMLE():new()
   oMLE:wordWrap := .F.
   oMLE:border   := .T.
   oMLE:dataLink := {| x | iif( x == NIL, cText, cText := x ) }
   oMLE:create( oStatic2, , { 180, 10 }, { 310, 250 } )

   oMLE:setData()

   oTBar:buttonClick := {| oBtn | iif( oBtn:caption == "Hide", oStatic:hide(), NIL ), ;
      iif( oBtn:caption == "Show", oStatic:show(), NIL ), ;
      iif( oBtn:caption == "Tools", oStatic2:show():toFront(), NIL ), ;
      iif( oBtn:caption == "FontDlg", ExeFontDialog( oCrt ), NIL ), ;
      iif( oBtn:caption $ "Hide,Show", oCrt:sendMessage( WM_SIZE, 0, 0 ), NIL ), ;
      oPanel2:caption := "Button [ " + oBtn:caption + " ] clicked!" }

   oCrt:resize := {|| ResizeDialogXbp( oCrt, oTBar, oSBar, oStatic, oCom, oTree, oAddr ) }

   oCrt:sendMessage( WM_SIZE, 0, 0 )
   oCrt:show()

   DO WHILE .T.
      IF Inkey() == K_ESC
         EXIT
      ENDIF
   ENDDO

   oCrt:Destroy()

   RETURN

STATIC FUNCTION ResizeDialogXbp( oCrt, oTBar, oSBar, oStatic, oCom, oTree, oAddr )

   LOCAL aCrt, aTBar, aSBar
   LOCAL nH, nT

   aCrt    := oCrt:currentSize()
   aTBar   := oTBar:currentSize()
   aSBar   := oSBar:currentSize()

   nT := aTBar[ 2 ]
   nH := aCrt[ 2 ] - aTBar[ 2 ] - aSBar[ 2 ]

   IF oStatic:isVisible