Ruby  1.9.3p551(2014-11-13revision48407)
handler.c
Go to the documentation of this file.
1 /*
2  * handler.c
3  *
4  * $Author: nobu $
5  *
6  * Copyright (C) 2003 why the lucky stiff
7  */
8 
9 #include "ruby/ruby.h"
10 #include "syck.h"
11 
12 SYMID
14 {
15  SYMID id;
16 
17  if ( ! n->id )
18  {
19  n->id = (p->handler)( p, n );
20  }
21  id = n->id;
22 
23  if ( n->anchor == NULL )
24  {
25  syck_free_node( n );
26  }
27  return id;
28 }
29 
30 SyckNode *
32 {
33  SyckNode *ntmp = NULL;
34 
35  n->anchor = a;
36  if ( p->bad_anchors != NULL )
37  {
38  SyckNode *bad;
39  if ( st_lookup( p->bad_anchors, (st_data_t)a, (void *)&bad ) )
40  {
41  if ( n->kind != syck_str_kind )
42  {
43  n->id = bad->id;
44  (p->handler)( p, n );
45  }
46  }
47  }
48  if ( p->anchors == NULL )
49  {
51  }
52  if ( st_lookup( p->anchors, (st_data_t)a, (void *)&ntmp ) )
53  {
54  if ( ntmp != (void *)1 )
55  {
56  syck_free_node( ntmp );
57  }
58  }
59  st_insert( p->anchors, (st_data_t)a, (st_data_t)n );
60  return n;
61 }
62 
63 void
65 {
66  char *atmp = a;
67  SyckNode *ntmp;
68  if ( p->anchors == NULL )
69  {
71  }
72  if ( st_delete( p->anchors, (void *)&atmp, (void *)&ntmp ) )
73  {
74  if ( ntmp != (void *)1 )
75  {
76  syck_free_node( ntmp );
77  }
78  }
79  st_insert( p->anchors, (st_data_t)a, (st_data_t)1 );
80 }
81 
82 SyckNode *
84 {
85  SyckNode *n = NULL;
86 
87  if ( p->anchors != NULL )
88  {
89  if ( st_lookup( p->anchors, (st_data_t)a, (void *)&n ) )
90  {
91  if ( n != (void *)1 )
92  {
93  S_FREE( a );
94  return n;
95  }
96  else
97  {
98  if ( p->bad_anchors == NULL )
99  {
101  }
102  if ( ! st_lookup( p->bad_anchors, (st_data_t)a, (void *)&n ) )
103  {
104  n = (p->bad_anchor_handler)( p, a );
106  }
107  }
108  }
109  }
110 
111  if ( n == NULL )
112  {
113  n = (p->bad_anchor_handler)( p, a );
114  }
115 
116  if ( n->anchor )
117  {
118  S_FREE( a );
119  }
120  else
121  {
122  n->anchor = a;
123  }
124 
125  return n;
126 }
127 
128 void
129 syck_add_transfer( char *uri, SyckNode *n, int taguri )
130 {
131  if ( n->type_id != NULL )
132  {
133  S_FREE( n->type_id );
134  }
135 
136  if ( taguri == 0 )
137  {
138  n->type_id = uri;
139  return;
140  }
141 
142  n->type_id = syck_type_id_to_uri( uri );
143  S_FREE( uri );
144 }
145 
146 char *
147 syck_xprivate( const char *type_id, int type_len )
148 {
149  char *uri = S_ALLOC_N( char, type_len + 14 );
150  uri[0] = '\0';
151  strcat( uri, "x-private:" );
152  strncat( uri, type_id, type_len );
153  return uri;
154 }
155 
156 char *
157 syck_taguri( const char *domain, const char *type_id, int type_len )
158 {
159  char *uri = S_ALLOC_N( char, strlen( domain ) + type_len + 14 );
160  uri[0] = '\0';
161  strcat( uri, "tag:" );
162  strcat( uri, domain );
163  strcat( uri, ":" );
164  strncat( uri, type_id, type_len );
165  return uri;
166 }
167 
168 int
170 {
171  return 1;
172 }
173 
ssize_t n
Definition: bigdecimal.c:5519
size_t strlen(const char *)
#define S_ALLOC_N(type, n)
Definition: syck.h:47
char * anchor
Definition: syck.h:117
SYMID SyckParser * p
Definition: yaml2byte.c:119
char * syck_type_id_to_uri(const char *type_id)
Definition: implicit.c:1612
st_table * bad_anchors
Definition: syck.h:251
char * syck_xprivate(const char *type_id, int type_len)
Definition: handler.c:147
#define st_delete
Definition: regint.h:146
#define st_lookup
Definition: regint.h:149
#define st_init_strtable
Definition: regint.h:144
SyckNodeHandler handler
Definition: syck.h:225
#define S_FREE(n)
Definition: syck.h:50
void syck_add_transfer(char *uri, SyckNode *n, int taguri)
Definition: handler.c:129
n NULL
Definition: yaml2byte.c:134
SyckBadAnchorHandler bad_anchor_handler
Definition: syck.h:229
void syck_hdlr_remove_anchor(SyckParser *p, char *a)
Definition: handler.c:64
const int id
Definition: nkf.c:209
void syck_free_node(SyckNode *n)
Definition: node.c:31
#define bad(x)
Definition: _sdbm.c:129
long st_data_t
Definition: syck.h:69
char * syck_taguri(const char *domain, const char *type_id, int type_len)
Definition: handler.c:157
SyckNode * syck_hdlr_get_anchor(SyckParser *p, char *a)
Definition: handler.c:83
enum syck_kind_tag kind
Definition: syck.h:113
#define st_insert
Definition: regint.h:148
SYMID id
Definition: syck.h:111
int syck_try_implicit(SyckNode *n)
Definition: handler.c:169
SyckNode * syck_hdlr_add_anchor(SyckParser *p, char *a, SyckNode *n)
Definition: handler.c:31
char * type_id
Definition: syck.h:115
st_table * anchors
Definition: syck.h:251
Real * a
Definition: bigdecimal.c:1140
#define SYMID
Definition: syck.h:72
SYMID syck_hdlr_add_node(SyckParser *p, SyckNode *n)
Definition: handler.c:13