mkrf 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +2 -0
- data/MIT-LICENSE +7 -0
- data/README +54 -0
- data/Rakefile +107 -0
- data/lib/mkrf.rb +4 -0
- data/lib/mkrf/availability.rb +219 -0
- data/lib/mkrf/generator.rb +146 -0
- data/test/abstract_unit.rb +4 -0
- data/test/fixtures/down_a_directory/header_down_a_directory.h +1 -0
- data/test/fixtures/stdmkrf.h +1 -0
- data/test/sample_files/libtrivial/Rakefile +31 -0
- data/test/sample_files/libtrivial/extconf.rb +3 -0
- data/test/sample_files/libtrivial/lib/libtrivial.c +5 -0
- data/test/sample_files/libtrivial/lib/libtrivial.o +0 -0
- data/test/sample_files/libtrivial/libtrivial_so.bundle +0 -0
- data/test/sample_files/libtrivial/mkrf.log +1 -0
- data/test/sample_files/libxml-ruby-0.3.8/CHANGELOG +74 -0
- data/test/sample_files/libxml-ruby-0.3.8/LICENSE +22 -0
- data/test/sample_files/libxml-ruby-0.3.8/README +144 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/cbg.c +76 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/extconf.rb +49 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/libxml.c +86 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/libxml.h +82 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/libxml.rb +107 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/mkrf.log +1 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/old_extconf.rb +95 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_attr.c +372 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_attr.h +21 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_attribute.c +224 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_attribute.h +21 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_document.c +1159 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_document.h +27 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_dtd.c +168 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_dtd.h +17 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_input_cbg.c +167 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_input_cbg.h +21 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_node.c +2139 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_node.h +28 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_node_set.c +248 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_node_set.h +26 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_ns.c +153 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_ns.h +21 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_parser.c +1417 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_parser.h +31 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_parser_context.c +715 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_parser_context.h +22 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_sax_parser.c +426 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_sax_parser.h +52 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_schema.c +142 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_schema.h +16 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_tree.c +43 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_tree.h +12 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xinclude.c +20 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xinclude.h +13 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpath.c +363 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpath.h +24 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpath_context.c +125 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpath_context.h +24 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpointer.c +100 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpointer.h +27 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpointer_context.c +21 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpointer_context.h +18 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/sax_parser_callbacks.inc +202 -0
- data/test/sample_files/syck-0.55/CHANGELOG +186 -0
- data/test/sample_files/syck-0.55/COPYING +54 -0
- data/test/sample_files/syck-0.55/Makefile +582 -0
- data/test/sample_files/syck-0.55/Makefile.am +5 -0
- data/test/sample_files/syck-0.55/Makefile.in +582 -0
- data/test/sample_files/syck-0.55/README +105 -0
- data/test/sample_files/syck-0.55/README.BYTECODE +484 -0
- data/test/sample_files/syck-0.55/README.EXT +444 -0
- data/test/sample_files/syck-0.55/RELEASE +123 -0
- data/test/sample_files/syck-0.55/TODO +25 -0
- data/test/sample_files/syck-0.55/aclocal.m4 +883 -0
- data/test/sample_files/syck-0.55/bootstrap +7 -0
- data/test/sample_files/syck-0.55/config.h +79 -0
- data/test/sample_files/syck-0.55/config.h.in +78 -0
- data/test/sample_files/syck-0.55/config.status +1197 -0
- data/test/sample_files/syck-0.55/config/README +14 -0
- data/test/sample_files/syck-0.55/config/depcomp +529 -0
- data/test/sample_files/syck-0.55/config/install-sh +323 -0
- data/test/sample_files/syck-0.55/config/missing +357 -0
- data/test/sample_files/syck-0.55/configure +6728 -0
- data/test/sample_files/syck-0.55/configure.in +36 -0
- data/test/sample_files/syck-0.55/ext/ruby/CHANGELOG +303 -0
- data/test/sample_files/syck-0.55/ext/ruby/README +400 -0
- data/test/sample_files/syck-0.55/ext/ruby/ext/syck/MANIFEST +1 -0
- data/test/sample_files/syck-0.55/ext/ruby/ext/syck/bytecode.c +1170 -0
- data/test/sample_files/syck-0.55/ext/ruby/ext/syck/emitter.c +1224 -0
- data/test/sample_files/syck-0.55/ext/ruby/ext/syck/extconf.rb +10 -0
- data/test/sample_files/syck-0.55/ext/ruby/ext/syck/gram.c +1894 -0
- data/test/sample_files/syck-0.55/ext/ruby/ext/syck/gram.h +79 -0
- data/test/sample_files/syck-0.55/ext/ruby/ext/syck/handler.c +174 -0
- data/test/sample_files/syck-0.55/ext/ruby/ext/syck/implicit.c +2989 -0
- data/test/sample_files/syck-0.55/ext/ruby/ext/syck/mkrf.log +1 -0
- data/test/sample_files/syck-0.55/ext/ruby/ext/syck/node.c +407 -0
- data/test/sample_files/syck-0.55/ext/ruby/ext/syck/rubyext.c +2385 -0
- data/test/sample_files/syck-0.55/ext/ruby/ext/syck/syck.c +504 -0
- data/test/sample_files/syck-0.55/ext/ruby/ext/syck/syck.h +458 -0
- data/test/sample_files/syck-0.55/ext/ruby/ext/syck/token.c +2707 -0
- data/test/sample_files/syck-0.55/ext/ruby/ext/syck/yaml2byte.c +250 -0
- data/test/sample_files/syck-0.55/ext/ruby/ext/syck/yamlbyte.h +170 -0
- data/test/sample_files/syck-0.55/ext/ruby/install.rb +1022 -0
- data/test/sample_files/syck-0.55/ext/ruby/lib/okay.rb +161 -0
- data/test/sample_files/syck-0.55/ext/ruby/lib/okay/news.rb +69 -0
- data/test/sample_files/syck-0.55/ext/ruby/lib/okay/rpc.rb +434 -0
- data/test/sample_files/syck-0.55/ext/ruby/lib/yaml.rb +436 -0
- data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/baseemitter.rb +247 -0
- data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/basenode.rb +216 -0
- data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/compat.rb +26 -0
- data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/constants.rb +45 -0
- data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/dbm.rb +111 -0
- data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/emitter.rb +107 -0
- data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/encoding.rb +33 -0
- data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/error.rb +34 -0
- data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/rubytypes.rb +438 -0
- data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/store.rb +29 -0
- data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/stream.rb +40 -0
- data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/stringio.rb +83 -0
- data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/syck.rb +19 -0
- data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/tag.rb +86 -0
- data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/types.rb +188 -0
- data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/yamlnode.rb +54 -0
- data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/ypath.rb +52 -0
- data/test/sample_files/syck-0.55/ext/ruby/lib/yod.rb +1168 -0
- data/test/sample_files/syck-0.55/ext/ruby/samples/okayNews-modules.rb +27 -0
- data/test/sample_files/syck-0.55/ext/ruby/samples/okayNews-sample.rb +336 -0
- data/test/sample_files/syck-0.55/ext/ruby/samples/okayNews-validate.rb +341 -0
- data/test/sample_files/syck-0.55/ext/ruby/samples/okayRpc-client.rb +51 -0
- data/test/sample_files/syck-0.55/ext/ruby/samples/okayRpc-server.rb +85 -0
- data/test/sample_files/syck-0.55/ext/ruby/samples/yaml-sortHashKeys.rb +128 -0
- data/test/sample_files/syck-0.55/ext/ruby/tests/basic.rb +1653 -0
- data/test/sample_files/syck-0.55/ext/ruby/yts/YtsAnchorAlias.yml +51 -0
- data/test/sample_files/syck-0.55/ext/ruby/yts/YtsBasicTests.yml +282 -0
- data/test/sample_files/syck-0.55/ext/ruby/yts/YtsBlockMapping.yml +78 -0
- data/test/sample_files/syck-0.55/ext/ruby/yts/YtsBlockSequence.yml +0 -0
- data/test/sample_files/syck-0.55/ext/ruby/yts/YtsDocumentSeparator.yml +102 -0
- data/test/sample_files/syck-0.55/ext/ruby/yts/YtsErrorTests.yml +23 -0
- data/test/sample_files/syck-0.55/ext/ruby/yts/YtsFlowCollections.yml +73 -0
- data/test/sample_files/syck-0.55/ext/ruby/yts/YtsFoldedScalars.yml +215 -0
- data/test/sample_files/syck-0.55/ext/ruby/yts/YtsMapInSeq.yml +0 -0
- data/test/sample_files/syck-0.55/ext/ruby/yts/YtsNullsAndEmpties.yml +66 -0
- data/test/sample_files/syck-0.55/ext/ruby/yts/YtsRubyTests.yml +182 -0
- data/test/sample_files/syck-0.55/ext/ruby/yts/YtsSpecificationExamples.yml +2699 -0
- data/test/sample_files/syck-0.55/ext/ruby/yts/YtsTypeTransfers.yml +265 -0
- data/test/sample_files/syck-0.55/ext/ruby/yts/YtsYpath.yml +221 -0
- data/test/sample_files/syck-0.55/ext/ruby/yts/cookbook.rb +159 -0
- data/test/sample_files/syck-0.55/ext/ruby/yts/index.yml +10 -0
- data/test/sample_files/syck-0.55/ext/ruby/yts/yts.rb +193 -0
- data/test/sample_files/syck-0.55/lib/Makefile +497 -0
- data/test/sample_files/syck-0.55/lib/Makefile.am +27 -0
- data/test/sample_files/syck-0.55/lib/Makefile.in +497 -0
- data/test/sample_files/syck-0.55/lib/bytecode.c +1170 -0
- data/test/sample_files/syck-0.55/lib/bytecode.re +525 -0
- data/test/sample_files/syck-0.55/lib/emitter.c +1224 -0
- data/test/sample_files/syck-0.55/lib/gram.c +1894 -0
- data/test/sample_files/syck-0.55/lib/gram.h +79 -0
- data/test/sample_files/syck-0.55/lib/gram.output +2005 -0
- data/test/sample_files/syck-0.55/lib/gram.y +481 -0
- data/test/sample_files/syck-0.55/lib/handler.c +174 -0
- data/test/sample_files/syck-0.55/lib/implicit.c +2989 -0
- data/test/sample_files/syck-0.55/lib/implicit.re +206 -0
- data/test/sample_files/syck-0.55/lib/node.c +407 -0
- data/test/sample_files/syck-0.55/lib/syck.c +504 -0
- data/test/sample_files/syck-0.55/lib/syck.h +458 -0
- data/test/sample_files/syck-0.55/lib/syck_st.c +577 -0
- data/test/sample_files/syck-0.55/lib/syck_st.h +46 -0
- data/test/sample_files/syck-0.55/lib/token.c +2707 -0
- data/test/sample_files/syck-0.55/lib/token.re +1139 -0
- data/test/sample_files/syck-0.55/lib/yaml2byte.c +250 -0
- data/test/sample_files/syck-0.55/lib/yamlbyte.h +170 -0
- data/test/sample_files/syck-0.55/stamp-h1 +1 -0
- data/test/sample_files/syck-0.55/tests/Basic.c +141 -0
- data/test/sample_files/syck-0.55/tests/CuTest.c +294 -0
- data/test/sample_files/syck-0.55/tests/CuTest.h +84 -0
- data/test/sample_files/syck-0.55/tests/Emit.c +87 -0
- data/test/sample_files/syck-0.55/tests/Makefile +480 -0
- data/test/sample_files/syck-0.55/tests/Makefile.am +13 -0
- data/test/sample_files/syck-0.55/tests/Makefile.in +480 -0
- data/test/sample_files/syck-0.55/tests/Parse.c +208 -0
- data/test/sample_files/syck-0.55/tests/YTS.c +2310 -0
- data/test/sample_files/syck-0.55/tests/YTS.c.erb +326 -0
- data/test/sample_files/syck-0.55/tests/YTS.c.rb +44 -0
- data/test/test_availability.rb +68 -0
- data/test/test_generator.rb +74 -0
- metadata +252 -0
@@ -0,0 +1,504 @@
|
|
1
|
+
/*
|
2
|
+
* syck.c
|
3
|
+
*
|
4
|
+
* $Author: why $
|
5
|
+
* $Date: 2005/01/01 02:06:25 $
|
6
|
+
*
|
7
|
+
* Copyright (C) 2003 why the lucky stiff
|
8
|
+
*/
|
9
|
+
#include <stdio.h>
|
10
|
+
#include <string.h>
|
11
|
+
|
12
|
+
#include "syck.h"
|
13
|
+
|
14
|
+
void syck_parser_pop_level( SyckParser * );
|
15
|
+
|
16
|
+
/*
|
17
|
+
* Custom assert
|
18
|
+
*/
|
19
|
+
void
|
20
|
+
syck_assert( char *file_name, unsigned line_num )
|
21
|
+
{
|
22
|
+
fflush( NULL );
|
23
|
+
fprintf( stderr, "\nAssertion failed: %s, line %u\n",
|
24
|
+
file_name, line_num );
|
25
|
+
fflush( stderr );
|
26
|
+
abort();
|
27
|
+
}
|
28
|
+
|
29
|
+
/*
|
30
|
+
* Allocates and copies a string
|
31
|
+
*/
|
32
|
+
char *
|
33
|
+
syck_strndup( char *buf, long len )
|
34
|
+
{
|
35
|
+
char *new = S_ALLOC_N( char, len + 1 );
|
36
|
+
S_MEMZERO( new, char, len + 1 );
|
37
|
+
S_MEMCPY( new, buf, char, len );
|
38
|
+
return new;
|
39
|
+
}
|
40
|
+
|
41
|
+
/*
|
42
|
+
* Default FILE IO function
|
43
|
+
*/
|
44
|
+
long
|
45
|
+
syck_io_file_read( char *buf, SyckIoFile *file, long max_size, long skip )
|
46
|
+
{
|
47
|
+
long len = 0;
|
48
|
+
|
49
|
+
ASSERT( file != NULL );
|
50
|
+
|
51
|
+
max_size -= skip;
|
52
|
+
len = fread( buf + skip, sizeof( char ), max_size, file->ptr );
|
53
|
+
len += skip;
|
54
|
+
buf[len] = '\0';
|
55
|
+
|
56
|
+
return len;
|
57
|
+
}
|
58
|
+
|
59
|
+
/*
|
60
|
+
* Default string IO function
|
61
|
+
*/
|
62
|
+
long
|
63
|
+
syck_io_str_read( char *buf, SyckIoStr *str, long max_size, long skip )
|
64
|
+
{
|
65
|
+
char *beg;
|
66
|
+
long len = 0;
|
67
|
+
|
68
|
+
ASSERT( str != NULL );
|
69
|
+
beg = str->ptr;
|
70
|
+
if ( max_size >= 0 )
|
71
|
+
{
|
72
|
+
max_size -= skip;
|
73
|
+
if ( max_size <= 0 ) max_size = 0;
|
74
|
+
else str->ptr += max_size;
|
75
|
+
|
76
|
+
if ( str->ptr > str->end )
|
77
|
+
{
|
78
|
+
str->ptr = str->end;
|
79
|
+
}
|
80
|
+
}
|
81
|
+
else
|
82
|
+
{
|
83
|
+
/* Use exact string length */
|
84
|
+
while ( str->ptr < str->end ) {
|
85
|
+
if (*(str->ptr++) == '\n') break;
|
86
|
+
}
|
87
|
+
}
|
88
|
+
if ( beg < str->ptr )
|
89
|
+
{
|
90
|
+
len = ( str->ptr - beg );
|
91
|
+
S_MEMCPY( buf + skip, beg, char, len );
|
92
|
+
}
|
93
|
+
len += skip;
|
94
|
+
buf[len] = '\0';
|
95
|
+
|
96
|
+
return len;
|
97
|
+
}
|
98
|
+
|
99
|
+
void
|
100
|
+
syck_parser_reset_levels( SyckParser *p )
|
101
|
+
{
|
102
|
+
while ( p->lvl_idx > 1 )
|
103
|
+
{
|
104
|
+
syck_parser_pop_level( p );
|
105
|
+
}
|
106
|
+
|
107
|
+
if ( p->lvl_idx < 1 )
|
108
|
+
{
|
109
|
+
p->lvl_idx = 1;
|
110
|
+
p->levels[0].spaces = -1;
|
111
|
+
p->levels[0].ncount = 0;
|
112
|
+
p->levels[0].domain = syck_strndup( "", 0 );
|
113
|
+
}
|
114
|
+
p->levels[0].status = syck_lvl_header;
|
115
|
+
}
|
116
|
+
|
117
|
+
void
|
118
|
+
syck_parser_reset_cursor( SyckParser *p )
|
119
|
+
{
|
120
|
+
if ( p->buffer == NULL )
|
121
|
+
{
|
122
|
+
p->buffer = S_ALLOC_N( char, p->bufsize );
|
123
|
+
S_MEMZERO( p->buffer, char, p->bufsize );
|
124
|
+
}
|
125
|
+
p->buffer[0] = '\0';
|
126
|
+
|
127
|
+
p->cursor = NULL;
|
128
|
+
p->lineptr = NULL;
|
129
|
+
p->linectptr = NULL;
|
130
|
+
p->token = NULL;
|
131
|
+
p->toktmp = NULL;
|
132
|
+
p->marker = NULL;
|
133
|
+
p->limit = NULL;
|
134
|
+
|
135
|
+
p->root = 0;
|
136
|
+
p->root_on_error = 0;
|
137
|
+
p->linect = 0;
|
138
|
+
p->eof = 0;
|
139
|
+
p->last_token = 0;
|
140
|
+
p->force_token = 0;
|
141
|
+
}
|
142
|
+
|
143
|
+
/*
|
144
|
+
* Value to return on a parse error
|
145
|
+
*/
|
146
|
+
void
|
147
|
+
syck_parser_set_root_on_error( SyckParser *p, SYMID roer )
|
148
|
+
{
|
149
|
+
p->root_on_error = roer;
|
150
|
+
}
|
151
|
+
|
152
|
+
/*
|
153
|
+
* Allocate the parser
|
154
|
+
*/
|
155
|
+
SyckParser *
|
156
|
+
syck_new_parser()
|
157
|
+
{
|
158
|
+
SyckParser *p;
|
159
|
+
p = S_ALLOC( SyckParser );
|
160
|
+
S_MEMZERO( p, SyckParser, 1 );
|
161
|
+
p->lvl_capa = ALLOC_CT;
|
162
|
+
p->levels = S_ALLOC_N( SyckLevel, p->lvl_capa );
|
163
|
+
p->input_type = syck_yaml_utf8;
|
164
|
+
p->io_type = syck_io_str;
|
165
|
+
p->io.str = NULL;
|
166
|
+
p->syms = NULL;
|
167
|
+
p->anchors = NULL;
|
168
|
+
p->bad_anchors = NULL;
|
169
|
+
p->implicit_typing = 1;
|
170
|
+
p->taguri_expansion = 0;
|
171
|
+
p->bufsize = SYCK_BUFFERSIZE;
|
172
|
+
p->buffer = NULL;
|
173
|
+
p->lvl_idx = 0;
|
174
|
+
syck_parser_reset_levels( p );
|
175
|
+
return p;
|
176
|
+
}
|
177
|
+
|
178
|
+
int
|
179
|
+
syck_add_sym( SyckParser *p, char *data )
|
180
|
+
{
|
181
|
+
SYMID id = 0;
|
182
|
+
if ( p->syms == NULL )
|
183
|
+
{
|
184
|
+
p->syms = st_init_numtable();
|
185
|
+
}
|
186
|
+
id = p->syms->num_entries + 1;
|
187
|
+
st_insert( p->syms, id, (st_data_t)data );
|
188
|
+
return id;
|
189
|
+
}
|
190
|
+
|
191
|
+
int
|
192
|
+
syck_lookup_sym( SyckParser *p, SYMID id, char **data )
|
193
|
+
{
|
194
|
+
if ( p->syms == NULL ) return 0;
|
195
|
+
return st_lookup( p->syms, id, (st_data_t *)data );
|
196
|
+
}
|
197
|
+
|
198
|
+
int
|
199
|
+
syck_st_free_nodes( char *key, SyckNode *n, char *arg )
|
200
|
+
{
|
201
|
+
if ( n != (void *)1 ) syck_free_node( n );
|
202
|
+
n = NULL;
|
203
|
+
return ST_CONTINUE;
|
204
|
+
}
|
205
|
+
|
206
|
+
void
|
207
|
+
syck_st_free( SyckParser *p )
|
208
|
+
{
|
209
|
+
/*
|
210
|
+
* Free the anchor tables
|
211
|
+
*/
|
212
|
+
if ( p->anchors != NULL )
|
213
|
+
{
|
214
|
+
st_foreach( p->anchors, syck_st_free_nodes, 0 );
|
215
|
+
st_free_table( p->anchors );
|
216
|
+
p->anchors = NULL;
|
217
|
+
}
|
218
|
+
|
219
|
+
if ( p->bad_anchors != NULL )
|
220
|
+
{
|
221
|
+
st_foreach( p->bad_anchors, syck_st_free_nodes, 0 );
|
222
|
+
st_free_table( p->bad_anchors );
|
223
|
+
p->bad_anchors = NULL;
|
224
|
+
}
|
225
|
+
}
|
226
|
+
|
227
|
+
void
|
228
|
+
syck_free_parser( SyckParser *p )
|
229
|
+
{
|
230
|
+
/*
|
231
|
+
* Free the adhoc symbol table
|
232
|
+
*/
|
233
|
+
if ( p->syms != NULL )
|
234
|
+
{
|
235
|
+
st_free_table( p->syms );
|
236
|
+
p->syms = NULL;
|
237
|
+
}
|
238
|
+
|
239
|
+
/*
|
240
|
+
* Free tables, levels
|
241
|
+
*/
|
242
|
+
syck_st_free( p );
|
243
|
+
syck_parser_reset_levels( p );
|
244
|
+
S_FREE( p->levels[0].domain );
|
245
|
+
S_FREE( p->levels );
|
246
|
+
|
247
|
+
if ( p->buffer != NULL )
|
248
|
+
{
|
249
|
+
S_FREE( p->buffer );
|
250
|
+
}
|
251
|
+
free_any_io( p );
|
252
|
+
S_FREE( p );
|
253
|
+
}
|
254
|
+
|
255
|
+
void
|
256
|
+
syck_parser_handler( SyckParser *p, SyckNodeHandler hdlr )
|
257
|
+
{
|
258
|
+
ASSERT( p != NULL );
|
259
|
+
p->handler = hdlr;
|
260
|
+
}
|
261
|
+
|
262
|
+
void
|
263
|
+
syck_parser_implicit_typing( SyckParser *p, int flag )
|
264
|
+
{
|
265
|
+
p->implicit_typing = ( flag == 0 ? 0 : 1 );
|
266
|
+
}
|
267
|
+
|
268
|
+
void
|
269
|
+
syck_parser_taguri_expansion( SyckParser *p, int flag )
|
270
|
+
{
|
271
|
+
p->taguri_expansion = ( flag == 0 ? 0 : 1 );
|
272
|
+
}
|
273
|
+
|
274
|
+
void
|
275
|
+
syck_parser_error_handler( SyckParser *p, SyckErrorHandler hdlr )
|
276
|
+
{
|
277
|
+
ASSERT( p != NULL );
|
278
|
+
p->error_handler = hdlr;
|
279
|
+
}
|
280
|
+
|
281
|
+
void
|
282
|
+
syck_parser_bad_anchor_handler( SyckParser *p, SyckBadAnchorHandler hdlr )
|
283
|
+
{
|
284
|
+
ASSERT( p != NULL );
|
285
|
+
p->bad_anchor_handler = hdlr;
|
286
|
+
}
|
287
|
+
|
288
|
+
void
|
289
|
+
syck_parser_set_input_type( SyckParser *p, enum syck_parser_input input_type )
|
290
|
+
{
|
291
|
+
ASSERT( p != NULL );
|
292
|
+
p->input_type = input_type;
|
293
|
+
}
|
294
|
+
|
295
|
+
void
|
296
|
+
syck_parser_file( SyckParser *p, FILE *fp, SyckIoFileRead read )
|
297
|
+
{
|
298
|
+
ASSERT( p != NULL );
|
299
|
+
free_any_io( p );
|
300
|
+
syck_parser_reset_cursor( p );
|
301
|
+
p->io_type = syck_io_file;
|
302
|
+
p->io.file = S_ALLOC( SyckIoFile );
|
303
|
+
p->io.file->ptr = fp;
|
304
|
+
if ( read != NULL )
|
305
|
+
{
|
306
|
+
p->io.file->read = read;
|
307
|
+
}
|
308
|
+
else
|
309
|
+
{
|
310
|
+
p->io.file->read = syck_io_file_read;
|
311
|
+
}
|
312
|
+
}
|
313
|
+
|
314
|
+
void
|
315
|
+
syck_parser_str( SyckParser *p, char *ptr, long len, SyckIoStrRead read )
|
316
|
+
{
|
317
|
+
ASSERT( p != NULL );
|
318
|
+
free_any_io( p );
|
319
|
+
syck_parser_reset_cursor( p );
|
320
|
+
p->io_type = syck_io_str;
|
321
|
+
p->io.str = S_ALLOC( SyckIoStr );
|
322
|
+
p->io.str->beg = ptr;
|
323
|
+
p->io.str->ptr = ptr;
|
324
|
+
p->io.str->end = ptr + len;
|
325
|
+
if ( read != NULL )
|
326
|
+
{
|
327
|
+
p->io.str->read = read;
|
328
|
+
}
|
329
|
+
else
|
330
|
+
{
|
331
|
+
p->io.str->read = syck_io_str_read;
|
332
|
+
}
|
333
|
+
}
|
334
|
+
|
335
|
+
void
|
336
|
+
syck_parser_str_auto( SyckParser *p, char *ptr, SyckIoStrRead read )
|
337
|
+
{
|
338
|
+
syck_parser_str( p, ptr, strlen( ptr ), read );
|
339
|
+
}
|
340
|
+
|
341
|
+
SyckLevel *
|
342
|
+
syck_parser_current_level( SyckParser *p )
|
343
|
+
{
|
344
|
+
return &p->levels[p->lvl_idx-1];
|
345
|
+
}
|
346
|
+
|
347
|
+
void
|
348
|
+
syck_parser_pop_level( SyckParser *p )
|
349
|
+
{
|
350
|
+
ASSERT( p != NULL );
|
351
|
+
|
352
|
+
/* The root level should never be popped */
|
353
|
+
if ( p->lvl_idx <= 1 ) return;
|
354
|
+
|
355
|
+
p->lvl_idx -= 1;
|
356
|
+
free( p->levels[p->lvl_idx].domain );
|
357
|
+
}
|
358
|
+
|
359
|
+
void
|
360
|
+
syck_parser_add_level( SyckParser *p, int len, enum syck_level_status status )
|
361
|
+
{
|
362
|
+
ASSERT( p != NULL );
|
363
|
+
if ( p->lvl_idx + 1 > p->lvl_capa )
|
364
|
+
{
|
365
|
+
p->lvl_capa += ALLOC_CT;
|
366
|
+
S_REALLOC_N( p->levels, SyckLevel, p->lvl_capa );
|
367
|
+
}
|
368
|
+
|
369
|
+
ASSERT( len > p->levels[p->lvl_idx-1].spaces );
|
370
|
+
p->levels[p->lvl_idx].spaces = len;
|
371
|
+
p->levels[p->lvl_idx].ncount = 0;
|
372
|
+
p->levels[p->lvl_idx].domain = syck_strndup( p->levels[p->lvl_idx-1].domain, strlen( p->levels[p->lvl_idx-1].domain ) );
|
373
|
+
p->levels[p->lvl_idx].status = status;
|
374
|
+
p->lvl_idx += 1;
|
375
|
+
}
|
376
|
+
|
377
|
+
void
|
378
|
+
free_any_io( SyckParser *p )
|
379
|
+
{
|
380
|
+
ASSERT( p != NULL );
|
381
|
+
switch ( p->io_type )
|
382
|
+
{
|
383
|
+
case syck_io_str:
|
384
|
+
if ( p->io.str != NULL )
|
385
|
+
{
|
386
|
+
S_FREE( p->io.str );
|
387
|
+
p->io.str = NULL;
|
388
|
+
}
|
389
|
+
break;
|
390
|
+
|
391
|
+
case syck_io_file:
|
392
|
+
if ( p->io.file != NULL )
|
393
|
+
{
|
394
|
+
S_FREE( p->io.file );
|
395
|
+
p->io.file = NULL;
|
396
|
+
}
|
397
|
+
break;
|
398
|
+
}
|
399
|
+
}
|
400
|
+
|
401
|
+
long
|
402
|
+
syck_move_tokens( SyckParser *p )
|
403
|
+
{
|
404
|
+
long count, skip;
|
405
|
+
ASSERT( p->buffer != NULL );
|
406
|
+
|
407
|
+
if ( p->token == NULL )
|
408
|
+
return 0;
|
409
|
+
|
410
|
+
skip = p->limit - p->token;
|
411
|
+
if ( skip < 1 )
|
412
|
+
return 0;
|
413
|
+
|
414
|
+
if ( ( count = p->token - p->buffer ) )
|
415
|
+
{
|
416
|
+
S_MEMMOVE( p->buffer, p->token, char, skip );
|
417
|
+
p->token = p->buffer;
|
418
|
+
p->marker -= count;
|
419
|
+
p->cursor -= count;
|
420
|
+
p->toktmp -= count;
|
421
|
+
p->limit -= count;
|
422
|
+
p->lineptr -= count;
|
423
|
+
p->linectptr -= count;
|
424
|
+
}
|
425
|
+
return skip;
|
426
|
+
}
|
427
|
+
|
428
|
+
void
|
429
|
+
syck_check_limit( SyckParser *p, long len )
|
430
|
+
{
|
431
|
+
if ( p->cursor == NULL )
|
432
|
+
{
|
433
|
+
p->cursor = p->buffer;
|
434
|
+
p->lineptr = p->buffer;
|
435
|
+
p->linectptr = p->buffer;
|
436
|
+
p->marker = p->buffer;
|
437
|
+
}
|
438
|
+
p->limit = p->buffer + len;
|
439
|
+
}
|
440
|
+
|
441
|
+
long
|
442
|
+
syck_parser_read( SyckParser *p )
|
443
|
+
{
|
444
|
+
long len = 0;
|
445
|
+
long skip = 0;
|
446
|
+
ASSERT( p != NULL );
|
447
|
+
switch ( p->io_type )
|
448
|
+
{
|
449
|
+
case syck_io_str:
|
450
|
+
skip = syck_move_tokens( p );
|
451
|
+
len = (p->io.str->read)( p->buffer, p->io.str, SYCK_BUFFERSIZE - 1, skip );
|
452
|
+
break;
|
453
|
+
|
454
|
+
case syck_io_file:
|
455
|
+
skip = syck_move_tokens( p );
|
456
|
+
len = (p->io.file->read)( p->buffer, p->io.file, SYCK_BUFFERSIZE - 1, skip );
|
457
|
+
break;
|
458
|
+
}
|
459
|
+
syck_check_limit( p, len );
|
460
|
+
return len;
|
461
|
+
}
|
462
|
+
|
463
|
+
long
|
464
|
+
syck_parser_readlen( SyckParser *p, long max_size )
|
465
|
+
{
|
466
|
+
long len = 0;
|
467
|
+
long skip = 0;
|
468
|
+
ASSERT( p != NULL );
|
469
|
+
switch ( p->io_type )
|
470
|
+
{
|
471
|
+
case syck_io_str:
|
472
|
+
skip = syck_move_tokens( p );
|
473
|
+
len = (p->io.str->read)( p->buffer, p->io.str, max_size, skip );
|
474
|
+
break;
|
475
|
+
|
476
|
+
case syck_io_file:
|
477
|
+
skip = syck_move_tokens( p );
|
478
|
+
len = (p->io.file->read)( p->buffer, p->io.file, max_size, skip );
|
479
|
+
break;
|
480
|
+
}
|
481
|
+
syck_check_limit( p, len );
|
482
|
+
return len;
|
483
|
+
}
|
484
|
+
|
485
|
+
SYMID
|
486
|
+
syck_parse( SyckParser *p )
|
487
|
+
{
|
488
|
+
ASSERT( p != NULL );
|
489
|
+
|
490
|
+
syck_st_free( p );
|
491
|
+
syck_parser_reset_levels( p );
|
492
|
+
syckparse( p );
|
493
|
+
return p->root;
|
494
|
+
}
|
495
|
+
|
496
|
+
void
|
497
|
+
syck_default_error_handler( SyckParser *p, char *msg )
|
498
|
+
{
|
499
|
+
printf( "Error at [Line %d, Col %d]: %s\n",
|
500
|
+
p->linect,
|
501
|
+
p->cursor - p->lineptr,
|
502
|
+
msg );
|
503
|
+
}
|
504
|
+
|