Added --with-yc option to configure. For the data1_node in data1.h:
[yaz-moved-to-github.git] / retrieval / d1_soif.c
1 /*
2  * Copyright (c) 1995, Index Data.
3  * See the file LICENSE for details.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: d1_soif.c,v $
7  * Revision 1.3  1997-09-17 12:10:37  adam
8  * YAZ version 1.4.
9  *
10  * Revision 1.2  1997/04/30 08:52:11  quinn
11  * Null
12  *
13  * Revision 1.1  1996/10/08  10:43:20  quinn
14  * Added SOIF syntax.
15  *
16  *
17  */
18
19 #include <wrbuf.h>
20
21 #include <data1.h>
22
23 /*
24  * This module generates SOIF (Simple Object Interchange Format) records
25  * from d1-nodes. nested elements are flattened out, depth first, by
26  * concatenating the tag names at each level.
27  */
28
29 static int nodetoelement(data1_node *n, int select, char *prefix, WRBUF b)
30 {
31     data1_node *c;
32     char tmp[1024];
33
34     for (c = n->child; c; c = c->next)
35     {
36         char *tag;
37
38         if (c->which == DATA1N_tag)
39         {
40             if (select && !c->u.tag.node_selected)
41                 continue;
42             if (c->u.tag.element && c->u.tag.element->tag)
43                 tag = c->u.tag.element->tag->names->name; /* first name */
44             else
45             tag = c->u.tag.tag; /* local string tag */
46
47             if (*prefix)
48                 sprintf(tmp, "%s-%s", prefix, tag);
49             else
50                 strcpy(tmp, tag);
51
52             if (nodetoelement(c, select, tmp, b) < 0)
53                 return 0;
54         }
55         else if (c->which == DATA1N_data)
56         {
57             char *p = c->u.data.data;
58             int l = c->u.data.len;
59
60             wrbuf_write(b, prefix, strlen(prefix));
61
62             sprintf(tmp, "{%d}:\t", l);
63             wrbuf_write(b, tmp, strlen(tmp));
64             wrbuf_write(b, p, l);
65             wrbuf_putc(b, '\n');
66         }
67     }
68     return 0;
69 }
70
71 char *data1_nodetosoif (data1_handle dh, data1_node *n, int select, int *len)
72 {
73     WRBUF b = data1_get_wrbuf (dh);
74     char buf[128];
75
76     wrbuf_rewind(b);
77     
78     if (n->which != DATA1N_root)
79         return 0;
80     sprintf(buf, "@%s{\n", n->u.root.type);
81     wrbuf_write(b, buf, strlen(buf));
82     if (nodetoelement(n, select, "", b))
83         return 0;
84     wrbuf_write(b, "}\n", 2);
85     *len = wrbuf_len(b);
86     return wrbuf_buf(b);
87 }