30 #include <yaz/snprintf.h>
31 #include <yaz/oid_db.h>
32 #include <yaz/marcdisp.h>
33 #include <yaz/readconf.h>
34 #include <yaz/xmalloc.h>
35 #include <yaz/tpath.h>
43 char line[512], *argv[50];
66 while ((argc = readconf_line(f, &lineno, line, 512, argv, 50)))
67 if (!strcmp(*argv,
"name"))
71 yaz_log(YLOG_WARN,
"%s:%d:Missing arg for %s", file, lineno,
75 res->
name = nmem_strdup(mem, argv[1]);
77 else if (!strcmp(*argv,
"reference"))
81 yaz_log(YLOG_WARN,
"%s:%d: Missing arg for %s", file, lineno,
85 res->
oid = yaz_string_to_oid_nmem(yaz_oid_std(),
86 CLASS_TAGSET, argv[1],
90 yaz_log(YLOG_WARN,
"%s:%d: Unknown tagset reference '%s'",
91 file, lineno, argv[1]);
95 else if (!strcmp(*argv,
"length-data-entry"))
99 yaz_log(YLOG_WARN,
"%s:%d: Missing arg for %s", file, lineno,
105 else if (!strcmp(*argv,
"length-starting"))
109 yaz_log(YLOG_WARN,
"%s:%d: Missing arg for %s", file, lineno,
115 else if (!strcmp(*argv,
"length-implementation"))
119 yaz_log(YLOG_WARN,
"%s:%d: Missing arg for %s", file, lineno,
125 else if (!strcmp(*argv,
"future-use"))
129 yaz_log(YLOG_WARN,
"%s:%d: Missing arg for %s", file, lineno,
135 else if (!strcmp(*argv,
"force-indicator-length"))
139 yaz_log(YLOG_WARN,
"%s:%d: Missing arg for %s", file, lineno,
145 else if (!strcmp(*argv,
"force-identifier-length"))
149 yaz_log(YLOG_WARN,
"%s:%d: Missing arg for %s", file, lineno,
155 else if (!strcmp(*argv,
"implementation-codes"))
159 yaz_log(YLOG_WARN,
"%s:%d: Missing arg for %s", file, lineno,
164 if (strlen(argv[1]) > 4)
165 yaz_log(YLOG_WARN,
"%s:%d: Max 4 characters for "
166 "implementation-codes", file, lineno);
171 yaz_log(YLOG_WARN,
"%s:%d: Unknown directive '%s'", file, lineno,
186 if (dst && *len < max)
188 size_t copy_len = max - *len;
189 if (copy_len > n->
u.
data.len)
190 copy_len = n->
u.
data.len;
191 memcpy(dst + *len, n->
u.
data.data, copy_len);
193 *len += n->
u.
data.len;
204 static void memint(
char *p,
int val,
int len)
212 yaz_snprintf(buf,
sizeof(buf),
"%08d", val);
213 memcpy(p, buf+8-len, len);
228 char **buf,
int *size)
234 int base_address = 25;
242 yaz_log(YLOG_DEBUG,
"nodetomarc");
254 for (field = n->
child; field; field = field->
next)
256 int control_field = 0;
261 if (selected && !field->
u.
tag.node_selected)
268 if (!yaz_matchstr(field->
u.
tag.tag,
"mc?"))
270 else if (!strcmp(field->
u.
tag.tag,
"leader"))
276 else if (!strcmp(field->
u.
tag.tag,
"controlfield"))
281 else if (!strcmp(field->
u.
tag.tag,
"datafield"))
310 for (; subf; subf = subf->
next)
324 *buf = (
char *)xmalloc(*size = len);
325 else if (*size <= len)
326 *buf = (
char *)xrealloc(*buf, *size = len);
331 memint(leader+12, base_address, 5);
334 memcpy(op, leader, 24);
338 data_p = base_address;
340 for (field = n->
child; field; field = field->
next)
342 int control_field = 0;
347 char indicator_data[6];
349 memset(indicator_data,
' ',
sizeof(indicator_data) - 1);
350 indicator_data[
sizeof(indicator_data)-1] =
'\0';
355 if (selected && !field->
u.
tag.node_selected)
362 if (!yaz_matchstr(field->
u.
tag.tag,
"mc?"))
364 else if (!strcmp(field->
u.
tag.tag,
"leader"))
366 else if (!strcmp(field->
u.
tag.tag,
"controlfield"))
371 else if (!strcmp(field->
u.
tag.tag,
"datafield"))
388 if (strlen(subf->
u.
tag.tag) <
sizeof(indicator_data))
389 strcpy(indicator_data, subf->
u.
tag.tag);
392 else if (marc_xml == 1 && !control_field)
395 for (xa = field->
u.
tag.attributes; xa; xa = xa->
next)
397 if (!strcmp(xa->
name,
"ind1"))
398 indicator_data[0] = xa->
value[0];
399 if (!strcmp(xa->
name,
"ind2"))
400 indicator_data[1] = xa->
value[0];
401 if (!strcmp(xa->
name,
"ind3"))
402 indicator_data[2] = xa->
value[0];
410 for (; subf; subf = subf->
next)
414 const char *identifier =
"a";
420 if (strcmp(subf->
u.
tag.tag,
"subfield"))
421 yaz_log(YLOG_WARN,
"Unhandled tag %s",
424 for (xa = subf->
u.
tag.attributes; xa; xa = xa->
next)
425 if (!strcmp(xa->
name,
"code"))
426 identifier = xa->
value;
429 yaz_log(YLOG_WARN,
"Malformed fields for marc output.");
431 identifier = subf->
u.
tag.tag;
432 op[data_p] = ISO2709_IDFS;
436 get_data2(subf, &dlen, op + data_p, 100000);
439 op[data_p++] = ISO2709_FS;
444 for (xa = field->
u.
tag.attributes; xa; xa = xa->
next)
445 if (!strcmp(xa->
name,
"tag"))
449 tag = field->
u.
tag.tag;
451 if (!tag || strlen(tag) != 3)
453 memcpy(op + entry_p, tag, 3);
462 op[entry_p++] = ISO2709_FS;
463 assert (entry_p == base_address);
464 op[data_p++] = ISO2709_RS;
465 assert (data_p == len);
470 int selected,
int *len)
478 *len =
nodetomarc(dh, p, n, selected, buf, size);
data1_marctab * data1_read_marctab(data1_handle dh, const char *file)
static void memint(char *p, int val, int len)
char * data1_nodetomarc(data1_handle dh, data1_marctab *p, data1_node *n, int selected, int *len)
static void get_data2(data1_node *n, int *len, char *dst, size_t max)
static int is_indicator(data1_marctab *p, data1_node *subf)
static int nodetomarc(data1_handle dh, data1_marctab *p, data1_node *n, int selected, char **buf, int *size)
char ** data1_get_map_buf(data1_handle dp, int **lenp)
FILE * data1_path_fopen(data1_handle dh, const char *file, const char *mode)
NMEM data1_nmem_get(data1_handle dh)
data1_node * data1_get_root_tag(data1_handle dh, data1_node *n)
void data1_pr_tree(data1_handle dh, data1_node *n, FILE *out)
int length_implementation
int force_indicator_length
char implementation_codes[5]
int force_identifier_length
struct data1_marctab * next
struct data1_node * child
struct data1_xattr * next