IDZEBRA  2.1.2
d1_utils.c
Go to the documentation of this file.
1 /* This file is part of the Zebra server.
2  Copyright (C) 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 #if HAVE_CONFIG_H
21 #include <config.h>
22 #endif
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 
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 
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)
103  if (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  * c-file-style: "Stroustrup"
122  * indent-tabs-mode: nil
123  * End:
124  * vim: shiftwidth=4 tabstop=8 expandtab
125  */
126 
#define DATA1N_tag
Definition: data1.h:276
char * name
Definition: data1.h:260
void data1_remove_idzebra_subtree(data1_handle dh, data1_node *n)
Definition: d1_utils.c:65
struct data1_xattr * next
Definition: data1.h:262
struct data1_node * last_child
Definition: data1.h:342
char * value
Definition: data1.h:261
void data1_remove_node(data1_handle dh, data1_node *n)
Definition: d1_utils.c:31
char * tag
Definition: data1.h:296
union data1_node::@2 u
struct data1_node::@2::@3 root
struct data1_node * child
Definition: data1.h:341
int which
Definition: data1.h:285
struct data1_node * parent
Definition: data1.h:343
struct data1_node * next
Definition: data1.h:340