source: trunk/gsdl/packages/d2m/MARCtidy.c@ 10385

Last change on this file since 10385 was 10385, checked in by kjdon, 19 years ago

a few changes to get it compiling on windows

  • Property svn:keywords set to Author Date Id Revision
File size: 3.9 KB
Line 
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
31void 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
42void 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 *) &pre;
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
68/* Add 245 subfields after $a */
69
70 if ( (strncmp(p, "245", 3) == 0) && (strncmp(p + 5, "$a", 2) == 0) )
71 {
72 if ( ( format == NORMARC ) && ( *mrec->subtitle) )
73 {
74 strcpy(p, " $b");
75 strcpy(l, mrec->subtitle);
76 nline(p, l, buf);
77 }
78 if ( *mrec->partitle )
79 {
80 if ( format == FINMARC || format == DANMARC )
81 {
82 strcpy(p, " ");
83 strcpy(l, mrec->partitle);
84 nline(p, l, buf);
85 }
86 if ( format == ISMARC )
87 {
88 strcpy(l, mrec->partitle);
89 nline(p, l, buf);
90 }
91 }
92 }
93
94/* Add year as 260 $c after $b */
95
96 if ( (strncmp(p, "260", 3) == 0) && (strncmp(p + 5, "$b", 2) == 0) )
97 {
98 if (*mrec->year)
99 {
100 strcpy(p, " $c");
101 strcpy(l, mrec->year);
102 nline(p, l, buf);
103 *mrec->year = 0;
104 }
105 }
106 }
107 u = strtok(NULL, "\n");
108 }
109
110/* Add year as 260 $c if not aleady done */
111
112 if (*mrec->year)
113 {
114 strcpy(p, "260 $c");
115 strcpy(l, mrec->year);
116 nline(p, l, buf);
117 }
118
119/* Add parallel title in spearate field */
120
121 if ( *mrec->partitle && ( format == ISMARC ) )
122 {
123 strcpy(p, "24630$c");
124 strcpy(l, mrec->partitle);
125 nline(p, l, buf);
126 }
127
128
129/* Add URL as 856 $u */
130
131 if (*mrec->url)
132 {
133 strcpy(p, "856 $u");
134 strcpy(l, mrec->url);
135 nline(p, l, buf);
136
137/* Add format as $q */
138
139 if (*mrec->fmat)
140 {
141 strcpy(p, " $q");
142 strcpy(l, mrec->fmat);
143 nline(p, l, buf);
144 }
145 }
146
147}
Note: See TracBrowser for help on using the repository browser.