[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/metaph.prg. Provides functions: ft_Metaph, _ftMakeAlpha, _ftConvVowel. This file provides legacy compatibility functions

[Assistant]
FUNCTION ft_Metaph( cName, nSize )

   LOCAL cMeta

   __defaultNIL( @cName, "" )
   __defaultNIL( @nSize, 4 )

   cMeta := " " + _ftMakeAlpha( Upper( AllTrim( cName ) ) ) + " "

   IF " KN"   $ cMeta ; cMeta := StrTran( cMeta, " KN"  , " N"  ) ; ENDIF
   IF " GN"   $ cMeta ; cMeta := StrTran( cMeta, " GN"  , " N"  ) ; ENDIF
   IF " PN"   $ cMeta ; cMeta := StrTran( cMeta, " PN"  , " N"  ) ; ENDIF
   IF " AE"   $ cMeta ; cMeta := StrTran( cMeta, " AE"  , " E"  ) ; ENDIF
   IF " X"    $ cMeta ; cMeta := StrTran( cMeta, " X"   , " S"  ) ; ENDIF
   IF " WR"   $ cMeta ; cMeta := StrTran( cMeta, " WR"  , " R"  ) ; ENDIF
   IF " WHO"  $ cMeta ; cMeta := StrTran( cMeta, " WHO" , " H"  ) ; ENDIF
   IF " WH"   $ cMeta ; cMeta := StrTran( cMeta, " WH"  , " W"  ) ; ENDIF
   IF " MCG"  $ cMeta ; cMeta := StrTran( cMeta, " MCG" , " MK" ) ; ENDIF
   IF " MC"   $ cMeta ; cMeta := StrTran( cMeta, " MC"  , " MK" ) ; ENDIF
   IF " MACG" $ cMeta ; cMeta := StrTran( cMeta, " MACG", " MK" ) ; ENDIF
   IF " MAC"  $ cMeta ; cMeta := StrTran( cMeta, " MAC" , " MK" ) ; ENDIF
   IF " GI"   $ cMeta ; cMeta := StrTran( cMeta, " GI"  , " K"  ) ; ENDIF

   IF "MB " $ cMeta ;  cMeta := StrTran( cMeta, "MB ", "M " ) ; ENDIF
   IF "NG " $ cMeta ;  cMeta := StrTran( cMeta, "NG ", "N " ) ; ENDIF

   IF " " $ SubStr( cMeta, 2, Len( cMeta ) - 2 )
      cMeta := " " + StrTran( cMeta, " " ) + " "
   ENDIF

   IF "BB"  $ cMeta ; cMeta := StrTran( cMeta, "BB", "B"  ) ; ENDIF
   IF "CC"  $ cMeta ; cMeta := StrTran( cMeta, "CC", "CH" ) ; ENDIF
   IF "DD"  $ cMeta ; cMeta := StrTran( cMeta, "DD", "T"  ) ; ENDIF
   IF "FF"  $ cMeta ; cMeta := StrTran( cMeta, "FF", "F"  ) ; ENDIF
   IF "GG"  $ cMeta ; cMeta := StrTran( cMeta, "GG", "K"  ) ; ENDIF
   IF "KK"  $ cMeta ; cMeta := StrTran( cMeta, "KK", "K"  ) ; ENDIF
   IF "LL"  $ cMeta ; cMeta := StrTran( cMeta, "LL", "L"  ) ; ENDIF
   IF "MM"  $ cMeta ; cMeta := StrTran( cMeta, "MM", "M"  ) ; ENDIF
   IF "NN"  $ cMeta ; cMeta := StrTran( cMeta, "NN", "N"  ) ; ENDIF
   IF "PP"  $ cMeta ; cMeta := StrTran( cMeta, "PP", "P"  ) ; ENDIF
   IF "RR"  $ cMeta ; cMeta := StrTran( cMeta, "RR", "R"  ) ; ENDIF
   IF "SS"  $ cMeta ; cMeta := StrTran( cMeta, "SS", "S"  ) ; ENDIF
   IF "TT"  $ cMeta ; cMeta := StrTran( cMeta, "TT", "T"  ) ; ENDIF
   IF "XX"  $ cMeta ; cMeta := StrTran( cMeta, "XX", "KS" ) ; ENDIF
   IF "ZZ"  $ cMeta ; cMeta := StrTran( cMeta, "ZZ", "S"  ) ; ENDIF

   IF "DGE" $ cMeta ; cMeta := StrTran( cMeta, "DGE", "J" ) ; ENDIF
   IF "DGY" $ cMeta ; cMeta := StrTran( cMeta, "DGY", "J" ) ; ENDIF
   IF "DGI" $ cMeta ; cMeta := StrTran( cMeta, "DGI", "J" ) ; ENDIF
   IF "GI"  $ cMeta ; cMeta := StrTran( cMeta, "GI" , "J" ) ; ENDIF
   IF "GE"  $ cMeta ; cMeta := StrTran( cMeta, "GE" , "J" ) ; ENDIF
   IF "GY"  $ cMeta ; cMeta := StrTran( cMeta, "GY" , "J" ) ; ENDIF

   IF "X"   $ cMeta ; cMeta := StrTran( cMeta, "X", "KS" ) ; ENDIF

   IF "ISCH" $ cMeta; cMeta := StrTran( cMeta, "ISCH", "IX" ) ; ENDIF
   IF "SCH"  $ cMeta; cMeta := StrTran( cMeta, "SCH" , "SK" ) ; ENDIF

   IF "CIA" $ cMeta ; cMeta := StrTran( cMeta, "CIA", "X" ) ; ENDIF
   IF "SIO" $ cMeta ; cMeta := StrTran( cMeta, "SIO", "X" ) ; ENDIF
   IF "C"   $ cMeta ; cMeta := StrTran( cMeta, "SIA", "X" ) ; ENDIF
   IF "SH"  $ cMeta ; cMeta := StrTran( cMeta, "SH" , "X" ) ; ENDIF
   IF "TIA" $ cMeta ; cMeta := StrTran( cMeta, "TIA", "X" ) ; ENDIF
   IF "TIO" $ cMeta ; cMeta := StrTran( cMeta, "TIO", "X" ) ; ENDIF
   IF "TCH" $ cMeta ; cMeta := StrTran( cMeta, "TCH", "X" ) ; ENDIF
   IF "CH"  $ cMeta ; cMeta := StrTran( cMeta, "CH" , "X" ) ; ENDIF

   IF "SCI" $ cMeta ; cMeta := StrTran( cMeta, "SCI", "S" ) ; ENDIF
   IF "SCE" $ cMeta ; cMeta := StrTran( cMeta, "SCE", "S" ) ; ENDIF
   IF "SCY" $ cMeta ; cMeta := StrTran( cMeta, "SCY", "S" ) ; ENDIF
   IF "CI"  $ cMeta ; cMeta := StrTran( cMeta, "CI" , "S" ) ; ENDIF
   IF "CE"  $ cMeta ; cMeta := StrTran( cMeta, "CE" , "S" ) ; ENDIF
   IF "CY"  $ cMeta ; cMeta := StrTran( cMeta, "CY" , "S" ) ; ENDIF
   IF "Z"   $ cMeta ; cMeta := StrTran( cMeta, "Z"  , "S" ) ; ENDIF

   IF "TH"  $ cMeta ; cMeta := StrTran( cMeta, "TH" , "0" ) ; ENDIF

   cMeta := Left( cMeta, 2 ) + _ftConvVowel( SubStr( cMeta, 3 ) )

   IF "Y" $ cMeta
      cMeta := StrTran( cMeta, "Yv", "#"  )
      cMeta := StrTran( cMeta, "Y" , ""   )
      cMeta := StrTran( cMeta, "#" , "Yv" )
   ENDIF

   IF "GHv"  $ cMeta ; cMeta := StrTran( cMeta, "GHv" , "G"  ) ; ENDIF
   IF "vGHT" $ cMeta ; cMeta := StrTran( cMeta, "vGHT", "T"  ) ; ENDIF
   IF "vGH"  $ cMeta ; cMeta := StrTran( cMeta, "vGH" , "W"  ) ; ENDIF
   IF "GN"   $ cMeta ; cMeta := StrTran( cMeta, "GN"  , "N"  ) ; ENDIF
   IF "G"    $ cMeta ; cMeta := StrTran( cMeta, "G"   , "K"  ) ; ENDIF

   IF "vHv" $ cMeta ; cMeta := StrTran( cMeta, "vHv" , "H"  ) ; ENDIF
   IF "vH"  $ cMeta ; cMeta := StrTran( cMeta, "vH"  , ""   ) ; ENDIF

   IF "PH"  $ cMeta ; cMeta := StrTran( cMeta, "PH"  , "F"  ) ; ENDIF
   IF "V"   $ cMeta ; cMeta := StrTran( cMeta, "V"   , "F"  ) ; ENDIF

   IF "D"   $ cMeta ; cMeta := StrTran( cMeta, "D"   , "T"  ) ; ENDIF

   IF "CK"  $ cMeta ; cMeta := StrTran( cMeta, "CK"  , "K"  ) ; ENDIF
   IF "Q"   $ cMeta ; cMeta := StrTran( cMeta, "Q"   , "K"  ) ; ENDIF
   IF "C"   $ cMeta ; cMeta := StrTran( cMeta, "C"   , "K"  ) ; ENDIF

   cMeta := StrTran( cMeta, "v" )

   RETURN PadR( AllTrim( cMeta ), nSize )

STATIC FUNCTION _ftMakeAlpha( cStr )

   LOCAL x, cAlpha := ""

   FOR x := 1 TO Len( cStr )
      IF SubStr( cStr, x, 1 ) == " " .OR. IsAlpha( SubStr( cStr, x, 1 ) )
         cAlpha += SubStr( cStr, x, 1 )
      ENDIF
   NEXT

   RETURN cAlpha

STATIC FUNCTION _ftConvVowel( cStr )

   LOCAL x, cConverted := ""

   FOR x := 1 TO Len( cStr )
      IF SubStr( cStr, x, 1 ) $ "AEIOU"
         cConverted += "v"
      ELSE
         cConverted += SubStr( cStr, x, 1 )
      ENDIF
   NEXT

   RETURN cConverted


[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 'hbct' (CA-Tools compatibility library): contrib/hbct/tests/ascpos.prg. Contains procedures: Main. This file provides legacy compatibility functions

[Assistant]
#ifdef __HARBOUR__
#require "hbct"
#endif

PROCEDURE Main()

   ctinit()

   ? "Begin test of AscPos()"
   ?

   ? '  AscPos( "0123456789" ) == 57    ? --> ' + Str( AscPos( "0123456789" ) )
   ? '  AscPos( "0123456789", 1 ) == 48 ? --> ' + Str( AscPos( "0123456789", 1 ) )
   ? '  AscPos( "0123456789", 11 ) == 0 ? --> ' + Str( AscPos( "0123456789", 11 ) )

   ?
   ? "End test of AscPos()"
   ?

   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] Create Harbour OOP classes for the functionality described: Harbour contribution module 'hbwin' (Windows API wrapper functions): contrib/hbwin/oleauto.prg. Defines classes: win_oleAuto. Provides functions: win_oleGetActiveObject, win_oleCreateObject. This file provides platform-specific functionality

[Assistant]
#define HB_CLS_NOTOBJECT
#include "hbclass.ch"

CREATE CLASS win_oleAuto

   VAR __hObj
   VAR __hObjEnum
   VAR __hSink
   VAR __cargo

   METHOD __enumStart( enum, lDescend )
   METHOD __enumSkip( enum, lDescend )
   METHOD __enumStop()

   METHOD __OpIndex( xIndex, xValue ) OPERATOR "[]"

   ERROR HANDLER __OnError()

ENDCLASS

METHOD __enumStart( enum, lDescend ) CLASS win_oleAuto

   LOCAL hObjEnum

   IF ! Empty( hObjEnum := __oleEnumCreate( ::__hObj, lDescend ) )
      IF ! Empty( ::__hObjEnum )

         Self := __objClone( Self )
      ENDIF
      ::__hObjEnum := hObjEnum

      ( @enum ):__enumBase( Self )
      RETURN ::__enumSkip( @enum, lDescend )
   ENDIF

   RETURN .F.

METHOD __enumSkip( enum, lDescend ) CLASS win_oleAuto

   LOCAL lContinue, xValue

   HB_SYMBOL_UNUSED( lDescend )

   xValue := __oleEnumNext( ::__hObjEnum, @lContinue, ::classH )

   ( @enum ):__enumValue( xValue )

   RETURN lContinue

METHOD PROCEDURE __enumStop() CLASS win_oleAuto

   ::__hObjEnum := NIL

   RETURN

FUNCTION win_oleGetActiveObject( ... )

   LOCAL oOle, hOle

   IF ! Empty( hOle := __oleGetActiveObject( ... ) )
      oOle := win_oleAuto()
      oOle:__hObj := hOle
   ENDIF

   RETURN oOle

FUNCTION win_oleCreateObject( ... )

   LOCAL oOle, hOle

   IF ! Empty( hOle := __oleCreateObject( ... ) )
      oOle := win_oleAuto()
      oOle:__hObj := hOle
   ENDIF

   RETURN oOle


[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: HotChoice. Harbour test program: tests/achoice3.prg. Provides functions: HotChoice. Contains procedures: Main. This test file tests specific function APIs

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

#include "achoice.ch"
#include "inkey.ch"

MEMVAR m_aItems

PROCEDURE Main()

   LOCAL nResult

   PRIVATE m_aItems := { ;
      "Apple", ;
      "Blueberry", ;
      "Cashew", ;
      "Grape", ;
      "Hazelnut", ;
      "Jackfruit", ;
      "Kumquat", ;
      "Mulberry" }

   CLS
   @ 7, 25 TO 8 + Len( m_aItems ), 57
   nResult := AChoice( 8, 26, 8 + Len( m_aItems ), 55, m_aItems,, "HotChoice" )
   IF nResult > 0
      Alert( m_aItems[ nResult ] + " selected" )
   ENDIF

   RETURN

FUNCTION HotChoice( nStatus, nCurrent, window_pos )

   LOCAL nKey, cKey

   HB_SYMBOL_UNUSED( nCurrent )
   HB_SYMBOL_UNUSED( window_pos )

   DO CASE
   CASE nStatus == AC_EXCEPT
      nKey := LastKey()
      cKey := Upper( hb_keyChar( nKey ) )
      DO CASE
      CASE AScan( m_aItems, {| c | Left( c, 1 ) == cKey } ) > 0
         hb_keyPut( K_ENTER )
         RETURN AC_GOTO
      CASE nKey == K_ENTER
         RETURN AC_SELECT
      CASE nKey == K_ESC
         RETURN AC_ABORT
      OTHERWISE
         ?? Chr( 7 )
      ENDCASE
   CASE nStatus == AC_NOITEM
      RETURN AC_ABORT
   ENDCASE

   RETURN AC_CONT


[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/objarr.prg. Provides functions: TNumber, New, Get. Contains procedures: Main. This test file tests specific function APIs

[Assistant]
PROCEDURE Main()

   LOCAL o := TNumber():New()

   ? "Direct reference : ", hb_ValToStr( o:x )

   o:x[ 1 ]     := "I am a data"
   o:Get()[ 2 ] := "I am a method"
   ? "Assign text      : ", hb_ValToStr( o:x )

   o:x[ 1 ]     := 4
   o:Get()[ 2 ] := 4
   ? "Assign 4         : ", hb_ValToStr( o:x )

   ? "Post increment   : ", o:x[ 1 ]++ , o:Get()[ 2 ]++
   ? "After            : ", o:x[ 1 ]   , o:Get()[ 2 ]
   ? "Pre decrement    : ", --o:x[ 1 ] , --o:Get()[ 2 ]
   ? "After            : ", o:x[ 1 ]   , o:Get()[ 2 ]

   o:x[ 1 ]     += 2
   o:Get()[ 2 ] += 2
   ? "Plus 2           : ", hb_ValToStr( o:x )

   o:x[ 1 ]     -= 3
   o:Get()[ 2 ] -= 3
   ? "Minus 3          : ", hb_ValToStr( o:x )

   o:x[ 1 ]
   ? "Times 3          : ", hb_ValToStr( o:x )

   o:x[ 1 ]     /= 1.5
   o:Get()[ 2 ] /= 1.5
   ? "Divide by 1.5    : ", hb_ValToStr( o:x )

   o:x[ 1 ]     %= 4
   o:Get()[ 2 ] %= 4
   ? "Modulus 4        : ", hb_ValToStr( o:x )

   o:x[ 1 ]     ^= 3
   o:Get()[ 2 ] ^= 3
   ? "To the power 3   : ", hb_ValToStr( o:x )

   ? "Global stack"
   ? hb_ValToExp( __dbgVMStkGList() )
   ? "Statics"
   ? hb_ValToExp( __dbgVMVarSList() )

   RETURN

FUNCTION TNumber()

   STATIC oNumber

   IF oNumber == NIL
      oNumber := HBClass():New( "TNumber" )

      oNumber:AddData  ( "x"   )
      oNumber:AddMethod( "Get", @Get() )
      oNumber:AddMethod( "New", @New() )
      oNumber:Create()
   ENDIF

   RETURN oNumber:Instance()

STATIC FUNCTION New()

   LOCAL self := QSelf()

   ::x := { 1, 1 }

   RETURN Self

STATIC FUNCTION Get()

   LOCAL self := QSelf()

   RETURN ::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] Generate Harbour code for: Harbour contribution module 'hbxpp' (xBase++ compatibility functions): contrib/hbxpp/thfuncx.prg. Provides functions: ThreadID, ThreadObject, ThreadWait, ThreadWaitAll. This file provides legacy compatibility functions

[Assistant]
FUNCTION ThreadID()
   RETURN hb_threadID()

FUNCTION ThreadObject( oThread )

   THREAD STATIC t_oThread

   IF PCount() > 0
      t_oThread := oThread
   ENDIF

   RETURN t_oThread

FUNCTION ThreadWait( aThreads, nTimeOut )

   LOCAL xResult, nPos, apThIDs, th

   apThIDs := {}
   FOR EACH th IN aThreads
      IF HB_ISOBJECT( th )
         AAdd( apThIDs, th:threadSelf )
      ELSE
         AAdd( apThIDs, th )
      ENDIF
   NEXT

   nPos := hb_threadWait( apThIDs, iif( HB_ISNUMERIC( nTimeOut ) .AND. nTimeOut != 0, ;
      nTimeOut / 100, ) )
   IF nPos != 0
      xResult := aThreads[ nPos ]
   ENDIF

   RETURN xResult

FUNCTION ThreadWaitAll( aThreads, nTimeOut )

   LOCAL apThIDs, th

   apThIDs := {}
   FOR EACH th IN aThreads
      IF HB_ISOBJECT( th )
         AAdd( apThIDs, th:threadSelf )
      ELSE
         AAdd( apThIDs, th )
      ENDIF
   NEXT

   RETURN hb_threadWait( apThIDs, iif( HB_ISNUMERIC( nTimeOut ) .AND. nTimeOut != 0, ;
      nTimeOut / 100, ), .T. ) == Len( apThIDs )


[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 'hbssl' (OpenSSL wrapper for SSL/TLS encryption): contrib/hbssl/tests/inetssl.prg. Provides functions: Client, Server, LoadCertificates, DispCertInfo. Contains procedures: Main. This file implements security and encryption functions

[Assistant]
#require "hbssl"

#define N_PORT          4001
#define EOL             e"\r\n"
#define PEM_CERT_FILE   "inetssl.pem"

STATIC s_lReady := .F.
STATIC s_lStop := .F.

STATIC s_lDelaySrv := .F.
STATIC s_lDelayCli := .F.

REQUEST HB_MT

PROCEDURE Main( delay )
   LOCAL thrd

   IF ! Empty( delay )
      s_lDelayCli := "C" $ Upper( delay )
      s_lDelaySrv := "S" $ Upper( delay )
   ENDIF

   SSL_init()
   RAND_seed( Time() + hb_TSToStr( hb_DateTime() ) + hb_DirBase() + NetName() )

   thrd := hb_threadStart( @Server() )
   IF Empty( thrd )
      ? "Cannot start thread."
      RETURN
   ENDIF

   DO WHILE ! s_lReady
      hb_idleSleep( 0.01 )
      IF hb_threadWait( thrd, 0 ) != 0
         hb_threadJoin( thrd )
         QUIT
      ENDIF
   ENDDO

   Client()

   s_lStop := .T.
   hb_threadJoin( thrd )
   ?

   RETURN

STATIC FUNCTION Client()
   LOCAL sock, ssl_ctx, ssl, nResult, nErr, cLine

   ssl_ctx := SSL_CTX_new()
   ssl := SSL_new( ssl_ctx )

   sock := hb_inetCreate()
   hb_inetTimeout( sock, 5000 )

   ? "CLIENT: connecting..."
   IF Empty( hb_inetConnectIP( "127.0.0.1", N_PORT, sock ) )
      ? "CLIENT: cannot connect to server."
   ELSE
      ? "CLIENT: connected to the server."
      hb_inetTimeout( sock, 3000 )

      IF s_lDelayCli
         ? "CLIENT: waiting..."
         hb_idleSleep( 1 )
      ENDIF

      ? "CLIENT: SSL CONNECT..."
      nResult := hb_inetSSL_CONNECT( sock, ssl )
      nErr := ERR_get_error()
      ?? hb_StrFormat( e"\nCLIENT: hb_inetSSL_CONNECT()=>%d (%d), '%s'\n", ;
                       nResult, nErr, ;
                       ERR_error_string( nErr ) )
      IF nResult == 1
         ? "CLIENT: connected with", SSL_get_cipher( ssl ), "encryption."
         DispCertInfo( ssl, "CLIENT: " )

         hb_inetSendAll( sock, hb_TSToStr( hb_DateTime() ) + EOL )
         DO WHILE ! Empty( cLine := hb_inetRecvLine( sock ) )
            ? "CLIENT: RECV:", hb_ValToExp( cLine )
         ENDDO
      ENDIF
   ENDIF
   hb_inetClose( sock )

   RETURN NIL

STATIC FUNCTION Server()
   LOCAL sockSrv, sockConn, ssl_ctx, ssl, nResult, nErr, cLine

   ? "SERVER: loading certificates..."
   ssl_ctx := SSL_CTX_new()
   LoadCertificates( ssl_ctx, PEM_CERT_FILE, PEM_CERT_FILE )
   ssl := SSL_new( ssl_ctx )

   ? "SERVER: create listen socket..."
   IF Empty( sockSrv := hb_inetServer( N_PORT ) )
      ? "SERVER: cannot create listen socket."
   ELSE

      ? "SERVER: waiting for connections..."
      hb_inetTimeout( sockSrv, 100 )
      s_lReady := .T.
      DO WHILE ! s_lStop
         IF ! Empty( sockConn := hb_inetAccept( sockSrv ) )
            ? "SERVER: accepted new connection."
            hb_inetTimeout( sockConn, 3000 )

            IF s_lDelaySrv
               ? "SERVER: waiting..."
               hb_idleSleep( 1 )
            ENDIF

            ? "SERVER: SSL ACCEPT..."
            nResult := hb_inetSSL_ACCEPT( sockConn, ssl )
            nErr := ERR_get_error()
            ?? hb_StrFormat( e"\nSERVER: hb_inetSSL_ACCEPT()=>%d (%d), '%s'\n", ;
                             nResult, nErr, ;
                             ERR_error_string( nErr ) )

            IF nResult == 1
               cLine := hb_inetRecvLine( sockConn )
               ? "SERVER: RECV:", hb_ValToExp( cLine )
               hb_inetSendAll( sockConn, ;
                               "ECHO[ " + cLine + " ]" + EOL + ;
                               hb_TSToStr( hb_DateTime() ) + EOL + ;
                               OS() + EOL + ;
                               Version() + EOL + ;
                               EOL )
            ENDIF

            hb_inetClose( sockConn )
            sockConn := nil
         ENDIF
      ENDDO

      s_lReady := .F.
   ENDIF

   RETURN NIL

STATIC FUNCTION LoadCertificates( ssl_ctx, cCertFile, cKeyFile )

   IF ! hb_FileExists( cCertFile ) .AND. ! hb_FileExists( cKeyFile )
      ? "SERVER: generating certificates..."
      hb_run( "openssl req -x509 -nodes -days 365 -newkey rsa:2048 " + ;
              "-out " + cCertFile + " -keyout " + cKeyFile )
   ENDIF

   IF SSL_CTX_use_certificate_file( ssl_ctx, cCertFile, HB_SSL_FILETYPE_PEM ) <= 0
      OutErr( hb_StrFormat( e"SERVER: SSL_CTX_use_certificate_file()=> '%s'\n", ;
                            ERR_error_string( ERR_get_error() ) ) )
      QUIT
   ENDIF

   IF SSL_CTX_use_PrivateKey_file( ssl_ctx, cKeyFile, HB_SSL_FILETYPE_PEM ) <= 0
      OutErr( hb_StrFormat( e"SERVER: SSL_CTX_use_PrivateKey_file()=> '%s'\n", ;
                            ERR_error_string( ERR_get_error() ) ) )
      QUIT
   ENDIF

   IF ! SSL_CTX_check_private_key( ssl_ctx ) == 1
      OutErr( e"SERVER: Private key does not match the public certificate\n" )
      QUIT
   ENDIF

   RETURN NIL

STATIC FUNCTION DispCertInfo( ssl, cWho )
   LOCAL cert

   IF ! Empty( cert := SSL_get_peer_certificate( ssl ) )
      ? cWho + "Server certificates:"
      ? cWho + "Subject:", X509_name_oneline( X509_get_subject_name( cert ), 0, 0 )
      ? cWho + "Issuer:", X509_name_oneline( X509_get_issuer_name( cert ), 0, 0 )
   ELSE
      ? cWho + "No certificates."
   ENDIF

   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] Implement these Harbour functions: Harbour test program: tests/dates3.prg. Provides functions: LastMonday. Contains procedures: Main. This test file exercises basic Harbour language features

[Assistant]
PROCEDURE Main()

   LOCAL dDate, i

   Set( _SET_DATEFORMAT, "dd/mm/yyyy" )
   dDate := hb_SToD( "19990525" )

   ? dDate, DoW( dDate )

   ? LastMonday( dDate )

   dDate += 3
   ? dDate, DoW( dDate )

   dDate += 4
   ? dDate, DoW( dDate )

   Set( _SET_DATEFORMAT, "mm/dd/yyyy" )
   dDate := hb_SToD( "19990525" )

   ? dDate, DoW( dDate )

   ? LastMonday( dDate )

   dDate += 3
   ? dDate, DoW( dDate )

   dDate += 4
   ? dDate, DoW( dDate )

   ?
   dDate := Date()
   FOR i := 1 TO 7
      ? dDate, DoW( dDate )
      dDate++
   NEXT
   ? hb_SToD(), DoW( hb_SToD() )

   RETURN

STATIC FUNCTION LastMonday( dDate )
   RETURN dDate - DoW( dDate ) + 2


[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 test program: tests/ipsvr.prg. Contains procedures: Main, process. This test file tests specific function APIs

[Assistant]
#include "inkey.ch"

#include "hbsocket.ch"

#define ADDRESS                     "0.0.0.0"
#define PORT                        10000
#define EOT                         hb_BChar( 4 )
#define TIMEOUT                     3000

PROCEDURE Main()

   LOCAL hListen
   LOCAL hSocket

   IF ! hb_mtvm()
      ? "multithread support required"
      RETURN
   ENDIF

   ? "create listening socket"
   IF Empty( hListen := hb_socketOpen() )
      ? "socket create error " + hb_ntos( hb_socketGetError() )
   ENDIF
   IF ! hb_socketBind( hListen, { HB_SOCKET_AF_INET, ADDRESS, PORT } )
      ? "bind error " + hb_ntos( hb_socketGetError() )
   ENDIF
   IF ! hb_socketListen( hListen )
      ? "listen error " + hb_ntos( hb_socketGetError() )
   ENDIF
   DO WHILE .T.
      IF Empty( hSocket := hb_socketAccept( hListen, , TIMEOUT ) )
         IF hb_socketGetError() == HB_SOCKET_ERR_TIMEOUT
            ? "loop"
         ELSE
            ? "accept error " + hb_ntos( hb_socketGetError() )
         ENDIF
      ELSE
         ? "accept socket request"
         hb_threadDetach( hb_threadStart( @process(), hSocket ) )
      ENDIF
      IF Inkey() == K_ESC
         ? "quitting - esc pressed"
         EXIT
      ENDIF
   ENDDO

   ? "close listening socket"

   hb_socketShutdown( hListen )
   hb_socketClose( hListen )

   RETURN

PROCEDURE process( hSocket )

   LOCAL cRequest
   LOCAL nLen
   LOCAL cBuf

   DO WHILE .T.
      cRequest := ""
      nLen := 1
      DO WHILE hb_BAt( EOT, cRequest ) == 0 .AND. nLen > 0
         cBuf := Space( 4096 )
         IF ( nLen := hb_socketRecv( hSocket, @cBuf,,, 10000 ) ) > 0
            cRequest += hb_BLeft( cBuf, nLen )
         ELSE
            IF nLen == -1 .AND. hb_socketGetError() == HB_SOCKET_ERR_TIMEOUT
               nLen := 0
            ENDIF
         ENDIF
      ENDDO

      IF nLen == -1
         ? "recv() error:", hb_socketGetError()
      ELSEIF nLen == 0
         ? "connection closed"
         EXIT
      ELSE
         ? cRequest
         IF "quit" $ cRequest
            ? "exit"
            EXIT
         ENDIF
      ENDIF
   ENDDO

   ? "close socket"

   hb_socketShutdown( hSocket )
   hb_socketClose( hSocket )

   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 contribution module 'hbwin' (Windows API wrapper functions): contrib/hbwin/tests/simwce.prg. Contains procedures: Main. This file provides platform-specific functionality

[Assistant]
#require "hbwin"

#include "hbsim.ch"

PROCEDURE Main()

#if defined( __PLATFORM__WINCE )

   LOCAL o := wce_Sim():New()
   LOCAL a

   IF o:lInitialize()
      Alert( "Api Sim initialized!!" + Str( o:nLastError ) )
   ELSE
      Alert( "Api Sim NOT initialized!!.  Error " + Str( o:nLastError ) )
   ENDIF

   IF ! o:lGetSimPhoneEntry( 1, SIM_PBSTORAGE_SIM, @a )
      Alert( "Pos 1 error" )
   ELSE
      Alert( "VALTYPE-> " + ValType( a ) + " LEN -> " + Str( Len( a ) ), a[ 1 ][ 1 ] )
      AEval( a, {| n | Alert( "Phone: " + n[ 1 ] + hb_eol() + "Name: " + n[ 2 ] + hb_eol() + "Adr. Type: " + Str( n[ 3 ] ) + hb_eol() + "Plan Type: " + Str( n[ 4 ] ), "pos 1" ) } )
   ENDIF

   IF ! o:lGetSimPhoneEntry( 110, SIM_PBSTORAGE_SIM, @a )
      Alert( "Pos 123 error" )
   ELSE
      AEval( a, {| n | Alert( "Phone: " + n[ 1 ] + hb_eol() + "Name: " + n[ 2 ] + hb_eol() + "Adr. Type: " + Str( n[ 3 ] ) + hb_eol() + "Plan Type: " + Str( n[ 4 ] ), "pos 110" ) } )
   ENDIF

   IF ! o:lSetSimPhoneEntry( 80, SIM_PBSTORAGE_SIM, "660099696", "pepeluis", SIM_NUMPLAN_UNKNOWN, SIM_ADDRTYPE_NATIONAL )
      Alert( "Error writing pos 80 Errpr=>" + Str( o:nLastError ) )
   ENDIF
   IF ! o:lDelSimPhoneEntry( 80, SIM_PBSTORAGE_SIM )
      Alert( "Error deletein pos 80 Errpr=>" + Str( o:nLastError ) )
   ENDIF

   IF ! o:lDeInitialize()
      Alert( "Not De-Initialized SIM api.  Error :" + Str( o:nLastError ) )
   ELSE
      Alert( "Api Sim Deinitialized!!!" )
   ENDIF

   o:End()

#else

   ? "This test requires WinCE to run."

#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] Write Harbour functions: ft_Byt2Bit. Harbour contribution module 'hbnf' (NanForum Toolkit - legacy Clipper compatibility functions): contrib/hbnf/byt2bit.prg. Provides functions: ft_Byt2Bit. This file provides legacy compatibility functions

[Assistant]
FUNCTION ft_Byt2Bit( cByte )

   LOCAL nCounter, cBitstring

   IF HB_ISSTRING( cByte )
      cByte := hb_BCode( cByte )
      cBitString := ""
      FOR nCounter := 7 TO 0 STEP -1
         cBitString += iif( hb_bitTest( cByte, nCounter ), "1", "0" )
      NEXT
      RETURN cBitString
   ENDIF

   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] Generate Harbour code for: Harbour source file: src/rdd/dbtotal.prg. Provides functions: __dbTotal, __GetField, __dbTransRec. This file implements core Record Driver Driver functionality

[Assistant]
#include "dbstruct.ch"
#include "error.ch"

FUNCTION __dbTotal( cFile, xKey, aFields, ;
                    xFor, xWhile, nNext, nRec, lRest, ;
                    cRDD, nConnection, cCodePage )

   LOCAL nOldArea
   LOCAL nNewArea

   LOCAL aNewDbStruct
   LOCAL aGetField
   LOCAL aFieldsSum
   LOCAL lDbTransRecord
   LOCAL xCurKey

   LOCAL bWhileBlock
   LOCAL bForBlock
   LOCAL bKeyBlock

   LOCAL oError
   LOCAL lError := .F.

   DO CASE
   CASE HB_ISEVALITEM( xWhile )
      bWhileBlock := xWhile
      lRest := .T.
   CASE HB_ISSTRING( xWhile ) .AND. ! Empty( xWhile )
      bWhileBlock := hb_macroBlock( xWhile )
      lRest := .T.
   OTHERWISE
      bWhileBlock := {|| .T. }
   ENDCASE

   DO CASE
   CASE HB_ISEVALITEM( xFor )
      bForBlock := xFor
   CASE HB_ISSTRING( xFor ) .AND. ! Empty( xFor )
      bForBlock := hb_macroBlock( xFor )
   OTHERWISE
      bForBlock := {|| .T. }
   ENDCASE

   __defaultNIL( @lRest, .F. )

   IF nRec != NIL
      dbGoto( nRec )
      nNext := 1
   ELSEIF nNext == NIL
      nNext := -1
      IF ! lRest
         dbGoTop()
      ENDIF
   ELSE
      lRest := .T.
   ENDIF

   nOldArea := Select()

   aNewDbStruct := {}
   AEval( dbStruct(), {| aField | iif( aField[ DBS_TYPE ] == "M", NIL, AAdd( aNewDbStruct, aField ) ) } )
   IF Empty( aNewDbStruct )
      RETURN .F.
   ENDIF

   BEGIN SEQUENCE

      IF HB_ISEVALITEM( xKey )
         bKeyBlock := xKey
      ELSE
         IF Empty( xKey )
            xKey := ordKey()
         ENDIF
         IF HB_ISSTRING( xKey ) .AND. ! Empty( xKey )
            bKeyBlock := hb_macroBlock( xKey )
         ELSE
            bKeyBlock := {|| NIL }
         ENDIF
      ENDIF

      aGetField := {}
      AEval( aFields, {| cField | AAdd( aGetField, __GetField( cField ) ) } )
      aFieldsSum := Array( Len( aGetField ) )

      dbCreate( cFile, aNewDbStruct, cRDD, .T., "", , cCodePage, nConnection )
      nNewArea := Select()

      dbSelectArea( nOldArea )
      DO WHILE ! Eof() .AND. nNext != 0 .AND. Eval( bWhileBlock )

         lDbTransRecord := .F.

         AFill( aFieldsSum, 0 )

         xCurKey := Eval( bKeyBlock )

         DO WHILE ! Eof() .AND. nNext-- != 0 .AND. Eval( bWhileBlock ) .AND. ;
               xCurKey == Eval( bKeyBlock )

            IF Eval( bForBlock )
               IF ! lDbTransRecord
                  __dbTransRec( nNewArea, aNewDbStruct )
                  dbSelectArea( nOldArea )
                  lDbTransRecord := .T.
               ENDIF
               AEval( aGetField, {| bFieldBlock, nFieldPos | aFieldsSum[ nFieldPos ] += Eval( bFieldBlock ) } )
            ENDIF

            dbSkip()
         ENDDO

         IF lDbTransRecord
            dbSelectArea( nNewArea )
            AEval( aGetField, {| bFieldBlock, nFieldPos | Eval( bFieldBlock, aFieldsSum[ nFieldPos ] ) } )
            dbSelectArea( nOldArea )
         ENDIF

      ENDDO

   RECOVER USING oError
      lError := .T.
   END SEQUENCE

   IF nNewArea != NIL
      dbSelectArea( nNewArea )
      dbCloseArea()
   ENDIF

   dbSelectArea( nOldArea )

   IF lError
      Break( oError )
   ENDIF

   RETURN .T.

STATIC FUNCTION __GetField( cField )

   LOCAL nCurrArea := Select()
   LOCAL nPos
   LOCAL oError

   IF ( nPos := At( "->", cField ) ) > 0

      IF Select( Left( cField, nPos - 1 ) ) != nCurrArea

         oError := ErrorNew()
         oError:severity   := ES_ERROR
         oError:genCode    := EG_SYNTAX
         oError:subSystem  := "DBCMD"
         oError:canDefault := .T.
         oError:operation  := cField
         oError:subCode    := 1101

         IF hb_defaultValue( Eval( ErrorBlock(), oError ), .T. )
            __errInHandler()
         ENDIF

         Break( oError )
      ENDIF

      cField := SubStr( cField, nPos + 2 )
   ENDIF

   RETURN FieldBlock( cField )

FUNCTION __dbTransRec( nDstArea, aFieldsStru )
   RETURN __dbTrans( nDstArea, aFieldsStru, , , 1 )


[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. Harbour test program: tests/dynobj.prg. Provides functions: TForm, New, Smile, BigSmile, Pause. Contains procedures: Main. This test file tests specific function APIs

[Assistant]
PROCEDURE Main()

   LOCAL oForm := TForm():New()

   ? "What methods are in the class :"
   ? hb_ValToExp( __objGetMethodList( oForm ) )

   ? "Let's add inline 'CalcArea' at run-time to an already instanced class"

   __objAddInline( oForm, "CalcArea", ;
      {| Self | ( ::nRight  - ::nLeft )
   ? "What methods are in the class :"
   ? hb_ValToExp( __objGetMethodList( oForm ) )

   ? "What is the Form area ?"
   ? oForm:CalcArea()

   ? "Let's add method 'Smile' at run-time to an already instanced class"

   __objAddMethod( oForm, "Smile", @Smile() )

   ? "What methods are in the class :"
   ? hb_ValToExp( __objGetMethodList( oForm ) )

   ? "Smile please "
   oForm:Smile()

   Pause()

   ? "Data items before"
   ? hb_ValToExp( oForm )

   ? "Let's add an additional data item"

   __objAddData( oForm, "cHelp" )

   oForm:cHelp := "This is a real tricky test"

   ? "Data items after"
   ? hb_ValToExp( oForm )

   Pause()

   ? "Let's attach a bigger smile"

   __objModMethod( oForm, "Smile", @BigSmile() )

   ? "Let's smile"
   oForm:Smile()

   ? "And CalcArea() will now give a result in square inches"

   __objModInline( oForm, "CalcArea", ;
      {| Self | ( ::nRight  - ::nLeft )
   ? "What is the Form area ?"
   ? oForm:CalcArea()

   ? "What methods are in the class :"
   ? hb_ValToExp( __objGetMethodList( oForm ) )

   ? "Delete CalcArea"
   __objDelInline( oForm, "CalcArea" )

   ? "What methods are in the class :"
   ? hb_ValToExp( __objGetMethodList( oForm ) )

   ? "Delete Smile"
   __objDelMethod( oForm, "Smile" )

   ? "What methods are in the class :"
   ? hb_ValToExp( __objGetMethodList( oForm ) )

   Pause()

   ? "Data items before"
   ? hb_ValToExp( oForm )

   ? "Let's delete cHelp"

   __objDelData( oForm, "cHelp" )

   ? "Data items after"
   ? hb_ValToExp( oForm )

   RETURN

FUNCTION TForm()

   STATIC s_oClass

   IF s_oClass == NIL
      s_oClass := HBClass():New( "TFORM" )

      s_oClass:AddData( "cText" )
      s_oClass:AddData( "nTop" )
      s_oClass:AddData( "nLeft" )
      s_oClass:AddData( "nBottom" )
      s_oClass:AddData( "nRight" )

      s_oClass:AddMethod( "New",  @New() )
      s_oClass:AddInline( "Show", {| self | ::cText } )

      s_oClass:Create()
   ENDIF

   RETURN s_oClass:Instance()

STATIC FUNCTION New()

   LOCAL Self := QSelf()

   ::nTop    := 10
   ::nLeft   := 10
   ::nBottom := 20
   ::nRight  := 40

   RETURN Self

STATIC FUNCTION Smile()

   LOCAL self := QSelf()

   IF ::CalcArea() == 300
      ? ":-)"
   ELSE
      ? ":-("
   ENDIF

   RETURN self

STATIC FUNCTION BigSmile()

   LOCAL self := QSelf()

   ? ":-)))"

   RETURN self

FUNCTION Pause()

   WAIT "Pause:"

   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] Generate Harbour code for: Harbour contribution module 'hbssl' (OpenSSL wrapper for SSL/TLS encryption): contrib/hbssl/tests/test.prg. Contains procedures: Main. This file implements security and encryption functions

[Assistant]
#require "hbssl"

#define CRLF Chr( 13 ) + Chr( 10 )

PROCEDURE Main()

   LOCAL ssl_ctx
   LOCAL ssl
   LOCAL cipher

   LOCAL socket
   LOCAL buffer

   LOCAL bits
   LOCAL tmp

   hb_inetInit()

   ? "-------"

   socket := hb_inetCreate()
   ? "INETTIMEOUT", hb_inetTimeout( socket, 500 )
   ? "INETCONN", hb_inetConnect( "www.fortify.net", 80, socket )
   ? "INETERR", hb_inetErrorCode( socket )
   ? "INETFD", hb_inetFD( socket )
   ? "INETSEND", hb_inetSend( socket, "GET / http/1.1" + CRLF + "Host: " + "www.fortify.net" + CRLF + CRLF )
   ? "INETERR", hb_inetErrorCode( socket )
   buffer := Space( 1024 )
   ? "INETRECVALL", hb_inetRecvAll( socket, @buffer, Len( buffer ) )
   ? "BUFFER", ">" + AllTrim( buffer ) + "<"
   ? "INETCLOSE", hb_inetClose( socket )

   ? "-------"

   socket := hb_inetCreate()
   ? hb_inetTimeout( socket, 2500 )
   ? hb_inetConnect( "www.fortify.net", 443, socket )
   ? hb_inetErrorCode( socket )

   SSL_init()

   ? SSLeay_version()
   ? SSLeay_version( HB_SSLEAY_VERSION  )
   ? SSLeay_version( HB_SSLEAY_CFLAGS   )
   ? SSLeay_version( HB_SSLEAY_BUILT_ON )
   ? SSLeay_version( HB_SSLEAY_PLATFORM )
   ? SSLeay_version( HB_SSLEAY_DIR      )

   ? "RAND_SEED", RAND_seed( "some entropy" )

   ? "SSL_CTX_NEW", ssl_ctx := SSL_CTX_new()

   ? "SSL_NEW", ssl := SSL_new( ssl_ctx )

   ? "SSL_VERSION", SSL_version( ssl )
   ? "SSL_GET_VERSION", SSL_get_version( ssl )

   ? "INET FD", hb_inetFD( socket )

   ? "SSL_SET_FD", SSL_set_fd( ssl, hb_inetFD( socket ) )
   ? "SSL_CONNECT", tmp := SSL_connect( ssl )
   ? "SSL_GET_ERROR", SSL_get_error( ssl, tmp )

   tmp := SSL_get_ciphers( ssl )
   FOR EACH cipher IN tmp
      ? "SSL_CIPHER_GET_NAME", SSL_CIPHER_get_name( cipher )
      ? "SSL_CIPHER_GET_VERSION", SSL_CIPHER_get_version( cipher )
      ? "SSL_CIPHER_GET_BITS", SSL_CIPHER_get_bits( cipher, @bits ), bits
      ? "SSL_CIPHER_DESCRIPTION", ">" + SSL_CIPHER_description( cipher ) + "<"
      ? "- - - - - - - - - - - - - - -"
   NEXT

   ? "SSL_GET_CIPHER_BITS", SSL_get_cipher_bits( ssl, @bits ), bits
   ? "SSL_GET_CIPHER_LIST", SSL_get_cipher_list( ssl )
   ? "SSL_GET_CIPHER_NAME", SSL_get_cipher_name( ssl )
   ? "SSL_GET_CIPHER_VERSION", SSL_get_cipher_version( ssl )

   ? "SSL_GET_CURRENT_CIPHER", cipher := SSL_get_current_cipher( ssl )
   ? "SSL_CIPHER_GET_NAME", SSL_CIPHER_get_name( cipher )
   ? "SSL_CIPHER_GET_VERSION", SSL_CIPHER_get_version( cipher )
   ? "SSL_CIPHER_GET_BITS", SSL_CIPHER_get_bits( cipher, @bits ), bits
   ? "SSL_CIPHER_DESCRIPTION", SSL_CIPHER_description( cipher )

   ? "SSL_WRITE", tmp := SSL_write( ssl, "GET / http/1.1" + CRLF + "Host: " + "www.fortify.net" + CRLF + CRLF )
   ? "SSL_GET_ERROR", SSL_get_error( ssl, tmp )
   buffer := Space( 1024 )
   ? "SSL_READ", tmp := SSL_read( ssl, @buffer )
   ? "SSL_GET_ERROR", SSL_get_error( ssl, tmp )
   ? buffer

   ? hb_inetClose( socket )

   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. Harbour contribution module 'hbct' (CA-Tools compatibility library): contrib/hbct/tests/charand.prg. Contains procedures: Main. This file provides legacy compatibility functions

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

PROCEDURE Main()

   ctinit()

   ? "Begin test of CharAnd()"
   ?

   ? "Simple tests:"

   ? '  CharAnd( "012345678", hb_BChar( 254 ) ) == "002244668" ? --> "' + CharAnd( "012345678", hb_BChar( 254 ) ) + '"'
   ? '  CharAnd( "012345678", hb_BChar( 254 ) + hb_BChar( 252 ) ) == "002044648" ? --> "' + CharAnd( "012345678", hb_BChar( 254 ) + hb_BChar( 252 ) ) + '"'

   ? "End test of CharAnd()"
   ?

   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]
Here is a Harbour (xBase/Clipper) implementation:

Harbour Runtime Library file: src/rtl/wait.prg. Provides functions: __Wait. This file provides utility functions

[Assistant]
#include "inkey.ch"

FUNCTION __Wait( xPrompt )

   LOCAL nKey
   LOCAL cKey
   LOCAL bBlock

   QOut( iif( xPrompt == NIL, "Press any key to continue...", xPrompt ) )

   DO WHILE .T.

      nKey := Inkey( 0 )

      IF ( bBlock := SetKey( nKey ) ) != NIL
         Eval( bBlock, ProcName( 1 ), ProcLine( 1 ), "" )
      ELSE
         cKey := hb_keyChar( nKey )
         IF Len( cKey ) > 0
            QQOut( cKey )
         ELSE
            cKey := Chr( 0 )
         ENDIF

         EXIT
      ENDIF

   ENDDO

   RETURN cKey


[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. Harbour contribution module 'hbct' (CA-Tools compatibility library): contrib/hbct/tests/charrem.prg. Contains procedures: Main. This file provides legacy compatibility functions

[Assistant]
#ifdef __HARBOUR__
#require "hbct"
#endif

PROCEDURE Main()

   ctinit()

   ? "Begin test of CharRem()"
   ?

   ? "Simple tests:"
   ? '  CharRem( " ", " 1  2  " ) == "12"   ? ---> "' + CharRem( " ", " 1  2  " ) + '"'
   ? '  CharRem( "3y", "xyz123" ) == "xz12" ? ---> "' + CharRem( "3y", "xyz123" ) + '"'
   ?

   ? "End test of CharRem()"
   ?

   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]
Here is a Harbour (xBase/Clipper) implementation:

Harbour test program: tests/rddtest/adscl52.prg. Provides functions: test_main. This test file tests specific function APIs

[Assistant]
#define _TEST_ADS_
REQUEST dbfcdx
#define _TESTRDD "dbfcdx"
#include "rddtst.prg"

FUNCTION test_main()

RDDTESTC {0,.t.,.t.,.f.}, LOCAL n
RDDTESTF "DBFCDX", {0,.t.,.t.,.f.}, RDDSETDEFAULT()
RDDTESTC {1,.t.,.t.,.f.}, USE "_tst" SHARED
RDDTESTF NIL, {1,.t.,.t.,.f.}, DBGOTOP()
RDDTESTF NIL, {1,.t.,.t.,.f.}, DBGOBOTTOM()
RDDTESTF NIL, {1,.t.,.t.,.f.}, DBSKIP(0)
RDDTESTF NIL, {1,.t.,.t.,.f.}, DBGOTO(0)
RDDTESTF NIL, {1,.f.,.t.,.f.}, DBSKIP(1)
RDDTESTF NIL, {1,.t.,.f.,.f.}, DBSKIP(-1)
RDDTESTF NIL, {1,.t.,.f.,.f.}, DBSKIP(0)
RDDTESTC {1,.t.,.f.,.f.}, SET DELETE ON
RDDTESTF NIL, {1,.t.,.t.,.f.}, DBGOTOP()
RDDTESTF NIL, {1,.t.,.t.,.f.}, DBGOBOTTOM()
RDDTESTF NIL, {1,.t.,.t.,.f.}, DBSKIP(0)
RDDTESTF NIL, {1,.t.,.t.,.f.}, DBGOTO(0)
RDDTESTF NIL, {1,.f.,.t.,.f.}, DBSKIP(1)
RDDTESTF NIL, {1,.t.,.f.,.f.}, DBSKIP(-1)
RDDTESTF NIL, {1,.t.,.f.,.f.}, DBSKIP(0)
RDDTESTC {1,.t.,.f.,.f.}, SET DELETE OFF
RDDTESTC {1,.t.,.t.,.f.}, INDEX on FNUM tag TG_N to "_tst"
RDDTESTC {1,.t.,.t.,.f.}, INDEX on FSTR tag TG_C to "_tst"
RDDTESTF "TG_C", {1,.t.,.t.,.f.}, ORDSETFOCUS()
RDDTESTF NIL, {1,.t.,.t.,.f.}, DBGOTOP()
RDDTESTF NIL, {1,.t.,.t.,.f.}, DBGOBOTTOM()
RDDTESTF NIL, {1,.t.,.t.,.f.}, DBSKIP(0)
RDDTESTF NIL, {1,.t.,.t.,.f.}, DBGOTO(0)
RDDTESTF NIL, {1,.f.,.t.,.f.}, DBSKIP(1)
RDDTESTF NIL, {1,.t.,.f.,.f.}, DBSKIP(-1)
RDDTESTF NIL, {1,.t.,.f.,.f.}, DBSKIP(0)
RDDTESTC {1,.t.,.f.,.f.}, SET DELETE ON
RDDTESTF NIL, {1,.t.,.t.,.f.}, DBGOTOP()
RDDTESTF NIL, {1,.t.,.t.,.f.}, DBGOBOTTOM()
RDDTESTF NIL, {1,.t.,.t.,.f.}, DBSKIP(0)
RDDTESTF NIL, {1,.t.,.t.,.f.}, DBGOTO(0)
RDDTESTF NIL, {1,.f.,.t.,.f.}, DBSKIP(1)
RDDTESTF NIL, {1,.t.,.f.,.f.}, DBSKIP(-1)
RDDTESTF NIL, {1,.t.,.f.,.f.}, DBSKIP(0)
RDDTESTF NIL, {1,.t.,.t.,.f.}, DBGOTO(0)
RDDTESTF .f., {1,.t.,.t.,.f.}, DBSEEK("", .T.,.F.)
RDDTESTF .f., {1,.t.,.t.,.f.}, DBSEEK("", .T.,.T.)
RDDTESTF .f., {1,.t.,.t.,.f.}, DBSEEK("", .F.,.F.)
RDDTESTF .f., {1,.t.,.t.,.f.}, DBSEEK("", .F.,.T.)
RDDTESTC {1,.t.,.t.,.f.}, SET DELETE OFF
RDDTESTC {15,.f.,.f.,.f.}, for n:=1 to 15                    ; dbappend()                          ; replace FNUM with int((n+2)/3)      ; replace FSTR with chr(FNUM+48)      ; next
RDDTESTF NIL, {15,.f.,.f.,.f.}, dbcommit()
RDDTESTF NIL, {15,.f.,.f.,.f.}, dbunlock()
RDDTESTF "TG_C", {15,.f.,.f.,.f.}, ORDSETFOCUS(1)
RDDTESTF "TG_N", {15,.f.,.f.,.f.}, ORDSETFOCUS()
RDDTESTF .f., {16,.f.,.t.,.f.}, DBSEEK(0,.T.,.F.)
RDDTESTF .f., {16,.f.,.t.,.f.}, DBSEEK(0,.T.,.T.)
RDDTESTF .f., {16,.f.,.t.,.f.}, DBSEEK(0.5,.T.,.F.)
RDDTESTF .f., {16,.f.,.t.,.f.}, DBSEEK(0.5,.T.,.T.)
RDDTESTF .t., {1,.f.,.f.,.t.}, DBSEEK(1.0,.T.,.F.)
RDDTESTF .t., {1,.f.,.f.,.t.}, DBSEEK(1.0,.T.,.T.)
RDDTESTF .t., {4,.f.,.f.,.t.}, DBSEEK(2.0,.T.,.F.)
RDDTESTF .t., {4,.f.,.f.,.t.}, DBSEEK(2.0,.T.,.T.)
RDDTESTF .f., {16,.f.,.t.,.f.}, DBSEEK(2.5,.T.,.F.)
RDDTESTF .f., {16,.f.,.t.,.f.}, DBSEEK(2.5,.T.,.T.)
RDDTESTF .t., {13,.f.,.f.,.t.}, DBSEEK(5.0,.T.,.F.)
RDDTESTF .t., {13,.f.,.f.,.t.}, DBSEEK(5.0,.T.,.T.)
RDDTESTF "TG_N", {13,.f.,.f.,.t.}, ORDSETFOCUS(2)
RDDTESTF "TG_C", {13,.f.,.f.,.t.}, ORDSETFOCUS()
RDDTESTF .t., {1,.f.,.f.,.t.}, DBSEEK("", .T.,.F.)
RDDTESTF .t., {1,.f.,.f.,.t.}, DBSEEK("", .T.,.T.)
RDDTESTF .f., {16,.f.,.t.,.f.}, DBSEEK(" ",.T.,.F.)
RDDTESTF .f., {16,.f.,.t.,.f.}, DBSEEK(" ",.T.,.T.)
RDDTESTF .f., {16,.f.,.t.,.f.}, DBSEEK("0",.T.,.F.)
RDDTESTF .f., {16,.f.,.t.,.f.}, DBSEEK("0",.T.,.T.)
RDDTESTF .t., {1,.f.,.f.,.t.}, DBSEEK("1",.T.,.F.)
RDDTESTF .t., {1,.f.,.f.,.t.}, DBSEEK("1",.T.,.T.)
RDDTESTF .t., {4,.f.,.f.,.t.}, DBSEEK("2",.T.,.F.)
RDDTESTF .t., {4,.f.,.f.,.t.}, DBSEEK("2",.T.,.T.)
RDDTESTF .t., {7,.f.,.f.,.t.}, DBSEEK("3",.T.,.F.)
RDDTESTF .t., {7,.f.,.f.,.t.}, DBSEEK("3",.T.,.T.)
RDDTESTF .t., {10,.f.,.f.,.t.}, DBSEEK("4",.T.,.F.)
RDDTESTF .t., {10,.f.,.f.,.t.}, DBSEEK("4",.T.,.T.)
RDDTESTF .t., {13,.f.,.f.,.t.}, DBSEEK("5",.T.,.F.)
RDDTESTF .t., {13,.f.,.f.,.t.}, DBSEEK("5",.T.,.T.)
RDDTESTF .f., {16,.f.,.t.,.f.}, DBSEEK("6",.T.,.F.)
RDDTESTF .f., {16,.f.,.t.,.f.}, DBSEEK("6",.T.,.T.)
RDDTESTF .t., {1,.f.,.f.,.t.}, DBSEEK("", .T.,.F.)
RDDTESTF .t., {1,.f.,.f.,.t.}, DBSEEK("", .T.,.T.)
RDDTESTF .f., {16,.f.,.t.,.f.}, DBSEEK(" ",.T.,.F.)
RDDTESTF .f., {16,.f.,.t.,.f.}, DBSEEK(" ",.T.,.T.)
RDDTESTF .f., {16,.f.,.t.,.f.}, DBSEEK("0",.T.,.F.)
RDDTESTF .f., {16,.f.,.t.,.f.}, DBSEEK("0",.T.,.T.)
RDDTESTF .t., {1,.f.,.f.,.t.}, DBSEEK("1",.T.,.F.)
RDDTESTF .t., {1,.f.,.f.,.t.}, DBSEEK("1",.T.,.T.)
RDDTESTF .t., {4,.f.,.f.,.t.}, DBSEEK("2",.T.,.F.)
RDDTESTF .t., {4,.f.,.f.,.t.}, DBSEEK("2",.T.,.T.)
RDDTESTF .t., {7,.f.,.f.,.t.}, DBSEEK("3",.T.,.F.)
RDDTESTF .t., {7,.f.,.f.,.t.}, DBSEEK("3",.T.,.T.)
RDDTESTF .t., {10,.f.,.f.,.t.}, DBSEEK("4",.T.,.F.)
RDDTESTF .t., {10,.f.,.f.,.t.}, DBSEEK("4",.T.,.T.)
RDDTESTF .t., {13,.f.,.f.,.t.}, DBSEEK("5",.T.,.F.)
RDDTESTF .t., {13,.f.,.f.,.t.}, DBSEEK("5",.T.,.T.)
RDDTESTF .f., {16,.f.,.t.,.f.}, DBSEEK("6",.T.,.F.)
RDDTESTF .f., {16,.f.,.t.,.f.}, DBSEEK("6",.T.,.T.)
RDDTESTC {15,.f.,.f.,.f.}, INDEX on FSTR tag TG_C to "_tst" DESCEND
RDDTESTF .f., {16,.f.,.t.,.f.}, DBSEEK("",.T.,.F.)
RDDTESTF .f., {16,.f.,.t.,.f.}, DBSEEK("",.T.,.T.)
RDDTESTF .f., {16,.f.,.t.,.f.}, DBSEEK(" ",.T.,.F.)
RDDTESTF .f., {16,.f.,.t.,.f.}, DBSEEK(" ",.T.,.T.)
RDDTESTF .f., {16,.f.,.t.,.f.}, DBSEEK("0",.T.,.F.)
RDDTESTF .f., {16,.f.,.t.,.f.}, DBSEEK("0",.T.,.T.)
RDDTESTF .t., {3,.f.,.f.,.t.}, DBSEEK("1",.T.,.F.)
RDDTESTF .t., {3,.f.,.f.,.t.}, DBSEEK("1",.T.,.T.)
RDDTESTF .t., {6,.f.,.f.,.t.}, DBSEEK("2",.T.,.F.)
RDDTESTF .t., {6,.f.,.f.,.t.}, DBSEEK("2",.T.,.T.)
RDDTESTF .t., {9,.f.,.f.,.t.}, DBSEEK("3",.T.,.F.)
RDDTESTF .t., {9,.f.,.f.,.t.}, DBSEEK("3",.T.,.T.)
RDDTESTF .t., {12,.f.,.f.,.t.}, DBSEEK("4",.T.,.F.)
RDDTESTF .t., {12,.f.,.f.,.t.}, DBSEEK("4",.T.,.T.)
RDDTESTF .t., {15,.f.,.f.,.t.}, DBSEEK("5",.T.,.F.)
RDDTESTF .t., {15,.f.,.f.,.t.}, DBSEEK("5",.T.,.T.)
RDDTESTF .f., {16,.f.,.t.,.f.}, DBSEEK("6",.T.,.F.)
RDDTESTF .f., {16,.f.,.t.,.f.}, DBSEEK("6",.T.,.T.)
RDDTESTC {1,.f.,.f.,.f.}, INDEX on FSTR tag TG_C to "_tst"
RDDTESTF NIL, {1,.f.,.f.,.f.}, DBGOTOP()
RDDTESTF NIL, {1,.f.,.f.,.f.}, DBSKIP(0)
RDDTESTF NIL, {1,.t.,.f.,.f.}, DBSKIP(-1)
RDDTESTF NIL, {1,.t.,.f.,.f.}, DBSKIP(0)
RDDTESTF NIL, {15,.f.,.f.,.f.}, DBGOBOTTOM()
RDDTESTF NIL, {15,.f.,.f.,.f.}, DBSKIP(0)
RDDTESTF NIL, {16,.f.,.t.,.f.}, DBSKIP(1)
RDDTESTF NIL, {16,.f.,.t.,.f.}, DBSKIP(0)
RDDTESTF NIL, {1,.f.,.f.,.f.}, DBGOTO(1)
RDDTESTF NIL, {1,.t.,.f.,.f.}, DBSKIP(-1)
RDDTESTF NIL, {2,.f.,.f.,.f.}, DBSKIP(1)
RDDTESTF NIL, {7,.f.,.f.,.f.}, DBSKIP(5)
RDDTESTF NIL, {12,.f.,.f.,.f.}, DBSKIP(5)
RDDTESTF NIL, {16,.f.,.t.,.f.}, DBSKIP(5)
RDDTESTF NIL, {15,.f.,.f.,.f.}, DBSKIP(-1)
RDDTESTF NIL, {10,.f.,.f.,.f.}, DBSKIP(-5)
RDDTESTF NIL, {16,.f.,.t.,.f.}, DBSKIP(10)
RDDTESTF NIL, {11,.f.,.f.,.f.}, DBSKIP(-5)
RDDTESTF NIL, {16,.t.,.t.,.f.}, DBGOTO(16)
RDDTESTF NIL, {15,.f.,.f.,.f.}, DBSKIP(-1)
RDDTESTF NIL, {1,.f.,.f.,.f.}, DBGOTO(1)
RDDTESTF NIL, {2,.f.,.f.,.f.}, DBSKIP(1)
RDDTESTF NIL, {1,.f.,.f.,.f.}, DBGOTO(1)
RDDTESTF NIL, {1,.t.,.f.,.f.}, DBSKIP(-1)
RDDTESTF NIL, {4,.f.,.f.,.f.}, DBGOTO(4)
RDDTESTF NIL, {5,.f.,.f.,.f.}, DBSKIP(1)
RDDTESTF NIL, {4,.f.,.f.,.f.}, DBGOTO(4)
RDDTESTF NIL, {3,.f.,.f.,.f.}, DBSKIP(-1)
RDDTESTF NIL, {6,.f.,.f.,.f.}, DBGOTO(6)
RDDTESTF NIL, {7,.f.,.f.,.f.}, DBSKIP(1)
RDDTESTF NIL, {6,.f.,.f.,.f.}, DBGOTO(6)
RDDTESTF NIL, {5,.f.,.f.,.f.}, DBSKIP(-1)
RDDTESTF NIL, {7,.f.,.f.,.f.}, DBGOTO(7)
RDDTESTF NIL, {8,.f.,.f.,.f.}, DBSKIP(1)
RDDTESTF NIL, {7,.f.,.f.,.f.}, DBGOTO(7)
RDDTESTF NIL, {6,.f.,.f.,.f.}, DBSKIP(-1)
RDDTESTF NIL, {12,.f.,.f.,.f.}, DBGOTO(12)
RDDTESTF NIL, {13,.f.,.f.,.f.}, DBSKIP(1)
RDDTESTF NIL, {12,.f.,.f.,.f.}, DBGOTO(12)
RDDTESTF NIL, {11,.f.,.f.,.f.}, DBSKIP(-1)
RDDTESTF NIL, {13,.f.,.f.,.f.}, DBGOTO(13)
RDDTESTF NIL, {14,.f.,.f.,.f.}, DBSKIP(1)
RDDTESTF NIL, {13,.f.,.f.,.f.}, DBGOTO(13)
RDDTESTF NIL, {12,.f.,.f.,.f.}, DBSKIP(-1)
RDDTESTF NIL, {14,.f.,.f.,.f.}, DBGOTO(14)
RDDTESTF NIL, {13,.f.,.f.,.f.}, DBSKIP(-1)
RDDTESTF NIL, {16,.t.,.t.,.f.}, DBGOTO(16)
RDDTESTF NIL, {15,.f.,.f.,.f.}, DBSKIP(-1)


[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/rtl/profiler.prg. Defines classes: HBProfileEntity, HBProfileFunction, HBProfileMethod, HBProfileOPCode, HBProfile. This file provides file I/O operations

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

CREATE CLASS HBProfileEntity

   EXPORTED:

   VAR cName    READONLY
   VAR nCalls   READONLY
   VAR nTicks   READONLY

   ACCESS nSeconds
   ACCESS nMeanTicks
   ACCESS nMeanSeconds

   METHOD init( cName, aInfo )
   METHOD describe()

ENDCLASS

METHOD init( cName, aInfo ) CLASS HBProfileEntity

   ::cName  := cName
   ::nCalls := aInfo[ 1 ]
   ::nTicks := aInfo[ 2 ]

   RETURN Self

ACCESS nSeconds CLASS HBProfileEntity
   RETURN hb_Clocks2Secs( ::nTicks )

ACCESS nMeanTicks CLASS HBProfileEntity
   RETURN iif( ::nCalls == 0, 0, ::nTicks / ::nCalls )

ACCESS nMeanSeconds CLASS HBProfileEntity
   RETURN iif( ::nCalls == 0, 0, ::nSeconds / ::nCalls )

METHOD describe() CLASS HBProfileEntity
   RETURN "Base Entity"

CREATE CLASS HBProfileFunction INHERIT HBProfileEntity

   EXPORTED:

   METHOD describe()

ENDCLASS

METHOD describe() CLASS HBProfileFunction
   RETURN "Function"

CREATE CLASS HBProfileMethod INHERIT HBProfileEntity

   EXPORTED:

   METHOD describe()

ENDCLASS

METHOD describe() CLASS HBProfileMethod
   RETURN "Method"

CREATE CLASS HBProfileOPCode INHERIT HBProfileEntity

   EXPORTED:

   METHOD describe()

ENDCLASS

METHOD describe() CLASS HBProfileOPCode
   RETURN "OPCode"

CREATE CLASS HBProfile

   EXPORTED:

   VAR aProfile

   METHOD init()
   METHOD gather()
   METHOD forEach( b )
   METHOD sort( b )
   METHOD nameSort()
   METHOD callSort()
   METHOD timeSort()
   METHOD totalCalls()
   METHOD totalTicks()
   METHOD totalSeconds()

   PROTECTED:

   METHOD gatherFunctions()
   METHOD gatherMethods()
   METHOD reset()
   METHOD ignoreSymbol( cSymbol )

ENDCLASS

METHOD init() CLASS HBProfile

   LOCAL lProfile := __SetProfiler( .F. )

   ::reset()

   __SetProfiler( lProfile )

   RETURN Self

METHOD reset() CLASS HBProfile

   ::aProfile := {}

   RETURN Self

METHOD ignoreSymbol( cSymbol ) CLASS HBProfile
   RETURN hb_LeftEq( cSymbol, "HBPROFILE" ) .OR. cSymbol == "__SETPROFILER"

METHOD gatherFunctions() CLASS HBProfile

   LOCAL lProfile  := __SetProfiler( .F. )
   LOCAL nSymCount := __dynsCount()
   LOCAL cName
   LOCAL n

   FOR n := 1 TO nSymCount

      IF __dynsIsFun( n )

         IF ! ::ignoreSymbol( cName := __dynsGetName( n ) )

            AAdd( ::aProfile, HBProfileFunction():new( cName, __dynsGetPrf( n ) ) )
         ENDIF
      ENDIF
   NEXT

   __SetProfiler( lProfile )

   RETURN Self

METHOD gatherMethods() CLASS HBProfile

   LOCAL lProfile := __SetProfiler( .F. )
   LOCAL n        := 1
   LOCAL cClass
   LOCAL nMembers
   LOCAL aMembers
   LOCAL nMember

   DO WHILE ! Empty( cClass := __className( n ) )

      IF ! ::ignoreSymbol( cClass )

         nMembers := Len( aMembers := __classSel( n ) )

         FOR nMember := 1 TO nMembers

            IF ! Empty( aMembers[ nMember ] )

               AAdd( ::aProfile, HBProfileMethod():new( cClass + ":" + aMembers[ nMember ], __GetMsgPrf( n, aMembers[ nMember ] ) ) )
            ENDIF
         NEXT
      ENDIF

      ++n
   ENDDO

   __SetProfiler( lProfile )

   RETURN Self

METHOD gather() CLASS HBProfile

   LOCAL lProfile  := __SetProfiler( .F. )

   ::reset()
   ::gatherFunctions()
   ::gatherMethods()

   __SetProfiler( lProfile )

   RETURN Self

METHOD forEach( b ) CLASS HBProfile

   LOCAL lProfile := __SetProfiler( .F. )

   AEval( ::aProfile, b )

   __SetProfiler( lProfile )

   RETURN Self

METHOD sort( b ) CLASS HBProfile

   LOCAL lProfile := __SetProfiler( .F. )

   ASort( ::aProfile, , , b )

   __SetProfiler( lProfile )

   RETURN Self

METHOD nameSort() CLASS HBProfile

   LOCAL lProfile := __SetProfiler( .F. )

   ::sort( {| oX, oY | oX:cName < oY:cName } )

   __SetProfiler( lProfile )

   RETURN Self

METHOD callSort() CLASS HBProfile

   LOCAL lProfile := __SetProfiler( .F. )

   ::sort( {| oX, oY | oX:nCalls > oY:nCalls } )

   __SetProfiler( lProfile )

   RETURN Self

METHOD timeSort() CLASS HBProfile

   LOCAL lProfile := __SetProfiler( .F. )

   ::sort( {| oX, oY | oX:nTicks > oY:nTicks } )

   __SetProfiler( lProfile )

   RETURN Self

METHOD totalCalls() CLASS HBProfile

   LOCAL lProfile := __SetProfiler( .F. )
   LOCAL nCalls   := 0

   ::forEach( {| o | nCalls += o:nCalls } )

   __SetProfiler( lProfile )

   RETURN nCalls

METHOD totalTicks() CLASS HBProfile

   LOCAL lProfile := __SetProfiler( .F. )
   LOCAL nTicks   := 0

   ::forEach( {| o | nTicks += o:nTicks } )

   __SetProfiler( lProfile )

   RETURN nTicks

METHOD totalSeconds() CLASS HBProfile

   LOCAL lProfile := __SetProfiler( .F. )
   LOCAL nSeconds := 0

   ::forEach( {| o | nSeconds += o:nSeconds } )

   __SetProfiler( lProfile )

   RETURN nSeconds

CREATE CLASS HBProfileLowLevel INHERIT HBProfile

   EXPORTED:

   METHOD gather()

   PROTECTED:

   METHOD gatherOPCodes()

ENDCLASS

METHOD gather() CLASS HBProfileLowLevel

   LOCAL lProfile := __SetProfiler( .F. )

   ::super:gather()

   ::gatherOPCodes()

   __SetProfiler( lProfile )

   RETURN Self

METHOD gatherOPCodes() CLASS HBProfileLowLevel

   LOCAL nMax := __opCount()
   LOCAL cName
   LOCAL nOP

   FOR nOP := 0 TO nMax - 1

      IF ! ::ignoreSymbol( cName := "OPCODE( " + Str( nOP, 3 ) + " )" )

         AAdd( ::aProfile, HBProfileOpcode():new( cName, __opGetPrf( nOP ) ) )
      ENDIF
   NEXT

   RETURN Self

CREATE CLASS HBProfileReport

   PROTECTED:

   VAR oProfile

   METHOD writeLines( aLines )
   METHOD header()
   METHOD emitHeader()
   METHOD line( oEntity )
   METHOD emitLine( oEntity )

   EXPORTED:

   METHOD init( oProfile )
   METHOD generate( bFilter )

ENDCLASS

METHOD init( oProfile ) CLASS HBProfileReport

   LOCAL lProfile := __SetProfiler( .F. )

   ::oProfile := oProfile

   __SetProfiler( lProfile )

   RETURN Self

METHOD writeLines( aLines ) CLASS HBProfileReport

   AEval( aLines, {| c | QOut( c ) } )

   RETURN Self

METHOD header() CLASS HBProfileReport
   RETURN { ;
      "Name                                Type       Calls    Ticks       Seconds", ;
      "=================================== ========== ======== =========== ===========" }

METHOD emitHeader() CLASS HBProfileReport

   ::writeLines( ::Header() )

   RETURN Self

METHOD line( oEntity ) CLASS HBProfileReport
   RETURN { ;
      PadR( oEntity:cName,      35 ) + " " + ;
      PadR( oEntity:describe(),  8 ) + " " + ;
      Str( oEntity:nCalls,      10 ) + " " + ;
      Str( oEntity:nTicks,      11 ) + " " + ;
      Str( oEntity:nSeconds,    11, 2 ) }

METHOD emitLine( oEntity ) CLASS HBProfileReport

   ::writeLines( ::line( oEntity ) )

   RETURN Self

METHOD generate( bFilter ) CLASS HBProfileReport

   LOCAL lProfile := __SetProfiler( .F. )

   hb_default( @bFilter, {|| .T. } )

   ::emitHeader():oProfile:forEach( {| o | iif( Eval( bFilter, o ), ::emitLine( o ), NIL ) } )

   __SetProfiler( lProfile )

   RETURN Self

CREATE CLASS HBProfileReportToFile INHERIT HBProfileReport

   PROTECTED:

   VAR hFile

   METHOD writeLines( aLines )

   EXPORTED:

   METHOD generate( bFilter, cFile )

ENDCLASS

METHOD writeLines( aLines ) CLASS HBProfileReportToFile

   IF ::hFile != F_ERROR
      AEval( aLines, {| c | FWrite( ::hFile, c + hb_eol() ) } )
   ENDIF

   RETURN Self

METHOD generate( bFilter, cFile ) CLASS HBProfileReportToFile

   LOCAL lProfile := __SetProfiler( .F. )

   IF ( ::hFile := FCreate( hb_defaultValue( cFile, "hbprof.txt" ) ) ) != F_ERROR
      ::super:generate( bFilter )
      FClose( ::hFile )
   ELSE

   ENDIF

   __SetProfiler( lProfile )

   RETURN Self

CREATE CLASS HBProfileReportToArray INHERIT HBProfileReport

   PROTECTED:

   VAR aReport

   METHOD writeLines( aLines )

   EXPORTED:

   METHOD generate( bFilter )

ENDCLASS

METHOD writeLines( aLines ) CLASS HBProfileReportToArray

   AEval( aLines, {| c | AAdd( ::aReport, c ) } )

   RETURN Self


[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 header file: include/hbhrb.ch. Defines 10 constants including: HB_HRB_CH_, HB_HRB_BIND_DEFAULT, HB_HRB_BIND_LOCAL, HB_HRB_BIND_OVERLOAD, HB_HRB_BIND_FORCELOCAL. Defines Harbour internal constants and macros

[Assistant]
#ifndef HB_HRB_CH_
#define HB_HRB_CH_

#define HB_HRB_BIND_DEFAULT      0x0

#define HB_HRB_BIND_LOCAL        0x1

#define HB_HRB_BIND_OVERLOAD     0x2

#define HB_HRB_BIND_FORCELOCAL   0x3

#define HB_HRB_BIND_MODEMASK     0x3

#define HB_HRB_BIND_LAZY         0x4

#define HB_HRB_ARG_PRGNAME       0x10

#define HB_HRB_FUNC_PUBLIC       0x1
#define HB_HRB_FUNC_STATIC       0x2
#define HB_HRB_FUNC_LOCAL        0x3
#define HB_HRB_FUNC_EXTERN       0x4

#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 Harbour functions: CallDll32, hb_DynaCall1, StrPtr. Harbour contribution module 'hbmisc' (Miscellaneous utility functions): contrib/hbmisc/calldll.prg. Provides functions: CallDll32, hb_DynaCall1, StrPtr, PtrStr. Contains procedures: UnloadAllDll. This file provides utility functions

[Assistant]
#include "hbdyn.ch"

STATIC s_hDLL := { => }
STATIC s_mutex := hb_mutexCreate()

PROCEDURE UnloadAllDll()

   hb_mutexLock( s_mutex )
   s_hDLL := { => }
   hb_mutexUnlock( s_mutex )

   RETURN

FUNCTION CallDll32( cFunction, cLibrary, ... )
   RETURN hb_DynaCall1( cFunction, cLibrary, NIL, ... )

#if define( __PLATFORM__WINDOWS )

   #define _DEF_CALLCONV_ HB_DYN_CALLCONV_STDCALL
#else
   #define _DEF_CALLCONV_ HB_DYN_CALLCONV_CDECL
#endif

FUNCTION hb_DynaCall1( cFunction, cLibrary, nCount, ... )

   LOCAL aParams
   LOCAL hHandle

   IF HB_ISSTRING( cFunction ) .AND. ;
      HB_ISSTRING( cLibrary )

      hb_mutexLock( s_mutex )

      IF ! cLibrary $ s_hDLL
         s_hDLL[ cLibrary ] := hb_libLoad( cLibrary )
      ENDIF

      hHandle := s_hDLL[ cLibrary ]

      hb_mutexUnlock( s_mutex )

      IF HB_ISNUMERIC( nCount ) .AND. nCount >= 0 .AND. nCount < PCount() - 3
         aParams := ASize( hb_AParams(), nCount )
         RETURN hb_DynCall( { cFunction, hHandle, _DEF_CALLCONV_ }, hb_ArrayToParams( aParams ) )
      ELSE
         RETURN hb_DynCall( { cFunction, hHandle, _DEF_CALLCONV_ }, ... )
      ENDIF
   ENDIF

   RETURN NIL

FUNCTION StrPtr( x )
   RETURN x

FUNCTION PtrStr( x )
   RETURN 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] Write Harbour functions: _dbExport, xpp_dbUseArea. Harbour contribution module 'hbxpp' (xBase++ compatibility functions): contrib/hbxpp/dbfuncsx.prg. Provides functions: _dbExport, xpp_dbUseArea. This file provides legacy compatibility functions

[Assistant]
FUNCTION _dbExport( cFile, aFields, bFor, bWhile, nNext, nRecord, lRest, cXPP_Driver, cDelimiter )

   SWITCH hb_defaultValue( cXPP_Driver, "" )
   CASE "SDFDBE"
      RETURN __dbCopy( cFile, aFields, bFor, bWhile, nNext, nRecord, lRest, "SDF" )
   CASE "DELDBE"
      RETURN __dbCopy( cFile, aFields, bFor, bWhile, nNext, nRecord, lRest, "DELIM", , , cDelimiter )
   ENDSWITCH

   RETURN __dbCopy( cFile, aFields, bFor, bWhile, nNext, nRecord, lRest, cXPP_Driver )

FUNCTION xpp_dbUseArea( lNewArea, cDriver, cName, xcAlias, lShared, lReadonly )

   LOCAL nOldArea
   LOCAL nArea

   IF HB_ISLOGICAL( lNewArea ) .AND. lNewArea

      hb_default( @xcAlias, "" )

      IF Empty( xcAlias )
         xcAlias := cName
      ENDIF

      IF HB_ISSTRING( xcAlias )
         nOldArea := Select()
         IF ( nArea := Select( xcAlias ) ) > 0
            xcAlias += "_" + hb_ntos( nArea )
         ENDIF
         dbSelectArea( nOldArea )
      ENDIF
   ENDIF

   RETURN dbUseArea( lNewArea, cDriver, cName, xcAlias, lShared, lReadonly )


[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/hbthread.ch. Defines constants: HB_THREAD_CH_, HB_THREAD_INHERIT_PUBLIC, HB_THREAD_INHERIT_PRIVATE, HB_THREAD_INHERIT_MEMVARS, HB_THREAD_MEMVARS_COPY. Defines Harbour internal constants and macros

[Assistant]
#ifndef HB_THREAD_CH_
#define HB_THREAD_CH_

#define HB_THREAD_INHERIT_PUBLIC    1
#define HB_THREAD_INHERIT_PRIVATE   2
#define HB_THREAD_INHERIT_MEMVARS   3
#define HB_THREAD_MEMVARS_COPY      4

#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]
Here is a Harbour (xBase/Clipper) implementation:

Header file for contribution module 'hblzf' (LZF compression library): contrib/hblzf/hblzf.ch. Defines 6 constants including: HBLZF_CH_, HB_LZF_OK, HB_LZF_BUF_ERROR, HB_LZF_MEM_ERROR, HB_LZF_DATA_CORRUPTED. Defines Harbour internal constants and macros

[Assistant]
#ifndef HBLZF_CH_
#define HBLZF_CH_

#define HB_LZF_OK               0
#define HB_LZF_BUF_ERROR        1
#define HB_LZF_MEM_ERROR        2
#define HB_LZF_DATA_CORRUPTED   22

#define HB_LZF_DEFAULT_BUFFSIZE 1024

#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 a Harbour program with procedures: Main. Harbour test program: tests/hbdoc.prg. Provides functions: DirGetName. Contains procedures: Main. This test file tests specific function APIs

[Assistant]
#include "directry.ch"
#include "simpleio.ch"

PROCEDURE Main( cRoot )

   LOCAL aEntry
   LOCAL cName

   LOCAL aDir
   LOCAL cDir

   LOCAL aFile

   LOCAL tModified
   LOCAL aErrMsg
   LOCAL tmp

   IF ! HB_ISSTRING( cRoot )

      cRoot := "." + hb_ps()
      DO WHILE hb_DirExists( cRoot + ".." )
         IF hb_FileExists( cRoot + "README.md" ) .AND. ;
            hb_FileExists( cRoot + "COPYING.txt" ) .AND. ;
            hb_DirExists( cRoot + "config" )
            EXIT
         ENDIF
         cRoot += ".." + hb_ps()
      ENDDO
   ELSE
      cDir := hb_DirSepAdd( cDir )
   ENDIF

   ? "Root: " + cRoot

   aDir := { cRoot }

   FOR EACH aFile IN Directory( cRoot + "contrib" + hb_ps() + hb_osFileMask(), "D" )
      IF "D" $ aFile[ F_ATTR ] .AND. ;
         !( aFile[ F_NAME ] == "." ) .AND. ;
         !( aFile[ F_NAME ] == ".." )
         AAdd( aDir, cRoot + "contrib" + hb_ps() + aFile[ F_NAME ] )
      ENDIF
   NEXT

   FOR EACH cDir IN aDir

      IF ! Empty( tModified := __hbdoc_DirLastModified( cDir ) )

         cName := DirGetName( cDir )
         IF Empty( cName )
            cName := "harbour"
         ENDIF

         aErrMsg := {}

         aEntry := __hbdoc_LoadDir( cDir, cName, aErrMsg )

         FOR EACH tmp IN aErrMsg
            ? tmp
         NEXT

         IF ! Empty( aEntry )
            ? __hbdoc_SaveHBD( cName, aEntry ), cName, Len( aEntry ), tModified
         ENDIF
      ENDIF
   NEXT

   RETURN

STATIC FUNCTION DirGetName( cDir )

   LOCAL cName

   cDir := hb_DirSepDel( cDir )

   hb_FNameSplit( cDir,, @cName )

   IF Empty( cName ) .OR. cName == "." .OR. cName == ".."
      RETURN ""
   ENDIF

   RETURN cName


[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/set.prg. Contains procedures: Main, testline. This test file tests specific function APIs

[Assistant]
REQUEST DBFNTX

PROCEDURE Main()

   @ Row(), Col() SAY ""

   TestLine( "_SET_EXACT",        1 )
   TestLine( "_SET_FIXED",        2 )
   TestLine( "_SET_DECIMALS",     3 )
   TestLine( "_SET_DATEFORMAT",   4 )
   TestLine( "_SET_EPOCH",        5 )
   TestLine( "_SET_PATH",         6 )
   TestLine( "_SET_DEFAULT",      7 )

   TestLine( "_SET_EXCLUSIVE",    8 )
   TestLine( "_SET_SOFTSEEK",     9 )
   TestLine( "_SET_UNIQUE",       10 )
   TestLine( "_SET_DELETED",      11 )

   TestLine( "_SET_CANCEL",       12 )
   TestLine( "_SET_DEBUG",        13 )
   TestLine( "_SET_TYPEAHEAD",    14 )

   TestLine( "_SET_COLOR",        15 )
   TestLine( "_SET_CURSOR",       16 )
   TestLine( "_SET_CONSOLE",      17 )
   TestLine( "_SET_ALTERNATE",    18 )
   TestLine( "_SET_ALTFILE",      19 )
   TestLine( "_SET_DEVICE",       20 )
   TestLine( "_SET_EXTRA",        21 )
   TestLine( "_SET_EXTRAFILE",    22 )
   TestLine( "_SET_PRINTER",      23 )
   TestLine( "_SET_PRINTFILE",    24 )
   TestLine( "_SET_MARGIN",       25 )

   TestLine( "_SET_BELL",         26 )
   TestLine( "_SET_CONFIRM",      27 )
   TestLine( "_SET_ESCAPE",       28 )
   TestLine( "_SET_INSERT",       29 )
   TestLine( "_SET_EXIT",         30 )
   TestLine( "_SET_INTENSITY",    31 )
   TestLine( "_SET_SCOREBOARD",   32 )
   TestLine( "_SET_DELIMITERS",   33 )
   TestLine( "_SET_DELIMCHARS",   34 )

   TestLine( "_SET_WRAP",         35 )
   TestLine( "_SET_MESSAGE",      36 )
   TestLine( "_SET_MCENTER",      37 )
   TestLine( "_SET_SCROLLBREAK",  38 )

#ifdef _SET_EVENTMASK
   TestLine( "_SET_EVENTMASK",    39 )

   TestLine( "_SET_VIDEOMODE",    40 )

   TestLine( "_SET_MBLOCKSIZE",   41 )
   TestLine( "_SET_MFILEEXT",     42 )

   TestLine( "_SET_STRICTREAD",   43 )
   TestLine( "_SET_OPTIMIZE",     44 )
   TestLine( "_SET_AUTOPEN",      45 )
   TestLine( "_SET_AUTORDER",     46 )
   TestLine( "_SET_AUTOSHARE",    47 )
#endif

#ifdef _SET_LANGUAGE
   TestLine( "_SET_LANGUAGE",    100 )
   TestLine( "_SET_IDLEREPEAT",  101 )
   TestLine( "_SET_FILECASE",    102 )
   TestLine( "_SET_DIRCASE",     103 )
   TestLine( "_SET_DIRSEPARATOR", 104 )
   Set( _SET_DIRSEPARATOR, "/" )
   TestLine( "_SET_DIRSEPARATOR", 104 )
#endif

   RETURN

PROCEDURE testline( c, n )

   ? ;
      Str( n, 3 ),;
      PadR( c, 20 ),;
      Set( n )

   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 contribution module 'hbtip' (Internet protocol utilities (FTP, HTTP, SMTP, POP3)): contrib/hbtip/tests/http_adv.prg. Contains procedures: Main. This file provides network protocol implementations

[Assistant]
#require "hbssl"
#require "hbtip"

#if ! defined( __HBSCRIPT__HBSHELL )
REQUEST __HBEXTERN__HBSSL__
#endif

PROCEDURE Main( cURL )

   LOCAL oHTTP, oURL, i

   IF Empty( oURL := TUrl():New( cURL ) )
      ? "Invalid URL", cURL
      RETURN
   ENDIF

   IF ! oURL:cProto == "http" .AND. ;
      ! oURL:cProto == "https"
      ? "This is a header test for http/https."
      ? "Use an http/https address."
      RETURN
   ENDIF

   IF oURL:cProto == "https" .AND. ! tip_SSL()
      ? "Error: Requires SSL support"
      RETURN
   ENDIF

   oHTTP := TIPClientHTTP():New( oURL )
   oHTTP:nConnTimeout := 20000
   ? "Connecting with", oURL:cServer
   IF oHTTP:Open( cURL )
      ? "Connection eshtablished"
      ? "Retrieving", oURL:cPath, oURL:cFile, oURL:cQuery

      IF oHTTP:Get( oURL:cPath )
         ? "Get Successful"
         FOR EACH i IN oHTTP:hHeaders
            ? i:__enumKey() + ":", i
         NEXT
      ELSE
         ? "Get failure (server reply:", oHTTP:cReply, ")"
      ENDIF

      oHTTP:Close()
   ELSE
      ? "Could not connect with", oURL:cServer
      IF oHTTP:SocketCon == NIL
         ? "Connection not initiated"
      ELSEIF hb_inetErrorCode( oHTTP:SocketCon ) == 0
         ? "Server replied:", oHTTP:cReply
      ELSE
         ? "Error in connection:", hb_inetErrorDesc( oHTTP:SocketCon )
      ENDIF
   ENDIF

   ? "Done"

   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 contribution module 'hbsqlit3' (SQLite3 database client library): contrib/hbsqlit3/tests/hooks.prg. Provides 6 functions including: CallBack, HookCommitY, HookCommitN, HookRollback, cErrorMsg. Contains procedures: Main. This file handles database operations

[Assistant]
#require "hbsqlit3"

PROCEDURE Main()

   LOCAL cSQLTEXT, cFile := ":memory:"
   LOCAL pDb, cb := @CallBack()

   IF Empty( pDb := PrepareDB( cFile ) )
      ErrorLevel( 1 )
      RETURN
   ENDIF

   sqlite3_commit_hook( pDb, "HookCommitY" )

   ? cSQLTEXT := "SELECT * FROM person WHERE name == 'Andy'"
   ? "return value: ", cErrorMsg( sqlite3_exec( pDb, cSQLTEXT, cb ) )

   ? cSQLTEXT := "BEGIN EXCLUSIVE TRANSACTION"
   ? "return value: ", cErrorMsg( sqlite3_exec( pDb, cSQLTEXT ) )

   ? cSQLTEXT := "DELETE FROM person WHERE name == 'Andy'"
   ? "return value: ", cErrorMsg( sqlite3_exec( pDb, cSQLTEXT ) )

   ? cSQLTEXT := "END TRANSACTION"
   ? "return value: ", cErrorMsg( sqlite3_exec( pDb, cSQLTEXT ) )

   ? cSQLTEXT := "SELECT * FROM person WHERE name == 'Andy'"
   ? "return value: ", cErrorMsg( sqlite3_exec( pDb, cSQLTEXT, cb ) )

   ? Replicate( "-", Len( cSQLTEXT ) )

   sqlite3_sleep( 10000 )

   sqlite3_commit_hook( pDb, @HookCommitN() )
   sqlite3_rollback_hook( pDb, @HookRollback() )

   ? cSQLTEXT := "SELECT * FROM person WHERE name == 'Ivet'"
   ? "return value: ", cErrorMsg( sqlite3_exec( pDb, cSQLTEXT, cb ) )

   ? cSQLTEXT := "BEGIN EXCLUSIVE TRANSACTION"
   ? "return value: ", cErrorMsg( sqlite3_exec( pDb, cSQLTEXT ) )

   ? cSQLTEXT := "DELETE FROM person WHERE name == 'Ivet'"
   ? "return value: ", cErrorMsg( sqlite3_exec( pDb, cSQLTEXT ) )

   ? cSQLTEXT := "END TRANSACTION"
   ? "return value: ", cErrorMsg( sqlite3_exec( pDb, cSQLTEXT ) )

   ? cSQLTEXT := "SELECT * FROM person WHERE name == 'Ivet'"
   ? "return value: ", cErrorMsg( sqlite3_exec( pDb, cSQLTEXT, cb ) )

   pDb := NIL

   sqlite3_sleep( 10000 )

   RETURN

FUNCTION CallBack( nColCount, aValue, aColName )

   LOCAL nI
   LOCAL oldColor := SetColor( "G/N" )

   FOR nI := 1 TO nColCount
      ? PadR( aColName[ nI ], 5 ), " == ", aValue[ nI ]
   NEXT

   SetColor( oldColor )

   RETURN 0

FUNCTION HookCommitY()

   LOCAL oldColor := SetColor( "R+/N" )

   ? "!! COMMIT"

   SetColor( oldColor )

   RETURN 0

FUNCTION HookCommitN()

   LOCAL oldColor := SetColor( "B+/N" )

   ? "?? COMMIT or ROLLBACK"

   SetColor( oldColor )

   RETURN 1

FUNCTION HookRollback()

   LOCAL oldColor := SetColor( "R+/N" )

   ? "!! ROLLBACK"

   SetColor( oldColor )

   RETURN 1

STATIC FUNCTION cErrorMsg( nError, lShortMsg )

   hb_default( @lShortMsg, .T. )

   RETURN iif( lShortMsg, hb_sqlite3_errstr_short( nError ), sqlite3_errstr( nError ) )

STATIC FUNCTION PrepareDB( cFile )

   LOCAL cSQLTEXT, cMsg
   LOCAL pDb, pStmt
   LOCAL hPerson := { ;
      "Bob" => 52, ;
      "Fred" => 32, ;
      "Sasha" => 17, ;
      "Andy" => 20, ;
      "Ivet" => 28 ;
      }, enum

   pDb := sqlite3_open( cFile, .T. )
   IF Empty( pDb )
      ? "Can't open/create database : ", cFile

      RETURN NIL
   ENDIF

   ? cSQLTEXT := "CREATE TABLE person( name TEXT, age INTEGER )"
   cMsg := cErrorMsg( sqlite3_exec( pDb, cSQLTEXT ) )

   IF !( cMsg == "SQLITE_OK" )
      ? "Can't create table : person"
      pDb := NIL

      RETURN NIL
   ENDIF

   cSQLTEXT := "INSERT INTO person( name, age ) VALUES( :name, :age )"
   pStmt := sqlite3_prepare( pDb, cSQLTEXT )
   IF Empty( pStmt )
      ? "Can't prepare statement : ", cSQLTEXT
      pDb := NIL

      RETURN NIL
   ENDIF

   ? sqlite3_sql( pStmt )
   ? Replicate( "-", Len( cSQLTEXT ) )

   FOR EACH enum IN hPerson
      sqlite3_reset( pStmt )
      sqlite3_bind_text( pStmt, 1, enum:__enumKey() )
      sqlite3_bind_int( pStmt, 2, enum:__enumValue() )
      sqlite3_step( pStmt )
   NEXT

   sqlite3_clear_bindings( pStmt )
   sqlite3_finalize( pStmt )

   RETURN pDb


[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: Header file for contribution module 'hbtip' (Internet protocol utilities (FTP, HTTP, SMTP, POP3)): contrib/hbtip/tip.ch. Defines constants: TIP_CH, TIP_RO, TIP_WO, TIP_RW

[Assistant]
#ifndef TIP_CH
#define TIP_CH

#define TIP_RO  0
#define TIP_WO  1
#define TIP_RW  2

#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] Implement this Harbour module: Harbour contribution module 'hbhpdf' (PDF generation library (libharu)): contrib/hbhpdf/errstr.prg. Provides functions: hb_HPDF_GetErrorString. This file provides graphics and image processing capabilities

[Assistant]
#include "harupdf.ch"

FUNCTION hb_HPDF_GetErrorString( nStatus )

   IF ! HB_ISNUMERIC( nStatus )
      RETURN "HB_HPDF_INVALID"
   ENDIF

   SWITCH nStatus
   CASE HB_HPDF_BADPARAM                    ; RETURN "HB_HPDF_BADPARAM"
   CASE HPDF_OK                             ; RETURN "HPDF_OK"
   CASE HPDF_ARRAY_COUNT_ERR                ; RETURN "HPDF_ARRAY_COUNT_ERR"
   CASE HPDF_ARRAY_ITEM_NOT_FOUND           ; RETURN "HPDF_ARRAY_ITEM_NOT_FOUND"
   CASE HPDF_ARRAY_ITEM_UNEXPECTED_TYPE     ; RETURN "HPDF_ARRAY_ITEM_UNEXPECTED_TYPE"
   CASE HPDF_BINARY_LENGTH_ERR              ; RETURN "HPDF_BINARY_LENGTH_ERR"
   CASE HPDF_CANNOT_GET_PALLET              ; RETURN "HPDF_CANNOT_GET_PALLET"
   CASE HPDF_DICT_COUNT_ERR                 ; RETURN "HPDF_DICT_COUNT_ERR"
   CASE HPDF_DICT_ITEM_NOT_FOUND            ; RETURN "HPDF_DICT_ITEM_NOT_FOUND"
   CASE HPDF_DICT_ITEM_UNEXPECTED_TYPE      ; RETURN "HPDF_DICT_ITEM_UNEXPECTED_TYPE"
   CASE HPDF_DICT_STREAM_LENGTH_NOT_FOUND   ; RETURN "HPDF_DICT_STREAM_LENGTH_NOT_FOUND"
   CASE HPDF_DOC_ENCRYPTDICT_NOT_FOUND      ; RETURN "HPDF_DOC_ENCRYPTDICT_NOT_FOUND"
   CASE HPDF_DOC_INVALID_OBJECT             ; RETURN "HPDF_DOC_INVALID_OBJECT"
   CASE HPDF_DUPLICATE_REGISTRATION         ; RETURN "HPDF_DUPLICATE_REGISTRATION"
   CASE HPDF_EXCEED_JWW_CODE_NUM_LIMIT      ; RETURN "HPDF_EXCEED_JWW_CODE_NUM_LIMIT"
   CASE HPDF_ENCRYPT_INVALID_PASSWORD       ; RETURN "HPDF_ENCRYPT_INVALID_PASSWORD"
   CASE HPDF_ERR_UNKNOWN_CLASS              ; RETURN "HPDF_ERR_UNKNOWN_CLASS"
   CASE HPDF_EXCEED_GSTATE_LIMIT            ; RETURN "HPDF_EXCEED_GSTATE_LIMIT"
   CASE HPDF_FAILD_TO_ALLOC_MEM             ; RETURN "HPDF_FAILD_TO_ALLOC_MEM"
   CASE HPDF_FILE_IO_ERROR                  ; RETURN "HPDF_FILE_IO_ERROR"
   CASE HPDF_FILE_OPEN_ERROR                ; RETURN "HPDF_FILE_OPEN_ERROR"
   CASE HPDF_FONT_EXISTS                    ; RETURN "HPDF_FONT_EXISTS"
   CASE HPDF_FONT_INVALID_WIDTHS_TABLE      ; RETURN "HPDF_FONT_INVALID_WIDTHS_TABLE"
   CASE HPDF_INVALID_AFM_HEADER             ; RETURN "HPDF_INVALID_AFM_HEADER"
   CASE HPDF_INVALID_ANNOTATION             ; RETURN "HPDF_INVALID_ANNOTATION"
   CASE HPDF_INVALID_BIT_PER_COMPONENT      ; RETURN "HPDF_INVALID_BIT_PER_COMPONENT"
   CASE HPDF_INVALID_CHAR_MATRICS_DATA      ; RETURN "HPDF_INVALID_CHAR_MATRICS_DATA"
   CASE HPDF_INVALID_COLOR_SPACE            ; RETURN "HPDF_INVALID_COLOR_SPACE"
   CASE HPDF_INVALID_COMPRESSION_MODE       ; RETURN "HPDF_INVALID_COMPRESSION_MODE"
   CASE HPDF_INVALID_DATE_TIME              ; RETURN "HPDF_INVALID_DATE_TIME"
   CASE HPDF_INVALID_DESTINATION            ; RETURN "HPDF_INVALID_DESTINATION"
   CASE HPDF_INVALID_DOCUMENT               ; RETURN "HPDF_INVALID_DOCUMENT"
   CASE HPDF_INVALID_DOCUMENT_STATE         ; RETURN "HPDF_INVALID_DOCUMENT_STATE"
   CASE HPDF_INVALID_ENCODER                ; RETURN "HPDF_INVALID_ENCODER"
   CASE HPDF_INVALID_ENCODER_TYPE           ; RETURN "HPDF_INVALID_ENCODER_TYPE"
   CASE HPDF_INVALID_ENCODING_NAME          ; RETURN "HPDF_INVALID_ENCODING_NAME"
   CASE HPDF_INVALID_ENCRYPT_KEY_LEN        ; RETURN "HPDF_INVALID_ENCRYPT_KEY_LEN"
   CASE HPDF_INVALID_FONTDEF_DATA           ; RETURN "HPDF_INVALID_FONTDEF_DATA"
   CASE HPDF_INVALID_FONTDEF_TYPE           ; RETURN "HPDF_INVALID_FONTDEF_TYPE"
   CASE HPDF_INVALID_FONT_NAME              ; RETURN "HPDF_INVALID_FONT_NAME"
   CASE HPDF_INVALID_IMAGE                  ; RETURN "HPDF_INVALID_IMAGE"
   CASE HPDF_INVALID_JPEG_DATA              ; RETURN "HPDF_INVALID_JPEG_DATA"
   CASE HPDF_INVALID_N_DATA                 ; RETURN "HPDF_INVALID_N_DATA"
   CASE HPDF_INVALID_OBJECT                 ; RETURN "HPDF_INVALID_OBJECT"
   CASE HPDF_INVALID_OBJ_ID                 ; RETURN "HPDF_INVALID_OBJ_ID"
   CASE HPDF_INVALID_OPERATION              ; RETURN "HPDF_INVALID_OPERATION"
   CASE HPDF_INVALID_OUTLINE                ; RETURN "HPDF_INVALID_OUTLINE"
   CASE HPDF_INVALID_PAGE                   ; RETURN "HPDF_INVALID_PAGE"
   CASE HPDF_INVALID_PAGES                  ; RETURN "HPDF_INVALID_PAGES"
   CASE HPDF_INVALID_PARAMETER              ; RETURN "HPDF_INVALID_PARAMETER"
   CASE HPDF_INVALID_PNG_IMAGE              ; RETURN "HPDF_INVALID_PNG_IMAGE"
   CASE HPDF_INVALID_STREAM                 ; RETURN "HPDF_INVALID_STREAM"
   CASE HPDF_MISSING_FILE_NAME_ENTRY        ; RETURN "HPDF_MISSING_FILE_NAME_ENTRY"
   CASE HPDF_INVALID_TTC_FILE               ; RETURN "HPDF_INVALID_TTC_FILE"
   CASE HPDF_INVALID_TTC_INDEX              ; RETURN "HPDF_INVALID_TTC_INDEX"
   CASE HPDF_INVALID_WX_DATA                ; RETURN "HPDF_INVALID_WX_DATA"
   CASE HPDF_ITEM_NOT_FOUND                 ; RETURN "HPDF_ITEM_NOT_FOUND"
   CASE HPDF_LIBPNG_ERROR                   ; RETURN "HPDF_LIBPNG_ERROR"
   CASE HPDF_NAME_INVALID_VALUE             ; RETURN "HPDF_NAME_INVALID_VALUE"
   CASE HPDF_NAME_OUT_OF_RANGE              ; RETURN "HPDF_NAME_OUT_OF_RANGE"
   CASE HPDF_PAGE_INVALID_PARAM_COUNT       ; RETURN "HPDF_PAGE_INVALID_PARAM_COUNT"
   CASE HPDF_PAGES_MISSING_KIDS_ENTRY       ; RETURN "HPDF_PAGES_MISSING_KIDS_ENTRY"
   CASE HPDF_PAGE_CANNOT_FIND_OBJECT        ; RETURN "HPDF_PAGE_CANNOT_FIND_OBJECT"
   CASE HPDF_PAGE_CANNOT_GET_ROOT_PAGES     ; RETURN "HPDF_PAGE_CANNOT_GET_ROOT_PAGES"
   CASE HPDF_PAGE_CANNOT_RESTORE_GSTATE     ; RETURN "HPDF_PAGE_CANNOT_RESTORE_GSTATE"
   CASE HPDF_PAGE_CANNOT_SET_PARENT         ; RETURN "HPDF_PAGE_CANNOT_SET_PARENT"
   CASE HPDF_PAGE_FONT_NOT_FOUND            ; RETURN "HPDF_PAGE_FONT_NOT_FOUND"
   CASE HPDF_PAGE_INVALID_FONT              ; RETURN "HPDF_PAGE_INVALID_FONT"
   CASE HPDF_PAGE_INVALID_FONT_SIZE         ; RETURN "HPDF_PAGE_INVALID_FONT_SIZE"
   CASE HPDF_PAGE_INVALID_GMODE             ; RETURN "HPDF_PAGE_INVALID_GMODE"
   CASE HPDF_PAGE_INVALID_INDEX             ; RETURN "HPDF_PAGE_INVALID_INDEX"
   CASE HPDF_PAGE_INVALID_ROTATE_VALUE      ; RETURN "HPDF_PAGE_INVALID_ROTATE_VALUE"
   CASE HPDF_PAGE_INVALID_SIZE              ; RETURN "HPDF_PAGE_INVALID_SIZE"
   CASE HPDF_PAGE_INVALID_XOBJECT           ; RETURN "HPDF_PAGE_INVALID_XOBJECT"
   CASE HPDF_PAGE_OUT_OF_RANGE              ; RETURN "HPDF_PAGE_OUT_OF_RANGE"
   CASE HPDF_REAL_OUT_OF_RANGE              ; RETURN "HPDF_REAL_OUT_OF_RANGE"
   CASE HPDF_STREAM_EOF                     ; RETURN "HPDF_STREAM_EOF"
   CASE HPDF_STREAM_READLN_CONTINUE         ; RETURN "HPDF_STREAM_READLN_CONTINUE"
   CASE HPDF_STRING_OUT_OF_RANGE            ; RETURN "HPDF_STRING_OUT_OF_RANGE"
   CASE HPDF_THIS_FUNC_WAS_SKIPPED          ; RETURN "HPDF_THIS_FUNC_WAS_SKIPPED"
   CASE HPDF_TTF_CANNOT_EMBEDDING_FONT      ; RETURN "HPDF_TTF_CANNOT_EMBEDDING_FONT"
   CASE HPDF_TTF_INVALID_CMAP               ; RETURN "HPDF_TTF_INVALID_CMAP"
   CASE HPDF_TTF_INVALID_FOMAT              ; RETURN "HPDF_TTF_INVALID_FOMAT"
   CASE HPDF_TTF_MISSING_TABLE              ; RETURN "HPDF_TTF_MISSING_TABLE"
   CASE HPDF_UNSUPPORTED_FONT_TYPE          ; RETURN "HPDF_UNSUPPORTED_FONT_TYPE"
   CASE HPDF_UNSUPPORTED_FUNC               ; RETURN "HPDF_UNSUPPORTED_FUNC"
   CASE HPDF_UNSUPPORTED_JPEG_FORMAT        ; RETURN "HPDF_UNSUPPORTED_JPEG_FORMAT"
   CASE HPDF_UNSUPPORTED_TYPE1_FONT         ; RETURN "HPDF_UNSUPPORTED_TYPE1_FONT"
   CASE HPDF_XREF_COUNT_ERR                 ; RETURN "HPDF_XREF_COUNT_ERR"
   CASE HPDF_ZLIB_ERROR                     ; RETURN "HPDF_ZLIB_ERROR"
   CASE HPDF_INVALID_PAGE_INDEX             ; RETURN "HPDF_INVALID_PAGE_INDEX"
   CASE HPDF_INVALID_URI                    ; RETURN "HPDF_INVALID_URI"
   CASE HPDF_PAGE_LAYOUT_OUT_OF_RANGE       ; RETURN "HPDF_PAGE_LAYOUT_OUT_OF_RANGE"
   CASE HPDF_PAGE_MODE_OUT_OF_RANGE         ; RETURN "HPDF_PAGE_MODE_OUT_OF_RANGE"
   CASE HPDF_PAGE_NUM_STYLE_OUT_OF_RANGE    ; RETURN "HPDF_PAGE_NUM_STYLE_OUT_OF_RANGE"
   CASE HPDF_ANNOT_INVALID_ICON             ; RETURN "HPDF_ANNOT_INVALID_ICON"
   CASE HPDF_ANNOT_INVALID_BORDER_STYLE     ; RETURN "HPDF_ANNOT_INVALID_BORDER_STYLE"
   CASE HPDF_PAGE_INVALID_DIRECTION         ; RETURN "HPDF_PAGE_INVALID_DIRECTION"


[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 test program: tests/asort.prg. Provides functions: aDump, xToStr. Contains procedures: Main. This test file tests specific function APIs

[Assistant]
#ifndef __HARBOUR__
   #define hb_ntos( n ) LTrim( Str( n ) )
#endif

PROCEDURE Main()

   LOCAL oError := ErrorNew()

   LOCAL a := { 3, 2, 1 }
   LOCAL b := { 10 }
   LOCAL c := { 2, .T., "B", NIL, { 1 }, {|| b }, oError, Date(), 1, .F., "A", NIL, Date() - 1, { 0 }, {|| a }, oError }

   ? "Original...:", aDump( a )
   ? "ASort......:", aDump( ASort( AClone( a ) ) )
   ? "ASort.block:", aDump( ASort( AClone( a ), , , {| x, y | x < y } ) )
   ?
   ? "Original...:", aDump( b )
   ? "ASort......:", aDump( ASort( AClone( b ) ) )
   ? "ASort.block:", aDump( ASort( AClone( b ), , , {| x, y | x < y } ) )
   ?
   ? "Original...:", aDump( c )
   ? "ASort......:", aDump( ASort( AClone( c ) ) )
   ? "ASort.block:", aDump( ASort( AClone( c ), , , {| x, y | xToStr( x ) < xToStr( y ) } ) )
   ?

   RETURN

FUNCTION aDump( a )

   LOCAL cStr := ""
   LOCAL n := Len( a )
   LOCAL i

   FOR i := 1 TO n
      cStr += AllTrim( xToStr( a[ i ] ) ) + " "
   NEXT

   RETURN cStr

FUNCTION xToStr( xValue )

   LOCAL cType := ValType( xValue )

   DO CASE
   CASE cType == "C" .OR. cType == "M"
      RETURN xValue
   CASE cType == "N"
      RETURN hb_ntos( xValue )
   CASE cType == "D"
      RETURN DToC( xValue )
   CASE cType == "L"
      RETURN iif( xValue, ".T.", ".F." )
   CASE cType == "U"
      RETURN "NIL"
   CASE cType == "A"
      RETURN "{.}"
   CASE cType == "B"
      RETURN "{|| }"
   CASE cType == "O"
      RETURN "[O]"
   ENDCASE

   RETURN xValue


[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 'hbct' (CA-Tools compatibility library): contrib/hbct/kxlat.prg. This file provides legacy compatibility functions

[Assistant]
#include "inkey.ch"

#include "hbgtinfo.ch"
#include "hbinkey.ch"

#include "ctscan.ch"

#define hb_keyCode( x )  Asc( x )

STATIC s_hTrs := { => }
STATIC s_hMutex := hb_mutexCreate()

STATIC sc_hCnv := { ;
   KS_DISABLE        => 0                 , ;
   KS_A              => hb_keyCode( "A" ) , ;
   KS_B              => hb_keyCode( "B" ) , ;
   KS_C              => hb_keyCode( "C" ) , ;
   KS_D              => hb_keyCode( "D" ) , ;
   KS_E              => hb_keyCode( "E" ) , ;
   KS_F              => hb_keyCode( "F" ) , ;
   KS_G              => hb_keyCode( "G" ) , ;
   KS_H              => hb_keyCode( "H" ) , ;
   KS_I              => hb_keyCode( "I" ) , ;
   KS_J              => hb_keyCode( "J" ) , ;
   KS_K              => hb_keyCode( "K" ) , ;
   KS_L              => hb_keyCode( "L" ) , ;
   KS_M              => hb_keyCode( "M" ) , ;
   KS_N              => hb_keyCode( "N" ) , ;
   KS_O              => hb_keyCode( "O" ) , ;
   KS_P              => hb_keyCode( "P" ) , ;
   KS_Q              => hb_keyCode( "Q" ) , ;
   KS_R              => hb_keyCode( "R" ) , ;
   KS_S              => hb_keyCode( "S" ) , ;
   KS_T              => hb_keyCode( "T" ) , ;
   KS_U              => hb_keyCode( "U" ) , ;
   KS_V              => hb_keyCode( "V" ) , ;
   KS_W              => hb_keyCode( "W" ) , ;
   KS_X              => hb_keyCode( "X" ) , ;
   KS_Y              => hb_keyCode( "Y" ) , ;
   KS_Z              => hb_keyCode( "Z" ) , ;
   KS_a              => hb_keyCode( "a" ) , ;
   KS_b              => hb_keyCode( "b" ) , ;
   KS_c              => hb_keyCode( "c" ) , ;
   KS_d              => hb_keyCode( "d" ) , ;
   KS_e              => hb_keyCode( "e" ) , ;
   KS_f              => hb_keyCode( "f" ) , ;
   KS_g              => hb_keyCode( "g" ) , ;
   KS_h              => hb_keyCode( "h" ) , ;
   KS_i              => hb_keyCode( "i" ) , ;
   KS_j              => hb_keyCode( "j" ) , ;
   KS_k              => hb_keyCode( "k" ) , ;
   KS_l              => hb_keyCode( "l" ) , ;
   KS_m              => hb_keyCode( "m" ) , ;
   KS_n              => hb_keyCode( "n" ) , ;
   KS_o              => hb_keyCode( "o" ) , ;
   KS_p              => hb_keyCode( "p" ) , ;
   KS_q              => hb_keyCode( "q" ) , ;
   KS_r              => hb_keyCode( "r" ) , ;
   KS_s              => hb_keyCode( "s" ) , ;
   KS_t              => hb_keyCode( "t" ) , ;
   KS_u              => hb_keyCode( "u" ) , ;
   KS_v              => hb_keyCode( "v" ) , ;
   KS_w              => hb_keyCode( "w" ) , ;
   KS_x              => hb_keyCode( "x" ) , ;
   KS_y              => hb_keyCode( "y" ) , ;
   KS_z              => hb_keyCode( "z" ) , ;
   KS_1              => hb_keyCode( "1" ) , ;
   KS_2              => hb_keyCode( "2" ) , ;
   KS_3              => hb_keyCode( "3" ) , ;
   KS_4              => hb_keyCode( "4" ) , ;
   KS_5              => hb_keyCode( "5" ) , ;
   KS_6              => hb_keyCode( "6" ) , ;
   KS_7              => hb_keyCode( "7" ) , ;
   KS_8              => hb_keyCode( "8" ) , ;
   KS_9              => hb_keyCode( "9" ) , ;
   KS_0              => hb_keyCode( "0" ) , ;
   KS_DOT            => hb_keyCode( "." ) , ;
   KS_COMMA          => hb_keyCode( "," ) , ;
   KS_CTRL_A         => K_CTRL_A          , ;
   KS_CTRL_B         => K_CTRL_B          , ;
   KS_CTRL_C         => K_CTRL_C          , ;
   KS_CTRL_D         => K_CTRL_D          , ;
   KS_CTRL_E         => K_CTRL_E          , ;
   KS_CTRL_F         => K_CTRL_F          , ;
   KS_CTRL_G         => K_CTRL_G          , ;
   KS_CTRL_H         => K_CTRL_H          , ;
   KS_CTRL_I         => K_CTRL_I          , ;
   KS_CTRL_M         => K_CTRL_M          , ;
   KS_CTRL_N         => K_CTRL_N          , ;
   KS_CTRL_R         => K_CTRL_R          , ;
   KS_CTRL_S         => K_CTRL_S          , ;
   KS_CTRL_T         => K_CTRL_T          , ;
   KS_CTRL_U         => K_CTRL_U          , ;
   KS_CTRL_V         => K_CTRL_V          , ;
   KS_CTRL_W         => K_CTRL_W          , ;
   KS_CTRL_X         => K_CTRL_X          , ;
   KS_CTRL_Y         => K_CTRL_Y          , ;
   KS_CTRL_Z         => K_CTRL_Z          , ;
   KS_ALT_A          => K_ALT_A           , ;
   KS_ALT_B          => K_ALT_B           , ;
   KS_ALT_C          => K_ALT_C           , ;
   KS_ALT_D          => K_ALT_D           , ;
   KS_ALT_E          => K_ALT_E           , ;
   KS_ALT_F          => K_ALT_F           , ;
   KS_ALT_G          => K_ALT_G           , ;
   KS_ALT_H          => K_ALT_H           , ;
   KS_ALT_I          => K_ALT_I           , ;
   KS_ALT_J          => K_ALT_J           , ;
   KS_ALT_K          => K_ALT_K           , ;
   KS_ALT_L          => K_ALT_L           , ;
   KS_ALT_M          => K_ALT_M           , ;
   KS_ALT_N          => K_ALT_N           , ;
   KS_ALT_O          => K_ALT_O           , ;
   KS_ALT_P          => K_ALT_P           , ;
   KS_ALT_Q          => K_ALT_Q           , ;
   KS_ALT_R          => K_ALT_R           , ;
   KS_ALT_S          => K_ALT_S           , ;
   KS_ALT_T          => K_ALT_T           , ;
   KS_ALT_U          => K_ALT_U           , ;
   KS_ALT_V          => K_ALT_V           , ;
   KS_ALT_W          => K_ALT_W           , ;
   KS_ALT_X          => K_ALT_X           , ;
   KS_ALT_Y          => K_ALT_Y           , ;
   KS_ALT_Z          => K_ALT_Z           , ;
   KS_ALT_1          => K_ALT_1           , ;
   KS_ALT_2          => K_ALT_2           , ;
   KS_ALT_3          => K_ALT_3           , ;
   KS_ALT_4          => K_ALT_4           , ;
   KS_ALT_5          => K_ALT_5           , ;
   KS_ALT_6          => K_ALT_6           , ;
   KS_ALT_7          => K_ALT_7           , ;
   KS_ALT_8          => K_ALT_8           , ;
   KS_ALT_9          => K_ALT_9           , ;
   KS_ALT_0          => K_ALT_0           , ;
   KS_F1             => K_F1              , ;
   KS_F2             => K_F2              , ;
   KS_F3             => K_F3              , ;
   KS_F4             => K_F4              , ;
   KS_F5             => K_F5              , ;
   KS_F6             => K_F6              , ;
   KS_F7             => K_F7              , ;
   KS_F8             => K_F8              , ;
   KS_F9             => K_F9              , ;
   KS_F10            => K_F10             , ;
   KS_F11            => K_F11             , ;
   KS_F12            => K_F12             , ;
   KS_SH_F1          => K_SH_F1           , ;
   KS_SH_F2          => K_SH_F2           , ;
   KS_SH_F3          => K_SH_F3           , ;
   KS_SH_F4          => K_SH_F4           , ;
   KS_SH_F5          => K_SH_F5           , ;
   KS_SH_F6          => K_SH_F6           , ;
   KS_SH_F7          => K_SH_F7           , ;
   KS_SH_F8          => K_SH_F8           , ;
   KS_SH_F9          => K_SH_F9           , ;
   KS_SH_F10         => K_SH_F10          , ;
   KS_SH_F11         => K_SH_F11          , ;
   KS_SH_F12         => K_SH_F12          , ;
   KS_CTRL_F1        => K_CTRL_F1         , ;
   KS_CTRL_F2        => K_CTRL_F2         , ;
   KS_CTRL_F3        => K_CTRL_F3         , ;
   KS_CTRL_F4        => K_CTRL_F4         , ;
   KS_CTRL_F5        => K_CTRL_F5         , ;
   KS_CTRL_F6        => K_CTRL_F6         , ;
   KS_CTRL_F7        => K_CTRL_F7         , ;
   KS_CTRL_F8        => K_CTRL_F8         , ;
   KS_CTRL_F9        => K_CTRL_F9         , ;
   KS_CTRL_F10       => K_CTRL_F10        , ;
   KS_CTRL_F11       => K_CTRL_F11        , ;
   KS_CTRL_F12       => K_CTRL_F12        , ;
   KS_ALT_F1         => K_ALT_F1          , ;
   KS_ALT_F2         => K_ALT_F2          , ;
   KS_ALT_F3         => K_ALT_F3          , ;
   KS_ALT_F4         => K_ALT_F4          , ;
   KS_ALT_F5         => K_ALT_F5          , ;
   KS_ALT_F6         => K_ALT_F6          , ;
   KS_ALT_F7         => K_ALT_F7          , ;
   KS_ALT_F8         => K_ALT_F8          , ;
   KS_ALT_F9         => K_ALT_F9          , ;
   KS_ALT_F10        => K_ALT_F10         , ;
   KS_ALT_F11        => K_ALT_F11         , ;
   KS_ALT_F12        => K_ALT_F12         , ;


[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 Runtime Library file: src/rtl/menuto.prg. Provides functions: __AtPrompt, __MenuTo, HitTest. This file provides utility functions

[Assistant]
#include "color.ch"
#include "inkey.ch"
#include "hbmemvar.ch"
#include "setcurs.ch"

#define _ITM_ROW     1
#define _ITM_COL     2
#define _ITM_PROMPT  3
#define _ITM_MSG     4
#define _ITM_COLOR   5

THREAD STATIC t_aLevel   := {}
THREAD STATIC t_nPointer := 1

FUNCTION __AtPrompt( nRow, nCol, cPrompt, cMsg, cColor )

   IF t_nPointer < 1
      t_nPointer := 1
   ENDIF

   DO WHILE Len( t_aLevel ) < t_nPointer
      AAdd( t_aLevel, {} )
   ENDDO

   AAdd( t_aLevel[ t_nPointer ], { ;
      nRow, ;
      nCol, ;
      cPrompt, ;
      cMsg, ;
      cColor } )

   DispOutAt( nRow, nCol, cPrompt, cColor )

   RETURN .F.

FUNCTION __MenuTo( bBlock, cVariable )

   LOCAL nKey
   LOCAL cKey
   LOCAL y
   LOCAL q
   LOCAL n
   LOCAL lExit
   LOCAL nArrLen
   LOCAL xMsg
   LOCAL nMsgCol
   LOCAL nMsgRow
   LOCAL lMsgCenter
   LOCAL nSaveCursor
   LOCAL cSaveReadVar

   LOCAL lDeclared
   LOCAL bAction
#ifdef HB_COMPAT_C53
   LOCAL nMouseClik
#endif

   LOCAL nPointer
   LOCAL cColor
   LOCAL cColorSelect
   LOCAL cColorNormal
#ifndef HB_CLP_STRICT
   LOCAL nHiLited
#endif

   lDeclared := ! __mvExist( cVariable )

   IF lDeclared
      __mvPublic( cVariable )
   ENDIF

   n := Eval( bBlock )

   IF t_nPointer < 1 .OR. t_nPointer > Len( t_aLevel )

      n := 0

   ELSE

      t_nPointer++
      nPointer := t_nPointer

      nArrLen := Len( t_aLevel[ nPointer - 1 ] )

      IF ! HB_ISNUMERIC( n ) .OR. n < 1
         n := 1
      ENDIF

      IF n > nArrLen
         n := nArrLen
      ENDIF

#ifndef HB_CLP_STRICT
      nHiLited := 0
#endif

      nSaveCursor := SetCursor( iif( Set( _SET_INTENSITY ), SC_NONE, NIL ) )
      cSaveReadVar := ReadVar( hb_asciiUpper( cVariable ) )
      xMsg := ""
      nMsgCol := 0
      nMsgRow := Set( _SET_MESSAGE )
      lMsgCenter := Set( _SET_MCENTER )
      lExit := .F.

      DO WHILE n != 0

         IF nMsgRow > 0

            IF ! Empty( xMsg )
               DispOutAt( nMsgRow, nMsgCol, Space( Len( xMsg ) ) )
            ENDIF

            xMsg := t_aLevel[ nPointer - 1 ][ n ][ _ITM_MSG ]

            IF HB_ISEVALITEM( xMsg )
               xMsg := Eval( xMsg )
            ENDIF

            hb_default( @xMsg, "" )

            IF lMsgCenter
               nMsgCol := Int( ( MaxCol() - Len( xMsg ) ) / 2 )
            ENDIF

            DispOutAt( nMsgRow, nMsgCol, xMsg )

         ENDIF

         q := n

         cColor := t_aLevel[ t_nPointer - 1 ][ n ][ _ITM_COLOR ]
         cColorNormal := hb_ColorIndex( iif( Empty( hb_ColorIndex( cColor, CLR_STANDARD ) ), SetColor(), cColor ), CLR_STANDARD )
         IF Set( _SET_INTENSITY )
            cColorSelect := hb_ColorIndex( iif( Empty( hb_ColorIndex( cColor, CLR_ENHANCED ) ), SetColor(), cColor ), CLR_ENHANCED )
         ELSE
            cColorSelect := cColorNormal
         ENDIF

#ifndef HB_CLP_STRICT

         IF nHiLited != n
            nHiLited := n
#endif

            DispOutAt( ;
               t_aLevel[ nPointer - 1 ][ n ][ _ITM_ROW ], ;
               t_aLevel[ nPointer - 1 ][ n ][ _ITM_COL ], ;
               t_aLevel[ nPointer - 1 ][ n ][ _ITM_PROMPT ], ;
               cColorSelect )
#ifndef HB_CLP_STRICT
         ENDIF
#endif

         IF lExit
            EXIT
         ENDIF

         nKey := 0
         DO WHILE nKey == 0

            nKey := Inkey( 0 )

            IF ( bAction := SetKey( nKey ) ) != NIL

               Eval( bBlock, n )
               Eval( bAction, ProcName( 1 ), ProcLine( 1 ), hb_asciiUpper( cVariable ) )
               n := Eval( bBlock )

               IF n < 1
                  n := 1
               ELSEIF n > nArrLen
                  n := nArrLen
               ENDIF

               nKey := 0

            ENDIF
         ENDDO

         SWITCH nKey
#ifdef HB_COMPAT_C53
         CASE K_MOUSEMOVE
            EXIT
         CASE K_LBUTTONDOWN
         CASE K_LDBLCLK
            IF ( nMouseClik := HitTest( t_aLevel[ nPointer - 1 ], ;
               MRow(), MCol() ) ) > 0
               n := nMouseClik
            ENDIF

            IF nKey == K_LDBLCLK
               lExit := .T.
            ENDIF
            EXIT
#endif
         CASE K_DOWN
         CASE K_RIGHT
            IF ++n > nArrLen
               n := iif( Set( _SET_WRAP ), 1, nArrLen )
            ENDIF
            EXIT
         CASE K_UP
         CASE K_LEFT
            IF --n < 1
               n := iif( Set( _SET_WRAP ), nArrLen, 1 )
            ENDIF
            EXIT
         CASE K_HOME
            n := 1
            EXIT
         CASE K_END
            n := nArrLen
            EXIT
         CASE K_ENTER
         CASE K_PGUP
         CASE K_PGDN
            lExit := .T.
            EXIT
         CASE K_ESC
            n := 0
            EXIT
         OTHERWISE

            IF Len( cKey := Upper( hb_keyChar( nKey ) ) ) > 0
               FOR y := 1 TO nArrLen
                  IF hb_LeftEqI( LTrim( t_aLevel[ nPointer - 1 ][ y ][ _ITM_PROMPT ] ), cKey )
                     n := y
                     lExit := .T.
                     EXIT
                  ENDIF
               NEXT
            ENDIF
         ENDSWITCH

         IF n != 0
#ifndef HB_CLP_STRICT

            IF nHiLited != n
               nHiLited := 0
#endif
               DispOutAt( ;
                  t_aLevel[ nPointer - 1 ][ q ][ _ITM_ROW ], ;
                  t_aLevel[ nPointer - 1 ][ q ][ _ITM_COL ], ;
                  t_aLevel[ nPointer - 1 ][ q ][ _ITM_PROMPT ], ;
                  cColorNormal )
#ifndef HB_CLP_STRICT
            ENDIF
#endif
         ENDIF

      ENDDO

      ReadVar( cSaveReadVar )
      SetCursor( nSaveCursor )

      t_nPointer := nPointer
      t_nPointer--
      ASize( t_aLevel, t_nPointer - 1 )

   ENDIF

   Eval( bBlock, n )

   IF lDeclared
      __mvXRelease( cVariable )
   ENDIF

   SetPos( MaxRow() - 1, 0 )

   RETURN n

#ifdef HB_COMPAT_C53

STATIC FUNCTION HitTest( aMenu, nMRow, nMCol )

   LOCAL aMenuItem

   FOR EACH aMenuItem IN aMenu
      IF nMRow == aMenuItem[ _ITM_ROW ] .AND. ;
         nMCol >= aMenuItem[ _ITM_COL ] .AND. ;
         nMCol < aMenuItem[ _ITM_COL ] + Len( aMenuItem[ _ITM_PROMPT ] )

         RETURN aMenuItem:__enumIndex()
      ENDIF
   NEXT

   RETURN 0

#endif