[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/dirscan.prg. Provides functions: hb_doScan, hb_DirScan, hb_DirRemoveAll, hb_FileDelete. This file provides file I/O operations

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

STATIC FUNCTION hb_doScan( cPath, cMask, cAttr, cPathSep )

   LOCAL aFile
   LOCAL lMatch
   LOCAL aResult := {}

   FOR EACH aFile IN hb_vfDirectory( cPath + hb_osFileMask(), cAttr + "D" )
      lMatch := hb_FileMatch( aFile[ F_NAME ], cMask )
      IF "D" $ aFile[ F_ATTR ]
         IF lMatch .AND. "D" $ cAttr
            AAdd( aResult, aFile )
         ENDIF
         IF !( aFile[ F_NAME ] == "." .OR. aFile[ F_NAME ] == ".." .OR. aFile[ F_NAME ] == "" )
            AEval( hb_DoScan( cPath + aFile[ F_NAME ] + cPathSep, cMask, cAttr, cPathSep ), ;
               {| x | x[ F_NAME ] := aFile[ F_NAME ] + cPathSep + x[ F_NAME ], ;
               AAdd( aResult, x ) } )
         ENDIF
      ELSEIF lMatch
         AAdd( aResult, aFile )
      ENDIF
   NEXT

   RETURN aResult

FUNCTION hb_DirScan( cPath, cFileMask, cAttr )
   RETURN hb_DoScan( hb_DirSepAdd( hb_defaultValue( cPath, "" ) ), ;
      iif( HB_ISSTRING( cFileMask ), cFileMask, hb_osFileMask() ), ;
      hb_defaultValue( cAttr, "" ), ;
      hb_ps() )

FUNCTION hb_DirRemoveAll( cDir )

   LOCAL aFile, cPath, cFile, nAttr

   IF ! Empty( cDir ) .AND. hb_vfDirExists( cDir )
      cPath := hb_DirSepDel( cDir )
      IF hb_vfAttrGet( cPath, @nAttr ) .AND. ! hb_bitAnd( nAttr, HB_FA_READONLY ) == 0
         hb_vfAttrSet( cPath, hb_bitXor( nAttr, HB_FA_READONLY ) )
      ENDIF
      cPath := hb_DirSepAdd( cPath )
      FOR EACH aFile IN hb_vfDirectory( cPath + hb_osFileMask(), "HSDL" )
         IF "D" $ aFile[ F_ATTR ] .AND. ! "L" $ aFile[ F_ATTR ]
            IF !( aFile[ F_NAME ] == "." .OR. aFile[ F_NAME ] == ".." .OR. aFile[ F_NAME ] == "" )
               IF ! hb_DirRemoveAll( cPath + aFile[ F_NAME ] )
                  RETURN .F.
               ENDIF
            ENDIF
         ELSE
            cFile := cPath + aFile[ F_NAME ]
            IF "R" $ aFile[ F_ATTR ] .AND. hb_vfAttrGet( cFile, @nAttr )
               hb_vfAttrSet( cFile, hb_bitAnd( nAttr, hb_bitNot( HB_FA_READONLY ) ) )
            ENDIF
            IF ! hb_vfErase( cFile ) == 0
               RETURN .F.
            ENDIF
         ENDIF
      NEXT
      RETURN hb_vfDirRemove( cDir ) == 0
   ENDIF

   RETURN .T.

FUNCTION hb_FileDelete( cFileMask, cAttr )

   LOCAL lAny := .F., aFile, cPath, cFile, cAttrMask, nAttr

   IF HB_ISSTRING( cFileMask ) .AND. ! Empty( cFileMask ) .AND. ;
      ! hb_vfDirExists( cFileMask )
      cPath := hb_FNameDir( cFileMask )
      cAttrMask := StrTran( hb_defaultValue( cAttr, "" ), "D" ) + "L"
      FOR EACH aFile IN hb_vfDirectory( cFileMask, cAttrMask )
         cFile := cPath + aFile[ F_NAME ]
         IF "R" $ aFile[ F_ATTR ] .AND. hb_vfAttrGet( cFile, @nAttr )
            hb_vfAttrSet( cFile, hb_bitAnd( nAttr, hb_bitNot( HB_FA_READONLY ) ) )
         ENDIF
         IF hb_vfErase( cFile ) == 0
            lAny := .T.
         ENDIF
      NEXT
   ENDIF

RETURN lAny


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

[User] Implement these Harbour functions: Harbour test program: tests/vmasort.prg. Provides functions: aMkArray, xToStr. Contains procedures: Main. This test file tests specific function APIs

[Assistant]
#ifndef __HARBOUR__
   #define hb_ntos( n ) LTrim( Str( n ) )
#endif

PROCEDURE Main( nPass )

   LOCAL aTest
   LOCAL aOrig

   IF nPass == NIL
      nPass := 1
   ELSE
      nPass := Val( nPass )
   ENDIF

   ? "Testing ASort() with " + hb_ntos( nPass ) + " loops."
   ?
   aTest := aMkArray( nPass )
   aOrig := AClone( aTest )

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

   ? "Original.....:", aDump( aOrig )
   ? "asort.c......:", aDump( ASort( aTest ) )

   RETURN

STATIC FUNCTION aMkArray( nPass )

   LOCAL aData := {}
   LOCAL n
   LOCAL nMult := 200
   LOCAL nMid  := ( nMult / 2 ) + 1
   LOCAL nMax  := nPass
   LOCAL cStr := ""
   LOCAL n := Len( a )
   LOCAL i

   FOR i := 1 TO n
      cStr += AllTrim( xToStr( a[ i ] ) ) + " "
   NEXT

   RETURN cStr

STATIC FUNCTION xToStr( xValue )

   LOCAL cType := ValType( xValue )

   DO CASE
   CASE cType == "C" .OR. cType == "M"
      RETURN xValue
   CASE cType == "N"
      RETURN hb_ntos( xValue )
   CASE cType == "D"
      RETURN DToC( xValue )
   CASE cType == "L"
      RETURN iif( xValue, ".T.", ".F." )
   CASE cType == "U"
      RETURN "NIL"
   CASE cType == "A"
      RETURN "{.}"
   CASE cType == "B"
      RETURN "{|| }"
   CASE cType == "O"
      RETURN "[O]"
   ENDCASE

   RETURN xValue


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

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

[Assistant]
#include "inkey.ch"

STATIC s_nRecNo := 1
STATIC s_nLastRec := 100
STATIC s_lFixPos := .F.

PROCEDURE Main()

   LOCAL nRow := 1

   CLS
   @ 0, 4        SAY "Is current RecNo but not repositioned until FixPos .T. <F2> Change FixPos"
   @ MaxRow(), 1 SAY "Please press <Enter> to select or <Esc> to exit and <F2> to FixPos is"
   WHILE LastKey() != K_ESC
      @ 0, 0 SAY s_nRecNo PICTURE "###"
      @ MaxRow(), 68 SAY iif( s_lFixPos, ".T.", ".F." )
      nRow := TestBrw( nRow  )
   ENDDO

   RETURN

FUNCTION TestBrw( nRowIni )

   LOCAL nKey, oBrw := TBrowseNew( 1, 0, MaxRow() - 1, MaxCol() )

   oBrw:SkipBlock     := {| n | n := iif( n < 0, Max( n, 1 - s_nRecNo ), ;
      Min( s_nLastRec - s_nRecNo, n ) ), ;
      s_nRecNo += n, n }
   oBrw:GoTopBlock    := {|| s_nRecNo := 1 }
   oBrw:GoBottomBlock := {|| s_nRecNo := s_nLastRec }
   oBrw:AddColumn( TBColumnNew( "RecNo #", {|| s_nRecNo } ) )

   IF s_lFixPos .AND. nRowIni > 1
      Eval( oBrw:skipBlock, 1 - nRowIni )
   ENDIF

   oBrw:rowPos := nRowIni
   WHILE .T.
      oBrw:forceStable()
      nKey := Inkey( 0 )
      IF nKey == K_ESC .OR. nKey == K_ENTER
         EXIT
      ELSEIF nKey == K_F2
         s_lFixPos := ! s_lFixPos
         EXIT
      ELSEIF nKey == K_DOWN
         oBrw:Down()
      ELSEIF nKey == K_UP
         oBrw:Up()
      ELSEIF nKey == K_PGDN
         oBrw:pageDown()
      ELSEIF nKey == K_PGUP
         oBrw:pageUp()
      ELSEIF nKey == K_CTRL_HOME .OR. nKey == K_CTRL_PGUP
         oBrw:goTop()
      ELSEIF nKey == K_CTRL_END .OR. nKey == K_CTRL_PGDN
         oBrw:goBottom()
      ELSEIF nKey == K_HOME
         oBrw:rowPos := 1
      ELSEIF nKey == K_END
         oBrw:rowPos := s_nLastRec
      ENDIF
   ENDDO

   RETURN oBrw:rowPos


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

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

Harbour contribution module 'hbnf' (NanForum Toolkit - legacy Clipper compatibility functions): contrib/hbnf/miltime.prg. Provides functions: ft_Mil2Min, ft_Mil2Civ, ft_Civ2Mil, ft_Sys2Mil. This file provides legacy compatibility functions

[Assistant]
FUNCTION ft_Mil2Min( cMILTIME )

   RETURN Int( Val( Left( cMILTIME, 2 ) )
      Right( "00" + hb_ntos( Int( nMin / 60 ) ), 2 ) + ;
      Right( "00" + hb_ntos( Int( nMin % 60 ) ), 2 )

FUNCTION ft_Mil2Civ( cMILTIME )

   LOCAL cHRS, cMINS, nHRS, cCIVTIME

   nHRS  := Val( Left( cMILTIME, 2 ) )
   cMINS := Right( cMILTIME, 2 )

   DO CASE
   CASE ( nHRS == 24 .OR. nHRS == 0 ) .AND. cMINS == "00"
      cCIVTIME := "12:00 m"
   CASE nHRS == 12
      IF cMINS == "00"
         cCIVTIME := "12:00 n"
      ELSE
         cCIVTIME := "12:" + cMINS + " pm"
      ENDIF
   CASE nHRS < 12
      IF nHRS == 0
         cHRS := "12"
      ELSE
         cHRS := Right( "  " + hb_ntos( Int( nHRS ) ), 2 )
      ENDIF
      cCIVTIME := cHRS + ":" + cMINS + " am"

   OTHERWISE
      cCIVTIME := Right( "  " + hb_ntos( Int( nHRS - 12 ) ), 2 ) + ;
         ":" + cMINS + " pm"
   ENDCASE

   RETURN cCIVTIME

FUNCTION ft_Civ2Mil( cTIME )

   LOCAL cKEY, cMILTIME

   cTIME := Replicate( "0", 3 - At( ":", LTrim( cTIME ) ) ) + LTrim( cTIME )

   IF Left( LTrim( cTIME ), 2 ) == "12"
      cTIME := Stuff( cTIME, 1, 2, "00" )
   ENDIF

   cKEY := SubStr( LTrim( cTIME ), 7, 1 )

   DO CASE
   CASE Upper( cKEY ) == "N"
      IF Left( cTIME, 2 ) + SubStr( cTIME, 4, 2 ) == "0000"
         cMILTIME := "1200"
      ELSE
         cMILTIME := "    "
      ENDIF
   CASE Upper( cKEY ) == "M"
      IF Left( cTIME, 2 ) + SubStr( cTIME, 4, 2 ) == "0000"
         cMILTIME := "0000"
      ELSE
         cMILTIME := "    "
      ENDIF
   CASE Upper( cKEY ) == "A"
      cMILTIME := Right( "00" + hb_ntos( Val( Left( cTIME, 2 ) ) ), 2 ) + ;
         SubStr( cTIME, 4, 2 )
   CASE Upper( cKEY ) == "P"
      cMILTIME := Right( "00" + hb_ntos( Val( Left( cTIME, 2 ) ) + 12 ), 2 ) + ;
         SubStr( cTIME, 4, 2 )
   OTHERWISE
      cMILTIME := "    "
   ENDCASE

   RETURN cMILTIME

FUNCTION ft_Sys2Mil()

   RETURN Left( Stuff( Time(), 3, 1, "" ), 4 )


[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: InitScrlBar, updateFilesScroll. Harbour test program: tests/sbar.prg. Provides functions: InitScrlBar, updateFilesScroll. Contains procedures: Main. This test file tests specific function APIs

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

#ifdef __HARBOUR__
   #define B_THIN  hb_UTF8ToStrBox( "█▀███▄██" )
#else
   #define B_THIN  ( Chr( 219 ) + Chr( 223 ) + Chr( 219 ) + Chr( 219 ) + ;
                     Chr( 219 ) + Chr( 220 ) + Chr( 219 ) + Chr( 219 ) )
#endif

PROCEDURE Main()

   InitScrlBar()

   RETURN

FUNCTION InitScrlBar()

   LOCAL tmpFileList, i

   LOCAL aFileList := {}
   LOCAL filesScroll

   CLS
   SetBlink( .F. )
#ifdef __HARBOUR__
   @  0,  0, MaxRow(), MaxCol() BOX Replicate( hb_UTF8ToStrBox( "▓" ), 9 ) COLOR "GR+/W*"
#else
   @  0,  0, MaxRow(), MaxCol() BOX Replicate( Chr( 178 ), 9 ) COLOR "GR+/W*"
#endif
   @  4, 28 SAY "            Directory            " COLOR "W+/B"
   @  5, 28, 15, 60 BOX B_THIN + " " COLOR "W/W*"

   tmpFileList := Directory()

   FOR i := 1 TO Len( tmpFileList )
      AAdd( aFileList, tmpFileList[ i ][ F_NAME ] )
   NEXT

   filesScroll := ScrollBar( 6, 14, 60, NIL, 1 )

   filesScroll:total := Len( aFileList )

   filesScroll:colorSpec := "W+/W, W+/W"
   SET COLOR TO "N/W*, W+/B,,,W/N"

   filesScroll:display()

   i := AChoice( 6, 29, 14, 59, aFileList, , {| modo | updateFilesScroll( modo, aFileList, filesScroll ) } )

   @ MaxRow() - 1, 0 SAY iif( i < 1, "", aFileList[ i ] ) COLOR "N/W*"
   SET COLOR TO
   @ MaxRow(), 0

   RETURN 0

STATIC FUNCTION updateFilesScroll( modo, aFileList, filesScroll )

   LOCAL newPos, valRet := AC_CONT
   LOCAL nLastKey := LastKey()

   newPos := filesScroll:current

   DO CASE
   CASE nLastKey == K_CTRL_PGUP
      newPos := 1
   CASE nLastKey == K_CTRL_PGDN
      newPos := filesScroll:total
   CASE nLastKey == K_CTRL_HOME
      newPos := newPos - ( filesScroll:barLength + 1 )
   CASE nLastKey == K_CTRL_END
      newPos := newPos + ( filesScroll:barLength + 1 )
   CASE nLastKey == K_PGUP
      newPos := newPos - ( filesScroll:barLength + 1 )
   CASE nLastKey == K_PGDN
      newPos := newPos + ( filesScroll:barLength + 1 )
   CASE nLastKey == K_UP
      newPos--
   CASE nLastKey == K_DOWN
      newPos++
   CASE modo == AC_EXCEPT
      DO CASE
      CASE nLastKey == K_ENTER
         valRet := AC_SELECT
      CASE nLastKey == K_ESC
         valRet := AC_ABORT
      OTHERWISE
         valRet := AC_GOTO
      ENDCASE
   ENDCASE

   IF newPos < 1
      newPos := 1
   ELSEIF newPos >= filesScroll:total
      newPos := filesScroll:total
   ENDIF

   filesScroll:current := newPos
   filesScroll:update()

   RETURN valRet


[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 'xhb' (Extended Harbour functions): contrib/xhb/ttable.prg. Provides 15 functions including: NetDbUse, NetLock, NetFunc, NetOpenFiles, NetDelete. Contains procedures: NetFlush. This file provides legacy compatibility functions

[Assistant]
#include "hbclass.ch"

#include "ttable.ch"
#include "ord.ch"
#include "inkey.ch"
#include "dbinfo.ch"
#include "error.ch"

STATIC s_aTables := {}

STATIC s_nNetDelay    := 30
STATIC s_lNetOk       := .F.
STATIC s_cNetMsgColor := "GR+/R"

FUNCTION NetDbUse( cDataBase, cAlias, nSeconds, cDriver, ;
      lNew, lOpenMode, lReadOnly )

   LOCAL nKey
   LOCAL lForever
   LOCAL cOldScreen := SaveScreen( MaxRow(), 0, MaxRow(), MaxCol() + 1 )
   LOCAL lFirstPass := .T.

   __defaultNIL( @cDriver, "DBFCDX" )
   __defaultNIL( @lNew, .T. )
   __defaultNIL( @lOpenMode, NET_OPEN_MODE )
   __defaultNIL( @lReadOnly, .F. )
   __defaultNIL( @nSeconds, s_nNetDelay )

   s_lNetOk := .F.
   nSeconds
            PadC( "Network retry | " + ;
            LTrim( Str( nSeconds, 4, 1 ) ) + " | ESCape = Exit ", ;
            MaxCol() + 1 ), ;
            s_cNetMsgColor )
         lFirstPass := .F.
      ENDIF

      dbUseArea( lNew, ;
         cDriver, cDatabase, cAlias, ;
         lOpenMode, ;
         .F. )

      IF ! NetErr()
         RestScreen( MaxRow(), 0, MaxRow(), MaxCol() + 1, cOldScreen )
         s_lNetOk := .T.
      ELSE
         lFirstPass := .F.
      ENDIF

      IF ! s_lNetOk
         nKey := Inkey( 0.5 )
         nSeconds -= 0.5
      ELSE
         RestScreen( MaxRow(), 0, MaxRow(), MaxCol() + 1, cOldScreen )
         EXIT
      ENDIF

      IF nKey == K_ESC
         RestScreen( MaxRow(), 0, MaxRow(), MaxCol() + 1, cOldScreen )
         EXIT
      ENDIF

   ENDDO

   RestScreen( MaxRow(), 0, MaxRow(), MaxCol() + 1, cOldScreen )

   RETURN s_lNetOk

FUNCTION NetLock( nType, lReleaseLocks, nSeconds )

   LOCAL cSave       := SaveScreen( MaxRow(), 0, MaxRow(), MaxCol() + 1 )
   LOCAL lContinue   := .T.
   LOCAL lSuccess    := .F.
   LOCAL nWaitTime
   LOCAL bOperation
   LOCAL xIdentifier
   LOCAL nKey
   LOCAL nCh
   LOCAL cWord

   IF ! HB_ISNUMERIC( nType ) .OR. ;
      ( nType != 1 .AND. ;
        nType != 2 .AND. ;
        nType != 3 )
      Alert( "Invalid Argument passed to NetLock()" )
      RETURN lSuccess
   ENDIF

   __defaultNIL( @lReleaseLocks, .F. )
   __defaultNIL( @nSeconds, s_nNetDelay )

   nWaitTime := nSeconds

   SWITCH nType
   CASE NET_RECLOCK
      xIdentifier := iif( lReleaseLocks, NIL, RecNo() )
      bOperation  := {| x | dbRLock( x ) }
      EXIT
   CASE NET_FILELOCK
      bOperation := {|| FLock() }
      EXIT
   CASE NET_APPEND
      xIdentifier := lReleaseLocks
      bOperation  := {| x | dbAppend( x ), ! NetErr() }
      EXIT
   ENDSWITCH

   s_lNetOk := .F.

   WHILE lContinue

      WHILE nSeconds > 0 .AND. lContinue
         IF Eval( bOperation, xIdentifier )
            nSeconds  := 0
            lSuccess  := .T.
            lContinue := .F.
            s_lNetOk  := .T.
            EXIT
         ELSE
            IF nType == 1
               cWord := "( " + dbInfo( DBI_ALIAS ) + " - Record Lock )"
            ELSEIF nType == 2
               cWord := "( " + dbInfo( DBI_ALIAS ) + " - File Lock )"
            ELSEIF nType == 3
               cWord := "( " + dbInfo( DBI_ALIAS ) + " - File Append )"
            ELSE
               cWord := "( " + dbInfo( DBI_ALIAS ) + " -  ??? "
            ENDIF

            hb_DispOutAt( MaxRow(), 0, ;
               PadC( "Network Retry " + cWord + " | " + Str( nSeconds, 3 ) + " | ESC Exit", MaxCol() + 1 ), ;
               s_cNetMsgColor )

            nKey := Inkey( 1 )
            nSeconds--
            IF nKey == K_ESC
               RestScreen( MaxRow(), 0, MaxRow(), MaxCol() + 1, cSave )
               EXIT
            ENDIF
         ENDIF
      ENDDO

      IF LastKey() == K_ESC
         RestScreen( MaxRow(), 0, MaxRow(), MaxCol() + 1, cSave )
         EXIT
      ENDIF

      IF ! lSuccess
         nSeconds := nWaitTime
         nCh := Alert( RETRY_MSG, { "  YES  ", "  NO  " } )

         lContinue := ( nCh == 1 )

         IF ! lContinue

            RestScreen( MaxRow(), 0, MaxRow(), MaxCol() + 1, cSave )
            RETURN lSuccess
         ENDIF

      ENDIF
   ENDDO

   RestScreen( MaxRow(), 0, MaxRow(), MaxCol() + 1, cSave )

   RETURN lSuccess

FUNCTION NetFunc( bBlock, nSeconds )

   LOCAL lForever

   __defaultNIL( @nSeconds, s_nNetDelay )
   lForever := ( nSeconds == 0 )

   DO WHILE lForever .OR. nSeconds > 0

      IF Eval( bBlock )
         RETURN .T.
      ENDIF

      Inkey( 1 )
      nSeconds -= 0.5
   ENDDO

   RETURN .F.

FUNCTION NetOpenFiles( aFiles )

   LOCAL nRet := 0
   LOCAL xFile, cIndex

   FOR EACH xFile IN aFiles

      IF ! hb_dbExists( xFile[ 1 ] )
         nRet := -1
         EXIT
      ENDIF

      IF NetDbUse( xFile[ 1 ], xFile[ 2 ], s_nNetDelay, "DBFCDX" )
         IF HB_ISARRAY( xFile[ 3 ] )
            FOR EACH cIndex IN xFile[ 3 ]
               IF hb_dbExists( cIndex )
                  ordListAdd( cIndex )
               ELSE
                  nRet := -3
                  EXIT
               ENDIF
            NEXT
         ENDIF
      ELSE
         nRet := -2
         EXIT
      ENDIF
   NEXT

   RETURN nRet

FUNCTION NetDelete()

   s_lNetOk := .F.

   IF NetLock( NET_RECLOCK )
      dbDelete()
      s_lNetOk := .T.
   ENDIF

   IF ! NetErr()
      dbSkip( 0 )
      dbCommit()
   ELSE
      s_lNetOk := .T.
      Alert( " Failed to DELETE Record -> " + Str( RecNo() ) )
   ENDIF

   RETURN s_lNetOk

FUNCTION NetRecall()

   s_lNetOk := .F.

   IF NetLock( NET_RECLOCK )
      dbRecall()
      s_lNetOk := .T.
   ENDIF

   IF ! NetErr()
      dbSkip( 0 )
      dbCommit()
   ELSE
      s_lNetOk := .T.
      Alert( " Failed to RECALL Record -> " + Str( RecNo() ) )
   ENDIF

   RETURN s_lNetOk

FUNCTION NetRecLock( nSeconds )

   __defaultNIL( @nSeconds, s_nNetDelay )

   s_lNetOk := .F.

   IF NetLock( NET_RECLOCK, , nSeconds )
      s_lNetOk := .T.
   ENDIF

   RETURN s_lNetOk

FUNCTION NetFileLock( nSeconds )

   s_lNetOk := .F.
   __defaultNIL( @nSeconds, s_nNetDelay )

   IF NetLock( NET_FILELOCK, , nSeconds )
      s_lNetOk := .T.
   ENDIF

   RETURN s_lNetOk

FUNCTION NetAppend( nSeconds, lReleaseLocks )

   LOCAL nOrd

   __defaultNIL( @lReleaseLocks, .T. )
   __defaultNIL( @nSeconds, s_nNetDelay )
   s_lNetOk := .F.
   nOrd := ordSetFocus( 0 )

   IF NetLock( NET_APPEND, , nSeconds )

      s_lNetOk := .T.
   ENDIF

   ordSetFocus( nOrd )

   RETURN s_lNetOk

PROCEDURE NetFlush()

   dbCommitAll()
   dbUnlockAll()
   dbSkip( 0 )

   RETURN

FUNCTION NetCommitAll()

   LOCAL n

   FOR n := 1 TO MAX_TABLE_AREAS
      IF ! Empty( Alias( n ) )
         ( Alias( n ) )->( dbCommit(), dbUnlock() )
      ENDIF
   NEXT

   RETURN n

FUNCTION IsLocked( nRecId )

   __defaultNIL( @nRecID, RecNo() )

   RETURN AScan( dbRLockList(), {| n | n == nRecID } ) > 0

FUNCTION NetError()

   RETURN ! s_lNetOk

FUNCTION SetNetDelay( nSecs )

   LOCAL nTemp := s_nNetDelay

   IF nSecs != NIL
      s_nNetDelay := nSecs
   ENDIF

   RETURN nTemp

FUNCTION SetNetMsgColor( cColor )

   LOCAL cTemp := s_cNetMsgColor

   IF cColor != NIL
      s_cNetMsgColor := cColor
   ENDIF

   RETURN cTemp

FUNCTION TableNew( cDBF, cALIAS, cOrderBag, cDRIVER, ;
      lNET, cPATH, lNEW, lREADONLY )

   LOCAL nPos
   LOCAL lAuto
   LOCAL oDB
   LOCAL o

   __defaultNIL( @lNET, .T. )
   __defaultNIL( @lNEW, .T. )
   __defaultNIL( @lREADONLY, .F. )
   __defaultNIL( @cDRIVER, "DBFCDX" )
   __defaultNIL( @cPATH, Set( _SET_DEFAULT ) )
   __defaultNIL( @cAlias, FixExt( cDbf ) )
   __defaultNIL( @cOrderBag, FixExt( cDbf ) )

   lAuto := Set( _SET_AUTOPEN, .F. )

   IF ( nPos := AScan( s_aTables, {| e | e[ 1 ] == Upper( cALIAS ) } ) ) > 0

      oDB := s_aTables[ nPos, 2 ]

   ELSE
      o := HBTable():New( cDBF, cALIAS, cOrderBag, cDRIVER, ;
         lNET, cPATH, lNEW, lREADONLY )
      IF o:Open()
         oDB := o:FldInit()
      ENDIF

      AAdd( s_aTables, { Upper( cAlias ), oDB } )

   ENDIF


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

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

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

[Assistant]
FUNCTION ft_Week( dGivenDate, nWeekNum )

   LOCAL nTemp, aRetVal, dTemp

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

   aRetVal      := ft_Year( dGivenDate )
   dTemp        := aRetVal[ 2 ]
   aRetVal[ 2 ] -= ft_DayToBoW( aRetVal[ 2 ] )

   IF HB_ISNUMERIC( nWeekNum )
      nTemp := Int( ( aRetVal[ 3 ] - aRetVal[ 2 ] ) / 7 ) + 1
      IF nWeekNum < 1 .OR. nWeekNum > nTemp
         nWeekNum := nTemp
      ENDIF
      dGivenDate := aRetVal[ 2 ] + ( nWeekNum - 1 )


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

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

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

[Assistant]
#require "hbwin"

#include "simpleio.ch"

PROCEDURE Main()

   LOCAL cSubject := "Test subject"
   LOCAL cBody := "Test body"
   LOCAL lMailConf := .F.
   LOCAL lFromUser := .T.
   LOCAL aSender := { "test from", "from@test.com" }
   LOCAL aDest := { { "test to", "to@test.com", WIN_MAPI_TO } }
   LOCAL aFiles := { { __FILE__, hb_FNameName( __FILE__ ) } }

   ? win_MAPISendMail( ;
      cSubject,                        ;
      cBody,                           ;
      NIL,                             ;
      DToS( Date() ) + " " + Time(),   ;
      "",                              ;
      lMailConf,                       ;
      lFromUser,                       ;
      aSender,                         ;
      aDest,                           ;
      aFiles                           )

   ? win_MAPISendMail( ;
      cSubject,                        ;
      cBody,                           ;
      NIL,                             ;
      DToS( Date() ) + " " + Time(),   ;
      "",                              ;
      lMailConf,                       ;
      lFromUser,                       ;
      "from@test.com",                 ;
      { "to@test.com" },               ;
      { __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] Implement this Harbour module: Harbour contribution module 'hbgd' (Graphics drawing library (GD)): contrib/hbgd/gdchart.prg. Defines classes: GDChart. This file provides graphics and image processing capabilities

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

CREATE CLASS GDChart INHERIT GDImage

   VAR cTitle
   VAR cAxisX
   VAR cAxisY
   VAR nWidth
   VAR nHeight
   VAR nScaleX
   VAR nScaleY

   VAR aSeries
   VAR aDataOfHashes
   VAR hDefs

   METHOD New( sx, sy )  CONSTRUCTOR
   METHOD AddData( hData )
   METHOD AddDef( cDefKey, xDefVal )
   METHOD SetData( aData )
   METHOD SetDefs( hDefs )

   METHOD PieChart()
   METHOD VerticalBarChart()
   METHOD HorizontalBarChart()
   METHOD LineChart()

   METHOD Clone()

   PROTECTED:
   METHOD CloneDataFrom( oSrc )

ENDCLASS

METHOD New( sx, sy ) CLASS GDChart

   hb_default( @sx, 320 )
   hb_default( @sy, 200 )

   ::cTitle := "Chart"
   ::aSeries        := {}
   ::hDefs          := { => }
   ::aDataOfHashes  := {}

   ::Create( sx, sy )

   RETURN Self

METHOD AddData( hData ) CLASS GDChart

   IF HB_ISHASH( hData )
      AAdd( ::aDataOfHashes, hData )
   ENDIF

   RETURN Self

METHOD SetData( aData ) CLASS GDChart

   IF HB_ISARRAY( aData )
      ::aDataOfHashes := aData
   ENDIF

   RETURN Self

METHOD AddDef( cDefKey, xDefVal ) CLASS GDChart

   IF HB_ISSTRING( cDefKey )
      ::hDefs[ Upper( cDefKey ) ] := xDefVal
   ENDIF

   RETURN Self

METHOD SetDefs( hDefs ) CLASS GDChart

   IF HB_ISHASH( hDefs )
      ::hDefs := hDefs
   ENDIF

   RETURN Self

METHOD PieChart() CLASS GDChart

   LOCAL hElement, nTot := 0
   LOCAL nDegree := 0
   LOCAL lFilled, lExtruded, nExtrude, nTotExtr := 0, pTile
   LOCAL colorp
   LOCAL nVal, nDim
   LOCAL nPosX, nPosY
   LOCAL cLabel, hFont, cFontName, nPitch, nAngle, textcolor
   LOCAL x, y, nWidth
   LOCAL aPieDataOfHash, hDefs
   LOCAL cFontPitch

   aPieDataOfHash := ::aDataOfHashes
   hDefs          := ::hDefs

   x          := __HGetValue( hDefs, "POSX" )
   y          := __HGetValue( hDefs, "POSY" )
   nWidth     := __HGetValue( hDefs, "WIDTH" )
   cFontPitch := __HGetValue( hDefs, "FONTPITCH" )

   hb_default( @x         , ::CenterWidth() )
   hb_default( @y         , ::CenterHeight() )
   hb_default( @nWidth    , Min( ::Width(), ::Height() ) )
   hb_default( @cFontPitch, "TINY" )

   DO CASE
   CASE cFontPitch == "TINY"
      ::SetFontTiny()
   CASE cFontPitch == "SMALL"
      ::SetFontSmall()
   CASE cFontPitch == "MEDIUM"
      ::SetFontMediumBold()
   CASE cFontPitch == "LARGE"
      ::SetFontLarge()
   CASE cFontPitch == "GIANT"
      ::SetFontGiant()
   ENDCASE

   FOR EACH hElement IN aPieDataOfHash
      nTot += hElement[ "VALUE" ]

      IF ( nExtrude := __HGetValue( hElement, "EXTRUDE" ) ) != NIL
         nTotExtr := Max( nTotExtr, nExtrude )
      ENDIF
   NEXT

   nWidth -= ( nTotExtr + 2 )
      cLabel    := __HGetValue( hElement, "LABEL" )
      lFilled   := __HGetValue( hElement, "FILLED" )
      nExtrude  := __HGetValue( hElement, "EXTRUDE" )
      pTile     := __HGetValue( hElement, "TILE" )
      IF nExtrude != NIL
         lExtruded := .T.
      ELSE
         lExtruded := .F.
      ENDIF
      colorp    := __HGetValue( hElement, "COLOR" )
      nVal      := hElement[ "VALUE" ]
      nDim      := 360
         hFont := __HGetValue( hElement, "FONT" )
         IF hFont == NIL
            ::SetFontMediumBold()
            cFontName := NIL
            nPitch    := NIL
            nAngle    := NIL
            textcolor := NIL
         ELSE
            cFontName := __HGetValue( hFont, "NAME" )
            nPitch    := __HGetValue( hFont, "PITCH" )
            nAngle    := __HGetValue( hFont, "ANGLE" )
            textcolor := __HGetValue( hFont, "COLOR" )
            hb_default( @cFontName, "Arial" )
            hb_default( @nPitch   , 8 )
            hb_default( @nAngle   , 0 )
         ENDIF
         nPosX   := nPosX + ( ( nExtrude + nWidth ) / 4 )
   x          := __HGetValue( hDefs, "POSX" )
   y          := __HGetValue( hDefs, "POSY" )
   nWidth     := __HGetValue( hDefs, "WIDTH" )
   nHeight    := __HGetValue( hDefs, "HEIGHT" )
   nMaxValue  := __HGetValue( hDefs, "MAXVALUE" )
   color      := __HGetValue( hDefs, "COLOR" )
   lShowAxis  := __HGetValue( hDefs, "SHOWAXIS" )
   lShowGrid  := __HGetValue( hDefs, "SHOWGRID" )
   cAxisPict  := __HGetValue( hDefs, "AXISPICT" )
   cFontPitch := __HGetValue( hDefs, "FONTPITCH" )

   hb_default( @x         , 0 )
   hb_default( @y         , 0 )
   hb_default( @nWidth    , ::Width() )
   hb_default( @nHeight   , ::Height() )
   hb_default( @color     , ::GetColor() )
   hb_default( @lShowAxis , .T. )
   hb_default( @lShowGrid , .T. )
   hb_default( @cAxisPict , "@E 9,999.99" )
   hb_default( @cFontPitch, "TINY" )

   hb_default( @nBorder, 4 )

   DO CASE
   CASE cFontPitch == "TINY"
      ::SetFontTiny()
   CASE cFontPitch == "SMALL"
      ::SetFontSmall()
   CASE cFontPitch == "MEDIUM"
      ::SetFontMediumBold()
   CASE cFontPitch == "LARGE"
      ::SetFontLarge()
   CASE cFontPitch == "GIANT"
      ::SetFontGiant()
   ENDCASE

   nMaxLabel := 0
   nMax      := 0
   FOR EACH hElement IN aDataOfHash
      IF hElement:__enumIndex() == 1
         nMax := hElement[ "VALUE" ]
      ELSE
         nMax := Max( nMax, hElement[ "VALUE" ] )
      ENDIF
      cLabel    := __HGetValue( hElement, "LABEL" )
      nMaxLabel := Max( nMaxLabel, Len( iif( cLabel != NIL, cLabel, "" ) ) )
      nTot      += hElement[ "VALUE" ]
   NEXT

   IF ! HB_ISNUMERIC( nLeftLabelSpace )
      nLeftLabelSpace := nBorder + Len( LTrim( Transform( nMax, cAxisPict ) ) )
      cLabel    := __HGetValue( hElement, "LABEL" )
      lFilled   := __HGetValue( hElement, "FILLED" )

      pTile     := __HGetValue( hElement, "TILE" )

      colorp    := __HGetValue( hElement, "COLOR" )
      nVal      := hElement[ "VALUE" ]
      nDim      := ( nVal / nMaxValue )
   x          := __HGetValue( hDefs, "POSX" )
   y          := __HGetValue( hDefs, "POSY" )
   nWidth     := __HGetValue( hDefs, "WIDTH" )
   nHeight    := __HGetValue( hDefs, "HEIGHT" )
   nMaxValue  := __HGetValue( hDefs, "MAXVALUE" )
   color      := __HGetValue( hDefs, "COLOR" )
   lShowAxis  := __HGetValue( hDefs, "SHOWAXIS" )
   lShowGrid  := __HGetValue( hDefs, "SHOWGRID" )
   cAxisPict  := __HGetValue( hDefs, "AXISPICT" )
   cFontPitch := __HGetValue( hDefs, "FONTPITCH" )

   hb_default( @x         , 0 )
   hb_default( @y         , 0 )
   hb_default( @nWidth    , ::Width() )
   hb_default( @nHeight   , ::Height() )
   hb_default( @color     , ::GetColor() )
   hb_default( @lShowAxis , .T. )
   hb_default( @lShowGrid , .T. )
   hb_default( @cAxisPict , "@E 9,999.99" )
   hb_default( @cFontPitch, "TINY" )

   hb_default( @nBorder, 4 )

   DO CASE
   CASE cFontPitch == "TINY"
      ::SetFontTiny()
   CASE cFontPitch == "SMALL"
      ::SetFontSmall()
   CASE cFontPitch == "MEDIUM"
      ::SetFontMediumBold()
   CASE cFontPitch == "LARGE"
      ::SetFontLarge()
   CASE cFontPitch == "GIANT"
      ::SetFontGiant()
   ENDCASE

   nMaxLabel := 0
   nMax      := 0
   FOR EACH hElement IN aDataOfHash
      IF hElement:__enumIndex() == 1
         nMax := hElement[ "VALUE" ]
      ELSE
         nMax := Max( nMax, hElement[ "VALUE" ] )
      ENDIF
      cLabel    := __HGetValue( hElement, "LABEL" )
      nMaxLabel := Max( nMaxLabel, Len( iif( cLabel != NIL, cLabel, "" ) ) )
      nTot      += hElement[ "VALUE" ]
   NEXT

   IF ! HB_ISNUMERIC( nLeftLabelSpace )
      nLeftLabelSpace := nBorder + nMaxLabel
      cLabel    := __HGetValue( hElement, "LABEL" )
      lFilled   := __HGetValue( hElement, "FILLED" )

      pTile     := __HGetValue( hElement, "TILE" )

      colorp    := __HGetValue( hElement, "COLOR" )
      nVal      := hElement[ "VALUE" ]
      nDim      := ( nVal / nMaxValue )
   x          := __HGetValue( hDefs, "POSX" )
   y          := __HGetValue( hDefs, "POSY" )
   nWidth     := __HGetValue( hDefs, "WIDTH" )
   nHeight    := __HGetValue( hDefs, "HEIGHT" )
   nMaxValue  := __HGetValue( hDefs, "MAXVALUE" )
   nMinValue  := __HGetValue( hDefs, "MINVALUE" )
   colorp     := __HGetValue( hDefs, "COLOR" )


[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 extra library: extras/hbxlsxml/tests/example.prg. Contains procedures: Main. This file provides spreadsheet generation capabilities

[Assistant]
#require "hbxlsxml"

PROCEDURE Main()

   LOCAL oXml, oSheet, xarquivo := "example.xml"
   LOCAL i, xqtddoc, xttotnot, xtbascal, xtvlricm, xtbasipi, xtvlripi, aDoc, nLinha
   LOCAL xEmpresa
   LOCAL xDataImp
   LOCAL xTitulo
   LOCAL xPeriodo
   LOCAL xOrdem
   LOCAL oObj

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

   oXml := ExcelWriterXML():New( xarquivo )
   oXml:setOverwriteFile( .T. )

   oObj := oXml:addStyle( "textLeft" )
   oObj:alignHorizontal( "Left" )
   oObj:alignVertical( "Center" )
   oObj:fontSize( 10 )

   oObj := oXml:addStyle( "textLeftWrap" )
   oObj:alignHorizontal( "Left" )
   oObj:alignVertical( "Center" )
   oObj:alignWraptext()
   oObj:fontSize( 10 )

   oObj := oXml:addStyle( "textLeftBold" )
   oObj:alignHorizontal( "Left" )
   oObj:alignVertical( "Center" )
   oObj:fontSize( 10 )
   oObj:setFontBold()

   oObj := oXml:addStyle( "textLeftBoldCor" )
   oObj:alignHorizontal( "Left" )
   oObj:alignVertical( "Center" )
   oObj:fontSize( 10 )
   oObj:setFontBold()
   oObj:bgColor( "lightblue" )
   oObj:alignWraptext()

   oObj := oXml:addStyle( "textRight" )
   oObj:alignHorizontal( "Right" )
   oObj:alignVertical( "Center" )
   oObj:fontSize( 10 )

   oObj := oXml:addStyle( "textRightBold" )
   oObj:alignHorizontal( "Right" )
   oObj:alignVertical( "Center" )
   oObj:fontSize( 10 )
   oObj:setFontBold()

   oObj := oXml:addStyle( "textRightBoldCor" )
   oObj:alignHorizontal( "Right" )
   oObj:alignVertical( "Center" )
   oObj:fontSize( 10 )
   oObj:setFontBold()
   oObj:bgColor( "lightblue" )
   oObj:alignWraptext()

   oObj := oXml:addStyle( "numberRight" )
   oObj:alignHorizontal( "Right" )
   oObj:alignVertical( "Center" )
   oObj:setNumberFormat( "#,##0.00" )
   oObj:fontSize( 10 )

   oObj := oXml:addStyle( "numberRightBold" )
   oObj:alignHorizontal( "Right" )
   oObj:alignVertical( "Center" )
   oObj:setNumberFormat( "#,##0.00" )
   oObj:fontSize( 10 )
   oObj:setFontBold()

   oObj := oXml:addStyle( "numberRightBoldCor" )
   oObj:alignHorizontal( "Right" )
   oObj:alignVertical( "Center" )
   oObj:setNumberFormat( "#,##0.00" )
   oObj:fontSize( 10 )
   oObj:setFontBold()
   oObj:bgColor( "lightblue" )

   oObj := oXml:addStyle( "numberRightZero" )
   oObj:alignHorizontal( "Right" )
   oObj:alignVertical( "Center" )
   oObj:setNumberFormat( "#,##0.00;[Red]-#,##0.00;;@" )
   oObj:fontSize( 10 )
   oObj:setFontBold()

   oObj := oXml:addStyle( "Cabec" )
   oObj:alignHorizontal( "Left" )
   oObj:alignVertical( "Center" )
   oObj:fontSize( 12 )
   oObj:setFontBold()

   oObj := oXml:addStyle( "CabecRight" )
   oObj:alignHorizontal( "Right" )
   oObj:alignVertical( "Center" )
   oObj:fontSize( 12 )
   oObj:setFontBold()

   oSheet := oXml:addSheet( "Plan1" )

   oObj := oSheet
   oObj:columnWidth(  1,  70 )
   oObj:columnWidth(  2,  20 )
   oObj:columnWidth(  3,  70 )
   oObj:columnWidth(  4,  70 )
   oObj:columnWidth(  5,  50 )
   oObj:columnWidth(  6,  50 )
   oObj:columnWidth(  7, 300 )
   oObj:columnWidth(  8,  20 )
   oObj:columnWidth(  9,  80 )
   oObj:columnWidth( 10,  80 )
   oObj:columnWidth( 11,  80 )
   oObj:columnWidth( 12,  80 )
   oObj:columnWidth( 13,  80 )

   xEmpresa := "EMPRESA DEMONSTRACAO LTDA"
   xDataImp := "2011-03-22"
   xTitulo := "RELATORIO PARA DEMONSTRAR XML EXCEL"
   xPeriodo := "2011-02-01 a 2011-02-28"
   xOrdem  := "DATA DE EMISSAO"

   nLinha := 0

   oObj:writeString( ++nLinha, 1, xEmpresa , "Cabec" )
   oObj:cellMerge(     nLinha, 1, 5, 0 )
   oObj:writeString(   nLinha, 12, "Data:" + xDataImp , "CabecRight" )
   oObj:cellMerge(     nLinha, 12, 1, 0 )
   oObj:writeString( ++nLinha, 1, xTitulo  , "Cabec" )
   oObj:cellMerge(     nLinha, 1, 5, 0 )
   oObj:writeString( ++nLinha, 1, xPeriodo , "Cabec" )
   oObj:cellMerge(     nLinha, 1, 5, 0 )
   oObj:writeString( ++nLinha, 1, xOrdem   , "Cabec" )
   oObj:cellMerge(     nLinha, 1, 5, 0 )

   oObj := oSheet
   oObj:writeString( ++nLinha,  1, "N.Fiscal"          , "textLeftBoldCor" )
   oObj:writeString(   nLinha,  2, "TM"                , "textLeftBoldCor" )
   oObj:writeString(   nLinha,  3, "Data Movto"        , "textLeftBoldCor" )
   oObj:writeString(   nLinha,  4, "Data Emis."        , "textLeftBoldCor" )
   oObj:writeString(   nLinha,  5, "CFOP"              , "textLeftBoldCor" )
   oObj:writeString(   nLinha,  6, "Codigo"            , "textLeftBoldCor" )
   oObj:writeString(   nLinha,  7, "Cliente/Fornecedor", "textLeftBoldCor" )
   oObj:writeString(   nLinha,  8, "UF"                , "textLeftBoldCor" )
   oObj:writeString(   nLinha,  9, "Vlr.Tot."          , "textRightBoldCor" )
   oObj:writeString(   nLinha, 10, "Base Calc."        , "textRightBoldCor" )
   oObj:writeString(   nLinha, 11, "Vlr ICMS"          , "textRightBoldCor" )
   oObj:writeString(   nLinha, 12, "Base IPI"          , "textRightBoldCor" )
   oObj:writeString(   nLinha, 13, "Valor IPI"         , "textRightBoldCor" )

   aDoc := {}
   FOR i := 1 TO 40
      AAdd( aDoc, ;
         { StrZero( i, 8 ), ;
         "VE", ;
         Date() - 49 - i, ;
         Date() - 50 - i, ;
         "5.102", ;
         StrZero( i, 5 ), ;
         "NOME DO CLIENTE TESTE " + hb_ntos( i ), ;
         "PR", ;
         i
      oObj:writeString( ++nLinha, 1, aDoc[ i, 1 ], "textLeft" )
      oObj:writeString( nLinha, 2, aDoc[ i, 2 ], "textLeft" )
      oObj:writeString( nLinha, 3, DToC( aDoc[ i, 3 ] ), "textLeft" )
      oObj:writeString( nLinha, 4, DToC( aDoc[ i, 4 ] ), "textLeft" )
      oObj:writeString( nLinha, 5, aDoc[ i, 5 ], "textLeft" )
      oObj:writeString( nLinha, 6, aDoc[ i, 6 ], "textLeft" )
      oObj:writeString( nLinha, 7, aDoc[ i, 7 ], "textLeft" )
      oObj:writeString( nLinha, 8, aDoc[ i, 8 ], "textLeft" )
      oObj:writeNumber( nLinha, 9, aDoc[ i, 9 ], "numberRight" )
      oObj:writeNumber( nLinha, 10, aDoc[ i, 10 ], "numberRight" )
      oObj:writeNumber( nLinha, 11, aDoc[ i, 11 ], "numberRight" )
      oObj:writeNumber( nLinha, 12, aDoc[ i, 12 ], "numberRight" )
      oObj:writeNumber( nLinha, 13, aDoc[ i, 13 ], "numberRight" )

      xqtddoc++
      xttotnot += aDoc[ i, 9 ]
      xtbascal += aDoc[ i, 10 ]
      xtvlricm += aDoc[ i, 11 ]
      xtbasipi += aDoc[ i, 12 ]
      xtvlripi += aDoc[ i, 13 ]
   NEXT

   oObj := oSheet
   oObj:writeString( ++nLinha,  1, "", "textLeft" )
   oObj:writeString(   nLinha,  2, "", "textLeft" )
   oObj:writeString(   nLinha,  3, "", "textLeft" )
   oObj:writeString(   nLinha,  4, "", "textLeft" )
   oObj:writeString(   nLinha,  5, "", "textLeft" )
   oObj:writeString(   nLinha,  6, "", "textLeft" )
   oObj:writeString(   nLinha,  7, "TOTAL ==> " + hb_ntos( xqtddoc ) + " document(s)", "textLeftBold" )
   oObj:writeString(   nLinha,  8, "", "textLeft" )
   oObj:writeFormula( "Number", nLinha, 9, "=SUM(R[-40]C:R[-1]C)", "numberRightBold" )
   oObj:writeNumber(   nLinha, 10, xtbascal, "numberRightBold" )
   oObj:writeNumber(   nLinha, 11, xtvlricm, "numberRightBold" )
   oObj:writeNumber(   nLinha, 12, xtbasipi, "numberRightBold" )
   oObj:writeNumber(   nLinha, 13, xtvlripi, "numberRightBold" )

   oXml:writeData( xarquivo )

   RETURN


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

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

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

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

PROCEDURE Main()

   LOCAL ni, cStr

   ctinit()

   ? "Begin test of CharNot()"
   ?

   ? "Simple tests:"

   ? '  CharNot( hb_BChar(  85 ) + hb_BChar( 128 ) + hb_BChar( 170 ) + hb_BChar(   1 ) ) =='
   ? '           hb_BChar( 170 ) + hb_BChar( 127 ) + hb_BChar(  85 ) + hb_BChar( 254 ) ? -->'

   ? '          '
   cStr := CharNot( hb_BChar( 85 ) + hb_BChar( 128 ) + hb_BChar( 170 ) + hb_BChar( 1 ) )
   FOR ni := 1 TO Len( cStr )
      ?? "hb_BChar( " + hb_ntos( Asc( SubStr( cStr, ni, 1 ) ) ) + " )"
      IF ni < Len( cStr )
         ?? " + "
      ENDIF
   NEXT
   ?

   ? '  CharNot( CharNot( "This is a test!" ) ) == "This is a test!" ?'
   ? '  --> "' + CharNot( CharNot( "This is a test!" ) ) + '"'
   ?

   ? "End test of CharNot()"
   ?

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

[Assistant]
#ifdef __XHARBOUR__
   #xtranslate hb_threadStart( <x,...> ) => StartThread( <x> )
   #xtranslate hb_threadJoin( <x,...> ) => JoinThread( <x> )
   #command begin sequence   => try
   #command always           => finally
#endif

proc main()
   local thID, i
   ? Version()
   ? "Main start"
   thID := hb_threadStart( @thFunc(), "A", "B", "C" )
   ? "Thread ID:", thID
   ? "==================="
   ?
   begin sequence
      for i := 1 to 10
         ?? "M"
         hb_idleSleep( 0.050 )
      next
      ? "==================="
      ? "Main QUIT"
      quit
   always
      ? "Main ALWAYS section"
      ?
   endsequence
   ? "End of main"
return

proc thFunc( ... )
   local i
   ? "Thread begin"
   ? "Parameters:"
   aeval( hb_aParams(), {| x | qqout( "", x ) } )
   ?
   begin sequence
      for i := 1 to 10
         ?? "t"
         hb_idleSleep( 0.030 )
         if i == 5
            ? "Thread QUIT"
            quit
         endif
      next
   always
      ? "Thread ALWAYS section"
      ?
   endsequence
   ? "Thread end"
   ?
return

exit proc p
? "I'm EXIT procedure"


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

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

Harbour header file: include/hbextlng.ch. Defines constants: HB_EXTLNG_CH_, __HBEXTERN__HBLANG__REQUEST. Defines Harbour internal constants and macros

[Assistant]
#ifndef HB_EXTLNG_CH_
#define HB_EXTLNG_CH_

#define __HBEXTERN__HBLANG__REQUEST
#include "hblang.hbx"

#endif


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

[User] Generate Harbour code for: Harbour test program: tests/for2.prg. Contains procedures: Main. This test file exercises basic Harbour language features

[Assistant]
PROCEDURE Main()

   LOCAL i

   FOR i := 1 TO 10

      ? i

      IF i == 4 .AND. .T.
         Inkey( 0 )
         ? i
         i := 9
         ? i
         Inkey( 0 )
      ENDIF

   NEXT

   RETURN


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

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

Harbour extra library: extras/hbxlsxml/xlsxml_y.prg. Defines classes: ExcelWriterXML_Style. This file provides spreadsheet generation capabilities

[Assistant]
#include "hbclass.ch"

CREATE CLASS ExcelWriterXML_Style

   VAR    id
   VAR    name
   VAR    useAlignment                            INIT .F.
   VAR    useFont                                 INIT .F.
   VAR    useBorder                               INIT .F.
   VAR    useInterior                             INIT .F.

   VAR    valign
   VAR    halign
   VAR    rotate
   VAR    shrinktofit                             INIT 0
   VAR    verticaltext                            INIT 0
   VAR    wraptext                                INIT 0

   VAR    fontColor                               INIT "Automatic"
   VAR    fontName
   VAR    fontFamily
   VAR    fontSize
   VAR    bold
   VAR    italic
   VAR    underline
   VAR    strikethrough
   VAR    shadow
   VAR    outline

   VAR    borderTop                               INIT { => }
   VAR    borderBottom                            INIT { => }
   VAR    borderLeft                              INIT { => }
   VAR    borderRight                             INIT { => }
   VAR    borderDL                                INIT { => }
   VAR    borderDR                                INIT { => }

   VAR    interiorColor
   VAR    interiorPattern
   VAR    interiorPatternColor

   VAR    numberFormat

   VAR    formatErrors                            INIT { => }
   VAR    namedColorsIE                           INIT { => }

   METHOD new( id )
   METHOD getID()
   METHOD getStyleXML()
   METHOD checkColor( color )
   METHOD setName( name )
   METHOD alignVertical( valign )
   METHOD alignHorizontal( halign )
   METHOD alignRotate( rotate )
   METHOD alignShrinktofit()
   METHOD alignVerticaltext()
   METHOD alignWraptext()
   METHOD setFontSize( fontSize )
   METHOD setFontColor( fontColor )
   METHOD setFontName( fontName )
   METHOD setFontFamily( fontFamily )
   METHOD setFontBold()
   METHOD setFontItalic()
   METHOD setFontStrikethrough()
   METHOD setFontUnderline( uStyle )
   METHOD setFontShadow()
   METHOD setFontOutline()
   METHOD border( position, weight, color, linestyle )
   METHOD bgColor( color, pattern, patternColor )
   METHOD bgPattern( pattern, color )
   METHOD bgPatternColor( color )
   METHOD setNumberFormat( formatString )
   METHOD setNumberFormatDate()
   METHOD setNumberFormatTime()
   METHOD setNumberFormatDatetime()

ENDCLASS

METHOD ExcelWriterXML_Style:New( id )

   ::id := id
   ::namedColorsIE := getColorIE()

   RETURN SELF

METHOD ExcelWriterXML_Style:getID()

   RETURN ::id

METHOD ExcelWriterXML_Style:getStyleXML()

   LOCAL fontcolor, positions, position, auxdata, pData, bLinestyle, bColor, bWeight, xml
   LOCAL numberFormat

   LOCAL name                 := ""
   LOCAL valign               := ""
   LOCAL halign               := ""
   LOCAL rotate               := ""
   LOCAL shrinktofit          := ""
   LOCAL verticaltext         := ""
   LOCAL wraptext             := ""

   LOCAL bold                 := ""
   LOCAL italic               := ""
   LOCAL strikethrough        := ""
   LOCAL underline            := ""
   LOCAL outline              := ""
   LOCAL shadow               := ""
   LOCAL fontName             := ""
   LOCAL fontFamily           := ""
   LOCAL fontSize             := ""

   LOCAL borders              := ""

   LOCAL interior             := ""
   LOCAL interiorColor        := ""
   LOCAL interiorPattern      := ""
   LOCAL interiorPatternColor := ""

   IF ! Empty( ::name )
      name := 'ss:Name="' + ::name + '"'
   ENDIF

   IF ::useAlignment
      IF ! Empty( ::valign )
         valign := 'ss:Vertical="' + ::valign + '"'
      ENDIF
      IF ! Empty( ::halign )
         halign := 'ss:Horizontal="' + ::halign + '"'
      ENDIF
      IF ! Empty( ::rotate )
         rotate := 'ss:Rotate="' + ::rotate + '"'
      ENDIF
      IF ! Empty( ::shrinktofit )
         shrinktofit := 'ss:ShrinkToFit="1"'
      ENDIF
      IF ! Empty( ::verticaltext )
         verticaltext := 'ss:VerticalText="1"'
      ENDIF
      IF ! Empty( ::wraptext )
         wraptext := 'ss:WrapText="1"'
      ENDIF
   ENDIF

   IF ::useFont
      IF ! Empty( ::fontColor )
         fontColor := 'ss:Color="' + ::fontColor + '"'
      ENDIF
      IF ! Empty( ::bold )
         bold := 'ss:Bold="1"'
      ENDIF
      IF ! Empty( ::italic )
         italic := 'ss:Italic="1"'
      ENDIF
      IF ! Empty( ::strikethrough )
         strikethrough := 'ss:StrikeThrough="' + ::strikethrough + '"'
      ENDIF
      IF ! Empty( ::underline )
         underline := 'ss:Underline="' + ::underline + '"'
      ENDIF
      IF ! Empty( ::outline )
         outline := 'ss:Outline="1"'
      ENDIF
      IF ! Empty( ::shadow )
         shadow := 'ss:Shadow="1"'
      ENDIF
      IF ! Empty( ::fontName )
         fontName := 'ss:FontName="' + ::fontName + '"'
      ENDIF
      IF ! Empty( ::fontFamily )
         fontFamily := 'x:Family="' + ::fontFamily + '"'
      ENDIF
      IF ! Empty( ::fontSize )
         fontSize := 'ss:Size="' + hb_ntos( ::fontSize ) + '"'
      ENDIF
   ENDIF

   IF ::useBorder
      borders := "      <Borders>" + hb_eol()
      positions := { ;
         "Top"           => ::borderTop,    ;
         "Bottom"        => ::borderBottom, ;
         "Left"          => ::borderLeft,   ;
         "Right"         => ::borderRight,  ;
         "DiagonalLeft"  => ::borderDL,     ;
         "DiagonalRight" => ::borderDR      }
      auxdata := NIL
      FOR EACH auxdata IN positions
         position := auxdata:Key
         pData    := auxdata:Value
         IF Empty( pData )
            LOOP
         ENDIF
         bLinestyle := iif( hb_HPos( pData, "LineStyle" ) > 0, ;
            'ss:LineStyle="' + pData[ "LineStyle" ] + '"', ;
            "" )
         bColor := iif( hb_HPos( pData, "Color" ) > 0, ;
            'ss:Color="' + pData[ "Color" ] + '"', ;
            "" )
         bWeight := iif( hb_HPos( pData, "Weight" ) > 0, ;
            'ss:Weight="' + hb_ntos( pData[ "Weight" ] ) + '"', ;
            "" )
         borders += '<Border ss:Position="' + AllTrim( position + '" ' + bLinestyle + " " + bColor + " " + bWeight ) + "/>" + hb_eol()
      NEXT
      borders += "</Borders>" + hb_eol()
   ENDIF

   IF ::useInterior
      IF ! Empty( ::interiorColor )
         interiorColor := 'ss:Color="' + ::interiorColor + '"'
      ENDIF
      IF ! Empty( ::interiorPattern )
         interiorPattern := 'ss:Pattern="' + ::interiorPattern + '"'
      ENDIF
      IF ! Empty( ::interiorPatternColor )
         interiorPatternColor := 'ss:PatternColor="' + ::interiorPatternColor + '"'
      ENDIF
      interior := "      <Interior " + AllTrim( interiorColor + " " + interiorPattern + " " + interiorPatternColor ) + "/>" + hb_eol()
   ENDIF

   IF Empty( ::numberFormat )
      numberFormat := "      <NumberFormat/>" + hb_eol()
   ELSE
      numberFormat := '      <NumberFormat ss:Format="' + ::numberFormat + '"/>' + hb_eol()
   ENDIF

   xml := '   <Style ss:ID="' + ::id + '" ' + name + ">" + hb_eol()
   IF ::useAlignment
      xml += "      <Alignment " + AllTrim( valign + " " + halign + " " + rotate + " " + shrinktofit + " " + wraptext + " " + verticaltext ) + "/>" + hb_eol()
   ENDIF
   IF ::useBorder
      xml += borders
   ENDIF
   IF ::useFont
      xml += "      <Font " + AllTrim( fontSize + " " + fontColor + " " + bold + " " + italic + " " + strikethrough + " " + underline + " " + shadow + " " + outline + " " + fontName + " " + fontFamily ) + "/>" + hb_eol()
   ENDIF
   IF ::useInterior
      xml += interior
   ENDIF
   xml += numberFormat
   xml += "      <Protection/>" + hb_eol()
   xml += "   </Style>" + hb_eol()

   RETURN xml

METHOD ExcelWriterXML_Style:checkColor( color )

   IF Left( color, 1 ) == "#"
      RETURN COLOR
   ELSEIF hb_HPos( ::namedColorsIE, Lower( color ) ) > 0
      color := ::namedColorsIE[ Lower( color ) ]
      RETURN COLOR
   ELSE
      RETURN ""
   ENDIF

   RETURN NIL

METHOD ExcelWriterXML_Style:setName( name )

   ::name := name

   RETURN NIL


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

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

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

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

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

PROCEDURE Main()

   LOCAL aWin := Array( 9 ), y, x, i, k, lFlag := .F., lBoard := .T.

   SetBlink( .F. )
   WBoard( 5, 5, 20, 75 )
   WMode( .T., .T., .T., .T. )
   WSetShadow( 7 )
   SetClearA( 10
   DispBox( 0, 0, MaxRow(), MaxCol(), Replicate( "#", 9 ), NToColor( 10
   ? "GT driver: " + hb_gtVersion()
   ? hb_gtVersion( 1 )
   ?
   ? "ESC - quit "
   ? "0 - select window 0 (base screen) "
   ? "1-9 select window 1-9 "
   ? "C - close window "
   ? "Q - clear screen "
   ? "P - print text at window 0 "
   ? "B - board switch "
   ? "INS - cursor shape "
   ? "DEL - hide cursor "
   ? "arrows - window move "

   SetClearB( 61 )
   FOR i := 1 TO Len( aWin )
      y := i + 2
      x := i
      SetColor( NToColor( i * 16 + 15 ) + ",W+/B*" )
      WSetShadow( i % 8 )
      aWin[ i ] := WOpen( y, x, y + 10, x + 20 )
      WBox()

      @ -1, 0 SAY "TITLE " + hb_ntos( aWin[ i ] )
      ? hb_ntos( Row() ) + ":" + hb_ntos( Col() ), "/", hb_ntos( MaxRow() ) + ":" + hb_ntos( MaxCol() ), ""
      ? hb_ntos( WRow() ) + ":" + hb_ntos( WCol() ), "/", hb_ntos( MaxRow( .T. ) ) + ":" + hb_ntos( MaxCol( .T. ) ), ""
      ? hb_ntos( WFRow() ) + ":" + hb_ntos( WFCol() ), "/", ;
         hb_ntos( WFLastRow() ) + ":" + hb_ntos( WFLastCol() ), ""
      ? hb_ntos( WFRow( .T. ) ) + ":" + hb_ntos( WFCol( .T. ) ), "/", ;
         hb_ntos( WFLastRow( .T. ) ) + ":" + hb_ntos( WFLastCol( .T. ) ), ""
      ? "window:", hb_ntos( aWin[ i ] ), ""
      SetCursor( Int( i % 5 ) )

   NEXT

   dspcord()
   WHILE .T.
      k := Inkey( 0, INKEY_ALL )
      IF k == K_ESC
         EXIT
      ELSEIF k >= hb_keyCode( "1" ) .AND. k <= hb_keyCode( "9" )
         WSelect( aWin[ k - hb_keyCode( "0" ) ] )
      ELSEIF k == hb_keyCode( "0" )
         WSelect( 0 )
      ELSEIF k == hb_keyCode( "C" ) .OR. k == hb_keyCode( "c" )
         WClose()
      ELSEIF k == hb_keyCode( "Q" ) .OR. k == hb_keyCode( "q" )
         CLS
      ELSEIF k == hb_keyCode( "B" ) .OR. k == hb_keyCode( "b" )
         IF lBoard
            WBoard( 0, 0, MaxRow( .T. ) - 1, MaxCol( .T. ) )
         ELSE
            WBoard( 5, 5, 20, 75 )
         ENDIF
         lBoard := ! lBoard
      ELSEIF k == hb_keyCode( "P" ) .OR. k == hb_keyCode( "P" )
         y := WFRow()
         x := WFCol()
         i := WSelect()
         WSelect( 0 )
         @ y, x SAY "THIS IS WINDOW 0 OUTPUT"
         WSelect( i )
      ELSEIF k == K_INS
         lFlag := ! lFlag
         SetCursor( iif( lFlag, 3, 1 ) )
      ELSEIF k == K_DEL
         SetCursor( SC_NONE )
      ELSEIF k == K_LEFT
         WMove( WRow(), WCol() - 1 )
      ELSEIF k == K_RIGHT
         WMove( WRow(), WCol() + 1 )
      ELSEIF k == K_UP
         WMove( WRow() - 1, WCol() )
      ELSEIF k == K_DOWN
         WMove( WRow() + 1, WCol() )
      ENDIF
      dspcord()
   ENDDO

   RETURN

STATIC PROCEDURE dspcord()

   LOCAL mr := MRow(), mc := MCol(), r := WRow(), c := WCol(), w := WSelect()

   WSelect( 0 )
   @ MaxRow(), 0 SAY PadR( "WPOS(" + hb_ntos( r ) + "," + hb_ntos( c ) + ")" + ;
      iif( MPresent(), "MPOS(" + hb_ntos( mr ) + "," + hb_ntos( mc ) + ")", "" ), MaxCol() + 1 )
   WSelect( w )

   RETURN


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

[User] Implement this Harbour module: Harbour header file: include/inkey.ch. Defines 10 constants including: HB_INKEY_CH_, INKEY_MOVE, INKEY_LDOWN, INKEY_LUP, INKEY_RDOWN. Defines keyboard input constants

[Assistant]
#ifndef HB_INKEY_CH_
#define HB_INKEY_CH_

#define INKEY_MOVE              1
#define INKEY_LDOWN             2
#define INKEY_LUP               4
#define INKEY_RDOWN             8
#define INKEY_RUP               16
#define INKEY_MMIDDLE           32
#define INKEY_MWHEEL            64
#define INKEY_KEYBOARD          128
#define INKEY_ALL               ( INKEY_KEYBOARD + INKEY_MOVE + INKEY_LDOWN + INKEY_LUP + INKEY_RDOWN + INKEY_RUP + INKEY_MMIDDLE + INKEY_MWHEEL )

#define HB_INKEY_RAW            256
#define HB_INKEY_GTEVENT        1024
#define HB_INKEY_EXT            2048

#define HB_INKEY_ALL            ( INKEY_ALL + HB_INKEY_GTEVENT )

#define K_MOUSEMOVE             1001
#define K_LBUTTONDOWN           1002
#define K_LBUTTONUP             1003
#define K_RBUTTONDOWN           1004
#define K_RBUTTONUP             1005
#define K_LDBLCLK               1006
#define K_RDBLCLK               1007
#define K_MBUTTONDOWN           1008
#define K_MBUTTONUP             1009
#define K_MDBLCLK               1010
#define K_MMLEFTDOWN            1011
#define K_MMRIGHTDOWN           1012
#define K_MMMIDDLEDOWN          1013
#define K_MWFORWARD             1014
#define K_MWBACKWARD            1015
#define K_NCMOUSEMOVE           1016
#define K_MWLEFT                1017
#define K_MWRIGHT               1018

#define K_MINMOUSE              1001
#define K_MAXMOUSE              1016

#define HB_K_RESIZE             1101
#define HB_K_CLOSE              1102
#define HB_K_GOTFOCUS           1103
#define HB_K_LOSTFOCUS          1104
#define HB_K_CONNECT            1105
#define HB_K_DISCONNECT         1106
#define HB_K_TERMINATE          1107
#define HB_K_MENU               1108

#define K_UP                    5
#define K_DOWN                  24
#define K_LEFT                  19
#define K_RIGHT                 4
#define K_HOME                  1
#define K_END                   6
#define K_PGUP                  18
#define K_PGDN                  3

#define K_CTRL_UP               397
#define K_CTRL_DOWN             401
#define K_CTRL_LEFT             26
#define K_CTRL_RIGHT            2
#define K_CTRL_HOME             29
#define K_CTRL_END              23
#define K_CTRL_PGUP             31
#define K_CTRL_PGDN             30

#define K_ALT_UP                408
#define K_ALT_DOWN              416
#define K_ALT_LEFT              411
#define K_ALT_RIGHT             413
#define K_ALT_HOME              407
#define K_ALT_END               415
#define K_ALT_PGUP              409
#define K_ALT_PGDN              417

#define K_ENTER                 13
#define K_INTRO                 13
#define K_RETURN                13
#define K_SPACE                 32
#define K_ESC                   27

#define K_CTRL_ENTER            10
#define K_CTRL_RETURN           10
#define K_CTRL_RET              10
#define K_CTRL_PRTSCR           379
#define K_CTRL_QUESTION         309

#define K_ALT_ENTER             284
#define K_ALT_RETURN            284
#define K_ALT_ESC               257

#define KP_CENTER               332

#define KP_ALT_ENTER            422

#define KP_CTRL_5               399
#define KP_CTRL_SLASH           405
#define KP_CTRL_ASTERISK        406
#define KP_CTRL_MINUS           398
#define KP_CTRL_PLUS            400

#define KP_ALT_5                5
#define KP_ALT_SLASH            420
#define KP_ALT_ASTERISK         311
#define KP_ALT_MINUS            330
#define KP_ALT_PLUS             334

#define K_INS                   22
#define K_DEL                   7
#define K_BS                    8
#define K_TAB                   9
#define K_SH_TAB                271

#define K_CTRL_INS              402
#define K_CTRL_DEL              403
#define K_CTRL_BS               127
#define K_CTRL_TAB              404

#define K_ALT_INS               418
#define K_ALT_DEL               419
#define K_ALT_BS                270
#define K_ALT_TAB               421

#define K_CTRL_SH_TAB           423
#define K_SH_BS                 423

#define K_CTRL_A                1
#define K_CTRL_B                2
#define K_CTRL_C                3
#define K_CTRL_D                4
#define K_CTRL_E                5
#define K_CTRL_F                6
#define K_CTRL_G                7
#define K_CTRL_H                8
#define K_CTRL_I                9
#define K_CTRL_J                10
#define K_CTRL_K                11
#define K_CTRL_L                12
#define K_CTRL_M                13
#define K_CTRL_N                14
#define K_CTRL_O                15
#define K_CTRL_P                16
#define K_CTRL_Q                17
#define K_CTRL_R                18
#define K_CTRL_S                19
#define K_CTRL_T                20
#define K_CTRL_U                21
#define K_CTRL_V                22
#define K_CTRL_W                23
#define K_CTRL_X                24
#define K_CTRL_Y                25
#define K_CTRL_Z                26

#define K_ALT_A                 286
#define K_ALT_B                 304
#define K_ALT_C                 302
#define K_ALT_D                 288
#define K_ALT_E                 274
#define K_ALT_F                 289
#define K_ALT_G                 290
#define K_ALT_H                 291
#define K_ALT_I                 279
#define K_ALT_J                 292
#define K_ALT_K                 293
#define K_ALT_L                 294
#define K_ALT_M                 306
#define K_ALT_N                 305
#define K_ALT_O                 280
#define K_ALT_P                 281
#define K_ALT_Q                 272
#define K_ALT_R                 275
#define K_ALT_S                 287
#define K_ALT_T                 276
#define K_ALT_U                 278
#define K_ALT_V                 303
#define K_ALT_W                 273
#define K_ALT_X                 301
#define K_ALT_Y                 277
#define K_ALT_Z                 300
#define K_ALT_BACKQUOTE         297
#define K_ALT_1                 376
#define K_ALT_2                 377
#define K_ALT_3                 378
#define K_ALT_4                 379
#define K_ALT_5                 380
#define K_ALT_6                 381
#define K_ALT_7                 382
#define K_ALT_8                 383
#define K_ALT_9                 384
#define K_ALT_0                 385
#define K_ALT_MINUS             386
#define K_ALT_EQUALS            387
#define K_ALT_OSB               282
#define K_ALT_CSB               283
#define K_ALT_BACKSLASH         299
#define K_ALT_SC                295
#define K_ALT_QUOTE             296
#define K_ALT_COMMA             307
#define K_ALT_PERIOD            308
#define K_ALT_SLASH             309

#define K_F1                    28
#define K_F2                    -1
#define K_F3                    -2
#define K_F4                    -3
#define K_F5                    -4
#define K_F6                    -5
#define K_F7                    -6
#define K_F8                    -7
#define K_F9                    -8
#define K_F10                   -9
#define K_F11                   -40
#define K_F12                   -41

#define K_CTRL_F1               -20
#define K_CTRL_F2               -21
#define K_CTRL_F3               -22
#define K_CTRL_F4               -23
#define K_CTRL_F5               -24
#define K_CTRL_F6               -25
#define K_CTRL_F7               -26
#define K_CTRL_F8               -27
#define K_CTRL_F9               -28
#define K_CTRL_F10              -29
#define K_CTRL_F11              -44


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

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

#if ! defined( __HBSCRIPT__HBSHELL )
REQUEST __HBEXTERN__HBSSL__
#endif

PROCEDURE Main()

   LOCAL cURL := iif( tip_SSL(), "https", "http" ) + ":
   LOCAL oHTTP := TIPClientHTTP():New( cURL )
   LOCAL cHtml, oNode, oDoc

   ? "URL:", cURL

   oHTTP:oURL:addGetForm( { ;
      "q"  => "Harbour+Project", ;
      "kl" => "us-en" } )

   IF ! oHTTP:Open()
      ? "Connection error:", oHTTP:lastErrorMessage()
      RETURN
   ENDIF

   cHtml := oHTTP:ReadAll()
   oHTTP:Close()
   ? hb_ntos( Len( cHtml ) ), "bytes received"
   ?

   oDoc := THtmlDocument():New( cHtml )

   oDoc:writeFile( "result.htm" )

   FOR EACH oNode IN oDoc:body:div( "links" ):aS
      IF oNode:class == "large"
         ? tip_HtmlToStr( oNode:getText( "" ) ), oNode:href
      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] Create Harbour OOP classes for the functionality described: Harbour contribution module 'gtwvg' (): contrib/gtwvg/bitmap.prg. Defines classes: WvgBitmap. 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 WvgBitmap

   VAR    bits                                  INIT 0 READONLY
   VAR    bufferOffset                          INIT 0 READONLY
   VAR    planes                                INIT 0 READONLY
   VAR    transparentClr                        INIT 0
   VAR    xSize                                 INIT 0 READONLY
   VAR    ySize                                 INIT 0 READONLY

   VAR    hBitmap
   VAR    hDCcompat
   VAR    lDCToDestroy                          INIT .F.

   METHOD new()
   METHOD create( oPScompat )
   METHOD configure()                           VIRTUAL
   METHOD destroy()

   METHOD draw()                                VIRTUAL
   METHOD getColorTable()                       VIRTUAL
   METHOD getDefaultBGColor()                   VIRTUAL
   METHOD load()                                VIRTUAL
   METHOD loadFile()                            VIRTUAL
   METHOD make()                                VIRTUAL
   METHOD presSpace()                           VIRTUAL
   METHOD saveFile()                            VIRTUAL
   METHOD setBuffer()                           VIRTUAL
   METHOD getPicture()                          VIRTUAL
   METHOD setPicture()                          VIRTUAL

ENDCLASS

METHOD WvgBitmap:new()
   RETURN Self

METHOD WvgBitmap:create( oPScompat )

   IF oPScompat == NIL
      ::hDCComp := wvg_GetDC()
      ::lDCToDestroy := .T.
   ELSE
      ::hDCComp := oPScompat:hDC
   ENDIF

   RETURN Self

METHOD WvgBitmap:destroy()

   IF ::hBitmap != NIL
      wvg_DeleteObject( ::hBitmap )
   ENDIF
   IF ::lDCtoDestroy
      wvg_ReleaseDC( ::hDCcompat )
   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] Generate Harbour code for: Harbour test program: tests/guestbk.prg. Contains procedures: Main. This test file tests specific function APIs

[Assistant]
#define _WWW_ROOT_DIR_  hb_DirSepAdd( hb_DirSepToOS( "/www/root/" ) )

PROCEDURE Main()

   LOCAL oIni  := TIniFile():New( _WWW_ROOT_DIR_ + "guestbk.ini" )
   LOCAL oHTML := THtml():New()
   LOCAL cOddColor, cEvenColor
   LOCAL cCode, i, j, l, cField, nEntry, cColor
   LOCAL aEntries, aLine, cLine

   oHTML:ProcessCGI()

   IF oHTML:QueryFields( "Oper" ) == "A"

      nEntry := oIni:ReadNumber( "Entries", "Entries", 0 ) + 1
      oIni:WriteNumber( "Entries", "Entries", nEntry )

      FOR i := 1 TO oIni:ReadNumber( "Header", "DataFields", 0 )

         cField := oIni:ReadString( "Header", "DataField" + hb_ntos( i ), "" )
         oIni:WriteString( "Entries", cField + hb_ntos( nEntry ), ;
            StrTran( StrTran( oHTML:QueryFields( cField ), Chr( 13 ) ), Chr( 10 ), "
" ) )
      NEXT

      oIni:WriteString( "Entries", "DateTime" + hb_ntos( nEntry ), ;
         CMonth( Date() ) + " " + hb_ntos( Day( Date() ) ) + ", " + ;
         hb_ntos( Year( Date() ) ) + " " + Time() )

      oIni:UpdateFile()

      oHTML:cContent := '<meta http-equiv="Refresh" ' + ;
         'content="0;url=/cgi-bin/guestbk.exe">'  + ;
         ''

      oHTML:ShowResult()
   ELSE

      oHTML:SetHTMLFile( _WWW_ROOT_DIR_ + "guestbk.html" )

      cOddColor := oIni:ReadString( "Header", "OddColor", "#FFFFFF" )
      cEvenColor := oIni:ReadString( "Header", "EvenColor", "#F0F0F0" )

      cCode := ""
      i := oIni:ReadNumber( "Entries", "Entries", 0 )

      aEntries := {}

      DO WHILE i > 0

         aLine := {}

         FOR j := 1 TO oIni:ReadNumber( "Header", "DataFields", 0 )

            cField := oIni:ReadString( "Header", "DataField" + hb_ntos( j ), "" )
            AAdd( aLine, { cField, ;
               oIni:ReadString( "Entries", cField + hb_ntos( i ), "" ) } )
         NEXT

         AAdd( aEntries, aLine )

         i--
      ENDDO

      cCode := ""

      FOR i := 1 TO Len( aEntries )

         cCode += "
" + hb_eol()
         cColor := iif( Mod( i, 2 ) == 0, cEvenColor, cOddColor )

         FOR j := 1 TO oIni:ReadNumber( "Format", "FormatLines", 0 )

            cCode += "
"

            cLine := oIni:ReadString( "Format", "Format" + hb_ntos( j ), "" )
            FOR l := 1 TO Len( aEntries[ i ] )
               cLine := StrTran( cLine, "<#" + aEntries[ i ][ l ][ 1 ] + ">", ;
                  aEntries[ i ][ l ][ 2 ] )
            NEXT

            cLine := StrTran( cLine, "<#DateTime>", ;
               oIni:ReadString( "Entries", "DateTime" + hb_ntos( Len( aEntries ) - i + 1 ), "" ) )

            cCode += cLine + "
" + hb_eol()
         NEXT

         cCode += "
" + hb_eol()
      NEXT

      oHTML:AddReplaceTag( "Entries", cCode )
      oHTML:Generate()
      oHTML:ShowResult()

   ENDIF

   RETURN

#if defined( __HBSCRIPT__HBSHELL )
SET PROCEDURE TO "cgi.prg"
SET PROCEDURE TO "inifile.prg"
#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 'hbssl' (OpenSSL wrapper for SSL/TLS encryption): contrib/hbssl/tests/encode.prg. Contains procedures: Main. This file implements security and encryption functions

[Assistant]
#require "hbssl"

PROCEDURE Main()

   LOCAL ctx
   LOCAL result
   LOCAL encrypted
   LOCAL decrypted

   SSL_init()

   OpenSSL_add_all_ciphers()

   ctx := hb_EVP_ENCODE_ctx_create()

   EVP_EncodeInit( ctx )

   encrypted := ""
   result := ""
   EVP_EncodeUpdate( ctx, @result, "sample text" )
   encrypted += result
   EVP_EncodeFinal( ctx, @result )
   encrypted += result
   ? "ENCRYTPTED", ">" + encrypted + "<"

   ctx := hb_EVP_ENCODE_ctx_create()

   EVP_DecodeInit( ctx )

   decrypted := ""
   result := ""
   EVP_DecodeUpdate( ctx, @result, encrypted )
   decrypted += result
   EVP_DecodeFinal( ctx, @result )
   decrypted += result
   ? "DECRYTPTED", ">" + decrypted + "<"

   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/fileio.prg. Contains procedures: Main. This test file exercises basic Harbour language features

[Assistant]
PROCEDURE Main()

   LOCAL h
   LOCAL cstr := " "
   LOCAL ntmp := 1

   h := FCreate( "test.txt" )
   ? "create handle", h

   FWrite( h, "This test worked if you can see this" )

   FClose( h )

   h := FOpen( "test.txt" )
   ? "open handle", h
   ?

   DO WHILE ntmp != 0
      ntmp := FRead( h, @cstr, 1 )
      IF ntmp > 0
         ?? cstr
      ENDIF
   ENDDO
   ?

   FClose( h )

   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 contribution module 'gtwvg' (): contrib/gtwvg/dataref.prg. Defines classes: WvgDataRef. 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 WvgDataRef

   VAR    changed                               INIT .F.
   VAR    dataLink                              INIT NIL
   VAR    lastValid                             INIT .T.
   VAR    sl_undo                               INIT NIL
   VAR    undoBuffer                            INIT NIL
   VAR    sl_validate                           INIT NIL

   METHOD new()

   VAR    sl_editBuffer
   VAR    sl_buffer

   ACCESS editBuffer                             INLINE ::sl_editBuffer
   ASSIGN editBuffer( xData )                    INLINE ::sl_editBuffer := xData

   METHOD getData()
   METHOD setData( xValue, mp2 )
   METHOD undo()

   METHOD validate( xParam )                     SETGET

ENDCLASS

METHOD WvgDataRef:new()
   RETURN Self

METHOD WvgDataRef:getData()

   DO CASE
   CASE ::className() == "COMBOBOX"
      IF HB_ISOBJECT( ::XbpListBox ) .AND. HB_ISBLOCK( ::XbpListBox:dataLink )
         ::sl_editBuffer := ::XbpListBox:getData()
      ELSEIF HB_ISOBJECT( ::XbpSLE ) .AND. HB_ISBLOCK( ::XbpSLE:dataLink )
         ::sl_editBuffer := ::XbpSLE:getData()
      ELSEIF HB_ISOBJECT( ::XbpListBox )
         ::sl_editBuffer := ::XbpListBox:getData()
      ENDIF

   CASE ::className() == "EDIT"
      ::sl_editBuffer := wvg_GetMessageText( ::hWnd, WM_GETTEXT, ::bufferLength + 1 )

   CASE ::className() == "LISTBOX"
      ::sl_editBuffer := wvg_LBGetCurSel( ::hWnd ) + 1

   ENDCASE

   IF HB_ISBLOCK( ::dataLink )
      Eval( ::dataLink, ::sl_editBuffer )
   ENDIF

   RETURN ::sl_editBuffer

METHOD WvgDataRef:setData( xValue, mp2 )

   LOCAL s

   HB_SYMBOL_UNUSED( mp2 )

   IF HB_ISBLOCK( ::dataLink )
      ::sl_editBuffer := Eval( ::dataLink  )
   ELSEIF xValue != NIL
      ::sl_editBuffer := xValue
   ENDIF

   DO CASE

   CASE ::className() == "BUTTON"
      ::sendMessage( BM_SETCHECK, iif( ::sl_editBuffer, BST_CHECKED, BST_UNCHECKED ), 0 )

   CASE ::className() == "LISTBOX"
      IF HB_ISNUMERIC( ::sl_editBuffer )
         RETURN wvg_lbSetCurSel( ::hWnd, ::sl_editBuffer - 1 ) >= 0
      ENDIF

   CASE ::className() == "SysTreeView32"
      IF ::sl_editBuffer != NIL .AND. ::sl_editBuffer:hItem != NIL
         wvg_TreeView_SelectItem( ::hWnd, ::sl_editBuffer:hItem )
      ENDIF

   CASE ::className() == "EDIT"
      IF HB_ISSTRING( ::sl_editBuffer )
         wvg_SendMessageText( ::hWnd, WM_SETTEXT, 0, ::sl_editBuffer )
      ENDIF

   CASE ::className() == "SCROLLBAR"
      IF ::sl_editBuffer != NIL
         wapi_SetScrollPos( ::pWnd, SB_CTL, ::sl_editBuffer, .T. )
      ENDIF

   CASE ::className() == "COMBOBOX"
      IF HB_ISARRAY( ::sl_editBuffer )

         FOR EACH s IN ::sl_editBuffer
            ::addItem( s )
         NEXT
      ENDIF

   ENDCASE

   RETURN ::sl_editBuffer

METHOD WvgDataRef:undo()
   RETURN .F.

METHOD WvgDataRef:validate( xParam )

   IF PCount() == 0 .AND. HB_ISBLOCK( ::sl_validate )
      RETURN Eval( ::sl_validate, Self )
   ELSEIF HB_ISBLOCK( xParam )
      ::sl_validate := xParam
   ENDIF

   RETURN .T.


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

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

Harbour Runtime Library file: src/rtl/getsyshb.prg. Provides functions: hb_GetReadVar. This file implements the GET system for input field handling

[Assistant]
FUNCTION hb_GetReadVar( oGet )

   LOCAL cName := hb_asciiUpper( oGet:name )
   LOCAL xSubScript

   IF oGet:subScript != NIL
      FOR EACH xSubScript IN oGet:subScript
         SWITCH ValType( xSubScript )
         CASE "C"
            cName += '["' + xSubScript + '"]'
            EXIT
         CASE "D"
            cName += "[0d" + DToS( xSubScript ) + "]"
            EXIT
         CASE "T"
            cName += '[t"' + hb_TSToStr( xSubScript, .T. ) + '"]'
            EXIT
         OTHERWISE
            cName += "[" + hb_ntos( xSubScript ) + "]"
         ENDSWITCH
      NEXT
   ENDIF

   RETURN cName


[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 utility program: utils/hbi18n/hbi18n.prg. Provides functions: HBRawVersion, ExpandWildCards, LoadFiles, LoadFilesAsHash. Contains 7 procedures. This file provides internationalization support

[Assistant]
#include "hbgtinfo.ch"
#include "hbver.ch"
#include "directry.ch"

#define _HB_I18N_MERGE   1
#define _HB_I18N_GENHBL  2
#define _HB_I18N_TRANS   3

#define LEFTEQUAL( l, r )       ( Left( l, Len( r ) ) == r )

#define I_( x )                 hb_UTF8ToStr( hb_i18n_gettext( x ) )

ANNOUNCE HB_GTSYS
REQUEST HB_GT_CGI_DEFAULT

PROCEDURE Main( ... )

   LOCAL aParams, aFiles
   LOCAL cFileOut, cFileIn, cExt
   LOCAL lError, lEmpty, lQuiet
   LOCAL nMode, n
   LOCAL cParam

   aParams := hb_AParams()
   IF Empty( aParams )
      Syntax()
   ENDIF

   lError := lEmpty := lQuiet := .F.
   aFiles := {}
   nMode := 0
   FOR n := 1 TO Len( aParams )
      IF LEFTEQUAL( aParams[ n ], "-" )
         cParam := SubStr( aParams[ n ], 2 )
         IF cParam == "m"
            IF nMode != 0
               lError := .T.
            ELSE
               nMode := _HB_I18N_MERGE
            ENDIF
         ELSEIF cParam == "g"
            IF nMode != 0
               lError := .T.
            ELSE
               nMode := _HB_I18N_GENHBL
            ENDIF
         ELSEIF cParam == "a"
            IF nMode != 0
               lError := .T.
            ELSE
               nMode := _HB_I18N_TRANS
            ENDIF
         ELSEIF LEFTEQUAL( cParam, "o" )
            IF ! Empty( cParam := SubStr( cParam, 2 ) )
               cFileOut := cParam
            ELSEIF n < Len( aParams ) .AND. ! LEFTEQUAL( aParams[ n + 1 ], "-" )
               cFileOut := aParams[ ++n ]
            ELSE
               lError := .T.
            ENDIF
         ELSEIF cParam == "e"
            lEmpty := .T.
         ELSEIF cParam == "q"
            lQuiet := .T.
         ELSE
            lError := .T.
         ENDIF
      ELSE
         AAdd( aFiles, aParams[ n ] )
      ENDIF
      IF lError
         Syntax()
      ENDIF
   NEXT

   aFiles := ExpandWildCards( aFiles )

   IF nMode == _HB_I18N_TRANS
      FOR n := 1 TO Len( aFiles )
         hb_FNameSplit( aFiles[ n ],,, @cExt )
         IF ! Lower( cExt ) == ".hbl"
            cFileIn := aFiles[ n ]
            hb_ADel( aFiles, n, .T. )
            EXIT
         ENDIF
      NEXT
   ENDIF

   IF nMode == 0 .OR. Empty( aFiles ) .OR. ;
      ( nMode == _HB_I18N_TRANS .AND. Empty( cFileIn ) )
      Syntax()
   ENDIF

   IF ! lQuiet
      Logo()
   ENDIF

   SWITCH nMode
   CASE _HB_I18N_MERGE
      Merge( aFiles, cFileOut )
      EXIT
   CASE _HB_I18N_GENHBL
      GenHBL( aFiles, cFileOut, lEmpty )
      EXIT
   CASE _HB_I18N_TRANS
      AutoTrans( cFileIn, aFiles, cFileOut )
      EXIT
   ENDSWITCH

   RETURN

STATIC FUNCTION HBRawVersion()
   RETURN hb_StrFormat( "%d.%d.%d%s (r%d)", ;
      hb_Version( HB_VERSION_MAJOR ), ;
      hb_Version( HB_VERSION_MINOR ), ;
      hb_Version( HB_VERSION_RELEASE ), ;
      hb_Version( HB_VERSION_STATUS ), ;
      hb_Version( HB_VERSION_REVISION ) )

STATIC PROCEDURE Logo()

   OutStd( ;
      "Harbour i18n .pot/.hbl file manager " + HBRawVersion() + hb_eol() + ;
      "Copyright (c) 2009-" + ;
         "2025" + ", " + ;
         "Przemyslaw Czerpak" + hb_eol() + ;
      hb_Version( HB_VERSION_URL_BASE ) + hb_eol() + ;
      hb_eol() )

   RETURN

STATIC PROCEDURE Syntax()

   Logo()
   OutStd( ;
      I_( "Syntax: hbi18n -m | -g | -a [-o<outfile>] [-e] [-q] <files1[.pot] ...>" ) + hb_eol() + ;
      hb_eol() + ;
      "    -m          " + I_( "merge given .pot files" ) + hb_eol() + ;
      "    -g          " + I_( "generate .hbl file from given .pot files" ) + hb_eol() + ;
      "    -a          " + I_( "add automatic translations to 1st .pot file using translations from other .pot/.hbl files" ) + hb_eol() + ;
      "    -o<outfile> " + I_( "output file name" ) + hb_eol() + ;
      "                " + I_( "default is first .pot file name with .po (merge) or .hbl extension" ) + hb_eol() + ;
      "    -e          " + I_( "do not strip empty translation rules from .hbl files" ) + hb_eol() + ;
      "    -q          " + I_( "quiet mode" ) + hb_eol() + ;
      hb_eol() )

   IF hb_gtInfo( HB_GTI_ISGRAPHIC )
      OutStd( I_( "Press any key to continue..." ) )
      Inkey( 0 )
   ENDIF
   ErrorLevel( 1 )
   QUIT

STATIC PROCEDURE ErrorMsg( cErrorMsg )

   OutStd( hb_StrFormat( I_( "error: %1$s" ), StrTran( cErrorMsg, ";", hb_eol() ) ) + hb_eol() )

   IF hb_gtInfo( HB_GTI_ISGRAPHIC )
      OutStd( I_( "Press any key to continue..." ) )
      Inkey( 0 )
   ENDIF
   ErrorLevel( 1 )
   QUIT

STATIC FUNCTION ExpandWildCards( aFiles )

#ifndef __PLATFORM__UNIX

   LOCAL cFile, cRealFile
   LOCAL aRealFiles
   LOCAL lWild := .F.

   FOR EACH cFile IN aFiles
      IF "*" $ cFile .OR. "?" $ cFile
         lWild := .T.
         EXIT
      ENDIF
   NEXT
   IF lWild
      aRealFiles := {}
      FOR EACH cFile IN aFiles
         IF "*" $ cFile .OR. "?" $ cFile
            FOR EACH cRealFile IN Directory( cFile )
               AAdd( aRealFiles, cRealFile[ F_NAME ] )
            NEXT
         ELSE
            AAdd( aRealFiles, cFile )
         ENDIF
      NEXT
      aFiles := aRealFiles
   ENDIF
#endif

   RETURN aFiles

STATIC FUNCTION LoadFiles( aFiles )

   LOCAL aTrans, aTrans2
   LOCAL hIndex
   LOCAL cErrorMsg
   LOCAL n

   IF ( aTrans := __i18n_potArrayLoad( aFiles[ 1 ], @cErrorMsg ) ) == NIL
      ErrorMsg( cErrorMsg )
   ENDIF
   FOR n := 2 TO Len( aFiles )
      IF ( aTrans2 := __i18n_potArrayLoad( aFiles[ n ], @cErrorMsg ) ) == NIL
         ErrorMsg( cErrorMsg )
      ENDIF
      __i18n_potArrayJoin( aTrans, aTrans2, @hIndex )
   NEXT

   RETURN aTrans

STATIC FUNCTION LoadFilesAsHash( aFiles )

   LOCAL cTrans, cExt, cErrorMsg
   LOCAL hTrans
   LOCAL aTrans
   LOCAL n

   FOR n := 1 TO Len( aFiles )
      hb_FNameSplit( aFiles[ n ],,, @cExt )
      IF Lower( cExt ) == ".hbl"
         cTrans := hb_MemoRead( aFiles[ n ] )
         IF ! hb_i18n_Check( cTrans )
            ErrorMsg( hb_StrFormat( I_( "Wrong file format: %1$s" ), aFiles[ n ] ) )
         ENDIF
         IF hTrans == NIL
            hTrans := __i18n_hashTable( hb_i18n_RestoreTable( cTrans ) )
         ELSE
            __i18n_hashJoin( hTrans, __i18n_hashTable( hb_i18n_RestoreTable( cTrans ) ) )
         ENDIF
      ELSE
         aTrans := __i18n_potArrayLoad( aFiles[ n ], @cErrorMsg )
         IF aTrans == NIL
            ErrorMsg( cErrorMsg )
         ENDIF
         hTrans := __i18n_potArrayToHash( aTrans,, hTrans )
      ENDIF
   NEXT

   RETURN hTrans

STATIC PROCEDURE Merge( aFiles, cFileOut )

   LOCAL cErrorMsg

   IF Empty( cFileOut )
      cFileOut := hb_FNameExtSet( aFiles[ 1 ], ".po" )
   ELSE
      cFileOut := hb_FNameExtSetDef( cFileOut, ".po" )
   ENDIF

   IF ! __i18n_potArraySave( cFileOut, LoadFiles( aFiles ), @cErrorMsg )
      ErrorMsg( cErrorMsg )
   ENDIF

   RETURN

STATIC PROCEDURE GenHBL( aFiles, cFileOut, lEmpty )

   LOCAL cHBLBody
   LOCAL pI18N

   IF Empty( cFileOut )
      cFileOut := hb_FNameExtSet( aFiles[ 1 ], ".hbl" )
   ELSE
      cFileOut := hb_FNameExtSetDef( cFileOut, ".hbl" )
   ENDIF

   pI18N := __i18n_hashTable( __i18n_potArrayToHash( LoadFiles( aFiles ), ;
      lEmpty ) )
   cHBLBody := hb_i18n_SaveTable( pI18N )
   IF ! hb_MemoWrit( cFileOut, cHBLBody )
      ErrorMsg( hb_StrFormat( I_( "cannot create file: %1$s" ), cFileOut ) )
   ENDIF

   RETURN

STATIC PROCEDURE AutoTrans( cFileIn, aFiles, cFileOut )

   LOCAL cErrorMsg

   IF Empty( cFileOut )
      cFileOut := hb_FNameExtSet( cFileIn, ".po" )
   ELSE
      cFileOut := hb_FNameExtSetDef( cFileOut, ".po" )
   ENDIF

   IF ! __i18n_potArraySave( cFileOut, ;
      __i18n_potArrayTrans( LoadFiles( { cFileIn } ), ;
                            LoadFilesAsHash( aFiles ) ), @cErrorMsg )
      ErrorMsg( cErrorMsg )
   ENDIF

   RETURN


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

[User] Implement this Harbour module: Harbour test program: tests/longstr2.prg. Contains procedures: Main. This test file exercises basic Harbour language features

[Assistant]
PROCEDURE Main()

   LOCAL short := "1234567890"
   LOCAL i, long, very_long

   long := short
   FOR i := 1 TO 12
      long += long
   NEXT

   very_long := long
   FOR i := 1 TO 5
      very_long += very_long
   NEXT

   OutErr( Len( short ), Len( long ), Len( very_long ) )
   QOut  ( Len( short ), Len( long ), Len( very_long ) )

   OutStd( hb_eol() )
   OutStd( Len( short ), Len( long ), Len( very_long ) )

   OutStd( hb_eol() )
   OutStd( hb_eol() )
   OutStd( short )

   OutStd( hb_eol() )
   OutStd( hb_eol() )
   OutStd( long )

   OutStd( hb_eol() )
   OutStd( hb_eol() )
   OutStd( very_long )

   RETURN


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

[User] Implement this Harbour module: Harbour contribution module 'hbpgsql' (PostgreSQL database client library): contrib/hbpgsql/tests/async.prg. Contains procedures: Main, Query. This file handles database operations

[Assistant]
#require "hbpgsql"

#include "inkey.ch"

PROCEDURE Main( cHost, cDatabase, cUser, cPass )

   LOCAL conn

   CLS

   ? "Connect", conn := PQconnectdb( ;
      "dbname = '" + hb_defaultValue( cDatabase, "postgres" ) + "' " + ;
      "host = '" + hb_defaultValue( cHost, "localhost" ) + "' " + ;
      "user = '" + hb_defaultValue( cUser, hb_UserName() ) + "' " + ;
      "password = '" + hb_defaultValue( cPass, "" ) + "' " + ;
      "port = 5432" )

   ? "Conection status", PQerrorMessage( conn ), PQstatus( conn )

   Query( conn, "SELECT codigo, descri FROM client limit 100", .F. )
   Query( conn, "SELECT codigo, descri FROM fornec limit 100", .F. )
   Query( conn, "SELECT pedido, vlrped FROM pedido", .T. )

   RETURN

STATIC PROCEDURE Query( conn, cQuery, lCancel )

   LOCAL pCancel, cErrMsg := ""
   LOCAL res, x, y, cTime

   ? "PQSendQuery", PQsendQuery( conn, cQuery )

   cTime := Time()
   CLEAR TYPEAHEAD

   DO WHILE hb_keyStd( Inkey() ) != K_ESC
      DevPos( Row(), 20 )
      DevOut( "Processing:", ElapTime( cTime, Time() ) )

      Inkey( 1 )

      IF lCancel
         pCancel := PQgetCancel( conn )
         ? "Canceled:", PQcancel( pCancel, @cErrMsg ), cErrMsg
         pCancel := NIL
      ENDIF

      IF PQconsumeInput( conn )
         IF ! PQisBusy( conn )
            EXIT
         ENDIF
      ENDIF
   ENDDO

   IF hb_keyStd( Inkey() ) != K_ESC
      ? "PQgetResult", hb_ValToExp( res := PQgetResult( conn ) )

      IF ! Empty( res )
         FOR x := 1 TO PQlastrec( res )
            ?
            FOR y := 1 TO PQfcount( res )
               ?? PQgetvalue( res, x, y ), " "
            NEXT
         NEXT
      ENDIF
   ELSE
      ? "Canceling Query", PQrequestCancel( conn )
   ENDIF

   RETURN


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

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

Harbour contribution module 'hbmisc' (Miscellaneous utility functions): contrib/hbmisc/fcomma.prg. Provides 17 functions including: FCM_INIT, FCM_NEW, FCM_CREATE, FCM_OPEN, FCM_CLOSE. Contains procedures: FCOMMA_INIT. This file provides utility functions

[Assistant]
#include "rddsys.ch"
#include "hbusrrdd.ch"
#include "fileio.ch"
#include "error.ch"

ANNOUNCE FCOMMA

STATIC FUNCTION FCM_INIT( nRDD )

   LOCAL aRData := Array( 10 )

   AFill( aRData, F_ERROR )
   USRRDD_RDDDATA( nRDD, aRData )

   RETURN HB_SUCCESS

STATIC FUNCTION FCM_NEW( pWA )

   LOCAL aWData := { -1, .F., .F. }

   USRRDD_AREADATA( pWA, aWData )

   RETURN HB_SUCCESS

STATIC FUNCTION FCM_CREATE( nWA, aOpenInfo )

   LOCAL oError := ErrorNew()

   oError:GenCode     := EG_CREATE
   oError:SubCode     := 1004
   oError:Description := hb_langErrMsg( EG_CREATE ) + " (" + ;
      hb_langErrMsg( EG_UNSUPPORTED ) + ")"
   oError:FileName    := aOpenInfo[ UR_OI_NAME ]
   oError:CanDefault  := .T.
   UR_SUPER_ERROR( nWA, oError )

   RETURN HB_FAILURE

STATIC FUNCTION FCM_OPEN( nWA, aOpenInfo )

   LOCAL cName, nMode, nSlot, nHandle, aRData, aWData, aField, oError, nResult

   IF aOpenInfo[ UR_OI_ALIAS ] == NIL
      hb_FNameSplit( aOpenInfo[ UR_OI_NAME ], , @cName )
      aOpenInfo[ UR_OI_ALIAS ] := cName
   ENDIF

   nMode := ;
      iif( aOpenInfo[ UR_OI_SHARED ], FO_SHARED, FO_EXCLUSIVE ) + ;
      iif( aOpenInfo[ UR_OI_READONLY ], FO_READ, FO_READWRITE )

   aRData := USRRDD_RDDDATA( USRRDD_ID( nWA ) )
   aWData := USRRDD_AREADATA( nWA )
   nSlot := AScan( aRData, F_ERROR )

   IF nSlot == 0
      oError := ErrorNew()
      oError:GenCode     := EG_OPEN
      oError:SubCode     := 1000
      oError:Description := hb_langErrMsg( EG_OPEN ) + ", no free slots"
      oError:FileName    := aOpenInfo[ UR_OI_NAME ]
      oError:CanDefault  := .T.
      UR_SUPER_ERROR( nWA, oError )
      RETURN HB_FAILURE
   ENDIF

   hb_FSelect( nSlot )
   nHandle := hb_FUse( aOpenInfo[ UR_OI_NAME ], nMode )
   IF nHandle == F_ERROR
      oError := ErrorNew()
      oError:GenCode     := EG_OPEN
      oError:SubCode     := 1001
      oError:Description := hb_langErrMsg( EG_OPEN )
      oError:FileName    := aOpenInfo[ UR_OI_NAME ]
      oError:OsCode      := FError()
      oError:CanDefault  := .T.

      UR_SUPER_ERROR( nWA, oError )
      RETURN HB_FAILURE
   ENDIF
   aRData[ nSlot ] := nHandle
   aWData[ 1 ] := nSlot
   aWData[ 2 ] := aWData[ 3 ] := .F.

   UR_SUPER_SETFIELDEXTENT( nWA, 1 )
   aField := Array( UR_FI_SIZE )
   aField[ UR_FI_NAME ]    := "LINE"
   aField[ UR_FI_TYPE ]    := HB_FT_STRING
   aField[ UR_FI_TYPEEXT ] := 0
   aField[ UR_FI_LEN ]     := 80
   aField[ UR_FI_DEC ]     := 0
   UR_SUPER_ADDFIELD( nWA, aField )

   nResult := UR_SUPER_OPEN( nWA, aOpenInfo )

   IF nResult == HB_SUCCESS
      FCM_GOTOP( nWA )
   ENDIF

   RETURN nResult

STATIC FUNCTION FCM_CLOSE( nWA )

   LOCAL aRData, nSlot := USRRDD_AREADATA( nWA )[ 1 ]

   IF nSlot >= 0
      hb_FSelect( nSlot )
      hb_FUse()
      aRData := USRRDD_RDDDATA( USRRDD_ID( nWA ) )
      aRData[ nSlot ] := F_ERROR
   ENDIF

   RETURN UR_SUPER_CLOSE( nWA )

STATIC FUNCTION FCM_GETVALUE( nWA, nField, xValue )

   LOCAL aWData := USRRDD_AREADATA( nWA )

   IF nField == 1
      IF aWData[ 3 ]

         xValue := ""
      ELSE
         hb_FSelect( aWData[ 1 ] )
         xValue := hb_FReadLn()
      ENDIF
      RETURN HB_SUCCESS
   ENDIF

   RETURN HB_FAILURE

STATIC FUNCTION FCM_GOTO( nWA, nRecord )

   LOCAL aWData := USRRDD_AREADATA( nWA )

   hb_FSelect( aWData[ 1 ] )
   IF nRecord <= 0
      aWData[ 2 ] := aWData[ 3 ] := .T.
   ELSEIF nRecord == 1
      hb_FGoTop()
      aWData[ 2 ] := aWData[ 3 ] := hb_FAtEof()
   ELSE
      hb_FSkip( 0 )
      hb_FGoto( nRecord )
      aWData[ 2 ] := hb_FRecNo() == 0
      aWData[ 3 ] := hb_FAtEof()
   ENDIF

   RETURN HB_SUCCESS

STATIC FUNCTION FCM_GOTOID( nWA, nRecord )
   RETURN FCM_GOTO( nWA, nRecord )

STATIC FUNCTION FCM_GOTOP( nWA )

   LOCAL aWData := USRRDD_AREADATA( nWA )

   hb_FSelect( aWData[ 1 ] )
   hb_FGoTop()
   aWData[ 2 ] := aWData[ 3 ] := hb_FAtEof()

   RETURN HB_SUCCESS

STATIC FUNCTION FCM_GOBOTTOM( nWA )

   LOCAL aWData := USRRDD_AREADATA( nWA )

   hb_FSelect( aWData[ 1 ] )
   IF hb_FLastRec() == 0
      aWData[ 2 ] := aWData[ 3 ] := .T.
   ELSE
      hb_FSkip( 0 )
      hb_FGoBottom()
      aWData[ 2 ] := aWData[ 3 ] := .F.
   ENDIF

   RETURN HB_SUCCESS

STATIC FUNCTION FCM_SKIPRAW( nWA, nRecords )

   LOCAL aWData

   IF nRecords != 0
      aWData := USRRDD_AREADATA( nWA )
      hb_FSelect( aWData[ 1 ] )
      IF aWData[ 3 ]
         IF nRecords > 0
            RETURN HB_SUCCESS
         ENDIF
         FCM_GOBOTTOM( nWA )
         ++nRecords
      ENDIF
      IF nRecords < 0 .AND. hb_FRecNo() <= -nRecords
         hb_FGoTop()
         aWData[ 2 ] := .T.
         aWData[ 3 ] := hb_FAtEof()
      ELSEIF nRecords != 0
         hb_FSkip( nRecords )
         aWData[ 2 ] := .F.
         aWData[ 3 ] := hb_FAtEof()
      ENDIF
   ENDIF

   RETURN HB_SUCCESS

STATIC FUNCTION FCM_Bof( nWA, lBof )

   LOCAL aWData := USRRDD_AREADATA( nWA )

   lBof := aWData[ 2 ]

   RETURN HB_SUCCESS

STATIC FUNCTION FCM_EOF( nWA, lEof )

   LOCAL aWData := USRRDD_AREADATA( nWA )

   lEof := aWData[ 3 ]

   RETURN HB_SUCCESS

STATIC FUNCTION FCM_DELETED( nWA, lDeleted )

   HB_SYMBOL_UNUSED( nWA )
   lDeleted := .F.

   RETURN HB_SUCCESS

STATIC FUNCTION FCM_RECID( nWA, nRecNo )

   LOCAL aWData := USRRDD_AREADATA( nWA )

   hb_FSelect( aWData[ 1 ] )
   IF aWData[ 3 ]
      nRecNo := hb_FLastRec() + 1
   ELSE
      nRecNo := hb_FRecNo()
   ENDIF

   RETURN HB_SUCCESS

STATIC FUNCTION FCM_RECCOUNT( nWA, nRecords )

   hb_FSelect( USRRDD_AREADATA( nWA )[ 1 ] )
   nRecords := hb_FLastRec()

   RETURN HB_SUCCESS

FUNCTION FCOMMA_GETFUNCTABLE( pFuncCount, pFuncTable, pSuperTable, nRddID )

   LOCAL cSuperRDD := NIL
   LOCAL aMyFunc[ UR_METHODCOUNT ]

   aMyFunc[ UR_INIT ]     := @FCM_INIT()
   aMyFunc[ UR_NEW ]      := @FCM_NEW()
   aMyFunc[ UR_CREATE ]   := @FCM_CREATE()
   aMyFunc[ UR_OPEN ]     := @FCM_OPEN()
   aMyFunc[ UR_CLOSE ]    := @FCM_CLOSE()
   aMyFunc[ UR_BOF  ]     := @FCM_Bof()
   aMyFunc[ UR_EOF  ]     := @FCM_EOF()
   aMyFunc[ UR_DELETED ]  := @FCM_DELETED()
   aMyFunc[ UR_SKIPRAW ]  := @FCM_SKIPRAW()
   aMyFunc[ UR_GOTO ]     := @FCM_GOTO()
   aMyFunc[ UR_GOTOID ]   := @FCM_GOTOID()
   aMyFunc[ UR_GOTOP ]    := @FCM_GOTOP()
   aMyFunc[ UR_GOBOTTOM ] := @FCM_GOBOTTOM()
   aMyFunc[ UR_RECID ]    := @FCM_RECID()
   aMyFunc[ UR_RECCOUNT ] := @FCM_RECCOUNT()
   aMyFunc[ UR_GETVALUE ] := @FCM_GETVALUE()

   RETURN USRRDD_GETFUNCTABLE( pFuncCount, pFuncTable, pSuperTable, nRddID, ;
      cSuperRDD, aMyFunc )

INIT PROCEDURE FCOMMA_INIT()

   rddRegister( "FCOMMA", RDT_FULL )

   RETURN