source: main/trunk/greenstone2/build-src/packages/isis-gdl/Unimarc.h@ 26670

Last change on this file since 26670 was 6127, checked in by mdewsnip, 20 years ago

IsisGdl package for reading CDS/ISIS databases. Provided by Jean-Claude Dauphin at UNESCO, and modified slightly to compile and run under Linux.

  • Property svn:keywords set to Author Date Id Revision
File size: 5.3 KB
Line 
1/**********************************************************************
2 *
3 * Unimarc.h
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
27#ifndef MARC_RECORD
28#define MARC_RECORD
29
30#define SUBFDELIM '\037' // %
31#define FIELDTERM '\036' // $
32#define RECTERM '\035' // # sharp
33
34#define MARC_LEADER_LEN 24
35#define MARC_DIRENT_LEN 12
36
37#define MARC_FMT_BRIEF 0
38#define MARC_FMT_FULL 1
39
40//---------------------
41// UNIMARC Record Label
42//---------------------
43struct MarcLeader
44{
45 char lreclen_[5]; /* logical record length */
46 char status_; /* record status_ */
47 char type_; /* type_ of record */
48 char bibLevel_; /* bibliographic level */
49 char ctrlType_; /* type_ of control */
50 char undPos_; /* undefined character position */
51 char indCount_; /* indicator count */
52 char scd_; /* subfield code count */
53 char base_[5]; /* base_ address of data */
54 char encLevel_; /* encoding level */
55 char dcf_; /* descriptive cataloging form */
56 char lrr_; /* linked record requirement */
57 char llof_; /* length of the length-of-field portion */
58 char lscp_; /* length of starting-character-position portion */
59 char lidp_; /* length of implementation-defined portion */
60 char uep_; /* undefined entry map character position */
61
62 MarcLeader()
63 {
64 lreclen_[0]=' ';
65 lreclen_[1]=' ';
66 lreclen_[2]=' ';
67 lreclen_[3]=' ';
68 lreclen_[4]=' ';
69 status_ = '0'; // New record
70 type_ = '0'; // Language materials, printed
71 bibLevel_ = '0'; // Monographic
72 ctrlType_ = '0'; // Hierarchical relationship undefined
73 undPos_ = '0'; // Undefined, contains a blank
74 indCount_ = '0'; // Invariably 2 in UNIMARC
75 scd_ = '0'; // Invariably 2 in UNIMARC
76 base_[0] = ' '; // Base_ address of data
77 base_[1] = ' ';
78 base_[2] = ' ';
79 base_[3] = ' ';
80 base_[4] = ' ';
81 encLevel_ = '0'; // (Blank) full level
82 dcf_ = '0'; // (Blank) record is in full ISBD form
83 lrr_ = '0'; // Undefined, contains a blank
84 llof_ = '4'; // Length of the length-of-field portion
85 lscp_ = '5'; // Length of starting-character-position portion
86 lidp_ = '0'; // Length of implementation-defined portion
87 uep_ = '0'; // Undefined, contains a blank
88 }
89
90 friend std::ostream& operator<<(std::ostream& s, const MarcLeader& leader);
91 friend std::istream& operator>>(std::istream& s, MarcLeader& leader);
92};
93
94//----------------
95// Directory entry
96//----------------
97struct DirectoryEntry
98{
99 char tag_[3]; /* tag */
100 char len_[4]; /* field length */
101 char scp_[5]; /* starting character position */
102 friend std::ostream& operator<<(std::ostream& s, const DirectoryEntry& de);
103 friend std::istream& operator>>(std::istream& s, DirectoryEntry& leader);
104};
105inline std::istream& operator>>(std::istream& s, DirectoryEntry& de)
106{
107 s.read(de.tag_, 3);
108 s.read(de.len_, 4);
109 s.read(de.scp_, 5);
110 return s;
111}
112inline std::ostream& operator<<(std::ostream& s, const DirectoryEntry& de)
113{
114 s.write(de.tag_, 3);
115 s.write(de.len_, 4);
116 s.write(de.scp_, 5);
117 return s;
118}
119
120
121
122//------------------
123// Subfield item
124//------------------
125struct MarcField
126{
127 int len_;
128 char* data_;
129};
130
131//-------------------
132// Directory entry
133//-------------------
134struct MarcDirectoryEntry
135{
136 char* tag_;
137 std::vector<MarcField> field_;
138};
139
140
141//---------------------------
142// UNIMARC record structure
143//---------------------------
144
145class MarcRecord
146{
147protected:
148 MarcLeader leader_;
149 char* data_;
150 int length_;
151 int dirCount_;
152 int encapsulated_;
153 std::vector<MarcDirectoryEntry> directory_;
154
155 int ParseMarcRecord();
156 int AddSubFields(MarcDirectoryEntry& d, char* b);
157public:
158 MarcRecord(char* data, int length, int copyData);
159 ~MarcRecord();
160 void PrintDetailed(FILE* fp);
161 void Get(char* buf,int maxlen,int format);
162 int GetSubField(char* tag, char subtag, char* buf, int maxlen);
163 int GetField(char* tag, char* buf, int maxlen);
164 int GetSubFields(char* tag, char subtag, char* buf, int maxlen);
165
166 int HasField(char* tag);
167 int HasSubField(char* tag, char subtag);
168
169 void Format(char* buf, int maxlen, int format);
170 int RecordLength();
171 int PrettyFormat(char* format, char* buf, int maxlen);
172
173 void Dump ();
174};
175#endif
Note: See TracBrowser for help on using the repository browser.