PHB_DYNS hb_dynsymFindWithNamespaces( const char * szName, const char * pNamespaces ) { if( pNamespaces ) { char * szNamespace = ( char * ) pNamespaces; PHB_DYNS pDynSym; while( *szNamespace ) { char * szQualified = hb_xstrcpy( NULL, szNamespace, ".", szName, NULL ); pDynSym = hb_dynsymFind( szQualified ); hb_xfree( szQualified ); if( pDynSym ) return pDynSym; szNamespace += strlen( szNamespace ) + 1; } return NULL; } else return hb_dynsymFind( szName ); }
char * hb_langName( void ) { char * pszName = ( char * ) hb_xgrab( 128 ); if( s_lang ) hb_snprintf( pszName, 128, "Harbour Language: %s %s (%s)", ( char * ) hb_langDGetItem( HB_LANG_ITEM_BASE_ID + HB_LANG_ITEM_ID_ID ), ( char * ) hb_langDGetItem( HB_LANG_ITEM_BASE_ID + HB_LANG_ITEM_ID_NAME ), ( char * ) hb_langDGetItem( HB_LANG_ITEM_BASE_ID + HB_LANG_ITEM_ID_NAMENAT ) ); else hb_xstrcpy( pszName, "Harbour Language: (not installed)", 0 ); return pszName; }
PHB_DYNS hb_dynsymFindNameWithNamespaces( const char * szName, const char *pNamespaces ) { if( pNamespaces ) { char *szNamespace = (char *) pNamespaces; PHB_DYNS pDynSym; char szUprName[ HB_SYMBOL_NAME_LEN + 1 ]; { int iLen = HB_SYMBOL_NAME_LEN; char * pDest = szUprName; do { char cChar = *szName++; if( cChar == 0 || cChar == ' ' || cChar == '\t' ) break; else if( cChar >= 'a' && cChar <= 'z' ) *pDest++ = cChar - ( 'a' - 'A' ); else *pDest++ = cChar; } while( --iLen ); *pDest = '\0'; } while ( *szNamespace ) { char *szQualified = hb_xstrcpy( NULL, szNamespace, ".", szUprName, NULL ); pDynSym = hb_dynsymFindName( szQualified ); hb_xfree( szQualified ); if( pDynSym ) { return pDynSym; } szNamespace += strlen( szNamespace ) + 1; } return NULL; } else { return hb_dynsymFindName( szName ); } }
static char * s_sockexName( PHB_SOCKEX pSock ) { char * pszName = hb_sockexIsRaw( HB_BFSOCK_GET( pSock )->sock ) ? NULL : hb_sockexName( HB_BFSOCK_GET( pSock )->sock ); if( pszName ) { char * pszFree = pszName; pszName = hb_xstrcpy( NULL, pSock->pFilter->pszName, "|", pszName, NULL ); hb_xfree( pszFree ); } else pszName = hb_strdup( pSock->pFilter->pszName ); return pszName; }
PHB_ITEM hb_fsDirectory( const char * pszDirSpec, const char * pszAttributes, HB_BOOL fDateTime ) { PHB_ITEM pDir = hb_itemArrayNew( 0 ); char * pszFree = NULL; PHB_FFIND ffind; HB_FATTR ulMask; /* Get the passed attributes and convert them to Harbour Flags */ ulMask = HB_FA_ARCHIVE | HB_FA_READONLY; if( pszAttributes && *pszAttributes ) ulMask |= hb_fsAttrEncode( pszAttributes ); if( pszDirSpec && *pszDirSpec ) { if( ulMask != HB_FA_LABEL ) { /* CA-Cl*pper compatible behavior - add all file mask when * last character is directory or drive separator */ HB_SIZE nLen = strlen( pszDirSpec ) - 1; #ifdef HB_OS_HAS_DRIVE_LETTER if( pszDirSpec[ nLen ] == HB_OS_PATH_DELIM_CHR || pszDirSpec[ nLen ] == HB_OS_DRIVE_DELIM_CHR ) #else if( pszDirSpec[ nLen ] == HB_OS_PATH_DELIM_CHR ) #endif pszDirSpec = pszFree = hb_xstrcpy( NULL, pszDirSpec, HB_OS_ALLFILE_MASK, NULL ); } } else pszDirSpec = HB_OS_ALLFILE_MASK; /* Get the file list */ if( ( ffind = hb_fsFindFirst( pszDirSpec, ulMask ) ) != NULL ) { PHB_ITEM pSubarray = hb_itemNew( NULL ); do { char buffer[ 32 ]; hb_arrayNew ( pSubarray, F_LEN ); hb_arraySetC ( pSubarray, F_NAME, ffind->szName ); hb_arraySetNInt( pSubarray, F_SIZE, ffind->size ); hb_arraySetC ( pSubarray, F_TIME, ffind->szTime ); hb_arraySetC ( pSubarray, F_ATTR, hb_fsAttrDecode( ffind->attr, buffer ) ); if( fDateTime ) hb_arraySetTDT( pSubarray, F_DATE, ffind->lDate, ffind->lTime ); else hb_arraySetDL ( pSubarray, F_DATE, ffind->lDate ); /* Don't exit when array limit is reached */ hb_arrayAddForward( pDir, pSubarray ); } while( hb_fsFindNext( ffind ) ); hb_itemRelease( pSubarray ); hb_fsFindClose( ffind ); } if( pszFree ) hb_xfree( pszFree ); return pDir; }
/* Export DBF content to a SQL script file */ static HB_ULONG hb_db2Sql( AREAP pArea, PHB_ITEM pFields, HB_MAXINT llNext, PHB_ITEM pWhile, PHB_ITEM pFor, const char * szDelim, const char * szSep, const char * szEsc, const char * szTable, HB_FHANDLE hFile, HB_BOOL fInsert, HB_BOOL fRecno ) { PHB_FILEBUF pFileBuf; HB_ULONG ulRecords = 0; HB_USHORT uiFields = 0, ui; PHB_ITEM pTmp; HB_BOOL fWriteSep = HB_FALSE; const char * szNewLine = hb_conNewLine(); char * szInsert = NULL; HB_BOOL fEof = HB_TRUE; HB_BOOL fNoFieldPassed = ( pFields == NULL || hb_arrayLen( pFields ) == 0 ); if( SELF_FIELDCOUNT( pArea, &uiFields ) != HB_SUCCESS ) return 0; if( fInsert && szTable ) szInsert = hb_xstrcpy( NULL, "INSERT INTO ", szTable, " VALUES ( ", NULL ); pFileBuf = hb_createFBuffer( hFile, HB_FILE_BUF_SIZE ); pTmp = hb_itemNew( NULL ); while( llNext-- > 0 ) { if( pWhile ) { if( SELF_EVALBLOCK( pArea, pWhile ) != HB_SUCCESS || ! hb_itemGetL( pArea->valResult ) ) break; } if( SELF_EOF( pArea, &fEof ) != HB_SUCCESS || fEof ) break; if( pFor ) { if( SELF_EVALBLOCK( pArea, pFor ) != HB_SUCCESS ) break; } if( ! pFor || hb_itemGetL( pArea->valResult ) ) { ++ulRecords; if( szInsert ) hb_addStrToFBuffer( pFileBuf, szInsert ); if( fRecno ) { HB_ULONG ulRec = ulRecords; char szRecno[ 13 ], * szVal; szVal = szRecno + sizeof( szRecno ); *--szVal = 0; do { *--szVal = ( char ) ( ulRec % 10 ) + '0'; ulRec /= 10; } while( ulRec ); hb_addStrToFBuffer( pFileBuf, szVal ); hb_addStrToFBuffer( pFileBuf, szSep ); } if( fNoFieldPassed ) { for( ui = 1; ui <= uiFields; ui++ ) { if( SELF_GETVALUE( pArea, ui, pTmp ) != HB_SUCCESS ) break; if( fWriteSep ) hb_addStrToFBuffer( pFileBuf, szSep ); fWriteSep = hb_exportBufSqlVar( pFileBuf, pTmp, szDelim, szEsc ); } if( ui <= uiFields ) break; } else { /* TODO: exporting only some fields */ } if( szInsert ) hb_addStrToFBuffer( pFileBuf, " );" ); hb_addStrToFBuffer( pFileBuf, szNewLine ); fWriteSep = HB_FALSE; } if( SELF_SKIP( pArea, 1 ) != HB_SUCCESS ) break; if( ( llNext % 10000 ) == 0 ) hb_inkeyPoll(); } if( szInsert ) hb_xfree( szInsert ); hb_destroyFBuffer( pFileBuf ); hb_itemRelease( pTmp ); /* Writing EOF */ /* hb_fsWrite( hFile, "\x1A", 1 ); */ return ulRecords; }
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; }
/* Export field values to text file */ static HB_BOOL hb_ExportVar( HB_FHANDLE handle, PHB_ITEM pValue, const char * cDelim, PHB_CODEPAGE cdp ) { switch( hb_itemType( pValue ) ) { /* a "C" field */ case HB_IT_STRING: { char * szStrEsc; char * szString; szStrEsc = hb_strescape( hb_itemGetCPtr( pValue ), hb_itemGetCLen( pValue ), cDelim ); if( cdp ) hb_cdpnDupLen( szStrEsc, strlen( szStrEsc ), hb_vmCDP(), cdp ); szString = hb_xstrcpy( NULL, cDelim, szStrEsc, cDelim, NULL ); /* FWrite( handle, szString ) */ hb_fsWriteLarge( handle, szString, strlen( szString ) ); /* Orphaned, get rif off it */ hb_xfree( szStrEsc ); hb_xfree( szString ); break; } /* a "D" field */ case HB_IT_DATE: { char * szDate = ( char * ) hb_xgrab( 9 ); hb_itemGetDS( pValue, szDate ); hb_fsWriteLarge( handle, szDate, strlen( szDate ) ); hb_xfree( szDate ); break; } /* an "L" field */ case HB_IT_LOGICAL: hb_fsWriteLarge( handle, ( hb_itemGetL( pValue ) ? "T" : "F" ), 1 ); break; /* an "N" field */ case HB_IT_INTEGER: case HB_IT_LONG: case HB_IT_DOUBLE: { char * szResult = hb_itemStr( pValue, NULL, NULL ); if( szResult ) { HB_SIZE nLen = strlen( szResult ); const char * szTrimmed = hb_strLTrim( szResult, &nLen ); hb_fsWriteLarge( handle, szTrimmed, strlen( szTrimmed ) ); hb_xfree( szResult ); } break; } /* an "M" field or the other, might be a "V" in SixDriver */ default: /* We do not want MEMO contents */ return HB_FALSE; } return HB_TRUE; }