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

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

Harbour source file: src/rdd/hbsix/sxcompat.prg. Provides 16 functions including: sxChar, sxNum, sxDate, sxLog, sx_Compress. This file implements core Record Driver Driver functionality

[Assistant]
#include "dbinfo.ch"
#include "dbstruct.ch"
#include "fileio.ch"
#include "ord.ch"
#include "hbsxdef.ch"

FUNCTION sxChar( nLen,  xKeyVal )

   SWITCH ValType( xKeyVal )
   CASE "C"
   CASE "M"
      EXIT
   CASE "N"
      xKeyVal := Str( xKeyVal )
      EXIT
   CASE "D"
      xKeyVal := DToS( xKeyVal )
      EXIT
   CASE "T"
      xKeyVal := hb_TToS( xKeyVal )
      EXIT
   CASE "L"
      xKeyVal := iif( xKeyVal, "T", "F" )
      EXIT
   OTHERWISE
      xKeyVal := iif( HB_ISNUMERIC( nLen ), "", Space( 10 ) )
      EXIT
   ENDSWITCH

   IF HB_ISNUMERIC( nLen )
      xKeyVal := PadR( LTrim( xKeyVal ), nLen )
   ENDIF

   RETURN xKeyVal

FUNCTION sxNum(  xKeyVal )

   SWITCH ValType( xKeyVal )
   CASE "N"
      EXIT
   CASE "C"
   CASE "M"
      xKeyVal := Val( xKeyVal )
      EXIT
   CASE "T"
   CASE "D"
      xKeyVal := xKeyVal - hb_SToD()
      EXIT
   CASE "L"
      xKeyVal := iif( xKeyVal, 1, 0 )
      EXIT
   OTHERWISE
      xKeyVal := 0.00
      EXIT
   ENDSWITCH

   RETURN xKeyVal

FUNCTION sxDate(  xKeyVal )

   SWITCH ValType( xKeyVal )
   CASE "D"
      EXIT
   CASE "T"
      xKeyVal := hb_TToD( xKeyVal )
      EXIT
   CASE "C"
   CASE "M"
      xKeyVal := CToD( xKeyVal )
      EXIT
   CASE "N"
      xKeyVal := hb_SToD() + xKeyVal
      EXIT
   OTHERWISE
      xKeyVal := hb_SToD()
      EXIT
   ENDSWITCH

   RETURN xKeyVal

FUNCTION sxLog(  xKeyVal )

   SWITCH ValType( xKeyVal )
   CASE "L"
      EXIT
   CASE "C"
   CASE "M"
      SWITCH xKeyVal
      CASE  "T";  CASE  "t";  CASE  "Y";  CASE  "y"
      CASE ".T."; CASE ".t."; CASE ".Y."; CASE ".y."
         xKeyVal := .T.
         EXIT
      OTHERWISE
         xKeyVal := .F.
         EXIT
      ENDSWITCH
      EXIT
   CASE "N"
      xKeyVal := xKeyVal != 0
      EXIT
   OTHERWISE
      xKeyVal := .F.
      EXIT
   ENDSWITCH

   RETURN xKeyVal

FUNCTION sx_Compress( xVal )

   LOCAL xRetVal

   SWITCH ValType( xVal )
   CASE "C"
   CASE "M"
      RETURN _sx_StrCompress( xVal )
   CASE "A"
      xRetVal := Array( Len( xVal ) )
      AEval( xVal, {| x, i | xRetVal[ i ] := sx_Compress( x ) } )
      RETURN xRetVal
   ENDSWITCH

   RETURN xVal

FUNCTION sx_Decompress( xVal )

   LOCAL xRetVal

   SWITCH ValType( xVal )
   CASE "C"
   CASE "M"
      RETURN _sx_StrDecompress( xVal )
   CASE "A"
      xRetVal := Array( Len( xVal ) )
      AEval( xVal, {| x, i | xRetVal[ i ] := sx_Decompress( x ) } )
      RETURN xRetVal
   ENDSWITCH

   RETURN xVal

FUNCTION sx_TagInfo( cIndex )

   LOCAL aInfo, nOrds, nFirst, i

   IF Used() .AND. ( nOrds := ordCount( cIndex ) ) > 0
      aInfo := Array( nOrds, 6 )
      IF HB_ISSTRING( cIndex )
         nFirst := dbOrderInfo( DBOI_BAGORDER, cIndex )
         nOrds += nFirst - 1
      ELSE
         nFirst := 1
      ENDIF
      FOR i := nFirst TO nOrds
         aInfo[ i ][ 1 ] := ordName( i )
         aInfo[ i ][ 2 ] := ordKey( i )
         aInfo[ i ][ 3 ] := ordFor( i )
         aInfo[ i ][ 4 ] := ordIsUnique( i )
         aInfo[ i ][ 5 ] := ordDescend( i )
         aInfo[ i ][ 6 ] := ordCustom( i )
      NEXT
      RETURN aInfo
   ENDIF

   RETURN {}

FUNCTION sx_TagCount( xIndex )

   LOCAL nTags := 0, cIndex, nOrder

   IF Used()
      DO CASE
      CASE HB_ISNUMERIC( xIndex )
         IF ( nOrder := sx_TagOrder( 1, xIndex ) ) != 0
            cIndex := dbOrderInfo( DBOI_FULLPATH,, nOrder )
         ENDIF
      CASE HB_ISSTRING( xIndex ) .AND. ! Empty( xIndex )
         cIndex := xIndex
      OTHERWISE
         cIndex := dbOrderInfo( DBOI_FULLPATH )
      ENDCASE
      IF ! Empty( cIndex )
         nTags := ordCount( cIndex )
      ENDIF
   ENDIF

   RETURN nTags

FUNCTION sx_Tags( xIndex )

   LOCAL aTagNames := {}, nOrder, nTags

   IF Used()
      DO CASE
      CASE HB_ISNUMERIC( xIndex )
         nOrder := sx_TagOrder( 1, xIndex )
      CASE HB_ISSTRING( xIndex ) .AND. ! Empty( xIndex )
         nOrder := dbOrderInfo( DBOI_BAGORDER, xIndex )
      OTHERWISE
         nOrder := ordNumber()
      ENDCASE
      IF nOrder != 0
         nTags := ordCount( dbOrderInfo( DBOI_FULLPATH,, nOrder ) )
         DO WHILE --nTags >= 0
            AAdd( aTagNames, ordName( nOrder++ ) )
         ENDDO
      ENDIF
   ENDIF

   RETURN aTagNames

FUNCTION sx_SetTag( xTag, xIndex )

   LOCAL lRet := .F., nOrder := 0, nOldOrd, cIndex

   IF Used() .AND. ValType( xTag ) $ "CN"
      IF HB_ISNUMERIC( xTag )
         IF Empty( xIndex ) .OR. ! ValType( xIndex ) $ "CN"
            nOrder := xTag
         ELSEIF HB_ISSTRING( xIndex )
            IF xTag >= 1 .AND. xTag <= ordCount( xIndex )
               nOrder := dbOrderInfo( DBOI_BAGORDER, xIndex ) + xTag - 1
            ENDIF
         ELSE
            nOrder := sx_TagOrder( xTag, xIndex )
         ENDIF
      ELSE
         IF Empty( xIndex ) .OR. ! ValType( xIndex ) $ "CN"
            nOrder := ordNumber( xTag )
         ELSEIF HB_ISSTRING( xIndex )
            nOrder := sx_TagOrder( xTag, xIndex )
         ELSE
            nOrder := sx_TagOrder( 1, xIndex )
            IF nOrder != 0
               cIndex := dbOrderInfo( DBOI_FULLPATH,, nOrder )
               IF Empty( cIndex )
                  nOrder := 0
               ELSE
                  nOrder := sx_TagOrder( xTag, cIndex )
               ENDIF
            ENDIF
         ENDIF
      ENDIF
      IF nOrder != 0
         nOldOrd := ordNumber()
         ordSetFocus( nOrder )
         lRet := nOrder == ordNumber()
         IF ! lRet
            ordSetFocus( nOldOrd )
         ENDIF
      ELSEIF Empty( xTag )
         ordSetFocus( 0 )
         lRet := .T.
      ENDIF
   ENDIF

   RETURN lRet

FUNCTION sx_KillTag( xTag, xIndex )

   LOCAL lRet := .F., nOrder, cIndex

   IF HB_ISLOGICAL( xTag )
      IF xTag
         DO CASE
         CASE Empty( xIndex )
            cIndex := sx_IndexName()
         CASE HB_ISNUMERIC( xIndex )
            cIndex := sx_IndexName( 1, xIndex )
         CASE HB_ISSTRING( xIndex )
            nOrder := dbOrderInfo( DBOI_BAGORDER, xIndex )
            IF nOrder != 0
               cIndex := dbOrderInfo( DBOI_FULLPATH,, nOrder )
            ENDIF
         ENDCASE
         IF ! Empty( cIndex )
            IF ordBagClear( cIndex )
               lRet := FErase( cIndex ) != F_ERROR
            ENDIF
         ENDIF
      ENDIF
   ELSE
      IF HB_ISNUMERIC( xTag )
         IF Empty( xIndex ) .OR. ! ValType( xIndex ) $ "CN"
            nOrder := xTag
         ELSEIF HB_ISSTRING( xIndex )
            IF xTag >= 1 .AND. xTag <= ordCount( xIndex )
               nOrder := dbOrderInfo( DBOI_BAGORDER, xIndex ) + xTag - 1
            ELSE
               nOrder := 0
            ENDIF
         ELSE
            nOrder := sx_TagOrder( xTag, xIndex )
         ENDIF
      ELSE
         IF Empty( xIndex ) .OR. ! ValType( xIndex ) $ "CN"
            nOrder := ordNumber( xTag )
         ELSEIF HB_ISSTRING( xIndex )
            nOrder := sx_TagOrder( xTag, xIndex )
         ELSE
            IF ( nOrder := sx_TagOrder( 1, xIndex ) ) != 0
               cIndex := dbOrderInfo( DBOI_FULLPATH,, nOrder )
               IF Empty( cIndex )
                  nOrder := 0
               ELSE
                  nOrder := sx_TagOrder( xTag, cIndex )
               ENDIF
            ENDIF
         ENDIF
      ENDIF
      IF nOrder != 0
         lRet := ordDestroy( nOrder )
      ENDIF
   ENDIF

   RETURN lRet

FUNCTION sx_FileOrder()
   RETURN dbOrderInfo( DBOI_BAGNUMBER )

FUNCTION sx_SetFileOrd( nIndex )
   RETURN iif( HB_ISNUMERIC( nIndex ), ;
      ordSetFocus( sx_TagOrder( 1, nIndex ) ), ;
      ordSetFocus() )

FUNCTION rdd_Count()
   RETURN Len( rddList() )

FUNCTION rdd_Name( nRDD )

   LOCAL aRDD

   IF HB_ISNUMERIC( nRDD ) .AND. nRDD >= 1
      aRDD := rddList()
      IF nRDD <= Len( aRDD )
         RETURN aRDD[ nRDD ]
      ENDIF
   ENDIF

   RETURN ""

FUNCTION rdd_Info( xID )

   LOCAL cRDD

   DO CASE
   CASE HB_ISNUMERIC( xID )
      IF ! Alias( xID ) == ""
         ( xID )->( rddName() )
      ENDIF
   CASE HB_ISSTRING( xID )
      cRDD := Upper( AllTrim( xID ) )


[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/altd.prg. Contains procedures: AltD. This file provides utility functions

[Assistant]
#define ALTD_DISABLE  0
#define ALTD_ENABLE   1

PROCEDURE AltD( nAction )

   IF PCount() == 0

      __dbgInvokeDebug( Set( _SET_DEBUG ) )

   ELSEIF HB_ISNUMERIC( nAction )

      SWITCH nAction
      CASE ALTD_DISABLE
         Set( _SET_DEBUG, .F. )
         EXIT
      CASE ALTD_ENABLE
         Set( _SET_DEBUG, .T. )
         EXIT
      ENDSWITCH

   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 a Harbour program with procedures: Main. Harbour contribution module 'hbgt' (): contrib/hbgt/tests/test.prg. Contains procedures: Main. This file provides utility functions

[Assistant]
#require "hbgt"
#require "hbtest"

PROCEDURE Main()

   HBTEST gt_AscPos( "Harbour", 1 )                                IS 72
   HBTEST gt_AtDiff( "This Is Harbour", "This Is Clipper" )        IS 9
   HBTEST gt_CharEven( "The_Power_Of_Harbour" )                    IS "h_oe_fHror"
   HBTEST gt_CharOdd( "The_Power_Of_Harbour" )                     IS "TePwrO_abu"
   HBTEST gt_ChrCount( "s", "she sells shells by the sea shore" )  IS 7
   HBTEST gt_ChrTotal( "sl", "she sells shells by the sea shore" ) IS 11
   HBTEST gt_CharMix( "CLIPPER", "harbour" )                       IS "ChLaIrPbPoEuRr"
   HBTEST gt_AsciiSum( "harbour" )                                 IS 755
   HBTEST gt_ChrFirst( "Ho", "the power of Harbour" )              IS 111
   HBTEST gt_StrCount( "the", "the cat sat on the mat" )           IS 2
   HBTEST gt_StrCSPN( "this is a test", "as " )                    IS 3
   HBTEST gt_StrCSPN( "this is a test", "elnjpq" )                 IS 11
   HBTEST gt_StrDiff( "the cat", "the rat" )                       IS "rat"
   HBTEST gt_StrExpand( "Harbour", 2, "-" )                        IS "H--a--r--b--o--u--r"
   HBTEST gt_StrLeft( "this is a test", "hsit " )                  IS 8
   HBTEST gt_StrPBRK( "this is a test", "sa " )                    IS "s is a test"
   HBTEST gt_StrRight( "this is a test", "teas " )                 IS 8

   RETURN


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

[User] Generate Harbour code for: Harbour contribution module 'hbodbc' (ODBC database connectivity): contrib/hbodbc/tests/todbc.prg. Contains procedures: Main. This file handles database operations

[Assistant]
#require "hbodbc"

PROCEDURE Main()

   LOCAL dsFunctions := TODBC():New( "DBQ=" + hb_FNameMerge( hb_DirBase(), "test.mdb" ) + ";Driver={Microsoft Access Driver (*.mdb)}" )

   LOCAL aOrders
   LOCAL nOp
   LOCAL i

   SET COLOR TO "W+/B"
   CLS

   DO WHILE .T.

      @  0,  0 SAY PadC( "- TODBC Demonstration -", MaxCol() + 1 ) COLOR "B/W"

      dsFunctions:SetSQL( "SELECT * FROM test" )
      dsFunctions:Open()

      @  3, 24 TO Len( dsFunctions:Fields ) + 4, 55

      aOrders := {}
      FOR i := 1 TO Len( dsFunctions:Fields )
         AAdd( aOrders, dsFunctions:Fields[ i ]:FieldName )
         @ i + 3, 25 PROMPT PadC( "ORDER BY " + aOrders[ i ], 30 )
      NEXT

      MENU TO nOp

      IF nOp == 0
         EXIT
      ENDIF

      dsFunctions:Close()

      dsFunctions:SetSQL( "SELECT * FROM test ORDER BY " + aOrders[ nOp ] )
      dsFunctions:Open()

      @ 14, 5 SAY " " + ;
         PadR( dsFunctions:FieldByName( "First" ):FieldName, 10 ) + "   " + ;
         PadR( dsFunctions:FieldByName( "Last" ):FieldName, 10 ) + "   " + ;
         PadR( dsFunctions:FieldByName( "Street" ):FieldName, 25 ) + "   " + ;
         PadR( dsFunctions:FieldByName( "City" ):FieldName, 40 ) ;
         COLOR "B/W"

      dsFunctions:Skip()

      DO WHILE ! dsFunctions:Eof()
         ? "      " + ;
            PadR( dsFunctions:FieldByName( "First" ):Value, 10 ), "|", ;
            PadR( dsFunctions:FieldByName( "Last" ):Value, 10 ), "|", ;
            PadR( dsFunctions:FieldByName( "Street" ):Value, 25 ), "|", ;
            PadR( dsFunctions:FieldByName( "City" ):Value, 40 )
         dsFunctions:Skip()
      ENDDO

      @ MaxRow(), 0
      @ MaxRow(), 1         SAY "Statement:" COLOR "GR+/B"
      @ MaxRow(), Col() + 1 SAY dsFunctions:cSQL

      dsFunctions:Close()

   ENDDO
   dsFunctions:Destroy()

   RETURN


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

[User] Implement this Harbour module: Harbour contribution module 'hbmisc' (Miscellaneous utility functions): contrib/hbmisc/tests/readfile.prg. Contains procedures: Main. This file provides utility functions

[Assistant]
#require "hbmisc"

PROCEDURE Main( cFile )

   LOCAL oFile := TFileRead():New( cFile )

   oFile:Open()
   IF oFile:Error()
      ? oFile:ErrorMsg( "FileRead:" )
   ELSE
      DO WHILE oFile:MoreToRead()
         ? oFile:ReadLine()
      ENDDO
      oFile:Close()
   ENDIF

   RETURN


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

[User] Generate Harbour code for: Harbour contribution module 'hbwin' (Windows API wrapper functions): contrib/hbwin/tests/mutexwin.prg. Contains procedures: Main. This file provides platform-specific functionality

[Assistant]
#require "hbwin"

STATIC s_hMutex

PROCEDURE Main()

   LOCAL cAppName

   hb_FNameSplit( hb_ProgName(), NIL, @cAppName )

   s_hMutex := wapi_CreateMutex( NIL, NIL, cAppName )
   IF ! Empty( s_hMutex ) .AND. wapi_GetLastError() == 0
      ? cAppName, "=> Hello World! OK."
   ELSE
      ? cAppName, "=> Application is running. Error", wapi_GetLastError()
   ENDIF

   WAIT

   RETURN


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

[User] Define Harbour macros and constants: Header file for contribution module 'xhb' (Extended Harbour functions): contrib/xhb/hbxml.ch. Defines 10 constants including: HB_XML_CH, HBXML_STYLE_NOINDENT, HBXML_STYLE_INDENT, HBXML_STYLE_TAB, HBXML_STYLE_THREESPACES. Defines Harbour internal constants and macros

[Assistant]
#ifndef HB_XML_CH
#define HB_XML_CH

#define HBXML_STYLE_NOINDENT      0
#define HBXML_STYLE_INDENT        1
#define HBXML_STYLE_TAB           2
#define HBXML_STYLE_THREESPACES   4
#define HBXML_STYLE_NOESCAPE      8
#define HBXML_STYLE_NONEWLINE     16

#define HBXML_STATUS_ERROR        0
#define HBXML_STATUS_OK           1
#define HBXML_STATUS_MORE         2
#define HBXML_STATUS_DONE         3
#define HBXML_STATUS_UNDEFINED    4
#define HBXML_STATUS_MALFORMED    5

#define HBXML_ERROR_NONE          0
#define HBXML_ERROR_IO            1
#define HBXML_ERROR_NOMEM         2
#define HBXML_ERROR_OUTCHAR       3
#define HBXML_ERROR_INVNODE       4
#define HBXML_ERROR_INVATT        5
#define HBXML_ERROR_MALFATT       6
#define HBXML_ERROR_INVCHAR       7
#define HBXML_ERROR_NAMETOOLONG   8
#define HBXML_ERROR_ATTRIBTOOLONG 9
#define HBXML_ERROR_VALATTOOLONG  10
#define HBXML_ERROR_UNCLOSED      11
#define HBXML_ERROR_UNCLOSEDENTITY   12
#define HBXML_ERROR_WRONGENTITY      13

#define HBXML_TYPE_TAG            0
#define HBXML_TYPE_COMMENT        1
#define HBXML_TYPE_PI             2
#define HBXML_TYPE_DIRECTIVE      3
#define HBXML_TYPE_DATA           4
#define HBXML_TYPE_CDATA          5
#define HBXML_TYPE_DOCUMENT       6

#endif


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

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

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

[Assistant]
REQUEST HB_LANG_HU
REQUEST HB_LANG_KO

PROCEDURE Main()

   ? "Prev:", hb_langSelect()
   ? hb_langName()
   ? NationMsg( 1 )
   ? CMonth( Date() )
   ? CDoW( Date() )
   ? "---------"

   ? "Prev:", hb_langSelect( "hu" )
   ? hb_langName()
   ? NationMsg( 1 )
   ? CMonth( Date() )
   ? CDoW( Date() )
   ? "---------"

   ? "Prev:", hb_langSelect( "ko" )
   ? hb_langName()
   ? NationMsg( 1 )
   ? CMonth( Date() )
   ? CDoW( Date() )
   ? "---------"

   ? "Prev:", hb_langSelect( "NOTHERE" )
   ? hb_langName()
   ? NationMsg( 1 )
   ? CMonth( Date() )
   ? CDoW( Date() )
   ? "---------"

   RETURN


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

[User] Implement this Harbour module: Harbour contribution module 'hbnf' (NanForum Toolkit - legacy Clipper compatibility functions): contrib/hbnf/nwsem.prg. Provides 8 functions including: ft_NWSemOpen, ft_NWSemEx, ft_NWSemWait, ft_NWSemSig, ft_NWSemClose. This file provides legacy compatibility functions

[Assistant]
#include "ftint86.ch"

#define WAIT_SEMAPHORE    2
#define SIGNAL_SEMAPHORE  3
#define CLOSE_SEMAPHORE   4

FUNCTION ft_NWSemOpen( cName, nInitVal, nHandle, nOpenCnt )

   LOCAL aRegs[ INT86_MAX_REGS ], cRequest, nRet

   __defaultNIL( @cName, "" )
   __defaultNIL( @nInitVal, 0 )
   __defaultNIL( @nHandle, 0 )
   __defaultNIL( @nOpenCnt, 0 )

   cName    := iif( hb_BLen( cName ) > 127, hb_BSubStr( cName, 1, 127 ), cName )
   cRequest := hb_BChar( Len( cName ) ) + cName

   aRegs[ AX ] := MAKEHI( 197 )
   aRegs[ DS ] := cRequest
   aRegs[ DX ] := REG_DS
   aRegs[ CX ] := nInitVal

   ft_int86( 33, aRegs )

   nHandle  := Bin2L( I2Bin( aRegs[ CX ] ) + I2Bin( aRegs[ DX ] ) )
   nOpenCnt := LOWBYTE( aRegs[ BX ] )

   nRet := LOWBYTE( aRegs[ AX ] )

   RETURN iif( nRet < 0, nRet + 256, nRet )

FUNCTION ft_NWSemEx( nHandle, nValue, nOpenCnt )

   LOCAL aRegs[ INT86_MAX_REGS ], nRet

   __defaultNIL( @nHandle, 0 )
   __defaultNIL( @nValue, 0 )
   __defaultNIL( @nOpenCnt, 0 )

   aRegs[ AX ] := MAKEHI( 197 ) + 1
   aRegs[ CX ] := Bin2I( hb_BSubStr( L2Bin( nHandle ), 1, 2 ) )
   aRegs[ DX ] := Bin2I( hb_BSubStr( L2Bin( nHandle ), 3, 2 ) )

   ft_int86( 33, aRegs )

   nValue   := aRegs[ CX ]
   nOpenCnt := LOWBYTE( aRegs[ DX ] )
   nRet     := LOWBYTE( aRegs[ AX ] )

   RETURN iif( nRet < 0, nRet + 256, nRet )

FUNCTION ft_NWSemWait( nHandle, nTimeout )

   RETURN _ftnwsem( WAIT_SEMAPHORE, nHandle, nTimeout )

FUNCTION ft_NWSemSig( nHandle )

   RETURN _ftnwsem( SIGNAL_SEMAPHORE, nHandle )

FUNCTION ft_NWSemClose( nHandle )

   RETURN _ftnwsem( CLOSE_SEMAPHORE, nHandle )

STATIC FUNCTION _ftnwsem( nOp, nHandle, nTimeout )

   LOCAL aRegs[ INT86_MAX_REGS ], nRet

   __defaultNIL( @nOp, SIGNAL_SEMAPHORE )
   __defaultNIL( @nHandle, 0 )
   __defaultNIL( @nTimeout, 0 )

   aRegs[ AX ] := MAKEHI( 197 ) + nOp
   aRegs[ CX ] := Bin2I( hb_BSubStr( L2Bin( nHandle ), 1, 2 ) )
   aRegs[ DX ] := Bin2I( hb_BSubStr( L2Bin( nHandle ), 3, 2 ) )
   aRegs[ BP ] := nTimeout

   ft_int86( 33, aRegs )
   nRet := LOWBYTE( aRegs[ AX ] )
   nRet := iif( nRet < 0, nRet + 256, nRet )

   RETURN nRet

FUNCTION ft_NWSemLock( cSemaphore, nHandle )

   LOCAL nOpenCnt := 0
   LOCAL nRc := ft_NWSemOpen( cSemaphore, 0, @nHandle, @nOpenCnt )

   IF nRc == 0
      IF nOpenCnt != 1
         ft_NWSemClose( nHandle )
      ENDIF
   ENDIF

   RETURN nOpenCnt == 1

FUNCTION ft_NWSemUnlock( nHandle )

   RETURN ft_NWSemClose( nHandle ) == 0


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

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

Harbour header file: include/hbpers.ch. Defines constants: HB_PERS_CH_. Declares 4 preprocessor commands. Defines Harbour internal constants and macros

[Assistant]
#ifndef HB_PERS_CH_
#define HB_PERS_CH_

#xcommand OBJECT <obj> AS <ClassName> => ;
          Self := hb_SetObject( Self, {|| <ClassName>():New() } )

#xcommand ENDOBJECT => Self := hb_EndObject()

#xcommand ARRAY <obj> LEN <nLen> => <obj> := Array( <nLen> )

#xcommand ENDARRAY =>

#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 'xhb' (Extended Harbour functions): contrib/xhb/hblognet.prg. Defines classes: HB_LogEmail, HB_LogInetPort. This file provides legacy compatibility functions

[Assistant]
#include "hbclass.ch"

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

CREATE CLASS HB_LogEmail INHERIT HB_LogChannel

   VAR cServer
   VAR cAddress        INIT "log@example.org"
   VAR cSubject        INIT "Log message from xHarbour application"
   VAR cSendTo
   VAR cHelo           INIT "xHarbour Email Logger"
   VAR nPort           INIT 25

   VAR cPrefix
   VAR cPostfix

   METHOD New( nLevel, cHelo, cServer, cSendTo, cSubject, cFrom )
   METHOD Open( cName )
   METHOD Close( cName )

   PROTECTED:
   METHOD Send( nStyle, cMessage, cName, nPriority )

   HIDDEN:
   METHOD GetOk( skCon )
   METHOD Prepare( nStyle, cMessage, cName, nPriority )

ENDCLASS

METHOD New( nLevel, cHelo, cServer, cSendTo, cSubject, cFrom ) CLASS HB_LogEmail

   LOCAL nPos

   ::Super:New( nLevel )

   nPos := At( ":", cServer )
   IF nPos > 0
      ::nPort := Val( SubStr( cServer, nPos + 1 ) )
      cServer := SubStr( cServer, 1, nPos - 1 )
   ENDIF

   ::cServer := cServer
   ::cSendTo := cSendTo

   IF cHelo != NIL
      ::cHelo := cHelo
   ENDIF

   IF cSubject != NIL
      ::cSubject := cSubject
   ENDIF

   IF cFrom != NIL
      ::cAddress := cFrom
   ENDIF

   RETURN Self

METHOD Open( cName ) CLASS HB_LogEmail

   HB_SYMBOL_UNUSED( cName )
   hb_inetInit()

   RETURN .T.

METHOD Close( cName ) CLASS HB_LogEmail

   HB_SYMBOL_UNUSED( cName )
   hb_inetCleanup()

   RETURN .T.

METHOD Send( nStyle, cMessage, cName, nPriority ) CLASS HB_LogEmail

   LOCAL skCon := hb_inetCreate()

   hb_inetTimeout( skCon, 10000 )

   hb_inetConnect( ::cServer, ::nPort, skCon )

   IF hb_inetErrorCode( skCon ) != 0 .OR. ! ::GetOk( skCon )
      RETURN .F.
   ENDIF

   hb_inetSendAll( skCon, "HELO " + ::cHelo + CRLF )
   IF ! ::GetOk( skCon )
      RETURN .F.
   ENDIF

   hb_inetSendAll( skCon, "MAIL FROM: <" + ::cAddress + ">" + CRLF )
   IF ! ::GetOk( skCon )
      RETURN .F.
   ENDIF

   hb_inetSendAll( skCon, "RCPT TO: <" + ::cSendTo + ">" + CRLF )
   IF ! ::GetOk( skCon )
      RETURN .F.
   ENDIF

   hb_inetSendAll( skCon, "DATA" + CRLF )
   IF ! ::GetOk( skCon )
      RETURN .F.
   ENDIF

   cMessage := ::Prepare( nStyle, cMessage, cName, nPriority )

   hb_inetSendAll( skCon,  cMessage + CRLF + "." + CRLF )
   IF ! ::GetOk( skCon )
      RETURN .F.
   ENDIF

   hb_inetSendAll( skCon, "QUIT" + CRLF )

   RETURN ::GetOk( skCon )

METHOD GetOk( skCon ) CLASS HB_LogEmail

   LOCAL nLen, cReply

   cReply := hb_inetRecvLine( skCon, @nLen, 128 )
   IF hb_inetErrorCode( skcon ) != 0 .OR. SubStr( cReply, 1, 1 ) == "5"
      RETURN .F.
   ENDIF

   RETURN .T.

METHOD Prepare( nStyle, cMessage, cName, nPriority ) CLASS HB_LogEmail

   LOCAL cPre

   cPre := "FROM: " + ::cAddress + CRLF + ;
      "TO: " + ::cSendTo + CRLF + ;
      "Subject:" + ::cSubject + CRLF + CRLF

   IF ! Empty( ::cPrefix )
      cPre += ::cPrefix + CRLF + CRLF
   ENDIF

   cPre += ::Format( nStyle, cMessage, cName, nPriority )

   IF ! Empty( ::cPostfix )
      cPre += CRLF + CRLF + ::cPostfix + CRLF
   ENDIF

   RETURN cPre

CREATE CLASS HB_LogInetPort FROM HB_LogChannel

   VAR nPort           INIT 7761
   VAR aListeners      INIT {}
   VAR skIn

   VAR bTerminate      INIT .F.
   VAR nThread
   VAR mtxBusy

   METHOD New( nLevel, nPort )
   METHOD Open( cName )
   METHOD Close( cName )

   PROTECTED:
   METHOD Send( nStyle, cMessage, cName, nPriority )

   HIDDEN:
   METHOD AcceptCon()

ENDCLASS

METHOD New( nLevel, nPort ) CLASS HB_LogInetPort

   ::Super:New( nLevel )

   IF nPort != NIL
      ::nPort := nPort
   ENDIF

   RETURN Self

METHOD Open( cName ) CLASS HB_LogInetPort

   HB_SYMBOL_UNUSED( cName )

   hb_inetInit()

   ::skIn := hb_inetServer( ::nPort )

   IF ::skIn == NIL
      RETURN .F.
   ENDIF

   ::mtxBusy := hb_mutexCreate()
   ::nThread := hb_threadStart( Self, "AcceptCon" )

   RETURN .T.

METHOD Close( cName ) CLASS HB_LogInetPort

   LOCAL sk

   HB_SYMBOL_UNUSED( cName )

   IF ::skIn == NIL
      RETURN .F.
   ENDIF

   ::bTerminate := .T.
   hb_threadJoin( ::nThread )

   hb_inetClose( ::skIn )

   DO WHILE Len( ::aListeners ) > 0
      sk := ATail( ::aListeners )
      ASize( ::aListeners, Len( ::aListeners ) - 1 )
      hb_inetClose( sk )
   ENDDO

   hb_inetCleanup()

   RETURN .T.

METHOD Send( nStyle, cMessage, cName, nPriority ) CLASS HB_LogInetPort

   LOCAL sk, nCount

   hb_mutexLock( ::mtxBusy )

   cMessage := ::Format( nStyle, cMessage, cName, nPriority )

   nCount := 1
   DO WHILE nCount <= Len( ::aListeners )
      sk := ::aListeners[ nCount ]
      hb_inetSendAll( sk, cMessage + CRLF )

      IF hb_inetErrorCode( sk ) != 0
         hb_ADel( ::aListeners, nCount, .T. )
      ELSE
         nCount++
      ENDIF
   ENDDO

   hb_mutexUnlock( ::mtxBusy )

   RETURN .T.

METHOD AcceptCon() CLASS HB_LogInetPort

   LOCAL sk

   hb_inetTimeout( ::skIn, 250 )
   DO WHILE ! ::bTerminate
      sk := hb_inetAccept( ::skIn )

      IF sk != NIL
         hb_mutexLock( ::mtxBusy )
         AAdd( ::aListeners, sk )
         hb_mutexUnlock( ::mtxBusy )
      ENDIF
   ENDDO

   RETURN .T.


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

[Assistant]
#require "rddsql"
#require "sddsqlt3"

#include "simpleio.ch"

REQUEST SDDSQLITE3, SQLMIX

PROCEDURE Main()

   LOCAL tmp

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

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

   rddSetDefault( "SQLMIX" )

   AEval( rddList(), {| X | QOut( X ) } )

   ? "-1-"
   ? "Connect:", tmp := rddInfo( RDDI_CONNECT, { "SQLITE3", hb_DirBase() + "test.sqlite3" } )
   IF tmp == 0
      ? "Unable connect to the server"
   ENDIF
   ? "-2-"
   ? "Use:", dbUseArea( .T., , "select * from t1", "t1" )
   ? "-3-"
   ? "Alias:", Alias()
   ? "-4-"
   ? "DB struct:", hb_ValToExp( dbStruct() )
   ? "-5-"
   FOR tmp := 1 TO FCount()
      ? FieldName( tmp ), hb_FieldType( tmp )
   NEXT
   ? "-6-"
   Inkey( 0 )
   Browse()

   INDEX ON FIELD->AGE TO age
   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] Implement this Harbour module: Harbour contribution module 'hbct' (CA-Tools compatibility library): contrib/hbct/scrmark.prg. Provides functions: ScreenMark. This file provides legacy compatibility functions

[Assistant]
FUNCTION ScreenMark( cSearch, xAttr, lUpperLower, lAll, cForward, cTrailing )

   LOCAL lFound := .F.
   LOCAL nCount := 1
   LOCAL nAt, nLen, nLast, nRow, nCol, nEnd, nCols
   LOCAL cScreen

   hb_default( @lUpperLower, .F. )
   hb_default( @lAll, .F. )

   IF ! HB_ISSTRING( cForward ) .OR. cForward == ""
      cForward := NIL
   ENDIF
   IF ! HB_ISSTRING( cTrailing ) .OR. cTrailing == ""
      cTrailing := NIL
   ENDIF

   nCols := MaxCol()
   cScreen := ScreenText( 0, 0, MaxRow(), nCols++ )
   nLen := Len( cSearch )
   nLast := Len( cScreen ) - nLen + 1

   IF ! lUpperLower
      cSearch := Upper( cSearch )
      cScreen := Upper( cScreen )
   ENDIF

   DO WHILE ( nAt := AtNum( cSearch, cScreen, nCount ) ) != 0

      IF ( nAt == 1 .OR. cForward == NIL .OR. ;
           SubStr( cScreen, nAt, 1 ) $ cForward ) .AND. ;
         ( nAt == nLast .OR. cTrailing == NIL .OR. ;
           SubStr( cScreen, nAt + nLen ) $ cTrailing )

         lFound := .T.
         --nAt
         nRow := Int( nAt / nCols )
         nCol := Int( nAt % nCols )
         nEnd := nCol + Len( cSearch ) - 1
         ColorWin( nRow, nCol, nRow, nEnd, xAttr )
         DO WHILE nEnd >= nCols
            nEnd -= nCols
            nCol := 0
            ++nRow
            ColorWin( nRow, nCol, nRow, nEnd, xAttr )
         ENDDO
         IF ! lAll
            EXIT
         ENDIF
      ENDIF
      nCount++
   ENDDO

   RETURN lFound


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

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

[Assistant]
#require "hbnf"

#include "inkey.ch"

PROCEDURE Main( cInFile )

   LOCAL nKey
   LOCAL nNColor   := 7
   LOCAL nHColor   := 15
   LOCAL nColSkip  := 5
   LOCAL nRMargin  := 132
   LOCAL cExitKeys := PadR( "AABBC", 12 )
   LOCAL lBrowse   := .F.
   LOCAL nStart    := 1
   LOCAL nBuffSize := 4096
   LOCAL GetList := {}

   LOCAL aExitKeys
   LOCAL tmp

   CLS

   hb_default( @cInFile, __FILE__ )

   cInFile := PadR( cInFile, 128 )

   @ 0,  0 SAY "ENTER FILENAME: "   GET cInFile   PICTURE "@S30"
   @ 1,  0 SAY "    FOREGROUND: "   GET nNColor   PICTURE "999"
   @ 2,  0 SAY "     HIGHLIGHT: "   GET nHColor   PICTURE "999"
   @ 3,  0 SAY "     EXIT KEYS: "   GET cEXitKeys
   @ 4,  0 SAY "   BUFFER SIZE: "   GET nBUffSize PICTURE "9999"
   @ 1, 40 SAY "COLUMN INCREMENT: " GET nCOlSkip  PICTURE "999"
   @ 2, 40 SAY "   MAX LINE SIZE: " GET nRMargin  PICTURE "999"
   @ 3, 40 SAY "     BROWSE MODE? " GET lBRowse   PICTURE "Y"

   READ

   aExitKeys := {}
   FOR EACH tmp IN cExitKeys
      AAdd( aExitKeys, hb_keyCode( tmp ) )
   NEXT

   AAdd( aExitKeys, K_F3 )

   @ 4, 9 TO 11, 71

   ft_DFSetup( AllTrim( cInFile ), 5, 10, 10, 70, nStart, ;
      nNColor, nHColor, aExitKeys, ;
      lBrowse, nColSkip, nRMargin, nBuffSize )

   nKey := ft_DispFile()

   ft_DFClose()

   @ 20, 0 SAY "Key pressed was: " + "[" + hb_keyChar( nKey ) + "] (" + hb_ntos( nKey ) + ")"

   RETURN


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

[User] Write a Harbour program with procedures: Main. Harbour contribution module 'hbct' (CA-Tools compatibility library): contrib/hbct/tests/token2.prg. Contains procedures: Main. This file provides legacy compatibility functions

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

PROCEDURE Main()

   LOCAL cStr1 := "A,BB,CCC,DDDD,EEEEE,FFFFFF"

   LOCAL cStr3 := "0123456789ABCDEFGHIJKLM"
   LOCAL cStr4 := "08:09:10:11:12"
   LOCAL cStr5 := "05:00+20:00+35:00+50:00"

   LOCAL cTE1, cTE2

   ctinit()

   ? "Begin test of incremental tokenizer function family"
   ?

   ? '  Incremental tokenizing the string "' + cStr1 + '"'
   ? '    TokenInit( @cStr1, ",", 1 ) == .T. ? ----> ' + LToC( TokenInit( @cStr1, ",", 1 ) )
   ? '    TokenNum() == 6 ? -----------------------> ' + Str( TokenNum() )
   ? '      TokenEnd() ? --------------------------> ' + LToC( TokenEnd() )
   WHILE ! TokenEnd()
      ? '      TokenNext(@cStr1)  -----------------> "' + TokenNext( @cStr1 ) + '"'
      ? '      TokenEnd() ? -----------------------> ' + LToC( TokenEnd() )
   ENDDO
   ?
   ? '    rewind with TokenInit() == .T. ? --------> ' + LToC( TokenInit() )
   ? '      TokenEnd() ? --------------------------> ' + LToC( TokenEnd() )
   WHILE ! TokenEnd()
      ? '      TokenNext( @cStr1 ) ----------------> "' + TokenNext( @cStr1 ) + '"'
      ? '      TokenEnd() ? -----------------------> ' + LToC( TokenEnd() )
   ENDDO
   ?
   ? '    access tokens directly with tokennext'
   ? '      TokenNext( @cStr1, 2 ) == "BB" ? ------> "' + TokenNext( @cStr1, 2 ) + '"'
   ? '      TokenNext( @cStr1, 4 ) == "DDDD" ? ----> "' + TokenNext( @cStr1, 4 ) + '"'
   ?

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

   ? '  Incremental tokenizing the string "' + cStr3 + '" with the'
   ? '  token environment of cStr1 !'
   ? '    rewind with TokenInit() == .T. ? ------> ' + LToC( TokenInit() )
   ? '      TokenEnd() ? -------------------------> ' + LToC( TokenEnd() )
   WHILE ! TokenEnd()
      ? '      TokenNext( @cStr3 ) ------------------> "' + TokenNext( @cStr3 ) + '"'
      ? '      TokenEnd() ? -------------------------> ' + LToC( TokenEnd() )
   ENDDO
   ?
   ? '    rewind with TokenInit() == .T. ? ------> ' + LToC( TokenInit() )
   ? '      TokenEnd() ? -------------------------> ' + LToC( TokenEnd() )
   WHILE ! TokenEnd()
      ? '      start / end with TokenAt(.F./.T.)-----> ' + Str( TokenAt() ) + ' ' + Str( TokenAt( .T. ) )
      TokenNext( @cStr1 )
      ? '      TokenEnd() ? -------------------------> ' + LToC( TokenEnd() )
   ENDDO
   ?
   ? '    access tokens directly with tokenat'
   ? '      TokenAt( .F., 2 ) == 3 ? ---------------> ' + Str( TokenAt( .F., 2 ) )
   ? '      TokenAt( .T., 4 ) == 14 ? --------------> ' + Str( TokenAt( .T., 4 ) )
   ?

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

   ? '  Save global token environment with savetoken'
   cTE1 := SaveToken()
   ? '    tokeninit a different string, cStr4 := "' + cStr4 + '", with TokenInit()'
   ? '    TokenInit( @cStr4, ":", 1 ) == .T. ? ----> ' + LToC( TokenInit( @cStr4, ":", 1 ) )
   ? '    TokenNum() == 5 ? ---------------------> ' + Str( TokenNum() )
   ? '    TokenNext() == "08" ? ------------------> "' + TokenNext( @cStr4 ) + '"'
   ? '    Now restore global token environment with resttoken and rewind it'
   RestToken( cTE1 )
   TokenInit()
   ? '    TokenNum() == 6 ? ----------------------> ' + Str( TokenNum() )
   ? '      TokenEnd() ? -------------------------> ' + LToC( TokenEnd() )
   WHILE ! TokenEnd()
      ? '      TokenNext( @cStr1 ) -----------------> "' + TokenNext( @cStr1 ) + '"'
      ? '      TokenEnd() ? -------------------------> ' + LToC( TokenEnd() )
   ENDDO
   ? '  Release global TE with TokenExit() ----> ' + LToC( TokenExit() )
   ?

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

   ? '  Now tokenize cStr4 := "' + cStr4 + '" and'
   ? '  cStr5 := "' + cStr5 + '"'
   ? '  and store the token environment locally to cTE1 and cTE2:'
   ? '    TokenInit( @cStr4, ":", 1, @cTE1 ) == .T. ? -> ' + LToC( TokenInit( @cStr4, ":", 1, @cTE1 ) )
   ? '    TokenInit( @cStr5, "+", 1, @cTE2 ) == .T. ? -> ' + LToC( TokenInit( @cStr5, "+", 1, @cTE2 ) )
   ? '    TokenNum( @cTE1 ) == 5 ? --------------------> ' + Str( TokenNum( @cTE1 ) )
   ? '    TokenNum( @cTE2 ) == 4 ? --------------------> ' + Str( TokenNum( @cTE2 ) )
   ? '        TokenEnd( @cTE1 ) ? ---------------------> ' + LToC( TokenEnd( @cTE1 ) )
   ? '        TokenEnd( @cTE2 ) ? ---------------------> ' + LToC( TokenEnd( @cTE2 ) )
   WHILE ! TokenEnd( @cTE1 ) .AND. ! TokenEnd( @cTE2 )
      ? '      next train at ' + TokenNext( cStr4,, @cTE1 ) + ":" + TokenNext( cStr5,, @cTE2 )
      ? '          compiled with TokenNext( cStr4,, @cTE1 ) + ":" + TokenNext( cStr5,, @cTE2 )'
      ? '        TokenEnd( @cTE1 ) ? ---------------------> ' + LToC( TokenEnd( @cTE1 ) )
      ? '        TokenEnd( @cTE2 ) ? ---------------------> ' + LToC( TokenEnd( @cTE2 ) )
   ENDDO

   ?
   ? "End test of incremental tokenizer function family"
   ?

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

   ctexit()

   RETURN


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

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

[Assistant]
PROCEDURE Main()

   LOCAL a

   ? "Direct reference : ", aFunc()[ 1 ]

   a := aFunc()
   ? "Ref via array    : ", a[ 1 ]

   aFunc()[ 1 ] := "Something different"
   ? "Assign new text  : ", aFunc()[ 1 ]

   aFunc()[ 1 ] := 4
   ? "Assign 4         : ", aFunc()[ 1 ]

   ? "Post increment   : ", aFunc()[ 1 ]++
   ? "After            : ", aFunc()[ 1 ]
   ? "Pre decrement    : ", --aFunc()[ 1 ]
   ? "After            : ", aFunc()[ 1 ]

   aFunc()[ 1 ] += 2
   ? "Plus 2           : ", aFunc()[ 1 ]

   aFunc()[ 1 ] -= 3
   ? "Minus 3          : ", aFunc()[ 1 ]

   aFunc()[ 1 ]
   ? "Times 3          : ", aFunc()[ 1 ]

   aFunc()[ 1 ] /= 1.5
   ? "Divide by 1.5    : ", aFunc()[ 1 ]

   aFunc()[ 1 ] %= 4
   ? "Modulus 4        : ", aFunc()[ 1 ]

   aFunc()[ 1 ] ^= 3
   ? "To the power 3   : ", aFunc()[ 1 ]

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

   RETURN

FUNCTION aFunc()

   STATIC s_aArray := { [Test] }

   RETURN s_aArray


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

[Assistant]
#require "hbwin"

#include "simpleio.ch"

PROCEDURE Main()

   Dump( win_printerList( .F., .F. ) )
   Dump( win_printerList( .F., .T. ) )
   Dump( win_printerList( .T., .F. ) )
   Dump( win_printerList( .T., .T. ) )

   ? "WIN_PRINTERGETDEFAULT:", ">" + win_printerGetDefault() + "<"
   ? "WIN_PRINTERSTATUS:", win_printerStatus()

   RETURN

STATIC PROCEDURE Dump( a )

   LOCAL b, c

   ? "=================="
   FOR EACH b IN a
      ?
      IF HB_ISARRAY( b )
         FOR EACH c IN b
            ?? c:__enumIndex(), c
            IF c:__enumIndex() == 2
               ?? ">>" + win_printerPortToName( c ) + "<<",  "|>>" + win_printerPortToName( c, .T. ) + "<<|"
            ENDIF
            ?
         NEXT
         ? "-----"
      ELSE
         ? b, win_printerExists( b ), win_printerStatus( b )
      ENDIF
   NEXT

   RETURN


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

[User] Write Harbour functions: TimeToSec, Millisec. Harbour contribution module 'hbct' (CA-Tools compatibility library): contrib/hbct/cttime.prg. Provides functions: TimeToSec, Millisec. This file provides legacy compatibility functions

[Assistant]
FUNCTION TimeToSec( cTime )

   LOCAL nSec := 0
   LOCAL nLen, i, aLim, aMod, nInd, n

   IF cTime == NIL
      nSec := Seconds()
   ELSEIF HB_ISSTRING( cTime )
      nLen := Len( cTime )
      IF ( nLen + 1 ) % 3 == 0 .AND. nLen <= 11
         nInd := 1
         aLim := { 24, 60, 60, 100 }
         aMod := { 3600, 60, 1, 1 / 100 }
         FOR i := 1 TO nLen STEP 3
            IF IsDigit( SubStr( cTime, i    , 1 ) ) .AND. ;
               IsDigit( SubStr( cTime, i + 1, 1 ) ) .AND. ;
               ( i == nLen - 1 .OR. SubStr( cTime, i + 2, 1 ) == ":" ) .AND. ;
               ( n := Val( SubStr( cTime, i, 2 ) ) ) < aLim[ nInd ]
               nSec += n
      h := ""
   ENDIF

   n := Int( n % 86400 )

   FOR i := 1 TO 3
      h := StrZero( n % 60, 2 ) + iif( h == "", "", ":" + h )
      n := Int( n / 60 )
   NEXT

   RETURN h

FUNCTION Millisec( nDelay )

   hb_idleSleep( nDelay / 1000 )

   RETURN ""


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

[User] Create Harbour preprocessor definitions: Harbour Runtime Library file: src/rtl/achoice.prg. Provides functions: AChoice. This file provides utility functions

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

#define INRANGE( xLo, xVal, xHi )  ( xVal >= xLo .AND. xVal <= xHi )
#define BETWEEN( xLo, xVal, xHi )  Min( Max( xLo, xVal ), xHi )

FUNCTION AChoice( nTop, nLeft, nBottom, nRight, acItems, xSelect, xUserFunc, nPos, nHiLiteRow )

   LOCAL nNumCols
   LOCAL nNumRows
   LOCAL nRowsClr
   LOCAL alSelect
   LOCAL nNewPos   := 0
   LOCAL lFinished
   LOCAL nKey      := 0
   LOCAL nMode
   LOCAL nAtTop
   LOCAL nItems    := 0
   LOCAL nGap

   LOCAL lUserFunc
   LOCAL nUserFunc
   LOCAL nSaveCsr
   LOCAL nFrstItem := 0
   LOCAL nLastItem := 0

   LOCAL bAction
   LOCAL cKey
   LOCAL nAux

   nTop := Int( hb_defaultValue( nTop, 0 ) )
   nBottom := Int( hb_defaultValue( nBottom, 0 ) )

   hb_default( @nLeft, 0 )
   hb_default( @nRight, 0 )

   IF nRight > MaxCol()
      nRight := MaxCol()
   ENDIF

   IF nBottom > MaxRow()
      nBottom := MaxRow()
   ENDIF

   IF ! HB_ISARRAY( acItems ) .OR. Len( acItems ) == 0
      SetPos( nTop, nRight + 1 )
      RETURN 0
   ENDIF

   nSaveCsr := SetCursor( SC_NONE )

   ColorSelect( CLR_STANDARD )

   IF Empty( xUserFunc ) .AND. ValType( xSelect ) $ "CBS"
      xUserFunc := xSelect
      xSelect := NIL
   ENDIF

   lUserFunc := ! Empty( xUserFunc ) .AND. ValType( xUserFunc ) $ "CBS"

   IF ! HB_ISARRAY( xSelect ) .AND. ! HB_ISLOGICAL( xSelect )
      xSelect := .T.
   ENDIF

   hb_default( @nPos, 1 )
   hb_default( @nHiLiteRow, 0 )

   nNumCols := nRight - nLeft + 1
   nNumRows := nBottom - nTop + 1

   IF HB_ISARRAY( xSelect )
      alSelect := xSelect
   ELSE
      alSelect := Array( Len( acItems ) )
      AFill( alSelect, xSelect )
   ENDIF

   IF ( nMode := Ach_Limits( @nFrstItem, @nLastItem, @nItems, alSelect, acItems ) ) == AC_NOITEM
      nPos := 0
   ENDIF

   nPos := BETWEEN( nFrstItem, nPos, nLastItem )

   nHiLiteRow := BETWEEN( 0, nHiLiteRow, nNumRows - 1 )

   nAtTop := BETWEEN( 1, Max( 1, nPos - nHiLiteRow ), nItems )

   IF ( nAtTop + nNumRows - 1 ) > nItems
      nAtTop := Max( 1, nItems - nNumrows + 1 )
   ENDIF

   DispPage( acItems, alSelect, nTop, nLeft, nRight, nNumRows, nPos, nAtTop, nItems, nItems )

   lFinished := ( nMode == AC_NOITEM )
   IF lFinished .AND. lUserFunc
      Do( xUserFunc, nMode, nPos, nPos - nAtTop )
   ENDIF
   DO WHILE ! lFinished

      IF nMode != AC_EXCEPT .AND. nMode != AC_NOITEM
         nKey  := Inkey( 0 )
         nMode := AC_IDLE
      ENDIF

      DO CASE
      CASE ( bAction := SetKey( nKey ) ) != NIL

         Eval( bAction, ProcName( 1 ), ProcLine( 1 ), "" )
         IF NextKey() == 0
            hb_keySetLast( 255 )
            nKey := 0
         ENDIF

         nRowsClr := Min( nNumRows, nItems )

         IF ( nMode := Ach_Limits( @nFrstItem, @nLastItem, @nItems, alSelect, acItems ) ) == AC_NOITEM
            nPos := 0
            nAtTop := Max( 1, nPos - nNumRows + 1 )
         ELSE
            DO WHILE nPos < nLastItem .AND. ! Ach_Select( alSelect, nPos )
               nPos++
            ENDDO

            IF nPos > nLastItem
               nPos := BETWEEN( nFrstItem, nPos, nLastItem )
            ENDIF

            nAtTop := Min( nAtTop, nPos )

            IF nAtTop + nNumRows - 1 > nItems
               nAtTop := BETWEEN( 1, nPos - nNumRows + 1, nItems - nNumRows + 1 )
            ENDIF

            IF nAtTop < 1
               nAtTop := 1
            ENDIF
         ENDIF

         DispPage( acItems, alSelect, nTop, nLeft, nRight, nNumRows, nPos, nAtTop, nItems, nRowsClr )

      CASE ( nKey == K_ESC .OR. nMode == AC_NOITEM ) .AND. ! lUserFunc

         IF nPos != 0
            DispLine( acItems[ nPos ], nTop + nPos - nAtTop, nLeft, .T., .F., nNumCols )
         ENDIF

         nMode     := AC_IDLE
         nPos      := 0
         lFinished := .T.

      CASE nKey == K_LDBLCLK .OR. nKey == K_LBUTTONDOWN
         nAux := HitTest( nTop, nLeft, nBottom, nRight, MRow(), MCol() )
         IF nAux != 0 .AND. ( nNewPos := nAtTop + nAux - 1 ) <= nItems
            IF Ach_Select( alSelect, nNewPos )
               DispLine( acItems[ nPos ], nTop + nPos - nAtTop, nLeft, Ach_Select( alSelect, nPos ), .F., nNumCols )
               nPos := nNewPos
               DispLine( acItems[ nPos ], nTop + nPos - nAtTop, nLeft, Ach_Select( alSelect, nPos ), .T., nNumCols )
               IF nKey == K_LDBLCLK
                  hb_keyIns( K_ENTER )
               ENDIF
            ENDIF
         ENDIF

#ifdef HB_CLP_STRICT
      CASE nKey == K_UP
#else
      CASE nKey == K_UP .OR. nKey == K_MWFORWARD
#endif

         IF nPos == nFrstItem
            nMode := AC_HITTOP
            IF nAtTop > Max( 1, nPos - nNumRows + 1 )
               nAtTop := Max( 1, nPos - nNumRows + 1 )
               DispPage( acItems, alSelect, nTop, nLeft, nRight, nNumRows, nPos, nAtTop, nItems )
            ENDIF
         ELSE
            nNewPos := nPos - 1
            DO WHILE ! Ach_Select( alSelect, nNewPos )
               nNewPos--
            ENDDO
            IF INRANGE( nAtTop, nNewPos, nAtTop + nNumRows - 1 )
               DispLine( acItems[ nPos ], nTop + nPos - nAtTop, nLeft, Ach_Select( alSelect, nPos ), .F., nNumCols )
               nPos := nNewPos
               DispLine( acItems[ nPos ], nTop + nPos - nAtTop, nLeft, Ach_Select( alSelect, nPos ), .T., nNumCols )
            ELSE
               DispBegin()
               DispLine( acItems[ nPos ], nTop + nPos - nAtTop, nLeft, Ach_Select( alSelect, nPos ), .F., nNumCols )
               Scroll( nTop, nLeft, nBottom, nRight, nNewPos - ( nAtTop + nNumRows - 1 ) )
               nAtTop := nNewPos
               nPos   := Max( nPos, nAtTop + nNumRows - 1 )
               DO WHILE nPos > nNewPos
                  IF nTop + nPos - nAtTop <= nBottom
                     DispLine( acItems[ nPos ], nTop + nPos - nAtTop, nLeft, Ach_Select( alSelect, nPos ), .F., nNumCols )
                  ENDIF
                  nPos--
               ENDDO
               DispLine( acItems[ nPos ], nTop + nPos - nAtTop, nLeft, Ach_Select( alSelect, nPos ), .T., nNumCols )
               DispEnd()
            ENDIF
         ENDIF

#ifdef HB_CLP_STRICT
      CASE nKey == K_DOWN
#else
      CASE nKey == K_DOWN .OR. nKey == K_MWBACKWARD
#endif

         IF nPos == nLastItem
            nMode := AC_HITBOTTOM
            IF nAtTop < Min( nPos, nItems - nNumRows + 1 )
               nAtTop := Min( nPos, nItems - nNumRows + 1 )
               DispPage( acItems, alSelect, nTop, nLeft, nRight, nNumRows, nPos, nAtTop, nItems )
            ENDIF
         ELSE

            nNewPos := nPos + 1

            DO WHILE ! Ach_Select( alSelect, nNewPos )
               nNewPos++
            ENDDO

            IF INRANGE( nAtTop, nNewPos, nAtTop + nNumRows - 1 )
               DispLine( acItems[ nPos ], nTop + nPos - nAtTop, nLeft, Ach_Select( alSelect, nPos ), .F., nNumCols )
               nPos := nNewPos
               DispLine( acItems[ nPos ], nTop + nPos - nAtTop, nLeft, Ach_Select( alSelect, nPos ), .T., nNumCols )
            ELSE
               DispBegin()
               DispLine( acItems[ nPos ], nTop + nPos - nAtTop, nLeft, Ach_Select( alSelect, nPos ), .F., nNumCols )
               Scroll( nTop, nLeft, nBottom, nRight, nNewPos - ( nAtTop + nNumRows - 1 ) )
               nAtTop := nNewPos - nNumRows + 1
               nPos   := Max( nPos, nAtTop )
               DO WHILE nPos < nNewPos
                  DispLine( acItems[ nPos ], nTop + nPos - nAtTop, nLeft, Ach_Select( alSelect, nPos ), .F., nNumCols )
                  nPos++
               ENDDO
               DispLine( acItems[ nPos ], nTop + nPos - nAtTop, nLeft, Ach_Select( alSelect, nPos ), .T., nNumCols )
               DispEnd()
            ENDIF
         ENDIF

      CASE nKey == K_CTRL_PGUP .OR. ( nKey == K_HOME .AND. ! lUserFunc )


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

[User] Generate Harbour code for: Harbour contribution module 'hbtip' (Internet protocol utilities (FTP, HTTP, SMTP, POP3)): contrib/hbtip/tests/tipwget.prg. Provides functions: ShowGauge. Contains procedures: Main. This file provides network protocol implementations

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

#if ! defined( __HBSCRIPT__HBSHELL )
REQUEST __HBEXTERN__HBSSL__
#endif

#include "hbclass.ch"
#include "inkey.ch"
#include "tip.ch"

PROCEDURE Main( cURL, cFile )

   LOCAL bWrite := .F.
   LOCAL oURL, oClient
   LOCAL cData

   ? "Harbour - TIP (class based internet client protocol) test"

   IF ! HB_ISSTRING( cURL ) .OR. Empty( cURL )
      ? hb_StrFormat( "Usage: %1$s <URI> [dumpToOrFromFileName]", hb_ProgName() )
      RETURN
   ENDIF

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

   SWITCH Lower( oURL:cProto )
   CASE "ftp"
      oClient := TIPClientFTP():New( oURL )
      EXIT
   CASE "http"
   CASE "https"
      oClient := TIPClientHTTP():New( oURL )
      EXIT
   CASE "pop"
   CASE "pops"
      oClient := TIPClientPOP():New( oURL )
      EXIT
   CASE "smtp"
   CASE "smtps"
      oClient := TIPClientSMTP():New( oURL )
      EXIT
   ENDSWITCH

   IF Empty( oClient )
      ? "Invalid URL", cURL
      RETURN
   ENDIF
   oClient:nConnTimeout := 2000

   oURL:cUserid := StrTran( oURL:cUserid, "&at;", "@" )

   ? "Connecting to", oURL:cProto + ":
   IF oClient:Open()
      ? "Connection status:", iif( Empty( oClient:cReply ), "<connected>", oClient:cReply )

      IF HB_ISSTRING( cFile ) .AND. hb_LeftEq( cFile, "+" )
         cFile := SubStr( cFile, 2 )
         bWrite := .T.
      ENDIF

      ?
      oClient:exGauge := {| done, size | ShowGauge( done, size ) }

      IF oClient:nAccessMode == TIP_WO .OR. ( oClient:nAccessMode == TIP_RW .AND. bWrite )
         IF oClient:WriteFromFile( cFile )
            ? "Data successfully sent"
         ELSE
            ? "Error: Data not sent", oClient:lastErrorMessage()
         ENDIF
      ELSE
         IF HB_ISSTRING( cFile )
            IF ( cData := oClient:Read() ) == ""
               ? "Error: file could not be retrieved", oClient:lastErrorMessage()
            ELSE
               ? "First 80 characters:", hb_ValToExp( hb_BLeft( cData, 80 ) ) )
            ENDIF
         ELSEIF oClient:ReadToFile( cFile )
            ? "File", cFile, "written."
            ? "Server replied", oClient:cReply
         ELSE
            ? "Error: Generic error in writing", cFile
         ENDIF
      ENDIF

      oClient:Close()
      ? "Done:", iif( Empty( oClient:cReply ), "(no goodbye message)", oClient:cReply )
   ELSE
      ? "Could not open URI", cURL
      IF ! Empty( oClient:cReply )
         ? oClient:cReply
      ENDIF
   ENDIF

   RETURN

STATIC FUNCTION ShowGauge( nSent, nSize )

   SetPos( Row(), 0 )
   ?? "Sending:", nSent, "/", nSize

   RETURN hb_keyStd( Inkey() ) != K_ESC


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

[Assistant]
PROCEDURE Main()

   LOCAL uVar

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

   ? "Testing Harbour Extended system:"
   ? "================================"
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?

   WAIT "Press any key to continue..."

   ? "Strings:"
   ? "========"
   ?
   ? '  _parc() and _retc() with Strings1( "Hello" ) =>', Strings1( "Hello" )
   ? '  _parc() and _retc() with Strings2( { "Hello" } ) =>', Strings2( { "Hello" } )
   ? '  _retclen() with Strings3( "Hello word", 5 ) =>', Strings3( "Hello", 5 )
   ? '  _parclen() with Strings4( "Hello word" ) => ', Strings4( "Hello word" )
   uVar := "Hello word"
   ? '  uVar := "Hello word"'
   Strings5( @uVar, "Harbour power!!!" )
   ? '  _storc() with Strings5( @uVar, "Harbour power!!!" ) => ', uVar
   Strings6( @uVar, "Harbour power!!!", 7 )
   ? '  _storclen() with Strings6( @uVar, "Harbour power!!!", 7 ) => ', uVar
   uVar := { "Hello word" }
   ? '  uVar := { "Hello word" }'
   Strings7( uVar, "Harbour power!!!" )
   ? '  _storc() with Strings7( uVar, "Harbour power!!!" ) => ', uVar[ 1 ]
   Strings8( uVar, "Harbour power!!!", 7 )
   ? '  _storclen() with Strings8( uVar, "Harbour power!!!", 7 ) => ', uVar[ 1 ]
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?

   WAIT "Press any key to continue..."

   ? "Logicals:"
   ? "========="
   ?
   ? '  _parl() and _retl() with Logical1( .T. ) =>', Logical1( .T. )
   ? '  _parl() and _parl() with Logical2( { .T. } ) =>', Logical2( { .T. } )
   uVar := .T.
   ? '  uVar := .T.'
   Logical3( @uVar, .F. )
   ? '  _storl() with Logical3( @uVar, .F. ) => ', uVar
   uVar := { .T. }
   ? '  uVar := { .T. }'
   Logical4( uVar, .F. )
   ? '  _storl() with Logical4( uVar, .F. ) => ', uVar[ 1 ]
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?

   WAIT "Press any key to continue..."

   ? "Dates: (SET CENTURY ON)"
   ? "======================="
   ?
   ? '  _pards() and _retds() with Date1( CToD( "2000-01-01" ) ) =>', Date1( CToD( "2000-01-01" ) )
   ? '  _pards() and retds() with Date2( { CToD( "2000-01-01" ) } ) =>', Date2( { CToD( "2000-01-01" ) } )
   uVar := CToD( "2000-01-01" )
   ? '  uVar := CToD( "2000-01-01" )'
   Date3( @uVar, CToD( "1999-12-31" ) )
   ? '  _stords() with Date3( @uVar, CToD( "1999-12-31" ) ) => ', uVar
   uVar := { CToD( "2000-01-01" ) }
   ? '  uVar := { CToD( "2000-01-01" ) }'
   Date4( uVar, CToD( "1999-12-31" ) )
   ? '  _stords() with Date4( uVar, CToD( "1999-12-31" ) ) => ', uVar[ 1 ]
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?

   WAIT "Press any key to continue..."

   ? "Numbers:"
   ? "========"
   ?
   ? '  _parni() and _retni() with Int1( 1 ) =>', Int1( 1 )
   ? '  _parni() and _retni() with Int2( { 1 } ) =>', Int2( { 1 } )
   ? '  _parnl() and _retnl() with Long1( 123456789 ) =>', Long1( 123456789 )
   ? '  _parnl() and _retnl() with Long2( { 123456789 } ) =>', Long2( { 123456789 } )
   ? '  _parnd() and _retnd() with Double1( 1234567.89 ) =>', Double1( 1234567.89 )
   ? '  _parnd() and _retnd() with Double2( { 1234567.89 } ) =>', Double2( { 1234567.89 } )
   uVar := 100
   ? '  uVar := 100'
   Int3( @uVar, 200 )
   ? '  _storni() with Int3( @uVar, 200 ) => ', uVar
   uVar := { 100 }
   ? '  uVar := { 100 }'
   Int4( uVar, 200 )
   ? '  _storni() with Int4( uVar, 200 ) => ', uVar[ 1 ]
   uVar := 123456789
   ? '  uVar := 123456789'
   Long3( @uVar, 987654321 )
   ? '  _stornl() with Long3( @uVar, 987654321 ) => ', uVar
   uVar := { 123456789 }
   ? '  uVar := { 123456789 }'
   Long4( uVar, 987654321 )
   ? '  _stornl() with Long4( uVar, 987654321 ) => ', uVar[ 1 ]
   uVar := 1234567.89
   ? '  uVar := 1234567.89'
   Double3( @uVar, 9876543.21 )
   ? '  _stornd() with Double3( @uVar, 9876543.21 ) => ', uVar
   uVar := { 1234567.89 }
   ? '  uVar := { 1234567.89 }'
   Double4( uVar, 9876543.21 )
   ? '  _stornl() with Double4( uVar, 9876543.21 ) => ', uVar[ 1 ]
   ?
   ?
   ?

   WAIT "Press any key to continue..."

   ? "Nil:"
   ? "===="
   ?
   ? '  _ret() with Nil1() =>', Nil1()
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?

   WAIT "Press any key to continue..."

   ? "Arrays:"
   ? "======="
   ?
   ? '  _reta() with Len( Arrays1( 100 ) ) =>', Len( Arrays1( 100 ) )
   ? '  _parinfa() with Arrays2( { 1, "a", .T. }, 0 ) =>', Arrays2( { 1, "a", .T. }, 0 )
   ? '  _parinfa() with Arrays2( { 1, "a", .T. }, 2 ) =>', Arrays2( { 1, "a", .T. }, 2 ), "( IT_STRING )"
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?

   WAIT "Press any key to continue..."

   ? "Parameters info:"
   ? "================"
   ?
   ? '  _pcount() with Params1( 1, "a", .T., 10 ) =>', Params1( 1, "a", .T., 10 )
   ? '  _parinfo() with Params2( 1, "a", .T., 0 ) =>', Params2( 1, "a", .T., 0 )
   ? '  _parinfo() with Params2( 1, "a", .T., 3 ) =>', Params2( 1, "a", .T., 3 ), "( IT_LOGICAL )"
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?

   WAIT "Press any key to continue..."

   ? "Undocumented features:"
   ? "======================"
   ?
   ? '  _parc( -1, ...) with Undoc2() =>', Undoc2()
   ? '  _parclen( -1, ...) with Undoc3() =>', Undoc3()
   ? '  _pards( -1, ...) with Undoc4( CToD( "2000-01-01" ) ) =>', Undoc4( CToD( "2000-01-01" ) )
   ? '  _parl( -1, ...) with Undoc5( .T. ) =>', Undoc5( .T. )
   ? '  _parnd( -1, ...) with Undoc6( 1234567.89 ) =>', Undoc6( 1234567.89 )
   ? '  _parni( -1, ...) with Undoc7( 1234 ) =>', Undoc7( 1234 )
   ? '  _parnl( -1, ...) with Undoc8( 123456789 ) =>', Undoc8( 123456789 )
   ? '  _parinfa( -1, ...) with Undoc9( 10 ) =>', Undoc9( 10 )
   ? '  _parinfo( -1 ) with Undoc10() =>', Undoc10(), "( IT_STRING )"
   ? '  _storc( szText, -1, ... ) with Undoc11( "Hello word" ) =>', Undoc11( "Hello word" )
   ? '  _storclen( szText, -1, ... ) with Undoc12( "Hello word", 7 ) =>', Undoc12( "Hello word", 7 )
   ? '  _stords( szDate, -1, ... ) with Undoc13( CToD( "2000-01-01" ) ) =>', Undoc13( CToD( "2000-01-01" ) )
   ? '  _storl( iLogical, -1 ) with Undoc14( .T. ) =>', Undoc14( .T. )
   ? '  _storni( iValue, -1 ) with Undoc15( 1234 ) =>', Undoc15( 1234 )
   ? '  _stornl( lValue, -1 ) with Undoc16( 123456789 ) =>', Undoc16( 123456789 )
   ? '  _stornd( dValue, -1 ) with Undoc17( 1234567.89 ) =>', Undoc17( 1234567.89 )
   ?
   ?
   ?
   ?
   ?

   RETURN


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

[User] Write a Harbour program with procedures: Main. Harbour test program: tests/memfile.prg. Provides functions: __mvScope. Contains procedures: Main. This test file exercises basic Harbour language features

[Assistant]
MEMVAR m_cLongerNameThen10Chars
#ifdef __HARBOUR__
MEMVAR m_cLongerN
#endif
MEMVAR m_cString
MEMVAR m_nDouble
MEMVAR m_nDoubleH
MEMVAR m_nInt
MEMVAR m_nLong
MEMVAR m_dDate
MEMVAR m_lLogicT
MEMVAR m_lLogicF
MEMVAR m_xStayHer

PROCEDURE Main()

   PRIVATE m_cLongerNameThen10Chars := "Long String Name!"
   PRIVATE m_cString   := "This is a" + Chr( 0 ) + "string to save."
   PRIVATE m_nDouble   := 100.0000
   PRIVATE m_nDoubleH  := 5000000000
   PRIVATE m_nInt      := 35
   PRIVATE m_nLong     := 3000000
   PRIVATE m_dDate     := Date()
   PRIVATE m_lLogicT := .F.
   PRIVATE m_lLogicF := .T.

   SAVE TO memfile ALL
   SAVE TO memsome ALL LIKE "m_nDouble*"

   CLEAR MEMORY

   SAVE TO memempt ALL

   PRIVATE m_xStayHer := "CONST"

   RESTORE FROM memfile ADDITIVE

   ? m_xStayHer
   ? m_cLongerN
   ? m_cString
   ? m_nDouble
   ? m_nDoubleH
   ? m_nInt
   ? m_nLong
   ? m_dDate
   ? m_lLogicF
   ? m_lLogicT

   RESTORE FROM memfile

   ? m_cLongerN
   ? m_cString
   ? m_nDouble
   ? m_nDoubleH
   ? m_nInt
   ? m_nLong
   ? m_dDate
   ? m_lLogicF
   ? m_lLogicT

   ? __MRestore( "memfile", .F., "m_nDouble*", .T. )
   ? m_nDouble
   ? m_nDoubleH
   ? __mvScope( "m_nInt" )

   FErase( "memempt.mem" )
   FErase( "memfile.mem" )
   FErase( "memsome.mem" )

   RETURN

#ifndef __HARBOUR__
FUNCTION __mvScope()
   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: Harbour contribution module 'hbnf' (NanForum Toolkit - legacy Clipper compatibility functions): contrib/hbnf/dfile.prg. Provides functions: ft_DFSetup, ft_DFClose. This file provides legacy compatibility functions

[Assistant]
#include "fileio.ch"

THREAD STATIC t_nHandle := F_ERROR

FUNCTION ft_DFSetup( cInFile, nTop, nLeft, nBottom, nRight, ;
      nStart, nCNormal, nCHighlight, cExitKeys, ;
      lBrowse, nColSkip, nRMargin, nBuffSize )

   LOCAL rval

   IF hb_FileExists( cInFile )

      hb_default( @nTop        , 0 )
      hb_default( @nLeft       , 0 )
      hb_default( @nBottom     , MaxRow() )
      hb_default( @nRight      , MaxCol() )
      hb_default( @nCNormal    , 7 )
      hb_default( @nCHighlight , 15 )
      hb_default( @nStart      , 1 )
      hb_default( @nColSkip    , 1 )
      hb_default( @lBrowse     , .F. )
      hb_default( @nRMargin    , 255 )
      hb_default( @nBuffSize   , 4096 )

      IF HB_ISARRAY( cExitKeys )
         IF Len( cExitKeys ) > 25
            ASize( cExitKeys, 25 )
         ENDIF
      ELSEIF HB_ISSTRING( cExitKeys )
         cExitKeys := Left( cExitKeys, 25 )
      ELSE
         cExitKeys := {}
      ENDIF

      t_nHandle := FOpen( cInFile )

      rval := FError()

      IF rval == 0
         rval := _ft_DFInit( t_nHandle, nTop, nLeft, nBottom, nRight, ;
            nStart, nCNormal, nCHighlight, cExitKeys, ;
            lBrowse, nColSkip, nRMargin, nBuffSize )
      ENDIF
   ELSE
      rval := 2
   ENDIF

   RETURN rval

FUNCTION ft_DFClose()

   IF t_nHandle != F_ERROR
      _ft_DFClos()

      FClose( t_nHandle )

      t_nHandle := F_ERROR
   ENDIF

   RETURN NIL


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

[User] Create Harbour preprocessor definitions: Harbour test program: tests/usrrdd/exarr.prg. Contains procedures: Main. This test file tests specific function APIs

[Assistant]
REQUEST ARRAYRDD

#define USE_DBCREATE_EXTENSIONS

PROCEDURE Main()

   LOCAL aStruct

   Set( _SET_DATEFORMAT, "yyyy-mm-dd" )
   SET DELETED OFF
   CLS

   ? "Create a new dbf in memory using dbCreate() command"
   aStruct := { ;
      { "NAME"     , "C", 40, 0 }, ;
      { "ADDRESS"  , "C", 40, 0 }, ;
      { "BIRTHDAY" , "D",  8, 0 }, ;
      { "AGE"      , "N",  3, 0 } }

#ifndef USE_DBCREATE_EXTENSIONS
   ? "Create it"
   dbCreate( "arrtest.dbf", aStruct, "ARRAYRDD" )
   WAIT
   ? "Open it"
   USE arrtest.dbf VIA "ARRAYRDD"
   WAIT
#else
   ? "Create it and leave opened"
   dbCreate( "arrtest.dbf", aStruct, "ARRAYRDD", .T., "arrtest" )
   WAIT
#endif

   ? "Show structure"
   ? hb_ValToExp( dbStruct() )
   WAIT

   ? "ALIAS", Alias(), "RECNO", RecNo(), ;
      "BOF", Bof(), "EOF", Eof(), "LASTREC", LastRec()
   ? RecNo(), '"' + FIELD->NAME + '"'
   dbGoBottom()
   ? RecNo(), '"' + FIELD->NAME + '"'
   dbGoTop()
   ? RecNo(), '"' + FIELD->NAME + '"'
   WAIT

   ? "Adding some data"
   dbAppend()
   field->name     := "Giudice Francesco Saverio"
   field->address  := "Main Street 10"
   field->birthday := hb_SToD( "19670103" )
   field->age      := 39

   ? RecNo(), '"' + FIELD->NAME + '"'

   dbAppend()
   field->name     := "Mouse Mickey"
   field->address  := "Main Street 20"
   field->birthday := hb_SToD( "19400101" )
   field->age      := 66

   WHILE ! Eof()
      ? RecNo(), '"' + FIELD->NAME + '"'
      IF RecNo() == 20
         Inkey( 0 )
      ENDIF
      dbSkip()
   ENDDO
   ? "ALIAS", Alias(), "RECNO", RecNo(), ;
      "BOF", Bof(), "EOF", Eof(), "LASTREC", LastRec()
   WAIT
   dbGoBottom()
   ? "ALIAS", Alias(), "RECNO", RecNo(), ;
      "BOF", Bof(), "EOF", Eof(), "LASTREC", LastRec()
   WAIT
   WHILE ! Bof()
      ? RecNo(), '[' + FIELD->NAME + ']'
      IF RecNo() == LastRec() - 20
         Inkey( 0 )
      ENDIF
      dbSkip( -1 )
   ENDDO
   ? "ALIAS", Alias(), "RECNO", RecNo(), ;
      "BOF", Bof(), "EOF", Eof(), "LASTREC", LastRec()
   WAIT

   ? "Show it - Please don't press any key except movement keys and ESC"
   ? "          to exit from Browse(), otherwise you will get an error"
   ? "          due to missing index support"
   WAIT
   Browse()

   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 'hbbz2' (BZ2 compression library): contrib/hbbz2/hbbz2.ch. Defines 10 constants including: HB_BZ2_CH_, HB_BZ_OK, HB_BZ_RUN_OK, HB_BZ_FLUSH_OK, HB_BZ_FINISH_OK. Defines Harbour internal constants and macros

[Assistant]
#ifndef HB_BZ2_CH_
#define HB_BZ2_CH_

#define HB_BZ_OK                    0
#define HB_BZ_RUN_OK                1
#define HB_BZ_FLUSH_OK              2
#define HB_BZ_FINISH_OK             3
#define HB_BZ_STREAM_END            4
#define HB_BZ_SEQUENCE_ERROR        ( -1 )
#define HB_BZ_PARAM_ERROR           ( -2 )
#define HB_BZ_MEM_ERROR             ( -3 )
#define HB_BZ_DATA_ERROR            ( -4 )
#define HB_BZ_DATA_ERROR_MAGIC      ( -5 )
#define HB_BZ_IO_ERROR              ( -6 )
#define HB_BZ_UNEXPECTED_EOF        ( -7 )
#define HB_BZ_OUTBUFF_FULL          ( -8 )
#define HB_BZ_CONFIG_ERROR          ( -9 )

#define HB_BZ_COMPRESSION_SPEED     1
#define HB_BZ_COMPRESSION_SIZE      9
#define HB_BZ_COMPRESSION_DEFAULT   9

#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 the following Harbour classes: TMySQLRow, TMySQLQuery. Harbour contribution module 'hbmysql' (MySQL database client library): contrib/hbmysql/tmysql.prg. Defines classes: TMySQLRow, TMySQLQuery. This file handles database operations

[Assistant]
#include "hbclass.ch"

#include "dbstruct.ch"

#include "mysql.ch"

CREATE CLASS TMySQLRow

   VAR aRow
   VAR aDirty
   VAR aOldValue

   VAR aOriValue

   VAR aFieldStruct
   VAR cTable

   METHOD New( aRow, aFStruct, cTableName )

   METHOD FieldGet( cnField )
   METHOD FieldPut( cnField, Value )
   METHOD FieldName( nNum )
   METHOD FieldPos( cFieldName )

   METHOD FieldLen( nNum )
   METHOD FieldDec( nNum, lFormat )
   METHOD FieldType( nNum )

   METHOD MakePrimaryKeyWhere()

ENDCLASS

METHOD New( aRow, aFStruct, cTableName ) CLASS TMySQLRow

   hb_default( @cTableName, "" )
   hb_default( @aFStruct, {} )

   ::aRow := aRow
   ::aOriValue := AClone( aRow )

   ::aFieldStruct := aFStruct
   ::cTable := cTableName

   ::aDirty := Array( Len( ::aRow ) )
   ::aOldValue := Array( Len( ::aRow ) )

   AFill( ::aDirty, .F. )

   RETURN Self

METHOD FieldGet( cnField ) CLASS TMySQLRow

   LOCAL nNum := iif( HB_ISSTRING( cnField ), ::FieldPos( cnField ), cnField )

   IF nNum > 0 .AND. nNum <= Len( ::aRow )

      IF ::FieldType( nNum ) == "C"
         RETURN PadR( ::aRow[ nNum ], ::aFieldStruct[ nNum ][ MYSQL_FS_LENGTH ] )
      ELSE
         RETURN ::aRow[ nNum ]
      ENDIF
   ENDIF

   RETURN NIL

METHOD FieldPut( cnField, Value ) CLASS TMySQLRow

   LOCAL nNum := iif( HB_ISSTRING( cnField ), ::FieldPos( cnField ), cnField )

   IF nNum > 0 .AND. nNum <= Len( ::aRow )

      IF ValType( Value ) == ValType( ::aRow[ nNum ] ) .OR. ::aRow[ nNum ] == NIL

         IF HB_ISSTRING( Value )
            Value := RTrim( Value )
         ENDIF

         IF ! ::aDirty[ nNum ]
            ::aOldValue[ nNum ] := ::aRow[ nNum ]
            ::aDirty[ nNum ] := .T.
         ENDIF

         ::aRow[ nNum ] := Value

         RETURN Value
      ENDIF
   ENDIF

   RETURN NIL

METHOD FieldPos( cFieldName ) CLASS TMySQLRow

   LOCAL cUpperName := Upper( cFieldName )

   RETURN AScan( ::aFieldStruct, {| aItem | Upper( aItem[ MYSQL_FS_NAME ] ) == cUpperName } )

METHOD FieldName( nNum ) CLASS TMySQLRow
   RETURN iif( nNum >= 1 .AND. nNum <= Len( ::aFieldStruct ), ::aFieldStruct[ nNum ][ MYSQL_FS_NAME ], "" )

METHOD FieldLen( nNum ) CLASS TMySQLRow
   RETURN iif( nNum >= 1 .AND. nNum <= Len( ::aFieldStruct ), ::aFieldStruct[ nNum ][ MYSQL_FS_LENGTH ], 0 )

METHOD FieldDec( nNum, lFormat ) CLASS TMySQLRow

   hb_default( @lFormat, .F. )

   IF nNum >= 1 .AND. nNum <= Len( ::aFieldStruct )

      IF ! lFormat .AND. ( ::aFieldStruct[ nNum ][ MYSQL_FS_TYPE ] == MYSQL_TYPE_FLOAT .OR. ;
                           ::aFieldStruct[ nNum ][ MYSQL_FS_TYPE ] == MYSQL_TYPE_DOUBLE )
         RETURN Set( _SET_DECIMALS )
      ELSE
         RETURN ::aFieldStruct[ nNum ][ MYSQL_FS_DECIMALS ]
      ENDIF
   ENDIF

   RETURN 0

METHOD FieldType( nNum ) CLASS TMySQLRow

   IF nNum >= 1 .AND. nNum <= Len( ::aFieldStruct )

      SWITCH ::aFieldStruct[ nNum ][ MYSQL_FS_TYPE ]
      CASE MYSQL_TYPE_TINY
      CASE MYSQL_TYPE_SHORT
      CASE MYSQL_TYPE_LONG
      CASE MYSQL_TYPE_LONGLONG
      CASE MYSQL_TYPE_FLOAT
      CASE MYSQL_TYPE_DOUBLE
      CASE MYSQL_TYPE_NEWDECIMAL
      CASE MYSQL_TYPE_INT24
         RETURN "N"

      CASE MYSQL_TYPE_VAR_STRING
      CASE MYSQL_TYPE_STRING
      CASE MYSQL_TYPE_DATETIME
         RETURN "C"

      CASE MYSQL_TYPE_DATE
         RETURN "D"

      CASE MYSQL_TYPE_BLOB
      CASE MYSQL_TYPE_MEDIUM_BLOB
         RETURN "M"

      ENDSWITCH
   ENDIF

   RETURN "U"

METHOD MakePrimaryKeyWhere() CLASS TMySQLRow

   LOCAL ni, cWhere := ""

   FOR nI := 1 TO Len( ::aFieldStruct )

      IF hb_bitAnd( ::aFieldStruct[ nI ][ MYSQL_FS_FLAGS ], PRI_KEY_FLAG ) == PRI_KEY_FLAG .OR. ;
         hb_bitAnd( ::aFieldStruct[ nI ][ MYSQL_FS_FLAGS ], MULTIPLE_KEY_FLAG ) == MULTIPLE_KEY_FLAG

         IF ! Empty( cWhere )
            cWhere += " AND "
         ENDIF

         cWhere += ::aFieldStruct[ nI ][ MYSQL_FS_NAME ] + "="

         IF ::aDirty[ nI ]
            cWhere += ClipValue2SQL( ::aOldValue[ nI ] )
         ELSE
            cWhere += ClipValue2SQL( ::aRow[ nI ] )
         ENDIF
      ENDIF
   NEXT

   IF ! Empty( cWhere )
      cWhere := " WHERE " + cWhere
   ENDIF

   RETURN cWhere

CREATE CLASS TMySQLQuery

   VAR nSocket
   VAR nResultHandle

   VAR cQuery

   VAR nNumRows
   VAR nCurRow

   VAR lBof
   VAR lEof

   VAR lFieldAsData

   VAR aRow

   VAR nNumFields
   VAR aFieldStruct

   VAR lError

   METHOD New( nSocket, cQuery )
   METHOD Destroy()
   METHOD End() INLINE ::Destroy()
   METHOD Refresh()

   METHOD GetRow( nRow )

   METHOD Skip( nRows )

   METHOD Bof() INLINE ::lBof
   METHOD Eof() INLINE ::lEof
   METHOD RecNo() INLINE ::nCurRow
   METHOD LastRec() INLINE ::nNumRows
   METHOD GoTop() INLINE ::GetRow( 1 )
   METHOD GoBottom() INLINE ::GetRow( ::nNumRows )
   METHOD GoTO( nRow ) INLINE ::GetRow( nRow )

   METHOD FCount()

   METHOD NetErr() INLINE ::lError
   METHOD Error()

   METHOD FieldName( nNum )
   METHOD FieldPos( cFieldName )
   METHOD FieldGet( cnField )

   METHOD FieldLen( nNum )
   METHOD FieldDec( nNum, lFormat )
   METHOD FieldType( nNum )

ENDCLASS

METHOD New( nSocket, cQuery ) CLASS TMySQLQuery

   LOCAL nI, aField

   ::nSocket := nSocket
   ::cQuery := cQuery

   ::lError := .F.
   ::aFieldStruct := {}
   ::nCurRow := 1
   ::nResultHandle := NIL
   ::nNumFields := 0
   ::nNumRows := 0
   ::lBof := .T.
   ::lEof := .T.

   ::lFieldAsData := .T.
   ::aRow := {}

   IF mysql_query( nSocket, cQuery ) == 0

      IF ! Empty( ::nResultHandle := mysql_store_result( nSocket ) )

         ::nNumRows := mysql_num_rows( ::nResultHandle )
         ::nNumFields := mysql_num_fields( ::nResultHandle )
         ::aRow := Array( ::nNumFields )

         FOR nI := 1 TO ::nNumFields
            aField := mysql_fetch_field( ::nResultHandle )
            AAdd( ::aFieldStruct, aField )
            IF ::lFieldAsData
               __objAddData( Self, ::aFieldStruct[ nI ][ MYSQL_FS_NAME ] )
            ENDIF
         NEXT

         ::getRow( ::nCurRow )
      ELSE
         ::nResultHandle := NIL
      ENDIF
   ELSE
      ::lError := .T.
   ENDIF

   RETURN Self

METHOD Refresh() CLASS TMySQLQuery

   ::nResultHandle := NIL

   ::lError := .F.

   IF mysql_query( ::nSocket, ::cQuery ) == 0

      ::nResultHandle := mysql_store_result( ::nSocket )
      ::nNumRows := mysql_num_rows( ::nResultHandle )

      IF ::nCurRow > ::nNumRows
         ::nCurRow := ::nNumRows
      ENDIF

      ::getRow( ::nCurRow )

   ELSE
      ::lError := .T.

   ENDIF

   RETURN ! ::lError

METHOD Skip( nRows ) CLASS TMySQLQuery

   LOCAL lBof

   hb_default( @nRows, 1 )

   ::lBof := Empty( ::LastRec() )

   IF nRows == 0

   ELSEIF nRows < 0

      IF ( ::RecNo() + nRows ) < 1
         nRows := - ::RecNo() + 1

         ::lBof := .T.
      ENDIF
   ELSE

      IF ( ::RecNo() + nRows ) > ::LastRec()
         nRows := ::LastRec() - ::RecNo() + 1
      ENDIF
   ENDIF

   ::nCurRow := ::nCurRow + nRows

   lBof := ::Bof()

   ::getRow( ::nCurrow )

   IF lBof
      ::lBof := .T.
   ENDIF

   RETURN NIL

METHOD GetRow( nRow ) CLASS TMySQLQuery

   LOCAL oRow := NIL
   LOCAL i


[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/common.ch. Defines constants: HB_COMMON_CH_, TRUE, FALSE, YES, NO. Declares 2 preprocessor commands. Declares 5 preprocessor translations. Defines Harbour internal constants and macros

[Assistant]
#ifndef HB_COMMON_CH_
#define HB_COMMON_CH_

#if defined( HB_LEGACY_LEVEL4 )
   #include "hbhash.ch"
#endif

#define TRUE                    .T.
#define FALSE                   .F.
#define YES                     .T.
#define NO                      .F.

#translate ISNIL( <xValue> )       => ( <xValue> == NIL )
#translate ISARRAY( <xValue> )     => HB_ISARRAY( <xValue> )
#translate ISBLOCK( <xValue> )     => HB_ISBLOCK( <xValue> )
#translate ISCHARACTER( <xValue> ) => HB_ISSTRING( <xValue> )
#translate ISDATE( <xValue> )      => HB_ISDATE( <xValue> )
#translate ISLOGICAL( <xValue> )   => HB_ISLOGICAL( <xValue> )
#translate ISMEMO( <xValue> )      => HB_ISMEMO( <xValue> )
#translate ISNUMBER( <xValue> )    => HB_ISNUMERIC( <xValue> )
#translate ISOBJECT( <xValue> )    => HB_ISOBJECT( <xValue> )

#xcommand DEFAULT <v1> TO <x1> [, <vn> TO <xn> ] => ;
                                IF <v1> == NIL ; <v1> := <x1> ; END ;
                                [; IF <vn> == NIL ; <vn> := <xn> ; END ]

#command UPDATE <v1> IF <exp> TO <v2> => ;
                                IF <exp> ; <v1> := <v2> ; END

#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] Create Harbour OOP classes for the functionality described: Harbour contribution module 'xhb' (Extended Harbour functions): contrib/xhb/hjwindow.prg. Defines classes: TJSWindow. This file provides legacy compatibility functions

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

CREATE CLASS TJSWindow

   VAR nH
   VAR Name INIT ""
   VAR oHtm
   VAR VarName INIT ""
   VAR URL INIT ""
   VAR Features INIT ""

   VAR ScreenX, ScreenY INIT 100
   VAR HEIGHT, WIDTH INIT 300
   VAR innerHeight, innerWidth, outerHeight INIT 0
   VAR alwaysRaised, alwaysLowered INIT .F.
   VAR Menubar, personalBar INIT .F.
   VAR location, directories, copyHistory INIT .F.
   VAR Toolbar INIT .F.
   VAR Status, TitleBar INIT .T.
   VAR Scrollbars, Resizable, dependent INIT .T.

   VAR TITLE
   VAR aScriptSRC
   VAR aServerSRC
   VAR BGIMAGE, BGCOLOR, fontColor
   VAR Style

   VAR onLoad
   VAR onUnLoad

   METHOD New( cVarName, cUrl, cName, x, y, w, h )
   METHOD setOnLoad( c ) INLINE ::onLoad := c
   METHOD setOnUnLoad( c ) INLINE ::onUnLoad := c
   METHOD Alert( c ) INLINE ::QOut( "Alert('" + c + "')" )
   METHOD confirm( c ) INLINE ::QOut( "confirm('" + c + "')" )
   METHOD SetSize( x, y, h, w )
   METHOD Write( c )
   METHOD lineBreak() INLINE ::QOut( "
" )
   METHOD Paragraph() INLINE ::QOut( "

" )
   METHOD Center( l ) INLINE ::QOut( iif( l, "", "" ) )
   METHOD bold( l ) INLINE ::QOut( iif( l, "", "" ) )
   METHOD Italic( l ) INLINE ::QOut( iif( l, "", "" ) )
   METHOD ULine( l ) INLINE ::QOut( iif( l, "", "" ) )
   METHOD Put()
   METHOD Begin()
   METHOD End()

   METHOD QOut( c )
   METHOD WriteLN( c ) INLINE ::QOut( c )
   METHOD SetFeatures( alwaysRaised, alwaysLowered, ;
      Resizable, Menubar, personalBar, ;
      dependent, location, directories, ;
      Scrollbars, Status, TitleBar, Toolbar, copyHistory )
   METHOD ImageURL( cImage, cUrl, nHeight, nBorder, ;
      cOnClick, cOnMsover, cOnMsout, ;
      cName, cAlt )

ENDCLASS

METHOD New( cVarName, cUrl, cName, x, y, w, h ) CLASS TJSWindow

   __defaultNIL( @cVarName, "newWin" )
   __defaultNIL( @cURL, " " )
   __defaultNIL( @cName, cVarName )
   __defaultNIL( @x, 100 )
   __defaultNIL( @y, 100 )
   __defaultNIL( @h, 300 )
   __defaultNIL( @w, 300 )

   ::nH      := HtmlPageHandle()
   ::oHtm    := HtmlPageObject()
   ::varName := cVarName
   ::URL     := cUrl
   ::Name    := cName

   ::ScreenX := x
   ::ScreenY := y
   ::height  := h
   ::width   := w

   RETURN Self

METHOD SetFeatures( alwaysRaised, alwaysLowered, ;
      Resizable, Menubar, personalBar, ;
      dependent, location, directories, ;
      Scrollbars, Status, TitleBar, Toolbar, copyHistory ) CLASS TJSWindow

   LOCAL cStr := ""

   __defaultNIL( @alwaysRaised, ::alwaysRaised )
   __defaultNIL( @alwaysLowered, ::alwaysLowered )
   __defaultNIL( @Resizable, ::Resizable )
   __defaultNIL( @Menubar, ::Menubar )
   __defaultNIL( @personalBar, ::personalBar )
   __defaultNIL( @dependent, ::dependent )
   __defaultNIL( @location, ::location )
   __defaultNIL( @directories, ::directories )
   __defaultNIL( @Scrollbars, ::Scrollbars )
   __defaultNIL( @Status, ::Status )
   __defaultNIL( @TitleBar, ::TitleBar )
   __defaultNIL( @Toolbar, ::Toolbar )
   __defaultNIL( @copyHistory, ::copyHistory )

   IF alwaysRaised
      cStr += "alwaysraised=yes,"
   ELSE
      cStr += "alwaysraised=no,"
   ENDIF
   IF alwaysLowered
      cStr += "alwayslowered=yes,"
   ELSE
      cStr += "alwayslowered=no,"
   ENDIF
   IF Resizable
      cStr += "resizable=yes,"
   ELSE
      cStr += "resizable=no,"
   ENDIF
   IF Menubar
      cStr += "menubar=yes,"
   ELSE
      cStr += "menubar=no,"
   ENDIF
   IF personalBar
      cStr += "personalbar=yes,"
   ELSE
      cStr += "personalbar=no,"
   ENDIF
   IF dependent
      cStr += "dependent=yes,"
   ELSE
      cStr += "dependent=no,"
   ENDIF
   IF location
      cStr += "location=yes,"
   ELSE
      cStr += "location=no,"
   ENDIF
   IF directories
      cStr += "directories=yes,"
   ELSE
      cStr += "directories=no,"
   ENDIF
   IF Scrollbars
      cStr += "scrollbars=yes,"
   ELSE
      cStr += "scrollbars=no,"
   ENDIF
   IF Status
      cStr += "status=yes,"
   ELSE
      cStr += "status=no,"
   ENDIF
   IF TitleBar
      cStr += "titlebar=yes,"
   ELSE
      cStr += "titlebar=no,"
   ENDIF
   IF Toolbar
      cStr += "toolbar=yes,"
   ELSE
      cStr += "toolbar=no,"
   ENDIF
   IF copyHistory
      cStr += "copyHistory=yes,"
   ELSE
      cStr += "copyHistory=no,"
   ENDIF

   ::features += iif( Empty( ::Features ), cStr + ",", cStr )

   RETURN Self

METHOD SetSize( x, y, h, w ) CLASS TJSWindow

   LOCAL cStr := ""

   __defaultNIL( @x, ::ScreenX )
   __defaultNIL( @y, ::ScreenY )
   __defaultNIL( @h, ::height )
   __defaultNIL( @w, ::width )

   ::ScreenX := x
   ::ScreenY := y
   ::height  := h
   ::width   := w

   cStr := "screenX=" + hb_ntos( ::screenX ) + ","

   cStr += "screenY=" + hb_ntos( ::screenY ) + ","
   cStr += "height=" + hb_ntos( ::height ) + ","
   cStr += "width=" + hb_ntos( ::width )

   ::features += iif( Empty( ::Features ), cStr + ",", cStr )

   RETURN Self

METHOD Put() CLASS TJSWindow

   LOCAL cStr := ""

   IF ::nH == NIL
      ::nH := HtmlPageHandle()
      IF ::nH == NIL
         RETURN Self
      ENDIF
   ENDIF

   IF Empty( ::features )
      ::setSize()
      ::setFeatures()
   ENDIF

   hb_default( @::name, "newWin" )

   cStr += ::varName + " = window.open('" + ;
      ::URL + "', '" + ;
      ::varName + "', '" + ;
      ::features + "')"

   HtmlJSCmd( ::nH, cStr )

   RETURN Self

METHOD Write( c ) CLASS TJSWindow

   HtmlJSCmd( ::nH, ::varName + ".document.write('" + c + "')" + CRLF() )

   RETURN Self

METHOD QOut( c ) CLASS TJSWindow

   FWrite( ::nH, ::varName + ".document.write('" + c + "')" + CRLF() )

   RETURN Self

METHOD Begin() CLASS TJSWindow

   LOCAL i

   FWrite( ::nH, "' )
      NEXT
   ENDIF

   IF ::aServerSrc != NIL
      FOR i := 1 TO Len( ::aServerSrc )
         ::QOut( ;
            '' )
      NEXT
   ENDIF

   IF ::Style != NIL
      ::QOut( "" )
   ENDIF

   ::QOut( "" + "' )

   IF ::bgColor != NIL
      ::QOut( '' )
   ENDIF

   IF ::fontColor != nil
      ::QOut( '' )
   ENDIF

   IF ::bgImage != nil
      ::QOut( '' )
   ENDIF

   FWrite( ::nH, "
   FWrite( ::nH, "</script>" + crlf() )

   RETURN Self

METHOD End() CLASS TJSWindow

   HtmlJSCmd( ::nH, ::varName + ".document.write('')" + CRLF() )

   RETURN Self

METHOD ImageURL( cImage, cUrl, nHeight, nBorder, ;
      cOnClick, cOnMsover, cOnMsout, ;
      cName, cAlt ) CLASS TJSWindow

   LOCAL cStr := ""

   __defaultNIL( @cUrl, "" )

   IF cName != NIL
      cStr += ' name= "' + cName + '"' + CRLF()
   ENDIF
   IF cAlt != NIL
      cStr += ' alt= "' + cAlt + '"' + CRLF()
   ENDIF

   IF nBorder != NIL
      cStr += " border= " + hb_ntos( nBorder ) + CRLF()
   ENDIF

   IF nHeight != NIL
      cStr += " height= " + hb_ntos( nHeight ) + "% " + CRLF()
   ENDIF

   IF cOnClick != NIL
      cStr += ' onClick="' + cOnClick + '"' + CRLF()
   ENDIF
   IF cOnMsOver != NIL
      cStr += ' onMouseOver="' + cOnMsOver + '"' + CRLF()
   ENDIF
   IF cOnMsOut != NIL
      cStr += ' onMouseOut="' + cOnMsOut + '"' + CRLF()
   ENDIF

   IF cURL != NIL
      ::QOut( '' )
   ELSE
      ::QOut( '<img src="' + cImage + '"' + ;


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

[User] Generate Harbour code for: Harbour test program: tests/newrdd.prg. Contains procedures: Main. This file handles database operations

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

REQUEST _DBF

PROCEDURE Main()

   LOCAL nI, aArray

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

   rddSetDefault( "DBF" )

   SET EXCLUSIVE OFF
   CLS

   dbUseArea( .T., "DBF", "test", "TESTDBF", .T., .F. )
   ? "RecCount:", TESTDBF->( RecCount() )
   ? "Used:", TESTDBF->( Used() )
   ? "Select:", TESTDBF->( Select() )
   ? "RecSize:", TESTDBF->( RecSize() )
   ? "RecNo:", TESTDBF->( RecNo() )
   ? "NetErr:", TESTDBF->( NetErr() )

   ? "Press any key to continue..."
   Inkey( 0 )
   CLS

   aArray := rddList( 0 )
   ? "Rdd's: "
   FOR nI := 1 TO Len( aArray )
      ?? aArray[ nI ], ""
   NEXT
   ? "RddName:", TESTDBF->( rddName() )
   ? "lUpdate:", TESTDBF->( LUpdate() )
   ? "Header:", TESTDBF->( Header() )
   ? "FieldPos( 'LAST' ):", TESTDBF->( FieldPos( "LAST" ) )
   ? "FieldName( 2 ):", TESTDBF->( FieldName( 2 ) )
   ? "Dbf():", TESTDBF->( Dbf() )
   ? "Alias( 1 ):", Alias( 1 )
   ? "dbTableExt():", TESTDBF->( dbTableExt() )
   aArray := TESTDBF->( dbStruct() )
   ? "dbStruct:"
   FOR nI := 1 TO Len( aArray )
      ? PadR( aArray[ nI ][ 1 ], 10 ), aArray[ nI ][ 2 ], aArray[ nI ][ 3 ], aArray[ nI ][ 4 ]
   NEXT

   ? "Press any key to continue..."
   Inkey( 0 )
   CLS

   ? "dbGoTop():"
   dbGoTop()
   ? "Bof Eof Found Deleted RecNo:", TESTDBF->( Bof() ), TESTDBF->( Eof() ), ;
      TESTDBF->( Found() ), TESTDBF->( Deleted() ), TESTDBF->( Deleted() ), ;
      TESTDBF->( RecNo() )
   ? "dbSkip( -1 ):"
   dbSkip( -1 )
   ? "Bof Eof Found Deleted RecNo:", TESTDBF->( Bof() ), TESTDBF->( Eof() ), ;
      TESTDBF->( Found() ), TESTDBF->( Deleted() ), TESTDBF->( Deleted() ), ;
      TESTDBF->( RecNo() )
   ? "dbSkip( -1 ):"
   dbSkip( -1 )
   ? "Bof Eof Found Deleted RecNo:", TESTDBF->( Bof() ), TESTDBF->( Eof() ), ;
      TESTDBF->( Found() ), TESTDBF->( Deleted() ), TESTDBF->( Deleted() ), ;
      TESTDBF->( RecNo() )
   ? "dbSkip( 1 ):"
   dbSkip( 1 )
   ? "Bof Eof Found Deleted RecNo:", TESTDBF->( Bof() ), TESTDBF->( Eof() ), ;
      TESTDBF->( Found() ), TESTDBF->( Deleted() ), TESTDBF->( Deleted() ), ;
      TESTDBF->( RecNo() )
   ? "dbSkip( 1 ):"
   dbSkip( 1 )
   ? "Bof Eof Found Deleted RecNo:", TESTDBF->( Bof() ), TESTDBF->( Eof() ), ;
      TESTDBF->( Found() ), TESTDBF->( Deleted() ), TESTDBF->( Deleted() ), ;
      TESTDBF->( RecNo() )
   ? "dbGoTop():"
   dbGoTop()
   ? "Bof Eof Found Deleted RecNo:", TESTDBF->( Bof() ), TESTDBF->( Eof() ), ;
      TESTDBF->( Found() ), TESTDBF->( Deleted() ), TESTDBF->( Deleted() ), ;
      TESTDBF->( RecNo() )
   ? "dbSkip( 1 ):"
   dbSkip( 1 )
   ? "Bof Eof Found Deleted RecNo:", TESTDBF->( Bof() ), TESTDBF->( Eof() ), ;
      TESTDBF->( Found() ), TESTDBF->( Deleted() ), TESTDBF->( Deleted() ), ;
      TESTDBF->( RecNo() )
   ? "dbSkip( 1 ):"
   dbSkip( 1 )
   ? "Bof Eof Found Deleted RecNo:", TESTDBF->( Bof() ), TESTDBF->( Eof() ), ;
      TESTDBF->( Found() ), TESTDBF->( Deleted() ), TESTDBF->( Deleted() ), ;
      TESTDBF->( RecNo() )
   ? "dbSkip( -1 ):"
   dbSkip( -1 )
   ? "Bof Eof Found Deleted RecNo:", TESTDBF->( Bof() ), TESTDBF->( Eof() ), ;
      TESTDBF->( Found() ), TESTDBF->( Deleted() ), TESTDBF->( Deleted() ), ;
      TESTDBF->( RecNo() )
   ? "dbSkip( -1 ):"
   dbSkip( -1 )
   ? "Bof Eof Found Deleted RecNo:", TESTDBF->( Bof() ), TESTDBF->( Eof() ), ;
      TESTDBF->( Found() ), TESTDBF->( Deleted() ), TESTDBF->( Deleted() ), ;
      TESTDBF->( RecNo() )
   Inkey( 0 )
   CLS

   ? "dbGoBottom():"
   dbGoBottom()
   ? "Bof Eof Found Deleted RecNo:", TESTDBF->( Bof() ), TESTDBF->( Eof() ), ;
      TESTDBF->( Found() ), TESTDBF->( Deleted() ), TESTDBF->( Deleted() ), ;
      TESTDBF->( RecNo() )
   ? "dbSkip( 1 ):"
   dbSkip( 1 )
   ? "Bof Eof Found Deleted RecNo:", TESTDBF->( Bof() ), TESTDBF->( Eof() ), ;
      TESTDBF->( Found() ), TESTDBF->( Deleted() ), TESTDBF->( Deleted() ), ;
      TESTDBF->( RecNo() )
   ? "dbSkip( 1 ):"
   dbSkip( 1 )
   ? "Bof Eof Found Deleted RecNo:", TESTDBF->( Bof() ), TESTDBF->( Eof() ), ;
      TESTDBF->( Found() ), TESTDBF->( Deleted() ), TESTDBF->( Deleted() ), ;
      TESTDBF->( RecNo() )
   ? "dbSkip( -1 ):"
   dbSkip( -1 )
   ? "Bof Eof Found Deleted RecNo:", TESTDBF->( Bof() ), TESTDBF->( Eof() ), ;
      TESTDBF->( Found() ), TESTDBF->( Deleted() ), TESTDBF->( Deleted() ), ;
      TESTDBF->( RecNo() )
   ? "dbSkip( -1 ):"
   dbSkip( -1 )
   ? "Bof Eof Found Deleted RecNo:", TESTDBF->( Bof() ), TESTDBF->( Eof() ), ;
      TESTDBF->( Found() ), TESTDBF->( Deleted() ), TESTDBF->( Deleted() ), ;
      TESTDBF->( RecNo() )

   ? "Press any key to continue..."
   Inkey( 0 )
   CLS

   ? "dbGoto( 490 ):"
   dbGoto( 490 )
   ? "Bof Eof Found Deleted RecNo:", TESTDBF->( Bof() ), TESTDBF->( Eof() ), ;
      TESTDBF->( Found() ), TESTDBF->( Deleted() ), TESTDBF->( Deleted() ), ;
      TESTDBF->( RecNo() )
   ? "FCount:", TESTDBF->( FCount() )
   FOR nI := 1 TO TESTDBF->( FCount() )
      ? "FieldGet( " + hb_ntos( nI ) + " ):", TESTDBF->( FieldGet( nI ) )
   NEXT

   ? "Press any key to continue..."
   Inkey( 0 )
   CLS

   ? "WHILE ! TESTDBF->( Eof() )"
   ? "   ? TESTDBF->FIRST, TESTDBF->( RecNo() )"
   ? "   TESTDBF->( dbSkip() )"
   ? "ENDDO"
   ? ""
   WHILE ! TESTDBF->( Eof() )
      ? TESTDBF->FIRST, TESTDBF->( RecNo() )
      TESTDBF->( dbSkip() )
   ENDDO

   ? "Press any key to continue..."
   Inkey( 0 )
   CLS

   ? "SET FILTER TO TESTDBF->AGE == 21"
   ? "? TESTDBF->( dbFilter() )"
   ? "TESTDBF->( dbGoTop() )"
   ? "WHILE ! TESTDBF->( Eof() )"
   ? "   ? TESTDBF->FIRST, TESTDBF->AGE, TESTDBF->( RecNo() )"
   ? "   TESTDBF->( dbSkip() )"
   ? "ENDDO"
   ? "SET FILTER TO"
   ? ""
   SET FILTER TO TESTDBF->AGE == 21
   ? TESTDBF->( dbFilter() )
   TESTDBF->( dbGoTop() )
   WHILE ! TESTDBF->( Eof() )
      ? TESTDBF->FIRST, TESTDBF->AGE, TESTDBF->( RecNo() )
      TESTDBF->( dbSkip() )
   ENDDO
   SET FILTER TO

   ? "Press any key to continue..."
   Inkey( 0 )
   CLS

   ? "TESTDBF->( Found() )"
   ? "LOCATE FOR TESTDBF->AGE == 23"
   ? "WHILE TESTDBF->( Found() )"
   ? "   ? TESTDBF->FIRST, TESTDBF->AGE, TESTDBF->( RecNo() )"
   ? "   CONTINUE"
   ? "ENDDO"
   TESTDBF->( Found() )
   LOCATE FOR TESTDBF->AGE == 23
   WHILE TESTDBF->( Found() )
      ? TESTDBF->FIRST, TESTDBF->AGE, TESTDBF->( RecNo() )
      CONTINUE
   ENDDO

   ? "Press any key to continue..."
   Inkey( 0 )
   CLS

   ? "TESTDBF->( dbEval( {|| QOut( TESTDBF->FIRST, TESTDBF->AGE ) }, ;"
   ? "                   {|| TESTDBF->AGE == 23 } ) )"
   ? ""
   ? "dbCommit()"
   TESTDBF->( dbEval( {|| QOut( TESTDBF->FIRST, TESTDBF->AGE ) }, ;
      {|| TESTDBF->AGE == 23 } ) )
   TESTDBF->( dbCommit() )

   ? "Press any key to continue..."
   Inkey( 0 )
   CLS

   ? 'dbCreate( "newrdd", { ;'
   ? '   { "First_Name", "C", 20, 0 }, ;'
   ? '   { "Age",        "N",  3, 0 }, ;'
   ? '   { "Date",       "D",  8, 0 }, ;'
   ? '   { "Rate",       "N",  6, 2 }, ;'
   ? '   { "Memo",       "M", 10, 0 }, ;'
   ? '   { "Student",    "L",  1, 0 } },, .T., "newrdd" )'
   ? 'SET CENTURY ON'
   dbCreate( "newrdd", { ;
      { "First_Name", "C", 20, 0 }, ;
      { "Age",        "N",  3, 0 }, ;
      { "Date",       "D",  8, 0 }, ;
      { "Rate",       "N",  6, 2 }, ;
      { "Memo",       "M", 10, 0 }, ;
      { "Student",    "L",  1, 0 } }, "DBFCDX", .T., "newrdd" )
   SET CENTURY ON
   ? "lUpdate:", NEWRDD->( LUpdate() )

   ? "Press any key to continue..."
   Inkey( 0 )
   CLS

   ? 'Select( "TESTDBF" )'
   ? "SET FILTER TO TESTDBF->SALARY > 120000"
   ? "TESTDBF->( dbGoTop() )"
   ? "WHILE ! TESTDBF->( Eof() )"
   ? "   NEWRDD->( dbAppend() )"
   ? "   NEWRDD->FIRST_NAME := TESTDBF->FIRST"
   ? "   NEWRDD->AGE := TESTDBF->AGE"
   ? "   NEWRDD->DATE := TESTDBF->HIREDATE"
   ? "   NEWRDD->RATE := Val( Right( hb_ntos( Seconds() ), 5 ) )"
   ? "   NEWRDD->MEMO := TESTDBF->FIRST + Chr( 13 ) + Chr( 10 ) + ;"
   ? "                   TESTDBF->LAST + Chr( 13 ) + Chr( 10 ) + ;"
   ? "                   TESTDBF->STREET"


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

[Assistant]
PROCEDURE Main()

   LOCAL oForm := TForm():New()

   ? oForm:ClassName()
   oForm:cText := "Let's show a form here :-)"

   oForm:Show()

   RETURN

FUNCTION TForm()

   STATIC s_oClass

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

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

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

      s_oClass:Create()
   ENDIF

   RETURN s_oClass:Instance()

STATIC FUNCTION New()

   LOCAL Self := QSelf()

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

   RETURN Self


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

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

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

[Assistant]
#require "hbnf"

PROCEDURE Main()

   LOCAL datamenu := { ;
      { "Customers", , {|| cust()    } }, ;
      { "Invoices",  , {|| inv()     } }, ;
      { "Vendors",   , {|| vendors() } }, ;
      { "Exit", "Return to Main Menu" } }

   LOCAL repmenu :=  { ;
      { "Customer List", , {|| custrep()   } }, ;
      { "Past Due",      , {|| pastdue()   } }, ;
      { "Weekly Sales",  , {|| weeksales() } }, ;
      { "Monthly P&L",   , {|| monthpl()   } }, ;
      { "Vendor List",   , {|| vendorrep() } }, ;
      { "Exit", "Return to Main Menu" } }

   LOCAL maintmenu := { ;
      { "Reindex",  "Rebuild index files", {|| re_ntx() } }, ;
      { "Backup",   "Backup data files"  , {|| backup() } }, ;
      { "Compress", "Compress data files", {|| compress() } }, ;
      { "Exit",     "Return to Main Menu" } }

   LOCAL MAINMENU := { ;
      { "DATA ENTRY",  "ENTER DATA",          {|| ft_Menu2( datamenu )  } }, ;
      { "Reports",     "Hard copy",           {|| ft_Menu2( repmenu )   } }, ;
      { "Maintenance", "Reindex files, etc.", {|| ft_Menu2( maintmenu ) } }, ;
      { "Quit",        "See ya later" } }

   CLS

   ft_Menu2( mainmenu )

   RETURN

STATIC PROCEDURE cust() ; RETURN
STATIC PROCEDURE inv() ; RETURN
STATIC PROCEDURE vendors() ; RETURN
STATIC PROCEDURE custrep() ; RETURN
STATIC PROCEDURE pastdue() ; RETURN
STATIC PROCEDURE weeksales() ; RETURN
STATIC PROCEDURE monthpl() ; RETURN
STATIC PROCEDURE vendorrep() ; RETURN
STATIC PROCEDURE re_ntx() ; RETURN
STATIC PROCEDURE backup() ; RETURN
STATIC PROCEDURE compress() ; RETURN


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

[User] Create Harbour preprocessor definitions: Harbour contribution module 'hbgd' (Graphics drawing library (GD)): contrib/hbgd/tests/test.prg. Contains procedures: Main. This file provides graphics and image processing capabilities

[Assistant]
#require "hbgd"

#define IMAGES_OUT "imgs_out" + hb_ps()

PROCEDURE Main()

   LOCAL im, im2, col, i

   im := gdImageCreateTrueColor( 100, 100 )
   col := gdImageColorAllocate( im, 255, 255, 255 )

   FOR i := 0 TO 99 STEP 10
      gdImageLine( im, i, 0, i, 99, col )
      gdImageLine( im, 0, i, 99, i, col )
   NEXT

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

   im2 := gdImageSquareToCircle( im, 400 )

   gdImagePng( im2, IMAGES_OUT + "gdtest_squared.png" )

   RETURN


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

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

Harbour contribution module 'hbnf' (NanForum Toolkit - legacy Clipper compatibility functions): contrib/hbnf/year.prg. Provides functions: ft_Year. This file provides legacy compatibility functions

[Assistant]
FUNCTION ft_Year( dGivenDate )

   LOCAL aRetVal[ 3 ]

   LOCAL cFY_Start := ft_DateCnfg()[ 1 ]

   IF ! HB_ISDATE( dGivenDate )
      dGivenDate := Date()
   ENDIF

   aRetVal[ 2 ] := hb_SToD( ;
      StrZero( Year( dGivenDate ) - iif( Month( dGivenDate ) < Month( hb_CToD( cFY_Start, "yyyy.mm.dd" ) ), 1, 0 ), 4 ) + ;
      SubStr( cFY_Start, 6, 2 ) + ;
      SubStr( cFY_Start, 9, 6 ) )
   aRetval[ 3 ] := ft_MAdd( aRetVal[ 2 ], 12 ) - 1
   aRetVal[ 1 ] := Str( Year( aRetVal[ 3 ] ), 4 )

   RETURN aRetVal