HB_BOOL hb_fsOS2QueryPathInfo( const char * pszPathName, HB_FOFFSET * pnSize, HB_FATTR * pnAttr, long * plJulian, long * plMillisec ) { HDIR hdirFindHandle = HDIR_CREATE; HB_FILEFINDBUF3L findBuffer; ULONG ulFindCount = 1; char * pszFree; APIRET ret; HB_BOOL fIsWSeB = hb_isWSeB(); pszPathName = hb_fsNameConv( pszPathName, &pszFree ); ret = DosFindFirst( ( PCSZ ) pszPathName, &hdirFindHandle, FILE_ARCHIVED | FILE_DIRECTORY | FILE_SYSTEM | FILE_HIDDEN | FILE_READONLY, &findBuffer, sizeof( findBuffer ), &ulFindCount, fIsWSeB ? FIL_STANDARDL : FIL_STANDARD ); hb_fsSetError( ( HB_ERRCODE ) ret ); if( hdirFindHandle != HDIR_CREATE ) DosFindClose( hdirFindHandle ); if( pszFree ) hb_xfree( pszFree ); if( ret == NO_ERROR ) { if( fIsWSeB ) { if( pnSize ) *pnSize = ( HB_FOFFSET ) findBuffer.ffbl.cbFile; if( pnAttr ) *pnAttr = hb_fsAttrFromRaw( ( HB_FATTR ) findBuffer.ffbl.attrFile ); if( plJulian ) *plJulian = hb_dateEncode( findBuffer.ffbl.fdateLastWrite.year + 1980, findBuffer.ffbl.fdateLastWrite.month, findBuffer.ffbl.fdateLastWrite.day ); if( plMillisec ) *plMillisec = hb_timeEncode( findBuffer.ffbl.ftimeLastWrite.hours, findBuffer.ffbl.ftimeLastWrite.minutes, findBuffer.ffbl.ftimeLastWrite.twosecs * 2, 0 ); } else { if( pnSize ) *pnSize = ( HB_FOFFSET ) findBuffer.ffb.cbFile; if( pnAttr ) *pnAttr = hb_fsAttrFromRaw( ( HB_FATTR ) findBuffer.ffb.attrFile ); if( plJulian ) *plJulian = hb_dateEncode( findBuffer.ffb.fdateLastWrite.year + 1980, findBuffer.ffb.fdateLastWrite.month, findBuffer.ffb.fdateLastWrite.day ); if( plMillisec ) *plMillisec = hb_timeEncode( findBuffer.ffb.ftimeLastWrite.hours, findBuffer.ffb.ftimeLastWrite.minutes, findBuffer.ffb.ftimeLastWrite.twosecs * 2, 0 ); } return HB_TRUE; } return HB_FALSE; }
/* return UTC julian timestamp in milliseconds */ HB_MAXUINT hb_dateMilliSeconds( void ) { HB_TRACE( HB_TR_DEBUG, ( "hb_dateMilliSeconds()" ) ); #if defined( HB_OS_WIN ) { SYSTEMTIME st; GetSystemTime( &st ); return ( HB_MAXUINT ) hb_dateEncode( st.wYear, st.wMonth, st.wDay ) * HB_MILLISECS_PER_DAY + hb_timeEncode( st.wHour, st.wMinute, st.wSecond, st.wMilliseconds ); } #elif defined( HB_OS_UNIX ) || defined( HB_OS_OS2 ) { struct timeval tv; gettimeofday( &tv, NULL ); return ( ( HB_MAXUINT ) tv.tv_sec + ( HB_MAXUINT ) HB_SYS_DATE_BASE * HB_SECONDS_PER_DAY ) * 1000 + tv.tv_usec / 1000; } #else { struct timeb tb; ftime( &tb ); return ( ( HB_MAXUINT ) tb.time + ( HB_MAXUINT ) HB_SYS_DATE_BASE * HB_SECONDS_PER_DAY ) * 1000 + tb.millitm; } #endif }
void hb_timeStampStrRawGet( const char * szDateTime, long * plJulian, long * plMilliSec ) { int iYear, iMonth, iDay, iHour, iMinutes, iSeconds, iMSec, iLen; HB_TRACE( HB_TR_DEBUG, ( "hb_timeStampStrRawGet(%s, %p, %p)", szDateTime, plJulian, plMilliSec ) ); *plJulian = *plMilliSec = 0; iLen = 0; while( iLen < 10 && HB_ISDIGIT( szDateTime[ iLen ] ) ) ++iLen; if( iLen == 8 || iLen >= 10 ) { hb_dateStrGet( szDateTime, &iYear, &iMonth, &iDay ); *plJulian = hb_dateEncode( iYear, iMonth, iDay ); szDateTime += 8; iLen -= 8; } if( iLen >= 2 ) { hb_timeStrRawGet( szDateTime, &iHour, &iMinutes, &iSeconds, &iMSec ); *plMilliSec = hb_timeEncode( iHour, iMinutes, iSeconds, iMSec ); } }
static int hb_lexDateGet( YYSTYPE * yylval_ptr, HB_MACRO_PTR pMacro, PHB_MACRO_LEX pLex ) { HB_BOOL fOK = HB_FALSE; char * dst = pLex->pDst; int iYear, iMonth, iDay; pLex->quote = HB_FALSE; while( pLex->nSrc < pLex->nLen ) { char ch = pLex->pString[ pLex->nSrc++ ]; if( ch == '"' ) { fOK = HB_TRUE; break; } *dst++ = ch; } *dst = '\0'; if( fOK && hb_timeStampStrGet( pLex->pDst, &iYear, &iMonth, &iDay, NULL, NULL, NULL, NULL ) ) { yylval_ptr->valLong.lNumber = hb_dateEncode( iYear, iMonth, iDay ); } else { yylval_ptr->valLong.lNumber = 0; hb_macroError( EG_SYNTAX, pMacro ); } return NUM_DATE; }
static int ct_doy( long lDate ) { int iYear, iMonth, iDay; long lFirst; hb_dateDecode( lDate, &iYear, &iMonth, &iDay ); lFirst = hb_dateEncode( iYear, 1, 1 ); return ( int ) ( lDate - lFirst + 1 ); }
long hb_dateEncStr( const char * szDate ) { int iYear, iMonth, iDay; HB_TRACE( HB_TR_DEBUG, ( "hb_dateEncStr(%.8s)", szDate ) ); hb_dateStrGet( szDate, &iYear, &iMonth, &iDay ); return hb_dateEncode( iYear, iMonth, iDay ); }
/* return local timestamp */ void hb_timeStampGet( long * plJulian, long * plMilliSec ) { int iYear, iMonth, iDay, iHour, iMinute, iSeconds, iMillisec; HB_TRACE( HB_TR_DEBUG, ( "hb_timeStampGet(%p,%p)", plJulian, plMilliSec ) ); hb_timeStampGetLocal( &iYear, &iMonth, &iDay, &iHour, &iMinute, &iSeconds, &iMillisec ); *plJulian = hb_dateEncode( iYear, iMonth, iDay ); *plMilliSec = hb_timeEncode( iHour, iMinute, iSeconds, iMillisec ); }
HB_EXPR_PTR hb_compExprNewDate( HB_EXPR_PTR pYear, HB_EXPR_PTR pMonth, HB_EXPR_PTR pDate ) { HB_EXPR_PTR pExpr; HB_TRACE(HB_TR_DEBUG, ("hb_compExprNewDate()")); pExpr = hb_compExprNew( HB_ET_DATE ); pExpr->value.asDate.date = hb_dateEncode( (int) pYear->value.asNum.lVal, (int) pMonth->value.asNum.lVal, (int) pDate->value.asNum.lVal ); pExpr->value.asDate.time = 0; pExpr->value.asDate.type = HB_ET_DDATE; pExpr->ValType = HB_EV_DATE; return pExpr; }
HB_BOOL hb_timeStampStrGetDT( const char * szDateTime, long * plJulian, long * plMilliSec ) { int iYear, iMonth, iDay, iHour, iMinutes, iSeconds, iMSec; HB_BOOL fValid; HB_TRACE( HB_TR_DEBUG, ( "hb_timeStampStrGetDT(%s, %p, %p)", szDateTime, plJulian, plMilliSec ) ); fValid = hb_timeStampStrGet( szDateTime, &iYear, &iMonth, &iDay, &iHour, &iMinutes, &iSeconds, &iMSec ); if( plJulian ) *plJulian = hb_dateEncode( iYear, iMonth, iDay ); if( plMilliSec ) *plMilliSec = hb_timeEncode( iHour, iMinutes, iSeconds, iMSec ); return fValid; }
double hb_timeStampPackD( int iYear, int iMonth, int iDay, int iHour, int iMinutes, double dSeconds ) { double dTimeStamp = 0; HB_TRACE( HB_TR_DEBUG, ( "hb_timeStampPackD(%d, %d, %d, %d, %d, %f)", iYear, iMonth, iDay, iHour, iMinutes, dSeconds ) ); if( iHour >= 0 && iHour < 24 && iMinutes >= 0 && iMinutes < 60 && dSeconds >= 0 && dSeconds < 60 ) { long lJulian = hb_dateEncode( iYear, iMonth, iDay ); if( lJulian != 0 || ( iYear == 0 && iMonth == 0 && iDay == 0 ) ) { dTimeStamp = ( double ) lJulian + ( double ) ( ( ( iHour * 60 + iMinutes ) * 60 ) + dSeconds ) / HB_SECONDS_PER_DAY; } } return dTimeStamp; }
double hb_timeStampPack( int iYear, int iMonth, int iDay, int iHour, int iMinutes, int iSeconds, int iMSec ) { double dTimeStamp = 0; HB_TRACE( HB_TR_DEBUG, ( "hb_timeStampPack(%d, %d, %d, %d, %d, %d, %d)", iYear, iMonth, iDay, iHour, iMinutes, iSeconds, iMSec ) ); if( iHour >= 0 && iHour < 24 && iMinutes >= 0 && iMinutes < 60 && iSeconds >= 0 && iSeconds < 60 && iMSec >= 0 && iMSec < 1000 ) { long lJulian = hb_dateEncode( iYear, iMonth, iDay ); if( lJulian != 0 || ( iYear == 0 && iMonth == 0 && iDay == 0 ) ) { dTimeStamp = ( double ) lJulian + ( double ) ( ( ( long ) ( iHour * 60 + iMinutes ) * 60 + iSeconds ) * 1000 + iMSec ) / HB_MILLISECS_PER_DAY; } } return dTimeStamp; }
int hb_macro_yylex( YYSTYPE * yylval_ptr, HB_MACRO_PTR pMacro ) { PHB_MACRO_LEX pLex = ( PHB_MACRO_LEX ) pMacro->pLex; while( pLex->nSrc < pLex->nLen ) { unsigned char ch = ( unsigned char ) pLex->pString[ pLex->nSrc++ ]; switch( ch ) { case ' ': case '\t': break; case '$': case ',': case '|': case '@': case '(': case '{': pLex->quote = HB_TRUE; return ch; case ')': case '}': case ']': pLex->quote = HB_FALSE; return ch; case '#': pLex->quote = HB_TRUE; return NE1; case '!': pLex->quote = HB_TRUE; if( pLex->pString[ pLex->nSrc ] == '=' ) { pLex->nSrc++; return NE2; } return NOT; case '<': pLex->quote = HB_TRUE; if( pLex->pString[ pLex->nSrc ] == '>' ) { pLex->nSrc++; return NE2; } else if( pLex->pString[ pLex->nSrc ] == '=' ) { pLex->nSrc++; return LE; } return '<'; case '>': pLex->quote = HB_TRUE; if( pLex->pString[ pLex->nSrc ] == '=' ) { pLex->nSrc++; return GE; } return '>'; case '=': pLex->quote = HB_TRUE; if( pLex->pString[ pLex->nSrc ] == '=' ) { pLex->nSrc++; return EQ; } else if( pLex->pString[ pLex->nSrc ] == '>' && HB_SUPPORT_HARBOUR ) { pLex->nSrc++; return HASHOP; } return '='; case '+': pLex->quote = HB_TRUE; if( pLex->pString[ pLex->nSrc ] == '+' ) { pLex->nSrc++; return INC; } else if( pLex->pString[ pLex->nSrc ] == '=' ) { pLex->nSrc++; return PLUSEQ; } return '+'; case '-': pLex->quote = HB_TRUE; if( pLex->pString[ pLex->nSrc ] == '-' ) { pLex->nSrc++; return DEC; } else if( pLex->pString[ pLex->nSrc ] == '=' ) { pLex->nSrc++; return MINUSEQ; } else if( pLex->pString[ pLex->nSrc ] == '>' ) { pLex->nSrc++; return ALIASOP; } return '-'; case '*': pLex->quote = HB_TRUE; if( pLex->pString[ pLex->nSrc ] == '*' ) { pLex->nSrc++; if( pLex->pString[ pLex->nSrc ] == '=' ) { pLex->nSrc++; return EXPEQ; } return POWER; } else if( pLex->pString[ pLex->nSrc ] == '=' ) { pLex->nSrc++; return MULTEQ; } return '*'; case '/': pLex->quote = HB_TRUE; if( pLex->pString[ pLex->nSrc ] == '=' ) { pLex->nSrc++; return DIVEQ; } return '/'; case '%': pLex->quote = HB_TRUE; if( pLex->pString[ pLex->nSrc ] == '=' ) { pLex->nSrc++; return MODEQ; } return '%'; case '^': pLex->quote = HB_TRUE; if( pLex->pString[ pLex->nSrc ] == '=' ) { pLex->nSrc++; return EXPEQ; } return POWER; case ':': pLex->quote = HB_TRUE; if( pLex->pString[ pLex->nSrc ] == '=' ) { pLex->nSrc++; return INASSIGN; } else if( pLex->pString[ pLex->nSrc ] == ':' ) { yylval_ptr->string = "SELF"; return IDENTIFIER; } return ':'; case '.': pLex->quote = HB_TRUE; if( pLex->nSrc < pLex->nLen && HB_ISDIGIT( pLex->pString[ pLex->nSrc ] ) ) { HB_SIZE ul = pLex->nSrc; while( ++ul < pLex->nLen && HB_ISDIGIT( pLex->pString[ ul ] ) ) {}; ul -= --pLex->nSrc; return hb_lexNumConv( yylval_ptr, pLex, ul ); } if( pLex->nLen - pLex->nSrc >= 4 && pLex->pString[ pLex->nSrc + 3 ] == '.' ) { if( ( pLex->pString[ pLex->nSrc + 0 ] | ( 'a' - 'A' ) ) == 'a' && ( pLex->pString[ pLex->nSrc + 1 ] | ( 'a' - 'A' ) ) == 'n' && ( pLex->pString[ pLex->nSrc + 2 ] | ( 'a' - 'A' ) ) == 'd' ) { pLex->nSrc += 4; return AND; } if( ( pLex->pString[ pLex->nSrc + 0 ] | ( 'a' - 'A' ) ) == 'n' && ( pLex->pString[ pLex->nSrc + 1 ] | ( 'a' - 'A' ) ) == 'o' && ( pLex->pString[ pLex->nSrc + 2 ] | ( 'a' - 'A' ) ) == 't' ) { pLex->nSrc += 4; return NOT; } } if( pLex->nLen - pLex->nSrc >= 3 && pLex->pString[ pLex->nSrc + 2 ] == '.' ) { if( ( pLex->pString[ pLex->nSrc + 0 ] | ( 'a' - 'A' ) ) == 'o' && ( pLex->pString[ pLex->nSrc + 1 ] | ( 'a' - 'A' ) ) == 'r' ) { pLex->nSrc += 3; return OR; } } if( pLex->nLen - pLex->nSrc >= 2 && pLex->pString[ pLex->nSrc + 1 ] == '.' ) { if( ( pLex->pString[ pLex->nSrc ] | ( 'a' - 'A' ) ) == 't' || ( pLex->pString[ pLex->nSrc ] | ( 'a' - 'A' ) ) == 'y' ) { pLex->quote = HB_FALSE; pLex->nSrc += 2; return TRUEVALUE; } if( ( pLex->pString[ pLex->nSrc ] | ( 'a' - 'A' ) ) == 'f' || ( pLex->pString[ pLex->nSrc ] | ( 'a' - 'A' ) ) == 'n' ) { pLex->quote = HB_FALSE; pLex->nSrc += 2; return FALSEVALUE; } if( pLex->pString[ pLex->nSrc ] == '.' ) { pLex->nSrc += 2; return EPSILON; } } return '.'; case '[': if( pLex->quote ) return hb_lexStringCopy( yylval_ptr, pMacro, pLex, ']' ); pLex->quote = HB_TRUE; return '['; case '`': case '\'': return hb_lexStringCopy( yylval_ptr, pMacro, pLex, '\'' ); case '"': return hb_lexStringCopy( yylval_ptr, pMacro, pLex, '"' ); case '&': if( pLex->nSrc < pLex->nLen ) { if( HB_ISFIRSTIDCHAR( pLex->pString[ pLex->nSrc ] ) ) { /* [&<keyword>[.[<nextidchars>]]]+ */ int iParts = 0; pLex->quote = HB_FALSE; yylval_ptr->string = pLex->pDst; pLex->nSrc--; do { ++iParts; *pLex->pDst++ = '&'; pLex->nSrc++; hb_lexIdentCopy( pLex ); if( pLex->pString[ pLex->nSrc ] == '.' ) { ++iParts; *pLex->pDst++ = '.'; pLex->nSrc++; hb_lexIdentCopy( pLex ); } } while( pLex->nLen - pLex->nSrc > 1 && pLex->pString[ pLex->nSrc ] == '&' && HB_ISFIRSTIDCHAR( pLex->pString[ pLex->nSrc + 1 ] ) ); if( iParts == 2 && *( pLex->pDst - 1 ) == '.' ) { pLex->pDst--; iParts = 1; } *pLex->pDst++ = '\0'; if( iParts == 1 ) { yylval_ptr->string++; if( pLex->pDst - yylval_ptr->string > HB_SYMBOL_NAME_LEN + 1 ) ( ( char * ) yylval_ptr->string )[ HB_SYMBOL_NAME_LEN ] = '\0'; return MACROVAR; } return MACROTEXT; } else if( pLex->pString[ pLex->nSrc ] == '\'' || pLex->pString[ pLex->nSrc ] == '"' || pLex->pString[ pLex->nSrc ] == '[' ) hb_macroError( EG_SYNTAX, pMacro ); } pLex->quote = HB_TRUE; return '&'; default: if( HB_ISDIGIT( ch ) ) { HB_SIZE n = pLex->nSrc; pLex->quote = HB_FALSE; if( ch == '0' && n < pLex->nLen ) { if( pLex->pString[ n ] == 'd' || pLex->pString[ n ] == 'D' ) { while( ++n < pLex->nLen && HB_ISDIGIT( pLex->pString[ n ] ) ) {}; if( n - pLex->nSrc == 9 ) { int year, month, day; hb_dateStrGet( pLex->pString + pLex->nSrc + 1, &year, &month, &day ); yylval_ptr->valLong.lNumber = hb_dateEncode( year, month, day ); pLex->nSrc = n; if( yylval_ptr->valLong.lNumber == 0 && ( year != 0 || month != 0 || day != 0 ) ) { hb_macroError( EG_SYNTAX, pMacro ); } return NUM_DATE; } else if( n - pLex->nSrc == 2 && pLex->pString[ pLex->nSrc + 1 ] == '0' ) { yylval_ptr->valLong.lNumber = 0; return NUM_DATE; } n = pLex->nSrc; } else if( pLex->pString[ n ] == 'x' || pLex->pString[ n ] == 'X' ) { while( ++n < pLex->nLen && HB_ISXDIGIT( pLex->pString[ n ] ) ) {}; if( n == pLex->nSrc + 1 ) --n; } else { while( n < pLex->nLen && HB_ISDIGIT( pLex->pString[ n ] ) ) ++n; if( pLex->nLen - n > 1 && pLex->pString[ n ] == '.' && HB_ISDIGIT( pLex->pString[ n + 1 ] ) ) { while( ++n < pLex->nLen && HB_ISDIGIT( pLex->pString[ n ] ) ) {}; } } } else { while( n < pLex->nLen && HB_ISDIGIT( pLex->pString[ n ] ) ) ++n; if( pLex->nLen - n > 1 && pLex->pString[ n ] == '.' && HB_ISDIGIT( pLex->pString[ n + 1 ] ) ) { while( ++n < pLex->nLen && HB_ISDIGIT( pLex->pString[ n ] ) ) {}; } } n -= --pLex->nSrc; return hb_lexNumConv( yylval_ptr, pLex, n ); } else if( HB_ISFIRSTIDCHAR( ch ) ) { HB_SIZE nLen; pLex->quote = HB_FALSE; yylval_ptr->string = pLex->pDst; *pLex->pDst++ = ch - ( ( ch >= 'a' && ch <= 'z' ) ? 'a' - 'A' : 0 ); hb_lexIdentCopy( pLex ); if( pLex->nLen - pLex->nSrc > 1 && pLex->pString[ pLex->nSrc ] == '&' && HB_ISFIRSTIDCHAR( pLex->pString[ pLex->nSrc + 1 ] ) ) { /* [<keyword>][&<keyword>[.[<nextidchars>]]]+ */ do { *pLex->pDst++ = '&'; pLex->nSrc++; hb_lexIdentCopy( pLex ); if( pLex->pString[ pLex->nSrc ] == '.' ) { *pLex->pDst++ = '.'; pLex->nSrc++; hb_lexIdentCopy( pLex ); } } while( pLex->nLen - pLex->nSrc > 1 && pLex->pString[ pLex->nSrc ] == '&' && HB_ISFIRSTIDCHAR( pLex->pString[ pLex->nSrc + 1 ] ) ); *pLex->pDst++ = '\0'; return MACROTEXT; } nLen = pLex->pDst - yylval_ptr->string; *pLex->pDst++ = '\0'; if( nLen == 1 ) { if( pLex->nLen > pLex->nSrc && pLex->pString[ pLex->nSrc ] == '"' ) { switch( yylval_ptr->string[ 0 ] ) { case 'E': pLex->nSrc++; return hb_lexStringExtCopy( yylval_ptr, pMacro, pLex ); case 'T': pLex->nSrc++; return hb_lexTimestampGet( yylval_ptr, pMacro, pLex ); case 'D': pLex->nSrc++; return hb_lexDateGet( yylval_ptr, pMacro, pLex ); } } } else if( nLen == 2 ) { if( yylval_ptr->string[ 0 ] == 'I' && yylval_ptr->string[ 1 ] == 'F' ) { hb_lexSkipBlank( pLex ); if( pLex->nSrc < pLex->nLen && pLex->pString[ pLex->nSrc ] == '(' ) return IIF; } } else if( nLen == 3 ) { if( yylval_ptr->string[ 0 ] == 'I' && yylval_ptr->string[ 1 ] == 'I' && yylval_ptr->string[ 2 ] == 'F' ) { hb_lexSkipBlank( pLex ); if( pLex->nSrc < pLex->nLen && pLex->pString[ pLex->nSrc ] == '(' ) return IIF; } else if( yylval_ptr->string[ 0 ] == 'N' && yylval_ptr->string[ 1 ] == 'I' && yylval_ptr->string[ 2 ] == 'L' ) return NIL; } else /* nLen >= 4 */ { switch( yylval_ptr->string[ 0 ] ) { case '_': if( nLen <= 6 && memcmp( "FIELD", yylval_ptr->string + 1, nLen - 1 ) == 0 ) { hb_lexSkipBlank( pLex ); if( pLex->nSrc + 1 < pLex->nLen && pLex->pString[ pLex->nSrc ] == '-' && pLex->pString[ pLex->nSrc + 1 ] == '>' ) return FIELD; } break; case 'F': if( nLen <= 5 && memcmp( "IELD", yylval_ptr->string + 1, nLen - 1 ) == 0 ) { hb_lexSkipBlank( pLex ); if( pLex->nSrc + 1 < pLex->nLen && pLex->pString[ pLex->nSrc ] == '-' && pLex->pString[ pLex->nSrc + 1 ] == '>' ) return FIELD; } break; case 'Q': if( nLen == 5 && memcmp( "SELF", yylval_ptr->string + 1, 4 ) == 0 ) { hb_lexSkipBlank( pLex ); if( pLex->nSrc < pLex->nLen && pLex->pString[ pLex->nSrc ] == '(' ) { HB_SIZE n = pLex->nSrc; while( ++n < pLex->nLen ) { if( pLex->pString[ n ] == ')' ) { pLex->nSrc = n + 1; return SELF; } else if( pLex->pString[ n ] != ' ' && pLex->pString[ n ] != '\t' ) break; } } } break; } if( pLex->pDst - yylval_ptr->string > HB_SYMBOL_NAME_LEN + 1 ) ( ( char * ) yylval_ptr->string )[ HB_SYMBOL_NAME_LEN ] = '\0'; } return IDENTIFIER; } return ch; } } return 0; }
HB_BOOL hb_timeStampStrGet( const char * szDateTime, int * piYear, int * piMonth, int * piDay, int * piHour, int * piMinutes, int * piSeconds, int * piMSec ) { int iYear, iMonth, iDay; HB_BOOL fValid; HB_TRACE( HB_TR_DEBUG, ( "hb_timeStampStrGet(%s, %p, %p, %p, %p, %p, %p, %p)", szDateTime, piYear, piMonth, piDay, piHour, piMinutes, piSeconds, piMSec ) ); iYear = iMonth = iDay = 0; fValid = HB_FALSE; if( szDateTime ) { while( HB_ISSPACE( *szDateTime ) ) ++szDateTime; if( HB_ISDIGIT( szDateTime[ 0 ] ) && HB_ISDIGIT( szDateTime[ 1 ] ) && HB_ISDIGIT( szDateTime[ 2 ] ) && HB_ISDIGIT( szDateTime[ 3 ] ) && ( szDateTime[ 4 ] == '-' || szDateTime[ 4 ] == '/' || szDateTime[ 4 ] == '.' ) && HB_ISDIGIT( szDateTime[ 5 ] ) && HB_ISDIGIT( szDateTime[ 6 ] ) && szDateTime[ 7 ] == szDateTime[ 4 ] && HB_ISDIGIT( szDateTime[ 9 ] ) && HB_ISDIGIT( szDateTime[ 9 ] ) && ! HB_ISDIGIT( szDateTime[ 10 ] ) ) { iYear = ( ( ( int ) ( szDateTime[ 0 ] - '0' ) * 10 + ( int ) ( szDateTime[ 1 ] - '0' ) ) * 10 + ( int ) ( szDateTime[ 2 ] - '0' ) ) * 10 + ( int ) ( szDateTime[ 3 ] - '0' ); iMonth = ( szDateTime[ 5 ] - '0' ) * 10 + ( szDateTime[ 6 ] - '0' ); iDay = ( szDateTime[ 8 ] - '0' ) * 10 + ( szDateTime[ 9 ] - '0' ); if( hb_dateEncode( iYear, iMonth, iDay ) != 0 || ( iYear == 0 && iMonth == 0 && iDay == 0 ) ) { szDateTime += 10; if( *szDateTime == 'T' || *szDateTime == 't' ) { if( HB_ISDIGIT( szDateTime[ 1 ] ) ) ++szDateTime; } else { if( *szDateTime == ',' ) ++szDateTime; while( HB_ISSPACE( *szDateTime ) ) ++szDateTime; if( *szDateTime == '\0' ) szDateTime = NULL; fValid = HB_TRUE; } } else { iYear = iMonth = iDay = 0; szDateTime = NULL; } } } if( piHour || piMinutes || piSeconds || piMSec ) { if( ! hb_timeStrGet( szDateTime, piHour, piMinutes, piSeconds, piMSec ) ) { if( szDateTime ) fValid = HB_FALSE; } else fValid = HB_TRUE; } else if( szDateTime ) fValid = HB_FALSE; if( piYear ) *piYear = iYear; if( piMonth ) *piMonth = iMonth; if( piDay ) *piDay = iDay; return fValid; }
static HB_ERRCODE ocilibGoTo( SQLBASEAREAP pArea, HB_ULONG ulRecNo ) { OCI_Statement * st = ( ( SDDDATA * ) pArea->pSDDData )->pStmt; OCI_Resultset * rs = OCI_GetResultset( st ); while( ulRecNo > pArea->ulRecCount && ! pArea->fFetched ) { PHB_ITEM pArray; HB_USHORT ui; if( ! OCI_FetchNext( rs ) ) { pArea->fFetched = HB_TRUE; break; } pArray = hb_itemArrayNew( pArea->area.uiFieldCount ); for( ui = 1; ui <= pArea->area.uiFieldCount; ++ui ) { PHB_ITEM pItem = NULL; LPFIELD pField = pArea->area.lpFields + ui - 1; switch( pField->uiType ) { case HB_FT_STRING: if( OCI_IsNull( rs, ui ) ) { char * pStr = ( char * ) hb_xgrab( ( HB_SIZE ) pField->uiLen + 1 ); memset( pStr, ' ', pField->uiLen ); pStr[ pField->uiLen ] = '\0'; pItem = hb_itemPutCLPtr( NULL, pStr, pField->uiLen ); } else { const dtext * val; if( ( val = OCI_GetString( rs, ui ) ) != NULL ) pItem = D_HB_ITEMPUTSTRLEN( NULL, val, ( HB_SIZE ) dtslen( val ) ); /* TODO: Pad it to pField->uiLen size with spaces? */ } break; case HB_FT_LONG: case HB_FT_INTEGER: if( pField->uiDec == 0 ) #if HB_VMLONG_MAX == INT32_MAX || defined( HB_LONG_LONG_OFF ) pItem = hb_itemPutNIntLen( NULL, OCI_GetInt( rs, ui ), pField->uiLen ); #else pItem = hb_itemPutNIntLen( NULL, OCI_GetBigInt( rs, ui ), pField->uiLen ); #endif else pItem = hb_itemPutNDLen( NULL, OCI_GetDouble( rs, ui ), pField->uiLen, pField->uiDec ); break; case HB_FT_VARLENGTH: case HB_FT_MEMO: { OCI_Long * val = OCI_GetLong( rs, ui ); if( val ) { unsigned int uiSize = OCI_LongGetSize( val ); if( OCI_LongGetType( val ) == OCI_CLONG ) pItem = D_HB_ITEMPUTSTRLEN( NULL, ( D_HB_CHAR * ) OCI_LongGetBuffer( val ), uiSize ); else pItem = hb_itemPutCL( NULL, ( char * ) OCI_LongGetBuffer( val ), uiSize ); } break; } case HB_FT_IMAGE: case HB_FT_BLOB: case HB_FT_OLE: { OCI_Long * val = OCI_GetLong( rs, ui ); if( val ) pItem = hb_itemPutCL( NULL, ( char * ) OCI_LongGetBuffer( val ), OCI_LongGetSize( val ) ); break; } case HB_FT_CURRENCY: case HB_FT_CURDOUBLE: case HB_FT_FLOAT: case HB_FT_DOUBLE: pItem = hb_itemPutNDLen( NULL, OCI_GetDouble( rs, ui ), pField->uiLen, pField->uiDec ); break; case HB_FT_DATE: { OCI_Date * date = OCI_GetDate( rs, ui ); int iYear, iMonth, iDay; if( date && OCI_DateGetDate( date, &iYear, &iMonth, &iDay ) ) pItem = hb_itemPutD( NULL, iYear, iMonth, iDay ); break; } case HB_FT_TIME: { OCI_Date * date = OCI_GetDate( rs, ui ); int iYear, iMonth, iDay, iHour, iMin, iSec; if( date && OCI_DateGetDateTime( date, &iYear, &iMonth, &iDay, &iHour, &iMin, &iSec ) ) pItem = hb_itemPutTDT( NULL, hb_dateEncode( iYear, iMonth, iDay ), hb_timeEncode( iHour, iMin, iSec, 0 ) ); break; } case HB_FT_TIMESTAMP: { OCI_Timestamp * ts = OCI_GetTimestamp( rs, ui ); int iYear, iMonth, iDay, iHour, iMin, iSec, iFSec; if( ts && OCI_TimestampGetDateTime( ts, &iYear, &iMonth, &iDay, &iHour, &iMin, &iSec, &iFSec ) ) pItem = hb_itemPutTDT( NULL, hb_dateEncode( iYear, iMonth, iDay ), hb_timeEncode( iHour, iMin, iSec, iFSec / 1000000 ) ); break; } } if( pItem ) { hb_arraySetForward( pArray, ui, pItem ); hb_itemRelease( pItem ); } } if( pArea->ulRecCount + 1 <= pArea->ulRecMax ) { pArea->pRow = ( void ** ) hb_xrealloc( pArea->pRow, ( pArea->ulRecMax + SQLDD_ROWSET_RESIZE ) * sizeof( void * ) ); pArea->pRowFlags = ( HB_BYTE * ) hb_xrealloc( pArea->pRowFlags, ( pArea->ulRecMax + SQLDD_ROWSET_RESIZE ) * sizeof( HB_BYTE ) ); pArea->ulRecMax += SQLDD_ROWSET_RESIZE; } pArea->ulRecCount++; pArea->pRow[ pArea->ulRecCount ] = pArray; pArea->pRowFlags[ pArea->ulRecCount ] = SQLDD_FLAG_CACHED; }
static int hb_dateUnformatRaw( const char * szDate, const char * szDateFormat, long * plDate ) { int d_value = 0, m_value = 0, y_value = 0; int iSize = 0; HB_TRACE( HB_TR_DEBUG, ( "hb_dateUnformatRaw(%s, %s, %p)", szDate, szDateFormat, plDate ) ); if( szDate ) { int d_pos = 0, m_pos = 0, y_pos = 0; int count, digit, non_digit, size, used; if( ! szDateFormat ) szDateFormat = hb_setGetDateFormat(); size = ( int ) strlen( szDateFormat ); for( count = used = 0; count < size && used < 3; count++ ) { switch( szDateFormat[ count ] ) { case 'D': case 'd': if( d_pos == 0 ) { ++used; if( m_pos == 0 && y_pos == 0 ) d_pos = 1; else if( m_pos == 0 || y_pos == 0 ) d_pos = 2; else d_pos = 3; } break; case 'M': case 'm': if( m_pos == 0 ) { ++used; if( d_pos == 0 && y_pos == 0 ) m_pos = 1; else if( d_pos == 0 || y_pos == 0 ) m_pos = 2; else m_pos = 3; } break; case 'Y': case 'y': if( y_pos == 0 ) { ++used; if( m_pos == 0 && d_pos == 0 ) y_pos = 1; else if( m_pos == 0 || d_pos == 0 ) y_pos = 2; else y_pos = 3; } } } /* If there are non-digits at the start of the date field, they are not to be treated as date field separators */ non_digit = 1; size = ( int ) strlen( szDate ); for( count = used = 0; count < size; count++ ) { digit = szDate[ count ]; if( HB_ISDIGIT( digit ) ) { /* Process the digit for the current date field */ if( d_pos == 1 ) d_value = ( d_value * 10 ) + digit - '0'; else if( m_pos == 1 ) m_value = ( m_value * 10 ) + digit - '0'; else if( y_pos == 1 ) y_value = ( y_value * 10 ) + digit - '0'; /* Treat the next non-digit as a date field separator */ non_digit = 0; } else { /* Process the non-digit */ if( non_digit == 0 ) { /* Only move to the next date field on the first consecutive non-digit that is encountered */ non_digit = 1; d_pos--; m_pos--; y_pos--; if( ++used >= 3 ) break; } } } iSize = count; y_value = hb_setUpdateEpoch( y_value ); } *plDate = hb_dateEncode( y_value, m_value, d_value ); return iSize; }
static HB_BOOL hb_fsFindNextLow( PHB_FFIND ffind ) { HB_BOOL bFound; int iYear = 0; int iMonth = 0; int iDay = 0; int iHour = 0; int iMin = 0; int iSec = 0; int iMSec = 0; HB_FATTR raw_attr = 0, nAttr = 0; /* Set the default values in case some platforms don't support some of these, or they may fail on them. */ ffind->szName[ 0 ] = '\0'; ffind->size = 0; /* Do platform dependant first/next search */ hb_vmUnlock(); #if defined( HB_OS_DOS ) { PHB_FFIND_INFO info = ( PHB_FFIND_INFO ) ffind->info; /* Handling HB_FA_LABEL doesn't need any special tricks under the MS-DOS platform. */ if( ffind->bFirst ) { ffind->bFirst = HB_FALSE; /* tzset(); */ #if defined( __WATCOMC__ ) bFound = ( _dos_findfirst( ffind->pszFileMask, ( HB_USHORT ) hb_fsAttrToRaw( ffind->attrmask ), &info->entry ) == 0 ); #else bFound = ( findfirst( ffind->pszFileMask, &info->entry, ( HB_USHORT ) hb_fsAttrToRaw( ffind->attrmask ) ) == 0 ); #endif } else { #if defined( __WATCOMC__ ) bFound = ( _dos_findnext( &info->entry ) == 0 ); #else bFound = ( findnext( &info->entry ) == 0 ); #endif } /* Fill Harbour found file info */ if( bFound ) { hb_strncpy( ffind->szName, info->entry.ff_name, sizeof( ffind->szName ) - 1 ); ffind->size = info->entry.ff_fsize; raw_attr = info->entry.ff_attrib; { time_t ftime; struct tm * ft; struct stat sStat; stat( info->entry.ff_name, &sStat ); ftime = sStat.st_mtime; ft = localtime( &ftime ); iYear = ft->tm_year + 1900; iMonth = ft->tm_mon + 1; iDay = ft->tm_mday; iHour = ft->tm_hour; iMin = ft->tm_min; iSec = ft->tm_sec; } } hb_fsSetIOError( bFound, 0 ); } #elif defined( HB_OS_OS2 ) { #define HB_OS2_DIRCNT 16 PHB_FFIND_INFO info = ( PHB_FFIND_INFO ) ffind->info; APIRET ret = NO_ERROR; /* TODO: HB_FA_LABEL handling */ if( ffind->bFirst ) { ffind->bFirst = HB_FALSE; info->isWSeB = hb_isWSeB(); info->findSize = sizeof( FILEFINDBUF3L ); if( info->findSize & 0x07 ) info->findSize += 0x08 - ( info->findSize & 0x07 ); info->findSize *= HB_OS2_DIRCNT; if( info->findSize > 0xF000 ) info->findSize = 0xF000; info->findInitCnt = ! info->isWSeB ? info->findSize / 32 : HB_OS2_DIRCNT; info->hFindFile = HDIR_CREATE; info->findCount = info->findInitCnt; ret = DosAllocMem( &info->entry, info->findSize, OBJ_TILE | PAG_COMMIT | PAG_WRITE ); if( ret == NO_ERROR ) { ret = DosFindFirst( ( PCSZ ) ffind->pszFileMask, &info->hFindFile, ( ULONG ) hb_fsAttrToRaw( ffind->attrmask ), info->entry, info->findSize, &info->findCount, FIL_STANDARDL ); bFound = ret == NO_ERROR && info->findCount > 0; if( bFound ) info->next = info->entry; } else { info->entry = NULL; bFound = HB_FALSE; } } else if( info->findCount == 0 ) { info->findCount = info->findInitCnt; ret = DosFindNext( info->hFindFile, info->entry, info->findSize, &info->findCount ); bFound = ret == NO_ERROR && info->findCount > 0; if( bFound ) info->next = info->entry; } else bFound = HB_TRUE; if( bFound ) { ULONG oNextEntryOffset; if( info->isWSeB ) { PFILEFINDBUF3L pFFB = ( PFILEFINDBUF3L ) info->next; hb_strncpy( ffind->szName, pFFB->achName, sizeof( ffind->szName ) - 1 ); ffind->size = ( HB_FOFFSET ) pFFB->cbFile; raw_attr = pFFB->attrFile; iYear = pFFB->fdateLastWrite.year + 1980; iMonth = pFFB->fdateLastWrite.month; iDay = pFFB->fdateLastWrite.day; iHour = pFFB->ftimeLastWrite.hours; iMin = pFFB->ftimeLastWrite.minutes; iSec = pFFB->ftimeLastWrite.twosecs * 2; oNextEntryOffset = pFFB->oNextEntryOffset; } else { PFILEFINDBUF3 pFFB = ( PFILEFINDBUF3 ) info->next; hb_strncpy( ffind->szName, pFFB->achName, sizeof( ffind->szName ) - 1 ); ffind->size = ( HB_FOFFSET ) pFFB->cbFile; raw_attr = pFFB->attrFile; iYear = pFFB->fdateLastWrite.year + 1980; iMonth = pFFB->fdateLastWrite.month; iDay = pFFB->fdateLastWrite.day; iHour = pFFB->ftimeLastWrite.hours; iMin = pFFB->ftimeLastWrite.minutes; iSec = pFFB->ftimeLastWrite.twosecs * 2; oNextEntryOffset = pFFB->oNextEntryOffset; } if( oNextEntryOffset > 0 ) { info->next = ( char * ) info->next + oNextEntryOffset; info->findCount--; } else info->findCount = 0; } hb_fsSetError( ( HB_ERRCODE ) ret ); } #elif defined( HB_OS_WIN ) { PHB_FFIND_INFO info = ( PHB_FFIND_INFO ) ffind->info; bFound = HB_FALSE; #if ! defined( HB_OS_WIN_CE ) if( ( ffind->attrmask & HB_FA_LABEL ) != 0 && ! info->fLabelDone ) { TCHAR lpVolName[ HB_PATH_MAX ]; LPTSTR lpFileMask = NULL; char * mask = NULL; info->fLabelDone = HB_TRUE; if( ffind->pszFileMask && *ffind->pszFileMask ) { PHB_FNAME pFileName = hb_fsFNameSplit( ffind->pszFileMask ); if( pFileName->szName && pFileName->szName[ 0 ] ) mask = hb_strdup( pFileName->szName ); if( pFileName->szPath && pFileName->szPath[ 0 ] && ( pFileName->szPath[ 1 ] || pFileName->szPath[ 0 ] != HB_OS_PATH_DELIM_CHR ) ) lpFileMask = HB_CHARDUP( pFileName->szPath ); hb_xfree( pFileName ); } bFound = GetVolumeInformation( lpFileMask, lpVolName, HB_SIZEOFARRAY( lpVolName ), NULL, NULL, NULL, NULL, 0 ) != 0; if( bFound ) { HB_OSSTRDUP2( lpVolName, ffind->szName, sizeof( ffind->szName ) - 1 ); if( mask && *mask && ! hb_strMatchFile( ffind->szName, mask ) ) { ffind->szName[ 0 ] = '\0'; bFound = HB_FALSE; } } if( lpFileMask ) hb_xfree( lpFileMask ); if( mask ) hb_xfree( mask ); } #endif if( ! bFound && ( ffind->attrmask & ( HB_FA_LABEL | HB_FA_HIDDEN | HB_FA_SYSTEM | HB_FA_DIRECTORY ) ) != HB_FA_LABEL ) { if( ffind->bFirst ) { LPTSTR lpFileMask = HB_CHARDUP( ffind->pszFileMask ); ffind->bFirst = HB_FALSE; info->dwAttr = ( DWORD ) hb_fsAttrToRaw( ffind->attrmask ); info->hFindFile = FindFirstFile( lpFileMask, &info->pFindFileData ); hb_xfree( lpFileMask ); if( ( info->hFindFile != INVALID_HANDLE_VALUE ) && _HB_WIN_MATCH() ) bFound = HB_TRUE; } if( ! bFound && info->hFindFile != INVALID_HANDLE_VALUE ) { while( FindNextFile( info->hFindFile, &info->pFindFileData ) ) { if( _HB_WIN_MATCH() ) { bFound = HB_TRUE; break; } } } /* Fill Harbour found file info */ if( bFound ) { HB_OSSTRDUP2( info->pFindFileData.cFileName, ffind->szName, sizeof( ffind->szName ) - 1 ); if( info->pFindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) ffind->size = 0; else { #if defined( __XCC__ ) || ( defined( __POCC__ ) && __POCC__ >= 500 ) /* NOTE: PellesC 5.00.1 will go into an infinite loop if we don't split this into two operations. [vszakats] */ ffind->size = ( HB_FOFFSET ) info->pFindFileData.nFileSizeLow; ffind->size += ( HB_FOFFSET ) info->pFindFileData.nFileSizeHigh << 32; #else ffind->size = ( HB_FOFFSET ) info->pFindFileData.nFileSizeLow + ( ( HB_FOFFSET ) info->pFindFileData.nFileSizeHigh << 32 ); #endif } raw_attr = ( HB_FATTR ) info->pFindFileData.dwFileAttributes; /* NOTE: One of these may fail when searching on an UNC path, I don't know yet what's the reason. [vszakats] */ { FILETIME ft; SYSTEMTIME time; if( FileTimeToLocalFileTime( &info->pFindFileData.ftLastWriteTime, &ft ) && FileTimeToSystemTime( &ft, &time ) ) { iYear = time.wYear; iMonth = time.wMonth; iDay = time.wDay; iHour = time.wHour; iMin = time.wMinute; iSec = time.wSecond; iMSec = time.wMilliseconds; } } } } hb_fsSetIOError( bFound, 0 ); } #elif defined( HB_OS_UNIX ) { PHB_FFIND_INFO info = ( PHB_FFIND_INFO ) ffind->info; char dirname[ HB_PATH_MAX ]; bFound = HB_FALSE; /* TODO: HB_FA_LABEL handling */ if( ffind->bFirst ) { char * pos; ffind->bFirst = HB_FALSE; hb_strncpy( dirname, ffind->pszFileMask, sizeof( dirname ) - 1 ); pos = strrchr( dirname, HB_OS_PATH_DELIM_CHR ); if( pos ) { hb_strncpy( info->pattern, pos + 1, sizeof( info->pattern ) - 1 ); *( pos + 1 ) = '\0'; } else { hb_strncpy( info->pattern, dirname, sizeof( info->pattern ) - 1 ); dirname[ 0 ] = '.'; dirname[ 1 ] = HB_OS_PATH_DELIM_CHR; dirname[ 2 ] = '\0'; } /* tzset(); */ info->dir = opendir( dirname ); hb_strncpy( info->path, dirname, sizeof( info->path ) - 1 ); } if( info->dir && info->pattern[ 0 ] != '\0' ) { while( ( info->entry = readdir( info->dir ) ) != NULL ) { if( hb_strMatchFile( info->entry->d_name, info->pattern ) ) { bFound = HB_TRUE; break; } } } /* Fill Harbour found file info */ if( bFound ) { hb_strncpy( dirname, info->path, sizeof( dirname ) - 1 ); hb_strncat( dirname, info->entry->d_name, sizeof( dirname ) - 1 ); { time_t ftime; struct tm lt; #if defined( HB_USE_LARGEFILE64 ) struct stat64 sStat, sStatL; if( lstat64( dirname, &sStat ) == 0 ) { if( S_ISLNK( sStat.st_mode ) && ( ffind->attrmask & HB_FA_LINK ) == 0 ) { if( stat64( dirname, &sStatL ) == 0 ) memcpy( &sStat, &sStatL, sizeof( sStat ) ); nAttr |= HB_FA_LINK; } #else struct stat sStat, sStatL; if( lstat( dirname, &sStat ) == 0 ) { if( S_ISLNK( sStat.st_mode ) && ( ffind->attrmask & HB_FA_LINK ) == 0 ) { if( stat( dirname, &sStatL ) == 0 ) memcpy( &sStat, &sStatL, sizeof( sStat ) ); nAttr |= HB_FA_LINK; } #endif hb_strncpy( ffind->szName, info->entry->d_name, sizeof( ffind->szName ) - 1 ); ffind->size = sStat.st_size; raw_attr = sStat.st_mode; ftime = sStat.st_mtime; # if defined( HB_HAS_LOCALTIME_R ) localtime_r( &ftime, < ); # else lt = *localtime( &ftime ); # endif iYear = lt.tm_year + 1900; iMonth = lt.tm_mon + 1; iDay = lt.tm_mday; iHour = lt.tm_hour; iMin = lt.tm_min; iSec = lt.tm_sec; # if defined( HB_OS_LINUX ) && \ defined( __GLIBC__ ) && defined( __GLIBC_MINOR__ ) && \ ( __GLIBC__ > 2 || ( __GLIBC__ == 2 && __GLIBC_MINOR__ >= 6 ) ) # if defined( _BSD_SOURCE ) || defined( _SVID_SOURCE ) || \ ( __GLIBC_MINOR__ >= 12 && \ ( ( defined( _POSIX_C_SOURCE ) || _POSIX_C_SOURCE >= 200809L ) || \ ( defined( _XOPEN_SOURCE ) || _XOPEN_SOURCE >= 700 ) ) ) iMSec = sStat.st_mtim.tv_nsec / 1000000; # else iMSec = sStat.st_mtimensec / 1000000; # endif # endif } else bFound = HB_FALSE; } } hb_fsSetIOError( bFound, 0 ); } #else { int iTODO; /* TODO: for given platform */ /* HB_SYMBOL_UNUSED( ffind ); */ HB_SYMBOL_UNUSED( iYear ); HB_SYMBOL_UNUSED( iMonth ); HB_SYMBOL_UNUSED( iDay ); HB_SYMBOL_UNUSED( iHour ); HB_SYMBOL_UNUSED( iMin ); HB_SYMBOL_UNUSED( iSec ); HB_SYMBOL_UNUSED( iMSec ); HB_SYMBOL_UNUSED( raw_attr ); bFound = HB_FALSE; hb_fsSetIOError( bFound, 0 ); } #endif /* Fill common Harbour found file info */ if( bFound ) { /* Do the conversions common for all platforms */ ffind->szName[ sizeof( ffind->szName ) - 1 ] = '\0'; #if ! defined( HB_OS_WIN ) /* Convert from OS codepage */ { char * pszFree = NULL; HB_SIZE nSize = sizeof( ffind->szName ); const char * pszResult = hb_osDecodeCP( ffind->szName, &pszFree, &nSize ); if( pszFree ) { hb_strncpy( ffind->szName, pszResult, sizeof( ffind->szName ) - 1 ); hb_xfree( pszFree ); } } #endif ffind->attr = hb_fsAttrFromRaw( raw_attr ) | nAttr; ffind->lDate = hb_dateEncode( iYear, iMonth, iDay ); ffind->lTime = hb_timeEncode( iHour, iMin, iSec, iMSec ); hb_dateStrPut( ffind->szDate, iYear, iMonth, iDay ); ffind->szDate[ 8 ] = '\0'; hb_snprintf( ffind->szTime, sizeof( ffind->szTime ), "%02d:%02d:%02d", iHour, iMin, iSec ); } hb_vmLock(); return bFound; } PHB_FFIND hb_fsFindFirst( const char * pszFileMask, HB_FATTR attrmask ) { PHB_FFIND ffind = ( PHB_FFIND ) hb_xgrabz( sizeof( HB_FFIND ) ); /* Allocate platform dependent file find info storage */ ffind->info = ( void * ) hb_xgrabz( sizeof( HB_FFIND_INFO ) ); /* Store search parameters */ #if defined( HB_OS_WIN ) ffind->pszFileMask = pszFileMask; #else /* Convert to OS codepage */ ffind->pszFileMask = hb_fsNameConv( pszFileMask, &ffind->pszFree ); #endif ffind->attrmask = attrmask; ffind->bFirst = HB_TRUE; /* Find first/next matching file */ if( hb_fsFindNext( ffind ) ) return ffind; /* If no file found at all, free stuff allocated so far and return NULL. */ hb_fsFindClose( ffind ); return NULL; }
static BOOL hb_fsFileStats( BYTE * pszFileName, BYTE * pszAttr, HB_FOFFSET * llSize, LONG * lcDate, LONG * lcTime, LONG * lmDate, LONG * lmTime ) { BOOL fResult = FALSE; #if defined( HB_OS_UNIX ) struct stat statbuf; if( stat( ( char * ) pszFileName, &statbuf ) == 0 ) { // determine if we can read/write/execute the file USHORT usAttr, ushbAttr = 0; time_t ftime; #if _POSIX_C_SOURCE >= 199506L struct tm tms; #endif struct tm * ptms; /* See which attribs are applicable */ if( statbuf.st_uid == geteuid() ) { usAttr = ( ( statbuf.st_mode & S_IRUSR ) ? 1 << 2 : 0 ) | ( ( statbuf.st_mode & S_IWUSR ) ? 1 << 1 : 0 ) | ( ( statbuf.st_mode & S_IXUSR ) ? 1 : 0 ); } else if( statbuf.st_gid == getegid() ) { usAttr = ( ( statbuf.st_mode & S_IRGRP ) ? 1 << 2 : 0 ) | ( ( statbuf.st_mode & S_IWGRP ) ? 1 << 1 : 0 ) | ( ( statbuf.st_mode & S_IXGRP ) ? 1 : 0 ); } else { usAttr = ( ( statbuf.st_mode & S_IROTH ) ? 1 << 2 : 0 ) | ( ( statbuf.st_mode & S_IWOTH ) ? 1 << 1 : 0 ) | ( ( statbuf.st_mode & S_IXOTH ) ? 1 : 0 ); } /* Standard characters */ if( ( usAttr & 4 ) == 0 ) /* Hidden (can't read)*/ ushbAttr |= HB_FA_HIDDEN; if( ( usAttr & 2 ) == 0 ) /* read only (can't write)*/ ushbAttr |= HB_FA_READONLY; if( ( usAttr & 1 ) == 1 ) /* executable? (xbit)*/ ushbAttr |= HB_FA_SYSTEM; /* Extension characters */ if( ( statbuf.st_mode & S_IFLNK ) == S_IFLNK ) *pszAttr++ = 'Z'; /* Xharbour extension */ if( ( statbuf.st_mode & S_IFSOCK ) == S_IFSOCK ) *pszAttr++ = 'K'; /* Xharbour extension */ /* device */ if( ( statbuf.st_mode & S_IFBLK ) == S_IFBLK || ( statbuf.st_mode & S_IFCHR ) == S_IFCHR ) ushbAttr |= HB_FA_DEVICE; /* Xharbour extension */ if( ( statbuf.st_mode & S_IFIFO ) == S_IFIFO ) *pszAttr++ = 'Y'; /* Xharbour extension */ if( S_ISDIR( statbuf.st_mode ) ) ushbAttr |= HB_FA_DIRECTORY; /* Xharbour extension */ /* Give the ARCHIVE if readwrite, not executable and not special */ else if( S_ISREG( statbuf.st_mode ) && ushbAttr == 0 ) ushbAttr |= HB_FA_ARCHIVE; *llSize = ( HB_FOFFSET ) statbuf.st_size; ftime = statbuf.st_mtime; #if _POSIX_C_SOURCE >= 199506L && ! defined( HB_OS_DARWIN_5 ) ptms = localtime_r( &ftime, &tms ); #else ptms = localtime( &ftime ); #endif *lcDate = hb_dateEncode( ptms->tm_year + 1900, ptms->tm_mon + 1, ptms->tm_mday ); *lcTime = ptms->tm_hour * 3600 + ptms->tm_min * 60 + ptms->tm_sec; ftime = statbuf.st_atime; #if _POSIX_C_SOURCE >= 199506L && ! defined( HB_OS_DARWIN_5 ) ptms = localtime_r( &ftime, &tms ); #else ptms = localtime( &ftime ); #endif *lmDate = hb_dateEncode( ptms->tm_year + 1900, ptms->tm_mon + 1, ptms->tm_mday ); *lmTime = ptms->tm_hour * 3600 + ptms->tm_min * 60 + ptms->tm_sec; hb_fsAttrDecode( ushbAttr, ( char * ) pszAttr ); fResult = TRUE; } #elif defined( HB_OS_WIN ) { DWORD dwAttribs; WIN32_FIND_DATAA ffind; HANDLE hFind; FILETIME filetime; SYSTEMTIME time; /* Get attributes... */ dwAttribs = GetFileAttributesA( ( char * ) pszFileName ); if( dwAttribs == INVALID_FILE_ATTRIBUTES ) { /* return */ return FALSE; } hb_fsAttrDecode( hb_fsAttrFromRaw( dwAttribs ), ( char * ) pszAttr ); /* If file existed, do a findfirst */ hFind = FindFirstFileA( ( char * ) pszFileName, &ffind ); if( hFind != INVALID_HANDLE_VALUE ) { FindClose( hFind ); /* get file times and work them out */ *llSize = ( HB_FOFFSET ) ffind.nFileSizeLow + ( ( HB_FOFFSET ) ffind.nFileSizeHigh << 32 ); if( FileTimeToLocalFileTime( &ffind.ftCreationTime, &filetime ) && FileTimeToSystemTime( &filetime, &time ) ) { *lcDate = hb_dateEncode( time.wYear, time.wMonth, time.wDay ); *lcTime = time.wHour * 3600 + time.wMinute * 60 + time.wSecond; } else { *lcDate = hb_dateEncode( 0, 0, 0 ); *lcTime = 0; } if( FileTimeToLocalFileTime( &ffind.ftLastAccessTime, &filetime ) && FileTimeToSystemTime( &filetime, &time ) ) { *lmDate = hb_dateEncode( time.wYear, time.wMonth, time.wDay ); *lmTime = time.wHour * 3600 + time.wMinute * 60 + time.wSecond; } else { *lcDate = hb_dateEncode( 0, 0, 0 ); *lcTime = 0; } fResult = TRUE; } } #else /* Generic algorithm based on findfirst */ { PHB_FFIND findinfo = hb_fsFindFirst( ( char * ) pszFileName, HB_FA_ALL ); if( findinfo ) { hb_fsAttrDecode( findinfo->attr, ( char * ) pszAttr ); *llSize = ( HB_FOFFSET ) findinfo->size; *lcDate = findinfo->lDate; *lcTime = ( findinfo->szTime[ 0 ] - '0' ) * 36000 + ( findinfo->szTime[ 1 ] - '0' ) * 3600 + ( findinfo->szTime[ 3 ] - '0' ) * 600 + ( findinfo->szTime[ 4 ] - '0' ) * 60 + ( findinfo->szTime[ 6 ] - '0' ) * 10 + ( findinfo->szTime[ 7 ] - '0' ); *lmDate = hb_dateEncode( 0, 0, 0 ); *lmTime = 0; hb_fsFindClose( findinfo ); fResult = TRUE; } } #endif hb_fsSetIOError( fResult, 0 ); return fResult; }
static HB_ERRCODE odbcGoTo( SQLBASEAREAP pArea, HB_ULONG ulRecNo ) { SQLHSTMT hStmt; SQLRETURN res; SQLLEN iLen; PHB_ITEM pArray, pItem; LPFIELD pField; HB_USHORT ui; /* No pArea->pSDDData for DBCreate() area... * though pArea->fFetched == HB_TRUE for them */ hStmt = pArea->pSDDData ? ( ( SDDDATA * ) pArea->pSDDData )->hStmt : NULL; while( ulRecNo > pArea->ulRecCount && ! pArea->fFetched ) { if( ! SQL_SUCCEEDED( SQLFetch( hStmt ) ) ) { pArea->fFetched = HB_TRUE; break; } pArray = hb_itemArrayNew( pArea->area.uiFieldCount ); pItem = NULL; for( ui = 1; ui <= pArea->area.uiFieldCount; ui++ ) { iLen = SQL_NULL_DATA; res = 0; pField = pArea->area.lpFields + ui - 1; switch( pField->uiType ) { case HB_FT_STRING: if( pField->uiType & HB_FF_BINARY ) { char buffer[ 1 ]; iLen = 0; if( SQL_SUCCEEDED( res = SQLGetData( hStmt, ui, SQL_C_BINARY, buffer, 0, &iLen ) ) ) { if( iLen >= 0 ) { char * val = ( char * ) hb_xgrab( iLen + 1 ); if( SQL_SUCCEEDED( res = SQLGetData( hStmt, ui, SQL_C_BINARY, val, iLen + 1, &iLen ) ) ) pItem = hb_itemPutCLPtr( pItem, val, ( HB_SIZE ) iLen ); else hb_xfree( val ); } } } else { O_HB_CHAR buffer[ 1 ]; #if defined( UNICODE ) SQLSMALLINT iTargetType = SQL_C_WCHAR; #else SQLSMALLINT iTargetType = SQL_C_CHAR; #endif iLen = 0; if( SQL_SUCCEEDED( res = SQLGetData( hStmt, ui, iTargetType, buffer, 0, &iLen ) ) ) { if( iLen >= 0 ) { O_HB_CHAR * val = ( O_HB_CHAR * ) hb_xgrab( iLen + sizeof( O_HB_CHAR ) ); if( SQL_SUCCEEDED( res = SQLGetData( hStmt, ui, iTargetType, val, iLen + sizeof( O_HB_CHAR ), &iLen ) ) ) { #if defined( UNICODE ) iLen >>= 1; #endif pItem = O_HB_ITEMPUTSTRLEN( pItem, val, ( HB_SIZE ) iLen ); } hb_xfree( val ); } } } break; case HB_FT_INTEGER: #if ODBCVER >= 0x0300 if( pField->uiTypeExtended == ( HB_USHORT ) SQL_BIGINT ) { HB_I64 val = 0; /* NOTE: SQL_C_SBIGINT not available before ODBC 3.0 */ if( SQL_SUCCEEDED( res = SQLGetData( hStmt, ui, SQL_C_SBIGINT, &val, sizeof( val ), &iLen ) ) ) pItem = hb_itemPutNIntLen( pItem, val, pField->uiLen ); } else #endif { SQLINTEGER val = 0; if( SQL_SUCCEEDED( res = SQLGetData( hStmt, ui, SQL_C_LONG, &val, sizeof( val ), &iLen ) ) ) pItem = hb_itemPutNLLen( pItem, val, pField->uiLen ); } break; case HB_FT_LONG: if( pField->uiDec == 0 && pField->uiLen < 10 ) { SQLINTEGER val = 0; if( SQL_SUCCEEDED( res = SQLGetData( hStmt, ui, SQL_C_LONG, &val, sizeof( val ), &iLen ) ) ) pItem = hb_itemPutNLLen( pItem, val, pField->uiLen ); } else { double val = 0.0; if( SQL_SUCCEEDED( res = SQLGetData( hStmt, ui, SQL_C_DOUBLE, &val, sizeof( val ), &iLen ) ) ) pItem = hb_itemPutNDLen( pItem, val, pField->uiLen, pField->uiDec ); } break; case HB_FT_DOUBLE: { double val = 0.0; if( SQL_SUCCEEDED( res = SQLGetData( hStmt, ui, SQL_C_DOUBLE, &val, sizeof( val ), &iLen ) ) ) pItem = hb_itemPutNDLen( pItem, val, pField->uiLen, pField->uiDec ); break; } case HB_FT_LOGICAL: { unsigned char val = 0; if( SQL_SUCCEEDED( res = SQLGetData( hStmt, ui, SQL_C_BIT, &val, sizeof( val ), &iLen ) ) ) pItem = hb_itemPutL( pItem, val != 0 ); break; } case HB_FT_DATE: { DATE_STRUCT val = { 0, 0, 0 }; if( SQL_SUCCEEDED( res = SQLGetData( hStmt, ui, SQL_C_DATE, &val, sizeof( val ), &iLen ) ) ) pItem = hb_itemPutD( pItem, val.year, val.month, val.day ); break; } case HB_FT_TIME: { TIME_STRUCT val = { 0, 0, 0 }; if( SQL_SUCCEEDED( res = SQLGetData( hStmt, ui, SQL_C_TIME, &val, sizeof( val ), &iLen ) ) ) pItem = hb_itemPutTDT( pItem, 0, hb_timeEncode( val.hour, val.minute, val.second, 0 ) ); break; } case HB_FT_TIMESTAMP: { TIMESTAMP_STRUCT val = { 0, 0, 0, 0, 0, 0, 0 }; if( SQL_SUCCEEDED( res = SQLGetData( hStmt, ui, SQL_C_TIMESTAMP, &val, sizeof( val ), &iLen ) ) ) pItem = hb_itemPutTDT( pItem, hb_dateEncode( val.year, val.month, val.day ), hb_timeEncode( val.hour, val.minute, val.second, val.fraction / 1000000 ) ); break; } } /* TODO: check SQL_SUCCEEDED( res ) */ /* TODO: check for SQL_NO_TOTAL. What does this mean? */ HB_SYMBOL_UNUSED( res ); if( pItem ) { /* NULL -> NIL */ if( iLen == SQL_NULL_DATA ) hb_itemClear( pItem ); else hb_arraySetForward( pArray, ui, pItem ); } } if( pItem ) hb_itemRelease( pItem ); if( pArea->ulRecCount + 1 >= pArea->ulRecMax ) { pArea->pRow = ( void ** ) hb_xrealloc( pArea->pRow, ( pArea->ulRecMax + SQLDD_ROWSET_RESIZE ) * sizeof( void * ) ); pArea->pRowFlags = ( HB_BYTE * ) hb_xrealloc( pArea->pRowFlags, ( pArea->ulRecMax + SQLDD_ROWSET_RESIZE ) * sizeof( HB_BYTE ) ); pArea->ulRecMax += SQLDD_ROWSET_RESIZE; } pArea->ulRecCount++; pArea->pRow[ pArea->ulRecCount ] = pArray; pArea->pRowFlags[ pArea->ulRecCount ] = SQLDD_FLAG_CACHED; }