summaryrefslogtreecommitdiff
path: root/src/utils/xb_tblinfo.cpp
blob: 6b884030cf87c3f2782d6fdd9848935d6788e8a3 (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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*  xb_dumpmdx.cpp

XBase64 Software Library

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

int main( int ac, char ** av ){

  xbXBase  x;
  xbBool   bHdr      = 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 );


  if( ac <= 1 ) {
    std::cout << "\nUsage: xb_dumpmdx filename.DBF -h -tTAGNAME...\n";
    std::cout << "-h dump mdx file header (default)\n";
    std::cout << "-tTAGNAME where TAGNAME is the name of a tag for extract\n";
    return 1;
  }

  if( ac > 2 ){
    for( int i = 1; i< ac; i++ ){
      if( strstr( av[i], "-h" ))
        bHdr = xbTrue;
      else if( strstr( av[i], "-t" ))
        sTagName.Set( av[i]+2 );
    }
  }

  if( bHdr == xbFalse && sTagName == "" )
    bHdr = xbTrue;


  //  std::cout << "Hdr = " << bHdr << std::endl;
  if( sTagName != "" )
    std::cout << "Tag = " << sTagName.Str() << std::endl;

  if(( iRc = x.OpenHighestVersion( av[1], "", &MyFile )) != XB_NO_ERROR ){
    std::cout << "Could not open file iRc = " << iRc  << " file = "  << av[1] << std::endl;
    x.DisplayError( iRc );
    return 0;
  }
  MyFile->DumpHeader( 4 );

  #ifdef XB_MDX_SUPPORT
  // for each mdx file, dump the header
  xbIxList *ixl = MyFile->GetIxList();
  xbIx *ixp;
  xbString sFileType;
  while( ixl ){
    ixp = ixl->ix;
    ixp->GetFileType( sFileType );

    #ifdef XB_DEBUG_SUPPORT
    if( sFileType == "MDX" ){
      bMdxFound = xbTrue;
      if( bHdr ){
        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;

  return 0;
}