1 | /* ------------------------------------------------------------------- */
|
---|
2 | /* MARCtidy : Tidying up of MARC record, building the line format */
|
---|
3 | /* record. */
|
---|
4 | /* */
|
---|
5 | /* Syntax : MARCtidy(marcrec *mrec, char *buf, int format) */
|
---|
6 | /* */
|
---|
7 | /* The preliminary MARC data are converted from the */
|
---|
8 | /* mrec struct to the buf line format buffer. */
|
---|
9 | /* */
|
---|
10 | /* The main data is in mrec->marcline, while some */
|
---|
11 | /* additional data (year, URL ...) are kept in separat */
|
---|
12 | /* variables to be added in. */
|
---|
13 | /* */
|
---|
14 | /* NOTE : The behaviour of this program i sto some extent */
|
---|
15 | /* depending on the format argument! */
|
---|
16 | /* */
|
---|
17 | /* Author : Ole Husby, BIBSYS */
|
---|
18 | /* Updated : 1998-09-30 */
|
---|
19 | /* ------------------------------------------------------------------- */
|
---|
20 |
|
---|
21 | #include <stdlib.h>
|
---|
22 | #include <string.h>
|
---|
23 | #include <ctype.h>
|
---|
24 | #ifdef HAVE_UNISTD_H
|
---|
25 | #include <unistd.h>
|
---|
26 | #endif
|
---|
27 | #include "d2m.h"
|
---|
28 |
|
---|
29 |
|
---|
30 |
|
---|
31 | void nline(char *p, char *l, char *buf)
|
---|
32 | {
|
---|
33 | strcat(buf, p);
|
---|
34 | if (strncmp(p, "00", 2) != 0)
|
---|
35 | strcat(buf, " ");
|
---|
36 | strcat(buf, l);
|
---|
37 | strcat(buf, "\n");
|
---|
38 | }
|
---|
39 |
|
---|
40 |
|
---|
41 |
|
---|
42 | void MARCtidy(struct marcrec *mrec, char *buf, int format)
|
---|
43 | {
|
---|
44 |
|
---|
45 | char *p, *u, *l;
|
---|
46 | char pre[64], line[10000];
|
---|
47 |
|
---|
48 | p = (char *) ⪯
|
---|
49 | l = (char *) &line;
|
---|
50 |
|
---|
51 | *buf = 0;
|
---|
52 |
|
---|
53 | strcpy(p, "008");
|
---|
54 | strcpy(l, mrec->s008);
|
---|
55 | nline(p, l, buf);
|
---|
56 |
|
---|
57 | u = strtok(mrec->marcline, "\n");
|
---|
58 | while (u && *u)
|
---|
59 | {
|
---|
60 | if (strlen(u) > 7)
|
---|
61 | {
|
---|
62 | *p = 0;
|
---|
63 | strncat(p, u, 7);
|
---|
64 | strcpy(l, u + 8);
|
---|
65 | nline(p, l, buf);
|
---|
66 |
|
---|
67 | /* Add 200 subfields after $a - unimarc */
|
---|
68 | if ( (strncmp(p, "200", 3) == 0) && (strncmp(p + 5, "$a", 2) == 0) )
|
---|
69 | {
|
---|
70 | if ( ( format == UNIMARC ) && ( *mrec->subtitle) )
|
---|
71 | {
|
---|
72 | strcpy(p, " $e");
|
---|
73 | strcpy(l, mrec->subtitle);
|
---|
74 | nline(p, l, buf);
|
---|
75 | }
|
---|
76 | }
|
---|
77 |
|
---|
78 | /* Add 245 subfields after $a */
|
---|
79 |
|
---|
80 | if ( (strncmp(p, "245", 3) == 0) && (strncmp(p + 5, "$a", 2) == 0) )
|
---|
81 | {
|
---|
82 | if ( ( format == NORMARC ) && ( *mrec->subtitle) )
|
---|
83 | {
|
---|
84 | strcpy(p, " $b");
|
---|
85 | strcpy(l, mrec->subtitle);
|
---|
86 | nline(p, l, buf);
|
---|
87 | }
|
---|
88 | if ( *mrec->partitle )
|
---|
89 | {
|
---|
90 | if ( format == FINMARC || format == DANMARC )
|
---|
91 | {
|
---|
92 | strcpy(p, " ");
|
---|
93 | strcpy(l, mrec->partitle);
|
---|
94 | nline(p, l, buf);
|
---|
95 | }
|
---|
96 | if ( format == ISMARC )
|
---|
97 | {
|
---|
98 | strcpy(l, mrec->partitle);
|
---|
99 | nline(p, l, buf);
|
---|
100 | }
|
---|
101 | }
|
---|
102 | }
|
---|
103 |
|
---|
104 | /* Add year as 260 $c after $b */
|
---|
105 |
|
---|
106 | if ( (strncmp(p, "260", 3) == 0) && (strncmp(p + 5, "$b", 2) == 0) )
|
---|
107 | {
|
---|
108 | if (*mrec->year)
|
---|
109 | {
|
---|
110 | strcpy(p, " $c");
|
---|
111 | strcpy(l, mrec->year);
|
---|
112 | nline(p, l, buf);
|
---|
113 | *mrec->year = 0;
|
---|
114 | }
|
---|
115 | }
|
---|
116 | }
|
---|
117 | u = strtok(NULL, "\n");
|
---|
118 | }
|
---|
119 |
|
---|
120 | /* Add year as 260 $c if not aleady done */
|
---|
121 |
|
---|
122 | if (*mrec->year)
|
---|
123 | {
|
---|
124 | strcpy(p, "260 $c");
|
---|
125 | strcpy(l, mrec->year);
|
---|
126 | nline(p, l, buf);
|
---|
127 | }
|
---|
128 |
|
---|
129 | /* Add parallel title in spearate field */
|
---|
130 |
|
---|
131 | if ( *mrec->partitle && ( format == ISMARC ) )
|
---|
132 | {
|
---|
133 | strcpy(p, "24630$c");
|
---|
134 | strcpy(l, mrec->partitle);
|
---|
135 | nline(p, l, buf);
|
---|
136 | }
|
---|
137 |
|
---|
138 |
|
---|
139 | /* Add URL as 856 $u (or 300 $a for unimarc) */
|
---|
140 |
|
---|
141 | if (*mrec->url)
|
---|
142 | {
|
---|
143 | if (format == UNIMARC) {
|
---|
144 | strcpy(p, "300 $a");
|
---|
145 | strcpy(l, mrec->url);
|
---|
146 | nline(p, l, buf);
|
---|
147 |
|
---|
148 |
|
---|
149 | } else {
|
---|
150 | strcpy(p, "856 $u");
|
---|
151 | strcpy(l, mrec->url);
|
---|
152 | nline(p, l, buf);
|
---|
153 | }
|
---|
154 | }
|
---|
155 | /* Add format as $q (or 336 $a for unimarc) */
|
---|
156 |
|
---|
157 | if (*mrec->fmat)
|
---|
158 | {
|
---|
159 |
|
---|
160 | if (format == UNIMARC) {
|
---|
161 | strcpy(p, "336 $a");
|
---|
162 | strcpy(l, mrec->fmat);
|
---|
163 | nline(p, l, buf);
|
---|
164 | }
|
---|
165 | else {
|
---|
166 | strcpy(p, " $q");
|
---|
167 | strcpy(l, mrec->fmat);
|
---|
168 | nline(p, l, buf);
|
---|
169 | }
|
---|
170 | }
|
---|
171 |
|
---|
172 |
|
---|
173 | }
|
---|