[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/hbiousr.ch. Defines 10 constants including: _HBIOUSR_CH, IOUSR_ACCEPT, IOUSR_EXISTS, IOUSR_DELETE, IOUSR_RENAME. Defines communication constants

[Assistant]
#ifndef _HBIOUSR_CH
#define _HBIOUSR_CH

#define IOUSR_ACCEPT                 1
#define IOUSR_EXISTS                 2
#define IOUSR_DELETE                 3
#define IOUSR_RENAME                 4
#define IOUSR_COPY                   5

#define IOUSR_DIREXISTS              6
#define IOUSR_DIRMAKE                7
#define IOUSR_DIRREMOVE              8
#define IOUSR_DIRSPACE               9
#define IOUSR_DIRECTORY             10

#define IOUSR_TIMEGET               11
#define IOUSR_TIMESET               12
#define IOUSR_ATTRGET               13
#define IOUSR_ATTRSET               14

#define IOUSR_LINK                  15
#define IOUSR_LINKSYM               16
#define IOUSR_LINKREAD              17

#define IOUSR_OPEN                  18
#define IOUSR_CLOSE                 19
#define IOUSR_LOCK                  20
#define IOUSR_LOCKTEST              21
#define IOUSR_READ                  22
#define IOUSR_WRITE                 23
#define IOUSR_READAT                24
#define IOUSR_WRITEAT               25
#define IOUSR_TRUNCAT               26
#define IOUSR_SEEK                  27
#define IOUSR_SIZE                  28
#define IOUSR_EOF                   29
#define IOUSR_FLUSH                 30
#define IOUSR_COMMIT                31
#define IOUSR_CONFIGURE             32
#define IOUSR_HANDLE                33

#define IOUSR_METHODCOUNT           33

#endif


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

[User] Generate Harbour code for: Harbour contribution module 'hbtip' (Internet protocol utilities (FTP, HTTP, SMTP, POP3)): contrib/hbtip/smtpcli.prg. Defines classes: TIPClientSMTP. This file provides network protocol implementations

[Assistant]
#include "hbclass.ch"

#include "tip.ch"

CREATE CLASS TIPClientSMTP INHERIT TIPClient

   VAR lAuthLOGIN INIT .F.
   VAR lAuthPLAIN INIT .F.
   VAR lTLS       INIT .F.

   METHOD New( oUrl, xTrace, oCredentials, cClientHost )
   METHOD Open( cUrl, lSSL )
   METHOD Close()
   METHOD Write( cData, nLen, bCommit )
   METHOD Mail( cFrom )
   METHOD Rcpt( cTo )
   METHOD Data( cData )
   METHOD Commit()
   METHOD Quit()
   METHOD GetOK()
   METHOD SendMail( oTIpMail )

   METHOD OpenSecure( cUrl, lSSL )
   METHOD Auth( cUser, cPass )
   METHOD AuthPlain( cUser, cPass )
   METHOD ServerSuportSecure( lAuthPlain, lAuthLogin )
   METHOD StartTLS()
   METHOD DetectSecurity()

   HIDDEN:

   VAR isAuth INIT .F.
   VAR cClientHost

ENDCLASS

METHOD New( oUrl, xTrace, oCredentials, cClientHost ) CLASS TIPClientSMTP

   ::super:new( oUrl, iif( hb_defaultValue( xTrace, .F. ), "smtp", xTrace ), oCredentials )

   ::nDefaultPort := iif( ::oUrl:cProto == "smtps", 465, 25 )
   ::nConnTimeout := 50000
   ::nAccessMode := TIP_WO
   ::cClientHost := cClientHost

   RETURN Self

METHOD Open( cUrl, lSSL ) CLASS TIPClientSMTP

   LOCAL lOk

   IF ! ::super:Open( cUrl )
      RETURN .F.
   ENDIF

   IF ! ::GetOk()
      RETURN .F.
   ENDIF

   IF hb_defaultValue( lSSL, .F. )
      ::EnableSSL( .T. )
      ::lAuthLogin := .T.
      ::lAuthPlain := .T.
   ENDIF

   ::inetSendAll( ::SocketCon, "HELO " + iif( Empty( ::cClientHost ), "TIPClientSMTP", ::cClientHost ) + ::cCRLF )

   DO WHILE .T.
      IF !( lOk := ::GetOk() ) .OR. ::cReply == NIL .OR. ;
         hb_LeftEq( ::cReply, "250 " )
         EXIT
      ENDIF
   ENDDO

   RETURN lOk

METHOD OpenSecure( cUrl, lSSL ) CLASS TIPClientSMTP

   LOCAL lOk

   IF ! ::super:Open( cUrl )
      RETURN .F.
   ENDIF

   IF ! ::GetOk()
      RETURN .F.
   ENDIF

   hb_default( @lSSL, .F. )

   IF lSSL
      ::EnableSSL( .T. )
      ::lAuthLogin := .T.
      ::lAuthPlain := .T.
   ENDIF

   ::inetSendAll( ::SocketCon, "EHLO " + iif( Empty( ::cClientHost ), "TIPClientSMTP", ::cClientHost ) + ::cCRLF )

   lOk := ::DetectSecurity()

   IF lOk .AND. ! lSSL .AND. ::lTLS
      lOk := ::StartTLS()
   ENDIF

   RETURN lOk

METHOD GetOk() CLASS TIPClientSMTP

   ::cReply := ::inetRecvLine( ::SocketCon,, 512 )
   IF ::inetErrorCode( ::SocketCon ) != 0 .OR. ! HB_ISSTRING( ::cReply ) .OR. hb_LeftEq( ::cReply, "5" )
      RETURN .F.
   ENDIF

   RETURN .T.

METHOD StartTLS() CLASS TIPClientSMTP

   ::inetSendAll( ::SocketCon, "STARTTLS" + ::cCRLF )

   IF ::GetOk() .AND. ::lHasSSL
      ::EnableSSL( .T. )
      __tip_SSLConnectFD( ::ssl, ::SocketCon )
      ::inetSendAll( ::SocketCon, "EHLO " + iif( Empty( ::cClientHost ), "TIPClientSMTP", ::cClientHost ) + ::cCRLF )
      RETURN ::DetectSecurity()
   ENDIF

   RETURN .F.

METHOD DetectSecurity() CLASS TIPClientSMTP

   LOCAL lOk

   DO WHILE .T.
      IF !( lOk := ::GetOk() ) .OR. ;
         ::cReply == NIL
         EXIT
      ENDIF
      IF "LOGIN" $ ::cReply
         ::lAuthLogin := .T.
      ENDIF
      IF "PLAIN" $ ::cReply
         ::lAuthPlain := .T.
      ENDIF
      IF ::HasSSL() .AND. "STARTTLS" $ ::cReply
         ::lTLS := .T.
         ::lAuthLogin := .T.
         ::lAuthPlain := .T.
      ENDIF

      IF hb_LeftEq( ::cReply, "250 " )
         EXIT
      ENDIF
   ENDDO

   RETURN lOk

METHOD Close() CLASS TIPClientSMTP

   ::InetTimeOut( ::SocketCon )
   ::Quit()

   RETURN ::super:Close()

METHOD Commit() CLASS TIPClientSMTP

   ::inetSendAll( ::SocketCon, ::cCRLF + "." + ::cCRLF )

   RETURN ::GetOk()

METHOD Quit() CLASS TIPClientSMTP

   ::inetSendAll( ::SocketCon, "QUIT" + ::cCRLF )
   ::isAuth := .F.

   RETURN ::GetOk()

METHOD Mail( cFrom ) CLASS TIPClientSMTP

   ::inetSendAll( ::SocketCon, "MAIL FROM: <" + cFrom + ">" + ::cCRLF )

   RETURN ::GetOk()

METHOD Rcpt( cTo ) CLASS TIPClientSMTP

   ::inetSendAll( ::SocketCon, "RCPT TO: <" + cTo + ">" + ::cCRLF )

   RETURN ::GetOk()

METHOD Data( cData ) CLASS TIPClientSMTP

   ::inetSendAll( ::SocketCon, "DATA" + ::cCRLF )
   IF ! ::GetOk()
      RETURN .F.
   ENDIF
   ::inetSendAll( ::SocketCon, cData + ::cCRLF + "." + ::cCRLF )

   RETURN ::GetOk()

METHOD Auth( cUser, cPass ) CLASS TIPClientSMTP

   ::inetSendAll( ::SocketCon, "AUTH LOGIN" + ::cCRLF )
   IF ::GetOk()
      ::inetSendAll( ::SocketCon, hb_base64Encode( StrTran( cUser, "&at;", "@" ) ) + ::cCRLF  )
      IF ::GetOk()
         ::inetSendAll( ::SocketCon, hb_base64Encode( cPass ) + ::cCRLF )
         IF ::GetOk()
            RETURN ::isAuth := .T.
         ENDIF
      ENDIF
   ENDIF

   RETURN ::isAuth := .F.

METHOD AuthPlain( cUser, cPass ) CLASS TIPClientSMTP

   ::inetSendAll( ::SocketCon, "AUTH PLAIN " + hb_base64Encode( hb_BChar( 0 ) + cUser + hb_BChar( 0 ) + cPass ) + ::cCRLF )

   RETURN ::isAuth := ::GetOk()

METHOD Write( cData, nLen, bCommit ) CLASS TIPClientSMTP

   LOCAL cRcpt

   IF ! ::bInitialized

      IF Empty( ::oUrl:cFile )
         RETURN -1
      ENDIF

      IF ! ::Mail( ::oUrl:cUserid )
         RETURN -1
      ENDIF

      FOR EACH cRcpt IN hb_regexSplit( ",", ::oUrl:cFile )
         IF ! ::Rcpt( cRcpt )
            RETURN -1
         ENDIF
      NEXT

      ::inetSendAll( ::SocketCon, "DATA" + ::cCRLF )
      IF ! ::GetOk()
         RETURN -1
      ENDIF
      ::bInitialized := .T.
   ENDIF

   RETURN ::super:Write( cData, nLen, bCommit )

METHOD ServerSuportSecure(  lAuthPlain,  lAuthLogin ) CLASS TIPClientSMTP

   IF ::OpenSecure()
      lAuthLogin := ::lAuthLogin
      lAuthPlain := ::lAuthPlain
      ::Close()
   ELSE
      lAuthLogin := .F.
      lAuthPlain := .F.
   ENDIF

   RETURN lAuthLogin .OR. lAuthPlain

METHOD SendMail( oTIpMail ) CLASS TIPClientSmtp

   LOCAL cTo

   IF ! ::isOpen
      RETURN .F.
   ENDIF

   IF ! ::isAuth
      ::Auth( ::oUrl:cUserId, ::oUrl:cPassword )
      IF ! ::isAuth
         RETURN .F.
      ENDIF
   ENDIF

   ::mail( oTIpMail:getFieldPart( "From" ) )

   FOR EACH cTo IN hb_regexSplit( ",", hb_StrReplace( oTIpMail:getFieldPart( "To" ), ;
                                                      { tip_CRLF(), Chr( 9 ), " " } ) )
      ::rcpt( cTo )
   NEXT

   RETURN ::data( oTIpMail:toString() )


[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 'hbblat' (Blat email sending utility): contrib/hbblat/hbblat.ch. Defines 10 constants including: _HBBLAT_CH, BLAT_ERR_UNKNONW, BLAT_SUCCESS, BLAT_ERR_MESSAGE_NOT_ACCEPTED, BLAT_ERR_MISSING_FROM. Defines file I/O constants

[Assistant]
#ifndef _HBBLAT_CH
#define _HBBLAT_CH

#define BLAT_ERR_UNKNONW                               -1

#define BLAT_SUCCESS                                   0
#define BLAT_ERR_MESSAGE_NOT_ACCEPTED                  1

#define BLAT_ERR_MISSING_FROM                          1000
#define BLAT_ERR_MISSING_TO                            1001
#define BLAT_ERR_MISSING_TOFILE                        1002
#define BLAT_ERR_MISSING_BODY                          1003
#define BLAT_ERR_MISSING_BODYFILE                      1004
#define BLAT_ERR_MISSING_SERVERSMTP                    1005
#define BLAT_ERR_MISSING_SUBJECTFILE                   1006
#define BLAT_ERR_MISSING_CCFILE                        1007
#define BLAT_ERR_MISSING_BCCFILE                       1008
#define BLAT_ERR_MISSING_PSFILE                        1009
#define BLAT_ERR_MISSING_ATTACHLISTBINFILE             1010
#define BLAT_ERR_MISSING_ATTACHLISTTEXTFILE            1011
#define BLAT_ERR_MISSING_ATTACHLISTEMBEDDEDFILE        1012
#define BLAT_ERR_MISSING_ALTERNATETEXTFILE             1013
#define BLAT_ERR_MISSING_SIGNATUREFILE                 1014
#define BLAT_ERR_MISSING_TAGFILE                       1015
#define BLAT_ERR_WRONG_DSN                             1016

#define BLAT_ERR_LOGICAL_EXPECTED                      2000
#define BLAT_ERR_STRING_EXPECTED                       2001

#define BLAT_TEXT_ERROR                                "Blat Error"

#define BLAT_TEXT_ERR_UNKNOWN                          "Unknown error"

#define BLAT_TEXT_SUCCESS                              "Ok"
#define BLAT_TEXT_ERR_MESSAGE_NOT_ACCEPTED             "Message not accepted by server"

#define BLAT_TEXT_ERR_MISSING_FROM                     "Missing From: parameter"
#define BLAT_TEXT_ERR_MISSING_TO                       "Missing To: parameter"
#define BLAT_TEXT_ERR_MISSING_TOFILE                   "ToFile file not found"
#define BLAT_TEXT_ERR_MISSING_BODY                     "Missing message body"
#define BLAT_TEXT_ERR_MISSING_BODYFILE                 "Message body file not found"
#define BLAT_TEXT_ERR_MISSING_SERVERSMTP               "Missing SMTP server"
#define BLAT_TEXT_ERR_MISSING_SUBJECTFILE              "Subject file not found"
#define BLAT_TEXT_ERR_MISSING_CCFILE                   "CC file not found"
#define BLAT_TEXT_ERR_MISSING_BCCFILE                  "BCC file not found"
#define BLAT_TEXT_ERR_MISSING_PSFILE                   "PS file not found"
#define BLAT_TEXT_ERR_MISSING_ATTACHLISTBINFILE        "Attach List Bin file not found"
#define BLAT_TEXT_ERR_MISSING_ATTACHLISTTEXTFILE       "Attach List Text file not found"
#define BLAT_TEXT_ERR_MISSING_ATTACHLISTEMBEDDEDFILE   "Attach List Embedded file not found"
#define BLAT_TEXT_ERR_MISSING_ALTERNATETEXTFILE        "Alternate Text file not found"
#define BLAT_TEXT_ERR_MISSING_SIGNATUREFILE            "Signature file not found"
#define BLAT_TEXT_ERR_MISSING_TAGFILE                  "Tag file not found"
#define BLAT_TEXT_ERR_WRONG_DSN                        "Wrong DSN values (admitted: n, s, f, d)"

#define BLAT_TEXT_ERR_LOGICAL_EXPECTED                 "Logical var expected"
#define BLAT_TEXT_ERR_STRING_EXPECTED                  "String var expected"

#define BLAT_ERR_CANT_MALLOC                           4001
#define BLAT_ERR_SENDING_DATA                          4002
#define BLAT_ERR_INITIALIZING                          4003
#define BLAT_ERR_VER_NOT_SUPPORTED                     4004
#define BLAT_ERR_EINVAL                                4005
#define BLAT_ERR_SYS_NOT_READY                         4006
#define BLAT_ERR_CANT_RESOLVE_HOSTNAME                 4007
#define BLAT_ERR_CANT_GET_SOCKET                       4008
#define BLAT_ERR_READING_SOCKET                        4009
#define BLAT_ERR_NOT_A_SOCKET                          4010
#define BLAT_ERR_BUSY                                  4011
#define BLAT_ERR_CLOSING                               4012
#define BLAT_WAIT_A_BIT                                4013
#define BLAT_ERR_CANT_RESOLVE_SERVICE                  4014
#define BLAT_ERR_CANT_CONNECT                          4015
#define BLAT_ERR_NOT_CONNECTED                         4016
#define BLAT_ERR_CONNECTION_REFUSED                    4017

#define BLAT_ERR_NO_ERROR_CODE                         -5000
#define BLAT_TRY_INFINITE_KEY                          -1
#define BLAT_TRY_INFINITE_VALUE                        "INFINITE"

#endif


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

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

Harbour header file: include/hbmacro.ch. Defines 8 constants including: HB_MACRO_CH_, HB_SM_HARBOUR, HB_SM_XBASE, HB_SM_SHORTCUTS, HB_SM_ARRSTR. Defines Harbour internal constants and macros

[Assistant]
#ifndef HB_MACRO_CH_
#define HB_MACRO_CH_

#define HB_SM_HARBOUR    1
#define HB_SM_XBASE      2
#define HB_SM_SHORTCUTS  8
#define HB_SM_ARRSTR     16
#define HB_SM_EXTOPT     32
#define HB_SM_RT_MACRO   64
#define HB_SM_PARSER     128

#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:

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

[Assistant]
#pragma -b-

#define HB_CLS_NOTOBJECT
#include "hbclass.ch"

CREATE CLASS HBDbMenuItem

   VAR nRow
   VAR nCol
   VAR cPrompt
   VAR bAction
   VAR lChecked
   VAR Ident

   ACCESS Checked()           INLINE ::lChecked
   ASSIGN Checked( lChecked ) INLINE ::lChecked := lChecked

   METHOD New( cPrompt, bAction, lChecked, xIdent )
   METHOD Display( cClrText, cClrHotKey )
   METHOD Toggle() INLINE ::lChecked := ! ::lChecked

ENDCLASS

METHOD New( cPrompt, bAction, lChecked, xIdent ) CLASS HBDbMenuItem

   ::cPrompt  := cPrompt
   ::bAction  := bAction
   ::lChecked := hb_defaultValue( lChecked, .F. )
   ::Ident    := xIdent

   RETURN Self

METHOD Display( cClrText, cClrHotKey ) CLASS HBDbMenuItem

   LOCAL nAt

   hb_DispOutAt( ::nRow, ::nCol, StrTran( ::cPrompt, "~" ), cClrText )

   hb_DispOutAt( ::nRow, ::nCol + ;
      ( nAt := At( "~", ::cPrompt ) ) - 1, ;
      SubStr( ::cPrompt, nAt + 1, 1 ), cClrHotKey )

   IF ::lChecked
      hb_DispOutAtBox( ::nRow, ::nCol, hb_UTF8ToStrBox( "√" ), cClrText )
   ENDIF

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

Harbour test program: tests/persist.prg. Defines classes: Test, Test2. Contains procedures: Main. This test file tests specific function APIs

[Assistant]
#include "hbclass.ch"

PROCEDURE Main()

   LOCAL oTest := Test():New()
   LOCAL oTest2 := Test2():New()

   oTest:One   := "hello"
   oTest:Two   := 123
   oTest:Three := "this value is not persistent"
   oTest:Four  := oTest2

   oTest2:Five := "some more text"

   ? oTest:SaveToText()

   oTest:SaveToFile( "test.txt" )

   RETURN

CREATE CLASS Test FROM HBPersistent

   VAR    One       PROPERTY
   VAR    Two       PROPERTY
   VAR    Three
   VAR    Four      PROPERTY

   METHOD Another() INLINE { 1, { "One", "Two" }, Date() } PROPERTY
   METHOD More()    VIRTUAL

ENDCLASS

CREATE CLASS Test2 FROM HBPersistent

   VAR Five  PROPERTY

ENDCLASS


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

[User] Generate Harbour code for: Harbour test program: tests/achoice2.prg. Provides functions: cUF, cUF2. Contains procedures: Main. This test file tests specific function APIs

[Assistant]
#include "inkey.ch"
#include "achoice.ch"

MEMVAR p_lHiLiTest

#ifndef __HARBOUR__
#include "clipper.ch"
#endif

PROCEDURE Main()

   LOCAL aMenu1 := { " --Wisky--", "", "not handled" }
   LOCAL aMenu2 := { " --Vodka--", " --Water--", NIL, "not handled" }
   LOCAL aMenu3 := { " --Grapa--", 33, "not handled" }

   LOCAL aMenu4 := { "", "not handled" }
   LOCAL aMenu5 := { " --Absnt--", "disabled1", "disabled2" }
   LOCAL aEnab5 := { .F., .F., .F. }

   LOCAL lExit := .F.
   LOCAL nCounter := 1
   LOCAL nKeyPressed

   PUBLIC p_lHiLiTest := .F.

   SetColor( "W+/N, BG+/B, , , W/N" )
   CLS
   @ 2,  1 SAY aMenu1[ 1 ]
   @ 2, 13 SAY aMenu2[ 1 ]
   @ 2, 25 SAY aMenu3[ 1 ]
   @ 2, 37 SAY aMenu4[ 1 ]
   @ 2, 49 SAY aMenu5[ 1 ]
   @ 3, 13 SAY aMenu2[ 2 ]
   DO WHILE ! lExit

      DO CASE
      CASE nCounter == 1
         AChoice( 2, 1, 3, 11, aMenu1 )
      CASE nCounter == 2
         AChoice( 2, 13, 3, 23, aMenu2, .T., "cUF" )
      CASE nCounter == 3
         AChoice( 2, 25, 3, 35, aMenu3, .T. )
      CASE nCounter == 4

         AChoice( 2, 37, 3, 47, aMenu4, .T., "cUF2" )
      CASE nCounter == 5
         AChoice( 2, 49, 4, 59, aMenu5, aEnab5, "cUF2" )
      ENDCASE

      nKeyPressed := LastKey()
      IF nKeyPressed == K_ESC
         lExit := .T.
      ELSEIF nKeyPressed == K_RIGHT
         nCounter := iif( nCounter == 5, 1, nCounter + 1 )
      ELSEIF nKeyPressed == K_LEFT
         nCounter := iif( nCounter == 1, 5, nCounter - 1 )
      ENDIF

   ENDDO

   RETURN

FUNCTION cUF( nMode, nCurElement, nRowPos )

   LOCAL nRetVal := AC_CONT
   LOCAL nKey := LastKey()

   HB_SYMBOL_UNUSED( nCurElement )
   HB_SYMBOL_UNUSED( nRowPos )

   IF p_lHiLiTest
      DispBox( 0, 0, MaxRow(), MaxCol(), Replicate( "#", 9 ), "GR+/G" )
   ENDIF

   IF nMode == AC_NOITEM
      nRetVal := AC_ABORT
   ELSEIF nMode == AC_EXCEPT
      DO CASE
      CASE nKey == K_ENTER
         nRetVal := AC_SELECT
      OTHERWISE
         nRetVal := AC_ABORT
      ENDCASE
   ENDIF

   RETURN nRetVal

FUNCTION cUF2( nMode, nCurElement, nRowPos )

   LOCAL nRetVal := AC_CONT
   LOCAL nKey := LastKey()

   HB_SYMBOL_UNUSED( nCurElement )
   HB_SYMBOL_UNUSED( nRowPos )

   DispBox( 0, 0, MaxRow(), MaxCol(), Replicate( "!", 9 ), "GR+/G" )

   IF nMode == AC_NOITEM
      nRetVal := AC_ABORT
   ELSEIF nMode == AC_EXCEPT
      DO CASE
      CASE nKey == K_ENTER
         nRetVal := AC_SELECT
      OTHERWISE
         nRetVal := AC_ABORT
      ENDCASE
   ENDIF

   RETURN nRetVal


[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 'gtwvg' (): contrib/gtwvg/crt.prg. Defines classes: WvgCrt. This file provides platform-specific functionality

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

#include "hbgtwvg.ch"
#include "wvtwin.ch"
#include "wvgparts.ch"

CREATE CLASS WvgCrt INHERIT WvgWindow, WvgPartHandler

   VAR    oMenu

   VAR    alwaysOnTop                           INIT .F.
   VAR    border                                INIT 0
   VAR    clipChildren                          INIT .F.
   VAR    closable                              INIT .T.
   VAR    fontHeight                            INIT 16
   VAR    fontWidth                             INIT 10
   VAR    fontName                              INIT "Courier New"
   VAR    gridMove                              INIT .F.
   VAR    icon                                  INIT 0
   VAR    minMax                                INIT .T.
   VAR    sysMenu                               INIT .T.
   VAR    taskList                              INIT .T.
   VAR    title                                 INIT " "
   VAR    titleBar                              INIT .T.
   VAR    visible                               INIT .T.

   VAR    autoFocus                             INIT .T.
   VAR    autoMark                              INIT .T.
   VAR    dropFont                              INIT .T.
   VAR    dropZone                              INIT .F.
   VAR    helpLink
   VAR    maxCol                                INIT 79
   VAR    maxRow                                INIT 24
   VAR    mouseMode                             INIT 1
   VAR    modalResult
   VAR    aSyncFlush                            INIT .F.
   VAR    tooltipText                           INIT ""
   VAR    useShortCuts                          INIT .F.
   VAR    xSize                                 INIT 640 READONLY
   VAR    ySize                                 INIT 400 READONLY

   VAR    animate                               INIT .F.
   VAR    clipParent                            INIT .F.
   VAR    clipSiblings                          INIT .T.
   VAR    group                                 INIT 0
   VAR    sizeRedraw                            INIT .F.
   VAR    tabStop                               INIT .F.

   VAR    sl_enter
   VAR    sl_leave
   VAR    sl_lbClick
   VAR    sl_lbDblClick
   VAR    sl_lbDown
   VAR    sl_lbUp
   VAR    sl_mbClick
   VAR    sl_mbDblClick
   VAR    sl_mbDown
   VAR    sl_mbUp
   VAR    sl_motion
   VAR    sl_rbClick
   VAR    sl_rbDblClick
   VAR    sl_rbDown
   VAR    sl_rbUp
   VAR    sl_wheel

   VAR    sl_close
   VAR    sl_helpRequest
   VAR    sl_keyboard
   VAR    sl_killDisplayFocus
   VAR    sl_killInputFocus
   VAR    sl_move
   VAR    sl_paint
   VAR    sl_quit
   VAR    sl_resize
   VAR    sl_setDisplayFocus
   VAR    sl_setInputFocus
   VAR    sl_dragEnter
   VAR    sl_dragMotion
   VAR    sl_dragLeave
   VAR    sl_dragDrop

   VAR    resizable                             INIT .T.
   VAR    resizeMode                            INIT HB_GTI_RESIZEMODE_FONT
   VAR    style                                 INIT ( WS_OVERLAPPED + WS_CAPTION + WS_SYSMENU + WS_SIZEBOX + WS_MINIMIZEBOX + WS_MAXIMIZEBOX )
   VAR    exStyle                               INIT 0
   VAR    lModal                                INIT .F.
   VAR    pGTp
   VAR    pGT
   VAR    objType                               INIT objTypeCrt
   VAR    ClassName                             INIT "WVGCRT"
   VAR    drawingArea
   VAR    hWnd
   VAR    aPos                                  INIT { 0, 0 }
   VAR    aSize                                 INIT { 24, 79 }
   VAR    aPresParams                           INIT {}
   VAR    lHasInputFocus                        INIT .F.
   VAR    nFrameState                           INIT 0

   VAR    isGT                                  INIT .F.

   METHOD setTitle( cTitle )                    INLINE ::title := cTitle, hb_gtInfo( HB_GTI_WINTITLE, cTitle )
   METHOD getTitle()                            INLINE hb_gtInfo( HB_GTI_WINTITLE )
   METHOD showWindow()                          INLINE ::show()
   METHOD refresh()                             INLINE ::invalidateRect()
   METHOD refreshEx()

   METHOD new( oParent, oOwner, aPos, aSize, aPresParams, lVisible )
   METHOD create( oParent, oOwner, aPos, aSize, aPresParams, lVisible )
   METHOD configure( oParent, oOwner, aPos, aSize, aPresParams, lVisible )
   METHOD destroy()

   METHOD currentPos()
   METHOD currentSize()
   METHOD captureMouse()
   METHOD disable()
   METHOD enable()
   METHOD getFrameState()
   METHOD getHWND()
   METHOD getModalState()
   METHOD hasInputFocus()
   METHOD hide()
   METHOD invalidateRect( nTop, nLeft, nBottom, nRight )
   METHOD isEnabled()
   METHOD isVisible()
   METHOD lockPS()
   METHOD lockUpdate()
   METHOD menuBar()
   METHOD setColorBG()
   METHOD setColorFG()
   METHOD setFont()
   METHOD setFontCompoundName()
   METHOD setFrameState( nState )
   METHOD setPresParam()
   METHOD setModalState()
   METHOD setPointer()
   METHOD setTrackPointer()
   METHOD setPos()
   METHOD setPosAndSize()
   METHOD setSize( aSize, lPaint )
   METHOD showModal()
   METHOD show()
   METHOD toBack()
   METHOD toFront()
   METHOD unlockPS()
   METHOD winDevice()

   METHOD enter( xParam )                       SETGET
   METHOD leave( xParam )                       SETGET
   METHOD lbClick( xParam )                     SETGET
   METHOD lbDblClick( xParam )                  SETGET
   METHOD lbDown( xParam )                      SETGET
   METHOD lbUp( xParam )                        SETGET
   METHOD mbClick( xParam )                     SETGET
   METHOD mbDblClick( xParam )                  SETGET
   METHOD mbDown( xParam )                      SETGET
   METHOD mbUp( xParam )                        SETGET
   METHOD motion( xParam )                      SETGET
   METHOD rbClick( xParam )                     SETGET
   METHOD rbDblClick( xParam )                  SETGET
   METHOD rbDown( xParam )                      SETGET
   METHOD rbUp( xParam )                        SETGET
   METHOD wheel( xParam )                       SETGET
   METHOD close( xParam )                       SETGET
   METHOD helpRequest( xParam )                 SETGET
   METHOD keyboard( xParam )                    SETGET
   METHOD killDisplayFocus( xParam )            SETGET
   METHOD killInputFocus( xParam )              SETGET
   METHOD move( xParam )                        SETGET
   METHOD paint( xParam )                       SETGET
   METHOD quit( xParam, xParam1 )               SETGET
   METHOD resize( xParam )                      SETGET
   METHOD setDisplayFocus( xParam )             SETGET
   METHOD setInputFocus( xParam )               SETGET
   METHOD dragEnter( xParam, xParam1 )          SETGET
   METHOD dragMotion( xParam )                  SETGET
   METHOD dragLeave( xParam )                   SETGET
   METHOD dragDrop( xParam, xParam1 )           SETGET

ENDCLASS

METHOD WvgCrt:new( oParent, oOwner, aPos, aSize, aPresParams, lVisible )

   ::WvgWindow:new( oParent, oOwner, aPos, aSize, aPresParams, lVisible )

   IF HB_ISARRAY( aPos )
      ::aPos := aPos
   ENDIF
   IF HB_ISARRAY( aSize )
      ::aSize := aSize
   ENDIF
   IF HB_ISARRAY( aPresParams )
      ::aPresParams := aPresParams
   ENDIF
   IF HB_ISLOGICAL( lVisible )
      ::visible := lVisible
   ENDIF

   ::drawingArea := Self

   RETURN Self

METHOD WvgCrt:create( oParent, oOwner, aPos, aSize, aPresParams, lVisible )

   LOCAL lRowCol := .T.

   __defaultNIL( @oParent    , ::oParent )
   __defaultNIL( @oOwner     , ::oOwner )
   __defaultNIL( @aPos       , ::aPos )
   __defaultNIL( @aSize      , ::aSize )
   __defaultNIL( @aPresParams, ::aPresParams )
   __defaultNIL( @lVisible   , ::visible )

   ::oParent     := oParent
   ::oOwner      := oOwner
   ::aPos        := aPos


[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/dbi.prg. Provides functions: xToStr. Contains procedures: Main. This file handles database operations

[Assistant]
#ifndef __HARBOUR__
   #xtranslate hb_eol() => ( Chr( 13 ) + Chr( 10 ) )
#endif

PROCEDURE Main()

   LOCAL i
   LOCAL cStr

   USE test NEW

   cStr := ""
   FOR i := 1 TO 100
      cStr += Str( i ) + " " + xToStr( dbInfo( i ) ) + hb_eol()
   NEXT
   cStr += Str(  101 ) + " " + xToStr( dbInfo(  101 ) ) + hb_eol()
   cStr += Str(  101 ) + " " + xToStr( dbInfo(  101, 1 ) ) + hb_eol()
   cStr += Str(  101 ) + " " + xToStr( dbInfo(  101, 2 ) ) + hb_eol()
   cStr += Str(  102 ) + " " + xToStr( dbInfo(  102 ) ) + hb_eol()
   cStr += Str(  101 ) + " " + xToStr( dbInfo(  102, 1 ) ) + hb_eol()
   cStr += Str(  101 ) + " " + xToStr( dbInfo(  102, 2 ) ) + hb_eol()
   cStr += Str(  999 ) + " " + xToStr( dbInfo(  999 ) ) + hb_eol()
   cStr += Str( 1000 ) + " " + xToStr( dbInfo( 1000 ) ) + hb_eol()

#ifdef __HARBOUR__
   MemoWrit( "dbi_hb.txt", cStr )
#else
   MemoWrit( "dbi_cl.txt", cStr )
#endif

   ? dbRecordInfo( 1 )
   ? dbRecordInfo( 2 )
   ? dbRecordInfo( 3 )
   ? dbRecordInfo( 4 )
   ? dbRecordInfo( 5 )

   ? dbFieldInfo( 1, 1 )
   ? dbFieldInfo( 2, 1 )
   ? dbFieldInfo( 3, 1 )
   ? dbFieldInfo( 4, 1 )

   RETURN

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]
Write the following Harbour (xBase/Clipper) code:

Harbour contribution module 'hbamf' (): contrib/hbamf/tests/test.prg. Contains procedures: Main. This file provides utility functions

[Assistant]
#require "hbamf"
#require "hbtest"

REQUEST HB_CODEPAGE_UTF8EX

PROCEDURE Main()

   hb_cdpSelect( "UTF8EX" )

   HBTEST amf3_Encode( {}                                             ) IS e"\011\001\001"
   HBTEST amf3_Encode( "a"                                            ) IS e"\006\003a"
   HBTEST amf3_Encode( "ą"                                            ) IS e"\006\005\304\205"
   HBTEST amf3_Encode( 1                                              ) IS e"\004\001"
   HBTEST amf3_Encode( 1000                                           ) IS e"\004\207h"
   HBTEST amf3_Encode( 1000000                                        ) IS e"\004\275\204@"
   HBTEST amf3_Encode( 268435455                                      ) IS e"\004\277\377\377\377"
   HBTEST amf3_Encode( 268435456                                      ) IS e"\005A\260\0\0\0\0\0\0"
   HBTEST amf3_Encode( 268435456000                                   ) IS e"\005BO@\0\0\0\0\0"
   HBTEST amf3_Encode( -1                                             ) IS e"\004\377\377\377\377"
   HBTEST amf3_Encode( 9007199254740990                               ) IS e"\005C?\377\377\377\377\377\376"
   HBTEST amf3_Encode( amf3_Decode( amf3_Encode( 9007199254740990 ) ) ) IS e"\005C?\377\377\377\377\377\376"
   HBTEST amf3_Encode( 9007199254740991                               ) IS e"\005C?\377\377\377\377\377\377"
   HBTEST amf3_Encode( amf3_Decode( amf3_Encode( 9007199254740991 ) ) ) IS e"\005C?\377\377\377\377\377\377"
   HBTEST amf3_Encode( 9007199254740991.00                            ) IS e"\005C?\377\377\377\377\377\377"
   HBTEST amf3_Encode( 6969.69                                        ) IS e"\005@\2739\260\243\327\012="
   HBTEST amf3_Encode( NIL                                            ) IS e"\001"
   HBTEST amf3_Encode( .T.                                            ) IS e"\003"
   HBTEST amf3_Encode( .F.                                            ) IS e"\002"
   HBTEST amf3_Encode( { 1, -1 }                                      ) IS e"\011\005\001\004\001\004\377\377\377\377"
   HBTEST amf3_Encode( { "ONE" => 0xCAFE, "TWO" => 0xBABE }           ) IS e"\011\001\007ONE\004\203\225~\007TWO\004\202\365>\001"

   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: Initialise, StaticText, WindowBounce. Harbour test program: tests/video.prg. Provides functions: Initialise, StaticText, WindowBounce, ColourBoxes, Summary. Contains procedures: Main. This test file tests specific function APIs

[Assistant]
#include "box.ch"
#ifdef __HARBOUR__
   #include "hbgtinfo.ch"
#endif

#ifdef __CLIP__
   #xtranslate hb_SecondsCPU( [<x>] ) => SecondsCPU( [<x>] )
#endif
#ifdef FlagShip
   #xtranslate hb_SecondsCPU( [<x>] ) => SecondsCPU( [<x>] )
#endif
#ifdef __XHARBOUR__
   #xtranslate hb_SecondsCPU( [<x>] ) => SecondsCPU( [<x>] )
   #undef __HARBOUR__
#else
   #ifndef __HARBOUR__
      #xtranslate hb_SecondsCPU( [<x>] ) => Seconds( [<x>] )
   #endif
#endif

#ifndef __HARBOUR__
   #xtranslate hb_eol() => ( Chr( 13 ) + Chr( 10 ) )
#endif

#command ? => OutStd( hb_eol() ); OutErr( hb_eol() )
#command ? <xx,...> => OutStd( <xx>, hb_eol() ); OutErr( <xx>, hb_eol() )

#ifdef FlagShip

STATIC s_nDispCount := 0

#xtranslate DispBegin() => iif( ( ++s_nDispCount ) == 1, DispBegin( NIL ), )
#xtranslate DispEnd()   => iif( s_nDispCount > 0 .AND. ( --s_nDispCount ) == 0, DispEnd( NIL ), )

#endif

PROCEDURE Main( xUtf, xCompatBuf )

   LOCAL aResult := {}

#ifdef __HARBOUR__
   hb_cdpSelect( iif( !Empty( xUtf ), "UTF8", "EN" ) )
   hb_gtInfo( HB_GTI_BOXCP, hb_cdpSelect() )
   hb_gtInfo( HB_GTI_COMPATBUFFER, !Empty( xCompatBuf ) )
   ? "codepage:", hb_cdpSelect(), "box CP:", hb_gtInfo( HB_GTI_BOXCP ), ;
     "compat buffer:", hb_gtInfo( HB_GTI_COMPATBUFFER )
#endif

   Initialise()

   AAdd( aResult, StaticText()   )
   AAdd( aResult, WindowBounce() )
   AAdd( aResult, ColourBoxes()  )

   Summary( aResult )

   RETURN

STATIC FUNCTION Initialise()

   SET COLOUR TO "W+/BG"
#ifdef __HARBOUR__
   DispBox( 0, 0, MaxRow(), MaxCol(), Replicate( hb_UTF8ToStrBox( "░" ), 9 ), "BG/B" )
#else
   DispBox( 0, 0, MaxRow(), MaxCol(), Replicate( Chr( 176 ), 9 ), "BG/B" )
#endif

   RETURN NIL

STATIC FUNCTION StaticText()

   LOCAL cResult
   LOCAL r       := MaxRow() / 2
   LOCAL str     := Version()
   LOCAL c
   LOCAL i
   LOCAL nEnd
   LOCAL nStart  := hb_SecondsCPU()

   str := "Hello World - From " + Left( str, At( " ", str ) - 1 )
   c   := ( MaxCol() - Len( str ) ) / 2

   FOR i := 1 TO 5000
      @ r, c SAY str
   NEXT

   nEnd := hb_SecondsCPU()

   cResult := "StaticText:  Iterations=5000, Time=" + hb_ntos( nEnd - nStart ) + ;
      "secs,  Average FPS = " + hb_ntos( Round( 5000 / ( nEnd - nStart ), 0 ) ) + " FPS"

   RETURN cResult

STATIC FUNCTION WindowBounce()

   LOCAL cResult
   LOCAL nBoxes  := Min( MaxRow(), MaxCol() - 7 ) - 6
   LOCAL x       := Array( NBOXES )
   LOCAL y       := Array( NBOXES )
   LOCAL dx      := Array( NBOXES )
   LOCAL dy      := Array( NBOXES )
   LOCAL clr     := Array( NBOXES )
   LOCAL scr     := Array( NBOXES )
   LOCAL nFrames := 0
   LOCAL nStart
   LOCAL nEnd
   LOCAL i
   LOCAL aCol := { ;
      "N", "B", "G", "BG", "R", "RB", "GR", "W", ;
      "N*", "B*", "G*", "BG*", "R*", "RB*", "GR*", "W*" }

   FOR i := 1 TO nBoxes
      x[ i ]   := i
      y[ i ]   := i - 1
      dx[ i ]  := -1
      dy[ i ]  := 1
      clr[ i ] := "W+/" + aCol[ ( i - 1 ) % 16 + 1 ]
   NEXT

   nStart := hb_SecondsCPU()
   DispBegin()

   DO WHILE nFrames < 5000

      FOR i := 1 TO nBoxes
         scr[ i ] := SaveScreen( x[ i ], y[ i ], x[ i ] + 6, y[ i ] + 12 )
#ifdef HB_B_SINGLE_UNI
         @ x[ i ], y[ i ], x[ i ] + 6, y[ i ] + 12 BOX HB_B_SINGLE_UNI + " " COLOR clr[ i ]
#else
         @ x[ i ], y[ i ], x[ i ] + 6, y[ i ] + 12 BOX B_SINGLE + " " COLOR clr[ i ]
#endif
      NEXT

      DispEnd()
      DispBegin()

      FOR i := nBoxes TO 1 STEP -1

         RestScreen( x[ i ], y[ i ], x[ i ] + 6, y[ i ] + 12, scr[ i ] )

         x[ i ] += dx[ i ]
         y[ i ] += dy[ i ]
         IF x[ i ] <= 0 .OR. x[ i ] + 6 >= MaxRow()
            dx[ i ] := -dx[ i ]
         ENDIF
         IF y[ i ] <= 0 .OR. y[ i ] + 12 >= MaxCol()
            dy[ i ] := -dy[ i ]
         ENDIF
      NEXT

      ++nFrames
   ENDDO

   DispEnd()
   nEnd := hb_SecondsCPU()

   cResult := "WindowBounce:Iterations=" + hb_ntos( nFrames ) + ", Time=" + hb_ntos( nEnd - nStart ) + ;
      "secs,  Average FPS = " + hb_ntos( Round( nFrames / ( nEnd - nStart ), 0 ) ) + " FPS"

   RETURN cResult

STATIC FUNCTION ColourBoxes()

   LOCAL cResult
   LOCAL nFrames := 0
   LOCAL nStart
   LOCAL nEnd
   LOCAL i
   LOCAL nDir := 1
   LOCAL nDepth := 0
   LOCAL aCol := { ;
      "N", "B", "G", "BG", "R", "RB", "GR", "W", ;
      "N*", "B*", "G*", "BG*", "R*", "RB*", "GR*", "W*" }

   nStart := hb_SecondsCPU()

   DO WHILE nFrames < 5000
      IF nDir == 1
         DispBegin()
      ELSE
         DispEnd()
      ENDIF

      nDepth += nDir

      IF nDepth > 4 .OR. nDepth < 1
         nDir := -nDir
      ENDIF
      i := nFrames % 16 + 1
      DispBox( 5, 10, MaxRow() - 5, MaxCol() - 10, ;
         Replicate( Chr( i + 64 ), 9 ), ;
         "W+/" + aCol[ i ] )
      ++nFrames
   ENDDO

   DO WHILE nDepth > 0
      DispEnd()
      nDepth--
   ENDDO

   nEnd := hb_SecondsCPU()

   cResult := "ColourBoxes: Iterations=" + hb_ntos( nFrames ) + ", Time=" + hb_ntos( nEnd - nStart ) + ;
      "secs,  Average FPS = " + hb_ntos( Round( nFrames / ( nEnd - nStart ), 0 ) ) + " FPS"

   RETURN cResult

STATIC FUNCTION Summary( aResult )

   LOCAL i

   CLS
   ? "Resolution:  " + hb_ntos( MaxRow() + 1 ) + " x " + hb_ntos( MaxCol() + 1 ) + " " + Version()
   FOR i := 1 TO Len( aResult )
      ? aResult[ i ]
   NEXT
   ?
   ? "press any key to continue"
   Inkey( 0 )

   RETURN aResult


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

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

Harbour test program: tests/gtkeys.prg. Contains procedures: Main. This test file exercises basic Harbour language features

[Assistant]
#include "inkey.ch"
#ifdef __HARBOUR__
#include "hbgtinfo.ch"

REQUEST HB_CODEPAGE_PLMAZ
REQUEST HB_CODEPAGE_PLISO
REQUEST HB_CODEPAGE_PL852
REQUEST HB_CODEPAGE_PLWIN
REQUEST HB_CODEPAGE_UTF8EX
#else
#xtranslate hb_keyStd( <n> )  => ( <n> )
#xtranslate hb_keyCode( <n> ) => Asc( <n> )
#xtranslate hb_keyChar( <c> ) => iif( <c> >= 32 .AND. <c> <= 255 .AND. <c> != 127, Chr( <c> ), "" )
#xtranslate hb_ntos( <n> )    => LTrim( Str( <n> ) )
#endif
#ifndef HB_K_RESIZE
#define HB_K_RESIZE 1101
#endif

PROCEDURE Main( cTermCP, cHostCP, lBoxChar, lRawKey )

   LOCAL k, kX, i, s
   LOCAL aKeys := { ;
      { "K_UP",               5, "Up arrow, Ctrl-E"                }, ;
      { "K_DOWN",            24, "Down arrow, Ctrl-X"              }, ;
      { "K_LEFT",            19, "Left arrow, Ctrl-S"              }, ;
      { "K_RIGHT",            4, "Right arrow, Ctrl-D"             }, ;
      { "K_HOME",             1, "Home, Ctrl-A"                    }, ;
      { "K_END",              6, "End, Ctrl-F"                     }, ;
      { "K_PGUP",            18, "PgUp, Ctrl-R"                    }, ;
      { "K_PGDN",             3, "PgDn, Ctrl-C"                    }, ;
      { "K_CTRL_UP",        397, "Ctrl-Up arrow"                   }, ;
      { "K_CTRL_DOWN",      401, "Ctrl-Down arrow"                 }, ;
      { "K_CTRL_LEFT",       26, "Ctrl-Left arrow, Ctrl-Z"         }, ;
      { "K_CTRL_RIGHT",       2, "Ctrl-Right arrow, Ctrl-B"        }, ;
      { "K_CTRL_HOME",       29, "Ctrl-Home, Ctrl-]"               }, ;
      { "K_CTRL_END",        23, "Ctrl-End, Ctrl-W"                }, ;
      { "K_CTRL_PGUP",       31, "Ctrl-PgUp, Ctrl-Hyphen"          }, ;
      { "K_CTRL_PGDN",       30, "Ctrl-PgDn, Ctrl-^"               }, ;
      { "K_ALT_UP",         408, "Alt-Up arrow"                    }, ;
      { "K_ALT_DOWN",       416, "Alt-Down arrow"                  }, ;
      { "K_ALT_LEFT",       411, "Alt-Left arrow"                  }, ;
      { "K_ALT_RIGHT",      413, "Alt-Right arrow"                 }, ;
      { "K_ALT_HOME",       407, "Alt-Home"                        }, ;
      { "K_ALT_END",        415, "Alt-End"                         }, ;
      { "K_ALT_PGUP",       409, "Alt-PgUp"                        }, ;
      { "K_ALT_PGDN",       417, "Alt-PgDn"                        }, ;
      { "K_ENTER",           13, "Enter, Ctrl-M"                   }, ;
      { "K_RETURN",          13, "Return, Ctrl-M"                  }, ;
      { "K_SPACE",           32, "Space bar"                       }, ;
      { "K_ESC",             27, "Esc, Ctrl-["                     }, ;
      { "K_CTRL_ENTER",      10, "Ctrl-Enter, Ctrl-J"              }, ;
      { "K_CTRL_RETURN",     10, "Ctrl-Return, Ctrl-J"             }, ;
      { "K_CTRL_RET",        10, "Ctrl-Return (Compat.)"           }, ;
      { "K_CTRL_PRTSCR",    379, "Ctrl-Print Screen, Alt-4"        }, ;
      { "K_ALT_COMMA",      307, "Alt-,"                           }, ;
      { "K_ALT_PERIOD",     308, "Alt-."                           }, ;
      { "K_CTRL_QUESTION",  309, "Ctrl-?, Alt-Slash"               }, ;
      { "K_ALT_SLASH",      309, "Alt-Slash"                       }, ;
      { "K_ALT_BACKSLASH",  299, "Alt-Backslash"                   }, ;
      { "K_ALT_ENTER",      284, "Alt-Enter"                       }, ;
      { "K_ALT_RETURN",     284, "Alt-Return"                      }, ;
      { "K_ALT_MINUS",      386, "Alt-Minus"                       }, ;
      { "K_ALT_EQUALS",     387, "Alt-Equals"                      }, ;
      { "K_ALT_ESC",        257, "Alt-Esc"                         }, ;
      { "K_ALT_BACKQUOTE",  297, "Alt-backquote"                   }, ;
      { "K_ALT_OSB",        282, "Alt-["                           }, ;
      { "K_ALT_CSB",        283, "Alt-]"                           }, ;
      { "K_ALT_SC",         295, "Alt-;"                           }, ;
      { "K_ALT_QUOTE",      296, "Alt-'"                           }, ;
      { "KP_CENTER",        332, "Keypad CENTER (5)"               }, ;
      { "KP_ALT_ENTER",     422, "Keypad Alt-Enter"                }, ;
      { "KP_CTRL_5",        399, "Keypad Ctrl-5"                   }, ;
      { "KP_CTRL_SLASH",    405, "Keypad Ctrl-/"                   }, ;
      { "KP_CTRL_ASTERISK", 406, "Keypad Ctrl-*"                   }, ;
      { "KP_CTRL_MINUS",    398, "Keypad Ctrl--"                   }, ;
      { "KP_CTRL_PLUS",     400, "Keypad Ctrl-+"                   }, ;
      { "KP_ALT_5",           5, "Keypad Alt-5"                    }, ;
      { "KP_ALT_SLASH",     420, "Keypad Alt-/"                    }, ;
      { "KP_ALT_ASTERISK",  311, "Keypad Alt-*"                    }, ;
      { "KP_ALT_MINUS",     330, "Keypad Alt--"                    }, ;
      { "KP_ALT_PLUS",      334, "Keypad Alt-+"                    }, ;
      { "K_INS",             22, "Ins, Ctrl-V"                     }, ;
      { "K_DEL",              7, "Del, Ctrl-G"                     }, ;
      { "K_BS",               8, "Backspace, Ctrl-H"               }, ;
      { "K_SH_BS",          423, "Shift-Backspace, Ctrl-Shift-Tab" }, ;
      { "K_CTRL_SH_TAB",    423, "Ctrl-Shift-Tab"                  }, ;
      { "K_TAB",              9, "Tab, Ctrl-I"                     }, ;
      { "K_SH_TAB",         271, "Shift-Tab"                       }, ;
      { "K_CTRL_INS",       402, "Ctrl-Ins"                        }, ;
      { "K_CTRL_DEL",       403, "Ctrl-Del"                        }, ;
      { "K_CTRL_BS",        127, "Ctrl-Backspace"                  }, ;
      { "K_CTRL_TAB",       404, "Ctrl-Tab"                        }, ;
      { "K_ALT_INS",        418, "Alt-Ins"                         }, ;
      { "K_ALT_DEL",        419, "Alt-Del"                         }, ;
      { "K_ALT_BS",         270, "Alt-Backspace"                   }, ;
      { "K_ALT_TAB",        421, "Alt-Tab"                         } }

   AAdd( aKeys, { "K_CTRL_A",           1, "Ctrl-A, Home"                    } )
   AAdd( aKeys, { "K_CTRL_B",           2, "Ctrl-B, Ctrl-Right arrow"        } )
   AAdd( aKeys, { "K_CTRL_C",           3, "Ctrl-C, PgDn, Ctrl-ScrollLock"   } )
   AAdd( aKeys, { "K_CTRL_D",           4, "Ctrl-D, Right arrow"             } )
   AAdd( aKeys, { "K_CTRL_E",           5, "Ctrl-E, Up arrow"                } )
   AAdd( aKeys, { "K_CTRL_F",           6, "Ctrl-F, End"                     } )
   AAdd( aKeys, { "K_CTRL_G",           7, "Ctrl-G, Del"                     } )
   AAdd( aKeys, { "K_CTRL_H",           8, "Ctrl-H, Backspace"               } )
   AAdd( aKeys, { "K_CTRL_I",           9, "Ctrl-I, Tab"                     } )
   AAdd( aKeys, { "K_CTRL_J",          10, "Ctrl-J"                          } )
   AAdd( aKeys, { "K_CTRL_K",          11, "Ctrl-K"                          } )
   AAdd( aKeys, { "K_CTRL_L",          12, "Ctrl-L"                          } )
   AAdd( aKeys, { "K_CTRL_M",          13, "Ctrl-M, Return"                  } )
   AAdd( aKeys, { "K_CTRL_N",          14, "Ctrl-N"                          } )
   AAdd( aKeys, { "K_CTRL_O",          15, "Ctrl-O"                          } )
   AAdd( aKeys, { "K_CTRL_P",          16, "Ctrl-P"                          } )
   AAdd( aKeys, { "K_CTRL_Q",          17, "Ctrl-Q"                          } )
   AAdd( aKeys, { "K_CTRL_R",          18, "Ctrl-R, PgUp"                    } )
   AAdd( aKeys, { "K_CTRL_S",          19, "Ctrl-S, Left arrow"              } )
   AAdd( aKeys, { "K_CTRL_T",          20, "Ctrl-T"                          } )
   AAdd( aKeys, { "K_CTRL_U",          21, "Ctrl-U"                          } )
   AAdd( aKeys, { "K_CTRL_V",          22, "Ctrl-V, Ins"                     } )
   AAdd( aKeys, { "K_CTRL_W",          23, "Ctrl-W, Ctrl-End"                } )
   AAdd( aKeys, { "K_CTRL_X",          24, "Ctrl-X, Down arrow"              } )
   AAdd( aKeys, { "K_CTRL_Y",          25, "Ctrl-Y"                          } )


[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/beforatn.prg. Contains procedures: Main. This file provides legacy compatibility functions

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

#include "ct.ch"

PROCEDURE Main()

   LOCAL cStr := "...This...is...a...test!"

   ctinit()

   ? "Begin test of BeforAtNum()"
   ?
   ? "  Value of cStr is: " + '"' + cStr + '"'
   ?

   ? "  Simple tests:"
   ? '  BeforAtNum( "..", cStr )       should be "...This...is...a.",'
   ? '                                    and is "' + BeforAtNum( "..", cStr ) + '"'
   ? '  BeforAtNum( "..", cStr, 2 )    should be "...This",'
   ? '                                    and is "' + BeforAtNum( "..", cStr, 2 ) + '"'
   ? '  BeforAtNum( "..", cStr, 2, 2 ) should be "...This...is",'
   ? '                                    and is "' + BeforAtNum( "..", cStr, 2, 2 ) + '"'
   ?

   ? "  Multi-Pass tests"
   ? "  Setting CSetAtMupa() to .T."
   CSetAtMupa( .T. )
   ? '  BeforAtNum( "..", cStr )       should be "...This...is...a.",'
   ? '                                    and is "' + BeforAtNum( "..", cStr ) + '"'
   ? '  BeforAtNum( "..", cStr, 2 )    should be ".",'
   ? '                                    and is "' + BeforAtNum( "..", cStr, 2 ) + '"'
   ? '  BeforAtNum( "..", cStr, 2, 2 ) should be "...This.",'
   ? '                                    and is "' + BeforAtNum( "..", cStr, 2, 2 ) + '"'
   ? "  Setting CSetAtMupa() to .F."
   CSetAtMupa( .F. )
   ?

   ? "  SetAtLike tests"
   ? '  Setting SetAtLike( CT_SETATLIKE_WILDCARD, "." )'
   SetAtLike( CT_SETATLIKE_WILDCARD, "." )
   ? '  BeforAtNum( "..", cStr )        should be "...This...is...a...tes",'
   ? '                                     and is "' + BeforAtNum( "..", cStr ) + '"'
   ? '  BeforAtNum( "..", cStr, 2, 2 )  should be "...T",'
   ? '                                     and is "' + BeforAtNum( "..", cStr, 2, 2 ) + '"'
   ? '  BeforAtNum( "..", cStr, 2, 10 ) should be "...This...is",'
   ? '                                     and is "' + BeforAtNum( "..", cStr, 2, 10 ) + '"'
   ?

   ? "End test of BeforAtNum()"
   ?

   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] Write a Harbour program with procedures: Main. Harbour contribution module 'hbgd' (Graphics drawing library (GD)): contrib/hbgd/tests/barcode.prg. Contains procedures: Main. This file provides graphics and image processing capabilities

[Assistant]
#require "hbgd"

#define IMAGES_OUT "imgs_out" + hb_ps()

PROCEDURE Main()

   LOCAL bar

   LOCAL black  := { 0, 0, 0 }
   LOCAL white  := { 255, 255, 255 }

   LOCAL ccode13    := "789136043666"
   LOCAL ccode8     := "0421000"

   LOCAL ccode128   := "Code 128"

   bar := GDBarCode():New( 13 )

   bar:Configure( 70, black, white, 2, 1 )

   bar:CreateBar( 205, 105, IMAGES_OUT + "bar13.jpg", white )

   bar:Draw13( ccode13 )

   bar:Finish( 2 )

   bar := GDBarCode():New( 8 )

   bar:Configure( 70, black, white, 2, 1 )

   bar:CreateBar( 154, 100, IMAGES_OUT + "bar8.gif", white )

   bar:Draw8( ccode8 )

   bar:Finish( 8 )

   bar:ResizeImage()

   bar := GDBarCode():New( 128 )

   bar:Configure( 50, black, white, 2, 1 )

   bar:CreateBar( 300, 400, IMAGES_OUT + "bar128.gif", white )

   bar:Draw128( cCode128, "B" )

   bar:Finish( 2 )

   bar := GDBarCode():New( 25 )

   bar:Configure( 25, black, white, 1, 1,, .T. )

   bar:CreateBar( 560, 60, IMAGES_OUT + "febraban.gif", white )
   bar:DrawI25( "104995628545723070285700000008218000" )
   bar:Finish( 8 )

   RETURN


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

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

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

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

PROCEDURE Main()

   LOCAL cStr := ".,.This.,.is.,.a.,.test!"

   ctinit()

   ? "Begin test of NumToken()"
   ?

   ? "  Simple tests:"
   ? '    NumToken( "Hello, World!" ) ==  2 ? --------------------------------> ' + Str( NumToken( "Hello, World!" ), 2 )
   ? '    NumToken( "This is good. See you! How do you do?", ".!?" ) == 3 ? --> ' + Str( NumToken( "This is good. See you! How do you do?", ".!?" ), 2 )
   ? '    NumToken( "one,,three,four,,six", ",", 1 ) ==  6 ? -----------------> ' + Str( NumToken( "one,,three,four,,six", ",", 1 ), 2 )
   ?

   ? '  # of tokens in the string "' + cStr + '"'
   ? '      separator list = ".,!" and skip width = 1: ' + Str( NumToken( cStr, ".,!", 1 ) )
   ? '                                 skip width = 3: ' + Str( NumToken( cStr, ".,!", 3 ) )
   ? '      separator list = ",!"  and skip width = 1: ' + Str( NumToken( cStr, ",!", 1 ) )
   ? '                                 skip width = 3: ' + Str( NumToken( cStr, ",!", 3 ) )
   ? '      separator list = "!"   and skip width = 1: ' + Str( NumToken( cStr, "!", 1 ) )
   ? '                                 skip width = 3: ' + Str( NumToken( cStr, "!", 3 ) )

   ?
   ? "End test of NumToken()"
   ?

   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 contribution module 'gtwvg' (): contrib/gtwvg/static.prg. Defines classes: WvgStatic. This file provides platform-specific functionality

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

#include "hbgtwvg.ch"
#include "wvtwin.ch"
#include "wvgparts.ch"

CREATE CLASS WvgStatic INHERIT WvgWindow

   VAR    autoSize                              INIT .F.
   VAR    caption                               INIT ""
   VAR    clipParent                            INIT .T.
   VAR    clipSiblings                          INIT .F.
   VAR    options                               INIT -1
   VAR    TYPE                                  INIT -1

   VAR    hBitmap

   METHOD new( oParent, oOwner, aPos, aSize, aPresParams, lVisible )
   METHOD create( oParent, oOwner, aPos, aSize, aPresParams, lVisible )
   METHOD configure( oParent, oOwner, aPos, aSize, aPresParams, lVisible )
   METHOD destroy()
   METHOD handleEvent( nMessage, aNM )

   METHOD setCaption( xCaption, cDll )

ENDCLASS

METHOD WvgStatic:new( oParent, oOwner, aPos, aSize, aPresParams, lVisible )

   ::wvgWindow:new( oParent, oOwner, aPos, aSize, aPresParams, lVisible )

   ::style       := WS_CHILD + WS_CLIPCHILDREN
   ::className   := "STATIC"
   ::objType     := objTypeStatic

   RETURN Self

METHOD WvgStatic:create( oParent, oOwner, aPos, aSize, aPresParams, lVisible )

   ::wvgWindow:create( oParent, oOwner, aPos, aSize, aPresParams, lVisible )

   SWITCH ::type
   CASE WVGSTATIC_TYPE_TEXT
      IF hb_bitAnd( ::options, WVGSTATIC_TEXT_LEFT ) == WVGSTATIC_TEXT_LEFT
         ::style += SS_LEFT
      ENDIF
      IF hb_bitAnd( ::options, WVGSTATIC_TEXT_RIGHT ) == WVGSTATIC_TEXT_RIGHT
         ::style += SS_RIGHT
      ENDIF
      IF hb_bitAnd( ::options, WVGSTATIC_TEXT_CENTER ) == WVGSTATIC_TEXT_CENTER
         ::style += SS_CENTER
      ENDIF
      IF hb_bitAnd( ::options, WVGSTATIC_TEXT_WORDBREAK ) == WVGSTATIC_TEXT_WORDBREAK
         ::style -= SS_LEFTNOWORDWRAP
      ENDIF
      EXIT

   CASE WVGSTATIC_TYPE_GROUPBOX
      EXIT
   CASE WVGSTATIC_TYPE_ICON
      ::style += SS_ICON
      EXIT
   CASE WVGSTATIC_TYPE_SYSICON
      EXIT
   CASE WVGSTATIC_TYPE_BITMAP
      ::style += SS_BITMAP
      DO CASE
      CASE ::options == WVGSTATIC_BITMAP_TILED
         ::style += SS_CENTERIMAGE
      CASE ::options == WVGSTATIC_BITMAP_SCALED

      OTHERWISE

      ENDCASE
      EXIT

   CASE WVGSTATIC_TYPE_FGNDRECT
      ::style += SS_WHITERECT
      EXIT
   CASE WVGSTATIC_TYPE_BGNDRECT
      ::style += SS_BLACKRECT
      EXIT
   CASE WVGSTATIC_TYPE_HALFTONERECT
      ::style += SS_GRAYRECT
      EXIT
   CASE WVGSTATIC_TYPE_FGNDFRAME
      ::style += SS_WHITEFRAME
      EXIT
   CASE WVGSTATIC_TYPE_BGNDFRAME
      ::style += SS_BLACKFRAME
      EXIT
   CASE WVGSTATIC_TYPE_HALFTONEFRAME
      ::style += SS_GRAYFRAME
      EXIT
   CASE WVGSTATIC_TYPE_RAISEDBOX
      ::style += SS_ETCHEDFRAME
      EXIT

   CASE WVGSTATIC_TYPE_RECESSEDBOX
      EXIT
   CASE WVGSTATIC_TYPE_RAISEDRECT
      EXIT
   CASE WVGSTATIC_TYPE_RECESSEDRECT
      EXIT
   CASE WVGSTATIC_TYPE_RAISEDLINE
      EXIT
   CASE WVGSTATIC_TYPE_RECESSEDLINE
      EXIT
   ENDSWITCH

#if 1

   IF AScan( { WVGSTATIC_TYPE_FGNDFRAME, WVGSTATIC_TYPE_BGNDFRAME, WVGSTATIC_TYPE_HALFTONEFRAME }, ::type ) > 0
      DO CASE
      CASE hb_bitAnd( ::options, WVGSTATIC_FRAMETHIN ) == WVGSTATIC_FRAMETHIN
         ::style += WS_BORDER
      CASE hb_bitAnd( ::options, WVGSTATIC_FRAMETHICK ) == WVGSTATIC_FRAMETHICK
         ::style += WS_DLGFRAME
      ENDCASE
   ENDIF
#endif

   ::oParent:addChild( Self )

   ::createControl()

   ::SetWindowProcCallback()

   IF ::visible
      ::show()
   ENDIF
   ::setPosAndSize()

   ::setCaption( ::caption )

   RETURN Self

METHOD WvgStatic:handleEvent( nMessage, aNM )

   DO CASE

   CASE nMessage == HB_GTE_RESIZED
      IF ::isParentCrt()
         ::rePosition()
      ENDIF
      IF HB_ISBLOCK( ::sl_resize )
         Eval( ::sl_resize, , , Self )
      ENDIF
      AEval( ::aChildren, {| o | o:handleEvent( HB_GTE_RESIZED, { 0, 0, 0, 0, 0 } ) } )
      RETURN EVENT_HANDELLED

   CASE nMessage == HB_GTE_CTLCOLOR
      IF HB_ISNUMERIC( ::clr_FG )
         wvg_SetTextColor( aNM[ 1 ], ::clr_FG )
      ENDIF
      IF HB_ISNUMERIC( ::hBrushBG )
         wvg_SetBkMode( aNM[ 1 ], 1 )
         RETURN ::hBrushBG
      ELSE
         RETURN wvg_GetCurrentBrush( aNM[ 1 ] )
      ENDIF

   CASE nMessage == HB_GTE_ANY
      IF ::isParentCrt()

      ENDIF

   ENDCASE

   RETURN EVENT_UNHANDELLED

METHOD PROCEDURE WvgStatic:destroy()

   IF ::hBitmap != NIL
      wvg_DeleteObject( ::hBitmap )
   ENDIF
   ::wvgWindow:destroy()

   RETURN

METHOD WvgStatic:configure( oParent, oOwner, aPos, aSize, aPresParams, lVisible )

   ::Initialize( oParent, oOwner, aPos, aSize, aPresParams, lVisible )

   RETURN Self

METHOD WvgStatic:setCaption( xCaption, cDll )

   HB_SYMBOL_UNUSED( cDll )

   __defaultNIL( @xCaption, ::caption )
   ::caption := xCaption

   DO CASE
   CASE ::type == WVGSTATIC_TYPE_TEXT
      wvg_SendMessageText( ::hWnd, WM_SETTEXT, 0, ::caption )

   CASE ::type == WVGSTATIC_TYPE_BITMAP
      IF ::hBitmap != nil
         wvg_DeleteObject( ::hBitmap )
      ENDIF

      ::hBitmap := wvg_LoadImage( ::caption, iif( HB_ISNUMERIC( ::caption ), 1, 2 ) )

      wvg_SendMessage( ::hWnd, STM_SETIMAGE, IMAGE_BITMAP, ::hBitmap )

   ENDCASE

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

Harbour contribution module 'gtwvg' (): contrib/gtwvg/genrc.prg. Provides functions: WvgSetAppWindow. Contains procedures: KillGTChildren. This file provides platform-specific functionality

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

#include "hbgtwvg.ch"
#include "wvtwin.ch"
#include "wvgparts.ch"

THREAD STATIC t_oCrt

EXIT PROCEDURE KillGTChildren()

   IF HB_ISOBJECT( t_oCrt ) .AND. __objGetClsName( t_oCrt ) == "WVGCRT" .AND. t_oCrt:isGT
      t_oCrt:destroy()
      t_oCrt := NIL
   ENDIF

   RETURN

FUNCTION WvgSetAppWindow( oCrt )

   LOCAL ooCrt := t_oCrt

   IF Empty( oCrt )
      IF Empty( t_oCrt )
         t_oCrt := WvgCrt():new()
         t_oCrt:hWnd := wvt_GetWindowHandle()
         t_oCrt:pWnd := win_N2P( t_oCrt:hWnd )
         hb_gtInfo( HB_GTI_NOTIFIERBLOCKGUI, {| nEvent, ... | t_oCrt:notifier( nEvent, ... ) } )
         t_oCrt:isGT := .T.
         RETURN t_oCrt
      ENDIF
   ELSE
      t_oCrt := oCrt
   ENDIF

   RETURN ooCrt


[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: Header file for contribution module 'xhb' (Extended Harbour functions): contrib/xhb/xhbinkey.ch. Defines 10 constants including: XHB_INKEY_CH_, XHB_K_CTRL_A, XHB_K_CTRL_B, XHB_K_CTRL_C, XHB_K_CTRL_D. Defines keyboard input constants

[Assistant]
#ifndef XHB_INKEY_CH_
#define XHB_INKEY_CH_

#define XHB_K_CTRL_A            513
#define XHB_K_CTRL_B            514
#define XHB_K_CTRL_C            515
#define XHB_K_CTRL_D            516
#define XHB_K_CTRL_E            517
#define XHB_K_CTRL_F            518
#define XHB_K_CTRL_G            519
#define XHB_K_CTRL_H            520
#define XHB_K_CTRL_I            521
#define XHB_K_CTRL_J            522
#define XHB_K_CTRL_K            523
#define XHB_K_CTRL_L            524
#define XHB_K_CTRL_M            525
#define XHB_K_CTRL_N            526
#define XHB_K_CTRL_O            527
#define XHB_K_CTRL_P            528
#define XHB_K_CTRL_Q            529
#define XHB_K_CTRL_R            530
#define XHB_K_CTRL_S            531
#define XHB_K_CTRL_T            532
#define XHB_K_CTRL_U            533
#define XHB_K_CTRL_V            534
#define XHB_K_CTRL_W            535
#define XHB_K_CTRL_X            536
#define XHB_K_CTRL_Y            537
#define XHB_K_CTRL_Z            538

#define XHB_K_SH_LEFT           424
#define XHB_K_SH_UP             425
#define XHB_K_SH_RIGHT          426
#define XHB_K_SH_DOWN           427

#define XHB_K_SH_INS            428
#define XHB_K_SH_DEL            429
#define XHB_K_SH_HOME           430
#define XHB_K_SH_END            431
#define XHB_K_SH_PGUP           432
#define XHB_K_SH_PGDN           433

#define XHB_K_SH_RETURN         434
#define XHB_K_SH_ENTER          434

#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: __SetFunction. Harbour Runtime Library file: src/rtl/setfunc.prg. Contains procedures: __SetFunction. This file provides utility functions

[Assistant]
#include "inkey.ch"

PROCEDURE __SetFunction( nFunctionKey, xKeySeq )

   DO CASE
   CASE nFunctionKey == 1  ; nFunctionKey := K_F1
#ifndef HB_CLP_STRICT
   CASE nFunctionKey == 11 ; nFunctionKey := K_F11
   CASE nFunctionKey == 12 ; nFunctionKey := K_F12
#endif
   OTHERWISE               ; nFunctionKey := -nFunctionKey + 1
   ENDCASE

   IF HB_ISSTRING( xKeySeq )
      SetKey( nFunctionKey, {|| __Keyboard(), hb_keyPut( xKeySeq ) } )
   ELSE
      SetKey( nFunctionKey, NIL )
   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 the following Harbour (xBase/Clipper) code:

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

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

#define FLX_EXCLUSIVE 0x0000
#define FLX_SHARED    0x0100
#define FLX_NO_WAIT   0x0000
#define FLX_WAIT      0x0200

#define hb_keyCode( x ) Asc( x )

STATIC s_lLocked
STATIC s_lExclusive
STATIC s_lBlocking

PROCEDURE Main()

   LOCAL hLockFile
   LOCAL lSuccess
   LOCAL nExclusivity
   LOCAL nBlocking
   LOCAL nKeyHit
   LOCAL nLockType

   CLS

   IF ! hb_FileExists( "emphasis.6lo" )
      hb_MemoWrit( "emphasis.6lo", "" )
   ENDIF

   ? "Opening lock file"
   IF ( hLockFile := FOpen( "emphasis.6lo", FO_READWRITE ) ) == F_ERROR
      ? "ERROR: Cannot open Lock File"
      RETURN
   ENDIF
   ? "Lock file opened - handle is", hb_ntos( hLockFile )
   ?
   s_lLocked      := .F.
   s_lExclusive   := .T.
   s_lBlocking    := .F.
   nExclusivity := FLX_EXCLUSIVE
   nBlocking    := FLX_NO_WAIT
   ShowStatus()
   ? "[+] to get a lock, [-] to release it, [Esc] to exit, [E] for exclusive, [S] for shared, [B] for blocking, [N] for non-blocking"
   DO WHILE .T.
      nKeyHit := Inkey( 0 )
      SWITCH nKeyHit
      CASE hb_keyCode( "+" )
         IF s_lLocked
            ? "Already locked"
         ELSE
            nLockType := nExclusivity + nBlocking
            ? "Requesting Lock"
            lSuccess := hb_FLock( hLockFile, 0, 1, nLockType  )
            IF lSuccess
               ? "Lock has been obtained"
               s_lLocked := .T.
            ELSE
               ? "Lock Request Failed - Error Code:", FError()
            ENDIF
         ENDIF
         EXIT
      CASE hb_keyCode( "-" )
         IF ! s_lLocked
            ? "Lock not currently held"
         ELSE
            lSuccess := hb_FUnlock( hLockFile, 0, 1 )
            IF lSuccess
               ? "Lock has been released"
               s_lLocked := .F.
            ELSE
               ? "Unlock Request Failed - Error Code:", FError()
            ENDIF
         ENDIF
         EXIT
      CASE hb_keyCode( "E" )
      CASE hb_keyCode( "e" )
         IF s_lLocked
            ? "Release Lock before changing lock type"
         ELSE
            s_lExclusive := .T.
            nExclusivity := FLX_EXCLUSIVE
            ShowStatus()
         ENDIF
         EXIT
      CASE hb_keyCode( "S" )
      CASE hb_keyCode( "s" )
         IF s_lLocked
            ? "Release Lock before changing lock type"
         ELSE
            s_lExclusive := .F.
            nExclusivity := FLX_SHARED
            ShowStatus()
         ENDIF
         EXIT
      CASE hb_keyCode( "B" )
      CASE hb_keyCode( "b" )
         IF s_lLocked
            ? "Release Lock before changing function mode"
         ELSE
            s_lBlocking := .T.
            nExclusivity := FLX_WAIT
            ShowStatus()
         ENDIF
         EXIT
      CASE hb_keyCode( "N" )
      CASE hb_keyCode( "n" )
         IF s_lLocked
            ? "Release Lock before changing function mode"
         ELSE
            s_lBlocking := .F.
            nExclusivity := FLX_NO_WAIT
            ShowStatus()
         ENDIF
         EXIT
      CASE K_ESC
         ?
         FClose( hLockFile )
         ? "Exiting"
         RETURN
      OTHERWISE
         ? "Key not supported", nKeyHit
      ENDSWITCH
   ENDDO

   RETURN

PROCEDURE ShowStatus()

   ? "Lock: " + iif( s_lLocked, "Held", "Released" ) +;
     "    Type: " + iif( s_lExclusive, "Exclusive", "Shared" ) +;
     "  Request is: " + iif( s_lBlocking, "Blocking", "Non-Blocking" )

   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 preprocessor definitions: Harbour extra library: extras/httpsrv/modules/showcounter.prg. Provides functions: HRBMAIN, CreateCounter. This file implements server functionality

[Assistant]
#if defined( HBMK_HAS_HBGD )

MEMVAR _SERVER
MEMVAR _REQUEST

#define IMAGES_IN  ".." + hb_ps() + ".." + hb_ps() + ".." + hb_ps() + "contrib" + hb_ps() + "hbgd" + hb_ps() + "tests" + hb_ps() + "digits" + hb_ps()
#define IMAGES_OUT ( _SERVER[ "DOCUMENT_ROOT" ] + hb_ps() + "counter" + hb_ps() )

#define DISPLAY_NUM  10

FUNCTION HRBMAIN()

   LOCAL cHtml

   IF hb_HHasKey( _REQUEST, "w" )

      cHtml := CreateCounter( hb_ntos( Val( _REQUEST[ "w" ] ) ) )
      IF ! Empty( cHtml )
         uhttpd_SetHeader( "Content-Type", "image/gif" )
         uhttpd_SetHeader( "Pragma", "no-cache" )
         uhttpd_SetHeader( "Content-Disposition", "inline; filename=counter" + hb_ntos( hb_RandomInt( 100 ) ) + ".gif" )
         uhttpd_Write( cHtml )
      ELSE
         uhttpd_SetHeader( "Content-Type", "text/html" )
         uhttpd_Write( "
Error: No image created
" )
      ENDIF
   ELSE
      uhttpd_SetHeader( "Content-Type", "text/html" )
      uhttpd_Write( "
Error: no parameters passed
" )
   ENDIF

   RETURN .T.

STATIC FUNCTION CreateCounter( cValue, cBaseImage )

   LOCAL oI, oIDigits, nWidth, nHeight, nDigits, nNumWidth, oTemp

   LOCAL aNumberImages := {}
   LOCAL n, nValue

   hb_default( @cValue, Str( hb_RandomInt( 1, 10 ^ DISPLAY_NUM ), DISPLAY_NUM ) )
   hb_default( @cBaseImage, "57chevy.gif" )

   IF ! hb_FileExists( IMAGES_IN + cBaseImage )
      RETURN NIL
   ENDIF

   nValue := Val( cValue )

   IF nValue > 10 ^ DISPLAY_NUM
      nValue := 10 ^ DISPLAY_NUM
   ENDIF

   cValue := StrZero( nValue, DISPLAY_NUM )

   oIDigits := GDImage():LoadFromGif( IMAGES_IN + cBaseImage )

   nWidth  := oIDigits:Width()
   nHeight := oIDigits:Height()

   DO CASE
   CASE nWidth % 10 == 0
      nDigits := 10
   CASE nWidth % 11 == 0
      nDigits := 11
   CASE nWidth % 13 == 0
      nDigits := 13
   OTHERWISE
      uhttpd_Write( "Error on digits image" )
   ENDCASE
   nNumWidth := nWidth / nDigits

   FOR n := 1 TO nDigits
      oTemp := oIDigits:Copy( ( n - 1 )
   ? "Image dimensions: ", oI:Width(), oI:Height()

   white := oI:SetColor( 255, 255, 255 )

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

   oI:Rectangle( 0, 0, 200, 30,, blue )
#endif

   FOR n := 1 TO Len( cValue )

      oTemp := aNumberImages[ Val( SubStr( cValue, n, 1 ) ) + 1 ]:Clone()

      oI:SetTile( oTemp )

      oI:Rectangle( ( n - 1 )
   oI:SaveGif( IMAGES_OUT + "counter" + StrZero( hb_RandomInt( 1, 99 ), 2 ) + ".gif" )

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

   RETURN oI:ToStringGif()

#endif


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

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

Harbour contribution module 'hbwin' (Windows API wrapper functions): contrib/hbwin/tests/serial2.prg. Contains procedures: Main. This file provides platform-specific functionality

[Assistant]
#require "hbwin"

PROCEDURE Main( cPortName )

   LOCAL oWinPort
   LOCAL cString := Space( 32 )
   LOCAL lCTS, lDSR, lRing, lDCD
   LOCAL lCTSHold, lDSRHold, lDCDHold, lXoffHold, lXoffSent, nInQueue, nOutQueue
   LOCAL nResult

   IF Empty( cPortName )
      ? "Usage : winport portname"
      RETURN
   ENDIF

   ? "Attach a scanner now ..."
   ?
   Inkey( 0 )

   oWinPort := win_com():Init( cPortName, WIN_CBR_9600, WIN_ODDPARITY, 7, WIN_ONESTOPBIT )
   IF ! oWinPort:Open()
      ? "Open() failed"
   ELSE
      ? "Open() succeeded"
      ?
      IF oWinPort:Status( @lCTS, @lDSR, @lRing, @lDCD )
         ? "Status() succeeded : CTS ", lCTS, ", DSR ", lDSR, ", Ring ", lRing, ", DCD ", lDCD
      ELSE
         ? "Status() failed :", oWinPort:ErrorText()
      ENDIF
      ?
      ? "Testing DTR, configure a scanner to require DTR"
      ? "Scan something... and press enter (shouldn't scan)"
      Inkey( 0 )
      ? "Read() ", oWinPort:Read( @cString, 32 ), Len( cString ), cString
      ?
      IF oWinPort:SetDTR( .T. )
         ? "SetDTR( .T. ) succeeded"
      ELSE
         ? "SetDTR( .T. ) failed :", oWinPort:ErrorText()
      ENDIF
      ? "Scan something... and press enter (read should work)"
      Inkey( 0 )
      ?
      IF oWinPort:QueueStatus( @lCTSHold, @lDSRHold, @lDCDHold, @lXoffHold, @lXoffSent, @nInQueue, @nOutQueue )
         ? "QueueStatus() : CTSHold", lCtsHold, ", DSRHold", lDsrHold, ", DCDHold", lDCDHold, ", XoffHold", lXoffHold, ;
            ", Xoff Sent ", lXoffSent, ", InQueue ", nInQueue, ", nOutQueue ", nOutQueue
      ELSE
         ? "QueueStatus() failed :", oWinPort:ErrorText()
      ENDIF
      ?
      ? "Read() ", oWinPort:Read( @cString, 32 ), Len( cString ), cString
      ?
      IF oWinPort:QueueStatus( @lCTSHold, @lDSRHold, @lDCDHold, @lXoffHold, @lXoffSent, @nInQueue, @nOutQueue )
         ? "QueueStatus() : CTSHold", lCtsHold, ", DSRHold", lDsrHold, ", DCDHold", lDCDHold, ", XoffHold", lXoffHold, ;
            ", Xoff Sent ", lXoffSent, ", InQueue ", nInQueue, ", nOutQueue ", nOutQueue
      ELSE
         ? "QueueStatus() failed :", oWinPort:ErrorText()
      ENDIF
      ?
      IF oWinPort:RTSFlow( WIN_RTS_CONTROL_HANDSHAKE )
         ? "RTSFlow( WIN_RTS_CONTROL_HANDSHAKE ) succeeded"
      ELSE
         ? "RTSFlow( WIN_RTS_CONTROL_HANDSHAKE ) failed :", oWinPort:ErrorText()
      ENDIF
      ? oWinPort:DebugDCB( HB_WIN_COM_DBGFLOW )
      IF oWinPort:SetRTS( .F. )
         ? "SetRTS( .F. ) succeeded (it shouldn't according to docs!)"
      ELSE
         ? "SetRTS( .F. ) failed (it should) :", oWinPort:ErrorText()
      ENDIF
      ?
      IF oWinPort:RTSFlow( WIN_RTS_CONTROL_DISABLE )
         ? "RTSFlow( WIN_RTS_CONTROL_DISABLE ) succeeded"
      ELSE
         ? "RTSFlow( WIN_RTS_CONTROL_DISABLE ) failed :", oWinPort:ErrorText()
      ENDIF
      ? oWinPort:DebugDCB( HB_WIN_COM_DBGFLOW )
      IF oWinPort:SetRTS( .F. )
         ? "SetRTS( .F. ) succeeded (it should)"
      ELSE
         ? "SetRTS( .F. ) failed :", oWinPort:ErrorText()
      ENDIF
      ?
      ? "Scan something... we'll not read it but purge it, press enter"
      Inkey( 0 )
      IF oWinPort:QueueStatus( @lCTSHold, @lDSRHold, @lDCDHold, @lXoffHold, @lXoffSent, @nInQueue, @nOutQueue )
         ? "QueueStatus() : CTSHold", lCtsHold, ", DSRHold", lDsrHold, ", DCDHold", lDCDHold, ", XoffHold", lXoffHold, ;
            ", Xoff Sent ", lXoffSent, ", InQueue ", nInQueue, ", nOutQueue ", nOutQueue
      ELSE
         ? "QueueStatus() failed :", oWinPort:ErrorText()
      ENDIF
      IF oWinPort:Purge( .T., .T. )
         ? "Purge() succeeded"
      ELSE
         ? "Purge() failed :", oWinPort:ErrorText()
      ENDIF
      ? "InQueue should be zero"
      IF oWinPort:QueueStatus( @lCTSHold, @lDSRHold, @lDCDHold, @lXoffHold, @lXoffSent, @nInQueue, @nOutQueue )
         ? "QueueStatus() : CTSHold", lCtsHold, ", DSRHold", lDsrHold, ", DCDHold", lDCDHold, ", XoffHold", lXoffHold, ;
            ", Xoff Sent ", lXoffSent, ", InQueue ", nInQueue, ", nOutQueue ", nOutQueue
      ELSE
         ? "QueueStatus() failed :", oWinPort:ErrorText()
      ENDIF
      ?
      ? "Read ", oWinPort:Read( @cString, 32 ), Len( cString ), cString
      ?
      ? "Close", oWinPort:Close()
   ENDIF

   ?
   ? "This is going to fail, so no device needed"
   Inkey( 0 )

   oWinPort := win_com():Init( cPortName, WIN_CBR_9600, WIN_NOPARITY, 99, WIN_ONESTOPBIT )
   IF ! oWinPort:Open
      ? "Open() failed :", oWinPort:ErrorText()
   ELSE
      ? "Open succeeded"
      ? "Close", oWinPort:Close()
   ENDIF

   ? "Attach a printer now ..."
   ?
   Inkey( 0 )

   oWinPort := win_com():Init( cPortName, WIN_CBR_9600, WIN_NOPARITY, 8, WIN_ONESTOPBIT )
   IF ! oWinPort:Open
      ? "Open() failed :", oWinPort:ErrorText()
   ELSE
      ? "Open succeeded"
      ?
      ? oWinPort:DebugDCB( HB_WIN_COM_DBGFLOW )
      ? "Printers will probably have CTS, DSR and DCD high, IF they are off they'll all be low"
      IF oWinPort:Status( @lCTS, @lDSR, @lRing, @lDCD )
         ? "Status() succeeded : CTS ", lCTS, ", DSR ", lDSR, ", Ring ", lRing, ", DCD ", lDCD
      ELSE
         ? "Status() failed :", oWinPort:ErrorText()
      ENDIF
      ?

      ? "With no flow control the write should succeed whether printer is on or off"
      cString := "this is a test string " + Replicate( "012356789", 30 ) + Chr( 13 ) + Chr( 10 )
      IF ( nResult := oWinPort:Write( cString ) ) == Len( cString )
         ? "Write() succeeded"
      ELSE
         ? "Write() failed, returned ", nResult, " expected ", Len( cString )
      ENDIF
      IF oWinPort:QueueStatus( @lCTSHold, @lDSRHold, @lDCDHold, @lXoffHold, @lXoffSent, @nInQueue, @nOutQueue )
         ? "QueueStatus() : CTSHold", lCtsHold, ", DSRHold", lDsrHold, ", DCDHold", lDCDHold, ", XoffHold", lXoffHold, ;
            ", Xoff Sent ", lXoffSent, ", InQueue ", nInQueue, ", nOutQueue ", nOutQueue
      ELSE
         ? "QueueStatus() failed :", oWinPort:ErrorText()
      ENDIF

      ?
      ? "Switch all handshaking on (normally only hardware and RTS)"
      IF oWinPort:RTSFlow( WIN_DTR_CONTROL_HANDSHAKE )
         ? "RTSFlow( WIN_RTS_CONTROL_HANDSHAKE ) succeeded"
      ELSE
         ? "RTSFlow( WIN_RTS_CONTROL_HANDSHAKE ) failed :", oWinPort:ErrorText()
      ENDIF
      IF oWinPort:DTRFlow( WIN_DTR_CONTROL_HANDSHAKE )
         ? "DTRFlow( WIN_DTR_CONTROL_HANDSHAKE ) succeeded"
      ELSE
         ? "DTRFlow( WIN_DTR_CONTROL_HANDSHAKE ) failed :", oWinPort:ErrorText()
      ENDIF
      IF oWinPort:XonXoffFlow( .T. )
         ? "XonXoffFlow( .T. ) ", oWinPort:XonXoffFlow( .T. )
      ELSE
         ? "XonXoffFlow( .T. ) failed :", oWinPort:ErrorText()
      ENDIF
      ?
      ? oWinPort:DebugDCB( HB_WIN_COM_DBGFLOW )

      ? "If it's on then no Hold status should be on, IF off then probably CTS and DSR"
      IF oWinPort:QueueStatus( @lCTSHold, @lDSRHold, @lDCDHold, @lXoffHold, @lXoffSent, @nInQueue, @nOutQueue )
         ? "QueueStatus() : CTSHold", lCtsHold, ", DSRHold", lDsrHold, ", DCDHold", lDCDHold, ", XoffHold", lXoffHold, ;
            ", Xoff Sent ", lXoffSent, ", InQueue ", nInQueue, ", nOutQueue ", nOutQueue
      ELSE
         ? "QueueStatus() failed :", oWinPort:ErrorText()
      ENDIF
      ?
      ? Seconds()
      IF ( nResult := oWinPort:Write( cString ) ) == Len( cString )
         ? "Write() succeeded"
      ELSE
         ? "Write() failed, returned ", nResult, " expected ", Len( cString )
      ENDIF
      ? Seconds()
      ? "Close", oWinPort:Close()
   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] Define Harbour macros and constants: Harbour test program: tests/gtwin.prg. This test file exercises basic Harbour language features

[Assistant]
#include "box.ch"

#ifdef __PLATFORM__WINDOWS
   #if ! defined( __HBSCRIPT__HBSHELL )
      REQUEST HB_GT_WVT_DEFAULT
   #endif
   #define THREAD_GT "WVT"
#else
   REQUEST HB_GT_STD_DEFAULT
   #define THREAD_GT "XWC"
#endif

proc main()
   local pGT, pGT1, pGT2

#if defined( __HBSCRIPT__HBSHELL )
   #if defined( __PLATFORM__WINDOWS )
      hbshell_gtSelect( "GTWVT" )
   #elif defined( __PLATFORM__UNIX )
      hbshell_gtSelect( "GTXWC" )
   #endif
#endif

   ? "This is small test for using more then one console window."
   ? "It needs GT which supports such functionality i.e. GTWVT in"
   ? "MS-Windows or GTXWC in XWindow"
   wait

   ? "Create two new GTs:"
   pGT1 := hb_gtCreate( THREAD_GT )
   ? "1 =>", pGT1
   pGT2 := hb_gtCreate( THREAD_GT )
   ? "2 =>", pGT1

   pGT := hb_gtSelect( pGT1 )
   SetColor( "W+/R" )
   DispBox( 10, 10, 20, 50, HB_B_DOUBLE_UNI + " " )
   ?? "This test is shown in 1-st GT window"

   hb_gtSelect( pGT2 )
   SetColor( "W+/B" )
   DispBox( 15, 30, 20, 70, HB_B_DOUBLE_UNI + " " )
   ?? "This test is shown in 2-nd GT window"

   hb_gtSelect( pGT )
   ? "New console window should be visible now"
   wait

   ? "Destroy 1-st window..."
   pGT1 := NIL
   ?? "done"
   wait

   ? "Destroy 2-nd window..."
   pGT2 := NIL
   ?? "done"

   wait "Press any key to exit"

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: __eInstVar52. Harbour Runtime Library file: src/rtl/einstv52.prg. Provides functions: __eInstVar52. This file provides utility functions

[Assistant]
#include "error.ch"

FUNCTION __eInstVar52( oVar, cMethod, xValue, cType, nSubCode, xMin, xMax )

   LOCAL oError
   LOCAL lError

   IF ValType( xValue ) == cType
      lError := .F.
      IF xMin != NIL
         lError := ! xValue >= xMin
      ENDIF

      IF xMax != NIL
         lError := ! xValue <= xMax
      ENDIF
   ELSE
      lError := .T.
   ENDIF

   IF lError
      oError := ErrorNew()
      oError:description := hb_langErrMsg( EG_ARG )
      oError:gencode := EG_ARG
      oError:severity := ES_ERROR
      oError:cansubstitute := .T.
      oError:subsystem := oVar:className
#ifdef HB_CLP_STRICT
      HB_SYMBOL_UNUSED( cMethod )
#else
      oError:operation := cMethod
#endif
      oError:subcode := nSubCode
      oError:args := { xValue }
      xValue := Eval( ErrorBlock(), oError )
      IF ! ValType( xValue ) == cType
         __errInHandler()
      ENDIF
   ENDIF

   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]
Write the following Harbour (xBase/Clipper) code:

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

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

PROCEDURE Main()

   ctinit()

   ? "Begin test of RangeRem()"
   ?

   ? '  RangeRem( "0", "9", "year2002.dbf" ) == "year.dbf"     ? --> "' + ;
        RangeRem( "0", "9", "year2002.dbf" ) + '"'
   ? '  RangeRem( "9", "0", "year2002.dbf" ) == "22"           ? --> "' + ;
        RangeRem( "9", "0", "year2002.dbf" ) + '"'
   ? '  RangeRem( "0", "9", "yearcurr.dbf" ) == "yearcurr.dbf" ? --> "' + ;
        RangeRem( "0", "9", "yearcurr.dbf" ) + '"'

   ?
   ? "End test of RangeRem()"
   ?

   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:

Header file for contribution module 'xhb' (Extended Harbour functions): contrib/xhb/hblog.ch. Defines 8 constants including: HB_LOG_CH, HB_LOG_ALL, HB_LOG_ST_DATE, HB_LOG_ST_TIME, HB_LOG_ST_SECS. Declares 5 preprocessor commands. Declares 5 preprocessor translations. Defines Harbour internal constants and macros

[Assistant]
#ifndef HB_LOG_CH
#define HB_LOG_CH

#include "hblogdef.ch"

#define HB_LOG_ALL         9999

#define HB_LOG_ST_DATE     0x0001
#define HB_LOG_ST_TIME     0x0002
#define HB_LOG_ST_SECS     0x0004
#define HB_LOG_ST_LEVEL    0x0008
#define HB_LOG_ST_ISODATE  0x0010
#define HB_LOG_ST_NAME     0x0020

#xcommand INIT LOG [ON] ;
   [<fil: FILE> ([<nFilPrio> [,<cFileName>[,<nFileSize>[,<nFileCount>]]]])] ;
   [<con: CONSOLE> ([<nConPrio>])] ;
   [<mon: MONITOR> ([<nMonPrio>[,<nMonPort>]])] ;
   [<sys: SYSLOG> ([<nSysPrio>[,<nSysId>]])] ;
   [<ema: EMAIL> ([<nEmaPrio> [,<cHelo>[,<cServer>[,<cDest>[,<cSubject>[,<cFrom>]]]]]])] ;
   [<dbg: DEBUG> ( [<nDebugPrio> [,<nMaxDebugPrio>]] )] ;
   [NAME <cName>] => ;
   hb_InitStandardLog() ;;
   IF <.con.> ;;
      hb_StandardLogAdd( HB_LogConsole():New( <nConPrio> ));;
   END ;;
   IF <.fil.> ;;
      hb_StandardLogAdd( HB_LogFile():New( <nFilPrio>, <cFileName>, <nFileSize>, <nFileCount> ));;
   END ;;
   IF <.mon.> ;;
      hb_StandardLogAdd( HB_LogInetPort():New( <nMonPrio>, <nMonPort> ));;
   END ;;
   IF <.sys.> ;;
      hb_StandardLogAdd( HB_LogSysLog():New( <nSysPrio>, <nSysId> ));;
   END ;;
   IF <.ema.> ;;
      hb_StandardLogAdd( HB_LogEmail():New( <nEmaPrio> ,<cHelo>,<cServer>,<cDest>,<cSubject>,<cFrom>));;
   END ;;
   IF <.dbg.> ;;
      hb_StandardLogAdd( HB_LogDebug():New( <nDebugPrio>, <nMaxDebugPrio> ) ) ;;
   END ;;
   hb_StandardLogName( <cName> );;
   hb_OpenStandardLog()

#xcommand SET LOG STYLE <nStyle> => hb_SetStandardLogStyle( <nStyle> )

#xcommand LOG <data,...> [PRIORITY <prio>] => ;
      hb_StandardLog( hb_BldLogMsg( <data> ), <prio> )
#xcommand LOG <data,...> [PRIO <prio>] => ;
      hb_StandardLog( hb_BldLogMsg( <data> ), <prio> )

#xcommand CLOSE LOG =>  hb_CloseStandardLog()

#xtranslate PRIO[RITY] DEFAULT  => PRIO HB_LOG_DEFAULT
#xtranslate PRIO[RITY] CRITICAL => PRIO HB_LOG_CRITICAL
#xtranslate PRIO[RITY] ERROR => PRIO HB_LOG_ERROR
#xtranslate PRIO[RITY] WARNING => PRIO HB_LOG_WARNING
#xtranslate PRIO[RITY] WARN => PRIO HB_LOG_WARN
#xtranslate PRIO[RITY] INFO => PRIO HB_LOG_INFO
#xtranslate PRIO[RITY] DEBUG => PRIO HB_LOG_DEBUG

#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 test program: tests/delim.prg. Contains procedures: Main. This test file tests specific function APIs

[Assistant]
PROCEDURE Main()

   LOCAL nCount := 0

   USE test NEW

   COPY TO test1 DELIMITED

   COPY FIELD first, last, street, city, state, zip TO test2 DELIMITED FOR _field->salary > 50000

   COPY RECORD 3 TO test3 DELIMITED

   COPY NEXT 4 TO test4 DELIMITED

   GO BOTTOM
   SKIP -4
   COPY WHILE ncount++ < 9 TO test4a DELIMITED

   GO BOTTOM
   SKIP -9
   COPY REST TO test5 DELIMITED

   GO BOTTOM
   SKIP -9
   COPY TO test6 DELIMITED WHILE ! Eof()

   GO BOTTOM
   SKIP -9
   COPY REST TO test7 DELIMITED FOR _field->married

   DELETE FILE test8.txt
   APPEND FROM test8 DELIMITED

   RETURN


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

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

Harbour contribution module 'hbwin' (Windows API wrapper functions): contrib/hbwin/tests/service.prg. Contains procedures: Main, SrvMain, Main. This file provides platform-specific functionality

[Assistant]
#if ! defined( __HBSCRIPT__HBSHELL )

#define _SERVICE_NAME "Harbour_Test_Service"

PROCEDURE Main( cMode )

   LOCAL nError
   LOCAL cMsg

   hb_default( @cMode, "S" )

   SWITCH Upper( cMode )
   CASE "I"

      IF win_serviceInstall( _SERVICE_NAME, "Harbour Windows Test Service" )
         ? "Service has been successfully installed"
      ELSE
         nError := wapi_GetLastError()
         cMsg := Space( 128 )
         wapi_FormatMessage( ,,,, @cMsg )
         ? "Error installing service: " + hb_ntos( nError ) + " " + cMsg
      ENDIF
      EXIT

   CASE "U"

      IF win_serviceDelete( _SERVICE_NAME )
         ? "Service has been deleted"
      ELSE
         nError := wapi_GetLastError()
         cMsg := Space( 128 )
         wapi_FormatMessage( ,,,, @cMsg )
         ? "Error deleting service: " + hb_ntos( nError ) + " " + cMsg
      ENDIF
      EXIT

   CASE "S"

      IF win_serviceStart( _SERVICE_NAME, @SrvMain() )
         ? "Service has started OK"
      ELSE
         nError := wapi_GetLastError()
         cMsg := Space( 128 )
         wapi_FormatMessage( ,,,, @cMsg )
         ? "Service has had some problems: " + hb_ntos( nError ) + " " + cMsg
      ENDIF
      EXIT

   ENDSWITCH

   RETURN

#include "fileio.ch"

PROCEDURE SrvMain( cParam1, cParam2 )

   LOCAL n := 0
   LOCAL fhnd := hb_FCreate( hb_FNameExtSet( hb_ProgName(), ".out" ), FC_NORMAL, FO_DENYNONE + FO_WRITE )
   LOCAL cParam

   hb_default( @cParam1, "" )
   hb_default( @cParam2, "" )

   FWrite( fhnd, "Startup" + hb_eol() )
   FWrite( fhnd, "|" + hb_CmdLine() + "|" + hb_eol() )
   FWrite( fhnd, "|" + cParam1 + "|" + cParam2 + "|" + hb_eol() )

   FOR EACH cParam IN hb_AParams()
      FWrite( fhnd, "Parameter " + hb_ntos( cParam:__enumIndex() ) + " >" + cParam + "<" + hb_eol() )
   NEXT

   DO WHILE win_serviceGetStatus() == WIN_SERVICE_RUNNING
      FWrite( fhnd, "Work in progress " + hb_ntos( ++n ) + hb_eol() )
      hb_idleSleep( 0.5 )
   ENDDO

   FWrite( fhnd, "Exiting..." + hb_eol() )
   FClose( fhnd )

   win_serviceSetExitCode( 0 )
   win_serviceStop()

   RETURN

#else

PROCEDURE Main()

   ? "Cannot be used in script mode."

   RETURN

#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:

Harbour contribution module 'hbnf' (NanForum Toolkit - legacy Clipper compatibility functions): contrib/hbnf/tests/tempfile.prg. Contains procedures: Main. This file provides legacy compatibility functions

[Assistant]
#require "hbnf"

#include "fileio.ch"

PROCEDURE Main( cPath, cHide )

   LOCAL cFile, nHandle

   cFile := ft_TempFil( cPath, cHide == "Y" )

   IF ! Empty( cFile )
      ? cFile
      nHandle := FOpen( cFile, FO_WRITE )
      FWrite( nHandle, "This is a test!" )
      FClose( nHandle )
   ELSE
      ? "An error occurred"
   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] Create Harbour preprocessor definitions: Header file for contribution module 'hbmagic': contrib/hbmagic/hbmagic.ch. Defines 10 constants including: HBMAGIC_CH_, MAGIC_NONE, MAGIC_DEBUG, MAGIC_SYMLINK, MAGIC_COMPRESS. Defines keyboard input constants

[Assistant]
#ifndef HBMAGIC_CH_
#define HBMAGIC_CH_

#define MAGIC_NONE              0x000000
#define MAGIC_DEBUG             0x000001
#define MAGIC_SYMLINK           0x000002
#define MAGIC_COMPRESS          0x000004
#define MAGIC_DEVICES           0x000008
#define MAGIC_MIME_TYPE         0x000010
#define MAGIC_CONTINUE          0x000020
#define MAGIC_CHECK             0x000040
#define MAGIC_PRESERVE_ATIME    0x000080
#define MAGIC_RAW               0x000100
#define MAGIC_ERROR             0x000200
#define MAGIC_MIME_ENCODING     0x000400
#define MAGIC_MIME              hb_bitOr( MAGIC_MIME_TYPE, MAGIC_MIME_ENCODING )
#define MAGIC_APPLE             0x000800
#define MAGIC_NO_CHECK_COMPRESS 0x001000
#define MAGIC_NO_CHECK_TAR      0x002000
#define MAGIC_NO_CHECK_SOFT     0x004000
#define MAGIC_NO_CHECK_APPTYPE  0x008000
#define MAGIC_NO_CHECK_ELF      0x010000
#define MAGIC_NO_CHECK_TEXT     0x020000
#define MAGIC_NO_CHECK_CDF      0x040000
#define MAGIC_NO_CHECK_TOKENS   0x100000
#define MAGIC_NO_CHECK_ENCODING 0x200000

#define MAGIC_NO_CHECK_ASCII    MAGIC_NO_CHECK_TEXT

#define MAGIC_NO_CHECK_FORTRAN  0x000000
#define MAGIC_NO_CHECK_TROFF    0x000000

#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 'hbcomm' (Serial communication library): contrib/hbcomm/comm.prg. Provides 8 functions including: INIT_PORT, OUTBUFCLR, ISWORKING, INCHR, OUTCHR. This file provides utility functions

[Assistant]
#include "hbcom.ch"

STATIC s_hPort := { => }
STATIC s_hbcomm_mutex := hb_mutexCreate()

FUNCTION INIT_PORT( cPort, nBaud, nData, nParity, nStop, nBufferSize )

   LOCAL nPort
   LOCAL cOldPortName
   LOCAL cParity

   hb_mutexLock( s_hbcomm_mutex )

   nPort := Len( s_hPort ) + 1

   IF HB_ISSTRING( cPort )
      cOldPortName := hb_comGetDevice( nPort )
      hb_comSetDevice( nPort, cPort )
   ENDIF

   hb_comClose( nPort )

   IF hb_comOpen( nPort )

      hb_default( @nBaud, 9600 )

      cParity := "N"
      IF HB_ISNUMERIC( nParity )
         SWITCH nParity
         CASE 0 ; cParity := "N" ; EXIT
         CASE 1 ; cParity := "O" ; EXIT
         CASE 2 ; cParity := "M" ; EXIT
         CASE 3 ; cParity := "E" ; EXIT
         ENDSWITCH
      ENDIF

      hb_default( @nStop, 1 )

      HB_SYMBOL_UNUSED( nBufferSize )

      IF hb_comInit( nPort, nBaud, cParity, nData, nStop )
         s_hPort[ nPort ] := cOldPortName
         hb_mutexUnlock( s_hbcomm_mutex )
         RETURN nPort
      ELSE
         hb_comClose( nPort )
      ENDIF
   ENDIF

   IF cOldPortName != NIL
      hb_comSetDevice( nPort, cOldPortName )
   ENDIF

   hb_mutexUnlock( s_hbcomm_mutex )

   RETURN 0

FUNCTION OUTBUFCLR( nPort )
   RETURN hb_comFlush( nPort, HB_COM_OFLUSH )

FUNCTION ISWORKING( nPort )
   RETURN nPort $ s_hPort

FUNCTION INCHR( nPort, nCount,  cData )

   cData := iif( HB_ISNUMERIC( nCount ), Space( nCount ), "" )

   RETURN hb_comRecv( nPort, @cData, nCount )

FUNCTION OUTCHR( nPort, cData )

   LOCAL nLen

   DO WHILE hb_BLen( cData ) > 0

      nLen := hb_comSend( nPort, cData,, 1000 )

      IF nLen <= 0
         RETURN .F.
      ENDIF

      cData := hb_BSubStr( cData, nLen + 1 )
   ENDDO

   RETURN .T.

FUNCTION INBUFSIZE( nPort )
   RETURN hb_comInputCount( nPort )

FUNCTION OUTBUFSIZE( nPort )
   RETURN hb_comOutputCount( nPort )

FUNCTION UNINT_PORT( nPort )

   LOCAL lRetVal := .F.

   hb_mutexLock( s_hbcomm_mutex )

   IF nPort $ s_hPort
      IF hb_comClose( nPort )

         IF s_hPort[ nPort ] != NIL
            hb_comSetDevice( nPort, s_hPort[ nPort ] )
         ENDIF
         hb_HDel( s_hPort, nPort )
         lRetVal := .T.
      ENDIF
   ENDIF

   hb_mutexUnlock( s_hbcomm_mutex )

   RETURN lRetVal