From 7039af02daa6290f2a0f0feded7c9341d15ed189 Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Wed, 1 Aug 2007 12:25:19 +0000 Subject: [PATCH] 2007-08-01 14:25 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/include/hbapifs.h * harbour/source/rtl/file.c + added xHarbour compatible C function hb_fsIsDirectory() * harbour/contrib/libct/color.c * harbour/contrib/libct/screen1.c + added UNTEXTWIN(), CHARWIN(), COLORWIN(), COLORREPL() * changed CLEARWIN(), INVERTWIN() to use common helper functions --- harbour/ChangeLog | 10 + harbour/contrib/libct/color.c | 105 ++----- harbour/contrib/libct/screen1.c | 524 +++++++++++++++++++++++++++++--- harbour/include/hbapifs.h | 1 + harbour/source/rtl/file.c | 28 +- 5 files changed, 546 insertions(+), 122 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 01472ec51c..cf7aff9d5e 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,16 @@ 2002-12-01 13:30 UTC+0100 Foo Bar */ +2007-08-01 14:25 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/include/hbapifs.h + * harbour/source/rtl/file.c + + added xHarbour compatible C function hb_fsIsDirectory() + + * harbour/contrib/libct/color.c + * harbour/contrib/libct/screen1.c + + added UNTEXTWIN(), CHARWIN(), COLORWIN(), COLORREPL() + * changed CLEARWIN(), INVERTWIN() to use common helper functions + 2007-07-31 23:00 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/make_gcc.sh * cleanup diff --git a/harbour/contrib/libct/color.c b/harbour/contrib/libct/color.c index e535073a82..44683db5a2 100644 --- a/harbour/contrib/libct/color.c +++ b/harbour/contrib/libct/color.c @@ -4,7 +4,9 @@ /* * Harbour Project source code: - * CT3 video function: - INVERTATTR(), INVERTWIN(), COLORTON() + * CT3 video function: + * INVERTATTR(), COLORTON(), NTOCOLOR(), + * ENHANCED(), STANDARD(), UNSELECTED() * * Copyright 2007 Przemyslaw Czerpak * www - http://www.harbour-project.org @@ -75,7 +77,7 @@ * $PLATFORMS$ * All * $FILES$ - * Source is invertcl.c, library is libct. + * Source is color.c, library is libct. * $SEEALSO$ * $END$ */ @@ -91,67 +93,6 @@ HB_FUNC( INVERTATTR ) } -/* $DOC$ - * $FUNCNAME$ - * INVERTWIN() - * $CATEGORY$ - * CT3 video functions - * $ONELINER$ - * - * $SYNTAX$ - * - * $ARGUMENTS$ - * $RETURNS$ - * $DESCRIPTION$ - * TODO: add documentation - * $EXAMPLES$ - * $TESTS$ - * $STATUS$ - * Started - * $COMPLIANCE$ - * INVERTWIN() is compatible with CT3's INVERTWIN(). - * $PLATFORMS$ - * All - * $FILES$ - * Source is invertcl.c, library is libct. - * $SEEALSO$ - * $END$ - */ - -HB_FUNC( INVERTWIN ) -{ - int iTop, iLeft, iBottom, iRight; - SHORT sTop, sLeft; - - hb_gtGetPos( &sTop, &sLeft ); - - iTop = ISNUM( 1 ) ? hb_parni( 1 ) : sTop; - iLeft = ISNUM( 2 ) ? hb_parni( 2 ) : sLeft; - iBottom = ISNUM( 3 ) ? hb_parni( 3 ) : hb_gtMaxRow(); - iRight = ISNUM( 4 ) ? hb_parni( 4 ) : hb_gtMaxCol(); - - hb_gtBeginWrite(); - while( iTop <= iBottom ) - { - int iCol = iLeft; - while( iCol <= iRight ) - { - BYTE bColor, bAttr; - USHORT usChar; - - hb_gtGetChar( iTop, iCol, &bColor, &bAttr, &usChar ); - bColor = ( bColor & 0x88 ) | - ( ( bColor & 0x07 ) << 4 ) | - ( ( bColor >> 4 ) & 0x07 ); - hb_gtPutChar( iTop, iCol, bColor, bAttr, usChar ); - ++iCol; - } - ++iTop; - } - hb_gtEndWrite(); -} - - /* $DOC$ * $FUNCNAME$ * COLORTON() @@ -185,7 +126,7 @@ HB_FUNC( INVERTWIN ) * $PLATFORMS$ * All * $FILES$ - * Source is color.prg, library is libct. + * Source is color.c, library is libct. * $SEEALSO$ * $END$ */ @@ -201,27 +142,29 @@ HB_FUNC( COLORTON ) /* $DOC$ * $FUNCNAME$ - * COLORTON() + * NTOCOLOR() * $CATEGORY$ - * CT3 video functions + * HBCT video functions * $ONELINER$ * $SYNTAX$ - * COLORTON ( ) -> + * NTOCOLOR ( , [] ) -> * $ARGUMENTS$ - * Designates the alphanumeric color attribute that is - * converted in NN/NN or CC/CC form. + * Designates the value for the combined numeric color + * attributes. + * + * If designated as .F. or if the parameter is omitted, + * NTOCOLOR() returns a string with a numeric color code. + * When designated as .T., NTOCOLOR() returns a string with + * the CA-Clipper alpha color coding. * * $RETURNS$ - * COLORTON() returns a number that corresponds to the combined numeric - * color attribute. + * NTOCOLOR() returns the designated color attribute in the NN/NN + * or CC/CC form. * * $DESCRIPTION$ - * COLOR TO (N)umeric - * The function changes an alphanumeric color attribute from NN/NN or - * CC/CC into a combined numeric attribute. These combined attribute - * values are useful with the CA-Clipper Tools functions STRSCREEN(), - * SCREENMIX(), SCREENATTR(), and the CA-Clipper commands - * SAVE/RESTORE SCREEN. + * NTOCOLOR() converts a color attribute returned from another function + * in numeric form, into the alphanumeric data format. Use this + * attribute in conjunction with the CA-Clipper SET COLOR TO command. * * TODO: add documentation * $EXAMPLES$ @@ -232,7 +175,7 @@ HB_FUNC( COLORTON ) * $PLATFORMS$ * All * $FILES$ - * Source is color.prg, library is libct. + * Source is color.c, library is libct. * $SEEALSO$ * $END$ */ @@ -279,7 +222,7 @@ HB_FUNC( NTOCOLOR ) * $PLATFORMS$ * All * $FILES$ - * Source is color.prg, library is libct. + * Source is color.c, library is libct. * $SEEALSO$ * STANDARD(),UNSELECTED() * $END$ @@ -314,7 +257,7 @@ HB_FUNC( ENHANCED ) * $PLATFORMS$ * All * $FILES$ - * Source is color.prg, library is libct. + * Source is color.c, library is libct. * $SEEALSO$ * ENHANCED(),UNSELECTED() * $END$ @@ -349,7 +292,7 @@ HB_FUNC( STANDARD ) * $PLATFORMS$ * All * $FILES$ - * Source is color.prg, library is libct. + * Source is color.c, library is libct. * $SEEALSO$ * ENHANCED(),STANDARD() * $END$ diff --git a/harbour/contrib/libct/screen1.c b/harbour/contrib/libct/screen1.c index 976b852ba1..33bd25dfa0 100644 --- a/harbour/contrib/libct/screen1.c +++ b/harbour/contrib/libct/screen1.c @@ -6,7 +6,8 @@ * Harbour Project source code: * CT3 video functions: * - * SCREENATTR(), SCREENMIX(), SAYSCREEN(), CLEARWIN() + * SCREENATTR(), SCREENMIX(), SAYSCREEN(), + * CLEARWIN(), INVERTWIN(), UNTEXTWIN(), CHARWIN(), COLORWIN(), COLORREPL() * * Copyright 2007 Przemyslaw Czerpak * @@ -112,6 +113,7 @@ HB_FUNC( SCREENATTR ) hb_retni( ( int ) bColor ); } + /* $DOC$ * $FUNCNAME$ * SCREENMIX() @@ -182,8 +184,42 @@ HB_FUNC( SCREENMIX ) hb_gtEndWrite(); } } + + hb_retc( NULL ); } + +/* $DOC$ + * $FUNCNAME$ + * SAYSCREEN() + * $CATEGORY$ + * HBCT video functions + * $ONELINER$ + * $SYNTAX$ + * SAYSCREEN( , [], [] ) -> + * $ARGUMENTS$ + * - the string to output. Although undocumented, can be NIL. + * - row number, defaults to cursor row. + * - column number, defaults to cursor column. + * $RETURNS$ + * Returns an empty string. + * $DESCRIPTION$ + * Outputs a string at specified coordinates without changing character + * attributes. + * $EXAMPLES$ + * $TESTS$ + * $STATUS$ + * Ready + * $COMPLIANCE$ + * $PLATFORMS$ + * All + * $FILES$ + * Source is screen2.prg, library is libct. + * $SEEALSO$ + * SCREENMIX() + * $END$ + */ + HB_FUNC( SAYSCREEN ) { ULONG ulLen = hb_parclen( 1 ); @@ -221,55 +257,463 @@ HB_FUNC( SAYSCREEN ) hb_gtEndWrite(); } } + + hb_retc( NULL ); +} + +static BOOL hb_ctGetWinCord( int * piTop, int * piLeft, + int * piBottom, int * piRight ) +{ + int iMaxRow = hb_gtMaxRow(); + int iMaxCol = hb_gtMaxCol(); + + hb_gt_GetPos( piTop, piLeft ); + + if( ISNUM( 1 ) ) + *piTop = hb_parni( 1 ); + if( ISNUM( 2 ) ) + *piLeft = hb_parni( 2 ); + if( ISNUM( 3 ) ) + { + *piBottom = hb_parni( 3 ); + if( *piBottom > iMaxRow ) + *piBottom = iMaxRow; + } + else + *piBottom = iMaxRow; + if( ISNUM( 4 ) ) + { + *piRight = hb_parni( 4 ); + if( *piRight > iMaxCol ) + *piRight = iMaxCol; + } + else + *piRight = iMaxCol; + + return *piTop >= 0 && *piLeft >= 0 && + *piTop <= *piBottom && *piLeft <= *piRight; +} + +static int hb_ctGetClearChar( int iParam ) +{ + int iChar; + + if( ISNUM( iParam ) ) + iChar = hb_parni( iParam ); + else if( ISCHAR( iParam ) ) + iChar = ( UCHAR ) hb_parc( iParam )[0]; + else + iChar = hb_gt_GetClearChar(); + + return iChar; +} + +static int hb_ctGetClearColor( int iParam ) +{ + int iColor; + + if( ISNUM( iParam ) ) + iColor = hb_parni( iParam ); + else if( ISCHAR( iParam ) ) + iColor = ( UCHAR ) hb_gtColorToN( hb_parc( iParam ) ); + else + iColor = hb_gt_GetClearColor(); + + return iColor; } HB_FUNC( CLEARWIN ) { - int iMaxRow = hb_gtMaxRow(); - int iMaxCol = hb_gtMaxCol(); int iTop, iLeft, iBottom, iRight; - BYTE bColor, bChar; - hb_gt_GetPos( &iTop, &iLeft ); - - if( ISNUM( 1 ) ) - iTop = hb_parni( 1 ); - if( ISNUM( 2 ) ) - iLeft = hb_parni( 2 ); - if( ISNUM( 3 ) ) + if( hb_ctGetWinCord( &iTop, &iLeft, &iBottom, &iRight ) ) { - iBottom = hb_parni( 3 ); - if( iBottom > iMaxRow ) - iBottom = iMaxRow; - } - else - iBottom = iMaxRow; - if( ISNUM( 4 ) ) - { - iRight = hb_parni( 4 ); - if( iRight > iMaxCol ) - iRight = iMaxCol; - } - else - iRight = iMaxCol; + BYTE bColor, bChar; - if( ISNUM( 5 ) ) - bColor = ( BYTE ) hb_parni( 5 ); - else if( hb_parclen( 5 ) > 0 ) - bColor = ( BYTE ) hb_gtColorToN( hb_parc( 5 ) ); - else - bColor = ( BYTE ) hb_gt_GetClearColor(); + bColor = ( BYTE ) hb_ctGetClearColor( 5 ); + bChar = ( BYTE ) hb_ctGetClearChar( 6 ); - if( ISNUM( 6 ) ) - bChar = ( BYTE ) hb_parni( 6 ); - else if( ISCHAR( 6 ) ) - bChar = ( BYTE ) hb_parc( 6 )[0]; - else - bChar = ( BYTE ) hb_gt_GetClearChar(); - - if( iTop >= 0 && iLeft >= 0 && iTop < iBottom && iLeft <= iRight ) - { hb_gt_Scroll( iTop, iLeft, iBottom, iRight, bColor, bChar, 0, 0 ); hb_gt_Flush(); } + + hb_retc( NULL ); +} + + +/* $DOC$ + * $FUNCNAME$ + * INVERTWIN() + * $CATEGORY$ + * CT3 video functions + * $ONELINER$ + * + * $SYNTAX$ + * + * $ARGUMENTS$ + * $RETURNS$ + * $DESCRIPTION$ + * TODO: add documentation + * $EXAMPLES$ + * $TESTS$ + * $STATUS$ + * Started + * $COMPLIANCE$ + * INVERTWIN() is compatible with CT3's INVERTWIN(). + * $PLATFORMS$ + * All + * $FILES$ + * Source is color.c, library is libct. + * $SEEALSO$ + * $END$ + */ + +HB_FUNC( INVERTWIN ) +{ + int iTop, iLeft, iBottom, iRight; + + if( hb_ctGetWinCord( &iTop, &iLeft, &iBottom, &iRight ) ) + { + hb_gtBeginWrite(); + while( iTop <= iBottom ) + { + int iCol = iLeft; + while( iCol <= iRight ) + { + BYTE bColor, bAttr; + USHORT usChar; + + hb_gtGetChar( iTop, iCol, &bColor, &bAttr, &usChar ); + bColor = ( bColor & 0x88 ) | + ( ( bColor & 0x07 ) << 4 ) | + ( ( bColor >> 4 ) & 0x07 ); + hb_gtPutChar( iTop, iCol, bColor, bAttr, usChar ); + ++iCol; + } + ++iTop; + } + hb_gtEndWrite(); + } + + hb_retc( NULL ); +} + + +/* $DOC$ + * $FUNCNAME$ + * UNTEXTWIN() + * $CATEGORY$ + * HBCT video functions + * $ONELINER$ + * $SYNTAX$ + * UNTEXTWIN(, , , , + * , + * [], + * []) --> cNull + * $ARGUMENTS$ + * Designates the line for the upper-left corner of the + * area. + * Designates the column for the upper-left corner of + * the area. + * Designates the line for the bottom-right corner of + * the area. + * Designates the line for the bottom-right column of + * the area. + * Replaces each + * character within the window, with the exception of those within the + * range of and + * . + * Designates the beginning of + * the bracketed area. The character can be number in the range of 0 to + * 255, or the character string type. The default value is 176. + * Designates the end of the bracketed + * area. The character can be number in the range of 0 to 255 or the + * character string type. The default value is 223. + * $RETURNS$ + * Returns a null string. + * $DESCRIPTION$ + * Replaces an area of characters from a region of the screen + * TODO: add documentation + * $EXAMPLES$ + * $TESTS$ + * $STATUS$ + * Started + * $COMPLIANCE$ + * $PLATFORMS$ + * All + * $FILES$ + * Source is untext.prg, library is hbct. + * $SEEALSO$ + * $END$ + */ + +HB_FUNC( UNTEXTWIN ) +{ + int iTop, iLeft, iBottom, iRight; + UCHAR ucRepl, ucInit, ucEnd; + + if( hb_ctGetWinCord( &iTop, &iLeft, &iBottom, &iRight ) ) + { + ucRepl = ( UCHAR ) hb_ctGetClearChar( 5 ); + + if( ISNUM( 6 ) ) + ucInit = ( UCHAR ) hb_parni( 6 ); + else if( hb_parclen( 6 ) > 0 ) + ucInit = ( UCHAR ) hb_parc( 6 )[0]; + else + ucInit = 176; + + if( ISNUM( 7 ) ) + ucEnd = ( UCHAR ) hb_parni( 7 ); + else if( hb_parclen( 7 ) > 0 ) + ucEnd = ( UCHAR ) hb_parc( 7 )[0]; + else + ucEnd = 223; + + hb_gtBeginWrite(); + while( iTop <= iBottom ) + { + int iCol = iLeft; + while( iCol <= iRight ) + { + BYTE bColor, bAttr; + USHORT usChar; + + hb_gtGetChar( iTop, iCol, &bColor, &bAttr, &usChar ); + if( ucInit <= ucEnd ? ( usChar < ucInit || usChar > ucEnd ) : + ( usChar > ucEnd && usChar < ucInit ) ) + hb_gtPutChar( iTop, iCol, bColor, bAttr, ucRepl ); + ++iCol; + } + ++iTop; + } + hb_gtEndWrite(); + } + + hb_retc( NULL ); +} + +/* $DOC$ + * $FUNCNAME$ + * CHARWIN() + * $CATEGORY$ + * HBCT video functions + * $ONELINER$ + * $SYNTAX$ + * CHARWIN (, , , , [], + * []) --> + * $ARGUMENTS$ + * - top row number, default 0 + * - left column number, default 0 + * - top row number, default MaxRow() + * - right column number, default MaxCol() + * - new character for the screen area, + * as a numeric value in the range of 0 to + * 255 or as a character string, default value is the CLEARB. + * - character to exchange. Specify the parameter + * as a numeric in the range of 0 to 255 + * or as a character string. The default is to exchange all characters. + * $RETURNS$ + * Returns an empty string. + * $DESCRIPTION$ + * Exchanges particular characters in a screen area. + * TODO: add documentation + * $EXAMPLES$ + * $TESTS$ + * $STATUS$ + * Started + * $COMPLIANCE$ + * $PLATFORMS$ + * All + * $FILES$ + * Source is screen3.prg, library is hbbct. + * $SEEALSO$ + * $END$ + */ + +HB_FUNC( CHARWIN ) +{ + int iTop, iLeft, iBottom, iRight; + + if( hb_ctGetWinCord( &iTop, &iLeft, &iBottom, &iRight ) ) + { + UCHAR ucNewChar, ucOldChar = 0; + BOOL fAll = FALSE; + + ucNewChar = ( UCHAR ) hb_ctGetClearChar( 5 ); + + if( ISNUM( 6 ) ) + ucOldChar = ( UCHAR ) hb_parni( 6 ); + else if( hb_parclen( 6 ) > 0 ) + ucOldChar = ( UCHAR ) hb_parc( 6 )[0]; + else + fAll = TRUE; + + hb_gtBeginWrite(); + while( iTop <= iBottom ) + { + int iCol = iLeft; + while( iCol <= iRight ) + { + BYTE bColor, bAttr; + USHORT usChar; + + hb_gtGetChar( iTop, iCol, &bColor, &bAttr, &usChar ); + if( fAll || usChar == ucOldChar ) + hb_gtPutChar( iTop, iCol, bColor, bAttr, ucNewChar ); + ++iCol; + } + ++iTop; + } + hb_gtEndWrite(); + } + + hb_retc( NULL ); +} + + +/* $DOC$ + * $FUNCNAME$ + * COLORWIN() + * $CATEGORY$ + * HBCT video functions + * $ONELINER$ + * $SYNTAX$ + * COLORWIN([], [], [], [], + * [], []) --> cNull + * $ARGUMENTS$ + * Designates the topmost line to begin processing. The + * default is the cursor line. + * Designates the leftmost column to begin processing. The + * default is the cursor column. + * Designates the bottommost line that is processed. + * The default is the last screen line or window line. + * Designates the rightmost column to clear. The default + * is the right screen border or window border. + * Designates the new attribute to replace the old + * one. The default is the standard attribute CLEARA. + * Designates the old character to exchange. The + * default is "exchange all attributes". + * $RETURNS$ + * Returns an empty string. + * $DESCRIPTION$ + * Exchanges particular attributes in a screen area + * TODO: add documentation + * $EXAMPLES$ + * $TESTS$ + * $STATUS$ + * Started + * $COMPLIANCE$ + * $PLATFORMS$ + * All + * $FILES$ + * Source is screen3.prg, library is hbct. + * $SEEALSO$ + * $END$ + */ + +HB_FUNC( COLORWIN ) +{ + int iTop, iLeft, iBottom, iRight; + + if( hb_ctGetWinCord( &iTop, &iLeft, &iBottom, &iRight ) ) + { + UCHAR ucNewColor, ucOldColor = 0; + BOOL fAll = FALSE; + + ucNewColor = ( UCHAR ) hb_ctGetClearColor( 5 ); + + if( ISNUM( 6 ) || ISCHAR( 6 ) ) + ucOldColor = ( UCHAR ) hb_ctGetClearColor( 6 ); + else + fAll = TRUE; + + hb_gtBeginWrite(); + while( iTop <= iBottom ) + { + int iCol = iLeft; + while( iCol <= iRight ) + { + BYTE bColor, bAttr; + USHORT usChar; + + hb_gtGetChar( iTop, iCol, &bColor, &bAttr, &usChar ); + if( fAll || bColor == ucOldColor ) + hb_gtPutChar( iTop, iCol, ucNewColor, bAttr, usChar ); + ++iCol; + } + ++iTop; + } + hb_gtEndWrite(); + } + + hb_retc( NULL ); +} + + +/* $DOC$ + * $FUNCNAME$ + * COLORREPL() + * $CATEGORY$ + * HBCT video functions + * $ONELINER$ + * $SYNTAX$ + * COLORREPL([], []) --> cNull + * $ARGUMENTS$ + * Designates the new attribute. The default is + * CLEARA. + * Designates the old attribute to exchange. The + * default is all existing attributes. + * $RETURNS$ + * Returns an empty string. + * $DESCRIPTION$ + * Exchanges particular screen attributes + * TODO: add documentation + * $EXAMPLES$ + * $TESTS$ + * $STATUS$ + * Started + * $COMPLIANCE$ + * $PLATFORMS$ + * All + * $FILES$ + * Source is screen3.prg, library is hbct. + * $SEEALSO$ + * $END$ + */ + +HB_FUNC( COLORREPL ) +{ + int iMaxRow = hb_gtMaxRow(); + int iMaxCol = hb_gtMaxCol(); + int iRow = 0, iCol; + UCHAR ucNewColor, ucOldColor = 0; + BOOL fAll = FALSE; + + ucNewColor = ( UCHAR ) hb_ctGetClearColor( 1 ); + + if( ISNUM( 2 ) || ISCHAR( 2 ) ) + ucOldColor = ( UCHAR ) hb_ctGetClearColor( 2 ); + else + fAll = TRUE; + + hb_gtBeginWrite(); + while( iRow <= iMaxRow ) + { + iCol = 0; + while( iCol <= iMaxCol ) + { + BYTE bColor, bAttr; + USHORT usChar; + + hb_gtGetChar( iRow, iCol, &bColor, &bAttr, &usChar ); + if( fAll || bColor == ucOldColor ) + hb_gtPutChar( iRow, iCol, ucNewColor, bAttr, usChar ); + ++iCol; + } + ++iRow; + } + hb_gtEndWrite(); + + hb_retc( NULL ); } diff --git a/harbour/include/hbapifs.h b/harbour/include/hbapifs.h index 0cd6434649..dda3d57ca5 100644 --- a/harbour/include/hbapifs.h +++ b/harbour/include/hbapifs.h @@ -120,6 +120,7 @@ extern HB_EXPORT BOOL hb_fsEof ( FHANDLE hFileHandle ); /* determine extern HB_EXPORT USHORT hb_fsError ( void ); /* retrieve file system error */ extern HB_EXPORT USHORT hb_fsOsError ( void ); /* retrieve system dependant file system error */ extern HB_EXPORT BOOL hb_fsFile ( BYTE * pszFileName ); /* determine if a file exists */ +extern HB_EXPORT BOOL hb_fsIsDirectory( BYTE * pFilename ); extern HB_EXPORT HB_FOFFSET hb_fsFSize ( BYTE * pszFileName, BOOL bUseDirEntry ); /* determine the size of a file */ extern HB_EXPORT FHANDLE hb_fsExtOpen ( BYTE * pszFileName, BYTE * pDefExt, USHORT uiFlags, BYTE * pPaths, PHB_ITEM pError ); /* open a file using default extension and a list of paths */ diff --git a/harbour/source/rtl/file.c b/harbour/source/rtl/file.c index ad310d040e..88877e03c3 100644 --- a/harbour/source/rtl/file.c +++ b/harbour/source/rtl/file.c @@ -59,7 +59,7 @@ HB_EXPORT BOOL hb_fsFile( BYTE * pFilename ) HB_TRACE(HB_TR_DEBUG, ("hb_fsFile(%s)", ( char * ) pFilename)); - pFilename = hb_fileNameConv( hb_strdup( ( char * ) pFilename) ); + pFilename = hb_fileNameConv( hb_strdup( ( char * ) pFilename ) ); if( ( ffind = hb_fsFindFirst( ( char * ) pFilename, HB_FA_ALL ) ) != NULL ) { @@ -72,3 +72,29 @@ HB_EXPORT BOOL hb_fsFile( BYTE * pFilename ) return FALSE; } +HB_EXPORT BOOL hb_fsIsDirectory( BYTE * pFilename ) +{ + BOOL bResult = FALSE; + PHB_FFIND ffind; + int iLen; + + HB_TRACE(HB_TR_DEBUG, ("hb_fsIsDirectory(%s)", ( char * ) pFilename)); + + pFilename = hb_fileNameConv( hb_strdup( ( char * ) pFilename ) ); + iLen = strlen( ( char * ) pFilename ); + while( iLen && strchr( OS_PATH_DELIMITER_LIST, pFilename[ iLen - 1 ] ) ) + pFilename[ --iLen ] = '\0'; + + if( iLen && iLen <= _POSIX_PATH_MAX ) + { + if( ( ffind = hb_fsFindFirst( ( char * ) pFilename, HB_FA_DIRECTORY ) ) != NULL ) + { + if( ( ffind->attr & HB_FA_DIRECTORY ) == HB_FA_DIRECTORY ) + bResult = TRUE; + hb_fsFindClose( ffind ); + } + } + + hb_xfree( pFilename ); + return bResult; +}