[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 'hbzebra' (Barcode generation library): contrib/hbzebra/tests/pclqr.prg. Contains procedures: Main, DrawBarcodePCL, PclWriteBitmap. This file provides graphics and image processing capabilities

[Assistant]
#require "hbzebra"

#define WIDTH     10

REQUEST HB_GT_CGI_DEFAULT

PROCEDURE Main( nDpi, nX, nY, cCode, cLabel, cFile, ... )
   LOCAL n

   IF HB_ISSTRING( nDpi )
      nDpi := Val( nDpi )
   ELSE
      nDpi := 300
   ENDIF

   IF HB_ISSTRING( nX )
      nX := Val( nX )
   ENDIF

   IF HB_ISSTRING( nY )
      nY := Val( nY )
   ENDIF

   IF PCount() > 6
      FOR n := 7 TO PCount()
         cFile += " " + hb_PValue( n )
      NEXT
   ENDIF

   IF Empty( cCode )
      cCode := "https:
   ENDIF

   DrawBarcodePCL( WIDTH, "QRCODE",, nDpi, nX, nY, cCode, cLabel, cFile )

   RETURN

STATIC PROCEDURE DrawBarcodePCL( nLineWidth, cType, nFlags, nDpi, nX, nY, cCode, cLabel, cFile )

   LOCAL hZebra, cBitMap, nXPad, nYPad, ;
      nLineHeight, nWidth, nHeight

   SWITCH cType

   CASE "QRCODE"     ; hZebra := hb_zebra_create_qrcode( cCode, nFlags ); nLineHeight := nLineWidth ; EXIT
   ENDSWITCH

   IF hZebra != NIL
      IF hb_zebra_geterror( hZebra ) == 0

         IF nLineHeight == NIL
            nLineHeight := nLineWidth
         ? "Type", cType, "Code", cCode, "Error", hb_zebra_geterror( hZebra )
      ENDIF
      hb_zebra_destroy( hZebra )
   ELSE
      ? "Invalid barcode type", cType
   ENDIF

   RETURN

PROCEDURE PclWriteBitmap( cBitMap, nWidth, nHeight, nDpi, nX, nY, cLabel, cFile )

   LOCAL hFile, cContents, lPrepend := .T.
   LOCAL nRow, nBytesPerRow, nPos, cRow

   IF Empty( cFile )
      cFile := "output.pcl"
      lPrepend := .F.
   ENDIF

   IF ! Empty( lPrepend ) .AND. File( cFile )
      cContents := hb_MemoRead( cFile )
   ENDIF

   hFile := FCreate( cFile )
   IF hFile < 0
      ? "Cannot create file:", cFile
      RETURN
   ENDIF

   nBytesPerRow := Int( ( nWidth + 7 ) / 8 )

   FWrite( hFile, Chr( 27 ) + "*t" + hb_ntos( nDpi ) + "R" )

   IF ! Empty( nX )
      FWrite( hFile, Chr( 27 ) + "*p" + hb_ntos( Int( nDpi * nX ) ) + "X" )
   ENDIF

   IF ! Empty( nY )
      FWrite( hFile, Chr( 27 ) + "*p" + hb_ntos( Int( nDpi * nY ) ) + "Y" )
   ENDIF

   FWrite( hFile, Chr( 27 ) + "*r1U" )
   FWrite( hFile, Chr( 27 ) + "*r0F" )

   IF Empty( nX )
      FWrite( hFile, Chr( 27 ) + "*r0A" )
   ELSE
      FWrite( hFile, Chr( 27 ) + "*r1A" )
   ENDIF

   FWrite( hFile, Chr( 27 ) + "*r" + hb_ntos( nHeight ) + "T" )

   nPos := 1
   FOR nRow := 1 TO nHeight
      cRow := hb_BSubStr( cBitMap, nPos, nBytesPerRow )

      nPos += nBytesPerRow

      FWrite( hFile, Chr( 27 ) + "*b" + hb_ntos( nBytesPerRow ) + "W" )
      FWrite( hFile, cRow )
   NEXT

   FWrite( hFile, Chr( 27 ) + "*rC" )

   IF ! Empty( cLabel ) .AND. ! cLabel == "."
      cLabel := StrTran( cLabel, "~", " " )
      FWrite( hFile, Chr( 10 ) )
      IF ! Empty( nX )
         FWrite( hFile, Chr( 27 ) + "*p" + hb_ntos( Int( nDpi * nX ) ) + "X" )
      ENDIF
      FWrite( hFile, cLabel )
   ENDIF

   FWrite( hFile, Chr( 27 ) + "*p0X" )
   FWrite( hFile, Chr( 27 ) + "*p0Y" )

   IF ! Empty( cContents )
      FWrite( hFile, cContents )
   ENDIF

   FClose( hFile )

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

[Assistant]
#require "hbtip"

PROCEDURE Main( cFileName )

   LOCAL oMail, cData, i

   IF ! HB_ISSTRING( cFileName ) .OR. ;
      ( cData := hb_MemoRead( cFileName ) ) == ""

      ? "Cannot open", cFileName
      RETURN
   ENDIF

   oMail := TIPMail():New()
   IF oMail:FromString( cData ) == 0
      ? "Malformed mail. Dumping up to where parsed"
   ENDIF

   ? PadC( " HEADERS ", 60, "-" )
   FOR EACH i IN oMail:hHeaders
      ? i:__enumKey(), ":", i
   NEXT
   ?

   ? PadC( " RECEIVED ", 60, "-" )
   FOR EACH cData IN oMail:aReceived
      ? cData
   NEXT
   ?

   ? PadC( " BODY ", 60, "-" )
   ? oMail:GetBody()
   ?

   DO WHILE oMail:GetAttachment() != NIL
      ? PadC( " ATTACHMENT ", 60, "-" )
      ? oMail:NextAttachment():GetBody()
      ?
   ENDDO

   ? "DONE"
   ?

   RETURN


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

[User] Generate Harbour code for: Harbour contribution module 'hbsms' (SMS sending via modem): contrib/hbsms/tests/send.prg. Contains procedures: Main. This file provides utility functions

[Assistant]
#require "hbsms"

PROCEDURE Main( cPort )

#if   defined( __PLATFORM__WINDOWS )
   hb_default( @cPort, "\\.\COM22" )
#elif defined( __PLATFORM__LINUX )
   hb_default( @cPort, "/dev/ttyS1" )
#elif defined( __PLATFORM__DARWIN )
   hb_default( @cPort, "/dev/cu.myport-COM1-1" )
#endif

   ? "start"
   ? sms_Send( cPort, "555555555", "test msg", .T. )
   ? "end"

   RETURN


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

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

[Assistant]
PROCEDURE Main()

   LOCAL cShell

#if defined( __PLATFORM__UNIX )
   cShell := GetEnv( "SHELL" )
#else
   cShell := GetEnv( "COMSPEC" )
#endif

   ? "About to shell to OS.."
   ! ( cShell )
   ? "Hey, I am back !"

   RETURN


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

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

[Assistant]
PROCEDURE Main()

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

   CLS
   SET CENTURY ON
   @ 2, 39 TO 7, 39 DOUBLE
   @ 0, 0 SAY "Testing @ SAY with and without PICTURE clauses"
   @ 0, 60 SAY Date()
   SET CENTURY OFF
   @ 2, 1  SAY -1.25
   @ 2, 41 SAY -1.25   PICTURE "@( 99,999.99"
   @ 3, 1  SAY  1.25   PICTURE "@( 9,999.99"
   @ 3, 41 SAY  1.25   PICTURE "@( $9,999.99"
   @ 5, 1  SAY Date()
   @ 5, 41 SAY Date()  PICTURE "@E"
   @ 7, 1  SAY "Hello"
   @ 7, 41 SAY "Hello" PICTURE "@!"

   RETURN


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

[User] Generate Harbour code for: Harbour contribution module 'hbnf' (NanForum Toolkit - legacy Clipper compatibility functions): contrib/hbnf/acctmnth.prg. Provides functions: ft_AcctMonth. This file provides legacy compatibility functions

[Assistant]
FUNCTION ft_AcctMonth( dGivenDate, nMonthNum )

   LOCAL nYTemp, nMTemp, aRetVal

   IF HB_ISNUMERIC( dGivenDate )
      nMonthNum := dGivenDate
      dGivenDate := Date()
   ELSEIF ! HB_ISDATE( dGivenDate )
      dGivenDate := Date()
   ENDIF

   aRetVal := ft_Month( dGivenDate )
   nYTemp := Val( SubStr( aRetVal[ 1 ], 1, 4 ) )
   nMTemp := Val( SubStr( aRetVal[ 1 ], 5, 2 ) )
   aRetVal[ 2 ] := ft_AcctAdj( aRetVal[ 2 ] )
   aRetVal[ 3 ] := ft_AcctAdj( aRetVal[ 3 ], .T. )

   IF dGivenDate < aRetVal[ 2 ]

      dGivenDate := ft_MAdd( dGivenDate, -1 )
      aRetVal    := ft_Month( dGivenDate )
      nMTemp     -= 1
      IF nMTemp  == 0
         nYTemp -= 1
         nMTemp := 12
      ENDIF
      aRetVal[ 2 ] := ft_AcctAdj( aRetVal[ 2 ] )
      aRetVal[ 3 ] := ft_AcctAdj( aRetVal[ 3 ], .T. )

   ELSEIF dGivenDate > aRetVal[ 3 ]

      dGivenDate := ft_MAdd( dGivenDate, 1 )
      aRetVal    := ft_Month( dGivenDate )
      nMTemp     += 1
      IF nMTemp == 13
         nYTemp += 1
         nMTemp := 1
      ENDIF
      aRetVal[ 2 ] := ft_AcctAdj( aRetVal[ 2 ] )
      aRetVal[ 3 ] := ft_AcctAdj( aRetVal[ 3 ], .T. )

   ENDIF

   IF HB_ISNUMERIC( nMonthNum )
      IF nMonthNum < 1 .OR. nMonthNum > 12
         nMonthNum := 12
      ENDIF
      aRetVal      := ft_Month( dGivenDate, nMonthNum )
      nYTemp       := Val( SubStr( aRetVal[ 1 ], 1, 4 ) )
      nMTemp       := Val( SubStr( aRetVal[ 1 ], 5, 2 ) )
      aRetVal[ 2 ] := ft_AcctAdj( aRetVal[ 2 ] )
      aRetVal[ 3 ] := ft_AcctAdj( aRetVal[ 3 ], .T. )
   ENDIF

   aRetVal[ 1 ] := Str( nYTemp, 4 ) + StrZero( nMTemp, 2 )

   RETURN aRetVal


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

[User] Generate Harbour code for: Harbour contribution module 'hbct' (CA-Tools compatibility library): contrib/hbct/tests/atadjust.prg. Contains procedures: Main. This file provides legacy compatibility functions

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

#include "ct.ch"

PROCEDURE Main()

   LOCAL aStr := { ;
      "Introduction: 1", ;
      "Theory: 5", ;
      "Material and Methods: 13", ;
      "Results: 19", ;
      "Discussion: 21" }
   LOCAL ni

   ctinit()

   ? "Begin test of AtAdjust()"
   ?

   ? "  Original strings:"
   FOR ni := 1 TO Len( aStr )
      ? Space( 4 ) + aStr[ ni ]
   NEXT
   ?

   ? '  AtAdjust( ":", aStr[ ni ], 21, 1,, "." ) yields'
   FOR ni := 1 TO Len( aStr )
      ? Space( 4 ) + AtAdjust( ":", aStr[ ni ], 21, 1,, "." )
   NEXT
   ?

   ? '  AtAdjust( ":", aStr[ ni ], 10, 1,, "." ) yields'
   FOR ni := 1 TO Len( aStr )
      ? Space( 4 ) + AtAdjust( ":", aStr[ ni ], 10, 1,, "." )
   NEXT
   ?

   ? '  SetAtLike( CT_SETATLIKE_WILDCARD, ":" )'
   ? '  AtAdjust( ":", aStr[ ni ], 10, 1,, "." ) yields now'
   SetAtLike( CT_SETATLIKE_WILDCARD, ":" )
   FOR ni := 1 TO Len( aStr )
      ? Space( 4 ) + AtAdjust( ":", aStr[ ni ], 10, 1,, "." )
   NEXT
   ?

   ? "End test of AtAdjust()"
   ?

   ctexit()

   RETURN


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

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

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

[Assistant]
#require "hbwin"

PROCEDURE Main()

   LOCAL nPrn := 1
   LOCAL cFileName := Space( 40 )
   LOCAL GetList := {}

   LOCAL aPrn := win_printerList()

   CLS

   IF Empty( aPrn )
      Alert( "No printers installed - Cannot continue" )
   ELSE
      DO WHILE nPrn != 0
         CLS
         @ 0, 0 SAY "win_PrintFileRaw() test program. Choose a printer to test"
         @ 1, 0 SAY "File name:" GET cFileName PICT "@!K"
         READ
         @ 2, 0 TO MaxRow(), MaxCol()
         nPrn := AChoice( 3, 1, MaxRow() - 1, MaxCol() - 1, aPrn, .T.,, nPrn )
         IF nPrn != 0
            PrnTest( aPrn[ nPrn ], cFileName )
         ENDIF
      ENDDO
   ENDIF

   RETURN

STATIC PROCEDURE PrnTest( cPrinter, cFileName )

   LOCAL lDelete

   IF Empty( cFileName )
      hb_MemoWrit( cFileName := hb_FNameExtSet( __FILE__, ".prn" ), "Hello World!" + Chr( 12 ) )
      lDelete := .T.
   ELSE
      lDelete := .F.
   ENDIF

   Alert( "win_PrintFileRaw() returned: " + hb_ntos( win_PrintFileRaw( cPrinter, cFileName, "testing raw printing" ) ) )

   IF lDelete
      FErase( cFileName )
   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 'hbunix' (Unix-specific functions): contrib/hbunix/tests/daemon.prg. Contains procedures: Main. This file provides platform-specific functionality

[Assistant]
#require "hbunix"

REQUEST HB_GT_CGI_DEFAULT

PROCEDURE Main()

   LOCAL cLogFile, cLogText

   cLogFile := hb_ps() + CurDir() + hb_ps() + hb_FNameExtSet( __FILE__, ".txt" )

   ? hb_StrFormat( "Parent(%d) launching child... ", posix_getpid() )

   IF unix_daemon( 0, 0 ) == -1
      ? hb_StrFormat( "failed with errno=%d", posix_errno() )
      ErrorLevel( 1 )
   ELSE
      IF hb_FileExists( cLogFile )
         FErase( cLogFile )
      ENDIF

      ? "***" + hb_eol() + "* If you see this, something is b0rked" + hb_eol() + "***"

      cLogText := hb_StrFormat( "Hello, this is the daemon child(%d) writing.", posix_getpid() ) + hb_eol()
      cLogText += hb_StrFormat( "I am currenty residing in %s and ", hb_ps() + CurDir() ) + hb_eol()
      cLogText += hb_StrFormat( "am writing this message to %s", cLogFile ) + hb_eol()
      cLogText += "Good bye now." + hb_eol()

      hb_MemoWrit( cLogFile, cLogText )
   ENDIF

   RETURN


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

[User] Implement these Harbour functions: Harbour contribution module 'hbnf' (NanForum Toolkit - legacy Clipper compatibility functions): contrib/hbnf/nooccur.prg. Provides functions: ft_NoOccur. This file provides legacy compatibility functions

[Assistant]
FUNCTION ft_NoOccur( cCheckFor, cCheckIn, lIgnoreCase )

   IF ! HB_ISLOGICAL( lIgnoreCase ) .OR. lIgnoreCase
      cCheckFor := Upper( cCheckFor )
      cCheckIn  := Upper( cCheckIn  )
   ENDIF

   RETURN iif( Len( cCheckFor ) == 0 .OR. Len( cCheckIn ) == 0, ;
      0, ;
      Int( ( Len( cCheckIn ) - Len( StrTran( cCheckIn, cCheckFor ) ) ) / ;
      Len( cCheckFor ) ) )


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

[User] Define Harbour macros and constants: Harbour contribution module 'hbnf' (NanForum Toolkit - legacy Clipper compatibility functions): contrib/hbnf/pchr.prg. Provides functions: ft_PChr. This file provides legacy compatibility functions

[Assistant]
#define LEFTEQUAL( l, r )       ( Left( l, Len( r ) ) == r )

FUNCTION ft_PChr( c_nums )

   LOCAL c_ret := "", c_st := 0, c_part, c_st2, c_hex := "0123456789ABCDEF"
   LOCAL c_upper, c_t1, c_t2

   IF Left( c_nums, 1 ) == "," .OR. RTrim( c_nums ) == ""
      RETURN ""
   ENDIF

   c_nums := RTrim( c_nums ) + ",~,"
   c_part := SubStr( c_nums, c_st + 1, At( ",", SubStr( c_nums, c_st + 2 ) ) )

   DO WHILE ! ( c_part == "~" .OR. c_part == "" )

      IF Left( c_part, 1 ) == '"'

         c_st2 := At( '"', SubStr( c_part, 2 ) ) + 1
         c_ret := c_ret + SubStr( c_part, 2, c_st2 - 2 )

      ELSEIF Left( c_part, 1 ) == "&"

         c_upper := Upper( c_part )
         c_t1 := At( SubStr( c_upper, 2, 1 ), c_hex ) - 1
         IF c_t1 > -1
            c_t2 := At( SubStr( c_upper, 3, 1 ), c_hex ) - 1
            IF c_t2 > -1
               c_t1 := c_t1
      ELSEIF ( Val( c_part ) > 0 .AND. Val( c_part ) < 256 ) .OR. c_part == "0"

         c_ret := c_ret + Chr( Val( c_part ) )

      ELSE

         IF Left( c_part, 1 ) == "/"

            c_upper := Upper( c_part )

            DO CASE
            CASE LEFTEQUAL( c_upper, "/GRAPHIC" )
               c_ret += hb_BChar( 27 ) + hb_BChar( 116 ) + hb_BChar( 1 )
            CASE LEFTEQUAL( c_upper, "/ITALIC" )
               c_ret += hb_BChar( 27 ) + hb_BChar( 116 ) + hb_BChar( 0 )
            CASE LEFTEQUAL( c_upper, "/PICTURE" )
               c_ret += ;
                  hb_BChar( 27 ) + hb_BChar( 116 ) + hb_BChar( 1 ) + ;
                  hb_BChar( 27 ) + hb_BChar( 120 ) + hb_BChar( 1 ) + ;
                  hb_BChar( 27 ) + hb_BChar( 107 ) + hb_BChar( 1 ) + ;
                  hb_BChar( 27 ) + hb_BChar( 77 ) + hb_BChar( 27 ) + "U"
            CASE LEFTEQUAL( c_upper, "/COND" ) .OR. LEFTEQUAL( c_upper, "/SI" )
               c_ret += hb_BChar( 15 )
            CASE LEFTEQUAL( c_upper, "/ROMAN" )
               c_ret += hb_BChar( 27 ) + hb_BChar( 107 ) + hb_BChar( 0 )
            CASE LEFTEQUAL( c_upper, "/SANS" )
               c_ret += hb_BChar( 27 ) + hb_BChar( 107 ) + hb_BChar( 1 )
            CASE LEFTEQUAL( c_upper, "/NLQ" )
               c_ret += hb_BChar( 27 ) + hb_BChar( 120 ) + hb_BChar( 1 )
            CASE LEFTEQUAL( c_upper, "/DRAFT" )
               c_ret += hb_BChar( 27 ) + hb_BChar( 120 ) + hb_BChar( 0 )
            CASE LEFTEQUAL( c_upper, "/ELITE" )
               c_ret += hb_BChar( 27 ) + hb_BChar( 77 )
            CASE LEFTEQUAL( c_upper, "/PICA" )
               c_ret += hb_BChar( 27 ) + hb_BChar( 80 )
            CASE LEFTEQUAL( c_upper, "/EMPHOFF" )
               c_ret += hb_BChar( 27 ) + hb_BChar( 70 )
            CASE LEFTEQUAL( c_upper, "/EMPH" )
               c_ret += hb_BChar( 27 ) + hb_BChar( 69 )
            CASE LEFTEQUAL( c_upper, "/1/6" )
               c_ret += hb_BChar( 27 ) + hb_BChar( 50 )
            CASE LEFTEQUAL( c_upper, "/1/8" )
               c_ret += hb_BChar( 27 ) + hb_BChar( 48 )
            CASE LEFTEQUAL( c_upper, "/SKIPOFF" )
               c_ret += hb_BChar( 27 ) + hb_BChar( 79 )
            CASE LEFTEQUAL( c_upper, "/SKIP" )
               c_ret += hb_BChar( 27 ) + hb_BChar( 78 )
            CASE LEFTEQUAL( c_upper, "/FF" ) .OR. LEFTEQUAL( c_upper, "/EJECT" )
               c_ret += hb_BChar( 12 )
            CASE LEFTEQUAL( c_upper, "/INIT" ) .OR. LEFTEQUAL( c_upper, "/RESET" )
               c_ret += hb_BChar( 27 ) + hb_BChar( 64 )
            CASE LEFTEQUAL( c_upper, "/SPANISH" )
               c_ret += hb_BChar( 27 ) + hb_BChar( 82 ) + hb_BChar( 12 )
            CASE LEFTEQUAL( c_upper, "/USA" )
               c_ret += hb_BChar( 27 ) + hb_BChar( 82 ) + hb_BChar( 0 )
            CASE LEFTEQUAL( c_upper, "/ONE" )
               c_ret += hb_BChar( 27 ) + "U" + hb_BChar( 1 )
            CASE LEFTEQUAL( c_upper, "/TWO" )
               c_ret += hb_BChar( 27 ) + "U" + hb_BChar( 0 )
            CASE LEFTEQUAL( c_upper, "/FAST" )
               c_ret += hb_BChar( 27 ) + "s" + hb_BChar( 0 )
            CASE LEFTEQUAL( c_upper, "/SLOW" )
               c_ret += hb_BChar( 27 ) + "s" + hb_BChar( 1 )
            CASE LEFTEQUAL( c_upper, "/OFF" )
               c_ret += hb_BChar( 19 )
            CASE LEFTEQUAL( c_upper, "/ON" )
               c_ret += hb_BChar( 17 )
            CASE LEFTEQUAL( c_upper, "/BEEP" ) .OR. LEFTEQUAL( c_upper, "/BELL" )
               c_ret += hb_BChar( 7 )
            CASE LEFTEQUAL( c_upper, "/CAN" )
               c_ret += hb_BChar( 24 )
            ENDCASE

         ENDIF

      ENDIF

      c_st := At( ",", SubStr( c_nums, c_st + 1 ) ) + c_st
      c_part := SubStr( c_nums, c_st + 1, At( ",", SubStr( c_nums, c_st + 2 ) ) )

   ENDDO

   RETURN c_ret


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

[User] Define Harbour macros and constants: Harbour contribution module 'hbgd' (Graphics drawing library (GD)): contrib/hbgd/tests/fontdpi.prg. Contains procedures: Main. This file provides graphics and image processing capabilities

[Assistant]
#require "hbgd"

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

PROCEDURE Main()

   LOCAL oI := GDImage():Create( 600, 300 )

   LOCAL black := oI:SetColor( 50, 0, 0 )

   oI:SetColor( black )
   oI:SetFontName( "Arial" )
   oI:SetFontPitch( 10 )

   oI:SayFreeType( 10, 100, "GD_RESOLUTION:  96 dpi" )

   oI:SayFreeType( 10, 150, "GD_RESOLUTION: 150 dpi",,,,,,,, 150 )

   oI:SayFreeType( 10, 200, "GD_RESOLUTION: 300 dpi",,,,,,,, 300 )

   oI:SavePng(  IMAGES_OUT + "testdpi.png" )
   oI:SaveJpeg( IMAGES_OUT + "testdpi.jpg" )
   oI:SaveGif(  IMAGES_OUT + "testdpi.gif" )

   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 'hbmemio' (Memory file I/O operations): contrib/hbmemio/tests/test.prg. Contains procedures: Main. This file handles data format parsing and generation

[Assistant]
#require "hbmemio"

REQUEST HB_MEMIO

PROCEDURE Main()

   LOCAL tmp

   dbCreate( "mem:test", { { "F1", "N", 9, 0 } }, , .T., "memarea" )
   FOR tmp := 1 TO 1000
      dbAppend()
      FIELD->F1 := hb_Random()
   dbDrop( "mem:test" )

   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 these Harbour functions: Harbour test program: tests/sha2.prg. Provides functions: StrToHex. Contains procedures: Main, Test_SHA2, Test_SHA2_HMAC. This test file tests specific function APIs

[Assistant]
PROCEDURE Main()

   ? "SHA-2 FIPS 180-2 Validation tests"
   Test_SHA2()

   ? "HMAC-SHA-2 IETF Validation tests"
   Test_SHA2_HMAC()

   RETURN

STATIC PROCEDURE Test_SHA2()

   LOCAL cMsg1  := "abc"
   LOCAL cMsg2a := "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
   LOCAL cMsg2b := "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"
   LOCAL cMsg3  := Replicate( "a", 1000000 )

   LOCAL results := {;
      {;
         "23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7" ,;
         "75388b16512776cc5dba5da1fd890150b0c6455cb4f58b1952522525" ,;
         "20794655980c91d8bbb4c1ea97618a4bf03f42581948b2ee4ee7ad67" },;
      {;
        "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad" ,;
        "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1" ,;
        "cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0" },;
      {;
        "cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7" ,;
        "09330c33f71147e83d192fc782cd1b4753111b173b3b05d22fa08086e3b0f712fcc7c71a557e2db966c3e9fa91746039" ,;
        "9d0e1809716474cb086e834e310a4a1ced149e9c00f248527972cec5704c2a5b07b8b3dc38ecc4ebae97ddd87f3d8985" },;
      {;
        "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f" ,;
        "8e959b75dae313da8cf4f72814fc143f8f7779c6eb9f7fa17299aeadb6889018501d289e4900f7e4331b99dec4b5433ac7d329eeb6dd26545e96e55b874be909" ,;
        "e718483d0ce769644e2e42c7bc15b4638e1f98b13b2044285632a803afa973ebde0ff244877ea60a4cb0432ce577c31beb009c5c2c49aa2e4eadb217ad8cc09b" } }

   ? StrToHex( hb_SHA224( cMsg1  ) ) == results[ 1 ][ 1 ]
   ? StrToHex( hb_SHA224( cMsg2a ) ) == results[ 1 ][ 2 ]
   ? StrToHex( hb_SHA224( cMsg3  ) ) == results[ 1 ][ 3 ]

   ? StrToHex( hb_SHA256( cMsg1  ) ) == results[ 2 ][ 1 ]
   ? StrToHex( hb_SHA256( cMsg2a ) ) == results[ 2 ][ 2 ]
   ? StrToHex( hb_SHA256( cMsg3  ) ) == results[ 2 ][ 3 ]

   ? StrToHex( hb_SHA384( cMsg1  ) ) == results[ 3 ][ 1 ]
   ? StrToHex( hb_SHA384( cMsg2b ) ) == results[ 3 ][ 2 ]
   ? StrToHex( hb_SHA384( cMsg3  ) ) == results[ 3 ][ 3 ]

   ? StrToHex( hb_SHA512( cMsg1  ) ) == results[ 4 ][ 1 ]
   ? StrToHex( hb_SHA512( cMsg2b ) ) == results[ 4 ][ 2 ]
   ? StrToHex( hb_SHA512( cMsg3  ) ) == results[ 4 ][ 3 ]

   RETURN

STATIC PROCEDURE Test_SHA2_HMAC()
   LOCAL aMsg := {;
      "Hi There",;
      "what do ya want for nothing?",;
      Replicate( hb_BChar( 0xdd ), 50 ),;
      Replicate( hb_BChar( 0xcd ), 50 ),;
      "Test With Truncation",;
      "Test Using Larger Than Block-Size Key - Hash Key First",;
      "This is a test using a larger than block-size key and a larger than block-size data. The key needs to be hashed before being used by the HMAC algorithm." }

   LOCAL results := {;
      "896fb1128abbdf196832107cd49df33f47b4b1169912ba4f53684b22",;
      "a30e01098bc6dbbf45690f3a7e9e6d0f8bbea2a39e6148008fd05e44",;
      "7fb3cb3588c6c1f6ffa9694d7d6ad2649365b0c1f65d69d1ec8333ea",;
      "6c11506874013cac6a2abc1bb382627cec6a90d86efc012de7afec5a",;
      "0e2aea68a90c8d37c988bcdb9fca6fa8",;
      "95e9a0db962095adaebe9b2d6f0dbce2d499f112f2d2b7273fa6870e",;
      "3a854166ac5d9f023f54d517d0b39dbd946770db9c2b95c9f6f565d1",;
      "b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c2e32cff7",;
      "5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843",;
      "773ea91e36800e46854db8ebd09181a72959098b3ef8c122d9635514ced565fe",;
      "82558a389a443c0ea4cc819899f2083a85f0faa3e578f8077a2e3ff46729665b",;
      "a3b6167473100ee06e0c796c2955552b",;
      "60e431591ee0b67f0d8a26aacbf5b77f8e0bc6213728c5140546040f0ee37f54",;
      "9b09ffa71b942fcb27635fbcd5b0e944bfdc63644f0713938a7f51535c3a35e2",;
      "afd03944d84895626b0825f4ab46907f15f9dadbe4101ec682aa034c7cebc59cfaea9ea9076ede7f4af152e8b2fa9cb6",;
      "af45d2e376484031617f78d2b58a6b1b9c7ef464f5a01b47e42ec3736322445e8e2240ca5e69e2c78b3239ecfab21649",;
      "88062608d3e6ad8a0aa2ace014c8a86f0aa635d947ac9febe83ef4e55966144b2a5ab39dc13814b94e3ab6e101a34f27",;
      "3e8a69b7783c25851933ab6290af6ca77a9981480850009cc5577c6e1f573b4e6801dd23c4a7d679ccf8a386c674cffb",;
      "3abf34c3503b2a23a46efc619baef897",;
      "4ece084485813e9088d2c63a041bc5b44f9ef1012a2b588f3cd11f05033ac4c60c2ef6ab4030fe8296248df163f44952",;
      "6617178e941f020d351e2f254e8fd32c602420feb0b8fb9adccebb82461e99c5a678cc31e799176d3860e6110c46523e",;
      "87aa7cdea5ef619d4ff0b4241a1d6cb02379f4e2ce4ec2787ad0b30545e17cdedaa833b7d6b8a702038b274eaea3f4e4be9d914eeb61f1702e696c203a126854",;
      "164b7a7bfcf819e2e395fbe73b56e0a387bd64222e831fd610270cd7ea2505549758bf75c05a994a6d034f65f8f0e6fdcaeab1a34d4a6b4b636e070a38bce737",;
      "fa73b0089d56a284efb0f0756c890be9b1b5dbdd8ee81a3655f83e33b2279d39bf3e848279a722c806b485a47e67c807b946a337bee8942674278859e13292fb",;
      "b0ba465637458c6990e5a8c5f61d4af7e576d97ff94b872de76f8050361ee3dba91ca5c11aa25eb4d679275cc5788063a5f19741120c4f2de2adebeb10a298dd",;
      "415fad6271580a531d4179bc891d87a6",;
      "80b24263c7c1a3ebb71493c1dd7be8b49b46d1f41b4aeec1121b013783f8f3526b56d037e05f2598bd0fd2215d6a1e5295e64f73f63f0aec8b915a985d786598",;
      "e37b6a775dc87dbaa4dfa9f96e5e3ffddebd71f8867289865df5a32d20cdc944b6022cac3c4982b10d5eeb55c3e4de15134676fb6de0446065c97440fa8c6a58"}

   LOCAL keys := {;
      Replicate( hb_BChar( 0x0b ),  20 ),;
      "Jefe",;
      Replicate( hb_BChar( 0xaa ),  20 ),;
      "",;
      Replicate( hb_BChar( 0x0c ),  20 ),;
      Replicate( hb_BChar( 0xaa ), 131 ),;
      Replicate( hb_BChar( 0xaa ), 131 ) }

   LOCAL tmp

   FOR tmp := 1 TO 25
      keys[ 4 ] += hb_BChar( tmp )
   NEXT

   FOR tmp := 1 TO 7
      IF tmp != 5
         ? StrToHex( hb_HMAC_SHA224( aMsg[ tmp ], keys[ tmp ] ) ) == results[ tmp ]
         ? StrToHex( hb_HMAC_SHA256( aMsg[ tmp ], keys[ tmp ] ) ) == results[ tmp + 7 ]
         ? StrToHex( hb_HMAC_SHA384( aMsg[ tmp ], keys[ tmp ] ) ) == results[ tmp + 14 ]
         ? StrToHex( hb_HMAC_SHA512( aMsg[ tmp ], keys[ tmp ] ) ) == results[ tmp + 21 ]

      ENDIF
   NEXT

   RETURN

STATIC FUNCTION StrToHex( cString )
   RETURN Lower( cString )


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

[User] Implement this Harbour module: Harbour Runtime Library file: src/debug/dbgbrwsr.prg. Defines classes: HBDbBrowser, HBDbColumn. Provides functions: HBDbColumnNew. This file provides utility functions

[Assistant]
#pragma -b-

#define HB_CLS_NOTOBJECT
#include "hbclass.ch"

CREATE CLASS HBDbBrowser

   VAR Window
   VAR cargo

   VAR nTop
   VAR nLeft
   VAR nBottom
   VAR nRight
   VAR cColorSpec
   VAR autoLite INIT .T.

   VAR goTopBlock
   VAR goBottomBlock
   VAR skipBlock

   VAR stable INIT .F.
   VAR rowCount INIT 0
   VAR rowPos INIT 1
   VAR colCount INIT 0
   VAR colPos INIT 1
   VAR hitBottom INIT .F.
   VAR freeze INIT 0

   VAR aColumns INIT {}
   VAR aRowState INIT {}
   VAR aColorSpec INIT {}
   VAR nFirstVisible INIT 1
   VAR lConfigured INIT .F.

   METHOD New( nTop, nLeft, nBottom, nRight, oParentWindow )
   METHOD AddColumn( oCol )    INLINE AAdd( ::aColumns, oCol ), ::colCount++, Self
   METHOD Resize( nTop, nLeft, nBottom, nRight )
   ACCESS ColorSpec            INLINE ::cColorSpec
   ASSIGN ColorSpec( cColors ) METHOD SetColorSpec( cColors )
   METHOD Configure()
   METHOD DeHiLite()           INLINE ::DispRow( ::rowPos, .F. )
   METHOD HiLite()             INLINE ::DispRow( ::rowPos, .T. )
   METHOD DispRow( nRow, lHiLite )
   METHOD MoveCursor( nSkip )
   METHOD GoTo( nRow )
   METHOD GoTop()              INLINE ::GoTo( 1 ), ::rowPos := 1, ::nFirstVisible := 1, ::RefreshAll()
   METHOD GoBottom()
   METHOD Down()               INLINE ::MoveCursor( 1 )
   METHOD Up()                 INLINE ::MoveCursor( -1 )
   METHOD PageDown()           INLINE ::MoveCursor( ::rowCount )
   METHOD PageUp()             INLINE ::MoveCursor( -::rowCount )
   METHOD GetColumn( nColumn ) INLINE ::aColumns[ nColumn ]
   METHOD RefreshAll()         INLINE AFill( ::aRowState, .F. ), Self
   METHOD RefreshCurrent()     INLINE iif( ::rowCount >= 1 .AND. ::rowPos <= Len( ::aRowState ), ::aRowState[ ::rowPos ] := .F., ), Self
   METHOD Invalidate()         INLINE ::RefreshAll()
   METHOD Stabilize()          INLINE ::ForceStable()
   METHOD ForceStable()

ENDCLASS

METHOD New( nTop, nLeft, nBottom, nRight, oParentWindow ) CLASS HBDbBrowser

   ::Window := oParentWindow
   ::nTop := nTop
   ::nLeft := nLeft
   ::nBottom := nBottom
   ::nRight := nRight

   RETURN Self

METHOD Configure() CLASS HBDbBrowser

   ::rowCount := ::nBottom - ::nTop + 1
   IF ::rowPos > ::rowCount
      ::nFirstVisible += ::rowPos - ::rowCount
      ::rowPos := ::rowCount
   ENDIF
   AFill( ASize( ::aRowState, ::rowCount ), .F. )
   ::lConfigured := .T.

   RETURN Self

METHOD SetColorSpec( cColors ) CLASS HBDbBrowser

   IF HB_ISSTRING( cColors )
      ::cColorSpec := cColors
      ::aColorSpec := hb_ATokens( ::cColorSpec, "," )
   ENDIF

   RETURN ::cColorSpec

METHOD MoveCursor( nSkip ) CLASS HBDbBrowser

   LOCAL nSkipped

   nSkipped := ::GoTo( ::rowPos + ::nFirstVisible - 1 + nSkip )
   IF ! ::hitBottom .OR. nSkipped != 0
      IF iif( nSkipped > 0, ::rowPos + nSkipped <= ::rowCount, ::rowPos + nSkipped >= 1 )
         ::RefreshCurrent()
         ::rowPos += nSkipped
         ::RefreshCurrent()
      ELSE
         ::nFirstVisible := Max( 1, nSkipped + ::nFirstVisible )
         ::RefreshAll()
      ENDIF
   ENDIF

   RETURN Self

METHOD DispRow( nRow, lHiLite ) CLASS HBDbBrowser

   LOCAL nColX, nWid, aClr, nClr
   LOCAL xData
   LOCAL oCol

   ::GoTo( ::nFirstVisible + nRow - 1 )
   IF ::hitBottom
      hb_Scroll( ::nTop + nRow - 1, ::nLeft, ::nTop + nRow - 1, ::nRight,,, ::aColorSpec[ 1 ] )
   ELSE
      DispBegin()
      nColX := ::nLeft
      FOR EACH oCol IN ::aColumns
         IF nColX <= ::nRight
            xData := Eval( oCol:block )
            nClr := iif( lHiLite, 2, 1 )
            aClr := Eval( oCol:colorBlock, xData )
            IF HB_ISARRAY( aClr )
               nClr := aClr[ nClr ]
            ELSE
               nClr := oCol:defColor[ nClr ]
            ENDIF
            nWid := oCol:width
            IF nWid == NIL
               nWid := Len( xData )
            ENDIF
            hb_DispOutAt( ::nTop + nRow - 1, nColX, ;
                          Left( PadR( xData, nWid ) + iif( oCol:__enumIsLast(), "", " " ), ;
                                ::nRight - nColX + 1 ), ::aColorSpec[ nClr ] )
            nColX += nWid + 1
         ENDIF
      NEXT
      DispEnd()
   ENDIF

   RETURN Self

METHOD ForceStable() CLASS HBDbBrowser

   LOCAL nRow

   IF ! ::lConfigured
      ::Configure()
   ENDIF
   DispBegin()
   FOR nRow := 1 TO ::rowCount
      IF ! ::aRowState[ nRow ]
         ::DispRow( nRow, nRow == ::rowPos )
         ::aRowState[ nRow ] := .T.
      ENDIF
   NEXT
   ::GoTo( ::nFirstVisible + ::rowPos - 1 )
   SetPos( ::nTop + ::rowPos - 1, ::nLeft )
   DispEnd()

   RETURN Self

METHOD GoTo( nRow ) CLASS HBDbBrowser

   LOCAL nOldRow := ::nFirstVisible + ::rowPos - 1
   LOCAL nSkipped := 0

   Eval( ::goTopBlock )
   IF nRow == 1
      ::hitBottom := .F.
   ELSE
      nSkipped := Eval( ::skipBlock, nRow - 1 )
      ::hitBottom := ( nSkipped != nRow - 1 )
   ENDIF

   RETURN nSkipped - nOldRow + 1

METHOD GoBottom() CLASS HBDbBrowser

   LOCAL nScroll

   DO WHILE ! ::hitBottom
      ::PageDown()
   ENDDO
   IF ::rowPos < ::rowCount .AND. ::nFirstVisible > 1
      nScroll := Min( ::nFirstVisible - 1, ::rowCount - ::rowPos )
      ::nFirstVisible -= nScroll
      ::rowPos += nScroll
   ENDIF

   RETURN Self

METHOD Resize( nTop, nLeft, nBottom, nRight ) CLASS HBDbBrowser

   LOCAL lResize := .F.

   IF HB_ISNUMERIC( nTop ) .AND. nTop != ::nTop
      ::nTop := nTop
      lResize := .T.
   ENDIF
   IF HB_ISNUMERIC( nLeft ) .AND. nLeft != ::nLeft
      ::nLeft := nLeft
      lResize := .T.
   ENDIF
   IF HB_ISNUMERIC( nBottom ) .AND. nBottom != ::nBottom
      ::nBottom := nBottom
      lResize := .T.
   ENDIF
   IF HB_ISNUMERIC( nRight ) .AND. nRight != ::nRight
      ::nRight := nRight
      lResize := .T.
   ENDIF

   IF lResize
      ::Configure():ForceStable()
   ENDIF

   RETURN Self

CREATE CLASS HBDbColumn

   EXPORTED:

   VAR block      AS CODEBLOCK
   VAR colorBlock AS CODEBLOCK INIT {|| NIL }
   VAR defColor   AS ARRAY     INIT { 1, 2 }
   VAR width      AS USUAL

   METHOD New( cHeading, bBlock )

ENDCLASS

METHOD New( cHeading, bBlock ) CLASS HBDbColumn

   HB_SYMBOL_UNUSED( cHeading )
   ::block := bBlock

   RETURN Self

FUNCTION HBDbColumnNew( cHeading, bBlock )
   RETURN HBDbColumn():New( cHeading, bBlock )


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

[Assistant]
#require "hbfbird"

PROCEDURE Main()

   LOCAL oServer, oQuery, oRow, i, x

   LOCAL cServer := "localhost:"
   LOCAL cDatabase
   LOCAL cUser := "SYSDBA"
   LOCAL cPass := "masterkey"
   LOCAL nPageSize := 1024
   LOCAL cCharSet := "UTF8"
   LOCAL nDialect := 1
   LOCAL cQuery, cName

   CLS

   hb_FNameSplit( hb_argv( 0 ), NIL, @cName, NIL )
   cDatabase := hb_DirTemp() + cName + ".fdb"

   IF ! hb_FileExists( cDatabase )
      ? FBCreateDB( cServer + cDatabase, cUser, cPass, nPageSize, cCharSet, nDialect )
   ENDIF

   ? "Connecting..."

   oServer := TFBServer():New( cServer + cDatabase, cUser, cPass, nDialect )

   IF oServer:NetErr()
      ? oServer:Error()
      QUIT
   ENDIF

   IF oServer:TableExists( "test" )
      ? oServer:Execute( "DROP TABLE Test" )
      ? oServer:Execute( "DROP DOMAIN boolean_field" )
   ENDIF

   ? "Creating domain for boolean fields..."

   ? oServer:Execute( "create domain boolean_field as smallint default 0 not null check (value in (0,1))" )

   ? "Creating test table..."
   cQuery := "CREATE TABLE test("
   cQuery += "     Code SmallInt not null primary key, "
   cQuery += "     dept Integer, "
   cQuery += "     Name Varchar(40), "
   cQuery += "     Sales boolean_field, "
   cQuery += "     Tax Float, "
   cQuery += "     Salary Double Precision, "
   cQuery += "     Budget Numeric(12,2), "
   cQuery += "     Discount Decimal(5,2), "
   cQuery += "     Creation Date, "
   cQuery += "     Description blob sub_type 1 segment size 40 ) "

   ? "CREATE TABLE:", oServer:Execute( cQuery )

   oQuery := oServer:Query( "SELECT code, dept, name, sales, salary, creation FROM test" )

   oServer:StartTransaction()

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

      oRow := oQuery:Blank()

      oRow:FieldPut( 1, i )
      oRow:FieldPut( 2, i + 1 )
      oRow:FieldPut( 3, "DEPARTMENT NAME " + StrZero( i ) )
      oRow:FieldPut( 4, ( i % 10 ) == 0 )
      oRow:FieldPut( 5, 3000 + i )
      oRow:FieldPut( 6, Date() )

      oServer:Append( oRow )

      IF i % 100 == 0
         oServer:Commit()
         oServer:StartTransaction()
      ENDIF
   NEXT

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

      oRow := oQuery:Blank()
      oServer:Delete( oRow, "code = " + Str( i ) )

      IF i % 100 == 0
         oServer:Commit()
         oServer:StartTransaction()
      ENDIF
   NEXT

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

      oRow := oQuery:Blank()
      oRow:FieldPut( 5, 4000 + i )
      oServer:update( oRow, "code = " + Str( i ) )

      IF i % 100 == 0
         oServer:Commit()
         oServer:StartTransaction()
      ENDIF
   NEXT

   oQuery := oServer:Query( "SELECT sum(salary) sum_salary FROM test WHERE code between 1 and 4000" )

   IF ! oQuery:NetErr()
      oQuery:Fetch()
      @ 18, 0 SAY "Sum values...." + Str( oQuery:FieldGet( 1 ) )
      oQuery:Destroy()
   ENDIF

   x := 0
   FOR i := 1 TO 4000
      oQuery := oServer:Query( "SELECT * FROM test WHERE code = " + Str( i ) )

      IF ! oQuery:NetErr()
         oQuery:Fetch()
         oRow := oQuery:getrow()

         oQuery:destroy()
         x += oRow:FieldGet( oRow:FieldPos( "salary" ) )

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

   oServer:Destroy()

   ? "Closing..."

   RETURN


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

[User] Implement this Harbour module: Harbour contribution module 'hbfoxpro' (FoxPro file format support): contrib/hbfoxpro/occurs.prg. Provides functions: Occurs, fox_At. This file handles data format parsing and generation

[Assistant]
FUNCTION Occurs( cSub, cStr )

   LOCAL nCount := 0, nPos

   IF HB_ISSTRING( cSub ) .AND. HB_ISSTRING( cStr )
      nPos := 0
      DO WHILE ( nPos := hb_At( cSub, cStr, nPos + 1 ) ) > 0
         ++nCount
      ENDDO
   ENDIF

   RETURN nCount

FUNCTION fox_At( cSub, cStr, nOccurrence )

   LOCAL nPos := 0

   IF HB_ISSTRING( cSub ) .AND. HB_ISSTRING( cStr )
      hb_default( @nOccurrence, 1 )
      DO WHILE --nOccurrence >= 0 .AND. ( nPos := hb_At( cSub, cStr, nPos + 1 ) ) != 0
      ENDDO
   ENDIF

   RETURN nPos


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

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

Harbour contribution module 'hbsqlit3' (SQLite3 database client library): contrib/hbsqlit3/tests/demo.prg. Contains procedures: Main, t1, t2. This file handles database operations

[Assistant]
#require "hbsqlit3"

#include "fileio.ch"

#define TRACE
#define TABLE_SQL "CREATE TABLE t1( id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER )"

PROCEDURE Main()

   ? sqlite3_libversion()
   sqlite3_sleep( 3000 )

   IF sqlite3_libversion_number() < 3005001
      RETURN
   ENDIF

   t1()
   t2()

   RETURN

PROCEDURE t1()

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

   IF ! Empty( db )
      sqlite3_exec( db, "DROP TABLE t1" )
   ENDIF

   RETURN

PROCEDURE t2()

   LOCAL lCreateIfNotExist := .T.
   LOCAL db := sqlite3_open( "new.s3db", lCreateIfNotExist )
   LOCAL stmt
   LOCAL nCCount, nCType, nI, nJ
   LOCAL aCType :=  { "SQLITE_INTEGER", "SQLITE_FLOAT", "SQLITE_TEXT", "SQLITE_BLOB", "SQLITE_NULL" }
   LOCAL aTable
#ifdef TRACE
   LOCAL hTraceFile, hProfileFile
#endif

   IF ! Empty( db )

#ifdef TRACE
      IF sqlite3_libversion_number() < 3014000
         sqlite3_profile( db, .T. )
         sqlite3_trace( db, .T. )
      ELSE
         hTraceFile := FOpen( "hbsq3_tr.log", FO_READWRITE + HB_FO_CREAT )
         FSeek( hTraceFile, 0, FS_END )
         hProfileFile := FOpen( "hbsq3_pr.log", FO_READWRITE + HB_FO_CREAT )
         FSeek( hProfileFile, 0, FS_END )
         sqlite3_trace_v2( db, SQLITE_TRACE_STMT + SQLITE_TRACE_PROFILE, {| nMask, pStmt, x |
            IF nMask == SQLITE_TRACE_STMT
               IF hb_LeftEq( x, "--" )
                  FWrite( hTraceFile, x + hb_eol() )
               ELSE
                  FWrite( hTraceFile, sqlite3_expanded_sql( pStmt ) + hb_eol() )
               ENDIF
            ELSEIF nMask == SQLITE_TRACE_PROFILE
               FWrite( hProfileFile, sqlite3_expanded_sql( pStmt ) + " - " + hb_NToS( x ) + hb_eol() )
            ENDIF
            RETURN 0
         } )
      ENDIF
#endif
      sqlite3_exec( db, "PRAGMA auto_vacuum=0" )
      sqlite3_exec( db, "PRAGMA page_size=4096" )

      IF sqlite3_exec( db, TABLE_SQL ) == SQLITE_OK
         ? "CREATE TABLE t1 - Ok"
      ENDIF

      sqlite3_exec( db, ;
         "BEGIN TRANSACTION;" + ;
         "INSERT INTO t1( name, age ) VALUES( 'Bob', 52 );" + ;
         "INSERT INTO t1( name, age ) VALUES( 'Fred', 40 );" + ;
         "INSERT INTO t1( name, age ) VALUES( 'Sasha', 25 );" + ;
         "INSERT INTO t1( name, age ) VALUES( 'Ivet', 28 );" + ;
         "COMMIT;" )

      ? "BEGIN TRANSACTION"
      ? "INSERT INTO t1( name, age ) VALUES( 'Bob', 52 )"
      ? "INSERT INTO t1( name, age ) VALUES( 'Fred', 40 )"
      ? "INSERT INTO t1( name, age ) VALUES( 'Sasha', 25 )"
      ? "INSERT INTO t1( name, age ) VALUES( 'Ivet', 28 )"
      ? "COMMIT"

      ? "The number of database rows that were changed: " + hb_ntos( sqlite3_changes( db ) )
      ? "Total changes: " + hb_ntos( sqlite3_total_changes( db ) )

      sqlite3_sleep( 3000 )

      stmt := sqlite3_prepare( db, "INSERT INTO t1( name, age ) VALUES( :name, :age )" )
      IF ! Empty( stmt )
         IF sqlite3_bind_text( stmt, 1, "Andy" ) == SQLITE_OK .AND. ;
            sqlite3_bind_int( stmt, 2, 17 ) == SQLITE_OK
            IF sqlite3_step( stmt ) == SQLITE_DONE
               ? "INSERT INTO t1( name, age ) VALUES( 'Andy', 17 ) - Done"
            ENDIF
         ENDIF
         sqlite3_reset( stmt )

         IF sqlite3_bind_text( stmt, 1, "Mary" ) == SQLITE_OK .AND. ;
            sqlite3_bind_int( stmt, 2, 19 ) == SQLITE_OK
            IF sqlite3_step( stmt ) == SQLITE_DONE
               ? "INSERT INTO t1( name, age ) VALUES( 'Mary', 19 ) - Done"
            ENDIF
         ENDIF
         sqlite3_clear_bindings( stmt )
         sqlite3_finalize( stmt )
      ENDIF

      ? "The number of database rows that were changed: " + hb_ntos( sqlite3_changes( db ) )
      ? "Total changes: " + hb_ntos( sqlite3_total_changes( db ) )
      ? "Last _ROWID_: " + Str( sqlite3_last_insert_rowid( db ) )
      ? ""

      stmt := sqlite3_prepare( db, "SELECT * FROM t1 WHERE name == :name " )
      sqlite3_bind_text( stmt, 1, "Andy" )

      ?
      ? "SELECT * FROM t1 WHERE name == 'Andy'"
      nJ := 0

      DO WHILE sqlite3_step( stmt ) == SQLITE_ROW
         nCCount := sqlite3_column_count( stmt )
         ++nJ
         ? "Record # " + Str( nJ )

         IF nCCount > 0
            FOR nI := 0 TO nCCount - 1
               nCType := sqlite3_column_type( stmt, nI )
               ? "Column name : " + sqlite3_column_name( stmt, nI )
               ? "Column type : " + aCType[ nCType ]
               ? "Column value: "

               SWITCH nCType
               CASE SQLITE_BLOB
                  ?? "BLOB"
                  EXIT

               CASE SQLITE_INTEGER
                  ?? Str( sqlite3_column_int( stmt, nI ) )
                  EXIT

               CASE SQLITE_NULL
                  ?? "NULL"
                  EXIT

               CASE SQLITE_TEXT
                  ?? sqlite3_column_text( stmt, nI )
                  EXIT
               ENDSWITCH

            NEXT
         ENDIF
      ENDDO
      ? "Total records - " + Str( nJ )

      sqlite3_clear_bindings( stmt )
      sqlite3_finalize( stmt )

      sqlite3_sleep( 3000 )

      stmt := sqlite3_prepare( db, "SELECT * FROM t1 WHERE age >= ?5" )
      sqlite3_bind_int( stmt, 5, 40 )

      ?
      ? "SELECT * FROM t1 WHERE age >= 40 "
      nJ := 0
      DO WHILE sqlite3_step( stmt ) == SQLITE_ROW
         nCCount := sqlite3_column_count( stmt )
         ++nJ
         ? "Record # " + Str( nJ )

         IF nCCount > 0
            FOR nI := 1 TO nCCount
               nCType := sqlite3_column_type( stmt, nI )
               ? "Column name : " + sqlite3_column_name( stmt, nI )
               ? "Column type : " + aCType[ nCType ]
               ? "Column value: "

               SWITCH nCType
               CASE SQLITE_BLOB
                  ?? "BLOB"
                  EXIT

               CASE SQLITE_INTEGER
                  ?? Str( sqlite3_column_int( stmt, nI ) )
                  EXIT

               CASE SQLITE_NULL
                  ?? "NULL"
                  EXIT

               CASE SQLITE_TEXT
                  ?? sqlite3_column_text( stmt, nI )
                  EXIT
               ENDSWITCH

            NEXT
         ENDIF
      ENDDO
      ? "Total records - " + Str( nJ )
      sqlite3_clear_bindings( stmt )
      sqlite3_finalize( stmt )

      sqlite3_sleep( 3000 )

      ?
      ? "SELECT id, name, age + 5 FROM t1"
      stmt := sqlite3_prepare( db, "SELECT id, name, age + 5 FROM t1" )

      ? sqlite3_column_name( stmt, 1 )
      ? sqlite3_column_name( stmt, 2 )
      ? sqlite3_column_name( stmt, 3 )

      ? aCType[ sqlite3_column_type( stmt, 1 ) ]
      ? aCType[ sqlite3_column_type( stmt, 2 ) ]
      ? aCType[ sqlite3_column_type( stmt, 3 ) ]

      ? sqlite3_column_decltype( stmt, 1 )
      ? sqlite3_column_decltype( stmt, 2 )
      ? sqlite3_column_decltype( stmt, 3 )

      sqlite3_finalize( stmt )

      sqlite3_sleep( 3000 )

      ?
      ? "sqlite3_get_table"
      ?
      aTable := sqlite3_get_table( db, "SELECT name, age  FROM t1 WHERE age BETWEEN 10 AND 20" )
      FOR nI := 1 TO Len( aTable )
         FOR nJ := 1 TO Len( aTable[ nI ] )
            ?? aTable[ nI ][ nJ ], " "
         NEXT
         ?
      NEXT

      sqlite3_sleep( 3000 )
   ENDIF

   RETURN


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

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

[Assistant]
#require "hbnf"

#include "inkey.ch"

PROCEDURE Main()

   LOCAL nver, nmar, ntype, nir, ppp

   nmar := ft_MVersion( @nver, @ntype, @nir )
   ppp := nmar + nver
   ? Str( nmar, 2, 0 ), ".", Str( nver, 2, 0 )
   ? ppp / 100
   Inkey( 0 )
   ? "is mouse on", ft_MReset()
   Inkey( 0 )
   ? ft_MShowCrs()
   Inkey( 0 )
   ? ft_MXLimit( 0, 8
      ? "mouse row is", ft_MGetX()
      ? "mouse col is", ft_MGetY()
      IF LastKey() == K_ESC
         EXIT
      ENDIF
   ENDDO
   ft_MHideCrs()

   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/multifnc/t1.prg. This test file tests specific function APIs

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

func p1(); return "P1:t1.prg"
func p2(); return "P2:t1.prg"
func p3(); return "P3:t1.prg"
func p4(); return "P4:t1.prg"

func alert()
return "[ALERT]"

#pragma begindump
#include "hbapi.h"

HB_FUNC( P7 )
{
   hb_retc( "P7:t1.prg" );
}
#pragma enddump


[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/dblist.prg. Contains procedures: __dbList. This file implements core Record Driver Driver functionality

[Assistant]
PROCEDURE __dbList( lOff, abEval, lAll, bFor, bWhile, nNext, nRecord, lRest, lToPrint, cToFileName )

   LOCAL lOldPrinter
   LOCAL lOldExtra
   LOCAL cOldExtraFile

   LOCAL oError
   LOCAL lError := .F.

   LOCAL bOutBlock

   IF lOff
      bOutBlock := {|| QOut( iif( Deleted(), "*", " " ) ), ;
                       AEval( abEval, {| bEval | QQOut( Eval( bEval ), "" ) } ) }
   ELSE
      bOutBlock := {|| QOut( Str( RecNo(), 7 ), iif( Deleted(), "*", " " ) ), ;
                       AEval( abEval, {| bEval | QQOut( Eval( bEval ), "" ) } ) }
   ENDIF

   IF ! Empty( lToPrint )
      lOldPrinter := Set( _SET_PRINTER, .T. )
   ENDIF
   IF ! Empty( cToFileName )
      lOldExtra := Set( _SET_EXTRA, .T. )
      cOldExtraFile := Set( _SET_EXTRAFILE, ;
                            iif( Set( _SET_DEFEXTENSIONS ), ;
                                 hb_FNameExtSetDef( cToFileName, ".txt" ), ;
                                 cToFileName ) )
   ENDIF

   BEGIN SEQUENCE

      IF Empty( lAll ) .AND. ;
         Empty( bFor ) .AND. ;
         Empty( bWhile ) .AND. ;
         Empty( nNext ) .AND. ;
         Empty( nRecord ) .AND. ;
         Empty( lRest )

         Eval( bOutBlock )
      ELSE
         dbEval( bOutBlock, bFor, bWhile, nNext, nRecord, lRest )
      ENDIF

   RECOVER USING oError
      lError := .T.
   END SEQUENCE

   IF ! Empty( lToPrint )
      Set( _SET_PRINTER, lOldPrinter )
   ENDIF
   IF ! Empty( cToFileName )
      Set( _SET_EXTRAFILE, cOldExtraFile )
      Set( _SET_EXTRA, lOldExtra )
   ENDIF

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

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

PROCEDURE Main()

   ctinit()

   ? "Begin test of CSetRef()"
   ? "  Default switch should be .F., is..................................", CSetRef()
   ? "  Setting switch to .T., return value should be .F., is.............", CSetRef( .T. )
   ? "  Switch setting should now be .T., is..............................", CSetRef()
   ? "  Setting switch to .F. again, return value should still be .T., is ", CSetRef( .F. )
   ? "End test of CSetRef()"
   ?

   ctexit()

   RETURN


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

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

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

[Assistant]
PROCEDURE Main()

#ifdef __HARBOUR__
   SET PRINTER TO dev_hb
#else
   SET PRINTER TO dev_cl
#endif
   SET DEVICE TO PRINTER
   DevPos( -2, 76 )
   ? PRow(), PCol()
   DevOut( "First text written!" )
   ? PRow(), PCol()
   DevOut( "Hello" )
   ? PRow(), PCol()
   DevPos( 6, 74 )
   ? PRow(), PCol()
   DevOut( "Off to the side!!" )
   ? PRow(), PCol()
   DevPos( 8, -12 )
   ? PRow(), PCol()
   DevPos( 13, -12 )
   ? PRow(), PCol()
   DevOut( "More test text!" )
   ? PRow(), PCol()
   DevOut( "Yet more text!" )
   ? PRow(), PCol()
   DevPos( 19, 85 )
   ? PRow(), PCol()
   DevPos( 500, 20 )
   ? PRow(), PCol()
   DevOut( "!" )
   ? PRow(), PCol()

   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/datecnfg.prg. Provides functions: ft_DateCnfg. This file provides legacy compatibility functions

[Assistant]
FUNCTION ft_DateCnfg( cFYStart, nDow )

   THREAD STATIC t_aDatePar := { hb_SToD( "19800101" ), 1 }

   LOCAL dCheck

   IF HB_ISSTRING( cFYStart )
      dCheck := CToD( cFYStart )
      IF ! Empty( dCheck )

         IF Month( dCheck ) == 2 .AND. Day( dcheck ) == 29
            dCheck--
         ENDIF

         t_aDatePar[ 1 ] := dCheck
      ENDIF
   ENDIF

   IF HB_ISNUMERIC( nDow ) .AND. nDow > 0 .AND. nDow < 8
      t_aDatePar[ 2 ] := nDow
   ENDIF

   RETURN { hb_DToC( t_aDatePar[ 1 ], "yyyy.mm.dd" ), t_aDatePar[ 2 ] }


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

[User] Implement the following Harbour classes: GDBar. Harbour contribution module 'hbgd' (Graphics drawing library (GD)): contrib/hbgd/gdbar.prg. Defines classes: GDBar. This file provides graphics and image processing capabilities

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

#define IMG_FORMAT_PNG   1
#define IMG_FORMAT_JPEG  2
#define IMG_FORMAT_WBMP  4
#define IMG_FORMAT_GIF   8
#define IMG_QUALITY      95

#define THICKNESS_I250   0
#define THICKNESS_I251   0

CREATE CLASS GDBar INHERIT GDImage

   VAR positionX      AS NUMERIC INIT 4
   VAR positionY      AS NUMERIC
   VAR maxHeight      AS NUMERIC INIT 25
   VAR maxHDefa       AS NUMERIC INIT 25
   VAR lastX          AS NUMERIC
   VAR lastY          AS NUMERIC
   VAR error          AS NUMERIC
   VAR imWidth        AS NUMERIC

   VAR Parity
   VAR LeftHand_Even  AS ARRAY
   VAR Right_Hand     AS ARRAY
   VAR LeftHand_Odd   AS ARRAY
   VAR keys           AS ARRAY

   VAR book           AS LOGICAL INIT .F.
   VAR acode          AS ARRAY
   VAR KeysModeA      AS CHARACTER
   VAR KeysModeB      AS CHARACTER
   VAR KeysModeC      AS ARRAY

   VAR res            AS NUMERIC
   VAR textfont       AS NUMERIC
   VAR TEXT           AS CHARACTER
   VAR filename       AS CHARACTER
   VAR color_b        AS ARRAY
   VAR color_f        AS ARRAY
   VAR FillColor      AS NUMERIC
   VAR BackColor      AS NUMERIC
   VAR lDrawValue     AS LOGICAL INIT .T.

   METHOD CreateBar( sx, sy, filename, cColor )
   METHOD Configure( nMaxHeight, aFillColor, aBackColor, nRes, nTextFont, lBook, lDrawValue )
   METHOD Allocate()
   METHOD DrawError( ptext )
   METHOD DrawSingleBar( pcode )
   METHOD DrawSingleI25( pcode )
   METHOD DrawText( lIsI25 )
   METHOD nextX( lI25 )
   METHOD Finish( image_style, quality, nFG )
   METHOD SetText( ptext )
   METHOD ResetColor()
   METHOD CheckCode()
   METHOD CheckValInArray( cChar )

ENDCLASS

METHOD CreateBar( sx, sy, filename, cColor ) CLASS GDBar

   ::Create( sx, sy )

   hb_default( @cColor, { 255, 255, 255 } )

   ::SetColor( cColor[ 1 ], cColor[ 2 ], cColor[ 3 ] )

   ::error     := 0
   ::positionY := 0
   ::imWidth   := sx

   IF ! Empty( filename )
      ::filename := filename
   ENDIF

   ::FillColor := ::SetColor( ::color_f[ 1 ], ::color_f[ 2 ], ::color_f[ 3 ] )
   ::BackColor := ::SetColor( ::color_b[ 1 ], ::color_b[ 2 ], ::color_b[ 3 ] )

   ::Setfont( "Arial" )

   IF     ::textfont == 1 ; ::SetFontSmall()
   ELSEIF ::textfont == 2 ; ::SetFontLarge()
   ELSEIF ::textfont == 3 ; ::SetFontMediumBold()
   ELSEIF ::textfont == 4 ; ::SetFontGiant()
   ELSEIF ::textfont == 5 ; ::SetFontTiny()
   ENDIF

   ::SetFontPitch( ::textfont )

   ::maxHeight := ::maxHDefa

   RETURN Self

METHOD Configure( nMaxHeight, aFillColor, aBackColor, nRes, nTextFont, lBook, lDrawValue ) CLASS GDBar

   hb_default( @lBook      , .F. )
   hb_default( @lDrawValue , .T. )
   hb_default( @nMaxHeight , 25 )
   hb_default( @nTextFont  , 2 )
   hb_default( @nRes       , 2 )
   hb_default( @aBackColor , { 255, 255, 255 } )
   hb_default( @aFillColor , { 0, 0, 0 } )

   ::book       := lBook
   ::maxHeight  := nMaxHeight
   ::res        := nRes
   ::textfont   := nTextFont
   ::lDrawValue := lDrawValue

   ::color_b    := AClone( aBackColor )
   ::color_f    := AClone( aFillColor )

   RETURN NIL

METHOD SetText( ptext ) CLASS GDBar

   ::text := ptext

   RETURN NIL

METHOD ResetColor() CLASS GDBar

   ::FillColor := ::SetColor( ::color_f[ 1 ], ::color_f[ 2 ], ::color_f[ 3 ] )
   ::BackColor := ::SetColor( ::color_b[ 1 ], ::color_b[ 2 ], ::color_b[ 3 ] )

   RETURN NIL

METHOD Allocate() CLASS GDBar

   LOCAL R := ::color_b[ 1 ]
   LOCAL G := ::color_b[ 2 ]
   LOCAL B := ::color_b[ 3 ]

   RETURN ::SetColor( R, G, B )

METHOD DrawSingleBar( pcode ) CLASS GDBar

   LOCAL i
   LOCAL j

   FOR j := 1 TO Len( pcode )

      FOR i := 1 TO ::res
         ::Line( ::positionX + i, ::positionY, ::positionX + i, ::positionY + ::maxHeight, ;
            iif( SubStr( pcode, j, 1 ) $ "0", ::BackColor, ::FillColor  ) )
      NEXT

      ::NextX()
   NEXT

   RETURN NIL

METHOD DrawSingleI25( pcode ) CLASS GDBar

   LOCAL j

   LOCAL widthSlimBar  := 1
   LOCAL widthFatBar   := 3

   LOCAL imgBar
   LOCAL imgWid
   LOCAL end_y
   LOCAL qw

   ::positionX := 10

   FOR j := 1 TO Len( pcode )

      imgBar := iif( j % 2 == 0, ::FillColor, ::BackColor )
      imgWid := iif( SubStr( pcode, j, 1 ) == "0", widthSlimBar, widthFatBar )

      end_y := ::maxHeight

      FOR qw := 1 TO imgWid
         ::Line( ::positionX, 1, ::positionX, end_y, imgBar )
         ::nextX( .T. )
      NEXT
   NEXT

   RETURN NIL

METHOD DrawError( ptext ) CLASS GDBar

   ::Say( 5, ::error
         ::say( xPosition, ::maxHeight, "*" + ::text + "*", ::FillColor )
         ::lastY := ::maxHeight + ::GetFontHeight()
      ENDIF
   ELSE
      If ::textfont != 0
         xPosition := ( ::positionX / 2 ) - ( Len( ::text ) / 2 )
         ::DrawError( "Character " + SubStr( ::text, i, 1 ) + " not allowed." )
         lRet := .F.
      ENDIF
   NEXT

   RETURN lRet

METHOD CheckValInArray( cChar ) CLASS GDBar

   LOCAL nPos := AScan( ::keys, {| x | SubStr( x, 1, 1 ) == cChar } )

   RETURN iif( nPos > 0, nPos, NIL )

METHOD Finish( image_style, quality, nFG ) CLASS GDBar

   hb_default( @image_style, IMG_FORMAT_PNG )
   hb_default( @quality    , 95 )
   hb_default( @nFG        , { 255, 255, 255 } )

   IF Empty( ::filename ) .OR. ::filename == NIL

      IF image_style == IMG_FORMAT_PNG
         ::OutputPng()
      ELSEIF image_style == IMG_FORMAT_JPEG
         ::OutputJpeg( , quality )
      ELSEIF image_style == IMG_FORMAT_WBMP
         ::OutputWBmp( , nFG )
      ELSEIF image_style == IMG_FORMAT_GIF
         ::OutputGif()
      ENDIF
   ELSE
      IF image_style == IMG_FORMAT_PNG
         ::SavePng(  ::filename )
      ELSEIF image_style == IMG_FORMAT_JPEG
         ::Savejpeg( ::filename, quality )
      ELSEIF image_style == IMG_FORMAT_WBMP
         ::SaveWBmp( ::filename, nFG )
      ELSEIF image_style == IMG_FORMAT_GIF
         ::SaveGif( ::filename )
      ENDIF
   ENDIF

   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] Create Harbour OOP classes for the functionality described: Harbour contribution module 'hbwin' (Windows API wrapper functions): contrib/hbwin/tests/activex.prg. Defines classes: HActiveX. Contains procedures: Main, Event. This file provides platform-specific functionality

[Assistant]
#require "hbwin"

#include "hbgtinfo.ch"
#include "hbclass.ch"

#if ! defined( __HBSCRIPT__HBSHELL )
REQUEST HB_GT_WVT_DEFAULT
#endif

PROCEDURE Main()

   LOCAL oMSCAL

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

   WAIT "Make sure we are 'Active Window'"
   oMSCAL := HActiveX():Init( wapi_GetActiveWindow(), "MSCAL.Calendar", 0, 0, 300, 300 )
   WAIT "Press any key to exit"

   HB_SYMBOL_UNUSED( oMSCAL )

   RETURN

CREATE CLASS HActiveX

   VAR oOLE
   VAR hWnd
   METHOD Init( hWnd, cProgId, nTop, nLeft, nWidth, nHeight, cID )
   METHOD Event( ... )
   ERROR HANDLER OnError()
   DESTRUCTOR Close()

ENDCLASS

METHOD Init( hWnd, cProgId, nTop, nLeft, nWidth, nHeight, cID ) CLASS HActiveX

   LOCAL nStyle := WIN_WS_CHILD + WIN_WS_VISIBLE + WIN_WS_CLIPCHILDREN

   win_axInit()
   ::hWnd := wapi_CreateWindowEx( 0, "AtlAxWin", cProgId, nStyle, nLeft, nTop, nWidth, nHeight, hWnd, 0 )
   ::oOLE := win_axGetControl( ::hWnd, {| event, ... | ::Event( event, ... ) }, cID )

   RETURN Self

PROCEDURE Event( ... ) CLASS HActiveX

   LOCAL cEvents := ""
   LOCAL aEvents := { ... }

   AEval( aEvents, {| xEvent | cEvents += hb_ValToStr( xEvent ) + ", " } )
   wapi_OutputDebugString( cEvents )

   RETURN

METHOD OnError() CLASS HActiveX
   RETURN hb_ExecFromArray( ::oOLE, __GetMessage(), hb_AParams() )

METHOD Close() CLASS HActiveX

   wapi_OutputDebugString( "Close" )
   wapi_DestroyWindow( ::hWnd )
   ::hWnd := NIL
   ::oOLE := NIL
   wapi_OutputDebugString( "After Close" )

   RETURN NIL


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

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

Harbour Runtime Library file: src/rtl/dbedit.prg. Provides functions: dbEdit, CallUser. This file handles database operations

[Assistant]
#include "dbedit.ch"
#include "inkey.ch"
#include "setcurs.ch"

FUNCTION dbEdit( nTop, nLeft, nBottom, nRight, ;
      acColumns, xUserFunc, ;
      xColumnSayPictures, xColumnHeaders, ;
      xHeadingSeparators, xColumnSeparators, ;
      xFootingSeparators, xColumnFootings )

   LOCAL nOldCUrsor, nKey, lContinue, nPos, nAliasPos, nColCount
   LOCAL lDoIdleCall, lAppend, lFlag
   LOCAL cHeading, cBlock
   LOCAL bBlock
   LOCAL oBrowse
   LOCAL oColumn
   LOCAL aCol

   IF ! Used()
      RETURN .F.
   ELSEIF Eof()
      dbGoBottom()
   ENDIF

   IF ! HB_ISNUMERIC( nTop ) .OR. nTop < 0
      nTop := 0
   ENDIF
   IF ! HB_ISNUMERIC( nLeft ) .OR. nLeft < 0
      nLeft := 0
   ENDIF
   IF ! HB_ISNUMERIC( nBottom ) .OR. nBottom > MaxRow() .OR. nBottom < nTop
      nBottom := MaxRow()
   ENDIF
   IF ! HB_ISNUMERIC( nRight ) .OR. nRight > MaxCol() .OR. nRight < nLeft
      nRight := MaxCol()
   ENDIF

   oBrowse := TBrowseDB( nTop, nLeft, nBottom, nRight )
   oBrowse:headSep   := iif( HB_ISSTRING( xHeadingSeparators ), xHeadingSeparators, hb_UTF8ToStrBox( "═╤═" ) )
   oBrowse:colSep    := iif( HB_ISSTRING( xColumnSeparators ), xColumnSeparators, hb_UTF8ToStrBox( " │ " ) )
   oBrowse:footSep   := hb_defaultValue( xFootingSeparators, "" )
   oBrowse:skipBlock := {| nRecs | Skipped( nRecs, lAppend ) }
   oBrowse:autoLite  := .F.

   IF HB_ISARRAY( acColumns )
      nColCount := 0
      FOR EACH aCol IN acColumns
         IF HB_ISSTRING( aCol ) .AND. ! Empty( aCol )
            nColCount++
         ELSE
            EXIT
         ENDIF
      NEXT
   ELSE
      nColCount := FCount()
   ENDIF

   IF nColCount == 0
      RETURN .F.
   ENDIF

   FOR nPos := 1 TO nColCount

      IF HB_ISARRAY( acColumns )
         cBlock := acColumns[ nPos ]
         IF ( nAliasPos := At( "->", cBlock ) ) > 0
            cHeading := Left( cBlock, nAliasPos - 1 ) + "->;" + ;
                        SubStr( cBlock, nAliasPos + 2 )
         ELSE
            cHeading := cBlock
         ENDIF
      ELSE
         cBlock := FieldName( nPos )
         cHeading := cBlock
      ENDIF

      bBlock := iif( Type( cBlock ) == "M", {|| "  <Memo>  " }, hb_macroBlock( cBlock ) )

      DO CASE
      CASE HB_ISARRAY( xColumnHeaders ) .AND. Len( xColumnHeaders ) >= nPos .AND. HB_ISSTRING( xColumnHeaders[ nPos ] )
         cHeading := xColumnHeaders[ nPos ]
      CASE HB_ISSTRING( xColumnHeaders )
         cHeading := xColumnHeaders
      ENDCASE

      oColumn := TBColumnNew( cHeading, bBlock )

      DO CASE
      CASE HB_ISARRAY( xColumnSayPictures ) .AND. nPos <= Len( xColumnSayPictures ) .AND. HB_ISSTRING( xColumnSayPictures[ nPos ] ) .AND. ! Empty( xColumnSayPictures[ nPos ] )
         oColumn:picture := xColumnSayPictures[ nPos ]
      CASE HB_ISSTRING( xColumnSayPictures ) .AND. ! Empty( xColumnSayPictures )
         oColumn:picture := xColumnSayPictures
      ENDCASE

      DO CASE
      CASE HB_ISARRAY( xColumnFootings ) .AND. nPos <= Len( xColumnFootings ) .AND. HB_ISSTRING( xColumnFootings[ nPos ] )
         oColumn:footing := xColumnFootings[ nPos ]
      CASE HB_ISSTRING( xColumnFootings )
         oColumn:footing := xColumnFootings
      ENDCASE

      IF HB_ISARRAY( xHeadingSeparators ) .AND. nPos <= Len( xHeadingSeparators ) .AND. HB_ISSTRING( xHeadingSeparators[ nPos ] )
         oColumn:headSep := xHeadingSeparators[ nPos ]
      ENDIF

      IF HB_ISARRAY( xColumnSeparators ) .AND. nPos <= Len( xColumnSeparators ) .AND. HB_ISSTRING( xColumnSeparators[ nPos ] )
         oColumn:colSep := xColumnSeparators[ nPos ]
      ENDIF

      IF HB_ISARRAY( xFootingSeparators ) .AND. nPos <= Len( xFootingSeparators ) .AND. HB_ISSTRING( xFootingSeparators[ nPos ] )
         oColumn:footSep := xFootingSeparators[ nPos ]
      ENDIF

      oBrowse:addColumn( oColumn )
   NEXT

   nOldCUrsor := SetCursor( SC_NONE )

   lAppend := .F.
   lFlag := .T.
   lDoIdleCall := .T.
   lContinue := .T.

   DO WHILE lContinue

      DO WHILE .T.
         nKey := Inkey()
         IF oBrowse:stabilize()
            EXIT
         ENDIF
#ifdef HB_COMPAT_C53
         IF nKey != 0 .AND. nKey != K_MOUSEMOVE
            EXIT
         ENDIF
#else
         IF nKey != 0
            EXIT
         ENDIF
#endif
      ENDDO

      IF nKey == 0
         IF lDoIdleCall
            lContinue := CallUser( oBrowse, xUserFunc, 0, @lAppend, @lFlag )
            oBrowse:forceStable()
         ENDIF
         IF lContinue .AND. lFlag
            oBrowse:hiLite()
#ifdef HB_COMPAT_C53
            DO WHILE ( nKey := Inkey( 0 ) ) == K_MOUSEMOVE
            ENDDO
#else
            nKey := Inkey( 0 )
#endif
            oBrowse:deHilite()
            IF ( bBlock := SetKey( nKey ) ) != NIL
               Eval( bBlock, ProcName( 1 ), ProcLine( 1 ), "" )
               LOOP
            ENDIF
         ELSE
            lFlag := .T.
         ENDIF
      ENDIF

      lDoIdleCall := .T.

      IF nKey != 0
#ifdef HB_CLP_UNDOC
         IF lAppend
            SWITCH nKey
            CASE K_DOWN
            CASE K_PGDN
            CASE K_CTRL_PGDN
               oBrowse:hitBottom := .T.
               LOOP
            CASE K_UP
            CASE K_PGUP
            CASE K_CTRL_PGUP
               oBrowse:hitTop := .T.
               LOOP
            ENDSWITCH
         ENDIF
#endif
         SWITCH nKey
#ifdef HB_COMPAT_C53
         CASE K_LBUTTONDOWN
         CASE K_LDBLCLK
            TBMouse( oBrowse, MRow(), MCol() )
            EXIT
#endif
         CASE K_DOWN          ; oBrowse:down()     ; EXIT
         CASE K_UP            ; oBrowse:up()       ; EXIT
         CASE K_PGDN          ; oBrowse:pageDown() ; EXIT
         CASE K_PGUP          ; oBrowse:pageUp()   ; EXIT
         CASE K_CTRL_PGUP     ; oBrowse:goTop()    ; EXIT
         CASE K_CTRL_PGDN     ; oBrowse:goBottom() ; EXIT
         CASE K_RIGHT         ; oBrowse:right()    ; EXIT
         CASE K_LEFT          ; oBrowse:left()     ; EXIT
         CASE K_HOME          ; oBrowse:home()     ; EXIT
         CASE K_END           ; oBrowse:end()      ; EXIT
         CASE K_CTRL_LEFT     ; oBrowse:panLeft()  ; EXIT
         CASE K_CTRL_RIGHT    ; oBrowse:panRight() ; EXIT
         CASE K_CTRL_HOME     ; oBrowse:panHome()  ; EXIT
         CASE K_CTRL_END      ; oBrowse:panEnd()   ; EXIT
         OTHERWISE
            lContinue := CallUser( oBrowse, xUserFunc, nKey, @lAppend, @lFlag )
            lDoIdleCall := .F.
         ENDSWITCH
      ENDIF
   ENDDO

   SetCursor( nOldCUrsor )

   RETURN .T.

STATIC FUNCTION CallUser( oBrowse, xUserFunc, nKey, lAppend, lFlag )

   LOCAL nPrevRecNo

   LOCAL nAction
   LOCAL nMode := ;
      iif( nKey != 0,                   DE_EXCEPT,    ;
      iif( ! lAppend .AND. IsDbEmpty(), DE_EMPTY,     ;
      iif( oBrowse:hitBottom,           DE_HITBOTTOM, ;
      iif( oBrowse:hitTop,              DE_HITTOP, DE_IDLE ) ) ) )

   oBrowse:forceStable()

   nPrevRecNo := RecNo()

   nAction := iif( HB_ISEVALITEM( xUserFunc ), ;
                                 Eval( xUserFunc, nMode, oBrowse:colPos ), ;
              iif( HB_ISSTRING( xUserFunc ) .AND. ! Empty( xUserFunc ), ;
                                 &xUserFunc( nMode, oBrowse:colPos ), ;
              iif( nKey == K_ENTER .OR. nKey == K_ESC, DE_ABORT, DE_CONT ) ) )

   IF ! lAppend .AND. Eof() .AND. ! IsDbEmpty()
      dbSkip( -1 )
   ENDIF

#ifdef HB_CLP_UNDOC
   IF nAction == DE_APPEND

      IF ( lAppend := !( lAppend .AND. Eof() ) )
         dbGoBottom()
         oBrowse:down()
      ELSE
         oBrowse:refreshAll():forceStable()
      ENDIF
      lFlag := .F.
      RETURN .T.
   ENDIF
#endif

   IF nAction == DE_REFRESH .OR. nPrevRecNo != RecNo()

      IF nAction != DE_ABORT

         lAppend := .F.

         IF ( Set( _SET_DELETED ) .AND. Deleted() ) .OR. ;
            ( ! Empty( dbFilter() ) .AND. ! Eval( hb_macroBlock( dbFilter() ) ) )
            dbSkip()
         ENDIF
         IF Eof()
            dbGoBottom()
         ENDIF

         nPrevRecNo := RecNo()


[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/pegs.prg. Provides functions: ft_Pegs, DrawBox, err_msg, moremoves. This file provides legacy compatibility functions

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

#translate DOUBLEBOX( <top>, <left>, <bottom>, <right> ) => hb_DispBox( <top>, <left>, <bottom>, <right>, hb_UTF8ToStrBox( "╔═╗║╝═╚║ " ) )

FUNCTION ft_Pegs()

   LOCAL XX, MOVE, MPOS, POSSIBLE_, BUFFER, TOPROW, OLDSCORE, MOVE2
   LOCAL SCANBLOCK, OLDCOLOR := SetColor( "w/n" )
   LOCAL oldscrn := SaveScreen( 0, 0, MaxRow(), MaxCol() )
   LOCAL GetList

   LOCAL board_ := { ;
      { {  0, 29,  2, 34 }, { 2, 4 }, { 3, 9 }, .T. }, ;
      { {  0, 37,  2, 42 }, { 5 }, { 10 }, .T. }, ;
      { {  0, 45,  2, 50 }, { 2, 6 }, { 1, 11 }, .T. }, ;
      { {  3, 29,  5, 34 }, { 5, 9 }, { 6, 16 }, .T. }, ;
      { {  3, 37,  5, 42 }, { 10 }, { 17 }, .T. }, ;
      { {  3, 45,  5, 50 }, { 5, 11 }, { 4, 18 }, .T. }, ;
      { {  6, 13,  8, 18 }, { 8, 14 }, { 9, 21 }, .T. }, ;
      { {  6, 21,  8, 26 }, { 9, 15 }, { 10, 22 }, .T. }, ;
      { {  6, 29,  8, 34 }, { 4, 8, 10, 16 }, { 1, 7, 11, 23 }, .T. }, ;
      { {  6, 37,  8, 42 }, { 5, 9, 11, 17 }, { 2, 8, 12, 24 }, .T. }, ;
      { {  6, 45,  8, 50 }, { 6, 10, 12, 18 }, { 3, 9, 13, 25 }, .T. }, ;
      { {  6, 53,  8, 58 }, { 11, 19 }, { 10, 26 }, .T. }, ;
      { {  6, 61,  8, 66 }, { 12, 20 }, { 11, 27 }, .T. }, ;
      { {  9, 13, 11, 18 }, { 15 }, { 16 }, .T. }, ;
      { {  9, 21, 11, 26 }, { 16 }, { 17 }, .T. }, ;
      { {  9, 29, 11, 34 }, { 9, 15, 17, 23 }, { 4, 14, 18, 28 }, .T. }, ;
      { {  9, 37, 11, 42 }, { 10, 16, 18, 24 }, { 5, 15, 19, 29 }, .F. }, ;
      { {  9, 45, 11, 50 }, { 11, 17, 19, 25 }, { 6, 16, 20, 30 }, .T. }, ;
      { {  9, 53, 11, 58 }, { 18 }, { 17 }, .T. }, ;
      { {  9, 61, 11, 66 }, { 19 }, { 18 }, .T. }, ;
      { { 12, 13, 14, 18 }, { 14, 22 }, { 7, 23 }, .T. }, ;
      { { 12, 21, 14, 26 }, { 15, 23 }, { 8, 24 }, .T. }, ;
      { { 12, 29, 14, 34 }, { 16, 22, 24, 28 }, { 9, 21, 25, 31 }, .T. }, ;
      { { 12, 37, 14, 42 }, { 17, 23, 25, 29 }, { 10, 22, 26, 32 }, .T. }, ;
      { { 12, 45, 14, 50 }, { 18, 24, 26, 30 }, { 11, 23, 27, 33 }, .T. }, ;
      { { 12, 53, 14, 58 }, { 19, 25 }, { 12, 24 }, .T. }, ;
      { { 12, 61, 14, 66 }, { 20, 26 }, { 13, 25 }, .T. }, ;
      { { 15, 29, 17, 34 }, { 23, 29 }, { 16, 30 }, .T. }, ;
      { { 15, 37, 17, 42 }, { 24 }, { 17 }, .T. }, ;
      { { 15, 45, 17, 50 }, { 25, 29 }, { 18, 28 }, .T. }, ;
      { { 18, 29, 20, 34 }, { 28, 32 }, { 23, 33 }, .T. }, ;
      { { 18, 37, 20, 42 }, { 29 }, { 24 }, .T. }, ;
      { { 18, 45, 20, 50 }, { 30, 32 }, { 25, 31 }, .T. } }

   scanblock := {| a | a[ 2 ] == move2 }
   hb_Scroll()
   SetColor( "w/r" )
   hb_DispBox( 22, 31, 24, 48, hb_UTF8ToStrBox( "┌─┐│┘─└│ " ) )
   hb_DispOutAt( 23, 33, "Your move:" )
   AEval( board_, {| a, x | HB_SYMBOL_UNUSED( a ), drawbox( board_, x ) } )
   DO WHILE LastKey() != K_ESC .AND. moremoves( board_ )
      move := 1

      SetColor( "w/n" )
      GetList := { Get():New( 23, 44, {| v | iif( PCount() == 0, move, move := v ) }, "move", "##" ) }
      ATail( GetList ):postBlock := {| oGet | RangeCheck( oGet,, 1, 33 ) }
      ATail( GetList ):display()
      READ

      IF move > 0
         DO CASE
         CASE ! board_[ move ][ 4 ]
            err_msg( "No piece there!" )
         OTHERWISE
            possible_ := {}
            FOR xx := 1 TO Len( board_[ move ][ 2 ] )
               IF board_[ board_[ move ][ 2, xx ] ][ 4 ] .AND. ;
                  ! board_[ board_[ move ][ 3, xx ] ][ 4 ]
                  AAdd( possible_, { board_[ move ][ 2, xx ], board_[ move ][ 3, xx ] } )
               ENDIF
            NEXT

            DO CASE
            CASE Len( possible_ ) == 1

               board_[ move ][ 4 ] := board_[ possible_[ 1, 1 ] ][ 4 ] := .F.
               board_[ possible_[ 1, 2 ] ][ 4 ] := .T.
               drawbox( board_, move )
               drawbox( board_, possible_[ 1, 1 ] )
               drawbox( board_, possible_[ 1, 2 ] )
            CASE Len( possible_ ) == 0
               err_msg( "Illegal move!" )
            OTHERWISE
               move2 := possible_[ 1, 2 ]
               toprow := 21 - Len( possible_ )
               SetColor( "+w/b" )
               buffer := SaveScreen( toprow, 55, 22, 74 )
               DOUBLEBOX( toprow, 55, 22, 74 )
               hb_DispOutAt( toprow, 58, "Possible Moves" )
               SetPos( toprow, 65 )
               AEval( possible_, {| a | hb_DispOutAt( Row() + 1, 65, Transform( a[ 2 ], "##" ) ) } )
               oldscore := Set( _SET_SCOREBOARD, .F. )

               GetList := { Get():New( 23, 44, {| v | iif( PCount() == 0, move2, move2 := v ) }, "move2", "##" ) }
               ATail( GetList ):postBlock := {|| AScan( possible_, scanblock ) > 0 }
               ATail( GetList ):display()
               READ

               RestScreen( toprow, 55, 22, 74, buffer )
               Set( _SET_SCOREBOARD, oldscore )
               mpos := AScan( possible_, {| a | move2 == a[ 2 ] } )

               board_[ move ][ 4 ] := board_[ possible_[ mpos, 1 ] ][ 4 ] := .F.
               board_[ move2 ][ 4 ] := .T.
               drawbox( board_, move )
               drawbox( board_, possible_[ mpos, 1 ] )
               drawbox( board_, move2 )

            ENDCASE
         ENDCASE
         move := 1
      ENDIF
   ENDDO
   SetColor( oldcolor )
   RestScreen( 0, 0, MaxRow(), MaxCol(), oldscrn )

   RETURN NIL

STATIC FUNCTION DrawBox( board_, nelement )

   SetColor( iif( board_[ nelement ][ 4 ], "+w/rb", "w/n" ) )

   hb_DispBox( ;
      board_[ nelement ][ 1, 1 ], ;
      board_[ nelement ][ 1, 2 ], ;
      board_[ nelement ][ 1, 3 ], ;
      board_[ nelement ][ 1, 4 ], hb_UTF8ToStrBox( "┌─┐│┘─└│ " ) )

   hb_DispOutAt( ;
      board_[ nelement ][ 1, 1 ] + 1, ;
      board_[ nelement ][ 1, 2 ] + 2, hb_ntos( nelement ) )

   RETURN NIL

STATIC FUNCTION err_msg( msg )

   LOCAL buffer := SaveScreen( 23, 33, 23, 47 )

   SetCursor( SC_NONE )
   SetColor( "+w/r" )
   hb_DispOutAt( 23, 33, msg )
   Inkey( 2 )
   SetCursor( SC_NORMAL )
   RestScreen( 23, 33, 23, 47, buffer )

   RETURN NIL

STATIC FUNCTION moremoves( board_ )

   LOCAL xx, yy, canmove := .F., piecesleft := 0, buffer

   FOR xx := 1 TO 33
      FOR yy := 1 TO Len( board_[ xx ][ 2 ] )
         IF board_[ xx ][ 4 ] .AND.  ;
            board_[ board_[ xx ][ 2, yy ] ][ 4 ] .AND. ;
            ! board_[ board_[ xx ][ 3, yy ] ][ 4 ]
            canmove := .T.
            EXIT
         ENDIF
      NEXT

      IF board_[ xx ][ 4 ]
         piecesleft++
      ENDIF
   NEXT
   IF ! canmove
      SetColor( "+w/b" )
      buffer := SaveScreen( 18, 55, 21, 74 )
      DOUBLEBOX( 18, 55, 21, 74 )
      hb_DispOutAt( 19, 58, "No more moves!" )
      hb_DispOutAt( 20, 58, hb_ntos( piecesleft ) + " pieces left" )
      Inkey( 0 )
      RestScreen( 18, 55, 21, 74, buffer )
   ENDIF

   RETURN canmove


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

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

Header file for contribution module 'hbtest' (Test framework utilities): contrib/hbtest/hbtest.ch. Defines constants: HB_TEST_CH_. Declares 1 preprocessor translations. Defines Harbour internal constants and macros

[Assistant]
#ifndef HB_TEST_CH_
#define HB_TEST_CH_

#xtranslate HBTEST <x> IS <result> => hbtest_Call( #<x>, {|| <x> }, <result> )

#pragma linenumber=on

#endif


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

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

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

[Assistant]
#include "hbclass.ch"
#include "error.ch"
#include "fileio.ch"
#include "inkey.ch"
#include "setcurs.ch"
#include "color.ch"
#include "hbgtinfo.ch"

CREATE CLASS XHBEditor

   VAR   cFile          INIT ""

   VAR   aText          INIT {}

   VAR   nTop
   VAR   nLeft
   VAR   nBottom
   VAR   nRight

   VAR   nFirstCol      INIT 1
   VAR   nFirstRow      INIT 1
   VAR   nRow           INIT 1
   VAR   nCol           INIT 1

   VAR   nPhysRow       INIT 0
   VAR   nPhysCol       INIT 0

   VAR   nTextRow       INIT 0
   VAR   nTextCol       INIT 0
   VAR   nWndRow        INIT 0
   VAR   nWndCol        INIT 0

   VAR   nNumCols       INIT 1
   VAR   nNumRows       INIT 1

   VAR   nTabWidth      INIT 5
   VAR   lEditAllow     INIT .T.
   VAR   lSaved         INIT .F.
   VAR   lWordWrap      INIT .T.
   VAR   nWordWrapCol   INIT 0
   VAR   lChanged       INIT .F.
   VAR   lExitEdit      INIT .F.

   VAR   cColorSpec     INIT SetColor()

   VAR   lRightScroll   INIT .T.
   VAR   nMarkPos
   VAR   nMarkLen
   VAR   nOrigCursor    INIT SetCursor()

   VAR   ProcName       INIT ""
   VAR   ProcLine       INIT 0

   VAR   nCurrentCursor INIT SetCursor()

   VAR   lSelActive     INIT .F.
   VAR   nRowSelStart   INIT 0
   VAR   nRowSelEnd     INIT 0
   VAR   nColSelRow     INIT 0
   VAR   nColSelStart   INIT 0
   VAR   nColSelEnd     INIT 0

   METHOD lInsert()              BLOCK {|| Set( _SET_INSERT ) }
   METHOD _lInsert( lInsert )    BLOCK {| Self, lInsert | HB_SYMBOL_UNUSED( Self ), iif( HB_ISLOGICAL( lInsert ), Set( _SET_INSERT, lInsert ), Set( _SET_INSERT ) ) }

   METHOD  New( cString, nTop, nLeft, nBottom, ;
      nRight, lEditMode, nLineLength, nTabSize, nTextRow, nTextCol, nWndRow, nWndCol )
   METHOD  LoadFile( cFileName )
   METHOD  LoadText( cString )
   METHOD  SaveFile()

   METHOD  AddLine( cLine, lSoftCR )
   METHOD  InsertLine( cLine, lSoftCR, nRow )
   METHOD  RemoveLine( nRow )
   METHOD  GetLine( nRow )
   METHOD  LineLen( nRow ) INLINE iif( nRow == NIL, nRow := ::nRow, ), iif( nRow <= ::LastRow(), Len( ::aText[ nRow ]:cText ), 0 )
   METHOD  SplitLine( nRow )
   METHOD  GotoLine( nRow )
   METHOD  GotoCol( nCol )
   METHOD  GotoPos( nRow, nCol, lRefresh )
   METHOD  GetText( lSoftCR )
   METHOD  DelText()
   METHOD  AddText( cString, lAtPos )
   METHOD  GetTextIndex()

   METHOD  SetTextSelection( cAction, nCount )
   METHOD  GetTextSelection( lSoftCr )
   METHOD  DelTextSelection()
   METHOD  ClrTextSelection()

   METHOD  RefreshWindow()
   METHOD  RefreshLine( lRefreshColSel )
   METHOD  RefreshColumn()

   METHOD  LineColor( nRow )
   METHOD  ColColor()

   METHOD  MoveCursor( nKey )
   METHOD  InsertState( lInsState )
   METHOD  Edit( nPassedKey )

   METHOD  KeyboardHook()
   METHOD  IdleHook()

   METHOD  Resize( nTop, nLeft, nBottom, nRight )
   METHOD  SetColor( cColorString )
   METHOD  Hilite()
   METHOD  DeHilite()

   METHOD  SetPos( nRow, nCol )
   METHOD  Row() INLINE ::nPhysRow
   METHOD  Col() INLINE ::nPhysCol

   METHOD  Down()
   METHOD  PageDown()
   METHOD  Bottom()
   METHOD  GoBottom()
   METHOD  Up()
   METHOD  PageUp()
   METHOD  Top()
   METHOD  GoTop()
   METHOD  Right()
   METHOD  WordRight()
   METHOD  End()
   METHOD  Left()
   METHOD  WordLeft()
   METHOD  Home()

   METHOD  K_Ascii( nKey )
   METHOD  K_Return()
   METHOD  K_Del()
   METHOD  K_Bs()
   METHOD  K_Tab()
   METHOD  K_Mouse( nKey )
   METHOD  K_Esc()

   VAR     cInsLabel
   VAR     lVerticalScroll   INIT .T.
   VAR     bKeyBlock

   METHOD  DisplayInsert( lInsert )
   METHOD  LastRow() INLINE Len( ::aText )
   METHOD  DelTextRight( nRow )
   METHOD  DelWordRight()
   METHOD  ReformParagraph()

   PROTECTED:

   METHOD   BrowseText( nPassedKey, lHandleOneKey )

   METHOD  GetCol( nRow, nCol ) INLINE iif( nRow > 0 .AND. nRow <= ::LastRow(), iif( nCol > 0 .AND. nCol <= Min( ::nWordWrapCol + 1, ::LineLen( nRow ) ), SubStr( ::aText[ nRow ]:cText, nCol, 1 ), "" ), "" )
   METHOD  IsEmptyLine( nRow )  INLINE iif( nRow > 0 .AND. nRow <= ::LastRow(), Empty( ::aText[ nRow ]:cText ), .T. )

ENDCLASS

METHOD New( cString, nTop, nLeft, nBottom, nRight, lEditMode, nLineLength, nTabSize, nTextRow, nTextCol, nWndRow, nWndCol ) CLASS XHBEditor

   __defaultNIL( @cString, "" )
   __defaultNIL( @nTop, 0 )
   __defaultNIL( @nLeft, 0 )
   __defaultNIL( @nBottom, MaxRow() )
   __defaultNIL( @nRight, MaxCol() )
   __defaultNIL( @lEditMode, .T. )
   __defaultNIL( @nLineLength, NIL )
   __defaultNIL( @nTabSize, NIL )
   __defaultNIL( @nTextRow, 1 )
   __defaultNIL( @nTextCol, 0 )
   __defaultNIL( @nWndRow, 0 )
   __defaultNIL( @nWndCol, 0 )

   IF nTop > nBottom .OR. nLeft > nRight
      Throw( xhb_ErrorNew( "BASE", 0, 1127, "Argument error: <nTop,nRight,nLeft,nBottom>", ProcName() ) )
   ENDIF

   ::cColorSpec := SetColor()

   ::nOrigCursor := SetCursor()

   ::nTop    := Min( Max( 0, nTop ), MaxRow() )
   ::nLeft   := Min( Max( 0, nLeft ), MaxCol() )
   ::nBottom := Max( 0, Min( MaxRow(), nBottom ) )
   ::nRight  := Max( 0, Min( MaxCol(), nRight ) )

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

   IF ! HB_ISNUMERIC( nLineLength )
      nLineLength := ::nNumCols
   ELSE
      IF nLineLength < 0
         nLineLength := 255
         ::lWordWrap := .F.
      ELSE
         nLineLength := Max( 6, nLineLength )
      ENDIF
   ENDIF

   ::nWordWrapCol := nLineLength - 1

   IF lEditMode != NIL
      ::lEditAllow := lEditMode
   ENDIF

   IF ::lEditAllow

      ::InsertState( ! Set( _SET_INSERT ) )
      ::InsertState( ! Set( _SET_INSERT ) )
   ENDIF

   ::lChanged := .F.

   IF nTabSize != NIL
      ::nTabWidth := nTabSize
   ENDIF

   ::nTextRow    := Max( 1, nTextRow )
   ::nTextCol    := Max( 0, nTextCol )
   ::nWndRow     := Max( 0, nWndRow  )
   ::nWndCol     := Max( 0, nWndCol  )

   ::nFirstRow := Max( 1, ::nTextRow - ::nWndRow )
   ::nFirstCol := Max( 1, ::nTextCol - ::nWndCol )

   ::aText := Text2Array( cString, nLineLength )

   IF ::LastRow() == 0
      AAdd( ::aText, HBTextLine():New() )
   ENDIF

   ::nRow := Max( 1, Min( ::nTextRow, Len( ::aText ) ) )
   ::nCol := Max( 1, Min( Len( ::aText[ ::nRow ]:cText ), ::nTextCol + 1 ) )

   IF ::nFirstRow >  ::LastRow()
      ::nFirstRow := ::LastRow()
   ENDIF

   IF ::nFirstCol >  ::LineLen( ::nRow ) + 1
      ::nFirstCol := ::LineLen( ::nRow ) + 1
   ENDIF

   ::SetPos( ::nTop + ::nWndRow, ::nLeft + ::nWndCol )

   ::RefreshWindow()

   RETURN Self


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

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

Harbour test program: tests/fib.prg. Provides functions: FibR, FibI. Contains procedures: Main. This test file tests specific function APIs

[Assistant]
PROCEDURE Main()

   LOCAL n

   FOR n := 1 TO 20
      ? FibR( n )
      ? FibI( n )
   NEXT

   RETURN

FUNCTION FibR( n )

   LOCAL nFib

   IF n < 2
      nFib := n
   ELSE
      nFib := FibR( n - 2 ) + FibR( n - 1 )
   ENDIF

   RETURN nFib

FUNCTION FibI( n )

   LOCAL nFibMin1  := 1
   LOCAL nFibMinN1 := 0
   LOCAL i         := 1
   LOCAL nFib

   IF n < 2
      nFib := n
   ELSE
      DO WHILE i < n
         nFib      := nFibMin1 + nFibMinN1
         nFibMinN1 := nFibMin1
         nFibMin1  := nFib
         ++i
      ENDDO
   ENDIF

   RETURN nFib


[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: extras/hbusb/hbusb.ch. Defines constants: HBUSB_CH, LIBUSB_UNREF_DEVICES, LIBUSB_KERNEL_HAS_INTERFACE, LIBUSB_ENDPOINT_IN, LIBUSB_ENDPOINT_OUT. Defines file I/O constants

[Assistant]
#ifndef HBUSB_CH
#define HBUSB_CH

#define LIBUSB_UNREF_DEVICES        1

#define LIBUSB_KERNEL_HAS_INTERFACE 1

#define LIBUSB_ENDPOINT_IN          129
#define LIBUSB_ENDPOINT_OUT         0

#endif


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

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

[Assistant]
PROCEDURE Main()

   dbCreate( "testsort", { { "ITEM", "N", 10, 2 } } )

   USE testsort
   dbAppend() ; FIELD->ITEM := 5.00
   dbAppend() ; FIELD->ITEM := -5.12
   dbAppend() ; FIELD->ITEM := 6.00
   dbAppend() ; FIELD->ITEM := 7.00
   dbAppend() ; FIELD->ITEM := -5.00

   SORT TO tempsort ON FIELD->ITEM /D

   USE tempsort
   dbEval( {|| QOut( FIELD->ITEM ) } )

   dbCloseArea()
   hb_dbDrop( "testsort" )
   hb_dbDrop( "tempsort" )

   RETURN


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

[User] Define Harbour macros and constants: Harbour contribution module 'hblzf' (LZF compression library): contrib/hblzf/tests/test.prg. Contains procedures: Main. This file provides utility functions

[Assistant]
#require "hblzf"

#define TEST_STRING "This is test of LZF extension"
#define _NREPL_     128

PROCEDURE Main()

   LOCAL cStr, str_compressed, str_decompressed
   LOCAL b64_expected_result := "BFRoaXMgIAIUdGVzdCBvZiBMWkYgZXh0ZW5zaW9u"
   LOCAL nLen, nResult := 0

   ? "LZF API version is", ;
      hb_ntos( hb_lzf_version() ) + " (0x" + hb_NumToHex( hb_lzf_version() ) + ")"
   ? "LibLZF optimized for", iif( hb_lzf_optimized_for_speed(), "speed.", "compression." )

   ? "--- test 1 ---"

   cStr := TEST_STRING
   str_compressed := hb_lzf_compress( cStr, 15, @nResult )

   IF nResult == HB_LZF_OK
      ? "Lenght of a string is", hb_ntos( Len( cStr ) )
      ? "Lenght of a compressed string is", hb_ntos( Len( str_compressed ) )
   ELSE
      ? "hb_lzf_compress() returns", iif( nResult == HB_LZF_BUF_ERROR, "LZF_BUF_ERROR", "LZF_MEM_ERROR" )
   ENDIF

   ? "--- test 2 ---"
   cStr := TEST_STRING
   str_compressed := Space( 15 )
   str_compressed := hb_lzf_compress( cStr, @str_compressed, @nResult )

   IF nResult == HB_LZF_OK
      ? "Lenght of a string is", hb_ntos( Len( cStr ) )
      ? "Lenght of a compressed string is", hb_ntos( Len( str_compressed ) )
   ELSE
      ? "hb_lzf_compress() returns", iif( nResult == HB_LZF_BUF_ERROR, "LZF_BUF_ERROR", "LZF_MEM_ERROR" )
   ENDIF

   ? "--- test 3 ---"
   nLen := hb_lzf_compressbound( cStr )

   cStr := TEST_STRING
   str_compressed := hb_lzf_compress( cStr, nLen, @nResult )

   IF nResult == HB_LZF_OK
      ? "Lenght of a string is", hb_ntos( Len( cStr ) )
      ? "Lenght of a compressed string is", hb_ntos( Len( str_compressed ) )

      ? iif( hb_base64Encode( str_compressed ) == b64_expected_result, "OK!", "not OK!" )
   ELSE
      ? "hb_lzf_compress() returns", iif( nResult == HB_LZF_BUF_ERROR, "LZF_BUF_ERROR", "LZF_MEM_ERROR" )
   ENDIF

   ? "--- test 4 ---"
   nLen := hb_lzf_compressbound( cStr )
   str_compressed := Space( nLen )

   cStr := TEST_STRING
   str_compressed := hb_lzf_compress( cStr, @str_compressed, @nResult )

   IF nResult == HB_LZF_OK
      ? "Lenght of a string is", hb_ntos( Len( cStr ) )
      ? "Lenght of a compressed string is", hb_ntos( Len( str_compressed ) )

      ? iif( hb_base64Encode( str_compressed ) == b64_expected_result, "OK!", "not OK!" )
   ELSE
      ? "hb_lzf_compress() returns", iif( nResult == HB_LZF_BUF_ERROR, "LZF_BUF_ERROR", "LZF_MEM_ERROR" )
   ENDIF

   ? "--- test 5 ---"
   cStr := Replicate( TEST_STRING, _NREPL_ )
   str_compressed := hb_lzf_compress( cStr, NIL, @nResult )

   IF nResult == HB_LZF_OK
      ? "Lenght of a string is", hb_ntos( Len( cStr ) )
      ? "Lenght of a compressed string is", hb_ntos( Len( str_compressed ) )
   ELSE
      ? "hb_lzf_compress() returns", iif( nResult == HB_LZF_BUF_ERROR, "LZF_BUF_ERROR", "LZF_MEM_ERROR" )
   ENDIF

   ? "--- test 6 ---"
   str_decompressed := hb_lzf_decompress( str_compressed, NIL, @nResult )

   IF nResult == HB_LZF_DATA_CORRUPTED
      ? "LZF decompression failed, compressed data corrupted"
   ELSE
      ? iif( cStr == str_decompressed, "OK!", "not OK!" )
   ENDIF

   ? "--- test 7 ---"
   cStr := Replicate( TEST_STRING, _NREPL_ )
   str_compressed := hb_ZCompress( cStr, NIL, @nResult )

   str_decompressed := hb_lzf_decompress( str_compressed, NIL, @nResult )

   IF nResult == HB_LZF_DATA_CORRUPTED
      ? "LZF decompression failed, compressed data corrupted!"
   ELSE
      ? iif( cStr == str_decompressed, "OK!", "not OK!" )
   ENDIF

   ? "--- test 8 ---"
   cStr := Replicate( TEST_STRING, _NREPL_ )
   str_compressed := hb_lzf_compress( cStr, NIL, @nResult )

   str_decompressed := Space( 4096 )
   str_decompressed := hb_lzf_decompress( str_compressed, @str_decompressed, @nResult )

   IF nResult == HB_LZF_DATA_CORRUPTED
      ? "LZF decompression failed, compressed data corrupted!"
   ELSE
      ? iif( cStr == str_decompressed, "OK!", "not OK!" )
   ENDIF

   ? "--- test 9 ---"
   cStr := Replicate( TEST_STRING, _NREPL_ )
   str_compressed := hb_lzf_compress( cStr, NIL, @nResult )

   str_decompressed := ""
   str_decompressed := hb_lzf_decompress( str_compressed, @str_decompressed, @nResult )

   IF nResult != HB_LZF_OK
      ? "hb_lzf_decompress() returns", ;
         iif( nResult == HB_LZF_MEM_ERROR, "HB_LZF_MEM_ERROR", hb_ntos( nResult ) )
   ELSE
      ? iif( cStr == str_decompressed, "OK!", "not OK!" )
   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 header file: include/box.ch. Defines 9 constants including: _BOX_CH, B_SINGLE, B_DOUBLE, B_SINGLE_DOUBLE, B_DOUBLE_SINGLE. Defines Harbour internal constants and macros

[Assistant]
#ifndef _BOX_CH
#define _BOX_CH

#define B_SINGLE        ( Chr( 218 ) + Chr( 196 ) + Chr( 191 ) + Chr( 179 ) + ;
                          Chr( 217 ) + Chr( 196 ) + Chr( 192 ) + Chr( 179 ) )

#define B_DOUBLE        ( Chr( 201 ) + Chr( 205 ) + Chr( 187 ) + Chr( 186 ) + ;
                          Chr( 188 ) + Chr( 205 ) + Chr( 200 ) + Chr( 186 ) )

#define B_SINGLE_DOUBLE ( Chr( 214 ) + Chr( 196 ) + Chr( 183 ) + Chr( 186 ) + ;
                          Chr( 189 ) + Chr( 196 ) + Chr( 211 ) + Chr( 186 ) )

#define B_DOUBLE_SINGLE ( Chr( 213 ) + Chr( 205 ) + Chr( 184 ) + Chr( 179 ) + ;
                          Chr( 190 ) + Chr( 205 ) + Chr( 212 ) + Chr( 179 ) )

#define HB_B_SINGLE_UNI        hb_UTF8ToStrBox( "┌─┐│┘─└│" )
#define HB_B_DOUBLE_UNI        hb_UTF8ToStrBox( "╔═╗║╝═╚║" )
#define HB_B_SINGLE_DOUBLE_UNI hb_UTF8ToStrBox( "╓─╖║╜─╙║" )
#define HB_B_DOUBLE_SINGLE_UNI hb_UTF8ToStrBox( "╒═╕│╛═╘│" )

#endif


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

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

[Assistant]
REQUEST FCOMMA

PROCEDURE Main()

   USE test.csv VIA "FCOMMA"
   ? "ALIAS", Alias(), "RECNO", RecNo(), ;
      "BOF", Bof(), "EOF", Eof(), "LASTREC", LastRec()
   ? RecNo(), '"' + FIELD->LINE + '"'
   dbGoBottom()
   ? RecNo(), '"' + FIELD->LINE + '"'
   dbGoTop()
   ? RecNo(), '"' + FIELD->LINE + '"'
   WAIT
   DO WHILE ! Eof()
      ? RecNo(), '"' + FIELD->LINE + '"'
      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
   DO WHILE ! Bof()
      ? RecNo(), '[' + FIELD->LINE + ']'
      IF RecNo() == LastRec() - 20
         Inkey( 0 )
      ENDIF
      dbSkip( -1 )
   ENDDO
   ? "ALIAS", Alias(), "RECNO", RecNo(), ;
      "BOF", Bof(), "EOF", Eof(), "LASTREC", LastRec()
   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] Implement this Harbour module: Harbour contribution module 'hbnf' (NanForum Toolkit - legacy Clipper compatibility functions): contrib/hbnf/scregion.prg. Provides functions: ft_SavRgn, ft_RstRgn, ft_RgnStack. This file provides legacy compatibility functions

[Assistant]
THREAD STATIC t_aRgnStack := {}

FUNCTION ft_SavRgn( nTop, nLeft, nBottom, nRight )

   RETURN hb_BChar( nTop ) + hb_BChar( nLeft ) + hb_BChar( nBottom ) + hb_BChar( nRight ) + ;
      SaveScreen( nTop, nLeft, nBottom, nRight )

FUNCTION ft_RstRgn( cScreen, nTop, nLeft )

   IF PCount() == 3
      RestScreen( nTop, nLeft, ;
         ( nTop  - hb_BCode( hb_BSubStr( cScreen, 1, 1 ) ) ) + hb_BCode( hb_BSubStr( cScreen, 3, 1 ) ), ;
         ( nLeft - hb_BCode( hb_BSubStr( cScreen, 2, 1 ) ) ) + hb_BCode( hb_BSubStr( cScreen, 4, 1 ) ), ;
         hb_BSubStr( cScreen, 5 ) )
   ELSE
      RestScreen( ;
         hb_BCode( hb_BSubStr( cScreen, 1, 1 ) ), ;
         hb_BCode( hb_BSubStr( cScreen, 2, 1 ) ), ;
         hb_BCode( hb_BSubStr( cScreen, 3, 1 ) ), ;
         hb_BCode( hb_BSubStr( cScreen, 4, 1 ) ), ;
         hb_BSubStr( cScreen, 5 ) )
   ENDIF

   RETURN NIL

FUNCTION ft_RgnStack( cAction, nTop, nLeft, nBottom, nRight )

   THREAD STATIC t_nStackPtr := 0

   LOCAL nPopTop

   IF cAction == "push"

      ASize( t_aRgnStack, ++t_nStackPtr )[ t_nStackPtr ] := ;
         ft_SavRgn( nTop, nLeft, nBottom, nRight )

   ELSEIF cAction == "pop" .OR. cAction == "pop all"

      nPopTop := iif( "all" $ cAction, 0, t_nStackPtr - 1 )

      DO WHILE t_nStackPtr > nPopTop
         ft_RstRgn( t_aRgnStack[ t_nStackPtr-- ] )
      ENDDO

      ASize( t_aRgnStack, t_nStackPtr )

   ENDIF

   RETURN NIL