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