1 | /**********************************************************************
|
---|
2 | *
|
---|
3 | * IsisGdl.cpp
|
---|
4 | * Copyright (C) 2003 UNESCO
|
---|
5 | *
|
---|
6 | * A component of the Greenstone digital library software
|
---|
7 | * from the New Zealand Digital Library Project at the
|
---|
8 | * University of Waikato, New Zealand.
|
---|
9 | *
|
---|
10 | * This program is free software; you can redistribute it and/or modify
|
---|
11 | * it under the terms of the GNU General Public License as published by
|
---|
12 | * the Free Software Foundation; either version 2 of the License, or
|
---|
13 | * (at your option) any later version.
|
---|
14 | *
|
---|
15 | * This program is distributed in the hope that it will be useful,
|
---|
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
18 | * GNU General Public License for more details.
|
---|
19 | *
|
---|
20 | * You should have received a copy of the GNU General Public License
|
---|
21 | * along with this program; if not, write to the Free Software
|
---|
22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
23 | *
|
---|
24 | *********************************************************************/
|
---|
25 |
|
---|
26 | // IsisGdl.cpp : Defines the entry point for the console application.
|
---|
27 | //
|
---|
28 |
|
---|
29 | #include "stdafx.h"
|
---|
30 | #include "IsisDb.h"
|
---|
31 | #include <iostream>
|
---|
32 |
|
---|
33 | void PausePrg()
|
---|
34 | {
|
---|
35 | std::cout << "\n";
|
---|
36 | std::cout << "Press enter to continue..." << "\n";
|
---|
37 | std::cin.get();
|
---|
38 | }
|
---|
39 |
|
---|
40 | void ClearInputStream(std::istream &s)
|
---|
41 | // Used to clear istream
|
---|
42 | {
|
---|
43 | char c;
|
---|
44 | s.clear();
|
---|
45 | while(s.get(c) && c != '\n') { ; }
|
---|
46 | }
|
---|
47 |
|
---|
48 | // Should be called with the master file name as parameter
|
---|
49 | // IsisGdl "full_path\master_file_name"
|
---|
50 | // IsisGdl C:\IsisGdl\cds.mst for ex
|
---|
51 |
|
---|
52 |
|
---|
53 | int main(int argc, _TCHAR* argv[])
|
---|
54 | {
|
---|
55 |
|
---|
56 | if (argc < 2)
|
---|
57 | {
|
---|
58 | std::cout << "usage: IsisGdl master_file_full_name" << std::endl;
|
---|
59 | return 1;
|
---|
60 | }
|
---|
61 | // Instantiation of the IsisDb Object
|
---|
62 | IsisDb db;
|
---|
63 | try
|
---|
64 | {
|
---|
65 | // The file name should be prefixed with the full path
|
---|
66 | // and should be the master file name with extension ".mst"
|
---|
67 | // "C:\IsisGdl\cds.mst" for ex
|
---|
68 | db.OpenDb(argv[1]);
|
---|
69 | }
|
---|
70 | catch(CIsisDbException e)
|
---|
71 | {
|
---|
72 | std::string msg = "Cannot open isis db: ";
|
---|
73 | msg += argv[1];
|
---|
74 | msg += isisExceptionMessage((IsisError) e.m_iError);
|
---|
75 | std::cerr<< msg << std::endl;
|
---|
76 | return false;
|
---|
77 | }
|
---|
78 |
|
---|
79 | // Create a Master File object without the Field Definition
|
---|
80 | // Information
|
---|
81 | MfRecord mfr(0);
|
---|
82 |
|
---|
83 | // Extract the number of the next master file number to
|
---|
84 | // assign
|
---|
85 | const long nextMfn = db.GetNextMfn();
|
---|
86 |
|
---|
87 |
|
---|
88 |
|
---|
89 | // Browse the master file in increasing order of Master
|
---|
90 | // file numbers (MFN is the record ID)
|
---|
91 | for (long i=1; i<nextMfn; i++)
|
---|
92 | {
|
---|
93 |
|
---|
94 | int status = db.ReadDbRecord(i, mfr);
|
---|
95 |
|
---|
96 | if (status == Active || status == LogicalyDeleted)
|
---|
97 | {
|
---|
98 | // If the record is physically on the master file
|
---|
99 | // then get the vector of field tags.
|
---|
100 |
|
---|
101 | // 1) Repetitive fields have the same tag and are stored in
|
---|
102 | // a single field but are separated by the "%" char
|
---|
103 | // 2) Subfields are separated by "^"letter (^a ^b ^c ...)
|
---|
104 | //
|
---|
105 | // 3) Terms or Phrases between "<>" are terms/Phrases to
|
---|
106 | // index
|
---|
107 | std::vector<int> vf = mfr.GetFieldTags();
|
---|
108 | std::cout << "----------" << std::endl;
|
---|
109 | // << "mfn=" << i
|
---|
110 | // << " nvf=" << vf.size() << std::endl;
|
---|
111 |
|
---|
112 | for (int j=0; j<vf.size(); j++)
|
---|
113 | {
|
---|
114 | std::string stemp;
|
---|
115 | // Special case when tag is <=0
|
---|
116 | if (vf[j]<=0 || vf[j]>SHRT_MAX)
|
---|
117 | continue;
|
---|
118 | // Extract the field with tag contained into vf[j]
|
---|
119 | bool rc = mfr.GetField(vf[j], stemp);
|
---|
120 | if (rc)
|
---|
121 | {
|
---|
122 | std::cout << "tag=" << vf[j]
|
---|
123 | << " data=" << stemp << std::endl;
|
---|
124 | }
|
---|
125 | }
|
---|
126 |
|
---|
127 | }
|
---|
128 | else
|
---|
129 | continue;
|
---|
130 | // PausePrg();
|
---|
131 |
|
---|
132 | }
|
---|
133 | return 0;
|
---|
134 | }
|
---|
135 |
|
---|