void hb_memvarGetRefer( PHB_ITEM pItem, PHB_SYMB pMemvarSymb ) { PHB_DYNS pDyn; HB_TRACE( HB_TR_DEBUG, ( "hb_memvarGetRefer(%p, %p)", pItem, pMemvarSymb ) ); pDyn = ( PHB_DYNS ) pMemvarSymb->pDynSym; if( pDyn ) { PHB_ITEM pMemvar; pMemvar = hb_dynsymGetMemvar( pDyn ); HB_TRACE( HB_TR_INFO, ( "Memvar item (%p)(%s) referenced", pMemvar, pMemvarSymb->szName ) ); if( pMemvar ) { if( HB_IS_BYREF( pMemvar ) && ! HB_IS_ENUM( pMemvar ) ) hb_itemCopy( pItem, pMemvar ); else { /* value is already created */ pItem->type = HB_IT_BYREF | HB_IT_MEMVAR; pItem->item.asMemvar.value = pMemvar; hb_xRefInc( pMemvar ); } } else { /* Generate an error with retry possibility * (user created error handler can make this variable accessible) */ PHB_ITEM pError; pError = hb_errRT_New( ES_ERROR, NULL, EG_NOVAR, 1003, NULL, pMemvarSymb->szName, 0, EF_CANRETRY ); while( hb_errLaunch( pError ) == E_RETRY ) { pMemvar = hb_dynsymGetMemvar( pDyn ); if( pMemvar ) { if( HB_IS_BYREF( pMemvar ) && ! HB_IS_ENUM( pMemvar ) ) hb_itemCopy( pItem, pMemvar ); else { /* value is already created */ pItem->type = HB_IT_BYREF | HB_IT_MEMVAR; pItem->item.asMemvar.value = pMemvar; hb_xRefInc( pMemvar ); } break; } } hb_errRelease( pError ); } } else hb_errInternal( HB_EI_MVBADSYMBOL, NULL, pMemvarSymb->szName, NULL ); }
/* * Assign a value to a field. */ HB_ERRCODE hb_rddPutFieldValue( PHB_ITEM pItem, PHB_SYMB pFieldSymbol ) { HB_ERRCODE errCode; HB_TRACE( HB_TR_DEBUG, ( "hb_rddPutFieldValue(%p, %p)", pItem, pFieldSymbol ) ); errCode = hb_rddFieldPut( pItem, pFieldSymbol ); if( errCode == HB_FAILURE && hb_vmRequestQuery() == 0 ) { /* * generate an error with retry possibility * (user created error handler can make this field accessible) */ PHB_ITEM pError = hb_errRT_New( ES_ERROR, NULL, EG_NOVAR, EDBCMD_NOVAR, NULL, pFieldSymbol->szName, 0, EF_CANRETRY ); while( hb_errLaunch( pError ) == E_RETRY ) { errCode = hb_rddFieldPut( pItem, pFieldSymbol ); if( errCode == HB_SUCCESS || hb_vmRequestQuery() != 0 ) break; } hb_itemRelease( pError ); } return errCode; }
static void s_pp_msg( void * cargo, int iErrorFmt, int iLine, const char * szModule, char cPrefix, int iValue, const char * szText, const char * szPar1, const char * szPar2 ) { HB_SYMBOL_UNUSED( cargo ); /* ignore all warning messages and errors when break or quit request */ if( cPrefix != 'W' && hb_vmRequestQuery() == 0 ) { char szMsgBuf[ 512 ], szLine[ 512 ]; PHB_ITEM pError; hb_snprintf( szMsgBuf, sizeof( szMsgBuf ), szText, szPar1, szPar2 ); if( ! szModule || *szModule == 0 || strcmp( szModule, "{SOURCE}.prg" ) == 0 ) hb_snprintf( szLine, sizeof( szLine ), "line:%i", iLine ); else hb_snprintf( szLine, sizeof( szLine ), iErrorFmt == HB_ERRORFMT_CLIPPER ? "%s(%i)" : "%s:%i", szModule, iLine ); pError = hb_errRT_New( ES_ERROR, "COMPILER", 1001, ( HB_ERRCODE ) iValue, szMsgBuf, szLine, 0 /*OsCode*/, EF_NONE ); hb_errLaunch( pError ); hb_errRelease( pError ); } }
HB_USHORT hb_errRT_BASE( HB_ERRCODE errGenCode, HB_ERRCODE errSubCode, const char * szDescription, const char * szOperation, HB_ULONG ulArgCount, ... ) { HB_USHORT uiAction; PHB_ITEM pError; PHB_ITEM pArray; va_list va; HB_ULONG ulArgPos; /* I replaced EF_CANRETRY with EF_NONE for Clipper compatibility * If it's wrong and I missed something please fix me, Druzus. */ pError = hb_errRT_New( ES_ERROR, HB_ERR_SS_BASE, errGenCode, errSubCode, szDescription, szOperation, 0, EF_NONE /* EF_CANRETRY */ ); /* Build the array from the passed arguments. */ switch( ulArgCount ) { case 0: pArray = NULL; break; case HB_ERR_ARGS_BASEPARAMS: pArray = hb_pcount() ? hb_arrayBaseParams() : NULL; break; case HB_ERR_ARGS_SELFPARAMS: pArray = hb_arraySelfParams(); break; default: pArray = hb_itemArrayNew( ulArgCount ); va_start( va, ulArgCount ); for( ulArgPos = 1; ulArgPos <= ulArgCount; ulArgPos++ ) { PHB_ITEM pArg = va_arg( va, PHB_ITEM ); if( pArg ) hb_itemArrayPut( pArray, ulArgPos, pArg ); } va_end( va ); } if( pArray ) { /* Assign the new array to the object data item. */ hb_errPutArgsArray( pError, pArray ); /* Release the Array. */ hb_itemRelease( pArray ); } /* Ok, launch... */ uiAction = hb_errLaunch( pError ); /* Release. */ hb_errRelease( pError ); return uiAction; }
/* ===================================================================================== */ static HB_USHORT hb_errRT_PostgreSQLDD( HB_ERRCODE errGenCode, HB_ERRCODE errSubCode, const char * szDescription, const char * szOperation, HB_ERRCODE errOsCode ) { HB_USHORT uiAction; PHB_ITEM pError; pError = hb_errRT_New( ES_ERROR, "SDDPG", errGenCode, errSubCode, szDescription, szOperation, errOsCode, EF_NONE ); uiAction = hb_errLaunch( pError ); hb_itemRelease( pError ); return uiAction; }
HB_USHORT hb_errRT_BASE_Ext1( HB_ERRCODE errGenCode, HB_ERRCODE errSubCode, const char * szDescription, const char * szOperation, HB_ERRCODE errOsCode, HB_USHORT uiFlags, HB_ULONG ulArgCount, ... ) { HB_USHORT uiAction; PHB_ITEM pError; PHB_ITEM pArray; va_list va; HB_ULONG ulArgPos; pError = hb_errRT_New( ES_ERROR, HB_ERR_SS_BASE, errGenCode, errSubCode, szDescription, szOperation, errOsCode, uiFlags ); /* Build the array from the passed arguments. */ switch( ulArgCount ) { case 0: pArray = NULL; break; case HB_ERR_ARGS_BASEPARAMS: pArray = hb_pcount() ? hb_arrayBaseParams() : NULL; break; case HB_ERR_ARGS_SELFPARAMS: pArray = hb_arraySelfParams(); break; default: pArray = hb_itemArrayNew( ulArgCount ); va_start( va, ulArgCount ); for( ulArgPos = 1; ulArgPos <= ulArgCount; ulArgPos++ ) { PHB_ITEM pArg = va_arg( va, PHB_ITEM ); if( pArg ) hb_itemArrayPut( pArray, ulArgPos, pArg ); } va_end( va ); } if( pArray ) { /* Assign the new array to the object data item. */ hb_errPutArgsArray( pError, pArray ); /* Release the Array. */ hb_itemRelease( pArray ); } /* Ok, launch... */ uiAction = hb_errLaunch( pError ); hb_errRelease( pError ); return uiAction; }
HB_USHORT hb_errRT_TERM( HB_ERRCODE errGenCode, HB_ERRCODE errSubCode, const char * szDescription, const char * szOperation, HB_ERRCODE errOsCode, HB_USHORT uiFlags ) { HB_USHORT uiAction; PHB_ITEM pError = hb_errRT_New( ES_ERROR, HB_ERR_SS_TERMINAL, errGenCode, errSubCode, szDescription, szOperation, errOsCode, uiFlags ); uiAction = hb_errLaunch( pError ); hb_errRelease( pError ); return uiAction; }
HB_USHORT hb_errRT_DBCMD( HB_ERRCODE errGenCode, HB_ERRCODE errSubCode, const char * szDescription, const char * szOperation ) { HB_USHORT uiAction; PHB_ITEM pError = hb_errRT_New( ES_ERROR, HB_ERR_SS_DBCMD, errGenCode, errSubCode, szDescription, szOperation, 0, EF_NONE ); uiAction = hb_errLaunch( pError ); hb_errRelease( pError ); return uiAction; }
static HB_ERRCODE hb_errRT_SQLBASE( HB_ERRCODE errGenCode, HB_ERRCODE errSubCode, const char * szDescription, const char * szOperation ) { PHB_ITEM pError; HB_ERRCODE iRet = HB_FAILURE; if( hb_vmRequestQuery() == 0 ) { pError = hb_errRT_New( ES_ERROR, "SQLBASE", errGenCode, errSubCode, szDescription, szOperation, 0, EF_NONE ); iRet = hb_errLaunch( pError ); hb_itemRelease( pError ); } return iRet; }
static void hb_errRT_OLE( HB_ERRCODE errGenCode, HB_ERRCODE errSubCode, HB_ERRCODE errOsCode, const char * szDescription, const char * szOperation ) { PHB_ITEM pError; pError = hb_errRT_New( ES_ERROR, "WINOLE", errGenCode, errSubCode, szDescription, szOperation, errOsCode, EF_NONE ); if( hb_pcount() != 0 ) { /* HB_ERR_ARGS_BASEPARAMS */ PHB_ITEM pArray = hb_arrayBaseParams(); hb_errPutArgsArray( pError, pArray ); hb_itemRelease( pArray ); } hb_errLaunch( pError ); hb_errRelease( pError ); }
static void s_errRT_IOUSR( HB_ERRCODE errGenCode, HB_ERRCODE errSubCode, const char * szDescription ) { PHB_ITEM pError, pArray; pError = hb_errRT_New( ES_ERROR, "IOUSR", errGenCode, errSubCode, szDescription, HB_ERR_FUNCNAME, 0, EF_NONE ); pArray = hb_arrayBaseParams(); if( pArray ) { hb_errPutArgsArray( pError, pArray ); hb_itemRelease( pArray ); } hb_errLaunch( pError ); hb_itemRelease( pError ); }
static PHRB_BODY hb_hrbLoadFromFile( const char * szHrb, HB_USHORT usMode ) { PHRB_BODY pHrbBody = NULL; PHB_ITEM pError = NULL; PHB_FILE pFile; /* Open as binary */ do { pFile = hb_fileExtOpen( szHrb, hb_stackSetStruct()->HB_SET_DEFEXTENSIONS ? ".hrb" : NULL, FO_READ | FXO_SHARELOCK, NULL, pError ); if( pFile == NULL ) { pError = hb_errRT_FileError( pError, NULL, EG_OPEN, 6102, szHrb ); if( hb_errLaunch( pError ) != E_RETRY ) break; } } while( pFile == NULL ); if( pError ) hb_itemRelease( pError ); if( pFile != NULL ) { HB_SIZE nBodySize = ( HB_SIZE ) hb_fileSize( pFile ); if( nBodySize ) { char * pbyBuffer; pbyBuffer = ( char * ) hb_xgrab( nBodySize + sizeof( char ) + 1 ); hb_fileReadAt( pFile, pbyBuffer, nBodySize, 0 ); pbyBuffer[ nBodySize ] = '\0'; pHrbBody = hb_hrbLoad( ( const char * ) pbyBuffer, nBodySize, usMode, szHrb ); hb_xfree( pbyBuffer ); } hb_fileClose( pFile ); } return pHrbBody; }
/* * Select a WorkArea by the name. */ HB_ERRCODE hb_rddSelectWorkAreaAlias( const char * szAlias ) { HB_ERRCODE errCode; int iArea; HB_TRACE( HB_TR_DEBUG, ( "hb_rddSelectWorkAreaAlias(%s)", szAlias ) ); errCode = hb_rddGetAliasNumber( szAlias, &iArea ); if( errCode == HB_FAILURE ) { /* * generate an error with retry possibility * (user created error handler can open a missing database) */ PHB_ITEM pError = hb_errRT_New( ES_ERROR, NULL, EG_NOALIAS, EDBCMD_NOALIAS, NULL, szAlias, 0, EF_CANRETRY ); do { if( hb_errLaunch( pError ) != E_RETRY ) break; errCode = hb_rddGetAliasNumber( szAlias, &iArea ); } while( errCode == HB_FAILURE ); hb_itemRelease( pError ); } if( errCode == HB_SUCCESS ) { if( iArea < 1 || iArea > HB_RDD_MAX_AREA_NUM ) errCode = hb_rddSelectFirstAvailable(); else errCode = hb_rddSelectWorkAreaNumber( iArea ); } return errCode; }
void hb_memvarGetValue( PHB_ITEM pItem, PHB_SYMB pMemvarSymb ) { HB_TRACE( HB_TR_DEBUG, ( "hb_memvarGetValue(%p, %p)", pItem, pMemvarSymb ) ); if( hb_memvarGet( pItem, pMemvarSymb ) == HB_FAILURE ) { /* Generate an error with retry possibility * (user created error handler can create this variable) */ PHB_ITEM pError; pError = hb_errRT_New( ES_ERROR, NULL, EG_NOVAR, 1003, NULL, pMemvarSymb->szName, 0, EF_CANRETRY ); while( hb_errLaunch( pError ) == E_RETRY ) { if( hb_memvarGet( pItem, pMemvarSymb ) == HB_SUCCESS ) break; } hb_errRelease( pError ); } }
HB_EXTERN_BEGIN static void hb_pp_ErrorMessage( void * cargo, const char * const szMsgTable[], char cPrefix, int iCode, const char * szParam1, const char * szParam2 ) { HB_TRACE( HB_TR_DEBUG, ( "hb_pp_ErrorGen(%p, %p, %c, %d, %s, %s)", cargo, szMsgTable, cPrefix, iCode, szParam1, szParam2 ) ); HB_SYMBOL_UNUSED( cargo ); /* ignore all warning messages and errors when break or quit request */ if( cPrefix != 'W' && hb_vmRequestQuery() == 0 ) { char szMsgBuf[ 1024 ]; PHB_ITEM pError; hb_snprintf( szMsgBuf, sizeof( szMsgBuf ), szMsgTable[ iCode - 1 ], szParam1, szParam2 ); pError = hb_errRT_New( ES_ERROR, "PP", 1001, ( HB_ERRCODE ) iCode, szMsgBuf, NULL, 0, EF_NONE | EF_CANDEFAULT ); hb_errLaunch( pError ); hb_errRelease( pError ); } }
static HB_BOOL hb_copyfile( const char * pszSource, const char * pszDest ) { HB_BOOL bRetVal = HB_FALSE; PHB_FILE pSource; PHB_ITEM pError = NULL; HB_TRACE( HB_TR_DEBUG, ( "hb_copyfile(%s, %s)", pszSource, pszDest ) ); do { pSource = hb_fileExtOpen( pszSource, NULL, FO_READ | FO_SHARED | FO_PRIVATE | FXO_DEFAULTS | FXO_SHARELOCK, NULL, pError ); if( pSource == NULL ) { pError = hb_errRT_FileError( pError, NULL, EG_OPEN, 2012, pszSource ); if( hb_errLaunch( pError ) != E_RETRY ) break; } } while( pSource == NULL ); if( pError ) { hb_itemRelease( pError ); pError = NULL; } if( pSource != NULL ) { PHB_FILE pDest; do { pDest = hb_fileExtOpen( pszDest, NULL, FO_READWRITE | FO_EXCLUSIVE | FO_PRIVATE | FXO_TRUNCATE | FXO_DEFAULTS | FXO_SHARELOCK, NULL, pError ); if( pDest == NULL ) { pError = hb_errRT_FileError( pError, NULL, EG_CREATE, 2012, pszDest ); if( hb_errLaunch( pError ) != E_RETRY ) break; } } while( pDest == NULL ); if( pError ) { hb_itemRelease( pError ); pError = NULL; } if( pDest != NULL ) { HB_UCHAR * buffer; HB_SIZE nRead; buffer = ( HB_UCHAR * ) hb_xgrab( BUFFER_SIZE ); bRetVal = HB_TRUE; while( ( nRead = hb_fileRead( pSource, buffer, BUFFER_SIZE, -1 ) ) != 0 ) { HB_SIZE nWritten = 0; while( nWritten < nRead ) { nWritten += hb_fileWrite( pDest, buffer + nWritten, nRead - nWritten, -1 ); if( nWritten < nRead ) { pError = hb_errRT_FileError( pError, NULL, EG_WRITE, 2016, pszDest ); if( hb_errLaunch( pError ) != E_RETRY ) { bRetVal = HB_FALSE; break; } } } } if( pError ) hb_itemRelease( pError ); hb_xfree( buffer ); hb_fileClose( pDest ); } hb_fileClose( pSource ); #if defined( HB_OS_UNIX ) if( bRetVal ) { HB_FATTR ulAttr; if( hb_fileAttrGet( pszSource, &ulAttr ) ) hb_fileAttrSet( pszDest, ulAttr ); } #endif } return bRetVal; }
/* * Select a WorkArea by the symbol name. */ HB_ERRCODE hb_rddSelectWorkAreaSymbol( PHB_SYMB pSymAlias ) { PHB_ITEM pError; HB_ERRCODE errCode; const char * szName; int iArea; HB_TRACE( HB_TR_DEBUG, ( "hb_rddSelectWorkAreaSymbol(%p)", pSymAlias ) ); iArea = ( int ) hb_dynsymAreaHandle( pSymAlias->pDynSym ); if( iArea ) { hb_rddSelectWorkAreaNumber( iArea ); return HB_SUCCESS; } szName = hb_dynsymName( pSymAlias->pDynSym ); if( szName[ 0 ] && ! szName[ 1 ] ) { if( szName[ 0 ] >= 'A' && szName[ 0 ] <= 'K' ) { hb_rddSelectWorkAreaNumber( szName[ 0 ] - 'A' + 1 ); return HB_SUCCESS; } else if( szName[ 0 ] >= 'a' && szName[ 0 ] <= 'k' ) { hb_rddSelectWorkAreaNumber( szName[ 0 ] - 'a' + 1 ); return HB_SUCCESS; } else if( szName[ 0 ] == 'M' || szName[ 0 ] == 'm' ) { hb_rddSelectWorkAreaNumber( HB_RDD_MAX_AREA_NUM ); return HB_SUCCESS; } } /* * generate an error with retry possibility * (user created error handler can open a missing database) */ pError = hb_errRT_New( ES_ERROR, NULL, EG_NOALIAS, EDBCMD_NOALIAS, NULL, pSymAlias->szName, 0, EF_CANRETRY ); errCode = HB_FAILURE; do { if( hb_errLaunch( pError ) != E_RETRY ) break; iArea = ( int ) hb_dynsymAreaHandle( pSymAlias->pDynSym ); if( iArea ) { hb_rddSelectWorkAreaNumber( iArea ); errCode = HB_SUCCESS; } } while( errCode == HB_FAILURE ); hb_itemRelease( pError ); return errCode; }
static HB_BOOL hb_copyfile( const char * szSource, const char * szDest ) { HB_BOOL bRetVal = HB_FALSE; HB_FHANDLE fhndSource; PHB_ITEM pError = NULL; HB_TRACE( HB_TR_DEBUG, ( "hb_copyfile(%s, %s)", szSource, szDest ) ); do { fhndSource = hb_fsExtOpen( szSource, NULL, FO_READ | FXO_DEFAULTS | FXO_SHARELOCK, NULL, pError ); if( fhndSource == FS_ERROR ) { pError = hb_errRT_FileError( pError, NULL, EG_OPEN, 2012, szSource ); if( hb_errLaunch( pError ) != E_RETRY ) break; } } while( fhndSource == FS_ERROR ); if( fhndSource != FS_ERROR ) { HB_FHANDLE fhndDest; do { fhndDest = hb_fsExtOpen( szDest, NULL, FXO_TRUNCATE | FO_READWRITE | FO_EXCLUSIVE | FXO_DEFAULTS | FXO_SHARELOCK, NULL, pError ); if( fhndDest == FS_ERROR ) { pError = hb_errRT_FileError( pError, NULL, EG_CREATE, 2012, szDest ); if( hb_errLaunch( pError ) != E_RETRY ) break; } } while( fhndDest == FS_ERROR ); if( fhndDest != FS_ERROR ) { #if defined( HB_OS_UNIX ) struct stat struFileInfo; int iSuccess = fstat( fhndSource, &struFileInfo ); #endif void * buffer; HB_USHORT usRead; buffer = hb_xgrab( BUFFER_SIZE ); bRetVal = HB_TRUE; while( ( usRead = hb_fsRead( fhndSource, buffer, BUFFER_SIZE ) ) != 0 ) { while( hb_fsWrite( fhndDest, buffer, usRead ) != usRead ) { pError = hb_errRT_FileError( pError, NULL, EG_WRITE, 2016, szDest ); if( hb_errLaunch( pError ) != E_RETRY ) { bRetVal = HB_FALSE; break; } } } hb_xfree( buffer ); #if defined( HB_OS_UNIX ) if( iSuccess == 0 ) fchmod( fhndDest, struFileInfo.st_mode ); #endif hb_fsClose( fhndDest ); } hb_fsClose( fhndSource ); } if( pError ) hb_itemRelease( pError ); return bRetVal; }
/* throwing a CT-subsystem error without value substitution - function adapted from errorapi.c */ HB_USHORT ct_error( HB_USHORT uiSeverity, HB_ERRCODE errGenCode, HB_ERRCODE errSubCode, const char * szDescription, const char * szOperation, HB_ERRCODE errOsCode, HB_USHORT uiFlags, HB_ULONG ulArgCount, ... ) { HB_USHORT uiAction; PHB_ITEM pError; PHB_ITEM pArray; va_list va; HB_ULONG ulArgPos; HB_TRACE( HB_TR_DEBUG, ( "ct_error(%hu, %d, %d, %s, %s, %d, %hu, %lu)", uiSeverity, errGenCode, errSubCode, szDescription, szOperation, errOsCode, uiFlags, ulArgCount ) ); pError = hb_errRT_New( uiSeverity, CT_SUBSYSTEM, errGenCode, errSubCode, szDescription, szOperation, errOsCode, uiFlags ); /* Build the array from the passed arguments. */ if( ulArgCount == 0 ) { pArray = NULL; } else if( ulArgCount == HB_ERR_ARGS_BASEPARAMS ) { if( hb_pcount() == 0 ) pArray = NULL; else pArray = hb_arrayBaseParams(); } else if( ulArgCount == HB_ERR_ARGS_SELFPARAMS ) { pArray = hb_arraySelfParams(); } else { pArray = hb_itemArrayNew( ulArgCount ); va_start( va, ulArgCount ); for( ulArgPos = 1; ulArgPos <= ulArgCount; ulArgPos++ ) { hb_itemArrayPut( pArray, ulArgPos, va_arg( va, PHB_ITEM ) ); } va_end( va ); } if( pArray ) { /* Assign the new array to the object data item. */ hb_vmPushSymbol( hb_dynsymGetSymbol( "_ARGS" ) ); hb_vmPush( pError ); hb_vmPush( pArray ); hb_vmSend( 1 ); /* Release the Array. */ hb_itemRelease( pArray ); } /* launch error codeblock */ uiAction = hb_errLaunch( pError ); /* release error codeblock */ hb_errRelease( pError ); return uiAction; }