source: main/trunk/greenstone2/runtime-src/packages/d2m/danMARC.c@ 22394

Last change on this file since 22394 was 22394, checked in by kjdon, 14 years ago

these needed stdlib.h for malloc

  • Property svn:keywords set to Author Date Id Revision
File size: 5.8 KB
Line 
1/* ------------------------------------------------------------------- */
2/* danMARC : Convert a metatag struct to DANMARC2 */
3/* */
4/* Specs : http://www.bibsys.no/meta/d2m/dancross.html */
5/* */
6/* Author : Ole Husby */
7/* Last update: 1998-09-30 */
8/* ------------------------------------------------------------------- */
9
10#include <stdlib.h>
11#include <stdio.h>
12#include <string.h>
13#include "d2m.h"
14
15
16
17/* Splits subject heading on ":". First occurence go into $a, second into $v */
18
19int split_dk5(char *str)
20{
21 char *p, *q, subtag[5];
22
23 if (!strstr(str, ":"))
24 return 1;
25
26 p = (char *) malloc(strlen(str) + 50);
27 *p = 0;
28 *subtag = 0;
29
30 q = strtok(str, ":");
31 if (q)
32 {
33 while ( ( q[0] == ' ' ) && ( strlen(q) ) )
34 q++;
35
36 while( ( q[strlen(q) - 1] == ' ' ) && ( strlen(q) ) )
37 q[strlen(q) - 1] = '\0';
38
39 if (*q)
40 {
41 strcat(p, subtag);
42 strcat(p, q);
43 strcpy(subtag, " $v ");
44 }
45 }
46
47 strcpy(str, p);
48 free(p);
49
50 return 1;
51}
52
53
54
55
56int danMARC(struct metatag *mt, struct marcrec *mr)
57{
58 char pre[64], type_tag[4];
59 int i;
60
61 *pre = 0;
62
63 if (strcasecmp(mt->name, "title") == 0)
64 {
65 if ( (!*mt->type)
66 | (strcasecmp(mt->type, "main") == 0)
67 | (strcasecmp(mt->type, "long") == 0) )
68 {
69 if (mr->ntitles)
70 {
71 strcat(mr->partitle, "$a ");
72 strcat(mr->partitle, mt->value);
73
74 }
75 else
76 {
77 mr->ntitles++;
78 strcpy(pre, "245 $a");
79 }
80 }
81 }
82
83 else if (strcasecmp(mt->name, "creator") == 0)
84 {
85 if ( strcasecmp(mt->type, "personal") == 0)
86 {
87 strcpy(pre, "700 $a");
88 split_name(mt->value);
89 }
90 else if (strcasecmp(mt->type, "corporate") == 0)
91 strcpy(pre, "710 $a");
92 }
93
94
95 else if (strcasecmp(mt->name, "publisher") == 0)
96 strcpy(pre, "260 $b");
97
98 else if (strcasecmp(mt->name, "description") == 0)
99 strcpy(pre, "504 $a");
100
101 else if (strncasecmp(mt->name, "contributor", 11) == 0)
102 {
103 if ( strcasecmp(mt->type, "personal") == 0 )
104 {
105 strcpy(pre, "700 $a");
106 split_name(mt->value);
107 }
108 else if (strcasecmp(mt->type, "corporate") == 0)
109 strcpy(pre, "710 $a");
110 }
111
112 else if (strcasecmp(mt->name, "coverage") == 0)
113 {
114 if (!*mt->type)
115 strcpy(pre, "559 $a");
116 else if (strcasecmp(mt->type , "spatial") == 0)
117 {
118 strcpy(pre, "633 $a");
119 split_subj(mt->value);
120 }
121 else if (strcasecmp(mt->type, "temporal") == 0)
122 {
123 strcpy(pre, "334 $b");
124 for (i = 0; i < strlen(mt->value); i++)
125 {
126 if (!isdigit(mt->value[i]))
127 {
128 strcpy(pre, "334 $a");
129 }
130 }
131 }
132 }
133
134 else if (strcasecmp(mt->name, "source") == 0)
135 strcpy(pre, "523 $a");
136
137 else if (strcasecmp(mt->name, "rights") == 0)
138 {
139 if (strcasecmp(mt->scheme, "url") == 0)
140 strcpy(pre, "856 $3 rights $u");
141 else
142 strcpy(pre, "518 $a");
143 }
144
145 else if (strcasecmp(mt->name, "identifier") == 0)
146 {
147 if (!*mt->scheme)
148 strcpy(mr->url, mt->value);
149 else if (strcasecmp(mt->scheme, "url") == 0)
150 strcpy(mr->url, mt->value);
151 else if (strcasecmp(mt->scheme, "urn") == 0)
152 strcpy(pre, "856 $g urn:");
153 else if (strcasecmp(mt->scheme, "isbn") == 0)
154 strcpy(pre, "021 $a");
155 else if (strcasecmp(mt->scheme, "issn") == 0)
156 strcpy(pre, "022 $a");
157 else if (strcasecmp(mt->scheme, "isrc") == 0)
158 strcpy(pre, "024 $a");
159 else if (strcasecmp(mt->scheme, "ismn") == 0)
160 strcpy(pre, "028 $a");
161 else if (strcasecmp(mt->scheme, "isrn") == 0)
162 strcpy(pre, "027 $a");
163 }
164
165 else if (strcasecmp(mt->name, "type") == 0)
166 strcpy(pre, "505 $a");
167
168 else if (strcasecmp(mt->name, "relation") == 0)
169 strcpy(pre, "559 $a");
170
171 else if (strcasecmp(mt->name, "language") == 0) /* Only if repeated ! */
172 {
173 if (strcasecmp(mt->scheme, "z39.53") == 0)
174 {
175 strcpy(pre, "041 $a");
176 put008(mr->s008, mt->value, F008_LANGUAGE);
177 }
178 }
179
180 else if (strcasecmp(mt->name, "format") == 0)
181 {
182 if ( (!*mt->scheme)
183 || (strcasecmp(mt->scheme, "imt") == 0)
184 || (strcasecmp(mt->scheme, "mime") == 0) )
185 strcpy(mr->fmat, mt->value);
186 }
187
188 else if (strcasecmp(mt->name, "subject") == 0)
189 {
190 if (!*mt->scheme)
191 strcpy(pre, "631 $a");
192 else if (strcasecmp(mt->scheme, "udc") == 0)
193 strcpy(pre, "080 $a");
194 else if (strcasecmp(mt->scheme, "lccs") == 0)
195 strcpy(pre, "050 $a");
196 else if (strcasecmp(mt->scheme, "lcsh") == 0)
197 strcpy(pre, "650 $a");
198 else if (strcasecmp(mt->scheme, "ddc") == 0)
199 strcpy(pre, "082 $a");
200 else if (strcasecmp(mt->scheme, "nlm") == 0)
201 strcpy(pre, "060 $a");
202 else if (strcasecmp(mt->scheme, "agr") == 0)
203 strcpy(pre, "662 $a");
204 else if (strcasecmp(mt->scheme, "eudised") == 0)
205 strcpy(pre, "661 $b");
206 else if (strcasecmp(mt->scheme, "dbc") == 0)
207 strcpy(pre, "666 $f");
208 else if (strcasecmp(mt->scheme, "mesh") == 0)
209 strcpy(pre, "690 $a");
210 else if (strcasecmp(mt->scheme, "dk5") == 0)
211 {
212 strcpy(pre, "652 $m");
213 split_dk5(mt->value);
214 }
215 }
216
217 else if (strcasecmp(mt->name, "date") == 0)
218 {
219 if ( (!*mt->type) || ( strcasecmp(mt->type, "current") == 0) )
220 {
221 if ( (strncasecmp(mt->scheme, "ans", 3) == 0)
222 || (strncasecmp(mt->scheme, "iso", 3) == 0) )
223 {
224 if (find_year(mt->value))
225 {
226 strcpy(mr->year, mt->value);
227 put008(mr->s008, mt->value, F008_DATE1);
228 }
229 }
230 }
231 }
232
233 if (*pre)
234 {
235 strcat(mr->marcline, pre);
236 strcat(mr->marcline, " ");
237 strcat(mr->marcline, mt->value);
238 strcat(mr->marcline, "\n");
239 }
240}
Note: See TracBrowser for help on using the repository browser.