1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/ext/syck/handler.c

175 lines
3.3 KiB
C
Raw Normal View History

/*
* handler.c
*
* $Author$
* $Date$
*
* Copyright (C) 2003 why the lucky stiff
*/
#include "ruby.h"
#include "syck.h"
SYMID
syck_hdlr_add_node( SyckParser *p, SyckNode *n )
{
SYMID id;
if ( ! n->id )
{
n->id = (p->handler)( p, n );
}
id = n->id;
if ( n->anchor == NULL )
{
syck_free_node( n );
}
return id;
}
SyckNode *
syck_hdlr_add_anchor( SyckParser *p, char *a, SyckNode *n )
{
* lib/yaml.rb: reworking YAML::Stream to use the new emitter. * lib/yaml/stream.rb: ditto. * lib/yaml/rubytypes.rb: added Object#yaml_new. * lib/yaml/tag.rb: the tag_subclasses? method now shows up in the class. allow taguri to be set using an accessor. continue support of Object#to_yaml_type. * ext/syck/rubyext.c: new emitter code. yaml_new and yaml_initialize get called, should they be present. consolidated all the diaspora of internal node types into the family below YAML::Syck::Node -- Map, Seq, Scalar -- all of whom are SyckNode structs pointing to Ruby data. moved Object#yaml_new into the node_import and made it the default behavior. the target_class is always called wih yaml_new, prepended a parameter, which is the klass. loaded nodes through GenericResolver show their style. new Resolver#tagurize converts type ids to taguris. * ext/syck/implicit.re: were 'y' and 'n' seriously omitted?? * ext/syck/emitter.c: renovated emitter, walks the tree in advance. consolidated redundant block_styles struct into the scalar_style struct. (this means loaded nodes can now be sent back to emitter and preserve at least its very basic formatting.) * ext/syck/gram.c: headless documents of any kind allowed. * ext/syck/node.c: new syck_replace_str methods and syck_empty_* methods for rewriting node contents, while keeping the ID and other setup info. added syck_seq_assign. * ext/syck/syck.h: reflect block_styles and new node functions. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9141 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 23:58:33 -04:00
SyckNode *ntmp = NULL;
n->anchor = a;
if ( p->bad_anchors != NULL )
{
SyckNode *bad;
if ( st_lookup( p->bad_anchors, (st_data_t)a, (st_data_t *)&bad ) )
{
if ( n->kind != syck_str_kind )
{
n->id = bad->id;
(p->handler)( p, n );
}
}
}
if ( p->anchors == NULL )
{
p->anchors = st_init_strtable();
}
* lib/yaml.rb: reworking YAML::Stream to use the new emitter. * lib/yaml/stream.rb: ditto. * lib/yaml/rubytypes.rb: added Object#yaml_new. * lib/yaml/tag.rb: the tag_subclasses? method now shows up in the class. allow taguri to be set using an accessor. continue support of Object#to_yaml_type. * ext/syck/rubyext.c: new emitter code. yaml_new and yaml_initialize get called, should they be present. consolidated all the diaspora of internal node types into the family below YAML::Syck::Node -- Map, Seq, Scalar -- all of whom are SyckNode structs pointing to Ruby data. moved Object#yaml_new into the node_import and made it the default behavior. the target_class is always called wih yaml_new, prepended a parameter, which is the klass. loaded nodes through GenericResolver show their style. new Resolver#tagurize converts type ids to taguris. * ext/syck/implicit.re: were 'y' and 'n' seriously omitted?? * ext/syck/emitter.c: renovated emitter, walks the tree in advance. consolidated redundant block_styles struct into the scalar_style struct. (this means loaded nodes can now be sent back to emitter and preserve at least its very basic formatting.) * ext/syck/gram.c: headless documents of any kind allowed. * ext/syck/node.c: new syck_replace_str methods and syck_empty_* methods for rewriting node contents, while keeping the ID and other setup info. added syck_seq_assign. * ext/syck/syck.h: reflect block_styles and new node functions. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9141 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 23:58:33 -04:00
if ( st_lookup( p->anchors, (st_data_t)a, (st_data_t *)&ntmp ) )
{
if ( ntmp != (void *)1 )
{
syck_free_node( ntmp );
}
}
st_insert( p->anchors, (st_data_t)a, (st_data_t)n );
return n;
}
void
syck_hdlr_remove_anchor( SyckParser *p, char *a )
{
* lib/yaml.rb: reworking YAML::Stream to use the new emitter. * lib/yaml/stream.rb: ditto. * lib/yaml/rubytypes.rb: added Object#yaml_new. * lib/yaml/tag.rb: the tag_subclasses? method now shows up in the class. allow taguri to be set using an accessor. continue support of Object#to_yaml_type. * ext/syck/rubyext.c: new emitter code. yaml_new and yaml_initialize get called, should they be present. consolidated all the diaspora of internal node types into the family below YAML::Syck::Node -- Map, Seq, Scalar -- all of whom are SyckNode structs pointing to Ruby data. moved Object#yaml_new into the node_import and made it the default behavior. the target_class is always called wih yaml_new, prepended a parameter, which is the klass. loaded nodes through GenericResolver show their style. new Resolver#tagurize converts type ids to taguris. * ext/syck/implicit.re: were 'y' and 'n' seriously omitted?? * ext/syck/emitter.c: renovated emitter, walks the tree in advance. consolidated redundant block_styles struct into the scalar_style struct. (this means loaded nodes can now be sent back to emitter and preserve at least its very basic formatting.) * ext/syck/gram.c: headless documents of any kind allowed. * ext/syck/node.c: new syck_replace_str methods and syck_empty_* methods for rewriting node contents, while keeping the ID and other setup info. added syck_seq_assign. * ext/syck/syck.h: reflect block_styles and new node functions. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9141 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 23:58:33 -04:00
char *atmp = a;
SyckNode *ntmp;
if ( p->anchors == NULL )
{
p->anchors = st_init_strtable();
}
* lib/yaml.rb: reworking YAML::Stream to use the new emitter. * lib/yaml/stream.rb: ditto. * lib/yaml/rubytypes.rb: added Object#yaml_new. * lib/yaml/tag.rb: the tag_subclasses? method now shows up in the class. allow taguri to be set using an accessor. continue support of Object#to_yaml_type. * ext/syck/rubyext.c: new emitter code. yaml_new and yaml_initialize get called, should they be present. consolidated all the diaspora of internal node types into the family below YAML::Syck::Node -- Map, Seq, Scalar -- all of whom are SyckNode structs pointing to Ruby data. moved Object#yaml_new into the node_import and made it the default behavior. the target_class is always called wih yaml_new, prepended a parameter, which is the klass. loaded nodes through GenericResolver show their style. new Resolver#tagurize converts type ids to taguris. * ext/syck/implicit.re: were 'y' and 'n' seriously omitted?? * ext/syck/emitter.c: renovated emitter, walks the tree in advance. consolidated redundant block_styles struct into the scalar_style struct. (this means loaded nodes can now be sent back to emitter and preserve at least its very basic formatting.) * ext/syck/gram.c: headless documents of any kind allowed. * ext/syck/node.c: new syck_replace_str methods and syck_empty_* methods for rewriting node contents, while keeping the ID and other setup info. added syck_seq_assign. * ext/syck/syck.h: reflect block_styles and new node functions. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9141 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 23:58:33 -04:00
if ( st_delete( p->anchors, (st_data_t *)&atmp, (st_data_t *)&ntmp ) )
{
if ( ntmp != (void *)1 )
{
syck_free_node( ntmp );
}
}
st_insert( p->anchors, (st_data_t)a, (st_data_t)1 );
}
SyckNode *
syck_hdlr_get_anchor( SyckParser *p, char *a )
{
SyckNode *n = NULL;
if ( p->anchors != NULL )
{
if ( st_lookup( p->anchors, (st_data_t)a, (st_data_t *)&n ) )
{
if ( n != (void *)1 )
{
S_FREE( a );
return n;
}
else
{
if ( p->bad_anchors == NULL )
{
p->bad_anchors = st_init_strtable();
}
if ( ! st_lookup( p->bad_anchors, (st_data_t)a, (st_data_t *)&n ) )
{
n = (p->bad_anchor_handler)( p, a );
st_insert( p->bad_anchors, (st_data_t)a, (st_data_t)n );
}
}
}
}
if ( n == NULL )
{
n = (p->bad_anchor_handler)( p, a );
}
if ( n->anchor )
{
S_FREE( a );
}
else
{
n->anchor = a;
}
return n;
}
void
syck_add_transfer( char *uri, SyckNode *n, int taguri )
{
if ( n->type_id != NULL )
{
S_FREE( n->type_id );
}
if ( taguri == 0 )
{
n->type_id = uri;
return;
}
n->type_id = syck_type_id_to_uri( uri );
S_FREE( uri );
}
char *
syck_xprivate( char *type_id, int type_len )
{
char *uri = S_ALLOC_N( char, type_len + 14 );
uri[0] = '\0';
strcat( uri, "x-private:" );
strncat( uri, type_id, type_len );
return uri;
}
char *
syck_taguri( char *domain, char *type_id, int type_len )
{
char *uri = S_ALLOC_N( char, strlen( domain ) + type_len + 14 );
uri[0] = '\0';
strcat( uri, "tag:" );
strcat( uri, domain );
strcat( uri, ":" );
strncat( uri, type_id, type_len );
return uri;
}
int
syck_try_implicit( SyckNode *n )
{
return 1;
}