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

[User] Create Harbour OOP classes for the functionality described: Harbour contribution module 'hbxpp' (xBase++ compatibility functions): contrib/hbxpp/tthreadx.prg. Defines classes: Signal, Thread. This file provides legacy compatibility functions

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

#include "thread.ch"

CREATE CLASS Signal

   VAR cargo      AS USUAL EXPORTED
   VAR mutex      AS USUAL PROTECTED

EXPORTED:

   METHOD new( ... )
   METHOD wait( nTimeOut )
   METHOD signal()

ENDCLASS

METHOD new( ... ) CLASS Signal

   ::mutex := hb_mutexCreate()
   ::Init( ... )

   RETURN Self

METHOD wait( nTimeOut ) CLASS SIGNAL
   RETURN __clsSyncWait( ::mutex, nTimeOut )

METHOD signal() CLASS Signal

   __clsSyncSignal( ::mutex )

   RETURN Self

CREATE CLASS Thread

EXPORTED:
   VAR active           AS LOGICAL READONLY  INIT .F.
   VAR atEnd            AS USUAL             INIT NIL
   VAR atStart          AS USUAL             INIT NIL
   VAR cargo            AS USUAL
   VAR deltaTime        AS NUMERIC READONLY  INIT 0
   VAR interval         AS USUAL   READONLY  INIT NIL
   VAR priority         AS NUMERIC READONLY  INIT 0
   VAR result           AS USUAL             INIT NIL
   VAR startCount       AS NUMERIC READONLY  INIT 0
   VAR startTime        AS USUAL   READONLY  INIT NIL
   VAR threadID         AS NUMERIC READONLY  INIT 0

PROTECTED:
   VAR maxStackSize     AS USUAL             INIT 50000

HIDDEN:
   VAR pThreadID        AS USUAL             INIT NIL

EXPORTED:
   METHOD new( ... )

PROTECTED:

   METHOD execute()

EXPORTED:
   METHOD quit( xResult, nRestart )
   METHOD setInterval( nHSeconds )
   METHOD setPriority( nPriority )
   METHOD setStartTime( nSeconds )
   METHOD start( xAction, ... )
   METHOD synchronize( nTimeOut )

   METHOD threadSelf()

ENDCLASS

METHOD new( ... ) CLASS Thread

   LOCAL nMaxStackSize

   IF PCount() == 1
      nMaxStackSize := hb_PValue( 1 )
      IF HB_ISNUMERIC( nMaxStackSize )
         ::maxStackSize := nMaxStackSize
      ENDIF

   ENDIF

   ::Init( ... )

   RETURN Self

METHOD PROCEDURE execute() CLASS Thread

   HB_SYMBOL_UNUSED( Self )

   RETURN

METHOD PROCEDURE quit( xResult, nRestart ) CLASS Thread

   IF hb_threadSelf() == ::pThreadID
      IF PCount() > 0
         ::result := xResult
      ENDIF
      IF ! HB_ISNUMERIC( nRestart ) .OR. nRestart != QUIT_RESTART
         ::interval := NIL
      ENDIF
      QUIT
   ENDIF

   RETURN

METHOD setInterval( nHSeconds ) CLASS Thread

   IF HB_ISNUMERIC( nHSeconds ) .AND. Int( nHSeconds ) >= 0
      ::interval := Int( nHSeconds )
   ELSEIF PCount() > 0 .OR. nHSeconds == NIL
      ::interval := NIL
   ELSE

      RETURN .F.
   ENDIF

   RETURN .T.

METHOD setPriority( nPriority ) CLASS Thread

   IF HB_ISNUMERIC( nPriority )
      ::priority := nPriority
   ENDIF

   RETURN .F.

METHOD setStartTime( nSeconds ) CLASS Thread

   IF HB_ISNUMERIC( nSeconds )
      IF nSeconds < 0 .OR. nSeconds > 86400
         RETURN .F.
      ENDIF
      ::startTime := nSeconds
   ELSEIF PCount() > 0 .OR. nSeconds == NIL
      ::startTime := NIL
   ELSE

      RETURN .F.
   ENDIF

   RETURN .T.

METHOD start( xAction, ... ) CLASS Thread

   IF ::active
      RETURN .F.
   ELSE
      ::pThreadID := hb_threadStart( HB_THREAD_INHERIT_PUBLIC, ;
            {| ... |
               LOCAL nTime

               ThreadObject( Self )

               ::active := .T.
               ::startCount++

               IF HB_ISNUMERIC( ::startTime )
                  nTime := ::startTime - Seconds()
                  IF nTime < 0
                     nTime += 86400
                  ENDIF
                  hb_idleSleep( nTime )
                  ::startTime := NIL
               ENDIF

               ::atStart( ... )
               IF HB_ISBLOCK( ::_atStart )
                  Eval( ::_atStart, ... )
               ENDIF

               DO WHILE .T.

                  nTime := hb_MilliSeconds()

                  BEGIN SEQUENCE
                     IF ! Empty( xAction ) .AND. ValType( xAction ) $ "CBS"
                        ::result := Do( xAction, ... )
                     ELSE
                        ::result := ::execute( ... )
                     ENDIF
                  ALWAYS
                     __QuitCancel()
                  END SEQUENCE

                  nTime := Int( ( hb_MilliSeconds() - nTime ) / 10 )
                  ::deltaTime := nTime

                  IF ! HB_ISNUMERIC( ::interval )
                     EXIT
                  ENDIF

                  nTime := ::interval - ::deltaTime
                  IF nTime > 0
                     hb_idleSleep( nTime / 100 )
                  ENDIF
                  ::startCount++

               ENDDO

               ::atEnd( ... )
               IF HB_ISBLOCK( ::_atEnd )
                  Eval( ::_atEnd, ... )
               ENDIF
               ::active := .F.

               RETURN NIL
            }, ... )

      ::threadID := iif( ::pThreadID == NIL, 0, hb_threadID( ::pThreadID ) )
   ENDIF

   RETURN .T.

METHOD synchronize( nTimeOut ) CLASS Thread

   LOCAL pThreadID := ::pThreadID

   IF hb_threadSelf() != pThreadID
      RETURN hb_threadWait( pThreadID, ;
         iif( HB_ISNUMERIC( nTimeOut ) .AND. nTimeOut != 0, ;
         nTimeOut / 100, ) )
   ENDIF

   RETURN .F.

METHOD threadSelf() CLASS Thread
   RETURN ::pThreadID


[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/usrrdd/exlog.prg. Provides functions: MyToString, hb_LogRddInherit. Contains procedures: Main. This test file tests specific function APIs

[Assistant]
#include "dbinfo.ch"
#include "hbusrrdd.ch"

REQUEST LOGRDD

REQUEST DBFCDX

PROCEDURE Main()

   rddSetDefault( "LOGRDD" )

   rddInfo( RDDI_MEMOVERSION, DB_MEMOVER_CLIP, "LOGRDD" )

   hb_LogRddLogFileName( "logs\changes.log" )

   hb_LogRddTag( NetName() + "\" + hb_UserName() )

   hb_LogRddActive( .T. )

   USE test
   field->name := "Francesco"
   CLOSE

   USE test VIA "DBFCDX"
   APPEND BLANK
   field->name := "Francesco"

   RETURN

STATIC FUNCTION MyToString( cCmd, nWA, xPar1, xPar2, xPar3 )

   LOCAL cString

   DO CASE
   CASE cCmd == "CREATE"

      cString := xPar1[ UR_OI_NAME ]
   CASE cCmd == "CREATEFIELDS"

      cString := hb_ValToExp( xPar1 )
   CASE cCmd == "OPEN"

   CASE cCmd == "CLOSE"

   CASE cCmd == "APPEND"

      cString := Alias() + "->RecNo() = " + hb_ntos( RecNo() )
   CASE cCmd == "DELETE"

      cString := Alias() + "->RecNo() = " + hb_ntos( RecNo() )
   CASE cCmd == "RECALL"

      cString := Alias() + "->RecNo() = " + hb_ntos( RecNo() )
   CASE cCmd == "PUTVALUE"

      HB_SYMBOL_UNUSED( xPar3 )
      cString := Alias() + "(" + hb_ntos( RecNo() ) + ")->" + PadR( FieldName( xPar1 ), 10 ) + " := " + hb_LogRddValueToText( xPar2 )
   CASE cCmd == "ZAP"

      cString := 'Alias : "' + Alias() + ' Table : "' + dbInfo( DBI_FULLPATH ) + '"'
   ENDCASE

   RETURN cString

FUNCTION hb_LogRddInherit()

   RETURN "DBFCDX"


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

[User] Write a Harbour program with procedures: Main. Harbour test program: tests/longdev.prg. Contains procedures: Main. This test file tests specific function APIs

[Assistant]
PROCEDURE Main()

   LOCAL cShort := "1234567890"
   LOCAL i, cLong, cBuffer, nHandle

   cLong := cShort
   FOR i := 1 TO 13
      cLong += cLong
   NEXT

   SET PRINTER TO longdev
   SET DEVICE TO PRINTER
   DevOut( cLong )
   SET PRINTER OFF
   SET DEVICE TO SCREEN

   ? "The length of the long string is", iif( Len( cLong ) == 80 * 1024, "correct", "wrong" )
   cBuffer := cLong
   ? "The length of a copy of the long string is", iif( Len( cLong ) == 80 * 1024, "correct", "wrong" )
   ? "The copy of the long string is", iif( cLong == cBuffer, "equal", "not equal" ), "to the long string"

   nHandle := FOpen( "longdev.prn" )
   cBuffer := FReadStr( nHandle, 90000 )
   ? "Original:", Len( cLong )
   ? "From file:", Len( cBuffer )
   ? "The strings are", iif( cLong == cBuffer, "equal", "not equal" )

   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 Runtime Library file: src/rtl/ttextlin.prg. Defines classes: HBTextLine. This file implements object-oriented classes using Harbour's class system

[Assistant]
#include "hbclass.ch"

CREATE CLASS HBTextLine

   VAR cText
   VAR lSoftCR

   METHOD Init( cLine, lSoftCR )

ENDCLASS

METHOD Init( cLine, lSoftCR ) CLASS HBTextLine

   ::cText := hb_defaultValue( cLine, "" )
   ::lSoftCR := hb_defaultValue( lSoftCR, .F. )

   RETURN Self


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

[User] Generate Harbour code for: Harbour contribution module 'hbct' (CA-Tools compatibility library): contrib/hbct/screen3.prg. Provides functions: ClearEol, ClEol, ClWin. This file provides legacy compatibility functions

[Assistant]
FUNCTION ClearEol( nRow, nCol, xAttr, xChar )

   IF ! HB_ISNUMERIC( nRow )
      nRow := Row()
   ENDIF

   RETURN ClearWin( nRow, nCol, nRow, , xAttr, xChar )

FUNCTION ClEol( nRow, nCol )

   IF ! HB_ISNUMERIC( nRow )
      nRow := Row()
   ENDIF

   RETURN ClearWin( nRow, nCol, nRow, , 7 , " " )

FUNCTION ClWin( nRow, nCol )
   RETURN ClearWin( nRow, nCol, , , 7 , " " )


[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 Runtime Library file: src/debug/debugger.prg. Defines classes: HBDebugger. Contains procedures: __dbgEntry. This file provides utility functions

[Assistant]
#pragma -b-

#define HB_CLS_NOTOBJECT
#include "hbclass.ch"

#include "hbdebug.ch"
#include "hbgtinfo.ch"
#include "hbmemvar.ch"

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

#define HB_DBG_VAR_MVALUE       HB_DBG_VAR_INDEX

#define WP_TYPE                 1
#define WP_EXPR                 2

#define DEBUGGER_MINROW         0
#define DEBUGGER_MINCOL         0
#define DEBUGGER_MAXROW         22
#define DEBUGGER_MAXCOL         77

#define DEBUGGER_CMDHIST_SIZE   128

THREAD STATIC t_oDebugger

PROCEDURE __dbgEntry( nMode, uParam1, uParam2, uParam3, uParam4 )

   LOCAL lStartup

   SWITCH nMode
   CASE HB_DBG_ACTIVATE

      IF ( lStartup := ( t_oDebugger == NIL ) )
         t_oDebugger := HBDebugger():New()
         t_oDebugger:pInfo := uParam1
      ENDIF
      t_oDebugger:nProcLevel := uParam2
      t_oDebugger:aCallStack := uParam3
      t_oDebugger:aModules := uParam4
      IF lStartup
         IF t_oDebugger:lRunAtStartup
            __dbgSetGo( uParam1 )
            RETURN
         ENDIF
      ENDIF
      t_oDebugger:lGo := .F.
      t_oDebugger:Activate()
      RETURN

   CASE HB_DBG_GETENTRY

      __dbgSetEntry()

   ENDSWITCH

   RETURN

CREATE CLASS HBDebugger

   VAR pInfo
   VAR aWindows          INIT {}
   VAR nCurrentWindow    INIT 1
   VAR oPullDown

   VAR oWndCode
   VAR oWndCommand
   VAR oWndStack
   VAR oWndVars

   VAR oBrwText
   VAR cPrgName
   VAR oBrwStack
   VAR oBrwVars
   VAR aVars             INIT {}

   VAR nAppDispCount

   VAR nAppDirCase
   VAR nAppFileCase
   VAR nAppTypeAhead
   VAR nAppLastKey

   VAR nMaxRow
   VAR nMaxCol

   VAR hUserWindow
   VAR hDebuggerWindow
   VAR lDebuggerWindowIsOpen INIT .F.

   VAR aCallStack        INIT {}
   VAR aProcStack        INIT {}
   VAR nProcLevel
   VAR aModules          INIT {}
   VAR aWatch            INIT {}
   VAR aColors           INIT { "W+/BG", "N/BG", "R/BG", "N+/BG", "W+/B", "GR+/B", "W/B", "N/W", "R/W", "N/BG", "R/BG" }

   VAR aHistCommands
   VAR aLastCommands
   VAR nCommand
   VAR oGetCommand

   VAR lAnimate          INIT .F.
   VAR lEnd              INIT .F.
   VAR lCaseSensitive    INIT .F.
   VAR lMonoDisplay      INIT .F.
   VAR lSortVars         INIT .F.

   VAR cSearchString     INIT ""
   VAR cPathForFiles
   VAR cSettingsFileName INIT "init.cld"
   VAR aPathDirs

   VAR nTabWidth         INIT 4
   VAR nSpeed            INIT 0

   VAR lShowPublics      INIT .F.
   VAR lShowPrivates     INIT .F.
   VAR lShowStatics      INIT .F.
   VAR lShowLocals       INIT .F.
   VAR lShowGlobals      INIT .F.
   VAR lShowAllGlobals   INIT .F.
   VAR lAll              INIT .F.
   VAR lShowCallStack    INIT .F.
   VAR lGo
   VAR lActive           INIT .F.
   VAR lCBTrace          INIT .T.
   VAR oBrwPnt
   VAR oWndPnt
   VAR lPPO              INIT .F.
   VAR lRunAtStartup     INIT .T.
   VAR lLineNumbers      INIT .T.
   VAR nHelpPage         INIT 1
   VAR nWaFocus          INIT 1
   VAR nCmdWndHight      INIT 3
   VAR lWindowsAutoSized INIT .T.

   METHOD New()
   METHOD Activate()

   METHOD All()

   METHOD Animate() INLINE iif( ::lAnimate, ::Step(), NIL )

   METHOD BarDisplay()
   METHOD BuildCommandWindow()
   METHOD BuildBrowseStack()
   METHOD ResizeCmdWnd( nLines )

   METHOD CallStackProcessKey( nKey )
   METHOD ClrModal() INLINE iif( ::lMonoDisplay, "N/W, W+/W, W/N, W+/N", ;
      "N/W, R/W, N/BG, R/BG" )
   METHOD GetColors() INLINE iif( ! ::lMonoDisplay, ::aColors, { ;
      "W+/N", "W+/N", "N/W", "N/W", ;
      "N/W", "N/W", "W+/N", "N/W", ;
      "W+/W", "W/N", "W+/N" } )
   METHOD CodeblockTrace()
   METHOD CodeWindowProcessKey( nKey )
   METHOD Colors()
   METHOD CommandWindowProcessKey( nKey )
   METHOD CommandWindowDisplay( cLine, lCmd )
   METHOD DoCommand( cCommand )
   METHOD DoScript( cFileName )
   METHOD EditColor( nColor, oBrwColors )
   METHOD EditSet( nSet, oBrwSets )
   METHOD EditVar( nVar )
   METHOD Exit() INLINE ::lEnd := .T.
   METHOD FindNext()
   METHOD FindPrevious()
   METHOD GetExprValue( xExpr, lValid )
   METHOD GetSourceFiles()
   METHOD ModuleMatch( cModuleName1, cModuleName2 )

   METHOD Global()

   METHOD Go()
   METHOD GoToLine( nLine )
   METHOD HandleEvent()
   METHOD Hide()
   METHOD HideCallStack()
   METHOD HideVars()
   METHOD InputBox( cMsg, uValue, bValid, lEditable )
   METHOD Inspect( uValue, cValueName )
   METHOD IsValidStopLine( cName, nLine )
   METHOD ListBox( cCaption, aItems )
   METHOD LoadColors()
   METHOD LoadSettings()
   METHOD LoadVars()
   METHOD LoadCallStack()

   METHOD Local()

   METHOD Locate( nMode, cValue )

   METHOD MonoDisplay()
   METHOD NextWindow()
   METHOD Open( cFileName )
   METHOD OpenMenu( cName )
   METHOD OpenPPO()
   METHOD Resume() INLINE ::ShowCodeLine( 1 )
   METHOD OSShell()
   METHOD PathForFiles( cPathForFiles )

   METHOD PrevWindow()
   METHOD Private()
   METHOD Public()
   METHOD Quit()
   METHOD RefreshVars()
   METHOD RestoreAppScreen()
   METHOD RestoreAppState()
   METHOD RestoreSettings( cFileName )
   METHOD RunAtStartup( lRunAtStartup )
   METHOD SaveAppScreen()
   METHOD SaveAppState()
   METHOD SaveSettings( cFileName )
   METHOD Show()
   METHOD ShowAllGlobals()
   METHOD ShowAppScreen()
   METHOD ShowCallStack()
   METHOD ShowCodeLine( nProc )
   METHOD ShowHelp( cTopic )
   METHOD ShowVars()
   METHOD LocatePrgPath( cPrgName )
   METHOD Sort() INLINE ASort( ::aVars,,, {| x, y | x[ HB_DBG_VAR_NAME ] < y[ HB_DBG_VAR_NAME ] } ), ;
      ::lSortVars := .T., ;
      iif( ::oBrwVars != NIL, ::oBrwVars:RefreshAll(), NIL ), ;
      iif( ::oWndVars != NIL .AND. ::oWndVars:lVisible, iif( ! ::lGo .AND. ::oBrwVars != NIL, ::oBrwVars:ForceStable(), NIL ), NIL )

   METHOD Speed() INLINE ::nSpeed := ::InputBox( "Step delay (in tenths of a second)", ::nSpeed )

   METHOD Stack( cParam )
   METHOD Static()

   METHOD Step()

   METHOD TabWidth() INLINE ;
      ::nTabWidth := ::InputBox( "Tab width", ::nTabWidth ), ;
      ::oBrwText:nTabWidth := ::nTabWidth, ::oBrwText:RefreshAll()

   METHOD BreakPointToggle( nLine, cFileName )
   METHOD BreakPointDelete( cPos )
   METHOD BreakPointFunc( cFuncName )
   METHOD BreakPointList()

   METHOD Trace()

   METHOD ToCursor()
   METHOD NextRoutine()
   METHOD ViewSets()
   METHOD WndVarsLButtonDown( nMRow, nMCol )
   METHOD LineNumbers( lLineNumbers )
   METHOD RemoveWindow( oWnd )
   METHOD SearchLine( cLine )
   METHOD ToggleAnimate() INLINE ::oPullDown:GetItemByIdent( "ANIMATE" ):checked := ::lAnimate := ! ::lAnimate
   METHOD ToggleCaseSensitive() INLINE ::oPullDown:GetItemByIdent( "CASE" ):checked := ::lCaseSensitive := ! ::lCaseSensitive
   METHOD ShowWorkAreas() INLINE __dbgShowWorkAreas( Self )

   METHOD TracepointAdd( cExpr )
   METHOD WatchpointAdd( cExpr )
   METHOD WatchpointDel( xPos )
   METHOD WatchpointsShow()
   METHOD WatchpointsHide()
   METHOD WatchpointEdit( nPos )
   METHOD WatchpointInspect( nPos )
   METHOD WatchGetInfo( nWatch )
   METHOD WatchpointList()

   METHOD VarGetInfo( aVar )
   METHOD VarGetValue( aVar )
   METHOD VarSetValue( aVar, uValue )

   METHOD ResizeWindows( oWindow )
   METHOD NotSupported() INLINE __dbgAlert( "Not implemented yet!" )

   METHOD OpenDebuggerWindow()
   METHOD CloseDebuggerWindow()

ENDCLASS

METHOD New() CLASS HBDebugger

   t_oDebugger := Self

   ::cPathForFiles := GetEnv( "HB_DBG_PATH" )
   IF Empty( ::cPathForFiles )
      ::cPathForFiles := GetEnv( "PATH" )
   ENDIF
   ::aPathDirs := PathToArray( ::cPathForFiles )

   ::lGo := ::lRunAtStartup

   ::nMaxRow := MaxRow()
   ::nMaxCol := MaxCol()

   ::oPullDown := __dbgBuildMenu( Self )

   ::oWndCode             := HBDbWindow():New( 1, 0, ;
                                               ::nMaxRow - ::nCmdWndHight - 3, ;
                                               ::nMaxCol )
   ::oWndCode:bKeyPressed := {| nKey | ::CodeWindowProcessKey( nKey ) }

   AAdd( ::aWindows, ::oWndCode )


[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 'sddodbc' (): contrib/sddodbc/tests/test1.prg. Contains procedures: Main. This file handles database operations

[Assistant]
#require "rddsql"
#require "sddodbc"

#include "simpleio.ch"

REQUEST SDDODBC, SQLMIX

PROCEDURE Main()

#if defined( __HBSCRIPT__HBSHELL )
   rddRegister( "SQLBASE" )
   rddRegister( "SQLMIX" )
   hb_SDDODBC_Register()
#endif

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

   rddSetDefault( "SQLMIX" )
   ? "Connect:", rddInfo( RDDI_CONNECT, { "ODBC", "DBQ=" + hb_DirBase() + "..\..\hbodbc\tests\test.mdb;Driver={Microsoft Access Driver (*.mdb)}" } )
   ? "Use:", dbUseArea( .T., , "select * from test", "test" )
   ? "Alias:", Alias()
   ? "DB struct:", hb_ValToExp( dbStruct() )
   Inkey( 0 )
   Browse()

   INDEX ON FIELD->SALARY TO salary
   dbGoTop()
   Browse()
   dbCloseArea()

   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:

Header file for contribution module 'hbcairo' (Cairo graphics library wrapper): contrib/hbcairo/hbcairo.ch. Defines 10 constants including: HB_CAIRO_CH_, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_SLANT_ITALIC, CAIRO_FONT_SLANT_OBLIQUE, CAIRO_FONT_WEIGHT_NORMAL. Defines Harbour internal constants and macros

[Assistant]
#ifndef HB_CAIRO_CH_
#define HB_CAIRO_CH_

#define CAIRO_FONT_SLANT_NORMAL              0
#define CAIRO_FONT_SLANT_ITALIC              1
#define CAIRO_FONT_SLANT_OBLIQUE             2

#define CAIRO_FONT_WEIGHT_NORMAL            0
#define CAIRO_FONT_WEIGHT_BOLD              1

#define CAIRO_PATH_MOVE_TO                  0
#define CAIRO_PATH_LINE_TO                  1
#define CAIRO_PATH_CURVE_TO                 2
#define CAIRO_PATH_CLOSE_PATH               3

#define CAIRO_LINE_CAP_BUTT                 0
#define CAIRO_LINE_CAP_ROUND                1
#define CAIRO_LINE_CAP_SQUARE               2

#define CAIRO_LINE_JOIN_MITER               0
#define CAIRO_LINE_JOIN_ROUND               1
#define CAIRO_LINE_JOIN_BEVEL               2

#define CAIRO_FORMAT_ARGB32                 0
#define CAIRO_FORMAT_RGB24                  1
#define CAIRO_FORMAT_A8                     2
#define CAIRO_FORMAT_A1                     3

#define CAIRO_FILL_RULE_WINDING             0
#define CAIRO_FILL_RULE_EVEN_ODD            1

#define CAIRO_OPERATOR_CLEAR                0
#define CAIRO_OPERATOR_SOURCE               1
#define CAIRO_OPERATOR_OVER                 2
#define CAIRO_OPERATOR_IN                   3
#define CAIRO_OPERATOR_OUT                  4
#define CAIRO_OPERATOR_ATOP                 5
#define CAIRO_OPERATOR_DEST                 6
#define CAIRO_OPERATOR_DEST_OVER            7
#define CAIRO_OPERATOR_DEST_IN              8
#define CAIRO_OPERATOR_DEST_OUT             9
#define CAIRO_OPERATOR_DEST_ATOP            10
#define CAIRO_OPERATOR_XOR                  11
#define CAIRO_OPERATOR_ADD                  12
#define CAIRO_OPERATOR_SATURATE             13

#define CAIRO_STATUS_SUCCESS                0
#define CAIRO_STATUS_NO_MEMORY              1
#define CAIRO_STATUS_INVALID_RESTORE        2
#define CAIRO_STATUS_INVALID_POP_GROUP      3
#define CAIRO_STATUS_NO_CURRENT_POINT       4
#define CAIRO_STATUS_INVALID_MATRIX         5
#define CAIRO_STATUS_INVALID_STATUS         6
#define CAIRO_STATUS_NULL_POINTER           7
#define CAIRO_STATUS_INVALID_STRING         8
#define CAIRO_STATUS_INVALID_PATH_DATA      9
#define CAIRO_STATUS_READ_ERROR             10
#define CAIRO_STATUS_WRITE_ERROR            11
#define CAIRO_STATUS_SURFACE_FINISHED       12
#define CAIRO_STATUS_SURFACE_TYPE_MISMATCH  13
#define CAIRO_STATUS_PATTERN_TYPE_MISMATCH  14
#define CAIRO_STATUS_INVALID_CONTENT        15
#define CAIRO_STATUS_INVALID_FORMAT         16
#define CAIRO_STATUS_INVALID_VISUAL         17
#define CAIRO_STATUS_FILE_NOT_FOUND         18
#define CAIRO_STATUS_INVALID_DASH           19
#define CAIRO_STATUS_INVALID_DSC_COMMENT    20
#define CAIRO_STATUS_INVALID_INDEX          21
#define CAIRO_STATUS_CLIP_NOT_REPRESENTABLE 22
#define CAIRO_STATUS_TEMP_FILE_ERROR        23
#define CAIRO_STATUS_INVALID_STRIDE         24
#define CAIRO_STATUS_FONT_TYPE_MISMATCH     25
#define CAIRO_STATUS_USER_FONT_IMMUTABLE    26
#define CAIRO_STATUS_USER_FONT_ERROR        27
#define CAIRO_STATUS_NEGATIVE_COUNT         28
#define CAIRO_STATUS_INVALID_CLUSTERS       29
#define CAIRO_STATUS_INVALID_SLANT          30
#define CAIRO_STATUS_INVALID_WEIGHT         31

#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 'hbgd' (Graphics drawing library (GD)): contrib/hbgd/tests/gdapi.prg. Contains procedures: Main. This file provides graphics and image processing capabilities

[Assistant]
#require "hbgd"

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

PROCEDURE Main()

   LOCAL im, im2
   LOCAL black, blue, red, green, cyan
   LOCAL color, font

   ? gdVersion()

   im := gdImageCreate( 200, 200 )

   im2 := gdImageCreateFromJpeg( IMAGES_IN + "conv_tst.jpg" )

   black := gdImageColorAllocate( im, 0, 0, 0 )
   blue  := gdImageColorAllocate( im, 0, 0, 255 )
   red   := gdImageColorAllocate( im, 255, 0, 0 )
   green := gdImageColorAllocate( im, 0, 255, 0 )
   cyan  := gdImageColorAllocate( im, 0, 255, 255 )

   gdImageFilledRectangle( im, 0, 0, 199, 199, cyan )
   gdImageRectangle( im, 0, 0, 199, 199, black )

   gdImageSetPixel( im, 50, 5, blue )
   gdImageSetPixel( im, 50, 15, blue )

   gdImageLine( im, 0, 0, 199, 199, blue )
   gdImageDashedLine( im, 0, 199, 199, 0, blue )

   gdImagePolygon( im, { { 10, 10 }, { 70, 10 }, { 80, 60 } }, red )
   gdImageFilledPolygon( im, { { 160, 180 }, { 170, 110 }, { 150, 160 } }, green )

   gdImageArc( im, 50, 50, 40, 40, 30, 190, red )
   gdImageFilledCircle( im, 50, 150, 45, green )
   gdImageEllipse( im, 120, 120, 50, 20, blue )

   font := gdFontGetLarge()

   gdImageString( im, font, 0, 0, "Test", black )
   gdImageString( im, font, 0, 15, "P", black )
   gdImageChar( im, font, 0, 30, "W", black )

   gdImageStringUp( im, font, 70, 90, "Test", black )
   gdImageStringUp( im, font, 70, 15, "P", black )
   gdImageCharUp( im, font, 70, 30, "W", black )

   gdImageStringFT( im, blue, "arial", 20, 30, 20, 90, "Test" )

   ? gdImageStringFTCircle( im, 120, 120, 50, 25, 0.8, "arial", 24, "Up", , red )

   gdImageSetClip( im, 25, 25, 75, 75 )

   color := gdImageGetPixel( im, gdImageSX( im ) / 2, gdImageSY( im ) / 2 )
   ? "Pixel Color is: ", color
   ? "RGB Values: ", gdImageRed( im, color ), gdImageGreen( im, color ), gdImageBlue( im, color )
   ? "Alpha Value: ",  gdImageAlpha( im, color )

   gdImagePng( im, IMAGES_OUT + "rect.png" )

   gdImagePng( im2, IMAGES_OUT + "conv_tst.png" )
   gdImageJpeg( im2, IMAGES_OUT + "conv_tst.jpg" )

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

   RETURN


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

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

Harbour test program: tests/mt/mttest09.prg. This test file tests specific function APIs

[Assistant]
STATIC s_mainThreadID

proc main()
   field F1
   local thID, bResult

   s_mainThreadID := hb_threadSelf()

   dbCreate("_tst", { { "F1", "C", 1, 0 } } )
   use _tst
   while lastRec() < 10000
      dbAppend()
      F1 := chr( recno() )
   enddo

   ? "main thread ID:", s_mainThreadID
   thID := hb_threadStart( @thFunc() )
   ? "current thread ID:", thID
   ? "work area in use, used() =>", used(), alias()
   WAIT "Press a key to detach work area"
   hb_dbDetach( , {|| countRecords( {|| F1 == "A" } ) } )
   ? "work area detached, used() =>", used(), alias()
   ? "we will make some other things now..."
   hb_idleSleep( 1 )
   ? "let's check the result"
   ? "request for work area"
   hb_dbRequest( , , @bResult, .T. )
   ? "work area atached, used() =>", used(), alias()
   ? "query result:", eval( bResult )
   close
   dbDrop("_tst")
   return

proc thFunc()
   local bQuery, xResult

   if hb_dbRequest( , , @bQuery, .T. )
      xResult := Eval( bQuery )
      hb_dbDetach( , {|| xResult } )
   endif
   return

static func countRecords( bFor )
   local nCount := 0
   dbGoTop()
   while ! eof()
      if eval( bFor )
         nCount ++
      endif
      dbSkip()
   enddo
   ? "!!! JOB DONE !!!" + iif( hb_threadSelf() == s_mainThreadID, ;
                               " (by main thread)", " (by child thread)" )
   return nCount


[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/statics.prg. Provides functions: Two, THREE, DetachVar. Contains procedures: Main, NumStat. This test file exercises basic Harbour language features

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

STATIC s_z := "First"

PROCEDURE Main()

   LOCAL i, cb

   STATIC a := "Hello", b := { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }

   ? a
   ? b[ 2 ]

   Two()

   ? "Ok!"

   FOR i := 1 TO 10
      NumStat()
   NEXT

   cb := DetachVar( 10 )
   FOR i := 1 TO 10
      ? Eval( cb, b[ i ] )
   NEXT

   RETURN

FUNCTION Two()

   STATIC a := "Test"

   ? a

   RETURN NIL

FUNCTION THREE( p )

   ? p

   RETURN p

PROCEDURE NumStat( a )

   STATIC s_n := 1

   LOCAL cb

   HB_SYMBOL_UNUSED( a )

   cb := {| x | s_z + Str( x ) }
   ? ++s_n
   ? Eval( cb, s_n )

   RETURN

FUNCTION DetachVar( xLocal )

   STATIC xStatic := 100

   RETURN {| x | ++xStatic, x + xStatic + xLocal }


[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 'hbmisc' (Miscellaneous utility functions): contrib/hbmisc/tests/strfmt.prg. Contains procedures: Main. This file provides utility functions

[Assistant]
#require "hbmisc"
#require "hbtest"

PROCEDURE Main()

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

   HBTEST StrFormat( "%1 thing %2", "a", "b" )                                 IS "a thing b"
   HBTEST StrFormat( "%1 thing %2", "a", 0d20121127 )                          IS "a thing 2012-11-27"
   HBTEST StrFormat( "%1 thing %2", .T., 0d20121127 )                          IS ".T. thing 2012-11-27"
   HBTEST StrFormat( "%1 thing %2", .T., NIL )                                 IS ".T. thing NIL"
   HBTEST StrFormat( "%1 thing %2", "space1  ", 100.20 )                       IS "space1 thing 100.20"
   HBTEST StrFormat( "%1 thing %2", "   space2  ", 213 )                       IS "space2 thing 213"
   HBTEST StrFormat( "%1 thing %2", "   space3", 0.12 )                        IS "space3 thing 0.12"
   HBTEST StrFormat( "%2 thing %1 stuff", "   space3", 0.12 )                  IS "0.12 thing space3 stuff"
   HBTEST StrFormat( "%2 %1 born on %3", "Smith", "Mr.", 0d20121127 )          IS "Mr. Smith born on 2012-11-27"

   HBTEST StrFormat( "Please insert disk %1 to drive %2", hb_ntos( 2 ), "A:" ) IS "Please insert disk 2 to drive A:"
   HBTEST StrFormat( "This is %1 from %2", "Victor", "Europe" )                IS "This is Victor from Europe"
   HBTEST StrFormat( "%2 %1 %2", "Param1", "Param2" )                          IS "Param2 Param1 Param2"
   HBTEST StrFormat( "Hello" )                                                 IS "Hello"
   HBTEST StrFormat( "%1 - %2", "one" )                                        IS "one - "
   HBTEST StrFormat( "%1 - %2", "one", "two" )                                 IS "one - two"
   HBTEST StrFormat( "%2 - %1", "one", "two" )                                 IS "two - one"
   HBTEST StrFormat( "%2 - %", "one", "two" )                                  IS "two - "
   HBTEST StrFormat( "%% - %", "one", "two" )                                  IS "% - "
   HBTEST StrFormat( "%9 - %", "one", "two" )                                  IS " - "

   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, draw, map_path_onto. Harbour contribution module 'hbcairo' (Cairo graphics library wrapper): contrib/hbcairo/tests/fancytxt.prg. Contains 4 procedures. This file provides graphics and image processing capabilities

[Assistant]
#require "hbcairo"

PROCEDURE Main()

   LOCAL hSurface

   hSurface := cairo_pdf_surface_create( "fancytxt.pdf", 566.9, 793.7 )
   draw( hSurface )
   cairo_surface_destroy( hSurface )

   hSurface := cairo_image_surface_create( "fancytxt.pdf", 567, 794 )
   draw( hSurface )
   cairo_surface_write_to_png( hSurface, "fancytxt.png" )
   cairo_surface_destroy( hSurface )

   RETURN

PROCEDURE draw( hSurface )

   LOCAL hCairo, hPath

   hCairo := cairo_create( hSurface )
   cairo_set_tolerance( hCairo, 0.01 )

   cairo_move_to( hCairo, 50, 650 )
   cairo_rel_line_to( hCairo, 250, 50 )
   cairo_rel_curve_to( hCairo, 100, 20, 200, -50, 200, -150 )
   cairo_rel_curve_to( hCairo, 0, -400, -300, -100, -400, -300 )
   hPath := cairo_copy_path_flat( hCairo )

   cairo_set_line_width( hCairo, 1 )
   cairo_set_source_rgb( hCairo, 0.6, 0.0, 0.0 )
   cairo_stroke( hCairo )

   cairo_new_path( hCairo )
   cairo_select_font_face( hCairo, "sans-serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL )
   cairo_set_font_size( hCairo, 72 )
   cairo_move_to( hCairo, 0, -5 )
   cairo_text_path( hCairo, "Welcome to the world of Harbour..." )

   map_path_onto( hCairo, hPath )
   cairo_path_destroy( hPath )

   cairo_set_line_cap( hCairo, CAIRO_LINE_CAP_ROUND )
   cairo_set_source_rgb( hCairo, 0.2, 0.1, 0.8 )
   cairo_fill_preserve( hCairo )

   cairo_set_line_width( hCairo, 1 )
   cairo_set_source_rgb( hCairo, 0.2, 0.2, 0.2 )
   cairo_stroke( hCairo )

   cairo_show_page( hCairo )
   cairo_destroy( hCairo )

   RETURN

PROCEDURE map_path_onto( hCairo, hPath )

   LOCAL hCurrentPath, aLengths, hIterator, nI, aPoints

   hCurrentPath := cairo_copy_path( hCairo )
   aLengths := path_lengths( hPath )
   hIterator := cairo_path_iterator_create( hCurrentPath )
   DO WHILE cairo_path_iterator_next( hIterator ) != NIL
      IF Len( aPoints := cairo_path_iterator_get_points( hIterator ) ) > 0
         FOR nI := 1 TO Len( aPoints )
            transform_point( @aPoints[ nI, 1 ], @aPoints[ nI, 2 ], hPath, aLengths )
         NEXT
         cairo_path_iterator_set_points( hIterator, aPoints )
      ENDIF
   ENDDO
   cairo_path_iterator_destroy( hIterator )
   cairo_append_path( hCairo, hCurrentPath )

   RETURN

STATIC PROCEDURE transform_point( nX, nY, hPath, aLengths )

   LOCAL hIterator, nI, nNX, nNY, nDX, nDY, nRatio, nType, aLast, aPoints, nK1, nK2

   nNX := nX
   nNY := nY
   hIterator := cairo_path_iterator_create( hPath )
   nI := 1
   DO WHILE ( nType := cairo_path_iterator_next( hIterator ) ) != NIL
      aPoints := cairo_path_iterator_get_points( hIterator )
      IF nNX <= aLengths[ nI ] .AND. nType != CAIRO_PATH_MOVE_TO
         EXIT
      ENDIF
      nNX -= aLengths[ nI ]
      nI++
      IF nType == CAIRO_PATH_MOVE_TO .OR. nType == CAIRO_PATH_LINE_TO
         aLast := aPoints[ 1 ]
      ELSEIF nType == CAIRO_PATH_CURVE_TO
         aLast := aPoints[ 3 ]
      ENDIF
   ENDDO

   IF nType == CAIRO_PATH_MOVE_TO
   ELSEIF nType == CAIRO_PATH_LINE_TO
      nRatio := nNX / aLengths[ nI ]
      nX := aLast[ 1 ]


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

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

Harbour header file: include/hbzlib.ch. Defines 10 constants including: HB_ZLIB_CH_, HB_ZLIB_METHOD_STORE, HB_ZLIB_METHOD_DEFLATED, HB_ZLIB_COMPRESSION_NONE, HB_ZLIB_COMPRESSION_SPEED. Defines error handling constants and codes

[Assistant]
#ifndef HB_ZLIB_CH_
#define HB_ZLIB_CH_

#define HB_ZLIB_METHOD_STORE              0
#define HB_ZLIB_METHOD_DEFLATED           8

#define HB_ZLIB_COMPRESSION_NONE          0
#define HB_ZLIB_COMPRESSION_SPEED         1
#define HB_ZLIB_COMPRESSION_SIZE          9
#define HB_ZLIB_COMPRESSION_DEFAULT       ( -1 )
#define HB_ZLIB_COMPRESSION_DISABLE       ( -2 )

#define HB_ZLIB_STRATEGY_DEFAULT          0
#define HB_ZLIB_STRATEGY_FILTERED         1
#define HB_ZLIB_STRATEGY_HUFFMAN_ONLY     2
#define HB_ZLIB_STRATEGY_RLE              3
#define HB_ZLIB_STRATEGY_FIXED            4

#define HB_ZLIB_RES_OK                    0
#define HB_ZLIB_RES_STREAM_END            1
#define HB_ZLIB_RES_NEED_DICT             2
#define HB_ZLIB_RES_ERRNO                 ( -1 )
#define HB_ZLIB_RES_STREAM_ERROR          ( -2 )
#define HB_ZLIB_RES_DATA_ERROR            ( -3 )
#define HB_ZLIB_RES_MEM_ERROR             ( -4 )
#define HB_ZLIB_RES_BUF_ERROR             ( -5 )
#define HB_ZLIB_RES_VERSION_ERROR         ( -6 )

#define HB_ZLIB_RES_UNSUPPORTED           ( -10 )

#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 these Harbour functions: Harbour extra library: extras/superlib/hbsuper.prg. Provides 14 functions including: CDIR, ISPRN, RAT_ROW, RAT_COL, RAT_EXIST. Contains 7 procedures. This file provides utility functions

[Assistant]
#include "fileio.ch"

FUNCTION CDIR( p )
   RETURN DirChange( p ) != F_ERROR

FUNCTION ISPRN( p )
   RETURN hb_IsPrinter( p )

PROCEDURE RAT_ON()

   MShow()

   RETURN

PROCEDURE RAT_OFF()

   MHide()

   RETURN

FUNCTION RAT_ROW()
   RETURN MRow()

FUNCTION RAT_COL()
   RETURN MCol()

PROCEDURE RAT_POSIT( nRow, nCol )

   MSetPos( nRow, nCol )

   RETURN

FUNCTION RAT_EXIST()
   RETURN MPresent()

PROCEDURE RAT_AREA( nTop, nLeft, nBottom, nRight )

   MSetBounds( nTop, nLeft, nBottom, nRight )

   RETURN

FUNCTION RAT_LBHD
   RETURN MLeftDown()

FUNCTION RAT_RBHD
   RETURN MRightDown()

PROCEDURE RAT_RESET()
   RETURN

PROCEDURE RAT_NOMOUS()
   RETURN

PROCEDURE RAT_FORCE()
   RETURN

FUNCTION RAT_ROWL()
   RETURN MRow()

FUNCTION RAT_ROWR()
   RETURN MRow()

FUNCTION RAT_COLL()
   RETURN MCol()

FUNCTION RAT_COLR()
   RETURN MCol()

FUNCTION RAT_LEFTB()
   RETURN MLeftDown()

FUNCTION RAT_RIGHTB()
   RETURN MRightDown()

FUNCTION SHIFTY( f )

   HB_SYMBOL_UNUSED( f )

   RETURN .F.


[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: CBhandler. Harbour contribution module 'gtwvw' (): contrib/gtwvw/tests/cb1.prg. Provides functions: CBhandler. Contains procedures: Main. This file provides platform-specific functionality

[Assistant]
#require "gtwvw"

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

STATIC s_cQuestion := "Quick survey: What do you think about GTWVW?"
STATIC s_cHint     := "Hint: Please be positive..."

STATIC s_aAnswers  := { "1-GTWVW is a great library!", ;
      "2-GT who? I never heard about him", ;
      "3-Sorry, I don't like it" }

STATIC s_cYourAnswer := "Your response is:"
STATIC s_cThankYou := "Thanks for participating in our survey :-)"

#define _SECRET_KEY  101010

ANNOUNCE HB_NOSTARTUPWINDOW

PROCEDURE Main()

   LOCAL nMaxWidth, nCBid, nPBid, nPos
   LOCAL ch, ncursor

#if defined( __HBSCRIPT__HBSHELL ) .AND. defined( __PLATFORM__WINDOWS )
   hbshell_gtSelect( "GTWVW" )
#endif

   SetColor( "N/W" )
   wvw_SetTitle( NIL, "Quick Survey" )
   wvw_NoClose( NIL )
   wvw_SetAltF4Close( .F. )
   wvw_SetLineSpacing( NIL, 4 )
   wvw_cbSetFont( NIL, "Arial", 16 )
   wvw_pbSetFont( NIL, "Arial", 16 )

   nMaxWidth := 0
   AEval( s_aAnswers, {| x | nMaxWIdth := Max( nMaxWidth, Len( x ) ) } )

   SetMode( 11, nMaxWidth + 1 + 10 + 2 )

   CLS
   nCursor := SetCursor( SC_NONE )
   @ 1, 1 SAY s_cQuestion
   @ 2, 1 SAY s_cHint
   nCBid := wvw_cbCreate( NIL, 4, 1, nMaxWidth, s_aAnswers, ;
      {| nWinNum, nId, nEvent, nIndex | ;
      CBhandler( nWinNum, nId, nEvent, nIndex, nPBid ) } )

   nPBid := wvw_pbCreate( NIL, 4, 1 + nMaxWidth + 1, 4, 1 + nMaxWidth + 1 + 10 - 1, "OK", NIL, ;
      {|| hb_keyPut( _SECRET_KEY ) }, { 0, 0, + 2, 0 } )

   wvw_cbSetFocus( NIL, nCBid )

   wvw_ShowWindow()

   nPos := 1
   DO WHILE ( ch := Inkey( 0 ) ) != _SECRET_KEY
      DO CASE
      CASE ch == K_TAB .OR. ch == K_ENTER
         IF nPos == 2 .AND. ch == K_ENTER .AND. wvw_pbEnable( NIL, nPBid )
            hb_keyPut( _SECRET_KEY )
            LOOP
         ELSE
            nPos++
         ENDIF
      CASE ch == K_SH_TAB
         nPos--
      ENDCASE
      IF nPos > 2
         nPos := 1
      ELSEIF nPos < 1
         nPos := 2
      ENDIF
      DO CASE
      CASE nPos == 1
         wvw_cbSetFocus( NIL, nCBid )
      CASE nPos == 2
         wvw_pbSetFocus( NIL, nPBid )
         wvw_pbSetStyle( NIL, nPBid, 1 )
      ENDCASE
   ENDDO

   wvw_cbEnable( NIL, nCBid, .F. )
   wvw_pbEnable( NIL, nPBid, .F. )
   @ 6, 1 SAY "Your response is:"
   @ 7, 1 SAY wvw_cbGetCurText( NIL, nCBid )
   @ 9, 1 SAY s_cThankYou
   Inkey( 0 )
   SetCursor( nCursor )

   RETURN

STATIC FUNCTION CBhandler( nWinNum, nId, nEvent, nIndex, nPBid )

   DO CASE
   CASE nEvent == 3

   CASE nEvent == 4

      IF nIndex == 0
         wvw_pbEnable( nWinNum, nPBid, .T. )
      ELSE
         wvw_pbEnable( nWinNum, nPBid, .F. )
      ENDIF
   CASE nEvent == 1
      IF ! wvw_cbIsDropped( nWinNum, nId )

         IF nIndex == 0
            wvw_pbEnable( nWinNum, nPBid, .T. )
         ELSE
            wvw_pbEnable( nWinNum, nPBid, .F. )
         ENDIF
         wvw_cbSetFocus( nWinNum, nId )
      ENDIF
   ENDCASE

   RETURN NIL


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

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

Harbour test program: tests/multifnc/t2.prg. This test file tests specific function APIs

[Assistant]
proc main3()
? "main3", procfile("main3"), procfile(@main3())
? "alert", procfile("alert"), procfile(@alert()), alert()
? "p0", procfile("p0"), procfile(@p0()), (@p0()):exec(), p0(), t("p0",@p0(),p0(),"t0.prg")
? "p1", procfile("p1"), procfile(@p1()), (@p1()):exec(), p1(), t("p1",@p1(),p1(),"t0.prg")
? "p2", procfile("p2"), procfile(@p2()), (@p2()):exec(), p2(), t("p2",@p2(),p2(),"t1.prg")
? "p3", procfile("p3"), procfile(@p3()), (@p3()):exec(), p3(), t("p3",@p3(),p3(),"t0.prg")
? "p4", procfile("p4"), procfile(@p4()), (@p4()):exec(), p4(), t("p4",@p4(),p4(),"t1.prg")
? "p5", procfile("p5"), procfile(@p5()), (@p5()):exec(), p5(), t("p5",@p5(),p5(),"t2.prg")
? "p6", procfile("p6"), procfile(@p6()), (@p6()):exec(), p6(), t("p6",@p6(),p6(),"t0.prg")
? "p7", procfile("p7"), procfile(@p7()), (@p7()):exec(), p7(), t("p7",@p7(),p7(),"t1.prg")
return

func p2(); return "P2:t2.prg"
func p3(); return "P3:t2.prg"
func p5(); return "P5:t2.prg"
func p6(); return "P6:t2.prg"
func p7(); return "P7:t2.prg"


[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 'hbgd' (Graphics drawing library (GD)): contrib/hbgd/gd.prg. Provides 9 functions including: gdImageCircle, gdImageFilledCircle, gdImageEllipse, gdImageFTWidth, gdImageFTHeight. Contains procedures: gdImageToFile, gdImageToHandle. This file provides graphics and image processing capabilities

[Assistant]
FUNCTION gdImageCircle( im, cx, cy, w, color )
   RETURN gdImageArc( im, cx, cy, w, w, 0, 360, color )

FUNCTION gdImageFilledCircle( im, cx, cy, w, color )
   RETURN gdImageFilledEllipse( im, cx, cy, w, w, color )

FUNCTION gdImageEllipse( im, cx, cy, w, h, color )
   RETURN gdImageArc( im, cx, cy, w, h, 0, 360, color )

FUNCTION gdImageFTWidth( fontname, ptsize, angle )

   LOCAL nWidth := 0
   LOCAL cErr
   LOCAL aRect := Array( 8 )

   hb_default( @fontname, "Arial" )
   hb_default( @ptsize, 8 )
   hb_default( @angle, 0 )

   cErr := gdImageStringFTEx( , @aRect, 0, fontname, ptsize, angle, 0, 0, "M" )

   IF cErr == ""
      nWidth := aRect[ 3 ] - aRect[ 1 ]
   ENDIF

   RETURN nWidth

FUNCTION gdImageFTHeight( fontname, ptsize, angle )

   LOCAL nWidth := 0
   LOCAL cErr
   LOCAL aRect := Array( 8 )

   hb_default( @fontname, "Arial" )
   hb_default( @ptsize, 8 )
   hb_default( @angle, 0 )

   cErr := gdImageStringFTEx( , @aRect, 0, fontname, ptsize, angle, 0, 0, "M" )
   IF cErr == ""
      nWidth := aRect[ 2 ] - aRect[ 8 ]
   ENDIF

   RETURN nWidth

FUNCTION gdImageFTSize( string, fontname, ptsize, angle )

   LOCAL nWidth  := 0
   LOCAL nHeight := 0
   LOCAL nX, nY
   LOCAL cErr
   LOCAL aRect := Array( 8 )

   hb_default( @fontname, "Arial" )
   hb_default( @ptsize, 8 )
   hb_default( @angle, 0 )

   cErr := gdImageStringFTEx( , @aRect, 0, fontname, ptsize, angle, 0, 0, string )

   IF cErr == ""
      nWidth  := aRect[ 3 ] - aRect[ 1 ]
      nHeight := aRect[ 2 ] - aRect[ 8 ]
      nX      := aRect[ 1 ]
      nY      := aRect[ 2 ]
   ENDIF

   RETURN { nWidth, nHeight, nX, nY }

FUNCTION gdImageStringFT( im, fg, fontname, ptsize, angle, x, y, string, ;
      linespacing, charmap, resolution )

   LOCAL cErr
   LOCAL aRect := Array( 8 )

   cErr := gdImageStringFTEx( , @aRect, fg, fontname, ptsize, angle, x, y, string, linespacing, charmap, resolution )
   IF cErr == ""
      cErr := gdImageStringFTEx( im, aRect, fg, fontname, ptsize, angle, x, y, string, linespacing, charmap, resolution )
   ENDIF

   RETURN cErr

FUNCTION gdImageFromFile( cFile )

   LOCAL cPath, cName, cExt, cDrive
   LOCAL cType, cMime
   LOCAL hFile := { => }
   LOCAL oImage

   IF hb_FileExists( cFile )
      hb_FNameSplit( cFile, @cPath, @cName, @cExt, @cDrive )

      SWITCH Lower( cExt )
      CASE ".jpg"
      CASE ".jpeg"
         hFile[ "file"  ] := cFile
         hFile[ "path"  ] := cPath
         hFile[ "name"  ] := cName
         hFile[ "ext"   ] := cExt
         hFile[ "drive" ] := cDrive
         cType  := "jpeg"
         cMime  := "image/jpeg"
         oImage := GDImage():LoadFromJpeg( cFile )
         EXIT
      CASE ".gif"
         hFile[ "file"  ] := cFile
         hFile[ "path"  ] := cPath
         hFile[ "name"  ] := cName
         hFile[ "ext"   ] := cExt
         hFile[ "drive" ] := cDrive
         cType  := "gif"
         cMime  := "image/gif"
         oImage := GDImage():LoadFromGif( cFile )
         EXIT
      CASE ".png"
         hFile[ "file"  ] := cFile
         hFile[ "path"  ] := cPath
         hFile[ "name"  ] := cName
         hFile[ "ext"   ] := cExt
         hFile[ "drive" ] := cDrive
         cType  := "png"
         cMime  := "image/png"
         oImage := GDImage():LoadFromPng( cFile )
         EXIT
      ENDSWITCH
   ENDIF

   RETURN { oImage, hFile, cType, cMime }

FUNCTION gdImageToString( oImage )

   LOCAL cString

   IF HB_ISOBJECT( oImage ) .AND. ( oImage:className() == "GDIMAGE" .OR. oImage:IsDerivedFrom( "GDIMAGE" ) ) .AND. oImage:cType != NIL
      SWITCH oImage:cType
      CASE "jpeg"
         cString := oImage:ToStringJpeg()
         EXIT
      CASE "gif"
         cString := oImage:ToStringGif()
         EXIT
      CASE "png"
         cString := oImage:ToStringPng()
         EXIT
      ENDSWITCH
   ENDIF

   RETURN cString

PROCEDURE gdImageToFile( oImage, cFile )

   LOCAL cString, cExt

   hb_default( @cFile, "image" )

   IF HB_ISOBJECT( oImage ) .AND. ( oImage:className() == "GDIMAGE" .OR. oImage:IsDerivedFrom( "GDIMAGE" ) ) .AND. oImage:cType != NIL
      SWITCH oImage:cType
      CASE "jpeg"
         cString := oImage:ToStringJpeg()
         cExt := ".jpg"
         EXIT
      CASE "gif"
         cString := oImage:ToStringGif()
         cExt := ".gif"
         EXIT
      CASE "png"
         cString := oImage:ToStringPng()
         cExt := ".png"
         EXIT
      OTHERWISE
         cExt := ""
      ENDSWITCH
      IF cString != NIL
         hb_MemoWrit( cFile + cExt, cString )
      ENDIF
   ENDIF

   RETURN

PROCEDURE gdImageToHandle( oImage, nHandle )

   hb_default( @nHandle, 1 )

   IF HB_ISOBJECT( oImage ) .AND. ( oImage:className() == "GDIMAGE" .OR. oImage:IsDerivedFrom( "GDIMAGE" ) )
      IF oImage:cType != NIL
         SWITCH oImage:cType
         CASE "jpeg"
            oImage:OutputJpeg( nHandle )
            EXIT
         CASE "gif"
            oImage:OutputGif( nHandle )
            EXIT
         CASE "png"
            oImage:OutputPng( nHandle )
            EXIT
         ENDSWITCH
      ENDIF
   ENDIF

   RETURN


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

[User] Write Harbour functions: GetPingResult. Harbour contribution module 'hbpgsql' (PostgreSQL database client library): contrib/hbpgsql/tests/ping.prg. Provides functions: GetPingResult. Contains procedures: Main, PingTest. This file handles database operations

[Assistant]
#require "hbpgsql"

PROCEDURE Main( cHost, cDatabase, cUser, cPass )

   LOCAL nVersion

   CLS

   ? "The function PQlibVersion() returns", nVersion := PQlibVersion()
   ?

   IF nVersion < 90100
      ? "Function PQping() not supported."
      QUIT
   ENDIF

   hb_default( @cHost, "localhost" )
   hb_default( @cDatabase, "postgres" )
   hb_default( @cUser, hb_UserName() )
   hb_default( @cPass, "" )

   HB_SYMBOL_UNUSED( cDatabase )
   HB_SYMBOL_UNUSED( cUser )
   HB_SYMBOL_UNUSED( cPass )

   PingTest( "" )

   PingTest( ;
      "host = localhost" + " " + ;
      "database = test" )

   PingTest( ;
      "host = " + cHost + " " + ;
      "port = " + "3333" )

   PingTest( ;
      "host = " + cHost + " " + ;
      "hostaddr = " + "127.0.0.1" + " " + ;
      "port = " + "5432" + " " + ;
      "connect_timeout = " + "10" )

   RETURN

STATIC PROCEDURE PingTest( cConnInfo )

   ? "cConnInfo is", '"' + cConnInfo + '"'
   ? "PQPing( cConnInfo ) returns:", GetPingResult( PQPing( cConnInfo ) )
   ?

   RETURN

STATIC FUNCTION GetPingResult( n )

   LOCAL aMsg := { ;
      { "PQPING_OK"         , "Server is accepting connections" }, ;
      { "PQPING_REJECT"     , "Server is alive but rejecting connections" }, ;
      { "PQPING_NO_RESPONSE", "Could not establish connection" }, ;
      { "PQPING_NO_ATTEMPT" , "Connection not attempted (bad params)" } }

   IF n >= 0 .AND. n < Len( aMsg )
      RETURN aMsg[ n + 1 ][ 1 ] + " " + aMsg[ n + 1 ][ 2 ]
   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 contribution module 'hbct' (CA-Tools compatibility library): contrib/hbct/tests/charrepl.prg. Contains procedures: Main. This file provides legacy compatibility functions

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

PROCEDURE Main()

   ctinit()

   ? "Begin test of CharRepl()"
   ?

   ? "Simple tests:"
   ? '  CharRepl( "1234", "1x2y3z", "abcd" ) ==            "axbycz" ? --> "' + CharRepl( "1234", "1x2y3z", "abcd" )            + '"'
   ? '  CharRepl( "abcdefghij", "jhfdb", "1234567890" ) == "08642"  ? --> "' + CharRepl( "abcdefghij", "jhfdb", "1234567890" ) + '"'
   ? '  CharRepl( "abcdefghij", "jhfdb", "12345" ) ==      "55542"  ? --> "' + CharRepl( "abcdefghij", "jhfdb", "12345" )      + '"'
   ? '  CharRepl( "1234", "1234", "234A" ) ==              "AAAA"   ? --> "' + CharRepl( "1234", "1234", "234A" )              + '"'
   ? '  CharRepl( "1234", "1234", "234A", .T. ) ==         "234A"   ? --> "' + CharRepl( "1234", "1234", "234A", .T. )         + '"'
   ?

   ? "End test of CharRepl()"
   ?

   ctexit()

   RETURN


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

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

Harbour Runtime Library file: src/rtl/tsymbol.prg. Defines classes: Symbol. This file implements object-oriented classes using Harbour's class system

[Assistant]
#include "hbclass.ch"

CREATE CLASS Symbol

   EXPORTED:

   METHOD Init( cSymName )
   METHOD name()
   METHOD isEqual( oSymbol )
   METHOD exec( ... )

   PROTECTED:

   VAR nSym

ENDCLASS

METHOD Init( cSymName ) CLASS Symbol

   ::nSym := __dynsN2Sym( cSymName )

   RETURN Self

METHOD name() CLASS Symbol
   RETURN ::nSym:Name

METHOD isEqual( oSymbol ) CLASS Symbol
   RETURN ::ClassH == oSymbol:ClassH .AND. ::nSym:Name == oSymbol:nSym:Name

METHOD exec( ... ) CLASS Symbol
   RETURN ::nSym:exec( ... )


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

[User] Implement these Harbour functions: Harbour contribution module 'xhb' (Extended Harbour functions): contrib/xhb/cstruct.prg. Provides functions: __ActiveStructure, hb_CStructureId, hb_CStructure. Contains procedures: __init_LONGLONGs, hb_Member, hb_CStructureCSyntax. This file provides legacy compatibility functions

[Assistant]
#include "cstruct.ch"
#include "hboo.ch"
#include "error.ch"

#define CLASS_PROPERTIES 6

THREAD STATIC t_aActiveStructure

STATIC s_aClasses := {}
STATIC s_aArrayClasses := {}
STATIC s_aSynonyms := {}
STATIC s_lInitLongs := .T.

PROCEDURE __init_LONGLONGs()

   hb_CStructureCSyntax( "ULONGLONG", { "-4", "ulong[2]", }, , , 8 )
   __ClsSetModule( __ActiveStructure() )

   hb_CStructureCSyntax( "LONGLONG", { "4", "long[2]", }, , , 8 )
   __ClsSetModule( __ActiveStructure() )

   RETURN

FUNCTION __ActiveStructure( cStructure, nAlign )

   LOCAL acMembers, aCTypes, hClass, Counter, cMember

   IF s_lInitLongs
      s_lInitLongs := .F.
      __init_LONGLONGs()
   ENDIF

   IF PCount() == 2
      cStructure := Upper( cStructure )

      IF AScan( s_aClasses, {| aClassInfo | aClassInfo[ 1 ] == cStructure } ) > 0

         RETURN t_aActiveStructure := { cStructure, NIL, {}, {}, iif( HB_ISNUMERIC( nAlign ), nAlign, 8 ) }
      ENDIF

      AAdd( s_aClasses, { cStructure, NIL, {}, {}, iif( HB_ISNUMERIC( nAlign ), nAlign, 8 ) } )

      t_aActiveStructure := ATail( s_aClasses )
   ELSE

      acMembers := t_aActiveStructure[ 3 ]
      aCTypes   := t_aActiveStructure[ 4 ]
      nAlign    := t_aActiveStructure[ 5 ]

      hClass := __clsNew( "C Structure " + t_aActiveStructure[ 1 ], Len( acMembers ) + CLASS_PROPERTIES )

      t_aActiveStructure[ 2 ] := hClass

      __clsAddMsg( hClass,  "Reset"     , @Reset()         , HB_OO_MSG_METHOD )
      __clsAddMsg( hClass,  "Buffer"    , @Buffer()        , HB_OO_MSG_METHOD )
      __clsAddMsg( hClass,  "Value"     , @Value()         , HB_OO_MSG_METHOD )
      __clsAddMsg( hClass,  "DeValue"   , @DeValue()       , HB_OO_MSG_METHOD )
      __clsAddMsg( hClass,  "Array"     , @ArrayMethod()   , HB_OO_MSG_METHOD )
      __clsAddMsg( hClass,  "SayMembers", @SayMembers()    , HB_OO_MSG_METHOD )
      __clsAddMsg( hClass,  "Init"      , @Init()          , HB_OO_MSG_METHOD )
      __clsAddMsg( hClass,  "Pointer"   , @Pointer()       , HB_OO_MSG_METHOD )
      __clsAddMsg( hClass,  "GetPointer", @GetPointer()    , HB_OO_MSG_METHOD )
      __clsAddMsg( hClass,  "CopyTo"    , @__CStr_CopyTo() , HB_OO_MSG_METHOD )

      FOR EACH cMember IN acMembers
         __clsAddMsg( hClass,       cMember, cMember:__enumIndex(), HB_OO_MSG_PROPERTY )
      NEXT

      Counter := Len( acMembers )
      __clsAddMsg( hClass,  "aCTypes"       , ++Counter, HB_OO_MSG_PROPERTY, acTypes )
      __clsAddMsg( hClass,  "aCMembers"     , ++Counter, HB_OO_MSG_PROPERTY, acMembers, HB_OO_CLSTP_READONLY )
      __clsAddMsg( hClass,  "nAlign"        , ++Counter, HB_OO_MSG_PROPERTY, nAlign, HB_OO_CLSTP_READONLY )
      __clsAddMsg( hClass,  "SizeOf"        , ++Counter, HB_OO_MSG_PROPERTY, hb_SizeOfCstructure( aCTypes, nAlign ), HB_OO_CLSTP_READONLY )
      __clsAddMsg( hClass,  "_nID"          , ++Counter, HB_OO_MSG_PROPERTY, Len( s_aClasses ) )

      __clsAddMsg( hClass,  "InternalBuffer", ++Counter, HB_OO_MSG_PROPERTY, , HB_OO_CLSTP_READONLY )

      RETURN hClass
   ENDIF

   RETURN t_aActiveStructure

PROCEDURE hb_Member( cMember, CType )

   LOCAL nLen, nAt

   IF Right( cMember, 1 ) == "]"
      nAt := At( "[", cMember )

      nLen := &( SubStr( cMember, nAt + 1, Len( cMember ) - nAt - 1 ) )

      AAdd( t_aActiveStructure[ 3 ], Left( cMember, nAt - 1 ) )
      AAdd( t_aActiveStructure[ 4 ], hb_CTypeArrayId( CType, nLen ) )
   ELSE
      AAdd( t_aActiveStructure[ 3 ], cMember )
      AAdd( t_aActiveStructure[ 4 ], CType )
   ENDIF

   RETURN

FUNCTION hb_CStructureId( cStructure, lInplace )

   LOCAL nID
   LOCAL oErr

   cStructure := Upper( cStructure )

   IF ( nID := AScan( s_aClasses, {| aClassInfo | aClassInfo[ 1 ] == cStructure } ) ) == 0
      IF ( nID := AScan( s_aSynonyms, {| aSynonym | aSynonym[ 1 ] == cStructure } ) ) == 0
         oErr := ErrorNew()
         oErr:Args          := { cStructure, lInplace }
         oErr:CanDefault    := .F.
         oErr:CanRetry      := .F.
         oErr:CanSubstitute := .T.
         oErr:Description   := "Structure not found: '" + cStructure + "'"
         oErr:Operation     := "hb_CStructureId()"
         oErr:Severity      := ES_ERROR
         oErr:SubCode       := 3
         oErr:SubSystem     := "C Structure"

         RETURN Eval( ErrorBlock(), oErr )
      ELSE
         nID := s_aSynonyms[ nID ][ 2 ]
      ENDIF

      nID += iif( lInplace, 0, CTYPE_STRUCTURE_PTR - CTYPE_STRUCTURE )
   ELSE
      nID += iif( lInplace, CTYPE_STRUCTURE, CTYPE_STRUCTURE_PTR )
   ENDIF

   RETURN nID

PROCEDURE hb_CStructureCSyntax( cStructure, aDefinitions, cTag, cSynonList, nAlign )

   LOCAL cElem, nAt, nIndex := 1
   LOCAL nLen, Counter, CType
   LOCAL oErr
   LOCAL nID, cSynon

   FOR EACH cElem IN aDefinitions

      IF cElem == NIL
         ASize( aDefinitions, nIndex - 1 )
         EXIT
      ENDIF

      IF ( nAt := At( "*", cElem ) ) > 1
         IF nIndex < Len( aDefinitions )
            hb_AIns( aDefinitions, nIndex + 1, SubStr( cElem, nAt + 1 ), .T. )
         ELSE
            AAdd( aDefinitions, SubStr( cElem, nAt + 1 ) )
         ENDIF

         aDefinitions[ nIndex ] := StrTran( Left( cElem, nAt ), " " )
      ELSEIF ( nAt := At( "-", cElem ) ) > 1
         IF nIndex < Len( aDefinitions )
            hb_AIns( aDefinitions, nIndex + 1, SubStr( cElem, nAt ), .T. )
         ELSE
            AAdd( aDefinitions, SubStr( cElem, nAt ) )
         ENDIF

         aDefinitions[ nIndex ] := RTrim( Left( cElem, nAt - 1 ) )
      ENDIF

      nIndex++
   NEXT

   __ActiveStructure( cStructure, nAlign )
   nID := Len( s_aClasses )

   IF ! Empty( cTag )
      AAdd( s_aSynonyms, { Upper( cTag ), nID + CTYPE_STRUCTURE } )

   ENDIF

   IF ! Empty( cSynonList )
      FOR EACH cSynon IN hb_ATokens( cSynonList )
         IF Left( cSynon, 1 ) == "*"
            AAdd( s_aSynonyms, { Upper( SubStr( cSynon, 2 ) ), nID + CTYPE_STRUCTURE_PTR } )
         ELSE
            AAdd( s_aSynonyms, { Upper( cSynon ), nID + CTYPE_STRUCTURE } )
         ENDIF

      NEXT
   ENDIF

   nLen := Len( aDefinitions )

   FOR Counter := 1 TO nLen STEP 2

      CType := aDefinitions[ Counter ]
      IF Val( CType ) != 0
         hb_Member( aDefinitions[ Counter + 1 ], Val( aDefinitions[ Counter ] ) )
      ELSE
         IF Right( CType, 1 ) == "*"
            CType := hb_CStructureId( Left( CType, Len( CType ) - 1 ), .F. )
         ELSE
            CType := hb_CStructureId( CType, .T. )

            IF CType == CTYPE_STRUCTURE .OR. CType == CTYPE_STRUCTURE_PTR
               oErr := ErrorNew()
               oErr:Args          := { cStructure, aDefinitions, cTag, cSynonList, nAlign }
               oErr:CanDefault    := .F.
               oErr:CanRetry      := .F.
               oErr:CanSubstitute := .T.
               oErr:Description   := "Undefined CType: '" + aDefinitions[ Counter ] + "'"
               oErr:Operation     := "hb_CStructureCSyntax()"
               oErr:Severity      := ES_ERROR
               oErr:SubCode       := 2
               oErr:SubSystem     := "C Structure"

               CType := Eval( ErrorBlock(), oErr )
            ENDIF
         ENDIF

         hb_Member( aDefinitions[ Counter + 1 ], CType )
      ENDIF
   NEXT

   RETURN

FUNCTION hb_CStructure( cStructure, nAlign )

   LOCAL hClass
   LOCAL oStructure
   LOCAL nID
   LOCAL oErr

   cStructure := Upper( cStructure )

   IF ( nID := AScan( s_aClasses, {| aClassInfo | aClassInfo[ 1 ] == cStructure } ) ) == 0
      oErr := ErrorNew()
      oErr:Args          := { cStructure, nAlign }
      oErr:CanDefault    := .F.
      oErr:CanRetry      := .F.
      oErr:CanSubstitute := .T.
      oErr:Description   := "Structure not initialized with __ActiveStructure()"
      oErr:Operation     := "hb_CStructure()"
      oErr:Severity      := ES_ERROR
      oErr:SubCode       := 3
      oErr:SubSystem     := "C Structure"

      RETURN Eval( ErrorBlock(), oErr )
   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 'hbnf' (NanForum Toolkit - legacy Clipper compatibility functions): contrib/hbnf/at2.prg. Provides functions: ft_At2, ft_RAt2. This file provides legacy compatibility functions

[Assistant]
FUNCTION ft_At2( cSearch, cTarget, nOccurs, lCaseSens )

   LOCAL nCount, nPos, nPos2 := 0
   LOCAL cSubstr := cTarget

   __defaultNIL( @lCaseSens, .T. )
   __defaultNIL( @nOccurs, 1 )

   FOR nCount := 1 TO nOccurs

      IF lCaseSens
         nPos := At( cSearch, cSubstr )
      ELSE
         nPos := At( Upper( cSearch ), Upper( cSubstr ) )
      ENDIF

      nPos2 += nPos

      cSubstr := SubStr( cSubstr, At( cSearch, cSubstr ) + 1 )

      IF nPos == 0
         EXIT
      ENDIF
   NEXT

   RETURN nPos2

FUNCTION ft_RAt2( cSearch, cTarget, nOccurs, lCaseSens )

   LOCAL nCount, nPos, nPos2 := 0
   LOCAL cSubstr := cTarget

   __defaultNIL( @lCaseSens, .T. )
   __defaultNIL( @nOccurs, 1 )

   FOR nCount := 1 TO nOccurs

      IF lCaseSens
         nPos := RAt( cSearch, cSubstr )
      ELSE
         nPos := RAt( Upper( cSearch ), Upper( cSubstr ) )
      ENDIF

      nPos2 := nPos

      cSubstr := SubStr( cSubstr, 1, RAt( cSearch, cSubstr ) - 1 )

      IF nPos == 0
         EXIT
      ENDIF
   NEXT

   RETURN nPos2


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

[Assistant]
#include "inkey.ch"

PROCEDURE Main()

   LOCAL oBrowse := TBrowseNew( 5, 5, 16, 30 )
   LOCAL aTest0  := { "This", "is", "a", "browse", "on", "an", "array", "test", "with", "a", "long", "data" }
   LOCAL aTest1  := { 1, 2, 3, 4, 5, 6, 7, 8, 10000, - 1000, 54, 456342 }
   LOCAL aTest2  := { Date(), Date() + 4, Date() + 56, Date() + 14, Date() + 5, Date() + 6, Date() + 7, Date() + 8, Date() + 10000, Date() - 1000, Date() - 54, Date() + 456342 }
   LOCAL aTest3  := { .T., .F., .T., .T., .F., .F., .T., .F., .T., .T., .F., .F. }
   LOCAL n       := 1
   LOCAL nCursor
   LOCAL cColor
   LOCAL nRow, nCol
#ifndef HB_COMPAT_C53
   LOCAL nKey
   LOCAL nTmpRow, nTmpCol
   LOCAL lEnd    := .F.
#endif

   oBrowse:colorSpec     := "W+/B, N/BG"
   oBrowse:ColSep        := hb_UTF8ToStrBox( "│" )
   oBrowse:HeadSep       := hb_UTF8ToStrBox( "╤═" )
   oBrowse:FootSep       := hb_UTF8ToStrBox( "╧═" )
   oBrowse:GoTopBlock    := {|| n := 1 }
   oBrowse:GoBottomBlock := {|| n := Len( aTest0 ) }
   oBrowse:SkipBlock     := {| nSkip, nPos | nPos := n, ;
      n := iif( nSkip > 0, Min( Len( aTest0 ), n + nSkip ), ;
      Max( 1, n + nSkip ) ), n - nPos }

   oBrowse:AddColumn( TBColumnNew( "First",  {|| n } ) )
   oBrowse:AddColumn( TBColumnNew( "Second", {|| aTest0[ n ] } ) )
   oBrowse:AddColumn( TBColumnNew( "Third",  {|| aTest1[ n ] } ) )
   oBrowse:AddColumn( TBColumnNew( "Forth",  {|| aTest2[ n ] } ) )
   oBrowse:AddColumn( TBColumnNew( "Fifth",  {|| aTest3[ n ] } ) )
   oBrowse:GetColumn( 1 ):Footing := "Number"
   oBrowse:GetColumn( 2 ):Footing := "String"

   oBrowse:GetColumn( 2 ):Picture := "@!"

   oBrowse:GetColumn( 3 ):Footing := "Number"
   oBrowse:GetColumn( 3 ):Picture := "999,999.99"
   oBrowse:GetColumn( 4 ):Footing := "Dates"
   oBrowse:GetColumn( 5 ):Footing := "Logical"

   oBrowse:Configure()

   Alert( oBrowse:ClassName() )
   Alert( oBrowse:GetColumn( 1 ):ClassName() )

   oBrowse:Freeze := 1
   nCursor := SetCursor( 0 )
   cColor := SetColor( "W+/B" )
   nRow := Row()
   nCol := Col()
   hb_DispBox( 4, 4, 17, 31, hb_UTF8ToStrBox( "┌─┐│┘─└│ " ) )
#ifdef HB_COMPAT_C53
   oBrowse:SetKey( 0, {| ob, nkey | DefProc( ob, nKey ) } )
   WHILE .T.
      oBrowse:ForceStable()
      IF oBrowse:applykey( Inkey( 0 ) ) == -1
         EXIT
      ENDIF
   ENDDO
#else
   WHILE ! lEnd
      oBrowse:ForceStable()

      nKey := Inkey( 0 )

      DO CASE
      CASE nKey == K_ESC
         SetPos( 17, 0 )
         lEnd := .T.

      CASE nKey == K_DOWN
         oBrowse:Down()

      CASE nKey == K_UP
         oBrowse:Up()

      CASE nKey == K_LEFT
         oBrowse:Left()

      CASE nKey == K_RIGHT
         oBrowse:Right()

      CASE nKey == K_PGDN
         oBrowse:pageDown()

      CASE nKey == K_PGUP
         oBrowse:pageUp()

      CASE nKey == K_CTRL_PGUP
         oBrowse:goTop()

      CASE nKey == K_CTRL_PGDN
         oBrowse:goBottom()

      CASE nKey == K_HOME
         oBrowse:home()

      CASE nKey == K_END
         oBrowse:end()

      CASE nKey == K_CTRL_LEFT
         oBrowse:panLeft()

      CASE nKey == K_CTRL_RIGHT
         oBrowse:panRight()

      CASE nKey == K_CTRL_HOME
         oBrowse:panHome()

      CASE nKey == K_CTRL_END
         oBrowse:panEnd()

      CASE nKey == K_TAB
         hb_DispOutAt( 0, 0, Time() )

      ENDCASE

   ENDDO
#endif
   SetPos( nRow, nCol )
   SetColor( cColor )
   SetCursor( nCursor )

   RETURN

#ifdef HB_COMPAT_C53

STATIC FUNCTION DefProc( oBrowse, nKey )

   IF nKey == K_TAB
      hb_DispOutAt( 0, 0, Time() )
      oBrowse:Refreshall()
   ENDIF

   RETURN 1

#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: Header file for contribution module 'hbxpp' (xBase++ compatibility functions): contrib/hbxpp/thread.ch. Defines constants: _THREAD_CH, QUIT_NORESTART, QUIT_RESTART. Defines threading constants and macros

[Assistant]
#ifndef _THREAD_CH
#define _THREAD_CH

#define QUIT_NORESTART  0
#define QUIT_RESTART    1

#endif


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

[User] Write Harbour functions: DispArray. Harbour contribution module 'hbnf' (NanForum Toolkit - legacy Clipper compatibility functions): contrib/hbnf/tests/savearr.prg. Provides functions: DispArray. Contains procedures: Main. This file provides legacy compatibility functions

[Assistant]
#require "hbnf"

PROCEDURE Main()

   LOCAL aArray := { ;
      { "Invoice 1", hb_SToD( "19910415" ), 1234.32, .T. }, ;
      { "Invoice 2", Date(), 234.98, .F. }, ;
      { "Invoice 3", Date() + 1, 0, .T. } }, aSave
   LOCAL nErrorCode := 0

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

   ft_SaveArr( aArray, "invoice.dat", @nErrorCode )
   IF nErrorCode == 0
      CLS
      DispArray( aArray )
      aSave := ft_RestArr( "invoice.dat", @nErrorCode )
      IF nErrorCode == 0
         DispArray( aSave )
      ELSE
         ? "Error restoring array"
      ENDIF
   ELSE
      ? "Error writing array"
   ENDIF

   RETURN

FUNCTION DispArray( aTest )

   LOCAL nk

   FOR nk := 1 TO Len( aTest )
      ? aTest[ nk, 1 ]
      ?? "  "
      ?? DToC( aTest[ nk, 2 ] )
      ?? "  "
      ?? Str( aTest[ nk, 3 ] )
      ?? "  "
      ?? iif( aTest[ nk, 4 ], "true", "false" )
   NEXT

   RETURN NIL


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

[User] Implement this Harbour module: Harbour contribution module 'hbwin' (Windows API wrapper functions): contrib/hbwin/win_os.prg. Provides functions: win_osNetRegOk, win_osNetVRedirOk. This file provides platform-specific functionality

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

FUNCTION win_osNetRegOk( lSetIt, lDoVista )

   LOCAL bRetVal := .T.
   LOCAL cKeySrv
   LOCAL cKeyWks

   hb_default( @lSetIt, .F. )

   IF ! hb_defaultValue( lDoVista, .T. ) .AND. hb_osIsWinVista()

   ELSEIF hb_osIsWin9x()
      bRetVal := win_regQuery( WIN_HKEY_LOCAL_MACHINE, "System\CurrentControlSet\Services\VxD\VREDIR", "DiscardCacheOnOpen", 1, lSetIt )
   ELSE
      cKeySrv := "System\CurrentControlSet\Services\LanmanServer\Parameters"
      cKeyWks := "System\CurrentControlSet\Services\LanmanWorkStation\Parameters"

      IF lSetIt
         lSetIt := ! hb_osIsWinNT() .OR. wapi_IsUserAnAdmin()
      ENDIF

      bRetVal := bRetVal .AND. win_regQuery( WIN_HKEY_LOCAL_MACHINE, cKeySrv, "CachedOpenLimit", 0, lSetIt )
      bRetVal := bRetVal .AND. win_regQuery( WIN_HKEY_LOCAL_MACHINE, cKeySrv, "EnableOpLocks", 0, lSetIt )
      bRetVal := bRetVal .AND. win_regQuery( WIN_HKEY_LOCAL_MACHINE, cKeySrv, "EnableOpLockForceClose", 1, lSetIt )
      bRetVal := bRetVal .AND. win_regQuery( WIN_HKEY_LOCAL_MACHINE, cKeySrv, "SharingViolationDelay", 0, lSetIt )
      bRetVal := bRetVal .AND. win_regQuery( WIN_HKEY_LOCAL_MACHINE, cKeySrv, "SharingViolationRetries", 0, lSetIt )

      bRetVal := bRetVal .AND. win_regQuery( WIN_HKEY_LOCAL_MACHINE, cKeyWks, "UseOpportunisticLocking", 0, lSetIt )
      bRetVal := bRetVal .AND. win_regQuery( WIN_HKEY_LOCAL_MACHINE, cKeyWks, "EnableOpLocks", 0, lSetIt )
      bRetVal := bRetVal .AND. win_regQuery( WIN_HKEY_LOCAL_MACHINE, cKeyWks, "EnableOpLockForceClose", 1, lSetIt )
      bRetVal := bRetVal .AND. win_regQuery( WIN_HKEY_LOCAL_MACHINE, cKeyWks, "UtilizeNtCaching", 0, lSetIt )
      bRetVal := bRetVal .AND. win_regQuery( WIN_HKEY_LOCAL_MACHINE, cKeyWks, "UseLockReadUnlock", 0, lSetIt )

      IF hb_osIsWin7()

         bRetVal := bRetVal .AND. win_regQuery( WIN_HKEY_LOCAL_MACHINE, cKeySrv, "DisableLeasing", 1, lSetIt )
      ELSEIF hb_osIsWinVista()

         bRetVal := bRetVal .AND. win_regQuery( WIN_HKEY_LOCAL_MACHINE, cKeySrv, "SMB2", 0, lSetIt )
      ENDIF

      IF hb_osIsWinVista()
         bRetVal := bRetVal .AND. win_regQuery( WIN_HKEY_LOCAL_MACHINE, cKeyWks, "FileInfoCacheLifetime", 0, lSetIt )
         bRetVal := bRetVal .AND. win_regQuery( WIN_HKEY_LOCAL_MACHINE, cKeyWks, "FileNotFoundCacheLifetime", 0, lSetIt )
         bRetVal := bRetVal .AND. win_regQuery( WIN_HKEY_LOCAL_MACHINE, cKeyWks, "DirectoryCacheLifetime", 0, lSetIt )
      ENDIF

      IF hb_osIsWin2K()
         bRetVal := bRetVal .AND. win_regQuery( WIN_HKEY_LOCAL_MACHINE, "System\CurrentControlSet\Services\MRXSmb\Parameters", "OpLocksDisabled", 1, lSetIt )
      ENDIF
   ENDIF

   RETURN bRetVal

FUNCTION win_osNetVRedirOk(  nResult )

   LOCAL aFiles

   nResult := 0

   IF hb_osIsWin9x() .AND. ;
      ! Empty( aFiles := Directory( hb_GetEnv( "WINDIR", "C:\WINDOWS" ) + "\SYSTEM\VREDIR.VXD" ) )
      SWITCH aFiles[ 1 ][ F_SIZE ]
         CASE 156749
            IF aFiles[ 1 ][ F_TIME ] == "11:11:10"
               nResult := 1111
            ENDIF
            EXIT
         CASE 140343
            IF aFiles[ 1 ][ F_TIME ] == "09:50:00"
               nResult := 950
            ENDIF
            EXIT
      ENDSWITCH
   ENDIF

   RETURN nResult == 0


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

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

Harbour test program: tests/warnings.prg. Provides 7 functions including: Test, Test2, Test3, SomeTest, nMyFunc. Contains procedures: Main, SOMEPROC, Main1. This test file tests specific function APIs

[Assistant]
#ifdef __HARBOUR__
   #pragma -es0
#else
   #translate AS ARRAY [OF <type>] =>
   #translate AS STRING =>
   #translate AS CLASS <ClassName> =>
   #translate AS NUMERIC =>
   #translate AS DATE =>
   #translate AS CODEBLOCK =>
   #translate AS OBJECT =>
   #translate AS LOGICAL =>
   #translate AS USUAL =>

   #command DECLARE <*x*> =>
#endif

DECLARE nMyFunc( cVar AS STRING, @nVar AS NUMERIC ) AS NUMERIC

DECLARE cOtherFunc( ) AS STRING

DECLARE cOtherFunc( @cVar as string, optional nVar as numeric, optional other  ) AS STRING

DECLARE Seconds() AS NUMERIC

DECLARE Int( n AS NUMERIC ) AS NUMERIC

DECLARE TEST() AS NUMERIC

DECLARE MyClass                              ;
        nMyFunc( nVal AS NUMERIC) AS NUMERIC

DECLARE MyClass                              ;
        nMyFunc( nVal AS NUMERIC ) AS NUMERIC ;
        nMyFunc( nVal AS NUMERIC ) AS NUMERIC ;
        cMyData    ;
        aInstances AS Array Of Object MyClass ;
        oNext( oInstance AS Class MyClass ) As Class MyClass

DECLARE OtherClass                              ;
        nMyFunc( nVal AS NUMERIC ) AS NUMERIC ;
        nMyFunc( nVal AS NUMERIC ) AS NUMERIC ;
        cMyData    ;
        aInstances AS Array Of Object MyClass ;
        oNext( oInstance AS Class OtherClass ) As Class MyClass

FIELD a AS STRING
FIELD b AS STRING

MEMVAR Var1 AS STRING

STATIC s_lGlobal AS LOGICAL

PROCEDURE Main( optional )

   STATIC lStatic := 0, oMyObj As Class WrongClass

   LOCAL cVar AS STRING := [declare function]

   LOCAL a As STRING, oB AS Class MyClass, c AS STRING, oD AS Class OtherClass

   FIELD b AS NUMERIC

   MEMVAR Var1 AS NUMERIC

   PRIVATE TEST AS STRING

   USE TEMP

   oMyObj:MyMethod( 2, 3, 4 )

   a := b:nMyFunc( 2, 3 )
   a := b:nMyFunc( 2 )

   a := oB:oNext( 1 ):cMyData
   a := oB:oNext( c ):cMyData2
   a := oB:oNext( d ):cMyData
   a := oB:oNext( oD ):cMyData

   a := oB:aInstances[ 1 ]:oNext:cMyData2
   a := oB:aInstances[ 1 ]:oNext:cMyData

   x := cOtherFunc( "A" )
   x := cOtherFunc( @Test )
   x := cOtherFunc( "A", "A", "A" )

   M->TEST := "TEST"

   a := "A"

   oB := "a"

   IF lStatic
      Var1 := .F.
   ENDIF

   IF s_lGlobal
      Var1 := .T.
   ENDIF

   RETURN

PROCEDURE SOMEPROC()

   PRIVATE TEST AS NUMERIC

   M->TEST := 1

   FOR M->TEST := 1 TO M->TEST + 10
      ? "Correct warnings for FOR/NEXT"
   NEXT

   REPLACE a WITH 1

   M->public_var := 0

   b := 0

   Var1 := 1

   IF s_lGlobal == 0
      ? "s_lGlobal is NOT Numeric"
   ENDIF

   RETURN

PROCEDURE Main1()

   PRIVATE OTHER, TEST AS STRING

   Var1 := M->TEST

   Var2 := Test()

   ? Var1 + 2

   M->TEST := 1
   M->TEST := "No Warning"

   Test[ 1 ][ 2 ] := "Correct warning"

   RETURN

FUNCTION Test()
   RETURN .T.

FUNCTION Test2()
   Local n As Numeric, lVar AS LOGICAL

   n := iif( lVar, "A", 3 )
   n := 2
   n := "a"
   n := Seconds() + 2
   n := Int( Seconds() + 2 )

   RETURN NIL

FUNCTION Test3()

   LOCAL n AS NUMERIC, cVar AS STRING, a[5,5,5] AS ARRAY OF STRING

   cVar := a[1]

   n := &SomeFun( 2, 3 )

   n := ExtFun()

   cVar := cOtherFunc( 3 )

   n := nMyFunc( a, cVar ) + 3

   n := &(cVar)

   n := "&SomeVar"

   n := &Var.1

   n := V&SomeVar.1

   n[ 2 ] := 4

   cVar := {| nb AS NUMERIC, cb AS STRING, db AS DATE | n := .F., nb := "A", cb := 1, db := 0, n := "wrong type", 0 }

   ? "This is a compiler test."

   n := "C is Wrong Type for n"

   n := { 1, 2, 3 }

   n := a

   iif( n, 2, 3 )

   RETURN NIL

FUNCTION SomeTest( lVar AS LOGICAL )

   LOCAL nVar AS NUMERIC, cVar AS STRING, lVar2 AS LOGICAL, nNoType := 3
   PRIVATE cMemVar1 AS STRING

   nVar := .T.

   nVar := 1

   nVar := "A"

   cVar := 2

   cVar := "B"

   cVar := 2

   lVar := .T.

   lVar := nNoType

   cVar := nVar

   M->cMemVar1 := 2

   NondDeclared := 2

   cVar := {| n AS NUMERIC, c AS STRING, d AS DATE | n := nMyFunc( n, c, d ), c := 2  }

   nVar := 8 + cVar

   IF 1

   ENDIF

   RETURN NIL

FUNCTION nMyFunc( cVar AS STRING, nVar AS NUMERIC )

   nVar := Val( cVar )

   RETURN nVar + 1

FUNCTION cOtherFunc( )
   RETURN "Hello"

FUNCTION ExtFun()
   RETURN 1


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

[User] Create Harbour preprocessor definitions: Harbour header file: include/hbinkey.ch. Defines 10 constants including: HB_HBINKEY_CH_, HB_INKEY_NONE, HB_INKEY_ALT, HB_INKEY_CTRL, HB_INKEY_SHIFT. Defines keyboard input constants

[Assistant]
#ifndef HB_HBINKEY_CH_
#define HB_HBINKEY_CH_

#define HB_INKEY_NONE                   256
#define HB_INKEY_ALT                    384
#define HB_INKEY_CTRL                   512
#define HB_INKEY_SHIFT                  640
#define HB_INKEY_ENHANCED               768

#define HB_K_ALT_A                      414
#define HB_K_ALT_B                      432
#define HB_K_ALT_C                      430
#define HB_K_ALT_D                      416
#define HB_K_ALT_E                      402
#define HB_K_ALT_F                      417
#define HB_K_ALT_G                      418
#define HB_K_ALT_H                      419
#define HB_K_ALT_I                      407
#define HB_K_ALT_J                      420
#define HB_K_ALT_K                      421
#define HB_K_ALT_L                      422
#define HB_K_ALT_M                      434
#define HB_K_ALT_N                      433
#define HB_K_ALT_O                      408
#define HB_K_ALT_P                      409
#define HB_K_ALT_Q                      400
#define HB_K_ALT_R                      403
#define HB_K_ALT_S                      415
#define HB_K_ALT_T                      404
#define HB_K_ALT_U                      406
#define HB_K_ALT_V                      431
#define HB_K_ALT_W                      401
#define HB_K_ALT_X                      429
#define HB_K_ALT_Y                      405
#define HB_K_ALT_Z                      428

#define HB_K_CTRL_A                     1
#define HB_K_CTRL_B                     2
#define HB_K_CTRL_C                     3
#define HB_K_CTRL_D                     4
#define HB_K_CTRL_E                     5
#define HB_K_CTRL_F                     6
#define HB_K_CTRL_G                     7
#define HB_K_CTRL_H                     8
#define HB_K_CTRL_I                     9
#define HB_K_CTRL_J                     10
#define HB_K_CTRL_K                     11
#define HB_K_CTRL_L                     12
#define HB_K_CTRL_M                     13
#define HB_K_CTRL_N                     14
#define HB_K_CTRL_O                     15
#define HB_K_CTRL_P                     16
#define HB_K_CTRL_Q                     17
#define HB_K_CTRL_R                     18
#define HB_K_CTRL_S                     19
#define HB_K_CTRL_T                     20
#define HB_K_CTRL_U                     21
#define HB_K_CTRL_V                     22
#define HB_K_CTRL_W                     23
#define HB_K_CTRL_X                     24
#define HB_K_CTRL_Y                     25
#define HB_K_CTRL_Z                     26
#define HB_K_CTRL_LEFT_SQUARE           27
#define HB_K_CTRL_BACK_SLASH            28
#define HB_K_CTRL_RIGHT_SQUARE          29
#define HB_K_CTRL_HAT                   30
#define HB_K_CTRL_UNDERSCORE            31

#define HB_K_SPACE                      32

#define HB_K_ALT_1                      386
#define HB_K_ALT_2                      387
#define HB_K_ALT_3                      388
#define HB_K_ALT_4                      389
#define HB_K_ALT_5                      390
#define HB_K_ALT_6                      391
#define HB_K_ALT_7                      392
#define HB_K_ALT_8                      393
#define HB_K_ALT_9                      394
#define HB_K_ALT_0                      395
#define HB_K_ALT_EQUAL                  397

#define HB_K_CTRL_1                     514
#define HB_K_CTRL_2                     515
#define HB_K_CTRL_3                     516
#define HB_K_CTRL_4                     517
#define HB_K_CTRL_5                     518
#define HB_K_CTRL_6                     519
#define HB_K_CTRL_7                     520
#define HB_K_CTRL_8                     521
#define HB_K_CTRL_9                     522
#define HB_K_CTRL_0                     523
#define HB_K_CTRL_COLON                 551
#define HB_K_CTRL_SEMI_COLON            551
#define HB_K_CTRL_COMMA                 563
#define HB_K_CTRL_PERIOD                564
#define HB_K_CTRL_SLASH                 565

#define HB_K_CTRL_MINUS                 524
#define HB_K_CTRL_EQUALS                525
#define HB_K_CTRL_PLUS                  525
#define HB_K_CTRL_LEFT_CURLY            538
#define HB_K_CTRL_RIGHT_CURLY           539

#define HB_K_BACKSPACE                  8
#define HB_K_ALT_BACKSPACE              398
#define HB_K_CTRL_BACKSPACE             127
#define HB_K_SHIFT_BACKSPACE

#define HB_K_ENTER                      13
#define HB_K_ALT_ENTER                  412
#define HB_K_CTRL_ENTER                 10
#define HB_K_SHIFT_ENTER                668

#define HB_K_ESC                        27
#define HB_K_ALT_ESC                    385
#define HB_K_CTRL_ESC                   513
#define HB_K_SHIFT_ESC                  641

#define HB_K_TAB                        9
#define HB_K_ALT_TAB                    399
#define HB_K_CTRL_TAB                   527
#define HB_K_SHIFT_TAB                  655

#define HB_K_F1                         315
#define HB_K_F2                         316
#define HB_K_F3                         317
#define HB_K_F4                         318
#define HB_K_F5                         319
#define HB_K_F6                         320
#define HB_K_F7                         321
#define HB_K_F8                         322
#define HB_K_F9                         323
#define HB_K_F10                        324
#define HB_K_F11                        343
#define HB_K_F12                        344

#define HB_K_ALT_F1                     443
#define HB_K_ALT_F2                     444
#define HB_K_ALT_F3                     445
#define HB_K_ALT_F4                     446
#define HB_K_ALT_F5                     447
#define HB_K_ALT_F6                     448
#define HB_K_ALT_F7                     449
#define HB_K_ALT_F8                     450
#define HB_K_ALT_F9                     451
#define HB_K_ALT_F10                    452
#define HB_K_ALT_F11                    471
#define HB_K_ALT_F12                    472

#define HB_K_CTRL_F1                    571
#define HB_K_CTRL_F2                    572
#define HB_K_CTRL_F3                    573
#define HB_K_CTRL_F4                    574
#define HB_K_CTRL_F5                    575
#define HB_K_CTRL_F6                    576
#define HB_K_CTRL_F7                    577
#define HB_K_CTRL_F8                    578
#define HB_K_CTRL_F9                    579
#define HB_K_CTRL_F10                   580
#define HB_K_CTRL_F11                   599
#define HB_K_CTRL_F12                   600

#define HB_K_SHIFT_F1                   699
#define HB_K_SHIFT_F2                   700
#define HB_K_SHIFT_F3                   701
#define HB_K_SHIFT_F4                   702
#define HB_K_SHIFT_F5                   703
#define HB_K_SHIFT_F6                   704
#define HB_K_SHIFT_F7                   705
#define HB_K_SHIFT_F8                   706
#define HB_K_SHIFT_F9                   707
#define HB_K_SHIFT_F10                  708
#define HB_K_SHIFT_F11                  727
#define HB_K_SHIFT_F12                  728

#define HB_KP_MINUS                     330
#define HB_KP_ALT_MINUS                 458
#define HB_KP_CTRL_MINUS                586
#define HB_KP_SHIFT_MINUS               714

#define HB_KP_PLUS                      334
#define HB_KP_ALT_PLUS                  462
#define HB_KP_CTRL_PLUS                 590
#define HB_KP_SHIFT_PLUS                718

#define HB_KP_SLASH                     1077
#define HB_KP_ALT_SLASH                 1205
#define HB_KP_CTRL_SLASH                1333
#define HB_KP_SHIFT_SLASH               1461

#define HB_KP_STAR                      311
#define HB_KP_ALT_STAR                  439
#define HB_KP_CTRL_STAR                 567
#define HB_KP_SHIFT_STAR                695

#define HB_KP_ENTER                     1052
#define HB_KP_ALT_ENTER                 1180
#define HB_KP_CTRL_ENTER                1308
#define HB_KP_SHIFT_ENTER               1436

#define HB_KP_HOME                      327
#define HB_KP_UP                        328
#define HB_KP_PG_UP                     329


[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/addascii.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 AddAscii()"
   ?
   ? "Simple tests:"
   ? '  This should be "1000": ' + AddAscii( "0000", 1, 1 )
   ? '  This should be "0001": ' + AddAscii( "0000", 1 )
   ? '  This should be "BAAA": ' + AddAscii( "AAAA", -255, 1 )
   ? '  This should be "AAAB": ' + AddAscii( "AAAA", -255 )

   ?
   ? "CSetRef() tests:"
   ? "  current csetref setting(should be .F.)...................:", CSetRef()
   ? "  return value of AddAscii( 'A', 1, 1 ) call(should be 'B'):", AddAscii( "A", 1, 1 )
   ? "  value of cStr............................................:", cStr
   ? "  return value of AddAscii( cStr, 1, 1 ) call..............:", AddAscii( cStr, 1, 1 )
   ? "  value of cStr is now.....................................:", cStr
   ? "  return value of AddAscii( @cStr, 1, 1 ) call.............:", AddAscii( @cStr, 1, 1 )
   ? "  value of cStr is now.....................................:", cStr
   ? "  return value of AddAscii( @cStr, -1, 1 ) call............:", AddAscii( @cStr, -1, 1 )
   ? "  value of cStr is now.....................................:", cStr
   ? "  return value of CSetRef( .T. )...........................:", CSetRef( .T. )
   ? "  return value of AddAscii( 'A', 1, 1 ) call...............:", AddAscii( "A", 1, 1 )
   ? "  return value of AddAscii( cStr, 1, 1 ) call..............:", AddAscii( cStr, 1, 1 )
   ? "  value of cStr is now.....................................:", cStr
   ? "  return value of AddAscii( @cStr, 1, 1 ) call.............:", AddAscii( @cStr, 1, 1 )
   ? "  value of cStr is now.....................................:", cStr
   ? "  return value of AddAscii( @cStr, -1, 1 ) call............:", AddAscii( @cStr, -1, 1 )
   ? "  value of cStr is now.....................................:", cStr
   ? "  return value of CSetRef( .F. )...........................:", CSetRef( .F. )

   ?
   ? "Carryover tests(new 4th parameter):"
   ? "  return value of AddAscii( 'AAAA', 1, 2, .T. ) call('ABAA')...:", AddAscii( "AAAA", 1, 2, .T. )
   ? "  return value of AddAscii( 'AAAA', 257, 2, .T. ) call('BBAA').:", AddAscii( "AAAA", 257, 2, .T. )
   ? "  return value of AddAscii( 'AAAA', 257, 2, .F. ) call('ABAA').:", AddAscii( "AAAA", 257, 2, .F. )
   ? "  return value of AddAscii( 'AAAA', 258,, .T. ) call('AABC')...:", AddAscii( "AAAA", 258,, .T. )
   ? "  return value of AddAscii( 'ABBA', -257, 3, .T. ) call('AAAA'):", AddAscii( "ABBA", -257, 3, .T. )

   ? "End test of AddAscii()"
   ?

   ctexit()

   RETURN


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

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

Harbour test program: tests/begin.prg. Contains 5 procedures. This test file tests specific function APIs

[Assistant]
MEMVAR m_oMemvar
MEMVAR m_cPrivate

PROCEDURE Main()

   LOCAL oLocal
   PRIVATE m_cPrivate := "private value in MAIN"

   BEGIN SEQUENCE
      ? " Inside SEQUENCE 1"
      ? "  No break issued...."
   RECOVER
      ? "  Recovering in 1 ..."
   END SEQUENCE
   ? "After SEQUENCE 1"

   BEGIN SEQUENCE
      ? " Inside SEQUENCE 2"
      Break( "VALUE 2" )
   RECOVER USING oLocal
      ? "  Recovering in 2 using....", oLocal
   END SEQUENCE
   ? "After SEQUENCE 2"

   BEGIN SEQUENCE
      ? " Inside SEQUENCE 3"
      Break
   RECOVER USING oLocal
      ? "  Recovering in 3 using....", oLocal
   END SEQUENCE
   ? "After SEQUENCE 3"

   BEGIN SEQUENCE
      ? " Inside SEQUENCE 4"
      Break
      ? "  Recovering in 4 using....", oLocal
   END SEQUENCE
   ? "After SEQUENCE 4"

   BEGIN SEQUENCE
      ? " Inside SEQUENCE 5"
      Break1()
      ? "  Recovering in 5 using....", oLocal
   END SEQUENCE
   ? "After SEQUENCE 5"

   BEGIN SEQUENCE
      ? " Inside SEQUENCE 6"
      Break1()
   RECOVER USING m_oMemvar
      ? "  Recovering in 6 using... ", m_oMemvar
   END SEQUENCE
   ? "After SEQUENCE 6"

   BEGIN SEQUENCE
      ? " Inside SEQUENCE 7"
      Break2()
   RECOVER USING m_oMemvar
      ? "  Recovering in 7 using... ", m_oMemvar
   END SEQUENCE
   ? "After SEQUENCE 7"

   ? M->m_cPrivate
   Break( "exit from MAIN" )
   ? "This text will be not printed"

   RETURN

PROCEDURE Break1()

   PRIVATE m_cPrivate := "VALUE from Break1"

   BREAK M->m_cPrivate

PROCEDURE Break2()

   BEGIN SEQUENCE
      ? " Inside SEQUENCE 8"
      Break3()
   RECOVER USING m_oMemvar
      ? "  Recovering in 8 using...", Eval( m_oMemvar, " eval in 8" )
      Break( "BREAK from recovery code" )
   END SEQUENCE
   ? "After SEQUENCE 8"

   RETURN

PROCEDURE Break3()

   STATIC s_oStatic

   BEGIN SEQUENCE
      ? " Inside SEQUENCE 9"

      BEGIN SEQUENCE
         ? " Inside SEQUENCE 10"
         Break( "value from nested SEQUENCE 10" )
      RECOVER USING s_oStatic
         ? "  Recovering in 10 using...", s_oStatic
      END SEQUENCE
      ? "After SEQUENCE 10"

      Break4( " and parameter" )

   RECOVER USING m_oMemvar
      ? "  Recovering in 9 using...", Eval( m_oMemvar, " eval in 9" )
      Break( m_oMemvar )
   END SEQUENCE
   ? "After SEQUENCE 9"

   RETURN

PROCEDURE Break4( cValue )

   LOCAL oLocal := " detached Break4 "

   Break( {| x | oLocal + x + cValue } )


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

[User] Create Harbour preprocessor definitions: Harbour contribution module 'hbct' (CA-Tools compatibility library): contrib/hbct/tests/tab.prg. Contains procedures: Main. This file provides legacy compatibility functions

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

PROCEDURE Main()

   LOCAL cStr, nLen

   ctinit()

   ? "Begin test of TabExpand()"
   ?

   ? "Simple tests:"
   ? '  TabExpand( "-" + Chr( 9 ) + "!" )            == "-       !" ? -> "' + TabExpand( "-" + Chr( 9 ) + "!" )            + '"'
   ? '  TabExpand( "----" + Chr( 9 ) + "!" )         == "----    !" ? -> "' + TabExpand( "----" + Chr( 9 ) + "!" )         + '"'
   ? '  TabExpand( "-" + Chr( 9 ) + "!",, "+" )      == "-+++++++!" ? -> "' + TabExpand( "-" + Chr( 9 ) + "!",, "+" )      + '"'
   ? '  TabExpand( "-" + Chr( 9 ) + "!", 4 )         == "-   !"     ? -> "' + TabExpand( "-" + Chr( 9 ) + "!", 4 )         + '"'
   ? '  TabExpand( "----" + Chr( 9 ) + "!", 8 )      == "----    !" ? -> "' + TabExpand( "----" + Chr( 9 ) + "!", 8 )      + '"'
   ? '  TabExpand( "----" + Chr( 9 ) + "!", 8, "+" ) == "----++++!" ? -> "' + TabExpand( "----" + Chr( 9 ) + "!", 8, "+" ) + '"'
   ?

   ? "Tests with newline characters: ^J == LF, ^M == CR"
   cStr := hb_eol()
   cStr := StrTran( cStr, Chr( 10 ), "^J" )
   cStr := StrTran( cStr, Chr( 13 ), "^M" )
   ? '  hb_eol() = "' + cStr + '"'
   cStr := TabExpand( "-" + Chr( 9 ) + "!" + hb_eol() + "----" + Chr( 9 ) + "!", , "+" )
   cStr := StrTran( cStr, Chr( 10 ), "^J" )
   cStr := StrTran( cStr, Chr( 13 ), "^M" )
   ? '  TabExpand( "-" + Chr( 9 ) + "!" + hb_eol() + "----" + Chr( 9 )+ "!",, "+" )'
   ? '     == "-+++++++!"+hb_eol()+"----++++!"  ? -> "' + cStr + '"'
   cStr := TabExpand( "-" + Chr( 9 ) + "!$$--" + hb_eol() + "--" + Chr( 9 ) + "!", , "+", "$" )
   cStr := StrTran( cStr, Chr( 10 ), "^J" )
   cStr := StrTran( cStr, Chr( 13 ), "^M" )
   ? '  TabExpand( "-" + Chr( 9 ) + "!$$--" + hb_eol() + "--" + Chr( 9 ) + "!",, "+", "$" )'
   nLen := Len( hb_eol() )
   ? '     == "-+++++++!$$--"+hb_eol()+"' + Replicate( "-", 4 - nLen ) + '++!"  ? -> "' + cStr + '"'
   ?

   ? "Tests with tab characters:"
   ? '  TabExpand( "-" + Chr( 9 ) + "-",, "+" ) == "-+++++++-" ? -> "' + TabExpand( "-" + Chr( 9 ) + "-",, "+" ) + '"'
   ? '  TabExpand( "-" + Chr( 9 ) + "-",, "+",, "-" )'
   ? '                                          == "++++++++^I+++++++" ? -> "' + StrTran( TabExpand( "-" + Chr( 9 ) + "-",, "+",, "-" ), Chr( 9 ), "^I" ) + '"'
   ?

   ? "End test of TabExpand()"
   ? "Press any key to continue with tests of TabPack()..."
   ?
   Inkey( 0 )

   ? "Begin test of TabPack()"
   ?

   ? "Simple tests: ^I == tab character"

   ? '  TabPack( "AAAAAAA*",, "*" )   == "AAAAAAA*"  ? -> "' + StrTran( TabPack( "AAAAAAA*",, "*" ), Chr( 9 ), "^I" )  + '"'
   ? '  TabPack( "AAAAA***",, "*" )   == "AAAAA^I"   ? -> "' + StrTran( TabPack( "AAAAA***",, "*" ), Chr( 9 ), "^I" )  + '"'
   ? '  TabPack( "AAAAA*****",, "*" ) == "AAAAA^I**" ? -> "' + StrTran( TabPack( "AAAAA*****",, "*" ), Chr( 9 ), "^I" ) + '"'
   ?

   ? "Tests with newline characters:"
   cStr := hb_eol()
   cStr := StrTran( cStr, Chr( 10 ), "^J" )
   cStr := StrTran( cStr, Chr( 13 ), "^M" )
   ? '  hb_eol() = "' + cStr + '"'

   cStr := "ABCD+" + hb_eol() + "++---+++++"
   cStr := TabPack( cStr, 4, "+" )
   cStr := StrTran( cStr, Chr( 10 ), "^J" )
   cStr := StrTran( cStr, Chr( 13 ), "^M" )
   cStr := StrTran( cStr, Chr( 9 ), "^I" )
   ? '  TabPack("ABCD+" + hb_eol() + "++---+++++", 4, "+")'
   ? '     == "ABCD+" + hb_eol() + "++---" + Chr( 9 ) + "++" ? -> "' + cStr + '"'

   ? "End test of TabPack()"
   ?

   ctexit()

   RETURN