summaryrefslogtreecommitdiff
path: root/src/utils/xb_pack.cpp
blob: 0cbba7ed16da24c06fdac4debf56b6efe3d6a83a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*  xb_pack.cpp

XBase64 Software Library

Copyright (c) 1997,2003,2014,2017,2023 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

*/

#include <xbase.h>
using namespace xb;

void PrintHelp();
void PrintHelp(){
  std::cout << "Usage: xb_pack [-h] [-?] [--help] [-v] [--version] -i filename.DBF"  << std::endl << std::endl;
  std::cout << "This program removes data records that are flagged for deletion in a DBF file and rebuilds indices." << std::endl << std::endl;
}
void PrintVersion();
void PrintVersion(){
  std::cout << "Xbase64 Version: " << xbase_VERSION_MAJOR << "." << xbase_VERSION_MINOR << "." << xbase_VERSION_PATCH << std::endl;
}

int main(int argc, char *argv[] )
{
  xbXBase x;
  xbInt16 iRc;
  xbDbf * MyFile = NULL;

  xbString sParm;
  if (argc < 2 || x.GetCmdLineOpt( argc, argv, "-h", sParm ) ||
                  x.GetCmdLineOpt( argc, argv, "-?", sParm ) ||
                  x.GetCmdLineOpt( argc, argv, "--help", sParm )){
    PrintHelp();
    return 1;
  }

  if ( x.GetCmdLineOpt( argc, argv, "-v", sParm ) ||
       x.GetCmdLineOpt( argc, argv, "--version", sParm )){
    PrintVersion();
    return 1;
  }

  if( !x.GetCmdLineOpt( argc, argv, "-i", sParm ) || sParm == "" ){
    PrintHelp();
    return 1;
  }

  if(( iRc = x.OpenHighestVersion( sParm.Str(), "", &MyFile )) != XB_NO_ERROR ){
    std::cout << "Could not open file iRc = " << iRc  << " file = "  << sParm.Str() << std::endl;
    x.DisplayError( iRc );
    return 1;
  }

  if(( iRc  = MyFile->Pack()) != XB_NO_ERROR ) {
    std::cout << "\nError packing DBF database ==> " << sParm.Str() << std::endl;
    std::cout << " Return Code = " << iRc << std::endl;
    return 1;
  }

  #ifdef XB_INDEX_SUPPORT
  if(( iRc  = MyFile->Reindex( 1 )) != XB_NO_ERROR ) {
    std::cout << "\nError reindexing DBF database ==> " << sParm.Str() << std::endl;
    std::cout << " Return Code = " << iRc << std::endl;
    x.DisplayError( iRc );
    return 1;
  }
  #endif  // XB_INDEX_SUPPORT

  MyFile->Close();
  delete MyFile;

  std::cout << "\nPack Database complete...\n\n";
  return 0;
}