wchar_t * hb_mbntowc( const char * srcA, HB_SIZE nLen ) { int length; wchar_t *dstW; nLen = hb_strnlen( srcA, nLen ); length = MultiByteToWideChar( CP_ACP, 0, srcA, ( int ) nLen, NULL, 0 ); dstW = ( wchar_t * ) hb_xgrab( ( length + 1 ) * sizeof( wchar_t ) ); MultiByteToWideChar( CP_ACP, 0, srcA, ( int ) nLen, dstW, length ); dstW[ length ] = L'\0'; return dstW; }
HB_BOOL hb_gt_winapi_getClipboard( HB_UINT uFormat, PHB_ITEM pItem ) { HB_SIZE nSize = 0; if( IsClipboardFormatAvailable( uFormat ) && OpenClipboard( NULL ) ) { HGLOBAL hglb = GetClipboardData( ( UINT ) uFormat ); if( hglb ) { LPVOID lpMem = GlobalLock( hglb ); if( lpMem ) { nSize = ( HB_SIZE ) GlobalSize( hglb ); switch( uFormat ) { case CF_UNICODETEXT: nSize = hb_wstrnlen( ( const wchar_t * ) lpMem, nSize >> 1 ); if( nSize ) hb_itemPutStrLenU16( pItem, HB_CDP_ENDIAN_NATIVE, ( const wchar_t * ) lpMem, nSize ); break; case CF_OEMTEXT: case CF_TEXT: nSize = hb_strnlen( ( const char * ) lpMem, nSize ); default: if( nSize ) hb_itemPutStrLen( pItem, uFormat == CF_TEXT ? hb_setGetOSCP() : NULL, ( const char * ) lpMem, nSize ); break; } ( void ) GlobalUnlock( hglb ); } } CloseClipboard(); }
long hb_timeUnformat( const char * szTime, const char * szTimeFormat ) { int iHour, iMinutes, iSeconds, iMSec, iPM; int size, i, count, prec, * pValue; HB_TRACE( HB_TR_DEBUG, ( "hb_timeUnformat(%s, %s)", szTime, szTimeFormat ) ); if( ! szTime ) return 0; if( ! szTimeFormat ) szTimeFormat = hb_setGetTimeFormat(); size = ( int ) hb_strnlen( szTime, hb_strnlen( szTimeFormat, 16 ) ); iHour = iMinutes = iSeconds = iMSec = iPM = -1; prec = 0; for( i = count = 0; i < size && szTime[ count ]; ++i ) { switch( szTimeFormat[ i ] ) { case 'H': case 'h': pValue = &iHour; break; case 'M': case 'm': pValue = &iMinutes; break; case 'S': case 's': pValue = &iSeconds; break; case 'F': case 'f': pValue = &iMSec; break; case 'P': case 'p': if( iPM < 0 ) { while( szTime[ count ] && ! HB_ISDIGIT( szTime[ count ] ) && szTime[ count ] != 'P' && szTime[ count ] != 'p' && szTime[ count ] != 'A' && szTime[ count ] != 'a' ) ++count; if ( szTime[ count ] == 'P' || szTime[ count ] == 'p' ) iPM = 1; else if( szTime[ count ] == 'A' || szTime[ count ] == 'a' ) iPM = 0; } default: pValue = NULL; } if( pValue && *pValue < 0 ) { *pValue = 0; while( szTime[ count ] && ! HB_ISDIGIT( szTime[ count ] ) ) ++count; while( HB_ISDIGIT( szTime[ count ] ) ) { *pValue = *pValue * 10 + ( szTime[ count ] - '0' ); ++count; if( pValue == &iMSec ) ++prec; } } } if( iHour < 0 ) iHour = 0; if( iMinutes < 0 ) iMinutes = 0; if( iSeconds < 0 ) iSeconds = 0; if( iMSec < 0 ) iMSec = 0; else if( iMSec > 0 ) { if( prec > 3 ) { do { iMSec /= 10; } while( --prec > 3 ); } else { while( prec++ < 3 ) iMSec *= 10; } } if( iPM > 0 ) { if( iHour == 0 ) iHour = 24; /* wrong time */ else if( iHour != 12 ) iHour += 12; } else if( iPM == 0 ) { if( iHour == 0 ) iHour = 24; /* wrong time */ else if( iHour == 12 ) iHour = 0; } return hb_timeEncode( iHour, iMinutes, iSeconds, iMSec ); }
/* Split given filename into path, name and extension, plus determine drive */ PHB_FNAME hb_fsFNameSplit( const char * pszFileName ) { PHB_FNAME pFileName; HB_TRACE( HB_TR_DEBUG, ( "hb_fsFNameSplit(%s)", pszFileName ) ); HB_TRACE( HB_TR_INFO, ( "hb_fsFNameSplit: Filename: |%s|", pszFileName ) ); /* Grab memory, set defaults */ pFileName = ( PHB_FNAME ) hb_xgrab( sizeof( HB_FNAME ) ); pFileName->szPath = pFileName->szName = pFileName->szExtension = pFileName->szDrive = NULL; if( pszFileName ) { char * pszPos, cDirSep; HB_ISIZ iSize, iPos; iPos = iSize = hb_strnlen( pszFileName, HB_PATH_MAX - 1 ); cDirSep = ( char ) hb_setGetDirSeparator(); pszPos = pFileName->szBuffer; /* Find the end of the path part, and find out where the name+ext starts */ while( --iPos >= 0 ) { if( pszFileName[ iPos ] == cDirSep || strchr( HB_OS_PATH_DELIM_CHR_LIST, pszFileName[ iPos ] ) ) { pFileName->szPath = pszPos; hb_strncpy( pszPos, pszFileName, iPos + 1 ); pszPos += iPos + 2; pszFileName += iPos + 1; iSize -= iPos + 1; break; } } /* From this point pszFileName will point to the name+ext part of the path */ /* Split the filename part to name and extension */ iPos = iSize; while( --iPos > 0 ) { if( pszFileName[ iPos ] == '.' ) { pFileName->szExtension = pszPos; hb_strncpy( pszPos, pszFileName + iPos, iSize - iPos ); pszPos += iSize - iPos + 1; iSize = iPos; break; } } if( iSize ) { pFileName->szName = pszPos; hb_strncpy( pszPos, pszFileName, iSize ); pszPos += iSize + 1; } /* Duplicate the drive letter from the path for easy access on platforms where applicable. Note that the drive info is always present also in the path itself. */ if( pFileName->szPath ) { iPos = 0; while( iPos < HB_MAX_DRIVE_LENGTH && pFileName->szPath[ iPos ] != '\0' ) { if( pFileName->szPath[ iPos ] == ':' ) { pFileName->szDrive = pszPos; hb_strncpy( pszPos, pFileName->szPath, iPos ); break; } ++iPos; } } } HB_TRACE( HB_TR_INFO, ( "hb_fsFNameSplit: szPath: |%s|", pFileName->szPath ) ); HB_TRACE( HB_TR_INFO, ( "hb_fsFNameSplit: szName: |%s|", pFileName->szName ) ); HB_TRACE( HB_TR_INFO, ( "hb_fsFNameSplit: szExt: |%s|", pFileName->szExtension ) ); HB_TRACE( HB_TR_INFO, ( "hb_fsFNameSplit: szDrive: |%s|", pFileName->szDrive ) ); return pFileName; }
/* time modifiers: * H - hour * M - minutes * S - seconds * F - fractional part of seconds * P - PM/AM marker * maximal size of time pattern: * 16 for "hh:mm:ss:ffff pp" * always safe buffer size is 17 (+1 for 0) */ char * hb_timeFormat( char * szBuffer, const char * szTimeFormat, long lMilliSec ) { char * szTimeBuffer; int iHour, iMinutes, iSeconds, iMSec, iPM, i12; int size, i, value, digits, skip; HB_TRACE( HB_TR_DEBUG, ( "hb_timeFormat(%p, %s, %ld)", szBuffer, szTimeFormat, lMilliSec ) ); hb_timeDecode( lMilliSec, &iHour, &iMinutes, &iSeconds, &iMSec ); szTimeBuffer = szBuffer; size = ( int ) hb_strnlen( szTimeFormat, 16 ); iPM = i12 = 0; for( i = 0; i < size; ++i ) { if( HB_TOUPPER( szTimeFormat[ i ] ) == 'P' ) { if( iHour >= 12 ) { iPM = 1; iHour -= 12; } if( iHour == 0 ) iHour += 12; if( iHour < 10 ) i12 = 1; break; } } i = 0; while( i < size ) { int count = -i; int ch = HB_TOUPPER( szTimeFormat[ i ] ); ++i; while( ch == HB_TOUPPER( szTimeFormat[ i ] ) && i < size ) ++i; count += i; switch( ch ) { case 'H': value = iHour; if( count == 2 && value >= 0 ) { if( i12 ) { *szTimeBuffer++ = ' '; --count; } digits = count; } else digits = 1; iHour = -1; break; case 'M': value = iMinutes; iMinutes = -1; digits = count > 2 ? 1 : count; break; case 'S': value = iSeconds; iSeconds = -1; digits = count > 2 ? 1 : count; break; case 'F': value = iMSec; iMSec = -1; digits = count > 4 ? 1 : count; switch( digits ) { case 4: value *= 10; break; case 2: value = ( value + 5 ) / 10; break; case 1: value = ( value + 50 ) / 100; break; } break; case 'P': if( iPM >= 0 ) { *szTimeBuffer++ = iPM ? 'P' : 'A'; if( --count ) { *szTimeBuffer++ = 'M'; --count; } iPM = -1; } default: digits = value = 0; } if( digits && value >= 0 ) { skip = digits; count -= digits; do { szTimeBuffer[ --digits ] = ( char ) ( '0' + value % 10 ); value /= 10; } while( digits ); szTimeBuffer += skip; } while( count-- ) *szTimeBuffer++ = ( char ) ch; } *szTimeBuffer = '\0'; return szBuffer; }