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

[User] Create Harbour preprocessor definitions: Harbour header file: include/hbusrrdd.ch. Defines 10 constants including: UR_BOF, UR_EOF, UR_FOUND, UR_GOBOTTOM, UR_GOTO. Defines Harbour internal constants and macros

[Assistant]
#define UR_BOF                                  1
#define UR_EOF                                  2
#define UR_FOUND                                3
#define UR_GOBOTTOM                             4
#define UR_GOTO                                 5
#define UR_GOTOID                               6
#define UR_GOTOP                                7
#define UR_SEEK                                 8
#define UR_SKIP                                 9
#define UR_SKIPFILTER                          10
#define UR_SKIPRAW                             11

#define UR_ADDFIELD                            12
#define UR_APPEND                              13
#define UR_CREATEFIELDS                        14
#define UR_DELETE                              15
#define UR_DELETED                             16
#define UR_FIELDCOUNT                          17
#define UR_FIELDDISPLAY                        18
#define UR_FIELDINFO                           19
#define UR_FIELDNAME                           20
#define UR_FLUSH                               21
#define UR_GETREC                              22
#define UR_GETVALUE                            23
#define UR_GETVARLEN                           24
#define UR_GOCOLD                              25
#define UR_GOHOT                               26
#define UR_PUTREC                              27
#define UR_PUTVALUE                            28
#define UR_RECALL                              29
#define UR_RECCOUNT                            30
#define UR_RECINFO                             31
#define UR_RECNO                               32
#define UR_RECID                               33
#define UR_SETFIELDEXTENT                      34

#define UR_ALIAS                               35
#define UR_CLOSE                               36
#define UR_CREATE                              37
#define UR_INFO                                38
#define UR_NEW                                 39
#define UR_OPEN                                40
#define UR_RELEASE                             41
#define UR_STRUCTSIZE                          42
#define UR_SYSNAME                             43
#define UR_DBEVAL                              44
#define UR_PACK                                45
#define UR_PACKREC                             46
#define UR_SORT                                47
#define UR_TRANS                               48
#define UR_TRANSREC                            49
#define UR_ZAP                                 50

#define UR_CHILDEND                            51
#define UR_CHILDSTART                          52
#define UR_CHILDSYNC                           53
#define UR_SYNCCHILDREN                        54
#define UR_CLEARREL                            55
#define UR_FORCEREL                            56
#define UR_RELAREA                             57
#define UR_RELEVAL                             58
#define UR_RELTEXT                             59
#define UR_SETREL                              60

#define UR_ORDLSTADD                           61
#define UR_ORDLSTCLEAR                         62
#define UR_ORDLSTDELETE                        63
#define UR_ORDLSTFOCUS                         64
#define UR_ORDLSTREBUILD                       65
#define UR_ORDSETCOND                          66
#define UR_ORDCREATE                           67
#define UR_ORDDESTROY                          68
#define UR_ORDINFO                             69

#define UR_CLEARFILTER                         70
#define UR_CLEARLOCATE                         71
#define UR_CLEARSCOPE                          72
#define UR_COUNTSCOPE                          73
#define UR_FILTERTEXT                          74
#define UR_SCOPEINFO                           75
#define UR_SETFILTER                           76
#define UR_SETLOCATE                           77
#define UR_SETSCOPE                            78
#define UR_SKIPSCOPE                           79
#define UR_LOCATE                              80

#define UR_COMPILE                             81
#define UR_ERROR                               82
#define UR_EVALBLOCK                           83

#define UR_RAWLOCK                             84
#define UR_LOCK                                85
#define UR_UNLOCK                              86

#define UR_CLOSEMEMFILE                        87
#define UR_CREATEMEMFILE                       88
#define UR_GETVALUEFILE                        89
#define UR_OPENMEMFILE                         90
#define UR_PUTVALUEFILE                        91

#define UR_READDBHEADER                        92
#define UR_WRITEDBHEADER                       93

#define UR_INIT                                94
#define UR_EXIT                                95
#define UR_DROP                                96
#define UR_EXISTS                              97
#define UR_RENAME                              98
#define UR_RDDINFO                             99

#define UR_WHOCARES                           100

#define UR_METHODCOUNT                        100

#ifndef HB_FT_NONE
#define HB_FT_NONE            0
#define HB_FT_STRING          1
#define HB_FT_LOGICAL         2
#define HB_FT_DATE            3
#define HB_FT_LONG            4
#define HB_FT_FLOAT           5
#define HB_FT_INTEGER         6
#define HB_FT_DOUBLE          7
#define HB_FT_TIME            8
#define HB_FT_TIMESTAMP       9
#define HB_FT_MODTIME         10
#define HB_FT_ROWVER          11
#define HB_FT_AUTOINC         12
#define HB_FT_CURRENCY        13
#define HB_FT_CURDOUBLE       14
#define HB_FT_VARLENGTH       15
#define HB_FT_MEMO            16
#define HB_FT_ANY             17
#define HB_FT_IMAGE           18
#define HB_FT_BLOB            19
#define HB_FT_OLE             20
#endif

#define DBTF_MATCH            0x0001
#define DBTF_PUTREC           0x0002
#define DBTF_CPYCTR           0x0004
#define DBTF_RECALL           0x0008

#define DBLM_EXCLUSIVE        1
#define DBLM_MULTIPLE         2
#define DBLM_FILE             3

#define FILE_LOCK             1
#define FILE_UNLOCK           2
#define REC_LOCK              3
#define REC_UNLOCK            4
#define HEADER_LOCK           5
#define HEADER_UNLOCK         6
#define APPEND_LOCK           7
#define APPEND_UNLOCK         8

#define UR_OI_AREA            1
#define UR_OI_NAME            2
#define UR_OI_ALIAS           3
#define UR_OI_SHARED          4
#define UR_OI_READONLY        5
#define UR_OI_CDPID           6
#define UR_OI_CONNECT         7
#define UR_OI_HEADER          8
#define UR_OI_SIZE            8

#define UR_FI_NAME            1
#define UR_FI_TYPE            2
#define UR_FI_TYPEEXT         3
#define UR_FI_LEN             4
#define UR_FI_DEC             5
#define UR_FI_SIZE            5

#define UR_LI_RECORD          1
#define UR_LI_METHOD          2
#define UR_LI_RESULT          3
#define UR_LI_SIZE            3

#define UR_FRI_BEXPR          1
#define UR_FRI_CEXPR          2
#define UR_FRI_ACTIVE         3
#define UR_FRI_OPTIMIZED      4
#define UR_FRI_CARGO          5
#define UR_FRI_SIZE           5

#define UR_RI_BEXPR           1
#define UR_RI_CEXPR           2
#define UR_RI_SCOPED          3
#define UR_RI_OPTIMIZED       4
#define UR_RI_PARENT          5
#define UR_RI_CHILD           6
#define UR_RI_NEXT            7
#define UR_RI_SIZE            7

#define UR_SI_BFOR            1
#define UR_SI_CFOR            2
#define UR_SI_BWHILE          3
#define UR_SI_CWHILE          4
#define UR_SI_NEXT            5
#define UR_SI_RECORD          6
#define UR_SI_REST            7
#define UR_SI_IGNOREFILTER    8
#define UR_SI_INCLUDEDELETED  9
#define UR_SI_LAST            10
#define UR_SI_IGNOREDUPS      11
#define UR_SI_BACKWARD        12
#define UR_SI_OPTIMIZED       13
#define UR_SI_SIZE            13

#define UR_EI_BLOCK           1
#define UR_EI_CEXPR           2
#define UR_EI_SCOPE           3


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

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

#define LI_NSTR         mslist[ 1 ]
#define LI_CLR          mslist[ 2 ]
#define LI_CLRV         mslist[ 3 ]
#define LI_BSKIP        mslist[ 4 ]
#define LI_BGTOP        mslist[ 5 ]
#define LI_BGBOT        mslist[ 6 ]
#define LI_BEOF         mslist[ 7 ]
#define LI_BBOF         mslist[ 8 ]
#define LI_B1           mslist[ 9 ]
#define LI_MSF          mslist[ 10 ]
#define LI_NAMES        mslist[ 11 ]
#define LI_NMCLR        mslist[ 12 ]
#define LI_FREEZE       mslist[ 13 ]
#define LI_RCOU         mslist[ 14 ]
#define LI_MSREC        mslist[ 15 ]
#define LI_PRFLT        mslist[ 16 ]
#define LI_TEKZP        mslist[ 17 ]
#define LI_KOLZ         mslist[ 18 ]
#define LI_VALID        mslist[ 19 ]
#define LI_WHEN         mslist[ 20 ]
#define LI_MSNAME       mslist[ 21 ]
#define LI_MSTYP        mslist[ 22 ]
#define LI_MSLEN        mslist[ 23 ]
#define LI_MSDEC        mslist[ 24 ]
#define LI_EXPFI        mslist[ 25 ]
#define LI_BDESHIN      mslist[ 26 ]
#define LI_BDESHOUT     mslist[ 27 ]
#define LI_RECNO        mslist[ 28 ]
#define LI_BGOTO        mslist[ 29 ]
#define LI_Y1           mslist[ 30 ]
#define LI_X1           mslist[ 31 ]
#define LI_Y2           mslist[ 32 ]
#define LI_X2           mslist[ 33 ]
#define LI_LSOHR        mslist[ 34 ]
#define LI_LVIEW        mslist[ 35 ]
#define LI_NCOLUMNS     mslist[ 36 ]
#define LI_LEFTVISIBLE  mslist[ 37 ]
#define LI_NLEFT        mslist[ 38 ]
#define LI_COLPOS       mslist[ 39 ]
#define LI_XPOS         mslist[ 40 ]
#define LI_MSED         mslist[ 41 ]
#define LI_COLCOUNT     mslist[ 42 ]
#define LI_LEN          42

PROCEDURE Main( filename )

   LOCAL vybkey := 1

   IF filename == NIL
      ? "Dbf browse demo"
      ? "Syntax:"
      ? "", "db_brows filename"
      QUIT
   ENDIF
   Set( _SET_DATEFORMAT, "yyyy-mm-dd" )
   USE ( filename )
   DO WHILE vybkey != 0
      vybkey := DBFLIST( , 3, 1, 76, 20, filename )
      DO CASE
      CASE vybkey == K_ENTER

      CASE vybkey == K_F3

      CASE vybkey == K_F5

      ENDCASE
   ENDDO

   RETURN

FUNCTION DBFLIST( mslist, x1, y1, x2, y2, title, maskey )

   LOCAL rezproc, xkey, rez, fipos, wndbuf, predit, predxx, oldcolors
   LOCAL i
   LOCAL fbar1, fbar2, vartmp, varbuf, razmer
   LOCAL GetList := {}

   LOCAL str_barbox := hb_UTF8ToStrBox( "░" )
   LOCAL str_bar    :=  Chr( 31 ) + Chr( 30 ) + hb_UTF8ToStr( "■" )

   IF mslist == NIL
      mslist := InitList()
   ENDIF
   LI_Y1 := y1
   LI_X1 := x1
   LI_Y2 := y2
   LI_X2 := x2
   IF LI_MSF == NIL
      LI_COLCOUNT := FCount()
      LI_MSTYP := Array( LI_COLCOUNT )
      LI_MSLEN := Array( LI_COLCOUNT )
      LI_MSDEC := Array( LI_COLCOUNT )
      AFields( , LI_MSTYP, LI_MSLEN, LI_MSDEC )
   ELSE
      LI_COLCOUNT := Len( LI_MSF )
      IF LI_MSTYP == NIL
         LI_MSTYP := Array( LI_COLCOUNT )
         LI_MSLEN := Array( LI_COLCOUNT )
         LI_MSDEC := Array( LI_COLCOUNT )
         FOR i := 1 TO LI_COLCOUNT
            IF HB_ISBLOCK( LI_MSF[ i ] )
               vartmp        := Eval( LI_MSF[ i ], mslist, i )
               LI_MSTYP[ i ] := ValType( vartmp )
               IF LI_MSTYP[ i ] == "C"
                  LI_MSLEN[ i ] := Len( vartmp )
               ELSEIF LI_MSTYP[ i ] == "N"
                  vartmp        := Str( vartmp )
                  LI_MSLEN[ i ] := Len( vartmp )
                  LI_MSDEC[ i ] := iif( "." $ vartmp, LI_MSLEN[ i ] - At( ".", vartmp ), 0 )
               ELSEIF LI_MSTYP[ i ] == "D"
                  LI_MSLEN[ i ] := 8
               ELSEIF LI_MSTYP[ i ] == "L"
                  LI_MSLEN[ i ] := 1
               ENDIF
            ELSE
               LI_MSTYP[ i ] := ValType( FieldGet( FieldPos( LI_MSF[ i ] ) ) )
            ENDIF
         NEXT
      ENDIF
   ENDIF
   IF HB_ISNUMERIC( LI_MSED )
      predxx := predit := LI_MSED
   ELSE
      predxx := predit := iif( AScan( LI_MSED, 3 ) != 0, 3, iif( AScan( LI_MSED, 2 ) != 0, 2, 1 ) )
   ENDIF
   SET CURSOR ( predit > 1 )
   IF LI_LSOHR
      wndbuf := SaveScreen( LI_Y1, LI_X1, LI_Y2, LI_X2 )
   ENDIF
   oldcolors := SetColor()
   SetColor( LI_CLR )
   hb_DispBox( LI_Y1, LI_X1, LI_Y2, LI_X2, hb_UTF8ToStrBox( "┌─┐│┘─└│ " ) )
   IF title != NIL
      hb_DispOutAt( LI_Y1, ( LI_X2 - LI_X1 - 1 - Len( title ) ) / 2 + LI_X1, " " + title + " " )
   ENDIF
   IF title != NIL .AND. LI_NAMES != NIL
      LI_Y1++
   ENDIF
   razmer := LI_Y2 - LI_Y1 - 1
   IF ! LI_PRFLT
      LI_KOLZ := Eval( LI_RCOU, mslist )
   ENDIF
   LI_COLPOS := 1
   LI_NLEFT  := LI_FREEZE + 1

   LI_LEFTVISIBLE := LI_NLEFT
   STORE .T. TO rez
   LI_NCOLUMNS := FLDCOUNT( mslist, LI_X1 + 2, LI_X2 - 2, LI_NLEFT )
   VIVNAMES( mslist, LI_NLEFT )
   IF Eval( LI_BEOF, mslist )
      Eval( LI_BGTOP, mslist )
      LI_NSTR := 1
   ELSE
      Eval( LI_BSKIP, mslist, -( LI_NSTR - 1 ) )
      IF Eval( LI_BBOF, mslist )
         Eval( LI_BGTOP, mslist )
         LI_NSTR := 1
      ENDIF
   ENDIF
   WNDVIVOD( mslist )
   Eval( LI_BSKIP, mslist, ( LI_NSTR - 1 ) )
   IF LI_KOLZ == 0 .AND. predit == 3
      LI_NSTR := 0
      hb_keyIns( K_DOWN )
   ENDIF
   DO WHILE rez
      SetColor( LI_CLR )
      Eval( LI_B1, mslist )

         SetColor( LI_CLRV )

      VIVSTR( mslist, LI_NSTR + LI_Y1, iif( predit > 1, LI_COLPOS, 0 ) )
      SetColor( LI_CLR )

      DO CASE
      CASE !( Type( "sx_KeyNo()" ) == "U" )
         fbar1 := "sx_KeyNo()"
         fbar2 := "sx_KeyCount()"
      CASE !( Type( "AdsKeyNo()" ) == "U" )
         fbar1 := "AdsKeyNo()"
         fbar2 := "AdsKeyCount()"
      CASE !( Type( "Ax_KeyNo()" ) == "U" )
         fbar1 := "Ax_KeyNo()"
         fbar2 := "Ax_KeyCount()"
      ENDCASE
      IF ! Empty( fbar1 )
         hb_DispBox( LI_Y1 + 2, LI_X2, LI_Y2 - 2, LI_X2, str_barbox )
         hb_DispOutAt( LI_Y1 + 1, LI_X2, SubStr( str_bar, 2, 1 ) )
         hb_DispOutAt( LI_Y2 - 1, LI_X2, SubStr( str_bar, 1, 1 ) )
         hb_DispOutAt( LI_Y1 + 2 + Int( iif( LI_PRFLT, LI_TEKZP, &fbar1 )
      CASE ( xkey == K_ENTER .OR. !( hb_keyChar( xkey ) == "" ) ) .AND. predit > 1
         fipos := LI_COLPOS + LI_NLEFT - 1 - LI_FREEZE
         IF LI_WHEN == NIL .OR. Len( LI_WHEN ) < fipos .OR. LI_WHEN[ fipos ] == NIL .OR. Eval( LI_WHEN[ fipos ] )
            IF ! HB_ISNUMERIC( LI_MSED )
               vartmp := iif( Len( LI_MSED ) < fipos, 1, LI_MSED[ fipos ] )
               IF HB_ISNUMERIC( vartmp )
                  IF vartmp != 2
                     LOOP
                  ENDIF
               ELSE
                  LOOP
               ENDIF
            ENDIF
            SET CURSOR ON
            SetColor( LI_CLRV + "," + LI_CLRV )
            IF xkey != K_ENTER
               DO WHILE NextKey() != 0
                  hb_keyPut( Inkey( 0 ) )
               ENDDO
               hb_keyIns( xkey )
            ENDIF
            vartmp := ReadExit( .T. )
            varbuf := FieldGet( fipos )
            @ LI_NSTR + LI_Y1, LI_XPOS GET varbuf PICTURE Defpict( mslist, fipos, LI_X2 - LI_X1 - 3 )
            IF LI_VALID != NIL .AND. Len( LI_VALID ) >= fipos .AND. LI_VALID[ fipos ] != NIL
               Getlist[ 1 ]:postBlock := LI_VALID[ fipos ]
            ENDIF
            READ
            IF LastKey() != K_ESC .AND. Updated()
               IF Eval( LI_BEOF, mslist )
                  APPEND BLANK
                  LI_KOLZ := Eval( LI_RCOU, mslist )
               ELSE
                  IF ! Set( _SET_EXCLUSIVE )
                     RLock()
                     IF NetErr()
                        LOOP
                     ENDIF
                  ENDIF
               ENDIF
               IF LI_BDESHOUT != NIL .AND. HB_ISSTRING( varbuf )
                  varbuf := Eval( LI_BDESHOUT, mslist, varbuf )
               ENDIF
               FieldPut( fipos, varbuf )
               IF ! Set( _SET_EXCLUSIVE )
                  UNLOCK
               ENDIF
            ENDIF
            IF ( LastKey() == K_ESC .OR. ! Updated() ) .AND. Eval( LI_BEOF, mslist )
               SetColor( LI_CLR )


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

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

Harbour header file: include/button.ch. Defines 10 constants including: HB_BUTTON_CH_, _BUTTON_DEFINED, SCROLL_VERTICAL, SCROLL_HORIZONTAL, MENU_SEPARATOR. Defines Harbour internal constants and macros

[Assistant]
#ifndef HB_BUTTON_CH_
#define HB_BUTTON_CH_
#define _BUTTON_DEFINED

#define SCROLL_VERTICAL          1
#define SCROLL_HORIZONTAL        2

#define MENU_SEPARATOR           Chr( 196 )
#define SEPARATOR_DOUBLE         ( Chr( 204 ) + Chr( 205 ) + Chr( 185 ) )
#define SEPARATOR_SINGLE         ( Chr( 195 ) + MENU_SEPARATOR + Chr( 180 ) )
#define SEPARATOR_DOUBLE_SINGLE  ( Chr( 199 ) + MENU_SEPARATOR + Chr( 182 ) )

#define HB_MENU_SEPARATOR_UNI          hb_UTF8ToStrBox( "─" )
#define HB_SEPARATOR_DOUBLE_UNI        hb_UTF8ToStrBox( "╠═╣" )
#define HB_SEPARATOR_SINGLE_UNI        hb_UTF8ToStrBox( "├─┤" )
#define HB_SEPARATOR_DOUBLE_SINGLE_UNI hb_UTF8ToStrBox( "╟─╢" )

#define HTNOWHERE                0

#define HTTOPLEFT                -1
#define HTTOP                    -2
#define HTTOPRIGHT               -3
#define HTRIGHT                  -4
#define HTBOTTOMRIGHT            -5
#define HTBOTTOM                 -6
#define HTBOTTOMLEFT             -7
#define HTLEFT                   -8

#define HTBORDERFIRST            -8
#define HTBORDERLAST             -1

#define HTCAPTION                -1025

#define HTCLIENT                 -2049

#define HTSCROLLTHUMBDRAG        -3073
#define HTSCROLLUNITDEC          -3074
#define HTSCROLLUNITINC          -3075
#define HTSCROLLBLOCKDEC         -3076
#define HTSCROLLBLOCKINC         -3077

#define HTSCROLLFIRST            -3077
#define HTSCROLLLAST             -3073

#define HTDROPBUTTON             -4097
#define HTSEPARATOR              -4098

#define HTCELL                   -5121
#define HTHEADING                -5122
#define HTFOOTING                -5123
#define HTHEADSEP                -5124
#define HTFOOTSEP                -5125
#define HTCOLSEP                 -5126

#define HTMENU                   -6145
#define HTSIZE                   -6146
#define HTMINBUTTON              -6147
#define HTMAXBUTTON              -6148
#define HTGROWBOX                HTSIZE
#define HTREDUCE                 HTMINBUTTON
#define HTZOOM                   HTMAXBUTTON

#endif


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

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

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

[Assistant]
PROCEDURE Main()

   ? CMonth( Date() )
   ? CMonth( Date() + 31 )
   ? CMonth( Date() + 60 )
   ?

   ? CDoW( Date() )
   ? CDoW( Date() + 6 )
   ? CDoW( Date() + 7 )
   ?

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

[Assistant]
#ifdef __HARBOUR__
#require "hbct"
#else
#define hb_ntos( n ) LTrim( Str( n ) )
#endif

PROCEDURE Main()

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

   ctinit()

   ? "Begin test of AtToken()"
   ?

   ? "  Simple tests:"
   ? '    AtToken( "Hello, World!" ) == 8 ? ------------> ' + Str( AtToken( "Hello, World!" ) )
   ? '    AtToken( "Hello, World!",, 2 ) == 8 ? --------> ' + Str( AtToken( "Hello, World!",, 2 ) )
   ? '    AtToken( "Hello, World!",, 2, 1 ) == 7 ? -----> ' + Str( AtToken( "Hello, World!",, 2, 1 ) )
   ? '    AtToken( "Hello, World!", " ", 2, 1 ) == 8 ? -> ' + Str( AtToken( "Hello, World!", " ", 2, 1 ) )
   ?

   ? '  Tokenizing a string with skip width == 1 and ".!" as tokenizer list:'
   ? "    Value of cStr is: " + '"' + cStr + '"'
   ?
   FOR ni := 1 TO NumToken( cStr, ".!", 1 )
      ? '    Token #' + hb_ntos( ni ) + '("' + Token( cStr, ".!", ni, 1 ) + '")'
      ? "          starts at pos " + Str( npos := AtToken( cStr, ".!", ni, 1 ), 3 ) + ;
         " and is " + iif( SubStr( cStr, npos, 1 ) $ ".!", "", "not " ) + "an empty token."
   NEXT

   ?
   ? "End test of AtToken()"
   ?

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

[Assistant]
#include "simpleio.ch"

PROCEDURE Main()

   LOCAL cVector, cStr

   LOCAL hTestVectors := { ;
      ""       => "", ;
      "f"      => "Zg==", ;
      "fo"     => "Zm8=", ;
      "foo"    => "Zm9v", ;
      "foob"   => "Zm9vYg==", ;
      "fooba"  => "Zm9vYmE=", ;
      "foobar" => "Zm9vYmFy" }

   FOR EACH cVector IN hTestVectors

      cStr := hb_base64Encode( cVector:__enumKey )
      IF !( cStr == cVector )
         ? hb_StrFormat( "hb_base64Encode(): expected '%s' got '%s' while encoding '%s'", ;
            cVector:__enumKey(), cStr, cVector )
      ELSE
         ? hb_StrFormat( "hb_base64Encode(): passed '%s'", cVector:__enumKey )
      ENDIF

      cStr := hb_base64Decode( cVector )
      IF !( cStr == cVector:__enumKey() )
         ? hb_StrFormat( "hb_base64Decode(): expected '%s' got '%s' while decoding '%s'", ;
            cVector, cStr, cVector:__enumKey() )
      ELSE
         ? hb_StrFormat( "hb_base64Decode(): passed '%s'", cVector )
      ENDIF
   NEXT

   RETURN


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

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

Harbour test program: tests/array16.prg. Provides functions: Test, ReleaseTest. Contains procedures: Main. This test file exercises basic Harbour language features

[Assistant]
PROCEDURE Main()

   LOCAL a := { 100, 200, "Third" }
   LOCAL b := Array( 8832 )

   ? ValType( a )
   ? ValType( { "A" } )

   AAdd( a, "new element" )
   ? Len( a )

   ? a[ 1 ]
   ? a[ 2 ]
   ? a[ 3 ]
   ? a[ 4 ]

   ? ATail( a )

   a[ 3 ] := { "this", { "seems", "to", { "work", "so", "well" } } }
   ? a[ 3 ][ 2 ][ 3 ][ 1 ]

   a[ 3, 2 ][ 3, 1 ] := "Harbour power!"
   ? a[ 3, 2, 3, 1 ]

   ? ValType( b )
   ? Len( b )

   b[ 8832 ] := "Harbour"

   ? b[ 8832 ]

   ? ATail( b )

   ASize( b, 200 )
   ? Len( b )

   b[ 100 ] := 10
   Test( b[ 100 ]++ )
   ? b[ 100 ]

   b[ 100 ] := 10
   Test( ++b[ 100 ] )
   ? b[ 100 ]

   b := { 1, { 2, { 4, 5 } } }
   Test( b[ 2 ][ 2 ][ 1 ]++ )
   ? b[ 2 ][ 2 ][ 1 ]

   b[ 2 ][ 2 ][ 1 ] := 2
   Test( ++b[ 2 ][ 2 ][ 1 ] )
   ? b[ 2 ][ 2 ][ 1 ]

   ReleaseTest()

   RETURN

FUNCTION Test( n )

   ? n

   RETURN NIL

FUNCTION ReleaseTest()

   LOCAL a := { 1, 2, 3 }

   HB_SYMBOL_UNUSED( a )

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

Header file for contribution module 'hbzebra' (Barcode generation library): contrib/hbzebra/hbzebra.ch. Defines 10 constants including: HB_ZEBRA_CH_, HB_ZEBRA_TYPE_EAN13, HB_ZEBRA_TYPE_EAN8, HB_ZEBRA_TYPE_UPCA, HB_ZEBRA_TYPE_UPCE. Defines Harbour internal constants and macros

[Assistant]
#ifndef HB_ZEBRA_CH_
#define HB_ZEBRA_CH_

#define HB_ZEBRA_TYPE_EAN13                 1
#define HB_ZEBRA_TYPE_EAN8                  2
#define HB_ZEBRA_TYPE_UPCA                  3
#define HB_ZEBRA_TYPE_UPCE                  4
#define HB_ZEBRA_TYPE_CODE128               5
#define HB_ZEBRA_TYPE_CODE93                6
#define HB_ZEBRA_TYPE_CODE39                7
#define HB_ZEBRA_TYPE_CODE11                8
#define HB_ZEBRA_TYPE_CODABAR               9
#define HB_ZEBRA_TYPE_ITF                   10
#define HB_ZEBRA_TYPE_MSI                   11

#define HB_ZEBRA_TYPE_PDF417                257
#define HB_ZEBRA_TYPE_DATAMATRIX            258
#define HB_ZEBRA_TYPE_QRCODE                259

#define HB_ZEBRA_ERROR_INVALIDCODE          1
#define HB_ZEBRA_ERROR_BADCHECKSUM          2
#define HB_ZEBRA_ERROR_TOOLARGE             3
#define HB_ZEBRA_ERROR_ARGUMENT             4

#define HB_ZEBRA_ERROR_INVALIDZEBRA         101

#define HB_ZEBRA_FLAG_CHECKSUM              1
#define HB_ZEBRA_FLAG_WIDE2                 0x00
#define HB_ZEBRA_FLAG_WIDE2_5               0x40
#define HB_ZEBRA_FLAG_WIDE3                 0x80

#define HB_ZEBRA_FLAG_PDF417_TRUNCATED      0x0100
#define HB_ZEBRA_FLAG_PDF417_LEVEL_MASK     0xF000
#define HB_ZEBRA_FLAG_PDF417_LEVEL0         0x1000
#define HB_ZEBRA_FLAG_PDF417_LEVEL1         0x2000
#define HB_ZEBRA_FLAG_PDF417_LEVEL2         0x3000
#define HB_ZEBRA_FLAG_PDF417_LEVEL3         0x4000
#define HB_ZEBRA_FLAG_PDF417_LEVEL4         0x5000
#define HB_ZEBRA_FLAG_PDF417_LEVEL5         0x6000
#define HB_ZEBRA_FLAG_PDF417_LEVEL6         0x7000
#define HB_ZEBRA_FLAG_PDF417_LEVEL7         0x8000
#define HB_ZEBRA_FLAG_PDF417_LEVEL8         0x9000

#define HB_ZEBRA_FLAG_DATAMATRIX_SQUARE     0x0100
#define HB_ZEBRA_FLAG_DATAMATRIX_RECTANGLE  0x0200

#define HB_ZEBRA_FLAG_QR_LEVEL_MASK         0x0700
#define HB_ZEBRA_FLAG_QR_LEVEL_L            0x0100
#define HB_ZEBRA_FLAG_QR_LEVEL_M            0x0200
#define HB_ZEBRA_FLAG_QR_LEVEL_Q            0x0300
#define HB_ZEBRA_FLAG_QR_LEVEL_H            0x0400

#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 contribution module 'hbnf' (NanForum Toolkit - legacy Clipper compatibility functions): contrib/hbnf/tests/menu1.prg. Provides functions: fubar. Contains procedures: Main. This file provides legacy compatibility functions

[Assistant]
#require "hbnf"

#include "setcurs.ch"

PROCEDURE Main( cCmdLine )

   LOCAL sDosScrn, nDosRow, nDosCol, lColor

   LOCAL cNormN
   LOCAL cWindN
   LOCAL cErrH
   LOCAL cErrN

   LOCAL aColors
   LOCAL aBar     := { " ENTER/EDIT ", " REPORTS ", " DISPLAY ", " MAINTENANCE ", " QUIT " }
   LOCAL aOptions[ Len( aBar ) ]

   LOCAL nMaxRow

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

   AEval( aBar, {| x, i | HB_SYMBOL_UNUSED( x ), aOptions[ i ] := { {}, {}, {} } } )

   cCmdLine := iif( cCmdLine == NIL, "", cCmdLine )

   lColor := iif( "MONO" $ Upper( cCmdLine ), .F., IsColor() )

   aColors := iif( lColor, { "W+/G", "N/G", "N/G", "N/W", "N+/G" }, ;
      { "W+/N", "W+/N", "W/N", "N/W", "W/N" } )

   ft_Fill( aOptions[ 1 ], "A. Execute A Dummy Procedure"        , {|| fubar() }, .T. )
   ft_Fill( aOptions[ 1 ], "B. Enter Daily Charge/Credit Slips"  , {|| .T. }, .T. )
   ft_Fill( aOptions[ 1 ], "C. Enter Payments On Accounts"       , {|| .T. }, .F. )
   ft_Fill( aOptions[ 1 ], "D. Edit Daily Transactions"          , {|| .T. }, .T. )
   ft_Fill( aOptions[ 1 ], "E. Enter/Update Member File"         , {|| .T. }, .T. )
   ft_Fill( aOptions[ 1 ], "F. Update Code File"                 , {|| .T. }, .F. )
   ft_Fill( aOptions[ 1 ], "G. Add/Update Auto Charge File"      , {|| .T. }, .T. )
   ft_Fill( aOptions[ 1 ], "H. Post All Transactions To A/R File", {|| .T. }, .T. )
   ft_Fill( aOptions[ 1 ], "I. Increment Next Posting Date"      , {|| .T. }, .T. )

   ft_Fill( aOptions[ 2 ], "A. Print Member List"                , {|| .T. }, .T. )
   ft_Fill( aOptions[ 2 ], "B. Print Active Auto Charges"        , {|| .T. }, .T. )
   ft_Fill( aOptions[ 2 ], "C. Print Edit List"                  , {|| .T. }, .T. )
   ft_Fill( aOptions[ 2 ], "D. Print Pro-Usage Report"           , {|| .T. }, .T. )
   ft_Fill( aOptions[ 2 ], "E. Print A/R Transaction Report"     , {|| .T. }, .T. )
   ft_Fill( aOptions[ 2 ], "F. Aging Report Preparation"         , {|| .T. }, .T. )
   ft_Fill( aOptions[ 2 ], "G. Add Interest Charges"             , {|| .T. }, .T. )
   ft_Fill( aOptions[ 2 ], "H. Print Aging Report"               , {|| .T. }, .T. )
   ft_Fill( aOptions[ 2 ], "I. Print Monthly Statements"         , {|| .T. }, .T. )
   ft_Fill( aOptions[ 2 ], "J. Print Mailing Labels"             , {|| .T. }, .T. )
   ft_Fill( aOptions[ 2 ], "K. Print Transaction Totals"         , {|| .T. }, .T. )
   ft_Fill( aOptions[ 2 ], "L. Print Transaction Codes File"     , {|| .T. }, .T. )
   ft_Fill( aOptions[ 2 ], "M. Print No-Activity List"           , {|| .T. }, .T. )

   ft_Fill( aOptions[ 3 ], "A. Transaction Totals Display"       , {|| .T. }, .T. )
   ft_Fill( aOptions[ 3 ], "B. Display Invoice Totals"           , {|| .T. }, .T. )
   ft_Fill( aOptions[ 3 ], "C. Accounts Receivable Display"      , {|| .T. }, .T. )

   ft_Fill( aOptions[ 4 ], "A. Backup Database Files"            , {|| .T. }, .T. )
   ft_Fill( aOptions[ 4 ], "B. Reindex Database Files"           , {|| .T. }, .T. )
   ft_Fill( aOptions[ 4 ], "C. Set System Parameters"            , {|| .T. }, .T. )
   ft_Fill( aOptions[ 4 ], "D. This EXITs Too"                   , {|| .F. }, .T. )

   ft_Fill( aOptions[ 5 ], "A. Does Nothing"                     , {|| .T. }, .T. )
   ft_Fill( aOptions[ 5 ], "B. Exit Application"                 , {|| .F. }, .T. )

   SET SCOREBOARD OFF

   cNormN := iif( lColor, "N/G" , "W/N"  )
   cWindN := iif( lColor, "W/B" , "W/N"  )
   cErrH  := iif( lColor, "W+/R", "W+/N" )
   cErrN  := iif( lColor, "W/R" , "W/N"  )

   SAVE SCREEN TO sDosScrn
   nDosRow := Row()
   nDosCol := Col()
   SetColor( "w/n" )
   CLS
   NoSnow( "NOSNOW" $ Upper( cCmdLine ) )
   IF "VGA" $ Upper( cCmdLine )
      SetMode( 50, 80 )
   ENDIF
   nMaxRow := MaxRow()
   SetBlink( .F. )
   SetColor( cWindN + "*" )
   CLS
   SetColor( cNormN )
   @ nMaxRow, 0
   @ nMaxRow, 0 SAY hb_UTF8ToStr( " FT_MENU1 1.0 │ " )
   @ nMaxRow, 16 SAY "WRITTEN BY PAUL FERRARA [76702,556] FOR NANFORUM.LIB"
   @ nMaxRow, 69 SAY hb_UTF8ToStr( "│ " ) + DToC( Date() )

   SetColor( cErrH )
   @ nMaxRow - 11, 23, nMaxRow - 3, 56 BOX hb_UTF8ToStr( "┌─┐│┘─└│ " )
   @ nMaxRow - 9, 23 SAY hb_UTF8ToStr( "├────────────────────────────────┤" )
   SetColor( cErrN )
   @ nMaxRow - 10, 33 SAY "Navigation Keys"
   @ nMaxRow - 8, 25 SAY "LeftArrow   RightArrow   Alt-E"
   @ nMaxRow - 7, 25 SAY "Home        End          Alt-R"
   @ nMaxRow - 6, 25 SAY "Tab         Shift-Tab    Alt-D"
   @ nMaxRow - 5, 25 SAY "PgUp        PgDn         Alt-M"
   @ nMaxRow - 4, 25 SAY "Enter       ESCape       Alt-Q"
   SetColor( cNormN )

   ft_Menu1( aBar, aOptions, aColors )

   SetColor( "W/N" )
   SetCursor( SC_NORMAL )
   SetBlink( .T. )
   IF "VGA" $ Upper( cCmdLine )
      SetMode( 25, 80 )
   ENDIF
   RESTORE SCREEN FROM sDosScrn
   SetPos( nDosRow, nDosCol )

   RETURN

FUNCTION fubar()

   LOCAL OldColor := SetColor( "W/N" )

   CLS
   QOut( "Press Any Key" )
   Inkey( 0 )
   SetColor( OldColor )

   RETURN .T.


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

[User] Implement this Harbour module: Harbour test program: tests/mt/mttest07.prg. This test file tests specific function APIs

[Assistant]
#define N_THREADS 5
#define N_JOBS    10000

static s_aCounters
static s_mtxJobs
static s_mtxResults

proc main()
   local aThreads, aResults, i, nDigit, nSum, nExpected

   ? Version()
   ? "Main start"

   s_aCounters := array( N_THREADS )
   aFill( s_aCounters, 0 )
   aThreads := {}
   aResults := {}
   s_mtxJobs := hb_mutexCreate()
   s_mtxResults := hb_mutexCreate()

   ? "Starting threads: "
   for i := 1 to N_THREADS
      aadd( aThreads, hb_threadStart( @thFunc() ) )
      ?? "<" + hb_ntos( i ) + ">"
   next

   ? "Sending jobs... "
   nDigit := 10
   for i := 1 to N_JOBS
      hb_mutexNotify( s_mtxJobs, nDigit )

      nDigit++
   next

   ? "Sending terminate values..."
   for i := 1 to N_THREADS
      hb_mutexNotify( s_mtxJobs, NIL )
      ?? "<" + hb_ntos( i ) + ">"
   next

   ? "Collecting results... "
   for i := 1 to N_JOBS
      hb_mutexSubscribe( s_mtxResults,, @nDigit )

      aadd( aResults, nDigit )
   next

   ? "Waiting for threads..."
   aEval( aThreads, {| x | hb_threadJoin( x ) } )
   ? "Threads joined"

   nSum := 0
   for each nDigit in aResults
      nSum += nDigit
   next

   nSum := round( nSum, 2 )
   nExpected := round( ( 10 + 10 + N_JOBS - 1 ) / 2 / 3
      ? "OK, final sum:", hb_ntos( nSum )
   else
      ? "ERROR, final sum:", hb_ntos( nSum ), ;
        "expected:", hb_ntos( nExpected )
   endif
   ? "End of main"
return

proc thFunc()
   local xJob, xResult
   while .T.
      hb_mutexSubscribe( s_mtxJobs,, @xJob )
      if xJob == NIL
         exit
      endif
      xResult := xJob / 3
      hb_mutexNotify( s_mtxResults, xResult )
   enddo
return


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

[User] Write Harbour functions: FPTCDX_GETFUNCTABLE. Harbour contribution module 'rddmisc' (): contrib/rddmisc/fptcdx.prg. Provides functions: FPTCDX_GETFUNCTABLE. Contains procedures: FPTCDX_INIT. This file handles database operations

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

REQUEST DBFCDX
REQUEST DBFFPT

ANNOUNCE FPTCDX

FUNCTION FPTCDX_GETFUNCTABLE( pFuncCount, pFuncTable, pSuperTable, nRddID, pSuperRddID )
   RETURN USRRDD_GETFUNCTABLE( pFuncCount, pFuncTable, pSuperTable, nRddID, ;
      "DBFCDX", {}, pSuperRddID )

INIT PROCEDURE FPTCDX_INIT()

   rddRegister( "FPTCDX", RDT_FULL )
   rddInfo( RDDI_MEMOTYPE, DB_MEMO_FPT, "FPTCDX" )

   RETURN


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

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

Harbour contribution module 'hbtip' (Internet protocol utilities (FTP, HTTP, SMTP, POP3)): contrib/hbtip/tests/tipmmail.prg. Contains procedures: Main, Usage. This file provides network protocol implementations

[Assistant]
#require "hbtip"

PROCEDURE Main( ... )

   LOCAL oMail, cData, i, oAttach
   LOCAL cFname

   IF PCount() == 0
      Usage()
      RETURN
   ENDIF

   oMail := TIPMail():New( "This is the body of the mail" )
   oMail:hHeaders[ "Content-Type" ] := "text/plain; charset=utf-8"
   oMail:hHeaders[ "Date" ] := tip_TimeStamp()

   FOR i := 1 TO PCount()

      SWITCH Lower( cData := hb_PValue( i ) )
      CASE "-h"
         Usage()
         RETURN
      CASE "-f"
         IF HB_ISSTRING( cData := hb_PValue( ++i ) )
            oMail:hHeaders[ "From" ] := hb_StrToUTF8( cData )
         ENDIF
         EXIT
      CASE "-t"
         IF HB_ISSTRING( cData := hb_PValue( ++i ) )
            oMail:hHeaders[ "To" ] := hb_StrToUTF8( cData )
         ENDIF
         EXIT
      CASE "-s"
         IF HB_ISSTRING( cData := hb_PValue( ++i ) )
            oMail:hHeaders[ "Subject" ] := hb_StrToUTF8( cData )
         ENDIF
         EXIT
      CASE "-b"
         IF HB_ISSTRING( cData := hb_PValue( ++i ) )
            oMail:SetBody( hb_StrToUTF8( cData ) + e"\r\n" )
         ENDIF
         EXIT
      CASE "-m"
         IF HB_ISSTRING( cData := hb_PValue( ++i ) )
            IF ( cData := hb_MemoRead( cData ) ) == ""
               ? "Fatal: Could not read", hb_PValue( i )
               RETURN
            ENDIF
            oMail:SetBody( cData + e"\r\n" )
         ENDIF
         EXIT
      OTHERWISE
         IF ( cData := hb_MemoRead( cData ) ) == ""
            ? "Fatal: Could not read attachment or attachment empty", hb_PValue( i )
            RETURN
         ENDIF

         oAttach := TIPMail():New()
         oAttach:SetEncoder( "base64" )

         cFName := hb_FNameNameExt( hb_PValue( i ) )

         oAttach:hHeaders[ "Content-Type" ] := ;
            "application/X-TIP-Attachment; filename=" + cFName

         oAttach:hHeaders[ "Content-Disposition" ] := ;
            "attachment; filename=" + cFname
         oAttach:SetBody( cData )

         oMail:Attach( oAttach )
      ENDSWITCH
   NEXT

   OutStd( oMail:ToString() )

   RETURN

STATIC PROCEDURE Usage()

   ? "Usage:"
   ? "   tipmmail [options] attachment1, attachment2..."
   ? "Options:"
   ? "   -h              Help"
   ? '   -f "from"       Set "mail from" field'
   ? '   -t "to"         Set "mail to" field'
   ? '   -s "subject"    Set mail subject'
   ? '   -b "body"       Set mail body (or message)'
   ? '   -m "bodyfile"   Set mail body using a file'
   ?

   RETURN


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

[User] Create Harbour OOP classes for the functionality described: Harbour test program: tests/clasinh.prg. Defines classes: TClassBase, TAnyClass. Contains procedures: Main. This test file tests specific function APIs

[Assistant]
#include "hbclass.ch"

PROCEDURE Main()

   LOCAL oObject, oBase

   oObject := TAnyClass():New()
   oBase := TClassBase():New()

   HB_SYMBOL_UNUSED( oObject )
   HB_SYMBOL_UNUSED( oBase )

   RETURN

CREATE CLASS TClassBase

   METHOD New()
   METHOD Test() INLINE Alert( "Test" )

ENDCLASS

METHOD New() CLASS TClassBase

   RETURN Self

CREATE CLASS TAnyClass FROM TClassBase

   METHOD New()

ENDCLASS

METHOD New() CLASS TAnyClass

   ::super:New()
   ::super:Test()

   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] Write a Harbour program with procedures: Main. Harbour extra library: extras/hbxlsxml/tests/example2.prg. Contains procedures: Main. This file provides spreadsheet generation capabilities

[Assistant]
#require "hbxlsxml"

PROCEDURE Main()

   LOCAL xml, format1, format2, format3, format4
   LOCAL sheet1, sheet2, sheet4

   xml := ExcelWriterXML():new( "my file.xml" )

   xml:docTitle( "My Demo Doc" )
   xml:docAuthor( "Robert F Greer" )
   xml:docCompany( "Greers.Org" )
   xml:docManager( "Wife" )

   format1 := xml:addStyle( "left_rotate60_big" )
   format1:alignRotate( 60 )
   format1:alignHorizontal( "Left" )
   format1:setFontSize( "18" )

   format2 := xml:addStyle( "verticaltext_left" )
   format2:alignVerticaltext( 45 )
   format2:alignHorizontal( "Left" )

   format3 := xml:addStyle( "wraptext_top" )
   format3:alignWraptext()
   format3:alignVertical( "Top" )

   sheet1 := xml:addSheet( "Alignment" )

   sheet1:writeString( 1, 1, "left_rotate45", format1 )
   sheet1:writeString( 1, 2, "vertical left", "verticaltext_left" )
   sheet1:writeString( 1, 3, "this text has been wrapped and is aligned at the top", "wraptext_top" )

   sheet2 := xml:addSheet( "Formulas" )

   sheet2:columnWidth( 1, 100 )
   sheet2:writeString( 1, 1, "Number" )
   sheet2:writeNumber( 1, 2, 50 )
   sheet2:writeString( 2, 1, "Number" )
   sheet2:writeNumber( 2, 2, 30 )
   sheet2:writeString( 3, 1, "Number" )
   sheet2:writeNumber( 3, 2, 20 )
   sheet2:writeString( 4, 1, "=SUM(R[-3]C:R[-1]C)" )
   sheet2:writeFormula( "Number", 4, 2, "=SUM(R[-3]C:R[-1]C)" )
   sheet2:writeString( 5, 1, "=SUM(R1C2:R3C2)" )
   sheet2:writeFormula( "Number", 5, 2, "=SUM(R1C1:R3C2)" )

   sheet4 := xml:addSheet( "more formatting" )
   format4 := xml:addStyle( "my style" )
   format4:setFontBold()
   format4:setFontItalic()
   format4:setFontUnderline( "DoubleAccounting" )
   format4:bgColor( "Black" )
   format4:setFontColor( "White" )
   format4:setNumberFormatDateTime()
   sheet4:writeDateTime( 1, 1, DToC( Date() ), format4 )

   sheet4:rowHeight( 1, "30" )
   sheet4:writeString( 2, 1, "formatted text + cell color + merged + underlined", format4 )

   sheet4:cellMerge( 2, 1, 4, 2 )

   xml:writeData( "example2.xml" )

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

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

#include "simpleio.ch"

REQUEST SQLMIX, SDDODBC

PROCEDURE Main()

   LOCAL nConnection, nI, aI

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

   rddSetDefault( "SQLMIX" )
   nConnection := rddInfo( RDDI_CONNECT, { "ODBC", "Server=localhost;Driver={MySQL ODBC 5.1 Driver};dsn=;User=test;database=test;" } )
   IF nConnection == 0
      ? "Unable connect to server", rddInfo( RDDI_ERRORNO ), rddInfo( RDDI_ERROR )
      RETURN
   ENDIF
   ? nConnection
   ? rddInfo( RDDI_EXECUTE, "DROP TABLE country" )
   ? rddInfo( RDDI_EXECUTE, "CREATE TABLE country (CODE char(3), NAME char(50), RESIDENTS int(11))" )
   ? rddInfo( RDDI_EXECUTE, "INSERT INTO country values ('LTU', 'Lithuania', 3369600),('USA', 'United States of America', 305397000), ('POR', 'Portugal', 10617600), ('POL', 'Poland', 38115967), ('AUS', 'Australia', 21446187), ('FRA', 'France', 64473140), ('RUS', 'Russia', 141900000)" )
   ? dbUseArea( .T., , "SELECT * FROM country", "country" )
   ? "LASTREC:", LastRec()
   DO WHILE ! Eof()
      aI := Array( FCount() )
      FOR nI := 1 TO FCount()
         aI[nI] := FieldGet( nI )
      NEXT
      ? RecNo(), hb_ValToExp( aI )
      dbSkip()
   ENDDO
   ? "LASTREC:", LastRec()
   dbCloseAll()

   RETURN


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

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

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

[Assistant]
proc main()
   local getList := {}
   local cVar := space( 20 )

   CLS

   if ! hb_mtvm()
      ? "No MT support in HVM. Clock will not be shown."
      WAIT
   else
      hb_threadStart( @thFunc() )
   endif

   @ 10, 10 SAY "Insert cVar:" GET cVar
   READ
   SetPos( 12, 0 )
   ? "Result -> [" + cVar + "]"
   WAIT

return

func thFunc()
   local cTime
   while .T.
      cTime := dtoc( date() ) + " " + time()

      hb_dispOutAt( 0, maxcol() - len( cTime ) + 1, cTime, "GR+/N" )
      hb_idleSleep( 1 )
   enddo
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]
Here is a Harbour (xBase/Clipper) implementation:

Harbour Runtime Library file: src/rtl/einstvar.prg. Provides functions: __eInstVar53. This file provides utility functions

[Assistant]
#include "error.ch"

FUNCTION __eInstVar53( oVar, cMethod, xValue, cType, nSubCode, bValid )

   LOCAL oError

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

   RETURN xValue


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

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

[Assistant]
PROCEDURE Main()

   ? "From Main()"

   Two( 1 )

   ? "back to Main()"

   Two( 2 )

   ? "back to Main()"

   RETURN

PROCEDURE Two( n )

   DO CASE
   CASE n == 1
      ? "n == 1"
      RETURN

   CASE n == 2
      ? "n == 2"
      RETURN
   ENDCASE

   ? "This message should not been seen"

   RETURN


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

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

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

[Assistant]
#define CASE_AT( x, y, z )               z[ At( x, y ) + 1 ]
#define FORCE_BETWEEN( x, y, z )         ( y := Max( Min( y, z ), x ) )

FUNCTION ft_ASum( aArray, nStartIndex, nEndIndex )

   LOCAL nSumTotal := 0

   __defaultNIL( @nStartIndex, 1 )
   __defaultNIL( @nEndIndex, Len( aArray ) )

   FORCE_BETWEEN( 1, nEndIndex,   Len( aArray ) )
   FORCE_BETWEEN( 1, nStartIndex, nEndIndex )

   AEval( aArray, ;
      {| xElement | ;
      nSumTotal += ;
      CASE_AT( ValType( xElement ), "NC", ;
      { 0, xElement, ;
      iif( HB_ISSTRING( xElement ), Len( xElement ), 0 ) } ) }, ;
      nStartIndex, nEndIndex - nStartIndex + 1 )

   RETURN nSumTotal


[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/month.prg. Provides functions: ft_Month. This file provides legacy compatibility functions

[Assistant]
FUNCTION ft_Month( dGivenDate, nMonthNum )

   LOCAL nTemp, aRetVal

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

   aRetVal := ft_Year( dGivenDate )

   IF HB_ISNUMERIC( nMonthNum )
      IF nMonthNum < 1 .OR. nMonthNum > 12
         nMonthNum := 12
      ENDIF
      dGivenDate := ft_MAdd( aRetVal[ 2 ], nMonthNum - 1 )
   ENDIF

   nTemp := Month( dGivenDate ) - Month( aRetVal[ 2 ] )
   nTemp += iif( nTemp >= 0, 1, 13 )

   aRetVal[ 1 ] += StrZero( nTemp, 2 )
   aRetVal[ 2 ] := ft_MAdd( aRetVal[ 2 ], nTemp - 1 )
   aRetVal[ 3 ] := ft_MAdd( aRetVal[ 2 ], 1 ) - 1

   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] Implement this Harbour module: Harbour contribution module 'gtwvg' (): contrib/gtwvg/wnd.prg. Defines classes: WvgWindow. This file provides platform-specific functionality

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

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

CREATE CLASS WvgWindow INHERIT WvgPartHandler

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

   VAR    pointerFocus                          INIT .T.

   VAR    dropZone                              INIT .F.
   VAR    helpLink
   VAR    s_tooltipText                         INIT ""
   METHOD tooltipText( cText )                  SETGET

   VAR    clr_FG
   VAR    clr_BG
   VAR    fnt_COMMPOUNDNAME
   VAR    fnt_hFont

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

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

   VAR    sl_close
   VAR    sl_setDisplayFocus
   VAR    sl_killDisplayFocus

   VAR    hBrushBG
   VAR    is_hidden                             INIT .F.
   VAR    is_enabled                            INIT .T.
   VAR    title                                 INIT " "
   VAR    icon                                  INIT 0
   VAR    closable                              INIT .T.
   VAR    resizable                             INIT .T.
   VAR    resizeMode                            INIT 0
   VAR    style                                 INIT WIN_WS_OVERLAPPEDWINDOW
   VAR    exStyle                               INIT 0
   VAR    lModal                                INIT .F.
   VAR    pGTp
   VAR    pGT
   VAR    objType                               INIT objTypeNone
   VAR    className                             INIT ""

   VAR    hWnd
   VAR    pWnd
   VAR    aPos                                  INIT { 0, 0 }
   VAR    aSize                                 INIT { 0, 0 }
   VAR    aPresParams                           INIT {}
   VAR    lHasInputFocus                        INIT .F.
   VAR    nFrameState                           INIT 0

   VAR    maxCol                                INIT 79
   VAR    maxRow                                INIT 24
   VAR    mouseMode                             INIT 1

   VAR    nID                                   INIT   0
   VAR    nControlID                            INIT   5000
   VAR    nOldProc                              INIT   0

   VAR    oMenu

   VAR    nTop
   VAR    nLeft
   VAR    nBottom
   VAR    nRight

   VAR    hWndTT

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

   METHOD captureMouse()
   METHOD currentPos()
   METHOD currentSize()
   METHOD disable()
   METHOD enable()
   METHOD getHWND()
   METHOD getModalState()
   METHOD hasInputFocus()
   METHOD hide()
   METHOD invalidateRect( aRect )
   METHOD lockPS()
   METHOD lockUpdate()
   METHOD isDerivedFrom( cClassORoObject )
   METHOD setColorBG( nRGB )
   METHOD setModalState()
   METHOD setPointer()
   METHOD setTrackPointer()
   METHOD setPos( aPos, lPaint )
   METHOD setPosAndSize( aPos, aSize, lPaint )
   METHOD setSize( aSize, lPaint )
   METHOD setFont()
   METHOD setFontCompoundName( xFont )
   METHOD setPresParam()
   METHOD show()
   METHOD toBack()
   METHOD toFront()
   METHOD unlockPS()
   METHOD winDevice()

   METHOD Initialize( oParent, oOwner, aPos, aSize, aPresParams, lVisible )
   METHOD setFocus()
   METHOD sendMessage( nMessage, nlParam, nwParam )
   METHOD findObjectByHandle( hWnd )

   METHOD getControlID()                        INLINE ++::nControlID
   METHOD HandleEvent()                         INLINE EVENT_UNHANDELLED
   METHOD isEnabled()                           INLINE ::is_enabled
   METHOD isVisible()                           INLINE ! ::is_hidden
   METHOD setColorFG( nRGB )                    INLINE ::clr_FG := iif( HB_ISSTRING( nRGB ), wvt_GetRGBColorByString( nRGB, 0 ), nRGB ), ::invalidateRect()

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

   PROTECTED:

   METHOD getPosAndSize( aPs, aSz )
   METHOD isParentCrt()                         INLINE ( iif( HB_ISOBJECT( ::oParent ), ::oParent:objType == objTypeCrt, .F. ) )
   METHOD rePosition()
   METHOD createControl()

ENDCLASS

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

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

   ::oParent     := oParent
   ::oOwner      := oOwner
   ::aPos        := aPos
   ::aSize       := aSize
   ::aPresParams := aPresParams
   ::visible     := lVisible

   ::WvgPartHandler:new( oParent, oOwner )

   RETURN Self

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

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

   ::oParent     := oParent
   ::oOwner      := oOwner
   ::aPos        := aPos
   ::aSize       := aSize
   ::aPresParams := aPresParams
   ::visible     := lVisible

   IF Empty( ::oParent )
      IF ! ::ClassName() $ "WVGCRT,WVGDIALOG"
         ::oParent := WvgSetAppWindow()
      ENDIF
   ENDIF

   ::WvgPartHandler:create( oParent, oOwner )


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

[User] Write a Harbour program with procedures: Main, draw_table, show_text_right. Harbour contribution module 'hbcairo' (Cairo graphics library wrapper): contrib/hbcairo/tests/table.prg. Contains 4 procedures. This file provides graphics and image processing capabilities

[Assistant]
#require "hbcairo"

PROCEDURE Main()

   LOCAL hSurface, hCairo
   FIELD CODE, NAME, RESIDENTS

   dbCreate( "country", { { "CODE", "C", 3, 0 }, { "NAME", "C", 30, 0 }, { "RESIDENTS", "N", 10, 0 } },, .T. )
   dbAppend(); CODE := "LTU";  NAME := "Lithuania";                 RESIDENTS :=   3369600
   dbAppend(); CODE := "USA";  NAME := "United States of America";  RESIDENTS := 305397000
   dbAppend(); CODE := "POR";  NAME := "Portugal";                  RESIDENTS :=  10617600
   dbAppend(); CODE := "POL";  NAME := "Poland";                    RESIDENTS :=  38115967
   dbAppend(); CODE := "AUS";  NAME := "Australia";                 RESIDENTS :=  21446187
   dbAppend(); CODE := "FRA";  NAME := "France";                    RESIDENTS :=  64473140
   dbAppend(); CODE := "RUS";  NAME := "Russia";                    RESIDENTS := 141900000

   hSurface := cairo_pdf_surface_create( "table.pdf", 566.9, 793.7 )
   hCairo := cairo_create( hSurface )

   cairo_select_font_face( hCairo, "sans-serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD )
   cairo_set_font_size( hCairo, 16 )
   cairo_set_source_rgb( hCairo, 0, 0, 0 )

   cairo_move_to( hCairo, 50, 50 )
   cairo_show_text( hCairo, "Table of countries" )

   draw_table( hCairo, 50, 75, { { "Code", "CODE" }, { "Country", "NAME" }, { "Residents", "RESIDENTS" } } )

   cairo_show_page( hCairo )
   cairo_destroy( hCairo )
   cairo_surface_destroy( hSurface )
   dbCloseAll()

   RETURN

STATIC PROCEDURE draw_table( hCairo, nX, nY, aCol )

   LOCAL nI, aWidth, nDX, nW, xValue

   cairo_save( hCairo )
   cairo_select_font_face( hCairo, "sans-serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL )
   cairo_set_font_size( hCairo, 10 )
   cairo_set_source_rgb( hCairo, 0, 0, 0 )
   cairo_set_line_width( hCairo, 1 )

   dbGoTop()
   aWidth := Array( Len( aCol ) )
   FOR nI := 1 TO Len( aCol )
      aWidth[ nI ] := cairo_text_extents( hCairo, Replicate( "9", FieldLen( FieldPos( aCol[ nI, 2 ] ) ) ) )[ 5 ]
      aWidth[ nI ] := Max( aWidth[ nI ], cairo_text_extents( hCairo, aCol[ nI, 1 ] )[ 5 ] ) + 20
   NEXT
   nW := 0
   AEval( aWidth, {| X | nW += X } )

   cairo_move_to( hCairo, nX, nY )
   cairo_rel_line_to( hCairo, nW, 0 )
   cairo_stroke( hCairo )

   nDX := nX
   FOR nI := 1 TO Len( aCol )
      cairo_move_to( hCairo, nDX + aWidth[ nI ] / 2, nY + 10 )
      show_text_center( hCairo, aCol[ nI, 1 ] )
      nDX += aWidth[ nI ]
      IF nI < Len( aCol )
         cairo_move_to( hCairo, nDX, nY )
         cairo_rel_line_to( hCairo, 0, 13 )
         cairo_stroke( hCairo )
      ENDIF
   NEXT
   nY += 13
   cairo_move_to( hCairo, nX, nY )
   cairo_rel_line_to( hCairo, nW, 0 )
   cairo_stroke( hCairo )

   DO WHILE ! Eof()
      nDX := nX
      FOR nI := 1 TO Len( aCol )
         xValue := FieldGet( FieldPos( aCol[ nI, 2 ] ) )
         SWITCH ValType( xValue )
         CASE "C"
            cairo_move_to( hCairo, nDX + 10, nY + 10 )
            cairo_show_text( hCairo, xValue )
            EXIT
         CASE "N"
            cairo_move_to( hCairo, nDX + aWidth[ nI ] - 10, nY + 10 )
            show_text_right( hCairo, Str( xValue ) )
            EXIT
         CASE "D"
            cairo_move_to( hCairo, nDX + 10, nY + 10 )
            show_text_right( hCairo, DToC( xValue ) )
            EXIT
         ENDSWITCH
         nDX += aWidth[ nI ]
         IF nI < Len( aCol )
            cairo_move_to( hCairo, nDX, nY )
            cairo_rel_line_to( hCairo, 0, 13 )
            cairo_stroke( hCairo )
         ENDIF
      NEXT
      dbSkip()
      nY += 13
   ENDDO
   cairo_move_to( hCairo, nX, nY )
   cairo_rel_line_to( hCairo, nW, 0 )
   cairo_stroke( hCairo )

   cairo_restore( hCairo )

   RETURN

STATIC PROCEDURE show_text_right( hCairo, cText )

   cairo_rel_move_to( hCairo, - cairo_text_extents( hCairo, cText )[ 5 ], 0 )
   cairo_show_text( hCairo, cText )

   RETURN

STATIC PROCEDURE show_text_center( hCairo, cText )

   cairo_rel_move_to( hCairo, -0.5


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

[User] Create Harbour preprocessor definitions: Header file for contribution module 'hbcurl' (libcurl wrapper for HTTP/FTP/SMTP operations): contrib/hbcurl/hbcurl.ch. Defines 10 constants including: HBCURL_CH_, HB_CURLOPT_FILE, HB_CURLOPT_URL, HB_CURLOPT_PORT, HB_CURLOPT_PROXY. Defines keyboard input constants

[Assistant]
#ifndef HBCURL_CH_
#define HBCURL_CH_

#define HB_CURLOPT_FILE                       1
#define HB_CURLOPT_URL                        2
#define HB_CURLOPT_PORT                       3
#define HB_CURLOPT_PROXY                      4
#define HB_CURLOPT_USERPWD                    5
#define HB_CURLOPT_PROXYUSERPWD               6
#define HB_CURLOPT_RANGE                      7
#define HB_CURLOPT_INFILE                     9
#define HB_CURLOPT_ERRORBUFFER                10
#define HB_CURLOPT_WRITEFUNCTION              11
#define HB_CURLOPT_READFUNCTION               12
#define HB_CURLOPT_TIMEOUT                    13
#define HB_CURLOPT_INFILESIZE                 14
#define HB_CURLOPT_POSTFIELDS                 15
#define HB_CURLOPT_REFERER                    16
#define HB_CURLOPT_FTPPORT                    17
#define HB_CURLOPT_USERAGENT                  18
#define HB_CURLOPT_LOW_SPEED_LIMIT            19
#define HB_CURLOPT_LOW_SPEED_TIME             20
#define HB_CURLOPT_RESUME_FROM                21
#define HB_CURLOPT_COOKIE                     22
#define HB_CURLOPT_HTTPHEADER                 23
#define HB_CURLOPT_HTTPPOST                   24
#define HB_CURLOPT_SSLCERT                    25
#define HB_CURLOPT_KEYPASSWD                  26
#define HB_CURLOPT_SSLCERTPASSWD              HB_CURLOPT_KEYPASSWD
#define HB_CURLOPT_SSLKEYPASSWD               HB_CURLOPT_KEYPASSWD
#define HB_CURLOPT_CRLF                       27
#define HB_CURLOPT_QUOTE                      28
#define HB_CURLOPT_WRITEHEADER                29
#define HB_CURLOPT_COOKIEFILE                 31
#define HB_CURLOPT_SSLVERSION                 32
#define HB_CURLOPT_TIMECONDITION              33
#define HB_CURLOPT_TIMEVALUE                  34
#define HB_CURLOPT_CUSTOMREQUEST              36
#define HB_CURLOPT_STDERR                     37
#define HB_CURLOPT_POSTQUOTE                  39
#define HB_CURLOPT_WRITEINFO                  40
#define HB_CURLOPT_VERBOSE                    41
#define HB_CURLOPT_HEADER                     42
#define HB_CURLOPT_NOPROGRESS                 43
#define HB_CURLOPT_NOBODY                     44
#define HB_CURLOPT_FAILONERROR                45
#define HB_CURLOPT_UPLOAD                     46
#define HB_CURLOPT_POST                       47
#define HB_CURLOPT_DIRLISTONLY                48
#define HB_CURLOPT_FTPLISTONLY                HB_CURLOPT_DIRLISTONLY
#define HB_CURLOPT_APPEND                     50
#define HB_CURLOPT_FTPAPPEND                  HB_CURLOPT_APPEND
#define HB_CURLOPT_NETRC                      51
#define HB_CURLOPT_FOLLOWLOCATION             52
#define HB_CURLOPT_TRANSFERTEXT               53
#define HB_CURLOPT_PUT                        54
#define HB_CURLOPT_PROGRESSFUNCTION           56
#define HB_CURLOPT_PROGRESSDATA               HB_CURLOPT_XFERINFODATA
#define HB_CURLOPT_XFERINFODATA               57
#define HB_CURLOPT_AUTOREFERER                58
#define HB_CURLOPT_PROXYPORT                  59
#define HB_CURLOPT_POSTFIELDSIZE              60
#define HB_CURLOPT_HTTPPROXYTUNNEL            61
#define HB_CURLOPT_INTERFACE                  62
#define HB_CURLOPT_KRBLEVEL                   63
#define HB_CURLOPT_KRB4LEVEL                  HB_CURLOPT_KRBLEVEL
#define HB_CURLOPT_SSL_VERIFYPEER             64
#define HB_CURLOPT_CAINFO                     65
#define HB_CURLOPT_MAXREDIRS                  68
#define HB_CURLOPT_FILETIME                   69
#define HB_CURLOPT_TELNETOPTIONS              70
#define HB_CURLOPT_MAXCONNECTS                71
#define HB_CURLOPT_CLOSEPOLICY                72
#define HB_CURLOPT_FRESH_CONNECT              74
#define HB_CURLOPT_FORBID_REUSE               75
#define HB_CURLOPT_RANDOM_FILE                76
#define HB_CURLOPT_EGDSOCKET                  77
#define HB_CURLOPT_CONNECTTIMEOUT             78
#define HB_CURLOPT_HEADERFUNCTION             79
#define HB_CURLOPT_HTTPGET                    80
#define HB_CURLOPT_SSL_VERIFYHOST             81
#define HB_CURLOPT_COOKIEJAR                  82
#define HB_CURLOPT_SSL_CIPHER_LIST            83
#define HB_CURLOPT_HTTP_VERSION               84
#define HB_CURLOPT_FTP_USE_EPSV               85
#define HB_CURLOPT_SSLCERTTYPE                86
#define HB_CURLOPT_SSLKEY                     87
#define HB_CURLOPT_SSLKEYTYPE                 88
#define HB_CURLOPT_SSLENGINE                  89
#define HB_CURLOPT_SSLENGINE_DEFAULT          90
#define HB_CURLOPT_DNS_USE_GLOBAL_CACHE       91
#define HB_CURLOPT_DNS_CACHE_TIMEOUT          92
#define HB_CURLOPT_PREQUOTE                   93
#define HB_CURLOPT_DEBUGFUNCTION              94
#define HB_CURLOPT_DEBUGDATA                  95
#define HB_CURLOPT_COOKIESESSION              96
#define HB_CURLOPT_CAPATH                     97
#define HB_CURLOPT_BUFFERSIZE                 98
#define HB_CURLOPT_NOSIGNAL                   99
#define HB_CURLOPT_SHARE                      100
#define HB_CURLOPT_PROXYTYPE                  101
#define HB_CURLOPT_ACCEPT_ENCODING            102
#define HB_CURLOPT_ENCODING                   HB_CURLOPT_ACCEPT_ENCODING
#define HB_CURLOPT_PRIVATE                    103
#define HB_CURLOPT_HTTP200ALIASES             104
#define HB_CURLOPT_UNRESTRICTED_AUTH          105
#define HB_CURLOPT_FTP_USE_EPRT               106
#define HB_CURLOPT_HTTPAUTH                   107
#define HB_CURLOPT_SSL_CTX_FUNCTION           108
#define HB_CURLOPT_SSL_CTX_DATA               109
#define HB_CURLOPT_FTP_CREATE_MISSING_DIRS    110
#define HB_CURLOPT_PROXYAUTH                  111
#define HB_CURLOPT_FTP_RESPONSE_TIMEOUT       112
#define HB_CURLOPT_IPRESOLVE                  113
#define HB_CURLOPT_MAXFILESIZE                114
#define HB_CURLOPT_INFILESIZE_LARGE           115
#define HB_CURLOPT_RESUME_FROM_LARGE          116
#define HB_CURLOPT_MAXFILESIZE_LARGE          117
#define HB_CURLOPT_NETRC_FILE                 118
#define HB_CURLOPT_USE_SSL                    119
#define HB_CURLOPT_FTP_SSL                    HB_CURLOPT_USE_SSL
#define HB_CURLOPT_POSTFIELDSIZE_LARGE        120
#define HB_CURLOPT_TCP_NODELAY                121
#define HB_CURLOPT_SOURCE_USERPWD             123
#define HB_CURLOPT_SOURCE_PREQUOTE            127
#define HB_CURLOPT_SOURCE_POSTQUOTE           128
#define HB_CURLOPT_FTPSSLAUTH                 129
#define HB_CURLOPT_IOCTLFUNCTION              130
#define HB_CURLOPT_IOCTLDATA                  131
#define HB_CURLOPT_SOURCE_URL                 132
#define HB_CURLOPT_SOURCE_QUOTE               133
#define HB_CURLOPT_FTP_ACCOUNT                134
#define HB_CURLOPT_COOKIELIST                 135
#define HB_CURLOPT_IGNORE_CONTENT_LENGTH      136
#define HB_CURLOPT_FTP_SKIP_PASV_IP           137
#define HB_CURLOPT_FTP_FILEMETHOD             138
#define HB_CURLOPT_LOCALPORT                  139
#define HB_CURLOPT_LOCALPORTRANGE             140
#define HB_CURLOPT_CONNECT_ONLY               141
#define HB_CURLOPT_CONV_FROM_NETWORK_FUNCTION 142
#define HB_CURLOPT_CONV_TO_NETWORK_FUNCTION   143
#define HB_CURLOPT_CONV_FROM_UTF8_FUNCTION    144
#define HB_CURLOPT_MAX_SEND_SPEED_LARGE       145
#define HB_CURLOPT_MAX_RECV_SPEED_LARGE       146
#define HB_CURLOPT_FTP_ALTERNATIVE_TO_USER    147
#define HB_CURLOPT_SOCKOPTFUNCTION            148
#define HB_CURLOPT_SOCKOPTDATA                149
#define HB_CURLOPT_SSL_SESSIONID_CACHE        150
#define HB_CURLOPT_SSH_AUTH_TYPES             151
#define HB_CURLOPT_SSH_PUBLIC_KEYFILE         152
#define HB_CURLOPT_SSH_PRIVATE_KEYFILE        153
#define HB_CURLOPT_FTP_SSL_CCC                154
#define HB_CURLOPT_TIMEOUT_MS                 155
#define HB_CURLOPT_CONNECTTIMEOUT_MS          156
#define HB_CURLOPT_HTTP_TRANSFER_DECODING     157
#define HB_CURLOPT_HTTP_CONTENT_DECODING      158
#define HB_CURLOPT_NEW_FILE_PERMS             159
#define HB_CURLOPT_NEW_DIRECTORY_PERMS        160
#define HB_CURLOPT_POST301                    161
#define HB_CURLOPT_SSH_HOST_PUBLIC_KEY_MD5    162


[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 'hbmxml' (XML generation library): contrib/hbmxml/tests/reminder.prg. Provides functions: simplexml_load_file, asXML, type_cb. Contains procedures: Main, my_mxmlError. This file handles data format parsing and generation

[Assistant]
#require "hbmxml"

STATIC s_mxml_error := .F.
STATIC s_mxml_error_msg := ""

PROCEDURE Main()

   LOCAL xml

   mxmlSetErrorCallback( @my_mxmlError() )

   IF hb_FileExists( "rem.xml" )
      xml := simplexml_load_file( "rem.xml" )
   ELSE
      RETURN
   ENDIF

   IF ! s_mxml_error
      OutStd( asXML( xml ), hb_eol() )
   ENDIF

   mxmlDelete( xml )

   IF hb_FileExists( "rem_err.xml" )
      xml := simplexml_load_file( "rem_err.xml" )

      IF s_mxml_error
         OutErr( "hbmxml:", s_mxml_error_msg, hb_eol() )
      ELSE
         OutStd( asXML( xml ), hb_eol() )
      ENDIF
   ENDIF

   RETURN

PROCEDURE my_mxmlError( cErrorMsg )

   s_mxml_error_msg := cErrorMsg
   s_mxml_error := .T.

   RETURN

STATIC FUNCTION simplexml_load_file( file )

   RETURN mxmlLoadString( NIL, hb_MemoRead( file ), @type_cb() )

STATIC FUNCTION asXML( xml )

   LOCAL cText := "", c
   LOCAL wt := 3
   LOCAL node, subnode

   node := mxmlFindElement( xml, xml, "note", NIL, NIL, MXML_DESCEND )
   IF Empty( node )
      RETURN ""
   ENDIF

   subnode := mxmlGetFirstChild( node )
   DO WHILE ! Empty( subnode := mxmlGetNextSibling( subnode ) )
      IF mxmlGetType( subnode ) == MXML_ELEMENT
         IF mxmlGetElement( subnode ) == "body"
            c := mxmlGetOpaque( subnode )
         ELSE
            c := mxmlGetText( subnode, @wt )
         ENDIF
         cText += ( c + " " )
      ENDIF
   ENDDO

   RETURN cText

FUNCTION type_cb( node )

   LOCAL nResult
   LOCAL cType

   IF Empty( cType := mxmlElementGetAttr( node, "type" ) )
      cType := mxmlGetElement( node )
   ENDIF

   SWITCH Lower( cType )
   CASE "note"
   CASE "to"
   CASE "from"
   CASE "heading"
      nResult := MXML_TEXT
      EXIT

   CASE "body"
   CASE "opaque"
      nResult := MXML_OPAQUE
      EXIT

   OTHERWISE
      nResult := MXML_IGNORE
      EXIT
   ENDSWITCH

   RETURN nResult


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

[User] Generate Harbour code for: Harbour contribution module 'hbgd' (Graphics drawing library (GD)): contrib/hbgd/tests/cgi.prg. Provides functions: GetVars, GetParams, URLDecode, URLEncode. Contains 5 procedures. This file provides graphics and image processing capabilities

[Assistant]
#require "hbgd"

#command WRITE <c> => FWrite( 1, <c> + hb_eol() )
#command OutHTML <c> => WRITE <c>

PROCEDURE Main( ... )

   LOCAL cPar
   LOCAL aParams := hb_AParams()
   LOCAL cQuery  := GetEnv( "QUERY_STRING" )
   LOCAL hParams := { => }

   LOCAL cImg, nPt, nWidth, nHeight, cPhoto

   IF Empty( aParams )
      IF ! Empty( cQuery )
         hParams := GetVars( cQuery )
      ENDIF
   ELSE
      hParams := GetParams( aParams )
   ENDIF

   IF ! Empty( hParams )
      FOR EACH cPar IN hParams:Keys

         DO CASE
         CASE cPar == "txt"

         CASE cPar == "img"
            cImg := hParams[ cPar ]

         CASE cPar == "photo"
            cPhoto := hParams[ cPar ]

         CASE cPar == "width"
            nWidth := Val( hParams[ cPar ] )

         CASE cPar == "height"
            nHeight := Val( hParams[ cPar ] )

         CASE cPar == "pt"
            nPt := Val( hParams[ cPar ] )

         ENDCASE
      NEXT
   ENDIF

   hb_default( @nPt, 30 )

   IF cImg != NIL
      OutPhoto( cImg, nWidth, nHeight )

   ELSEIF cPhoto != NIL
      StartHTML()
      OutHTML "
"
      OutHTML "
"
      OutHTML "" + "
"
      OutHTML "
"
      OutHTML "
"
      OutHTML "" + "
"
      OutHTML "
"
      OutHTML "
"
      OutHTML cPhoto
      OutHTML "
"
      OutHTML "
"
      OutHTML "
"
      EndHTML()
   ELSE
      StartHTML()
      EndHTML()
   ENDIF

   RETURN

PROCEDURE StartHTML( cTitle )

   hb_default( @cTitle, "" )

   WRITE "content-type: text/html"
   WRITE "Pragma: no-cache"
   WRITE hb_eol()
   WRITE ""
   WRITE ""
   WRITE "<title>" + cTitle + "</title>"
   WRITE ""
   WRITE ""

   RETURN

PROCEDURE EndHTML()

   WRITE ""
   WRITE ""

   RETURN

PROCEDURE OutPhoto( cPhoto, nWidth, nHeight )

   LOCAL cType

   LOCAL oImage := GDImage():LoadFromFile( cPhoto )

   IF nWidth != NIL .AND. nHeight != NIL
      oImage:Resize( nWidth, nHeight )
   ELSEIF nWidth != NIL .AND. nHeight == NIL
      nHeight := oImage:Height()
   WRITE "content-type: " + oImage:cMime + hb_eol()
   cType := oImage:cType

   DO CASE
   CASE cType == "jpeg"
      oImage:OutputJpeg()
   CASE cType == "gif"
      oImage:OutputGif()
   CASE cType == "png"
      oImage:OutputPng()
   ENDCASE

   RETURN

PROCEDURE OutJpg( cText, nPitch )

   LOCAL oI

   LOCAL blue
   LOCAL aSize, nWidth, nHeight, nX, nY

   hb_default( @cText, "Sample TEXT" )
   hb_default( @nPitch, 30 )

   oI := GDImage( 400, 100 )

   oI:SetFontName( "Verdana" )
   oI:SetFontPitch( nPitch )
#endif
   __OutDebug( oI:GetFTFontHeight() )
#endif
   aSize := oI:GetFTStringSize( cText )
   nWidth  := aSize[ 1 ]
   nHeight := aSize[ 2 ]
   nX      := aSize[ 3 ]
   nY      := aSize[ 4 ]
   oI:Resize( nWidth, nHeight )

   blue := oI:SetColor( 0, 0, 200 )
   oI:SetFontName( "Verdana" )
   oI:SetFontPitch( nPitch )
   oI:SayFreeType( 0 - nX, 0 + nHeight - nY, cText, , , 0, blue )
#endif
   oI:SayFreeType( 0, 0, cText, , , 0, blue )

   oI:Resize( nWidth, nHeight )
   __OutDebug( "prima", oI:Width(), oI:Height() )
   oI:Resize( 60, 40 )
   __OutDebug( "dopo", oI:Width(), oI:Height() )

   oI:SetFontLarge()
   oI:SetColor( blue )
   oI:Say( 0, 0, cText )
#endif

   WRITE "content-type: image/jpeg" + hb_eol()

   oI:OutputJpeg()

   RETURN

FUNCTION GetVars( cFields, cSeparator )

   LOCAL hHashVars := { => }
   LOCAL aField, cField, aFields
   LOCAL cName, xValue

   hb_default( @cSeparator, "&" )

   aFields := hb_regexSplit( cSeparator, cFields )

   FOR EACH cField in aFields
      aField := hb_regexSplit( "=", cField, 2 )
      IF Len( aField ) != 2
         LOOP
      ENDIF

      cName  := LTrim( aField[ 1 ] )
      xValue := UrlDecode( aField[ 2 ] )

      IF SubStr( cName, Len( cName ) - 1 ) == "[]"
         cName := SubStr( cName, 1, Len( cName ) - 2 )

         hHashVars[ cName ] := { xValue }

      ELSE

         hHashVars[ cName ] := xValue

      ENDIF

   NEXT

   RETURN hHashVars

FUNCTION GetParams( aParams )

   LOCAL hHashVars := { => }
   LOCAL aField, cField, aFields
   LOCAL cName, xValue

   aFields := aParams

   FOR EACH cField in aFields
      aField := hb_regexSplit( "=", cField, 2 )
      IF Len( aField ) != 2
         LOOP
      ENDIF

      cName  := LTrim( aField[ 1 ] )
      xValue := UrlDecode( aField[ 2 ] )

      IF SubStr( cName, Len( cName ) - 1 ) == "[]"
         cName := SubStr( cName, 1, Len( cName ) - 2 )

         hHashVars[ cName ] := { xValue }

      ELSE

         hHashVars[ cName ] := xValue

      ENDIF

   NEXT

   RETURN hHashVars

FUNCTION URLDecode( cStr )

   LOCAL cRet := "", i, cCar

   FOR i := 1 TO Len( cStr )
      cCar := cStr[ i ]

      DO CASE
      CASE cCar == "+"
         cRet += " "

      CASE cCar == "%"
         i++
         cRet += Chr( hb_HexToNum( SubStr( cStr, i, 2 ) ) )
         i++

      OTHERWISE
         cRet += cCar

      ENDCASE

   NEXT

   RETURN cRet

FUNCTION URLEncode( cStr )

   LOCAL cRet := "", i, nVal, cCar

   FOR i := 1 TO Len( cStr )
      cCar := cStr[ i ]
      DO CASE
      CASE cCar == " "
         cRet += "+"

      CASE cCar >= "A" .AND. cCar <= "Z"
         cRet += cCar

      CASE cCar >= "a" .AND. cCar <= "z"
         cRet += cCar

      CASE cCar >= "0" .AND. cCar <= "9"
         cRet += cCar

      OTHERWISE
         nVal := Asc( cCar )
         cRet += "%" + hb_NumToHex( nVal )
      ENDCASE
   NEXT

   RETURN cRet


[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: HBDbWindow. Harbour Runtime Library file: src/debug/dbgtwin.prg. Defines classes: HBDbWindow. This file provides utility functions

[Assistant]
#pragma -b-

#define HB_CLS_NOTOBJECT
#include "hbclass.ch"

#include "hbmemvar.ch"

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

CREATE CLASS HBDbWindow

   VAR nTop
   VAR nLeft
   VAR nBottom
   VAR nRight
   VAR cCaption
   VAR cBackImage
   VAR cColor
   VAR lFocused     INIT .F.
   VAR bGotFocus
   VAR bLostFocus
   VAR bKeyPressed
   VAR bPainted
   VAR bLButtonDown
   VAR bLDblClick
   VAR lShadow      INIT .F.
   VAR lVisible     INIT .F.
   VAR Cargo
   VAR Browser

   METHOD New( nTop, nLeft, nBottom, nRight, cCaption, cColor )

   METHOD Hide()
   METHOD IsOver( nRow, nCol )
   METHOD nWidth() INLINE ::nRight - ::nLeft + 1
   METHOD Clear()
   METHOD ScrollUp( nLines )
   METHOD SetCaption( cCaption )
   METHOD ShowCaption()
   METHOD SetFocus( lOnOff )
   METHOD Show( lFocused )
   METHOD ShowModal()
   METHOD LButtonDown( nMRow, nMCol )
   METHOD LDblClick( nMRow, nMCol )
   METHOD LoadColors()

   METHOD Move()
   METHOD KeyPressed( nKey )
   METHOD Refresh()
   METHOD Resize( nTop, nLeft, nBottom, nRight )

ENDCLASS

METHOD New( nTop, nLeft, nBottom, nRight, cCaption, cColor ) CLASS HBDbWindow

   ::nTop     := nTop
   ::nLeft    := nLeft
   ::nBottom  := nBottom
   ::nRight   := nRight
   ::cCaption := cCaption
   ::cColor   := hb_defaultValue( cColor, __dbgColors()[ 1 ] )

   RETURN Self

METHOD PROCEDURE Clear() CLASS HBDbWindow

   hb_Scroll( ::nTop + 1, ::nLeft + 1, ::nBottom - 1, ::nRight - 1,,, ::cColor )

   RETURN

METHOD PROCEDURE Hide() CLASS HBDbWindow

   __dbgRestScreen( ::nTop, ::nLeft, ::nBottom + iif( ::lShadow, 1, 0 ), ;
                    ::nRight + iif( ::lShadow, 2, 0 ), ::cBackImage )
   ::cBackImage := NIL
   ::lVisible := .F.

   RETURN

METHOD IsOver( nRow, nCol ) CLASS HBDbWindow

   RETURN ;
      nRow >= ::nTop .AND. nRow <= ::nBottom .AND. ;
      nCol >= ::nLeft .AND. nCol <= ::nRight

METHOD PROCEDURE ScrollUp( nLines ) CLASS HBDbWindow

   hb_Scroll( ::nTop + 1, ::nLeft + 1, ::nBottom - 1, ::nRight - 1, hb_defaultValue( nLines, 1 ),, ::cColor )

   RETURN

METHOD PROCEDURE SetCaption( cCaption ) CLASS HBDbWindow

   ::cCaption := cCaption

   RETURN

METHOD PROCEDURE ShowCaption() CLASS HBDbWindow

   IF ! Empty( ::cCaption )
      hb_DispOutAt( ::nTop, ::nLeft + ( ( ::nRight - ::nLeft ) / 2 ) - ;
         ( ( Len( ::cCaption ) + 2 ) / 2 ), ;
         " " + ::cCaption + " ", ::cColor )
   ENDIF

   RETURN

METHOD PROCEDURE SetFocus( lOnOff ) CLASS HBDbWindow

   IF ! lOnOff .AND. HB_ISEVALITEM( ::bLostFocus )
      Eval( ::bLostFocus, Self )
   ENDIF

   ::lFocused := lOnOff

   IF lOnOff .AND. HB_ISEVALITEM( ::bGotFocus )
      Eval( ::bGotFocus, Self )
   ENDIF

   RETURN

METHOD PROCEDURE Refresh() CLASS HBDbWindow

   DispBegin()

   hb_DispBox( ::nTop, ::nLeft, ::nBottom, ::nRight, iif( ::lFocused, HB_B_DOUBLE_UNI, HB_B_SINGLE_UNI ), ::cColor )
   hb_DispOutAtBox( ::nTop, ::nLeft + 1, hb_UTF8ToStrBox( "[■]" ), ::cColor )

   ::ShowCaption( ::cCaption )

   IF HB_ISEVALITEM( ::bPainted )
      Eval( ::bPainted, Self )
   ENDIF

   DispEnd()

   RETURN

METHOD PROCEDURE Show( lFocused ) CLASS HBDbWindow

   ::cBackImage := __dbgSaveScreen( ::nTop, ::nLeft, ;
                                    ::nBottom + iif( ::lShadow, 1, 0 ), ;
                                    ::nRight + iif( ::lShadow, 2, 0 ) )
   hb_Scroll( ::nTop, ::nLeft, ::nBottom, ::nRight,,, ::cColor )
   ::SetFocus( hb_defaultValue( lFocused, ::lFocused ) )

   IF ::lShadow
      hb_Shadow( ::nTop, ::nLeft, ::nBottom, ::nRight )
   ENDIF

   ::Refresh()
   ::lVisible := .T.

   RETURN

METHOD PROCEDURE ShowModal() CLASS HBDbWindow

   LOCAL lExit := .F.
   LOCAL nKey

   ::lShadow := .T.
   ::Show()

   DO WHILE ! lExit
      nKey := __dbgInkey()

      IF HB_ISEVALITEM( ::bKeyPressed )
         Eval( ::bKeyPressed, nKey )
      ENDIF

      SWITCH nKey
      CASE K_ESC
         lExit := .T.
         EXIT

      CASE K_LBUTTONDOWN
         IF MRow() == ::nTop .AND. MCol() >= ::nLeft + 1 .AND. ;
            MCol() <= ::nLeft + 3
            lExit := .T.
         ENDIF
         EXIT

      ENDSWITCH
   ENDDO

   ::Hide()

   RETURN

METHOD PROCEDURE LButtonDown( nMRow, nMCol ) CLASS HBDbWindow

   IF HB_ISEVALITEM( ::bLButtonDown )
      Eval( ::bLButtonDown, nMRow, nMCol )
   ENDIF

   RETURN

METHOD PROCEDURE LDblClick( nMRow, nMCol ) CLASS HBDbWindow

   IF HB_ISEVALITEM( ::bLDblClick )
      Eval( ::bLDblClick, nMRow, nMCol )
   ENDIF

   RETURN

METHOD PROCEDURE Move() CLASS HBDbWindow

   LOCAL nOldTop    := ::nTop
   LOCAL nOldLeft   := ::nLeft
   LOCAL nOldBottom := ::nbottom
   LOCAL nOldRight  := ::nright
   LOCAL nKey

   DO WHILE .T.
      __dbgRestScreen( ,,,, ::cBackImage )
      hb_DispBox( ::nTop, ::nLeft, ::nRight, ::nBottom, Replicate( hb_UTF8ToStrBox( "░" ), 8 ) + " ", ::cColor )

      SWITCH nKey := __dbgInkey()
      CASE K_UP

         IF ::nTop != 0
            ::nTop--
            ::nBottom--
         ENDIF
         EXIT

      CASE K_DOWN

         IF ::nBottom != MaxRow()
            ::nTop++
            ::nBottom++
         ENDIF
         EXIT

      CASE K_LEFT

         IF ::nLeft != 0
            ::nLeft--
            ::nRight--
         ENDIF
         EXIT

      CASE K_RIGHT

         IF ::nBottom != MaxRow()
            ::nLeft++
            ::nRight++
         ENDIF
         EXIT

      CASE K_ESC

         ::nTop    := nOldTop
         ::nLeft   := nOldLeft
         ::nBottom := nOldBottom
         ::nRight  := nOldRight
         EXIT

      ENDSWITCH

      IF nKey == K_ESC .OR. nKey == K_ENTER
         EXIT
      ENDIF
   ENDDO

   RETURN

METHOD PROCEDURE KeyPressed( nKey ) CLASS HBDbWindow

   IF HB_ISEVALITEM( ::bKeyPressed )
      Eval( ::bKeyPressed, nKey, Self )
   ENDIF

   RETURN

METHOD PROCEDURE LoadColors() CLASS HBDbWindow

   LOCAL aClr := __dbgColors()

   ::cColor := aClr[ 1 ]

   IF ::Browser != NIL
      ::Browser:ColorSpec := aClr[ 2 ] + "," + aClr[ 5 ] + "," + aClr[ 3 ] + "," + aClr[ 6 ]
   ENDIF

   RETURN

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

   LOCAL lShow

   IF ( ! HB_ISNUMERIC( nTop ) .OR. nTop == ::nTop ) .AND. ;
      ( ! HB_ISNUMERIC( nLeft ) .OR. nLeft == ::nLeft ) .AND. ;
      ( ! HB_ISNUMERIC( nBottom ) .OR. nBottom == ::nBottom ) .AND. ;
      ( ! HB_ISNUMERIC( nRight ) .OR. nRight == ::nRight )
      RETURN Self
   ENDIF

   IF ( lShow := ::lVisible )
      ::Hide()
   ENDIF

   IF HB_ISNUMERIC( nTop )
      ::nTop := nTop
   ENDIF
   IF HB_ISNUMERIC( nBottom )
      ::nBottom := nBottom
   ENDIF
   IF HB_ISNUMERIC( nLeft )
      ::nLeft := nLeft
   ENDIF
   IF HB_ISNUMERIC( nRight )
      ::nRight := nRight
   ENDIF

   IF ::Browser != NIL
      ::Browser:Resize( ::nTop + 1, ::nLeft + 1, ::nBottom - 1, ::nRight - 1 )
   ENDIF

   IF lShow
      ::Show( ::lFocused )
   ENDIF

   RETURN Self


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

[User] Implement this Harbour module: Harbour contribution module 'gtwvg' (): contrib/gtwvg/tests/demoxbp.prg. Provides functions: ResizeDialogXbp. Contains procedures: Main. This file provides platform-specific functionality

[Assistant]
#require "gtwvg"

#include "inkey.ch"
#include "hbgtinfo.ch"

PROCEDURE Main()

   LOCAL oCrt, oTBar, oSBar, oStatic, oCom, oXbp, oTree, oItem1, oItem2
   LOCAL oListBox, oCheck, oRadio, oStatic2, oMLE, oAddr
   LOCAL oPanel, oPanel1, oPanel2, cText, cNavigate, oDA
   LOCAL cVarA  := "Test A", cVarB := "Test B"
   LOCAL aState := { "not selected", "selected", "undefined" }
   LOCAL aParts := {}

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

   oCrt := WvgDialog():new( , , { 30, 30 }, { 900, 600 }, , .T. )
   oCrt:closable := .T.
   oCrt:icon := "vr_1.ico"
   oCrt:create()

   oCrt:setFontCompoundName( "12.Courier italic" )

   oDA := oCrt:drawingArea

   ActiveXBuildMenuXbp( oCrt, @oStatic, @oStatic2 )

   oTBar := ActiveXBuildToolBarXbp( oDA )

   oSBar   := WvgStatusBar():new( oCrt ):create( , , , , , .T. )
   oSBar:panelClick := {| oPanel | wvg_MessageBox( , oPanel:caption ) }
   oPanel  := oSBar:getItem( 1 )
   oPanel:caption := "My Root Panel"
   oPanel1 := oSBar:addItem()
   oPanel1:caption := "Ready"
   oPanel2 := oSBar:addItem()
   oPanel2:caption := "Click on any part!"

   oStatic := WvgStatic():new( oDA )
   oStatic:type    := WVGSTATIC_TYPE_TEXT
   oStatic:options := WVGSTATIC_TEXT_CENTER
   oStatic:caption := Chr( 13 ) + "Implemented   Xbase++ Parts"

   oStatic:create( , , { 0, oTBar:currentSize()[ 2 ] + 3 }, { 120, oCrt:currentSize()[ 2 ] - ;
      oTBar:currentSize()[ 2 ] - oSBar:currentSize()[ 2 ] - 4 }, , .T. )
   oStatic:setColorBG( RGB( 200, 200, 200 ) )

   oListBox := WvgListBox():new()
   oListBox:create( oStatic, , { 5, 55 }, { 107, 380 } )

   oListBox:setColorFG( RGB( 218, 61, 34 ) )

   AAdd( aParts, "XbpDialog"        )
   AAdd( aParts, "XbpMenuBar"       )
   AAdd( aParts, "XbpToolBar"       )
   AAdd( aParts, "XbpToolBarButton" )
   AAdd( aParts, "XbpStatusBar"     )
   AAdd( aParts, "XbpStatic"        )
   AAdd( aParts, "XbpTreeView"      )
   AAdd( aParts, "XbpTreeViewItem"  )
   AAdd( aParts, "XbpActiveXControl" )
   AAdd( aParts, "XbpListBox"       )
   AAdd( aParts, "XbpPushButton"    )
   AAdd( aParts, "XbpCheckBox"      )
   AAdd( aParts, "XbpRadioButton"   )
   AAdd( aParts, "Xbp3State"        )
   AAdd( aParts, "XbpSLE"           )
   AAdd( aParts, "XbpMLE"           )
   AAdd( aParts, "XbpHTMLViewer"    )
   AAdd( aParts, "XbpSysWindow"     )
   AAdd( aParts, "XbpFontDialog"    )
   AAdd( aParts, "XbpFont"          )
   AAdd( aParts, "-------------"    )
   AAdd( aParts, "DataRef"          )

   AEval( aParts, {| e | oListBox:addItem( e ) } )
   oListBox:itemSelected := {|| wvg_MessageBox( , oListBox:getCurItem() ) }
   oListBox:setData( 3 )

   oXbp := WvgPushButton():new( oStatic )
   oXbp:caption := "Hide"
   oXbp:create( , , { 20, 440 }, { 80, 30 } )
   oXbp:activate := {|| oStatic:hide(), oCrt:sendMessage( WM_SIZE, 0, 0 ) }

   oTree := WvgTreeView():new( oDA, , { oCrt:currentSize()[ 1 ] - 160, oTBar:currentSize()[ 2 ] + 3 }, ;
      { 160, oCrt:currentSize()[ 2 ] - ;
      oTBar:currentSize()[ 2 ] - oSBar:currentSize()[ 2 ] - 4 }, , .T. )
   oTree:hasLines   := .T.
   oTree:hasButtons := .T.
   oTree:alwaysShowSelection := .T.
   oTree:create()
   oTree:setColorBG( RGB( 120, 15, 240 ) )
   oTree:setColorFG( RGB( 15, 240, 120 ) )
   oTree:itemSelected := {| oItem | iif( oItem != NIL, wvg_MessageBox( , oItem:caption ), NIL ) }

   oItem1 := oTree:rootItem:addItem( "First level A" )

   oTree:rootItem:addItem( "First level B" )

   oItem2 := oItem1:addItem( "Second level A" )
   oItem1:addItem( "Second level B" )

   oItem2:addItem( "Third level A" )
   oItem2:addItem( "Third level B" )
   oItem2:addItem( "Third level C" )

   oTree:setData( oItem2 )

   hb_gtInfo( HB_GTI_WINTITLE, "http:
   oCom:create()
   oCom:Navigate( "http:

   oAddr := WvgSLE():new()
   oAddr:bufferLength := 500
   oAddr:border       := .T.
   cNavigate          := "http:
   oAddr:dataLink     := {| x | iif( x == NIL, cNavigate, cNavigate := x ) }
   oAddr:setColorFG( RGB( 0, 0, 255   ) )
   oAddr:setColorBG( RGB( 0, 255, 255 ) )
   oAddr:create( oDA, , { 120, oTBar:currentSize()[ 2 ] }, { 500, 20 }, , .T. )
   oAddr:setData()
   oAddr:killInputFocus := {| m1, m2, oS | m1 := m1, m2 := m2, oS:getData(), oCom:navigate( cNavigate ) }

   oStatic2 := WvgStatic():New( oDA, , { 150, 150 }, { 500, 310 }, , .F. )

   oStatic2:exStyle += WS_EX_WINDOWEDGE

   oStatic2:create()
   oStatic2:setColorBG( RGB( 175, 175, 175 ) )

   oXbp    := WvgPushButton():new( oStatic2 )
   oXbp:caption     := "Hide"
   oXbp:caption     := "Hide"
   oXbp:create( , , { 430, 275 }, { 60, 25 } )
   oXbp:activate    := {|| oStatic2:hide(), oCrt:sendMessage( WM_SIZE, 0, 0 ) }

   oRadio  := WvgRadioButton():new( oStatic2, , { 10, 10 }, { 100, 15 } )
   oRadio:caption   := "Com 1"
   oRadio:selection := .T.
   oRadio:selected  := {| m1, m2, obj | m1 := m1, m2 := m2, wvg_MessageBox( , obj:caption + iif( obj:selection, "< S >", "< N >" ) ) }
   oRadio:create()

   oRadio  := WvgRadioButton():new( oStatic2, , { 10, 35 }, { 100, 15 } )
   oRadio:caption   := "Com 2"
   oRadio:create()

   oCheck  := WvgCheckBox():New( oStatic2, , { 10, 70 }, { 100, 15 }, , .T. )
   oCheck:caption   := "Checkbox A"
   oCheck:create()
   oCheck:selected  := {| m1, m2, o | m1 := m1, m2 := m2, wvg_MessageBox( , iif( o:getData(), "I am selected", "I am not selected" ) ) }

   oXbp    := Wvg3State():new()
   oXbp:caption := "3 State A"
   oXbp:create( oStatic2, , { 10, 100 }, { 100, 15 } )

   oXbp:selected := {| m1, m2, oBtn | m2 := m2, oBtn := oBtn, oPanel1:caption := "3State A [" + aState[ m1 + 1 ] + "]" }

   oXbp    := Wvg3State():new( oStatic2, , { 10, 125 }, { 100, 15 } )
   oXbp:caption := "3 State B"
   oXbp:create( oStatic2 )

   oXbp:selected := {| m1, m2, oBtn | m1 := m1, m2 := m2, wvg_MessageBox( , "3State B", aState[ oBtn:getData() + 1 ] ) }

   oXbp                := WvgSLE():new()
   oXbp:autoTab        := .T.
   oXbp:bufferLength   := 20

   oXbp:dataLink       := {| x | iif( x == NIL, cVarA, cVarA := x ) }
   oXbp:create( oStatic2, , { 10, 170 }, { 150, 20 } )
   oXbp:setData()

   oXbp:killInputFocus := {| x, y, oSLE | x := x, y := y, oSLE:getData(), oPanel:caption := "cVarA =" + cVarA }

   oXbp                := WvgSLE():new( , , { 10, 200 }, { 150, 20 } )
   oXbp:tabStop        := .T.
   oXbp:bufferLength   := 15
   oXbp:dataLink       := {| x | iif( x == NIL, cVarB, cVarB := x ) }
   oXbp:create( oStatic2 )
   oXbp:setData()
   oXbp:killInputFocus := {| x, y, oSLE | x := x, y := y, oSLE:getData(), oPanel:caption := "cVarB =" + cVarB }

   cText   := MemoRead( "gtwvg.hbc" )

   oMLE    := WvgMLE():new()
   oMLE:wordWrap := .F.
   oMLE:border   := .T.
   oMLE:dataLink := {| x | iif( x == NIL, cText, cText := x ) }
   oMLE:create( oStatic2, , { 180, 10 }, { 310, 250 } )

   oMLE:setData()

   oTBar:buttonClick := {| oBtn | iif( oBtn:caption == "Hide"   , oStatic:hide(), NIL ), ;
      iif( oBtn:caption == "Show"   , oStatic:show(), NIL ), ;
      iif( oBtn:caption == "Tools"  , oStatic2:show():toFront(), NIL ), ;
      iif( oBtn:caption == "FontDlg", ExeFontDialog( oCrt ), NIL ), ;
      iif( oBtn:caption $ "Hide,Show", oCrt:sendMessage( WM_SIZE, 0, 0 ), NIL ), ;
      oPanel2:caption := "Button [ " + oBtn:caption + " ] clicked!" }

   oCrt:resize := {|| ResizeDialogXbp( oCrt, oTBar, oSBar, oStatic, oCom, oTree, oAddr ) }

   oCrt:sendMessage( WM_SIZE, 0, 0 )
   oCrt:show()

   DO WHILE .T.
      IF Inkey() == K_ESC
         EXIT
      ENDIF
   ENDDO

   oCrt:Destroy()

   RETURN

STATIC FUNCTION ResizeDialogXbp( oCrt, oTBar, oSBar, oStatic, oCom, oTree, oAddr )

   LOCAL aCrt, aTBar, aSBar
   LOCAL nH, nT

   aCrt    := oCrt:currentSize()
   aTBar   := oTBar:currentSize()
   aSBar   := oSBar:currentSize()

   nT := aTBar[ 2 ]
   nH := aCrt[ 2 ] - aTBar[ 2 ] - aSBar[ 2 ]

   IF oStatic:isVisible