Omit CVS Id. Update copyright year.
[idzebra-moved-to-github.git] / data1 / d1_utils.c
1 /* This file is part of the Zebra server.
2    Copyright (C) 1995-2008 Index Data
3
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
7 version.
8
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
18 */
19
20 #include <stdio.h>
21 #include <assert.h>
22 #include <stdlib.h>
23
24 #include <yaz/log.h>
25 #include <idzebra/data1.h>
26
27
28 void data1_remove_node (data1_handle dh, data1_node *n)
29 {
30     fprintf (stdout, "REMOVE tag %s \n", n->u.tag.tag);
31     /* n is first childen */
32     if(n->parent->child == n){
33         n->parent->child = n->next;
34
35         /* n is the only child */
36         if(! n->next){
37             n->parent->last_child = 0;                
38         }
39     } 
40     /* n is one of the following childrens */
41     else {
42         data1_node * before;
43         
44         /* need to find sibling before me */
45         before = n->parent->child;
46         while (before->next != n)
47             before = before->next;
48         
49         before->next = n->next;
50         
51         /* n is last child of many */
52         if ( n->parent->last_child == n){
53             n->parent->last_child = before;
54         }
55     }
56     /* break pointers to root, parent and following siblings */
57     n->parent = 0;
58     n->root = 0;
59     n->next = 0;
60 }
61
62 void data1_remove_idzebra_subtree (data1_handle dh, data1_node *n)
63 {
64     switch (n->which)
65         {
66             /*
67         case DATA1N_root:
68             break;
69             */
70         case DATA1N_tag:
71             if (!strcmp(n->u.tag.tag, "idzebra")){
72                 if (n->u.tag.attributes){
73                     data1_xattr *xattr = n->u.tag.attributes;
74                     
75                     for (; xattr; xattr = xattr->next){
76                         if (!strcmp(xattr->name, "xmlns") 
77                             & !strcmp(xattr->value, 
78                                       "http://www.indexdata.dk/zebra/"))
79                             data1_remove_node (dh, n);
80                     }
81                 }
82             }
83                 
84             break;
85             /*
86         case DATA1N_data:
87             break;
88         case DATA1N_comment:
89             break;
90         case DATA1N_preprocess:
91             break;
92         case DATA1N_variant:
93         break;
94             */
95         default:
96             break;
97         }
98     if (n->child)
99         data1_remove_idzebra_subtree (dh, n->child);
100     if (n->next)
101         data1_remove_idzebra_subtree (dh, n->next);
102     /*
103     else
104         {
105             if (n->parent && n->parent->last_child != n)
106                 fprintf(out, "%*sWARNING: last_child=%p != %p\n", level, "",
107                         n->parent->last_child, n);
108         }
109     */
110     
111 }
112
113
114
115 /*
116  * Local variables:
117  * c-basic-offset: 4
118  * indent-tabs-mode: nil
119  * End:
120  * vim: shiftwidth=4 tabstop=8 expandtab
121  */
122