diff options
Diffstat (limited to 'src/utils')
-rwxr-xr-x | src/utils/checkndx.cpp | 71 | ||||
-rwxr-xr-x | src/utils/dbfxtrct.cpp | 182 | ||||
-rwxr-xr-x | src/utils/preamble.txt | 19 | ||||
-rwxr-xr-x | src/utils/reindex.cpp | 83 | ||||
-rwxr-xr-x | src/utils/xb_dbfutil.cpp | 87 | ||||
-rwxr-xr-x | src/utils/xb_pack.cpp | 13 | ||||
-rwxr-xr-x | src/utils/xb_tblinfo.cpp | 18 |
7 files changed, 85 insertions, 388 deletions
diff --git a/src/utils/checkndx.cpp b/src/utils/checkndx.cpp deleted file mode 100755 index adb5e1c..0000000 --- a/src/utils/checkndx.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/* - Xbase64 project source code - - Copyright (C) 1997,2003 Gary A. Kunkel - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - Contact: - - Email: - - xbase64-devel@lists.sourceforge.net - xbase64-users@lists.sourceforge.net - -*/ - - -// FIXME - program needs to be updated - -#include <xbase64/xbase64.h> - -int main(int ac,char** av) -{ -#ifdef XBASE_DEBUG - xbXBase x; - xbDbf d( &x ); - xbNdx i( &d ); - xbInt16 rc; - - if( 3 != ac ){ - std::cout << - "\nUsage: checkndx dbf_file index_file\n"; - return 1; - } - - if(( rc = d.Open( av[1] )) != XB_NO_ERROR ) - { - std::cout << "\nCould not open file " << av[1] << " rc = " << rc << "\n"; - return 2; - } - - if(( rc = i.OpenIndex( av[2] )) != XB_NO_ERROR ) - { - std::cout << "\nCould not open file " << av[2] << " rc = " << rc << "\n"; - return 3; - } - - std::cout << "\nRunning...\n"; - rc = i.CheckIndexIntegrity( 1 ); - std::cout << "\nNdx integrity check = " << rc << "\n"; - - i.DumpHdrNode(0); - - d.Close(); -#else - std::cout << "\nXBASE_DEBUG is not compiled in\n"; -#endif - return 0; -} diff --git a/src/utils/dbfxtrct.cpp b/src/utils/dbfxtrct.cpp deleted file mode 100755 index 17752c1..0000000 --- a/src/utils/dbfxtrct.cpp +++ /dev/null @@ -1,182 +0,0 @@ -/* - Xbase64 project source code - - This program extracts data from a dbf data file and puts it in - a comma delimited output file, suitable for input into an awk or - perl script - - This program excludes all memo fields - - Copyright (C) 1997,2003 Gary A. Kunkel - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - Contact: - - Email: - - xbase64-devel@lists.sourceforge.net - xbase64-users@lists.sourceforge.net - -*/ - -#include <xbase64/xbase64.h> - - -// FIXME - program need to be updated - -/*************************************************************************/ -void Usage(); -void Usage() -{ - std::cout << "\nUsage: dbfxtrct -iDATABASE.DBF -sINDEX.N[TD]X -f -F -dMM/DD/YY\n"; - std::cout << "\nWhere DATABASE.DBF is the name of the database file to dump\n"; - std::cout << "INDEX.NTX or .NDX is an optional index sort paramater\n"; - std::cout << "-f optional field name list in first record\n"; - std::cout << "-F optional field name and attributes in first record\n"; - std::cout << "MM/DD/YY is an optional output date format for any date fields\n"; - std::cout << "\nThis program creates output suitable for awk and perl scripts\n"; - std::cout << "\nThis program does not support memo fields (yet).\n"; -} -/*************************************************************************/ -int main(int ac,char** av) -{ - xbXBase x; - xbDbf d( &x ); - xbInt16 rc, FieldOption = 0; - xbIndex *ix = 0; - xbNdx z(&d); - - char *dbfname = NULL; - char *ixname = NULL; - char *p; - char buf[200]; - xbExpn exp( &x ); - -/* Get the input paramaters - - -i input datafile name - -s optional sort index name - -f optional field names in record one - -F optional field names and attributes in record one - -d date format -*/ - for( int i = 1; i < ac; i++ ) - { - p = av[i]; - if( *p != '-' ){ - std::cout << "Invalid paramater " << *p << std::endl; - Usage(); - return 1; - } - p++; - if( *p == 'i' ) - dbfname = ++p; - else if( *p == 's' ) - ixname = ++p; - else if( *p == 'f' ) - FieldOption = 1; - else if( *p == 'F' ) - FieldOption = 2; - else if( *p == 'd' ) - x.SetDefaultDateFormat( ++p ); - else{ - std::cout << "Invalid paramater " << *p << std::endl; - Usage(); - return 1; - } - } - -/* if missing params, display a usage message and exit */ - - if( !dbfname ){ - Usage(); - return 1; - } - -/* open the database file */ - - if(( rc = d.Open( dbfname )) != XB_NO_ERROR ) - { - std::cout << "\nCould not open file " << dbfname << " rc = " << rc - << "\n"; - return 2; - } - -/* if an index was specified, open the index file */ - - if( ixname ){ - -#ifdef XB_INDEX_NTX - if( strstr( ixname, "NTX" )) - ix = new xbNtx( &d ); -#endif - -#ifdef XB_INDEX_NDX - if( strstr( ixname, "NDX" )) - ix = new xbNdx( &d ); -#endif - if( !ix ){ - std::cout << "Unknown index type. .NTX and .NDX index file support only\n"; - return 3; - } - if(( rc = ix->OpenIndex( ixname )) != XB_NO_ERROR ) - { - std::cout << "\nCould not open index " << ixname << " rc = " << rc - << "\n"; - return 4; - } - } - - -/* if -f or -F paramater, dump the header information */ - if( FieldOption ){ - for( xbLong l = 0; l < d.FieldCount(); l++ ){ - if( l ) std::cout << ","; - std::cout << d.GetFieldName(l); - if( FieldOption == 2 ){ - std::cout << "|" << d.GetFieldType(l) << "|" << d.GetFieldLen(l); - std::cout << "|" << d.GetFieldDecimal(l); - } - } - std::cout << std::endl; - } - -/* if an index used, then loop thru each record, based on index, else - dump in dbf sort order */ - if( ixname ) - rc = ix->GetFirstKey(); - else - rc = d.GetFirstRecord(); - - while( rc == XB_NO_ERROR ){ - for( xbLong l = 0; l < d.FieldCount(); l++ ){ - if( l ) std::cout << ","; - strcpy( buf, exp.LTRIM( d.GetStringField( l ))); - if( d.GetFieldType( l ) == 'D' ) - std::cout << exp.DTOC( buf ); - else - std::cout << exp.TRIM( buf ); - } - if( ixname ) - rc = ix->GetNextKey(); - else - rc = d.GetNextRecord(); - std::cout << std::endl; - } - - d.Close(); - return 0; -} diff --git a/src/utils/preamble.txt b/src/utils/preamble.txt deleted file mode 100755 index e2aeda8..0000000 --- a/src/utils/preamble.txt +++ /dev/null @@ -1,19 +0,0 @@ -/* xbXXXXX.XXX - -XBase64 Software Library - -Copyright (c) 1997,2003,2014,2017 Gary A Kunkel - -The xb64 software library is covered under -the terms of the GPL Version 3, 2007 license. - -Email Contact: - - xb64-devel@lists.sourceforge.net - xb64-users@lists.sourceforge.net - -*/ - - -namespace xb{ - diff --git a/src/utils/reindex.cpp b/src/utils/reindex.cpp deleted file mode 100755 index 3013167..0000000 --- a/src/utils/reindex.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/* - Xbase64 project source code - - This sample program packs an Xbase DBF file - - Copyright (C) 1997,2003 Gary A. Kunkel - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - Contact: - - Email: - - xbase64-devel@lists.sourceforge.net - xbase64-users@lists.sourceforge.net -*/ - - -// FIXME - program needs to be updated - -#include <xbase64/xbase64.h> - -static void -showStatus(xbLong itemNum, xbLong numItems) -{ - printf("indexing record %ld of %ld\r", itemNum, numItems); - fflush(stdout); -} - -int main(int ac,char** av) -{ - if (3 != ac) { - std::cout << - "\nUsage: reindex dbf_file ndx_file\n" - ; - return 1; - } - - char* filename = av[1]; - char* filename2 = av[2]; - - xbXBase x; - xbDbf MyFile( &x ); - xbNdx MyIndex( &MyFile ); - - if( MyFile.Open( filename )) { - std::cout << "Could not open file " << filename << "\n"; - return 0; - } - if( MyIndex.OpenIndex( filename2 )) { - std::cout << "Could not open index file " << filename2 << "\n"; - return 0; - } - - xbInt16 rc = MyIndex.ReIndex(showStatus); - printf("\n"); - if( rc != XB_NO_ERROR ) { - std::cout << "\nError reindexing index ==> " << filename2; - std::cout << " Return Code = " << rc; - } - - /* or - if(( rc = MyFile.RebuildAllIndicis()) != XB_NO_ERROR ) - { - std::cout << "\nError reindexing..."; - std::cout << "\nReturn Code = " << rc; - } - */ - MyFile.Close(); - return 0; -} diff --git a/src/utils/xb_dbfutil.cpp b/src/utils/xb_dbfutil.cpp index e008155..9c04fe3 100755 --- a/src/utils/xb_dbfutil.cpp +++ b/src/utils/xb_dbfutil.cpp @@ -87,6 +87,7 @@ class xbUtil{ void CopyDbfStructure(); void UpdateTableAutoCommit(); void DisplayTableInfo(); + void RenameTable(); // 4 - RecordMenu options void GetRecord(); @@ -136,18 +137,18 @@ class xbUtil{ #ifdef XB_INDEX_SUPPORT void LockIndices(); void UnlockIndices(); - #endif // XB_INDEX_SUPPORT + #endif // XB_INDEX_SUPPORT #ifdef XB_MEMO_SUPPORT void LockMemo(); void UnlockMemo(); - #endif + #endif // XB_MEMO_SUPPORT void LockHeader(); void UnlockHeader(); void xbFileLock(); void xbFileUnlock(); - #endif + #endif // XB_LOCKING_SUPPORT // 7 - Expression Menu options #ifdef XB_EXPRESSION_SUPPORT @@ -159,8 +160,8 @@ class xbUtil{ void IsLeapYear(); #ifdef XB_DEBUG_SUPPORT void DumpExpressionTree(); - #endif - #endif + #endif // XB_DEBUG_SUPPORT + #endif // XB_EXPRESSION_SUPPORT // 8 - Index Menu Options #ifdef XB_INDEX_SUPPORT @@ -345,10 +346,12 @@ void xbUtil::UnlockIndices(){ x.DisplayError( iRc ); } -#endif // XB_LOCKING_SUPPORT +#endif // XB_LOCKING_SUPPORT +#endif // XB_INDEX_SUPPORT /*************************************************************************************/ +#ifdef XB_EXPRESSION_SUPPORT void xbUtil::ParseExpression( xbInt16 iOption ){ if( iOption == 0 ) @@ -395,9 +398,9 @@ void xbUtil::ProcessParsedExpression( xbInt16 iOption ){ if( !exp ) return; - std::cout << "Dump from w/i dbfutil before processing expression\n"; - exp->DumpTree( xbTrue ); - std::cout << "-- end of dumptree in dbfutil before processExpression\n"; + // std::cout << "Dump from w/i dbfutil before processing expression\n"; + //exp->DumpTree( xbTrue ); + //std::cout << "-- end of dumptree in dbfutil before processExpression\n"; xbInt16 iRc = exp->ProcessExpression(); if( iRc != XB_NO_ERROR ){ @@ -405,9 +408,9 @@ void xbUtil::ProcessParsedExpression( xbInt16 iOption ){ return; } - std::cout << "Dump from w/i dbfutil after processing expression\n"; - exp->DumpTree( xbTrue ); - std::cout << "-- end of dumptree in dbfutil\n"; + //std::cout << "Dump from w/i dbfutil after processing expression\n"; + //exp->DumpTree( xbTrue ); + //std::cout << "-- end of dumptree in dbfutil\n"; xbString sResult; xbDouble dResult; @@ -455,7 +458,6 @@ void xbUtil::DumpExpressionTree(){ } #endif // XB_DEBUG_SUPPORT - void xbUtil::JulToDate8(){ std::cout << "Convert Julian Date to Date8 (CCYYMMDD) format" << std::endl; std::cout << "Enter Julian Value" << std::endl; @@ -1427,6 +1429,31 @@ void xbUtil::DisplayTableInfo(){ } /*************************************************************************************/ +void xbUtil::RenameTable(){ + + if( !dActiveTable ) + dActiveTable = GetTablePtr( " - select table" ); + + if( !dActiveTable ){ + std::cout << "No table selected" << std::endl; + return; + } + + char cBuf[128]; + std::cout << "Enter new tablefile name (filename.DBF)" << std::endl; + std::cin.getline( cBuf, 128 ); + + if( cBuf[0] ){ + dActiveTable->Rename( cBuf ); + dActiveTable->Close(); + dActiveTable = NULL; + std::cout << "Table closed. Reopen if needed.\n"; + } + + +} + +/*************************************************************************************/ void xbUtil::GetRecord(){ char cBuf[15]; @@ -1528,7 +1555,7 @@ void xbUtil::UpdateTableAutoCommit(){ std::cout << "ON]" << std::endl; else std::cout << "OFF]" << std::endl; - std::cout << " 0 ==> Disable Auto Commit for table" << std::endl; + std::cout << " 0 ==> Disable Auto Commit for table" << std::endl; std::cout << " 1 ==> Enable Auto Commit for table" << std::endl; std::cout << "Current setting is [" << d->GetAutoCommit() << "]" << std::endl; char cBuf[15]; @@ -1546,7 +1573,7 @@ void xbUtil::UpdateTableAutoCommit(){ } d->SetAutoCommit( iAuto ); std::cout << "Auto Commit set to [" << d->GetAutoCommit(0) << "]" << std::endl; - if( d->GetAutoCommit() ) + if( d->GetAutoCommit() ) std::cout << "Auto Commit enabled for table" << std::endl; else std::cout << "Auto Commit disabled for table" << std::endl; @@ -1582,7 +1609,7 @@ void xbUtil::CopyDbfStructure(){ return; } std::cout << "Copy Table" << std::endl; - std::cout << "Enter new DBF file name (ie; myfile.dbf or MYFILE.DBF): "; + std::cout << "Enter new DBF file name (ie; MYFILE.DBF): "; std::cin.getline( filename, 128 ); f.SetFileName( filename ); if( strlen( filename ) == 0 ){ @@ -1725,7 +1752,7 @@ void xbUtil::Open(){ unsigned char cFileTypeByte; std::cout << "Open Table" << std::endl; - std::cout << "Enter DBF file name (.dbf or .DBF): "; + std::cout << "Enter DBF file name (.DBF): "; std::cin.getline( filename, 128 ); f.SetFileName( filename ); @@ -2138,6 +2165,8 @@ void xbUtil::ProcessOption( const xbString &sOption ){ UpdateTableAutoCommit(); else if( sOption == "=3.14" ) DisplayTableInfo(); + else if( sOption == "=3.15" ) + RenameTable(); else if( sOption == "=4" ) RecordMenu(); else if( sOption == "=4.1" ) @@ -2169,7 +2198,7 @@ void xbUtil::ProcessOption( const xbString &sOption ){ else if( sOption == "=4.14" ) CommitRecord(); #ifdef XB_FILTER_SUPPORT - else if( sOption == "=4.20" ) + else if( sOption == "=4.20" ) SetFilter(); else if( sOption == "=4.21" ) GetFirstFilterRec(); @@ -2238,8 +2267,8 @@ void xbUtil::ProcessOption( const xbString &sOption ){ xbFileLock(); else if( sOption == "=6.21" ) xbFileUnlock(); - #endif - #endif + #endif // XB_DEBUG_SUPPORT + #endif // XB_LOCKING_SUPPORT #ifdef XB_EXPRESSION_SUPPORT else if( sOption == "=7" ) @@ -2250,6 +2279,7 @@ void xbUtil::ProcessOption( const xbString &sOption ){ ProcessParsedExpression( 0 ); else if( sOption == "=7.3" ) ParseAndProcessExpression(); + #ifdef XB_DEBUG_SUPPORT else if (sOption == "=7.4" ) DumpExpressionTree(); @@ -2263,7 +2293,6 @@ void xbUtil::ProcessOption( const xbString &sOption ){ #endif // XB_EXPRESSION_SUPPORT #ifdef XB_INDEX_SUPPORT - else if( sOption == "=8" ) IndexMenu(); else if( sOption == "=8.1" ) @@ -2408,11 +2437,12 @@ void xbUtil::IndexMenu() std::cout << " 10 - Get Prev Key" << std::endl; std::cout << " 11 - Get Last Key" << std::endl; std::cout << " 12 - Find Key" << std::endl; - std::cout << " 13 - Check Index Integrity" << std::endl; + std::cout << " 13 - Check Index Integrity" << std::endl; std::cout << " 14 - Reindex" << std::endl; std::cout << " 15 - Delete Tag" << std::endl; std::cout << " 16 - Associate NDX file" << std::endl; - + + #ifdef XB_DEBUG_SUPPORT std::cout << std::endl; std::cout << " 20 - Dump Header" << std::endl; @@ -2768,6 +2798,8 @@ void xbUtil::FileMenu() std::cout << "12 - Copy Dbf Structure" << std::endl; std::cout << "13 - Update Table Auto Commit Setting" << std::endl; std::cout << "14 - Display Table Info" << std::endl; + std::cout << "15 - Rename Table" << std::endl; + std::cout << "99 - Exit Menu" << std::endl; option = GetOption(); @@ -2787,6 +2819,7 @@ void xbUtil::FileMenu() case 12: CopyDbfStructure(); break; case 13: UpdateTableAutoCommit(); break; case 14: DisplayTableInfo(); break; + case 15: RenameTable(); break; case 99: break; default: std::cout << "Invalid Option" << std::endl; @@ -2886,7 +2919,10 @@ void xbUtil::SystemMenu() void xbUtil::MainMenu() { int option = 0; - std::cout << std::endl<< std::endl << "XBase64 Utility Program"; + std::cout << std::endl<< std::endl << "XBase64 Utility Program " << + xbase_VERSION_MAJOR << "." << xbase_VERSION_MINOR << "." << + xbase_VERSION_PATCH << "\n"; + DisplayActiveTable(); while( option != 99 ) { std::cout << std::endl << std::endl << " 0 - Main Menu" << std::endl; @@ -2968,6 +3004,7 @@ void xbUtil::MainMenu() } } /*************************************************************************************/ + #ifdef XB_INDEX_SUPPORT void xbUtil::DisplayOpenIndexFiles(){ @@ -3425,8 +3462,8 @@ void xbUtil::AssociateNonProdIx(){ std::cout << "See InfFile menu option, option 11 from the main menu or =11 from here\n"; } -#ifdef XB_DEBUG_SUPPORT +#ifdef XB_DEBUG_SUPPORT void xbUtil::DumpRecsByIx( xbInt16 iOpt ){ // iDirection = 0 - Forward - MDX // = 1 - Reverse - MDX diff --git a/src/utils/xb_pack.cpp b/src/utils/xb_pack.cpp index ba61837..ccec5a3 100755 --- a/src/utils/xb_pack.cpp +++ b/src/utils/xb_pack.cpp @@ -22,11 +22,7 @@ int main(int ac,char** av) if (ac <= 1) { std::cout << "\nUsage: xb_pack filename...\n" - "\nThis program does not automatically reindex any NDX indexes." - "\nUse the reindex program to reindex any indexes associated" - "\nwith the database, or build your own program which executes " - "\nthe Pack() method after opening all the index files " - "\nassociated with the database.\n\n"; + "\nThis program does automatically reindexes any open NDX or MDX indexes."; return 1; } @@ -44,6 +40,13 @@ int main(int ac,char** av) std::cout << " Return Code = " << iRc << std::endl; } + #ifdef XB_INDEX_SUPPORT + if(( iRc = MyFile->Reindex( 1 )) != XB_NO_ERROR ) { + std::cout << "\nError reindexing DBF database ==> " << av[1] << std::endl; + std::cout << " Return Code = " << iRc << std::endl; + } + #endif // XB_INDEX_SUPPORT + MyFile->Close(); delete MyFile; diff --git a/src/utils/xb_tblinfo.cpp b/src/utils/xb_tblinfo.cpp index 884ce5e..6b88403 100755 --- a/src/utils/xb_tblinfo.cpp +++ b/src/utils/xb_tblinfo.cpp @@ -23,11 +23,17 @@ int main( int ac, char ** av ){ xbXBase x; xbBool bHdr = xbFalse; - xbBool bMdxFound = xbFalse; xbInt16 iRc; xbString sTagName; xbDbf *MyFile = NULL; + #ifdef XB_MDX_SUPPORT + #ifdef XB_DEBUG_SUPPORT + xbBool bMdxFound = xbFalse; + #endif // XB_DEBUG_SUPPORT + #endif // XB_MDX_SUPPORT + + x.EnableMsgLogging(); x.SetLogSize( 1000000L ); @@ -63,6 +69,7 @@ int main( int ac, char ** av ){ } MyFile->DumpHeader( 4 ); + #ifdef XB_MDX_SUPPORT // for each mdx file, dump the header xbIxList *ixl = MyFile->GetIxList(); xbIx *ixp; @@ -71,18 +78,23 @@ int main( int ac, char ** av ){ ixp = ixl->ix; ixp->GetFileType( sFileType ); + #ifdef XB_DEBUG_SUPPORT if( sFileType == "MDX" ){ bMdxFound = xbTrue; if( bHdr ){ - // std::cout << "MDX header\n"; ixp->DumpHeader( 1, 3 ); } } + #endif // XB_DEBUG_SUPPORT ixl = ixl->next; - } + } + #ifdef XB_DEBUG_SUPPORT if( !bMdxFound ) std::cout << "No MDX index for file." << std::endl; + #endif // XB_DEBUG_SUPPORT + #endif // XB_MDX_SUPPORT + MyFile->Close(); delete MyFile; |