const char * hb_fsNameConv( const char * szFileName, char ** pszFree ) { if( s_fFnTrim || s_cDirSep != HB_OS_PATH_DELIM_CHR || s_iFileCase != HB_SET_CASE_MIXED || s_iDirCase != HB_SET_CASE_MIXED ) { PHB_FNAME pFileName; if( pszFree ) { szFileName = *pszFree = hb_strncpy( ( char * ) hb_xgrab( HB_PATH_MAX ), szFileName, HB_PATH_MAX - 1 ); } if( s_cDirSep != HB_OS_PATH_DELIM_CHR ) { char * p = ( char * ) szFileName; while( *p ) { if( *p == s_cDirSep ) *p = HB_OS_PATH_DELIM_CHR; p++; } } pFileName = hb_fsFNameSplit( szFileName ); /* strip trailing and leading spaces */ if( s_fFnTrim ) { HB_SIZE nLen; if( pFileName->szName ) { nLen = strlen( pFileName->szName ); while( nLen && pFileName->szName[ nLen - 1 ] == ' ' ) --nLen; while( nLen && pFileName->szName[ 0 ] == ' ' ) { ++pFileName->szName; --nLen; } ( ( char * ) pFileName->szName )[ nLen ] = '\0'; } if( pFileName->szExtension ) { nLen = strlen( pFileName->szExtension ); while( nLen && pFileName->szExtension[ nLen - 1 ] == ' ' ) --nLen; while( nLen && pFileName->szExtension[ 0 ] == ' ' ) { ++pFileName->szExtension; --nLen; } ( ( char * ) pFileName->szExtension )[ nLen ] = '\0'; } } /* FILECASE */ if( s_iFileCase == HB_SET_CASE_LOWER ) { if( pFileName->szName ) hb_strlow( ( char * ) pFileName->szName ); if( pFileName->szExtension ) hb_strlow( ( char * ) pFileName->szExtension ); } else if( s_iFileCase == HB_SET_CASE_UPPER ) { if( pFileName->szName ) hb_strupr( ( char * ) pFileName->szName ); if( pFileName->szExtension ) hb_strupr( ( char * ) pFileName->szExtension ); } /* DIRCASE */ if( pFileName->szPath ) { if( s_iDirCase == HB_SET_CASE_LOWER ) hb_strlow( ( char * ) pFileName->szPath ); else if( s_iDirCase == HB_SET_CASE_UPPER ) hb_strupr( ( char * ) pFileName->szPath ); } hb_fsFNameMerge( ( char * ) szFileName, pFileName ); hb_xfree( pFileName ); } else if( pszFree ) *pszFree = NULL; return szFileName; }
/* * Open a data store in the WorkArea. */ static HB_ERRCODE hb_sdfOpen( SDFAREAP pArea, LPDBOPENINFO pOpenInfo ) { PHB_ITEM pError = NULL; PHB_FNAME pFileName; HB_ERRCODE errCode; HB_USHORT uiFlags; HB_BOOL fRetry; char szFileName[ HB_PATH_MAX ]; char szAlias[ HB_RDD_MAX_ALIAS_LEN + 1 ]; HB_TRACE( HB_TR_DEBUG, ( "hb_sdfOpen(%p,%p)", pArea, pOpenInfo ) ); pArea->fShared = HB_TRUE; /* pOpenInfo->fShared; */ pArea->fReadonly = HB_TRUE; /* pOpenInfo->fReadonly; */ if( pOpenInfo->cdpId ) { pArea->area.cdPage = hb_cdpFindExt( pOpenInfo->cdpId ); if( ! pArea->area.cdPage ) pArea->area.cdPage = hb_vmCDP(); } else pArea->area.cdPage = hb_vmCDP(); uiFlags = ( pArea->fReadonly ? FO_READ : FO_READWRITE ) | ( pArea->fShared ? FO_DENYNONE : FO_EXCLUSIVE ); pFileName = hb_fsFNameSplit( pOpenInfo->abName ); /* Add default file name extension if necessary */ if( hb_setGetDefExtension() && ! pFileName->szExtension ) { PHB_ITEM pFileExt = hb_itemPutC( NULL, NULL ); SELF_INFO( &pArea->area, DBI_TABLEEXT, pFileExt ); pFileName->szExtension = hb_itemGetCPtr( pFileExt ); hb_fsFNameMerge( szFileName, pFileName ); hb_itemRelease( pFileExt ); } else { hb_strncpy( szFileName, pOpenInfo->abName, sizeof( szFileName ) - 1 ); } /* Create default alias if necessary */ if( ! pOpenInfo->atomAlias && pFileName->szName ) { const char * szName = strrchr( pFileName->szName, ':' ); if( szName == NULL ) szName = pFileName->szName; else ++szName; hb_strncpyUpperTrim( szAlias, szName, sizeof( szAlias ) - 1 ); pOpenInfo->atomAlias = szAlias; } hb_xfree( pFileName ); /* Try open */ do { pArea->pFile = hb_fileExtOpen( szFileName, NULL, uiFlags | FXO_DEFAULTS | FXO_SHARELOCK | FXO_COPYNAME | FXO_NOSEEKPOS, NULL, pError ); if( ! pArea->pFile ) { if( ! pError ) { pError = hb_errNew(); hb_errPutGenCode( pError, EG_OPEN ); hb_errPutSubCode( pError, EDBF_OPEN_DBF ); hb_errPutOsCode( pError, hb_fsError() ); hb_errPutDescription( pError, hb_langDGetErrorDesc( EG_OPEN ) ); hb_errPutFileName( pError, szFileName ); hb_errPutFlags( pError, EF_CANRETRY | EF_CANDEFAULT ); } fRetry = ( SELF_ERROR( &pArea->area, pError ) == E_RETRY ); } else fRetry = HB_FALSE; } while( fRetry ); if( pError ) hb_itemRelease( pError ); if( ! pArea->pFile ) return HB_FAILURE; errCode = SUPER_OPEN( &pArea->area, pOpenInfo ); if( errCode != HB_SUCCESS ) { SELF_CLOSE( &pArea->area ); return HB_FAILURE; } hb_sdfInitArea( pArea, szFileName ); /* Position cursor at the first record */ return SELF_GOTOP( &pArea->area ); }
/* NOTE: pszTempDir must be at least HB_PATH_MAX long. */ HB_ERRCODE hb_fsTempDir( char * pszTempDir ) { HB_ERRCODE nResult = ( HB_ERRCODE ) FS_ERROR; pszTempDir[ 0 ] = '\0'; #if defined( HB_OS_UNIX ) { char * pszTempDirEnv = hb_getenv( "TMPDIR" ); if( fsGetTempDirByCase( pszTempDir, pszTempDirEnv, HB_FALSE ) ) nResult = 0; #ifdef P_tmpdir else if( fsGetTempDirByCase( pszTempDir, P_tmpdir, HB_TRUE ) ) nResult = 0; #endif else if( fsGetTempDirByCase( pszTempDir, "/tmp", HB_TRUE ) ) nResult = 0; if( pszTempDirEnv ) hb_xfree( pszTempDirEnv ); } #elif defined( HB_OS_WIN ) { TCHAR lpDir[ HB_PATH_MAX ]; if( GetTempPath( HB_PATH_MAX, lpDir ) ) { nResult = 0; lpDir[ HB_PATH_MAX - 1 ] = TEXT( '\0' ); HB_OSSTRDUP2( lpDir, pszTempDir, HB_PATH_MAX - 1 ); } } #else { #if ! defined( HB_OS_OS2 ) char szBuffer[ L_tmpnam ]; if( tmpnam( szBuffer ) != NULL ) { PHB_FNAME pTempName = hb_fsFNameSplit( szBuffer ); if( fsGetTempDirByCase( pszTempDir, pTempName->szPath, HB_TRUE ) ) nResult = 0; hb_xfree( pTempName ); } if( nResult != 0 ) #endif { static const char * env_tmp[] = { "TEMP", "TMP", "TMPDIR", NULL }; const char ** tmp = env_tmp; while( *tmp && nResult != 0 ) { char * pszTempDirEnv = hb_getenv( *tmp++ ); if( pszTempDirEnv ) { if( fsGetTempDirByCase( pszTempDir, pszTempDirEnv, HB_FALSE ) ) nResult = 0; hb_xfree( pszTempDirEnv ); } } } } #endif if( nResult == 0 && pszTempDir[ 0 ] != '\0' ) { int len = ( int ) strlen( pszTempDir ); if( pszTempDir[ len - 1 ] != HB_OS_PATH_DELIM_CHR && len < HB_PATH_MAX - 1 ) { pszTempDir[ len ] = HB_OS_PATH_DELIM_CHR; pszTempDir[ len + 1 ] = '\0'; } } else { pszTempDir[ 0 ] = '.'; pszTempDir[ 1 ] = HB_OS_PATH_DELIM_CHR; pszTempDir[ 2 ] = '\0'; } return nResult; }
int main( int argc, char * argv[] ) { FILE * handl_o; char szFileName[ _POSIX_PATH_MAX + 1 ]; char szPpoName[ _POSIX_PATH_MAX + 1 ]; int iArg = 1; BOOL bOutTable = FALSE; BOOL bOutNew = FALSE; DEFINES * stdef; COMMANDS * stcmd; HB_TRACE(HB_TR_DEBUG, ("main(%d, %p)", argc, argv)); printf( "Harbour Preprocessor (old revision) %d.%d.%d\n", HB_VER_MAJOR, HB_VER_MINOR, HB_VER_REVISION ); printf( "Copyright (c) 1999-2008, http://www.harbour-project.org/\n" ); hb_pp_Table(); stdef = hb_pp_topDefine; stcmd = hb_pp_topCommand; hb_pp_Init(); while( iArg < argc ) { if( HB_ISOPTSEP(argv[ iArg ][ 0 ])) { switch( argv[ iArg ][ 1 ] ) { case 'd': case 'D': /* defines a #define from the command line */ { char *szDefText = hb_strdup( argv[iArg] + 2 ), *pAssign, *sDefLine; unsigned int i = 0; while( i < strlen( szDefText ) && ! HB_ISOPTSEP( szDefText[ i ] ) ) i++; szDefText[ i ] = '\0'; if( szDefText ) { if( ( pAssign = strchr( szDefText, '=' ) ) == NULL ) { hb_pp_AddDefine_( szDefText, 0 ); } else { szDefText[ pAssign - szDefText ] = '\0'; /* hb_pp_AddDefine_( szDefText, pAssign + 1 ); */ sDefLine = hb_xstrcpy( NULL, szDefText, " ", pAssign + 1, NULL ); hb_pp_ParseDefine_( sDefLine ); hb_xfree( sDefLine ); } } hb_xfree( szDefText ); } break; case 'i': case 'I': AddSearchPath( argv[ iArg ]+2, &hb_comp_pIncludePath ); break; case 'o': case 'O': bOutTable = TRUE; break; case 'n': case 'N': bOutNew = TRUE; break; case 'w': case 'W': s_iWarnings = 1; if( argv[ iArg ][ 2 ] ) { /*there is -w<0,1,2,3> probably */ s_iWarnings = argv[ iArg ][ 2 ] - '0'; if( s_iWarnings < 0 || s_iWarnings > 3 ) printf( "\nInvalid command line option: %s\n", argv[ iArg ] ); } break; default: printf( "\nInvalid command line option: %s\n", &argv[ iArg ][ 1 ] ); break; } } else hb_comp_pFileName = hb_fsFNameSplit( argv[ iArg ] ); iArg++; } if( hb_comp_pFileName ) { if( ! hb_comp_pFileName->szExtension ) hb_comp_pFileName->szExtension =".prg"; hb_fsFNameMerge( szFileName, hb_comp_pFileName ); if( !hb_pp_fopen( szFileName ) ) { printf("\nCan't open %s\n", szFileName ); return 1; } printf( "\nParsing file %s\n", szFileName ); } else { printf( "\nSyntax: %s <file[.prg]> [options]" "\n" "\nOptions: /d<id>[=<val>] #define <id>" "\n /i<path> add #include file search path" "\n /o creates hbpp.out with all tables" "\n /n with those only, which defined in your file" "\n /w enable warnings" "\n" , argv[ 0 ] ); if( bOutTable ) OutTable( NULL, NULL ); return 1; } hb_comp_pFileName->szExtension = ".ppo"; hb_fsFNameMerge( szPpoName, hb_comp_pFileName ); if( ( handl_o = fopen( szPpoName, "wt" ) ) == NULL ) { printf("\nCan't open %s\n", szPpoName ); return 1; } { char * szInclude = hb_getenv( "INCLUDE" ); if( szInclude ) { char * pPath; char * pDelim; pPath = szInclude; while( ( pDelim = strchr( pPath, HB_OS_PATH_LIST_SEP_CHR ) ) != NULL ) { *pDelim = '\0'; AddSearchPath( pPath, &hb_comp_pIncludePath ); pPath = pDelim + 1; } AddSearchPath( pPath, &hb_comp_pIncludePath ); hb_xfree( szInclude ); } } hb_buffer = ( char* ) hb_xgrab( HB_PP_STR_SIZE ); while( hb_pp_Internal_( handl_o,hb_buffer ) > 0 ); fclose( hb_comp_files.pLast->handle ); hb_xfree( hb_comp_files.pLast->pBuffer ); hb_xfree( hb_comp_files.pLast ); hb_xfree( hb_buffer ); fclose( handl_o ); if( bOutTable ) OutTable( NULL, NULL ); else if( bOutNew ) OutTable( stdef, stcmd ); printf( "\nOk" ); return 0; }
/* * Create a data store in the specified WorkArea. */ static HB_ERRCODE hb_sdfCreate( SDFAREAP pArea, LPDBOPENINFO pCreateInfo ) { HB_ERRCODE errCode; PHB_FNAME pFileName; PHB_ITEM pError = NULL; HB_BOOL fRetry; char szFileName[ HB_PATH_MAX ]; HB_TRACE( HB_TR_DEBUG, ( "hb_sdfCreate(%p,%p)", pArea, pCreateInfo ) ); pArea->fShared = HB_FALSE; /* pCreateInfo->fShared; */ pArea->fReadonly = HB_FALSE; /* pCreateInfo->fReadonly */ if( pCreateInfo->cdpId ) { pArea->area.cdPage = hb_cdpFindExt( pCreateInfo->cdpId ); if( ! pArea->area.cdPage ) pArea->area.cdPage = hb_vmCDP(); } else pArea->area.cdPage = hb_vmCDP(); pFileName = hb_fsFNameSplit( pCreateInfo->abName ); if( hb_setGetDefExtension() && ! pFileName->szExtension ) { PHB_ITEM pItem = hb_itemPutC( NULL, NULL ); SELF_INFO( &pArea->area, DBI_TABLEEXT, pItem ); pFileName->szExtension = hb_itemGetCPtr( pItem ); hb_fsFNameMerge( szFileName, pFileName ); hb_itemRelease( pItem ); } else { hb_strncpy( szFileName, pCreateInfo->abName, sizeof( szFileName ) - 1 ); } hb_xfree( pFileName ); /* Try create */ do { pArea->pFile = hb_fileExtOpen( szFileName, NULL, FO_READWRITE | FO_EXCLUSIVE | FXO_TRUNCATE | FXO_DEFAULTS | FXO_SHARELOCK | FXO_COPYNAME | FXO_NOSEEKPOS, NULL, pError ); if( ! pArea->pFile ) { if( ! pError ) { pError = hb_errNew(); hb_errPutGenCode( pError, EG_CREATE ); hb_errPutSubCode( pError, EDBF_CREATE_DBF ); hb_errPutOsCode( pError, hb_fsError() ); hb_errPutDescription( pError, hb_langDGetErrorDesc( EG_CREATE ) ); hb_errPutFileName( pError, szFileName ); hb_errPutFlags( pError, EF_CANRETRY | EF_CANDEFAULT ); } fRetry = ( SELF_ERROR( &pArea->area, pError ) == E_RETRY ); } else fRetry = HB_FALSE; } while( fRetry ); if( pError ) hb_itemRelease( pError ); if( ! pArea->pFile ) return HB_FAILURE; errCode = SUPER_CREATE( &pArea->area, pCreateInfo ); if( errCode != HB_SUCCESS ) { SELF_CLOSE( &pArea->area ); return errCode; } hb_sdfInitArea( pArea, szFileName ); /* Position cursor at the first record */ return SELF_GOTOP( &pArea->area ); }
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 char * hb_buildArgsOS2( const char *pszFileName, APIRET * ret ) { PHB_FNAME pFilepath; char szFileBuf[ HB_PATH_MAX ]; char * pArgs = NULL, * pszFree = NULL, cQuote = 0, c; HB_SIZE nLen = 0, nLen2; void * pMem; while( HB_ISSPACE( *pszFileName ) ) ++pszFileName; pszFileName = hb_osEncodeCP( pszFileName, &pszFree, NULL ); while( ( c = *pszFileName ) != '\0' ) { ++pszFileName; if( c == '"' ) cQuote = cQuote ? 0 : c; else { if( cQuote == 0 && HB_ISSPACE( c ) ) break; if( nLen < sizeof( szFileBuf ) - 1 ) szFileBuf[ nLen++ ] = c; } } szFileBuf[ nLen ] = '\0'; while( HB_ISSPACE( *pszFileName ) ) ++pszFileName; nLen2 = strlen( pszFileName ); pFilepath = hb_fsFNameSplit( szFileBuf ); if( pFilepath->szPath && ! pFilepath->szExtension ) { pFilepath->szExtension = ".com"; if( ! hb_fsFileExists( hb_fsFNameMerge( szFileBuf, pFilepath ) ) ) { pFilepath->szExtension = ".exe"; if( ! hb_fsFileExists( hb_fsFNameMerge( szFileBuf, pFilepath ) ) ) { pFilepath->szExtension = NULL; hb_fsFNameMerge( szFileBuf, pFilepath ); } } nLen = strlen( szFileBuf ); } hb_xfree( pFilepath ); *ret = DosAllocMem( &pMem, nLen + nLen2 + 3, PAG_COMMIT | PAG_READ | PAG_WRITE | OBJ_TILE ); if( *ret == NO_ERROR ) { pArgs = ( char * ) pMem; memcpy( pArgs, szFileBuf, nLen + 1 ); memcpy( pArgs + nLen + 1, pszFileName, nLen2 + 1 ); pArgs[ nLen + nLen2 + 2 ] = '\0'; } if( pszFree ) hb_xfree( pszFree ); return pArgs; }
static void hb_compChkEnvironVar( HB_COMP_DECL, const char * szSwitch ) { if( szSwitch && ! HB_COMP_PARAM->fExit ) { const char * s = szSwitch; /* If szSwitch doesn't start with a HB_OSOPTSEP char * show an error */ if( ! HB_ISOPTSEP( *s ) ) hb_compGenError( HB_COMP_PARAM, hb_comp_szErrors, 'F', HB_COMP_ERR_BADOPTION, s, NULL ); else { s++; switch( *s ) { case 'a': case 'A': if( *( s + 1 ) == '-' ) HB_COMP_PARAM->fAutoMemvarAssume = HB_FALSE; else HB_COMP_PARAM->fAutoMemvarAssume = HB_TRUE; break; case 'b': case 'B': { unsigned int i = 0; char *szOption = hb_strupr( hb_strdup( s ) ); while( i < strlen( szOption ) && ! HB_ISOPTSEP( szOption[ i ] ) ) i++; szOption[ i ] = '\0'; if( strcmp( szOption, "BUILD" ) == 0 ) HB_COMP_PARAM->fBuildInfo = HB_TRUE; else { if( *( s + 1 ) == '-' ) HB_COMP_PARAM->fDebugInfo = HB_FALSE; else { HB_COMP_PARAM->fDebugInfo = HB_TRUE; HB_COMP_PARAM->fLineNumbers = HB_TRUE; } } hb_xfree( szOption ); break; } case 'c': case 'C': { unsigned int i = 0; char *szOption = hb_strupr( hb_strdup( s ) ); while( i < strlen( szOption ) && ! HB_ISOPTSEP( szOption[ i ] ) ) i++; szOption[ i ] = '\0'; if( strcmp( szOption, "CREDITS" ) == 0 || strcmp( szOption, "CREDIT" ) == 0 || strcmp( szOption, "CREDI" ) == 0 || strcmp( szOption, "CRED" ) == 0 ) HB_COMP_PARAM->fCredits = HB_TRUE; else hb_compGenError( HB_COMP_PARAM, hb_comp_szErrors, 'F', HB_COMP_ERR_BADOPTION, szOption, NULL ); hb_xfree( szOption ); break; } case 'd': case 'D': /* NOTE: Ignore these -d switches will be processed separately */ break; case 'e': case 'E': if( *( s + 1 ) == 's' || *( s + 1 ) == 'S' ) { switch( *( s + 2 ) ) { case '\0': case '0': HB_COMP_PARAM->iExitLevel = HB_EXITLEVEL_DEFAULT; break; case '1': HB_COMP_PARAM->iExitLevel = HB_EXITLEVEL_SETEXIT; break; case '2': HB_COMP_PARAM->iExitLevel = HB_EXITLEVEL_DELTARGET; break; default: hb_compGenError( HB_COMP_PARAM, hb_comp_szErrors, 'F', HB_COMP_ERR_BADOPTION, s, NULL ); } } else hb_compGenError( HB_COMP_PARAM, hb_comp_szErrors, 'F', HB_COMP_ERR_BADOPTION, s, NULL ); break; case 'g': case 'G': switch( *( s + 1 ) ) { case 'c': case 'C': HB_COMP_PARAM->iLanguage = HB_LANG_C; switch( *( s + 2 ) ) { case '3': HB_COMP_PARAM->iGenCOutput = HB_COMPGENC_REALCODE; break; case '2': HB_COMP_PARAM->iGenCOutput = HB_COMPGENC_VERBOSE; break; case '1': HB_COMP_PARAM->iGenCOutput = HB_COMPGENC_NORMAL; break; case '\0': case '0': HB_COMP_PARAM->iGenCOutput = HB_COMPGENC_COMPACT; break; default: hb_compGenError( HB_COMP_PARAM, hb_comp_szErrors, 'F', HB_COMP_ERR_BADOPTION, s, NULL ); } break; case 'h': case 'H': HB_COMP_PARAM->iLanguage = HB_LANG_PORT_OBJ; break; case 'd': case 'D': if( HB_COMP_PARAM->szDepExt ) { hb_xfree( HB_COMP_PARAM->szDepExt ); HB_COMP_PARAM->szDepExt = NULL; } if( s[ 2 ] == '-' ) HB_COMP_PARAM->iTraceInclude = 0; else if( s[ 2 ] == '.' || s[ 2 ] == '\0' ) { HB_COMP_PARAM->iTraceInclude = 2; if( s[ 2 ] != '\0' ) HB_COMP_PARAM->szDepExt = hb_strdup( s + 2 ); } else hb_compGenError( HB_COMP_PARAM, hb_comp_szErrors, 'F', HB_COMP_ERR_BADOPTION, s, NULL ); break; case 'e': case 'E': switch( *( s + 2 ) ) { case '1': HB_COMP_PARAM->iErrorFmt = HB_ERRORFMT_IDE; break; case '\0': case '0': HB_COMP_PARAM->iErrorFmt = HB_ERRORFMT_CLIPPER; break; default: hb_compGenError( HB_COMP_PARAM, hb_comp_szErrors, 'F', HB_COMP_ERR_BADOPTION, s, NULL ); } break; default: hb_compGenError( HB_COMP_PARAM, hb_comp_szErrors, 'F', HB_COMP_ERR_UNSUPPORTED_LANG, NULL, NULL ); break; } break; /* NOTE: h or H from HELP or help */ case 'h': case 'H': case '?': break; /* NOTE: It already has support for several include files */ case 'i': case 'I': switch( *( s + 1 ) ) { case '-': HB_COMP_PARAM->fINCLUDE = HB_FALSE; break; case '+': HB_COMP_PARAM->fINCLUDE = HB_TRUE; break; default: hb_pp_addSearchPath( HB_COMP_PARAM->pLex->pPP, s + 1, HB_FALSE ); } break; case 'j': case 'J': HB_COMP_PARAM->fI18n = HB_TRUE; if( s[ 1 ] ) HB_COMP_PARAM->pI18nFileName = hb_fsFNameSplit( s + 1 ); break; case 'k': case 'K': { int i = 1; while( s[ i ] && ! HB_COMP_PARAM->fExit ) { switch( s[ i++ ] ) { case '?': hb_compPrintLogo( HB_COMP_PARAM ); hb_compPrintModes( HB_COMP_PARAM ); HB_COMP_PARAM->fLogo = HB_FALSE; HB_COMP_PARAM->fQuiet = HB_TRUE; break; case 'h': case 'H': /* default Harbour mode */ if( s[ i ] == '-' ) { i++; HB_COMP_PARAM->supported &= ~HB_COMPFLAG_HARBOUR; } else HB_COMP_PARAM->supported |= HB_COMPFLAG_HARBOUR; break; case 'c': case 'C': /* clear all flags - minimal set of features */ HB_COMP_PARAM->supported &= HB_COMPFLAG_SHORTCUTS; HB_COMP_PARAM->supported |= HB_COMPFLAG_OPTJUMP | HB_COMPFLAG_MACROTEXT; break; case 'x': case 'X': if( s[ i ] == '-' ) { i++; HB_COMP_PARAM->supported &= ~HB_COMPFLAG_XBASE; } else HB_COMP_PARAM->supported |= HB_COMPFLAG_XBASE; break; case 'i': case 'I': if( s[ i ] == '-' ) { i++; HB_COMP_PARAM->supported &= ~HB_COMPFLAG_HB_INLINE; } else HB_COMP_PARAM->supported |= HB_COMPFLAG_HB_INLINE; break; case 'j': case 'J': if( s[ i ] == '+' ) { i++; HB_COMP_PARAM->supported |= HB_COMPFLAG_OPTJUMP; } else HB_COMP_PARAM->supported &= ~HB_COMPFLAG_OPTJUMP; break; case 'm': case 'M': if( s[ i ] == '+' ) { i++; HB_COMP_PARAM->supported |= HB_COMPFLAG_MACROTEXT; } else HB_COMP_PARAM->supported &= ~HB_COMPFLAG_MACROTEXT; break; case 'd': case 'D': if( s[ i ] == '-' ) { i++; HB_COMP_PARAM->supported &= ~HB_COMPFLAG_MACRODECL; } else HB_COMP_PARAM->supported |= HB_COMPFLAG_MACRODECL; break; case 'r': case 'R': if( s[ i ] == '-' ) { i++; HB_COMP_PARAM->supported &= ~HB_COMPFLAG_RT_MACRO; } else HB_COMP_PARAM->supported |= HB_COMPFLAG_RT_MACRO; break; case 's': case 'S': if( s[ i ] == '-' ) { i++; HB_COMP_PARAM->supported &= ~HB_COMPFLAG_ARRSTR; } else HB_COMP_PARAM->supported |= HB_COMPFLAG_ARRSTR; break; case 'o': case 'O': if( s[ i ] == '-' ) { i++; HB_COMP_PARAM->supported &= ~HB_COMPFLAG_EXTOPT; } else HB_COMP_PARAM->supported |= HB_COMPFLAG_EXTOPT; break; case 'u': case 'U': if( s[ i ] == '-' ) { i++; HB_COMP_PARAM->supported &= ~HB_COMPFLAG_USERCP; } else HB_COMP_PARAM->supported |= HB_COMPFLAG_USERCP; break; default: hb_compGenError( HB_COMP_PARAM, hb_comp_szErrors, 'F', HB_COMP_ERR_BADOPTION, s, NULL ); break; } } break; } case 'l': case 'L': if( *( s + 1 ) == '-' ) HB_COMP_PARAM->fLineNumbers = HB_TRUE; else HB_COMP_PARAM->fLineNumbers = HB_FALSE; break; case 'm': case 'M': if( *( s + 1 ) == '-' ) HB_COMP_PARAM->fSingleModule = HB_FALSE; else HB_COMP_PARAM->fSingleModule = HB_TRUE; break; case 'n': case 'N': HB_COMP_PARAM->fNoStartUp = s[ 1 ] == '1'; switch( s[ 1 ] ) { case '-': HB_COMP_PARAM->iStartProc = 0; break; case '\0': case '0': case '1': HB_COMP_PARAM->iStartProc = 1; break; case '2': HB_COMP_PARAM->iStartProc = 2; break; default: hb_compGenError( HB_COMP_PARAM, hb_comp_szErrors, 'F', HB_COMP_ERR_BADOPTION, s, NULL ); } break; case 'o': case 'O': HB_COMP_PARAM->pOutPath = hb_fsFNameSplit( s + 1 ); break; /* Added for preprocessor needs */ case 'p': case 'P': if( s[ 1 ] == '+' && s[ 2 ] == '\0' ) HB_COMP_PARAM->fPPT = HB_TRUE; else { if( HB_COMP_PARAM->pPpoPath ) { hb_xfree( HB_COMP_PARAM->pPpoPath ); HB_COMP_PARAM->pPpoPath = NULL; } if( s[ 1 ] == '-' && s[ 2 ] == '\0' ) HB_COMP_PARAM->fPPO = HB_FALSE; else { if( s[ 1 ] ) HB_COMP_PARAM->pPpoPath = hb_fsFNameSplit( s + 1 ); HB_COMP_PARAM->fPPO = HB_TRUE; } } break; case 'q': case 'Q': switch( *( s + 1 ) ) { case '2': HB_COMP_PARAM->fFullQuiet = HB_TRUE; case '0': HB_COMP_PARAM->fLogo = HB_FALSE; default: HB_COMP_PARAM->fQuiet = HB_TRUE; } break; case 'r': case 'R': if( *( s + 1 ) == ':' ) { int iOverflow; int iCycles = ( int ) hb_strValInt( s + 2, &iOverflow ); if( ! iOverflow && iCycles > 0 ) HB_COMP_PARAM->iMaxTransCycles = iCycles; } else { /* TODO: Implement this switch */ hb_notSupportedInfo( HB_COMP_PARAM, s ); } break; case 's': case 'S': switch( *( s + 1 ) ) { case '\0': HB_COMP_PARAM->iSyntaxCheckOnly = 1; break; case '-': HB_COMP_PARAM->iSyntaxCheckOnly = 0; break; case 'm': case 'M': if( s[ 2 ] == '\0' ) { HB_COMP_PARAM->iSyntaxCheckOnly = 2; break; } default: hb_compGenError( HB_COMP_PARAM, hb_comp_szErrors, 'F', HB_COMP_ERR_BADOPTION, s, NULL ); } break; case 't': case 'T': /* TODO: Implement this switch */ hb_notSupportedInfo( HB_COMP_PARAM, s ); break; case 'u': case 'U': if( ( s[ 1 ] == 'N' || s[ 1 ] == 'n' ) && ( s[ 2 ] == 'D' || s[ 2 ] == 'd' ) && ( s[ 3 ] == 'E' || s[ 3 ] == 'e' ) && ( s[ 4 ] == 'F' || s[ 4 ] == 'f' ) && s[ 5 ] == ':' ) { /* NOTE: Ignore these -undef: switches (will be processed * separately) except -undef:.arch. */ if( s[ 6 ] == '.' && ( s[ 7 ] == 'A' || s[ 7 ] == 'a' ) && ( s[ 8 ] == 'R' || s[ 8 ] == 'r' ) && ( s[ 9 ] == 'C' || s[ 9 ] == 'c' ) && ( s[ 10 ] == 'H' || s[ 10 ] == 'h' ) && s[ 11 ] == '.' ) { HB_COMP_PARAM->fNoArchDefs = HB_TRUE; } break; } /* extended definitions file (-u+<file>) */ if( s[ 1 ] == '+' ) { if( s[ 2 ] ) { if( HB_COMP_PARAM->iStdChExt == 0 ) HB_COMP_PARAM->szStdChExt = ( char ** ) hb_xgrab( sizeof( char * ) ); else HB_COMP_PARAM->szStdChExt = ( char ** ) hb_xrealloc( HB_COMP_PARAM->szStdChExt, ( HB_COMP_PARAM->iStdChExt + 1 ) * sizeof( char * ) ); HB_COMP_PARAM->szStdChExt[ HB_COMP_PARAM->iStdChExt++ ] = hb_strdup( s + 2 ); } else hb_compGenError( HB_COMP_PARAM, hb_comp_szErrors, 'F', HB_COMP_ERR_BADOPTION, s, NULL ); } else { if( HB_COMP_PARAM->szStdCh ) hb_xfree( HB_COMP_PARAM->szStdCh ); HB_COMP_PARAM->szStdCh = hb_strdup( s + 1 ); } break; case 'v': case 'V': if( *( s + 1 ) == '-' ) HB_COMP_PARAM->fForceMemvars = HB_FALSE; else HB_COMP_PARAM->fForceMemvars = HB_TRUE; break; case 'w': case 'W': HB_COMP_PARAM->iWarnings = 1; if( s[ 1 ] ) /* there is -w<0,1,2,3> probably */ { HB_COMP_PARAM->iWarnings = s[ 1 ] - '0'; if( HB_COMP_PARAM->iWarnings < 0 || HB_COMP_PARAM->iWarnings > 3 ) hb_compGenError( HB_COMP_PARAM, hb_comp_szErrors, 'F', HB_COMP_ERR_BADOPTION, s, NULL ); } break; case 'x': case 'X': { unsigned int i = 1; while( s[ i ] && ! HB_ISOPTSEP( s[ i ] ) && i < sizeof( HB_COMP_PARAM->szPrefix ) - 1 ) { ++i; } if( i > 1 ) { memcpy( HB_COMP_PARAM->szPrefix, s + 1, i - 1 ); HB_COMP_PARAM->szPrefix[ i - 1 ] = '_'; HB_COMP_PARAM->szPrefix[ i ] = '\0'; } else { hb_snprintf( HB_COMP_PARAM->szPrefix, sizeof( HB_COMP_PARAM->szPrefix ), "%08lX_", PackDateTime() ); } break; } #ifdef YYDEBUG case 'y': case 'Y': yydebug = HB_TRUE; break; #endif case 'z': case 'Z': if( *( s + 1 ) == '-' ) HB_COMP_PARAM->supported |= HB_COMPFLAG_SHORTCUTS; else HB_COMP_PARAM->supported &= ~HB_COMPFLAG_SHORTCUTS; break; default: hb_compGenError( HB_COMP_PARAM, hb_comp_szErrors, 'F', HB_COMP_ERR_BADOPTION, s, NULL ); break; } } } }
void hb_cmdargUpdate( void ) { HB_TRACE( HB_TR_DEBUG, ( "hb_cmdargUpdate()" ) ); #if ! defined( HB_OS_WIN ) if( s_argc > 0 ) { #if defined( HB_OS_OS2 ) { PPIB ppib = NULL; APIRET ulrc; ulrc = DosGetInfoBlocks( NULL, &ppib ); if( ulrc == NO_ERROR ) { ulrc = DosQueryModuleName( ppib->pib_hmte, HB_SIZEOFARRAY( s_szAppName ), s_szAppName ); if( ulrc == NO_ERROR ) s_argv[ 0 ] = s_szAppName; } } #else /* NOTE: try to create absolute path from s_argv[ 0 ] if necessary */ { PHB_FNAME pFName = hb_fsFNameSplit( s_argv[ 0 ] ); HB_BOOL fInPath = HB_FALSE; if( ! pFName->szPath ) { char * pszPATH = hb_getenv( "PATH" ); if( pszPATH && *pszPATH ) { HB_PATHNAMES * pSearchPath = NULL, * pNextPath; hb_fsAddSearchPath( pszPATH, &pSearchPath ); pNextPath = pSearchPath; while( pNextPath ) { pFName->szPath = pNextPath->szPath; hb_fsFNameMerge( s_szAppName, pFName ); if( hb_fsFileExists( s_szAppName ) ) { /* even if the file is located using PATH then it does * not mean we will have absolute path here. It's not * good idea but PATH envvar can also contain relative * directories, f.e. "." or "bin" so we should add * current directory if necessary in code below. */ hb_xfree( pFName ); pFName = hb_fsFNameSplit( s_szAppName ); fInPath = HB_TRUE; break; } pNextPath = pNextPath->pNext; } hb_fsFreeSearchPath( pSearchPath ); if( ! fInPath ) pFName->szPath = NULL; } if( pszPATH ) hb_xfree( pszPATH ); } if( pFName->szPath ) { #if defined( HB_OS_HAS_DRIVE_LETTER ) if( pFName->szPath[ 0 ] != HB_OS_PATH_DELIM_CHR && ! pFName->szDrive ) #else if( pFName->szPath[ 0 ] != HB_OS_PATH_DELIM_CHR ) #endif { if( pFName->szPath[ 0 ] == '.' && pFName->szPath[ 1 ] == HB_OS_PATH_DELIM_CHR ) pFName->szPath += 2; s_szAppName[ 0 ] = HB_OS_PATH_DELIM_CHR; hb_fsCurDirBuff( 0, s_szAppName + 1, HB_PATH_MAX - 1 ); if( s_szAppName[ 1 ] != 0 ) { hb_strncat( s_szAppName, HB_OS_PATH_DELIM_CHR_STRING, HB_PATH_MAX - 1 ); hb_strncat( s_szAppName, pFName->szPath, HB_PATH_MAX - 1 ); pFName->szPath = hb_strdup( s_szAppName ); hb_fsFNameMerge( s_szAppName, pFName ); hb_xfree( ( void * ) pFName->szPath ); s_argv[ 0 ] = s_szAppName; } } else if( fInPath ) s_argv[ 0 ] = s_szAppName; } hb_xfree( pFName ); } #endif } #endif }
static int hb_zipDeleteFile( const char * szZipFile, const char * szFileMask ) { char szTempFile[ HB_PATH_MAX ]; char szCurrFile[ HB_PATH_MAX ]; PHB_FNAME pFileName; HB_FHANDLE hFile; unzFile hUnzip; zipFile hZip; unz_global_info ugi; unz_file_info ufi; zip_fileinfo zfi; char * pszGlobalComment = NULL; char * pszFileComment = NULL; void * pExtraField = NULL; void * pLocalExtraField = NULL; int iFilesLeft = 0; int iFilesDel = 0; int iExtraFieldLen; int method; int level; int iResult; char * pszFree; /* open source file */ hUnzip = unzOpen( hb_fsNameConv( szZipFile, &pszFree ) ); if( pszFree ) hb_xfree( pszFree ); if( hUnzip == NULL ) return UNZ_ERRNO; pFileName = hb_fsFNameSplit( szZipFile ); hFile = hb_fsCreateTemp( pFileName->szPath, NULL, FC_NORMAL, szTempFile ); hZip = NULL; if( hFile != FS_ERROR ) { hb_fsClose( hFile ); hZip = zipOpen( szTempFile, APPEND_STATUS_CREATE ); } hb_xfree( pFileName ); if( hZip == NULL ) { unzClose( hUnzip ); return UNZ_ERRNO; } iResult = unzGetGlobalInfo( hUnzip, &ugi ); if( iResult == UNZ_OK ) { if( ugi.size_comment > 0 ) { pszGlobalComment = ( char * ) hb_xgrab( ugi.size_comment + 1 ); if( ( uLong ) unzGetGlobalComment( hUnzip, pszGlobalComment, ugi.size_comment ) != ugi.size_comment ) iResult = UNZ_ERRNO; pszGlobalComment[ ugi.size_comment ] = '\0'; } if( iResult == UNZ_OK ) iResult = unzGoToFirstFile( hUnzip ); } while( iResult == UNZ_OK ) { iResult = unzGetCurrentFileInfo( hUnzip, &ufi, szCurrFile, HB_PATH_MAX - 1, NULL, 0, NULL, 0 ); if( iResult != UNZ_OK ) break; if( hb_strMatchFile( szCurrFile, szFileMask ) ) iFilesDel++; else { if( ufi.size_file_extra ) pExtraField = ( char * ) hb_xgrab( ufi.size_file_extra ); if( ufi.size_file_comment ) pszFileComment = ( char * ) hb_xgrab( ufi.size_file_comment + 1 ); iResult = unzGetCurrentFileInfo( hUnzip, &ufi, NULL, 0, pExtraField, ufi.size_file_extra, pszFileComment, ufi.size_file_comment ); if( pszFileComment ) pszFileComment[ ufi.size_file_comment ] = '\0'; if( iResult != UNZ_OK ) break; iResult = unzOpenCurrentFile2( hUnzip, &method, &level, 1 ); if( iResult != UNZ_OK ) break; iExtraFieldLen = unzGetLocalExtrafield( hUnzip, NULL, 0 ); if( iExtraFieldLen < 0 ) { iResult = UNZ_ERRNO; break; } else if( iExtraFieldLen > 0 ) { pLocalExtraField = hb_xgrab( iExtraFieldLen ); if( unzGetLocalExtrafield( hUnzip, pLocalExtraField, iExtraFieldLen ) != iExtraFieldLen ) { iResult = UNZ_ERRNO; break; } } memset( &zfi, 0, sizeof( zfi ) ); memcpy( &zfi.tmz_date, &ufi.tmu_date, sizeof( tm_unz ) ); zfi.dosDate = ufi.dosDate; zfi.internal_fa = ufi.internal_fa; zfi.external_fa = ufi.external_fa; iResult = zipOpenNewFileInZip2( hZip, szCurrFile, &zfi, pLocalExtraField, iExtraFieldLen, pExtraField, ufi.size_file_extra, pszFileComment, method, level, 1 ); if( iResult != UNZ_OK ) break; if( ufi.compressed_size ) { void * buffer = hb_xgrab( HB_Z_IOBUF_SIZE ); uLong ulLeft = ufi.compressed_size; while( ulLeft > 0 ) { int iRead = HB_MIN( ulLeft, HB_Z_IOBUF_SIZE ); iResult = unzReadCurrentFile( hUnzip, ( voidp ) buffer, iRead ); if( iResult < 0 ) break; if( iResult != iRead ) { iResult = UNZ_ERRNO; break; } iResult = zipWriteInFileInZip( hZip, ( voidp ) buffer, iRead ); if( iResult != UNZ_OK ) break; ulLeft -= iRead; } hb_xfree( buffer ); if( iResult != UNZ_OK ) break; } iResult = zipCloseFileInZipRaw( hZip, ufi.uncompressed_size, ufi.crc ); if( iResult != UNZ_OK ) break; iResult = unzCloseCurrentFile( hUnzip ); if( iResult != UNZ_OK ) break; if( pExtraField ) { hb_xfree( pExtraField ); pExtraField = NULL; } if( pszFileComment ) { hb_xfree( pszFileComment ); pszFileComment = NULL; } if( pLocalExtraField ) { hb_xfree( pLocalExtraField ); pLocalExtraField = NULL; } iFilesLeft++; } iResult = unzGoToNextFile( hUnzip ); } if( pExtraField ) hb_xfree( pExtraField ); if( pszFileComment ) hb_xfree( pszFileComment ); if( pLocalExtraField ) hb_xfree( pLocalExtraField ); if( iFilesDel == 0 ) iResult = UNZ_ERRNO; else if( iResult == UNZ_END_OF_LIST_OF_FILE ) iResult = UNZ_OK; if( iResult != UNZ_OK ) zipClose( hZip, NULL ); else iResult = zipClose( hZip, pszGlobalComment ); unzClose( hUnzip ); if( pszGlobalComment ) hb_xfree( pszGlobalComment ); if( iResult != UNZ_OK ) hb_fsDelete( szTempFile ); else { hb_fsDelete( szZipFile ); if( iFilesLeft == 0 ) hb_fsDelete( szTempFile ); else if( ! hb_fsRename( szTempFile, szZipFile ) ) iResult = UNZ_ERRNO; } return iResult; }
int main( int argc, char * argv[] ) { char * szFile = NULL, * szRuleFile = NULL, * szVerFile = NULL; char * szStdCh = NULL, * szLogFile = NULL, * szInclude; HB_BOOL fWrite = HB_FALSE, fChgLog = HB_FALSE; char * szChangeLogID = NULL, * szLastEntry = NULL; int iRevID = 0, iResult = 0, iQuiet = 0, i; char * szPPRuleFuncName = NULL; PHB_PP_STATE pState; pState = hb_pp_new(); if( argc >= 2 ) { szFile = argv[ 1 ]; for( i = 2; szFile && i < argc; i++ ) { if( ! HB_ISOPTSEP( argv[ i ][ 0 ] ) ) szFile = NULL; else { switch( argv[ i ][ 1 ] ) { case 'q': case 'Q': if( ! argv[ i ][ 2 ] ) iQuiet = 1; else if( argv[ i ][ 2 ] == '-' && ! argv[ i ][ 3 ] ) iQuiet = 0; else if( argv[ i ][ 2 ] >= '0' && argv[ i ][ 2 ] <= '2' && ! argv[ i ][ 3 ] ) iQuiet = argv[ i ][ 2 ] - '0'; else szFile = NULL; break; case 'd': case 'D': if( ! argv[ i ][ 2 ] ) szFile = NULL; else { char * szDefText = hb_strdup( argv[ i ] + 2 ), * szAssign; szAssign = strchr( szDefText, '=' ); if( szAssign ) *szAssign++ = '\0'; hb_pp_addDefine( pState, szDefText, szAssign ); hb_xfree( szDefText ); } break; case 'e': case 'E': if( argv[ i ][ 2 ] ) szPPRuleFuncName = argv[ i ] + 2; else szPPRuleFuncName = NULL; break; case 'w': case 'W': if( argv[ i ][ 2 ] ) szFile = NULL; else fWrite = HB_TRUE; break; case 'c': case 'C': fChgLog = HB_TRUE; if( argv[ i ][ 2 ] ) szLogFile = argv[ i ] + 2; break; case 'i': case 'I': if( argv[ i ][ 2 ] ) hb_pp_addSearchPath( pState, argv[ i ] + 2, HB_FALSE ); else szFile = NULL; break; case 'o': case 'O': if( argv[ i ][ 2 ] ) szRuleFile = argv[ i ] + 2; else szFile = NULL; break; case 'v': case 'V': if( argv[ i ][ 2 ] ) szVerFile = argv[ i ] + 2; else szFile = NULL; break; case 'u': case 'U': if( argv[ i ][ 2 ] ) szStdCh = argv[ i ] + 2; else szStdCh = NULL; break; default: szFile = NULL; break; } } } } if( iQuiet < 2 ) { printf( "Harbour Preprocessor %d.%d.%d%s\n", HB_VER_MAJOR, HB_VER_MINOR, HB_VER_RELEASE, HB_VER_STATUS ); printf( "Copyright (c) 1999-2014, http://harbour-project.org/\n" ); } if( szFile ) { if( ! szRuleFile && ! szVerFile ) fWrite = HB_TRUE; hb_pp_init( pState, iQuiet != 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ); szInclude = hb_getenv( "INCLUDE" ); if( szInclude ) { if( szInclude[ 0 ] ) hb_pp_addSearchPath( pState, szInclude, HB_FALSE ); hb_xfree( szInclude ); } if( szStdCh ) hb_pp_readRules( pState, szStdCh ); if( hb_pp_inFile( pState, szFile, HB_TRUE, NULL, HB_TRUE ) ) { if( fWrite ) { char szFileName[ HB_PATH_MAX ]; PHB_FNAME pFileName; pFileName = hb_fsFNameSplit( szFile ); pFileName->szExtension = ".ppo"; hb_fsFNameMerge( szFileName, pFileName ); hb_xfree( pFileName ); hb_pp_outFile( pState, szFileName, NULL ); } if( fChgLog ) iResult = hb_pp_parseChangelog( pState, szLogFile, iQuiet, &iRevID, &szChangeLogID, &szLastEntry ); if( iResult == 0 ) iResult = hb_pp_preprocesfile( pState, szRuleFile, szPPRuleFuncName ); if( iResult == 0 && szVerFile ) iResult = hb_pp_generateVerInfo( szVerFile, iRevID, szChangeLogID, szLastEntry ); if( iResult == 0 && hb_pp_errorCount( pState ) > 0 ) iResult = 1; } else iResult = 1; } else { hb_pp_usage( argv[ 0 ] ); iResult = 1; } if( szChangeLogID ) hb_xfree( szChangeLogID ); if( szLastEntry ) hb_xfree( szLastEntry ); hb_pp_free( pState ); return iResult; }
static int hb_pp_parseChangelog( PHB_PP_STATE pState, const char * pszFileName, int iQuiet, int * piRevID, char ** pszChangeLogID, char ** pszLastEntry ) { char * pszFree = NULL; int iResult = 0; FILE * file_in; char szToCheck[ HB_PATH_MAX ]; PHB_FNAME pFileName = hb_fsFNameSplit( pszFileName ); if( ! pFileName->szName ) { static const char * s_szNames[] = { "ChangeLog.txt", "CHANGES.txt", #if defined( HB_OS_DOS ) "ChangeLo.txt", "Change~1.txt", "Change~?.txt", "Chang~??.txt", #endif NULL }; int i = 0; if( ! pFileName->szPath ) pFileName->szPath = "../../../../.."; pszFileName = s_szNames[ i++ ]; while( pszFileName ) { pFileName->szName = pszFileName; hb_fsFNameMerge( szToCheck, pFileName ); if( hb_fsFileExists( szToCheck ) ) { pszFileName = szToCheck; break; } if( strchr( szToCheck, '?' ) != NULL ) { pszFree = hb_fsFileFind( szToCheck ); if( pszFree ) { pszFileName = pszFree; break; } } pszFileName = s_szNames[ i++ ]; } if( ! pszFileName ) pszFileName = s_szNames[ 0 ]; } hb_xfree( pFileName ); file_in = hb_fopen( pszFileName, "r" ); if( ! file_in ) { if( iQuiet < 2 ) { #if ! defined( HB_OS_WIN_CE ) perror( pszFileName ); #else fprintf( stderr, "Cannot open the %s file.\n", pszFileName ); #endif } iResult = 1; } else { char szLine[ 256 ]; char szId[ 128 ]; char szLog[ 128 ]; char * szFrom, * szTo; int iLen; if( iQuiet == 0 ) fprintf( stdout, "Reading ChangeLog file: %s\n", pszFileName ); *szId = *szLog = '\0'; do { if( ! fgets( szLine, sizeof( szLine ), file_in ) ) break; if( ! *szId ) { szFrom = strstr( szLine, "$" "Id" ); if( szFrom ) { szFrom += 3; szTo = strchr( szFrom, '$' ); if( szTo ) { /* Is it tarball source package? */ if( szTo == szFrom ) { /* we do not have revision number :-( */ hb_strncpy( szId, "unknown -1 (source tarball without keyword expanding)", sizeof( szId ) - 1 ); } else if( szTo - szFrom > 3 && szTo[ -1 ] == ' ' && szFrom[ 0 ] == ':' && szFrom[ 1 ] == ' ' ) { szTo[ -1 ] = '\0'; hb_strncpy( szId, szFrom + 2, sizeof( szId ) - 1 ); } } } } else if( ! *szLog ) { if( szLine[ 4 ] == '-' && szLine[ 7 ] == '-' && szLine[ 10 ] == ' ' && szLine[ 13 ] == ':' ) { hb_strncpy( szLog, szLine, sizeof( szLog ) - 1 ); iLen = ( int ) strlen( szLog ); while( iLen-- && HB_ISSPACE( szLog[ iLen ] ) ) szLog[ iLen ] = '\0'; } } } while( ! *szLog ); fclose( file_in ); if( ! *szLog ) { if( iQuiet < 2 ) fprintf( stderr, "Cannot find valid $" "Id entry in the %s file.\n", pszFileName ); iResult = 1; } else { char szRevID[ 18 ]; *szLine = '"'; hb_strncpy( szLine + 1, szLog, sizeof( szLine ) - 3 ); iLen = ( int ) strlen( szLine ); szLine[ iLen ] = '"'; szLine[ ++iLen ] = '\0'; hb_pp_addDefine( pState, "HB_VER_LENTRY", szLine ); *pszLastEntry = hb_strdup( szLog ); hb_strncpy( szLine + 1, szId, sizeof( szLine ) - 3 ); iLen = ( int ) strlen( szLine ); szLine[ iLen ] = '"'; szLine[ ++iLen ] = '\0'; hb_pp_addDefine( pState, "HB_VER_CHLID", szLine ); *pszChangeLogID = hb_strdup( szId ); if( strlen( szLog ) >= 16 ) { long lJulian = 0, lMilliSec = 0; int iUTC = 0; if( strlen( szLog ) >= 25 && szLog[ 17 ] == 'U' && szLog[ 18 ] == 'T' && szLog[ 19 ] == 'C' && ( szLog[ 20 ] == '+' || szLog[ 20 ] == '-' ) && HB_ISDIGIT( szLog[ 21 ] ) && HB_ISDIGIT( szLog[ 22 ] ) && HB_ISDIGIT( szLog[ 23 ] ) && HB_ISDIGIT( szLog[ 24 ] ) ) { iUTC = ( ( int ) ( szLog[ 21 ] - '0' ) * 10 + ( int ) ( szLog[ 22 ] - '0' ) ) * 60 + ( int ) ( szLog[ 23 ] - '0' ) * 10 + ( int ) ( szLog[ 24 ] - '0' ); } szLog[ 16 ] = '\0'; if( iUTC != 0 && hb_timeStampStrGetDT( szLog, &lJulian, &lMilliSec ) ) { hb_timeStampUnpackDT( hb_timeStampPackDT( lJulian, lMilliSec ) - ( double ) iUTC / ( 24 * 60 ), &lJulian, &lMilliSec ); } if( lJulian && lMilliSec ) { hb_timeStampStrRawPut( szRevID, lJulian, lMilliSec ); memmove( szRevID, szRevID + 2, 10 ); } else { szRevID[ 0 ] = szLog[ 2 ]; szRevID[ 1 ] = szLog[ 3 ]; szRevID[ 2 ] = szLog[ 5 ]; szRevID[ 3 ] = szLog[ 6 ]; szRevID[ 4 ] = szLog[ 8 ]; szRevID[ 5 ] = szLog[ 9 ]; szRevID[ 6 ] = szLog[ 11 ]; szRevID[ 7 ] = szLog[ 12 ]; szRevID[ 8 ] = szLog[ 14 ]; szRevID[ 9 ] = szLog[ 15 ]; } szRevID[ 10 ] = '\0'; } else szRevID[ 0 ] = '\0'; *piRevID = ( int ) hb_strValInt( szRevID, &iLen ); hb_pp_addDefine( pState, "HB_VER_REVID", szRevID ); #ifdef HB_LEGACY_LEVEL4 hb_pp_addDefine( pState, "HB_VER_SVNID", szRevID ); #endif } } if( pszFree ) hb_xfree( pszFree ); return iResult; }
static int hb_pp_parseChangelog( PHB_PP_STATE pState, const char * pszFileName, int iQuiet, int * piCommitRev, char ** pszCommitInfo ) { char * pszFree = NULL; int iResult = 0; FILE * file_in; char szToCheck[ HB_PATH_MAX ]; PHB_FNAME pFileName = hb_fsFNameSplit( pszFileName ); if( ! pFileName->szName ) { static const char * s_szNames[] = { "ChangeLog.txt", "CHANGES.txt", #if defined( HB_OS_DOS ) "ChangeLo.txt", "Change~1.txt", "Change~?.txt", "Chang~??.txt", #endif NULL }; int i = 0; if( ! pFileName->szPath ) pFileName->szPath = "../../../../.."; pszFileName = s_szNames[ i++ ]; while( pszFileName ) { pFileName->szName = pszFileName; hb_fsFNameMerge( szToCheck, pFileName ); if( hb_fsFileExists( szToCheck ) ) { pszFileName = szToCheck; break; } if( strchr( szToCheck, '?' ) != NULL ) { pszFree = hb_fsFileFind( szToCheck ); if( pszFree ) { pszFileName = pszFree; break; } } pszFileName = s_szNames[ i++ ]; } if( ! pszFileName ) pszFileName = s_szNames[ 0 ]; } hb_xfree( pFileName ); file_in = hb_fopen( pszFileName, "r" ); if( ! file_in ) { if( iQuiet < 2 ) { #if ! defined( HB_OS_WIN_CE ) perror( pszFileName ); #else fprintf( stderr, "Cannot open the %s file.\n", pszFileName ); #endif } iResult = 1; } else { char szLine[ 256 ]; char szLog[ 128 ]; int iLen; if( iQuiet == 0 ) fprintf( stdout, "Reading ChangeLog file: %s\n", pszFileName ); *szLog = '\0'; do { if( ! fgets( szLine, sizeof( szLine ), file_in ) ) break; if( ! *szLog ) { if( szLine[ 4 ] == '-' && szLine[ 7 ] == '-' && szLine[ 10 ] == ' ' && szLine[ 13 ] == ':' ) { hb_strncpy( szLog, szLine, sizeof( szLog ) - 1 ); iLen = ( int ) strlen( szLog ); while( iLen-- && HB_ISSPACE( szLog[ iLen ] ) ) szLog[ iLen ] = '\0'; } } } while( ! *szLog ); fclose( file_in ); if( ! *szLog ) { if( iQuiet < 2 ) fprintf( stderr, "Cannot find valid $" "Id entry in the %s file.\n", pszFileName ); iResult = 1; } else { *szLine = '"'; hb_strncpy( szLine + 1, szLog, sizeof( szLine ) - 3 ); iLen = ( int ) strlen( szLine ); szLine[ iLen ] = '"'; szLine[ ++iLen ] = '\0'; hb_pp_addDefine( pState, "HB_VER_COMMIT_INFO", szLine ); *pszCommitInfo = hb_strdup( szLog ); *piCommitRev = hb_pp_TimeStampToNum( pState, szLog ); } } if( pszFree ) hb_xfree( pszFree ); return iResult; }
HB_BOOL hb_spFile( const char * pszFileName, char * pszRetPath ) { char * pszPath; HB_BOOL bIsFile = HB_FALSE; PHB_FNAME pFilepath; HB_TRACE( HB_TR_DEBUG, ( "hb_spFile(%s, %p)", pszFileName, pszRetPath ) ); if( pszRetPath ) pszPath = pszRetPath; else pszPath = ( char * ) hb_xgrab( HB_PATH_MAX ); pFilepath = hb_fsFNameSplit( pszFileName ); if( pFilepath->szPath ) { hb_fsFNameMerge( pszPath, pFilepath ); bIsFile = hb_fsFile( pszPath ); } else { const char * szDefault = hb_setGetDefault(); if( szDefault ) { pFilepath->szPath = szDefault; hb_fsFNameMerge( pszPath, pFilepath ); bIsFile = hb_fsFile( pszPath ); } if( ! bIsFile && hb_setGetPath() ) { HB_PATHNAMES * pNextPath = hb_setGetFirstSetPath(); while( bIsFile == HB_FALSE && pNextPath ) { pFilepath->szPath = pNextPath->szPath; hb_fsFNameMerge( pszPath, pFilepath ); bIsFile = hb_fsFile( pszPath ); pNextPath = pNextPath->pNext; } } /* * This code is intentional. To eliminate race condition, * in pending hb_spCreate()/hb_spOpen() call when we have to know * real path and file name we have to set its deterministic value * here. If it's not necessary the caller may drop this value. */ if( ! bIsFile ) { pFilepath->szPath = szDefault ? szDefault : "."; hb_fsFNameMerge( pszPath, pFilepath ); } } hb_xfree( pFilepath ); if( pszRetPath == NULL ) hb_xfree( pszPath ); return bIsFile; }