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,250 @@
|
|
1
|
+
/*
|
2
|
+
* yaml2byte.c
|
3
|
+
*
|
4
|
+
* $Author: why $
|
5
|
+
* $Date: 2004/08/02 17:32:35 $
|
6
|
+
*
|
7
|
+
* Copyright (C) 2003 why the lucky stiff, clark evans
|
8
|
+
*
|
9
|
+
* WARNING WARNING WARNING --- THIS IS *NOT JUST* PLAYING
|
10
|
+
* ANYMORE! -- WHY HAS EMBRACED THIS AS THE REAL THING!
|
11
|
+
*/
|
12
|
+
#include <syck.h>
|
13
|
+
#include <assert.h>
|
14
|
+
#define YAMLBYTE_UTF8
|
15
|
+
#include "yamlbyte.h"
|
16
|
+
|
17
|
+
#include <stdio.h>
|
18
|
+
#define TRACE0(a) \
|
19
|
+
do { printf(a); printf("\n"); fflush(stdout); } while(0)
|
20
|
+
#define TRACE1(a,b) \
|
21
|
+
do { printf(a,b); printf("\n"); fflush(stdout); } while(0)
|
22
|
+
#define TRACE2(a,b,c) \
|
23
|
+
do { printf(a,b,c); printf("\n"); fflush(stdout); } while(0)
|
24
|
+
#define TRACE3(a,b,c,d) \
|
25
|
+
do { printf(a,b,c,d); printf("\n"); fflush(stdout); } while(0)
|
26
|
+
|
27
|
+
/* Reinvent the wheel... */
|
28
|
+
#define CHUNKSIZE 64
|
29
|
+
#define HASH ((long)0xCAFECAFE)
|
30
|
+
typedef struct {
|
31
|
+
long hash;
|
32
|
+
char *buffer;
|
33
|
+
long length;
|
34
|
+
long remaining;
|
35
|
+
int printed;
|
36
|
+
} bytestring_t;
|
37
|
+
bytestring_t *bytestring_alloc() {
|
38
|
+
bytestring_t *ret;
|
39
|
+
/*TRACE0("bytestring_alloc()");*/
|
40
|
+
ret = S_ALLOC(bytestring_t);
|
41
|
+
ret->hash = HASH;
|
42
|
+
ret->length = CHUNKSIZE;
|
43
|
+
ret->remaining = ret->length;
|
44
|
+
ret->buffer = S_ALLOC_N(char, ret->length + 1 );
|
45
|
+
ret->buffer[0] = 0;
|
46
|
+
ret->printed = 0;
|
47
|
+
return ret;
|
48
|
+
}
|
49
|
+
void bytestring_append(bytestring_t *str, char code,
|
50
|
+
char *start, char *finish)
|
51
|
+
{
|
52
|
+
long grow;
|
53
|
+
long length = 2; /* CODE + LF */
|
54
|
+
char *curr;
|
55
|
+
assert(str && HASH == str->hash);
|
56
|
+
/*TRACE0("bytestring_append()");*/
|
57
|
+
if(start) {
|
58
|
+
if(!finish)
|
59
|
+
finish = start + strlen(start);
|
60
|
+
length += (finish-start);
|
61
|
+
}
|
62
|
+
if(length > str->remaining) {
|
63
|
+
grow = (length - str->remaining) + CHUNKSIZE;
|
64
|
+
str->remaining += grow;
|
65
|
+
str->length += grow;
|
66
|
+
str->buffer = S_REALLOC_N( str->buffer, char, str->length + 1 );
|
67
|
+
assert(str->buffer);
|
68
|
+
}
|
69
|
+
curr = str->buffer + (str->length - str->remaining);
|
70
|
+
*curr = code;
|
71
|
+
curr += 1;
|
72
|
+
if(start)
|
73
|
+
while(start < finish)
|
74
|
+
*curr ++ = *start ++;
|
75
|
+
*curr = '\n';
|
76
|
+
curr += 1;
|
77
|
+
*curr = 0;
|
78
|
+
str->remaining = str->remaining - length;
|
79
|
+
assert( (str->buffer + str->length) - str->remaining );
|
80
|
+
}
|
81
|
+
void bytestring_extend(bytestring_t *str, bytestring_t *ext)
|
82
|
+
{
|
83
|
+
char *from;
|
84
|
+
char *curr;
|
85
|
+
char *stop;
|
86
|
+
long grow;
|
87
|
+
long length;
|
88
|
+
assert(str && HASH == str->hash);
|
89
|
+
assert(ext && HASH == ext->hash);
|
90
|
+
if(ext->printed) {
|
91
|
+
assert(ext->buffer[0] ==YAMLBYTE_ANCHOR);
|
92
|
+
curr = ext->buffer;
|
93
|
+
while( '\n' != *curr)
|
94
|
+
curr++;
|
95
|
+
bytestring_append(str, YAMLBYTE_ALIAS, ext->buffer + 1, curr);
|
96
|
+
} else {
|
97
|
+
ext->printed = 1;
|
98
|
+
length = (ext->length - ext->remaining);
|
99
|
+
if(length > str->remaining) {
|
100
|
+
grow = (length - str->remaining) + CHUNKSIZE;
|
101
|
+
str->remaining += grow;
|
102
|
+
str->length += grow;
|
103
|
+
str->buffer = S_REALLOC_N( str->buffer, char, str->length + 1 );
|
104
|
+
}
|
105
|
+
curr = str->buffer + (str->length - str->remaining);
|
106
|
+
from = ext->buffer;
|
107
|
+
stop = ext->buffer + length;
|
108
|
+
while( from < stop )
|
109
|
+
*curr ++ = *from ++;
|
110
|
+
*curr = 0;
|
111
|
+
str->remaining = str->remaining - length;
|
112
|
+
assert( (str->buffer + str->length) - str->remaining );
|
113
|
+
}
|
114
|
+
}
|
115
|
+
|
116
|
+
/* convert SyckNode into yamlbyte_buffer_t objects */
|
117
|
+
SYMID
|
118
|
+
syck_yaml2byte_handler(p, n)
|
119
|
+
SyckParser *p;
|
120
|
+
SyckNode *n;
|
121
|
+
{
|
122
|
+
SYMID oid;
|
123
|
+
long i;
|
124
|
+
char ch;
|
125
|
+
char nextcode;
|
126
|
+
char *start;
|
127
|
+
char *current;
|
128
|
+
char *finish;
|
129
|
+
bytestring_t *val = NULL;
|
130
|
+
bytestring_t *sav = NULL;
|
131
|
+
/*TRACE0("syck_yaml2byte_handler()");*/
|
132
|
+
val = bytestring_alloc();
|
133
|
+
if(n->anchor) bytestring_append(val,YAMLBYTE_ANCHOR, n->anchor, NULL);
|
134
|
+
if ( n->type_id )
|
135
|
+
{
|
136
|
+
if ( p->taguri_expansion )
|
137
|
+
{
|
138
|
+
bytestring_append(val,YAMLBYTE_TRANSFER, n->type_id, NULL);
|
139
|
+
}
|
140
|
+
else
|
141
|
+
{
|
142
|
+
char *type_tag = S_ALLOC_N( char, strlen( n->type_id ) + 1 );
|
143
|
+
type_tag[0] = '\0';
|
144
|
+
strcat( type_tag, "!" );
|
145
|
+
strcat( type_tag, n->type_id );
|
146
|
+
bytestring_append( val, YAMLBYTE_TRANSFER, type_tag, NULL);
|
147
|
+
}
|
148
|
+
}
|
149
|
+
switch (n->kind)
|
150
|
+
{
|
151
|
+
case syck_str_kind:
|
152
|
+
nextcode = YAMLBYTE_SCALAR;
|
153
|
+
start = n->data.str->ptr;
|
154
|
+
finish = start + n->data.str->len - 1;
|
155
|
+
current = start;
|
156
|
+
/*TRACE2("SCALAR: %s %d", start, n->data.str->len); */
|
157
|
+
while(1) {
|
158
|
+
ch = *current;
|
159
|
+
if('\n' == ch || 0 == ch || current > finish) {
|
160
|
+
if(current >= start) {
|
161
|
+
bytestring_append(val, nextcode, start, current);
|
162
|
+
nextcode = YAMLBYTE_CONTINUE;
|
163
|
+
}
|
164
|
+
start = current + 1;
|
165
|
+
if(current > finish)
|
166
|
+
{
|
167
|
+
break;
|
168
|
+
}
|
169
|
+
else if('\n' == ch )
|
170
|
+
{
|
171
|
+
bytestring_append(val,YAMLBYTE_NEWLINE,NULL,NULL);
|
172
|
+
}
|
173
|
+
else if(0 == ch)
|
174
|
+
{
|
175
|
+
bytestring_append(val,YAMLBYTE_NULLCHAR,NULL,NULL);
|
176
|
+
}
|
177
|
+
else
|
178
|
+
{
|
179
|
+
assert("oops");
|
180
|
+
}
|
181
|
+
}
|
182
|
+
current += 1;
|
183
|
+
}
|
184
|
+
break;
|
185
|
+
case syck_seq_kind:
|
186
|
+
bytestring_append(val,YAMLBYTE_SEQUENCE,NULL,NULL);
|
187
|
+
for ( i = 0; i < n->data.list->idx; i++ )
|
188
|
+
{
|
189
|
+
oid = syck_seq_read( n, i );
|
190
|
+
syck_lookup_sym( p, oid, (char **)&sav );
|
191
|
+
bytestring_extend(val, sav);
|
192
|
+
}
|
193
|
+
bytestring_append(val,YAMLBYTE_END_BRANCH,NULL,NULL);
|
194
|
+
break;
|
195
|
+
case syck_map_kind:
|
196
|
+
bytestring_append(val,YAMLBYTE_MAPPING,NULL,NULL);
|
197
|
+
for ( i = 0; i < n->data.pairs->idx; i++ )
|
198
|
+
{
|
199
|
+
oid = syck_map_read( n, map_key, i );
|
200
|
+
syck_lookup_sym( p, oid, (char **)&sav );
|
201
|
+
bytestring_extend(val, sav);
|
202
|
+
oid = syck_map_read( n, map_value, i );
|
203
|
+
syck_lookup_sym( p, oid, (char **)&sav );
|
204
|
+
bytestring_extend(val, sav);
|
205
|
+
}
|
206
|
+
bytestring_append(val,YAMLBYTE_END_BRANCH,NULL,NULL);
|
207
|
+
break;
|
208
|
+
}
|
209
|
+
oid = syck_add_sym( p, (char *) val );
|
210
|
+
/*TRACE1("Saving: %s", val->buffer );*/
|
211
|
+
return oid;
|
212
|
+
}
|
213
|
+
|
214
|
+
char *
|
215
|
+
syck_yaml2byte(char *yamlstr)
|
216
|
+
{
|
217
|
+
SYMID oid;
|
218
|
+
char *ret;
|
219
|
+
bytestring_t *sav;
|
220
|
+
|
221
|
+
SyckParser *parser = syck_new_parser();
|
222
|
+
syck_parser_str_auto( parser, yamlstr, NULL );
|
223
|
+
syck_parser_handler( parser, syck_yaml2byte_handler );
|
224
|
+
syck_parser_error_handler( parser, NULL );
|
225
|
+
syck_parser_implicit_typing( parser, 1 );
|
226
|
+
syck_parser_taguri_expansion( parser, 1 );
|
227
|
+
oid = syck_parse( parser );
|
228
|
+
syck_lookup_sym( parser, oid, (char **)&sav );
|
229
|
+
|
230
|
+
ret = S_ALLOC_N( char, strlen( sav->buffer ) + 3 );
|
231
|
+
ret[0] = '\0';
|
232
|
+
strcat( ret, "D\n" );
|
233
|
+
strcat( ret, sav->buffer );
|
234
|
+
|
235
|
+
syck_free_parser( parser );
|
236
|
+
return ret;
|
237
|
+
}
|
238
|
+
|
239
|
+
#ifdef TEST_YBEXT
|
240
|
+
#include <stdio.h>
|
241
|
+
int main() {
|
242
|
+
char *yaml = "test: 1\nand: \"with new\\nline\\n\"\nalso: &3 three\nmore: *3";
|
243
|
+
printf("--- # YAML \n");
|
244
|
+
printf(yaml);
|
245
|
+
printf("\n...\n");
|
246
|
+
printf(syck_yaml2byte(yaml));
|
247
|
+
return 0;
|
248
|
+
}
|
249
|
+
#endif
|
250
|
+
|
@@ -0,0 +1,170 @@
|
|
1
|
+
/* yamlbyte.h
|
2
|
+
*
|
3
|
+
* The YAML bytecode "C" interface header file. See the YAML bytecode
|
4
|
+
* reference for bytecode sequence rules and for the meaning of each
|
5
|
+
* bytecode.
|
6
|
+
*/
|
7
|
+
|
8
|
+
#ifndef YAMLBYTE_H
|
9
|
+
#define YAMLBYTE_H
|
10
|
+
#include <stddef.h>
|
11
|
+
|
12
|
+
/* define what a character is */
|
13
|
+
typedef unsigned char yamlbyte_utf8_t;
|
14
|
+
typedef unsigned short yamlbyte_utf16_t;
|
15
|
+
#ifdef YAMLBYTE_UTF8
|
16
|
+
#ifdef YAMLBYTE_UTF16
|
17
|
+
#error Must only define YAMLBYTE_UTF8 or YAMLBYTE_UTF16
|
18
|
+
#endif
|
19
|
+
typedef yamlbyte_utf8_t yamlbyte_char_t;
|
20
|
+
#else
|
21
|
+
#ifdef YAMLBYTE_UTF16
|
22
|
+
typedef yamlbyte_utf16_t yamlbyte_char_t;
|
23
|
+
#else
|
24
|
+
#error Must define YAMLBYTE_UTF8 or YAMLBYTE_UTF16
|
25
|
+
#endif
|
26
|
+
#endif
|
27
|
+
|
28
|
+
/* specify list of bytecodes */
|
29
|
+
#define YAMLBYTE_FINISH ((yamlbyte_char_t) 0)
|
30
|
+
#define YAMLBYTE_DOCUMENT ((yamlbyte_char_t)'D')
|
31
|
+
#define YAMLBYTE_DIRECTIVE ((yamlbyte_char_t)'V')
|
32
|
+
#define YAMLBYTE_PAUSE ((yamlbyte_char_t)'P')
|
33
|
+
#define YAMLBYTE_MAPPING ((yamlbyte_char_t)'M')
|
34
|
+
#define YAMLBYTE_SEQUENCE ((yamlbyte_char_t)'Q')
|
35
|
+
#define YAMLBYTE_END_BRANCH ((yamlbyte_char_t)'E')
|
36
|
+
#define YAMLBYTE_SCALAR ((yamlbyte_char_t)'S')
|
37
|
+
#define YAMLBYTE_CONTINUE ((yamlbyte_char_t)'C')
|
38
|
+
#define YAMLBYTE_NEWLINE ((yamlbyte_char_t)'N')
|
39
|
+
#define YAMLBYTE_NULLCHAR ((yamlbyte_char_t)'Z')
|
40
|
+
#define YAMLBYTE_ANCHOR ((yamlbyte_char_t)'A')
|
41
|
+
#define YAMLBYTE_ALIAS ((yamlbyte_char_t)'R')
|
42
|
+
#define YAMLBYTE_TRANSFER ((yamlbyte_char_t)'T')
|
43
|
+
/* formatting bytecodes */
|
44
|
+
#define YAMLBYTE_COMMENT ((yamlbyte_char_t)'c')
|
45
|
+
#define YAMLBYTE_INDENT ((yamlbyte_char_t)'i')
|
46
|
+
#define YAMLBYTE_STYLE ((yamlbyte_char_t)'s')
|
47
|
+
/* other bytecodes */
|
48
|
+
#define YAMLBYTE_LINE_NUMBER ((yamlbyte_char_t)'#')
|
49
|
+
#define YAMLBYTE_WHOLE_SCALAR ((yamlbyte_char_t)'<')
|
50
|
+
#define YAMLBYTE_NOTICE ((yamlbyte_char_t)'!')
|
51
|
+
#define YAMLBYTE_SPAN ((yamlbyte_char_t)')')
|
52
|
+
#define YAMLBYTE_ALLOC ((yamlbyte_char_t)'@')
|
53
|
+
|
54
|
+
/* second level style bytecodes, ie "s>" */
|
55
|
+
#define YAMLBYTE_FLOW ((yamlbyte_char_t)'>')
|
56
|
+
#define YAMLBYTE_LITERAL ((yamlbyte_char_t)'|')
|
57
|
+
#define YAMLBYTE_BLOCK ((yamlbyte_char_t)'b')
|
58
|
+
#define YAMLBYTE_PLAIN ((yamlbyte_char_t)'p')
|
59
|
+
#define YAMLBYTE_INLINE_MAPPING ((yamlbyte_char_t)'{')
|
60
|
+
#define YAMLBYTE_INLINE_SEQUENCE ((yamlbyte_char_t)'[')
|
61
|
+
#define YAMLBYTE_SINGLE_QUOTED ((yamlbyte_char_t)39)
|
62
|
+
#define YAMLBYTE_DOUBLE_QUOTED ((yamlbyte_char_t)'"')
|
63
|
+
|
64
|
+
/*
|
65
|
+
* The "C" API has two variants, one based on instructions,
|
66
|
+
* with events delivered via pointers; and the other one
|
67
|
+
* is character based where one or more instructions are
|
68
|
+
* serialized into a buffer.
|
69
|
+
*
|
70
|
+
* Note: In the instruction based API, WHOLE_SCALAR does
|
71
|
+
* not have the '<here' marshalling stuff.
|
72
|
+
*/
|
73
|
+
|
74
|
+
typedef void * yamlbyte_consumer_t;
|
75
|
+
typedef void * yamlbyte_producer_t;
|
76
|
+
|
77
|
+
/* push and pull APIs need a way to communicate results */
|
78
|
+
typedef enum {
|
79
|
+
YAMLBYTE_OK = 0, /* proceed */
|
80
|
+
YAMLBYTE_E_MEMORY = 'M', /* could not allocate memory */
|
81
|
+
YAMLBYTE_E_READ = 'R', /* input stream read error */
|
82
|
+
YAMLBYTE_E_WRITE = 'W', /* output stream write error */
|
83
|
+
YAMLBYTE_E_OTHER = '?', /* some other error condition */
|
84
|
+
YAMLBYTE_E_PARSE = 'P', /* parse error, check bytecodes */
|
85
|
+
} yamlbyte_result_t;
|
86
|
+
|
87
|
+
typedef const yamlbyte_char_t *yamlbyte_buff_t;
|
88
|
+
|
89
|
+
/*
|
90
|
+
* The "Instruction" API
|
91
|
+
*/
|
92
|
+
|
93
|
+
typedef struct yaml_instruction {
|
94
|
+
yamlbyte_char_t bytecode;
|
95
|
+
yamlbyte_buff_t start;
|
96
|
+
yamlbyte_buff_t finish; /* open range, *finish is _not_ part */
|
97
|
+
} *yamlbyte_inst_t;
|
98
|
+
|
99
|
+
/* producer pushes the instruction with one bytecode event to the
|
100
|
+
* consumer; if the consumer's result is not YAMLBYTE_OK, then
|
101
|
+
* the producer should stop */
|
102
|
+
typedef
|
103
|
+
yamlbyte_result_t
|
104
|
+
(*yamlbyte_push_t)(
|
105
|
+
yamlbyte_consumer_t self,
|
106
|
+
yamlbyte_inst_t inst
|
107
|
+
);
|
108
|
+
|
109
|
+
/* consumer pulls a bytecode instruction from the producer; in this
|
110
|
+
* case the instruction (and is buffer) are owned by the producer and
|
111
|
+
* will remain valid till the pull function is called once again;
|
112
|
+
* if the instruction is NULL, then there are no more results; and
|
113
|
+
* it is important to call the pull function till it returns NULL so
|
114
|
+
* that the producer can clean up its memory allocations */
|
115
|
+
typedef
|
116
|
+
yamlbyte_result_t
|
117
|
+
(*yamlbyte_pull_t)(
|
118
|
+
yamlbyte_producer_t self,
|
119
|
+
yamlbyte_inst_t *inst /* to be filled in by the producer */
|
120
|
+
);
|
121
|
+
|
122
|
+
/*
|
123
|
+
* Buffer based API
|
124
|
+
*/
|
125
|
+
|
126
|
+
/* producer pushes a null terminated buffer filled with one or more
|
127
|
+
* bytecode events to the consumer; if the consumer's result is not
|
128
|
+
* YAMLBYTE_OK, then the producer should stop */
|
129
|
+
typedef
|
130
|
+
yamlbyte_result_t
|
131
|
+
(*yamlbyte_pushbuff_t)(
|
132
|
+
yamlbyte_consumer_t self,
|
133
|
+
yamlbyte_buff_t buff
|
134
|
+
);
|
135
|
+
|
136
|
+
/* consumer pulls bytecode events from the producer; in this case
|
137
|
+
* the buffer is owned by the producer, and will remain valid till
|
138
|
+
* the pull function is called once again; if the buffer pointer
|
139
|
+
* is set to NULL, then there are no more results; it is important
|
140
|
+
* to call the pull function till it returns NULL so that the
|
141
|
+
* producer can clean up its memory allocations */
|
142
|
+
typedef
|
143
|
+
yamlbyte_result_t
|
144
|
+
(*yamlbyte_pullbuff_t)(
|
145
|
+
yamlbyte_producer_t self,
|
146
|
+
yamlbyte_buff_t *buff /* to be filled in by the producer */
|
147
|
+
);
|
148
|
+
|
149
|
+
/* convert a pull interface to a push interface; the reverse process
|
150
|
+
* requires threads and thus is language dependent */
|
151
|
+
#define YAMLBYTE_PULL2PUSH(pull,producer,push,consumer,result) \
|
152
|
+
do { \
|
153
|
+
yamlbyte_pullbuff_t _pull = (pull); \
|
154
|
+
yamlbyte_pushbuff_t _push = (push); \
|
155
|
+
yamlbyte_result_t _result = YAMLBYTE_OK; \
|
156
|
+
yamlbyte_producer_t _producer = (producer); \
|
157
|
+
yamlbyte_consumer_t _consumer = (consumer); \
|
158
|
+
while(1) { \
|
159
|
+
yamlbyte_buff_t buff = NULL; \
|
160
|
+
_result = _pull(_producer,&buff); \
|
161
|
+
if(YAMLBYTE_OK != result || NULL == buff) \
|
162
|
+
break; \
|
163
|
+
_result = _push(_consumer,buff); \
|
164
|
+
if(YAMLBYTE_OK != result) \
|
165
|
+
break; \
|
166
|
+
} \
|
167
|
+
(result) = _result; \
|
168
|
+
} while(0)
|
169
|
+
|
170
|
+
#endif
|
@@ -0,0 +1 @@
|
|
1
|
+
timestamp for config.h
|
@@ -0,0 +1,141 @@
|
|
1
|
+
//
|
2
|
+
// Basic.c
|
3
|
+
//
|
4
|
+
// $Author: why $
|
5
|
+
// $Date: 2004/05/15 02:31:52 $
|
6
|
+
//
|
7
|
+
// Copyright (C) 2003 why the lucky stiff
|
8
|
+
//
|
9
|
+
|
10
|
+
#include "syck.h"
|
11
|
+
#include "CuTest.h"
|
12
|
+
|
13
|
+
//
|
14
|
+
// Test allocating a single node of kind 'str'.
|
15
|
+
//
|
16
|
+
void
|
17
|
+
TestSyckNodeAlloc( CuTest *tc )
|
18
|
+
{
|
19
|
+
SyckNode* n;
|
20
|
+
|
21
|
+
n = syck_new_str( "YAML", scalar_plain );
|
22
|
+
|
23
|
+
CuAssert( tc, "Allocated 'str' node reporting as 'seq'.", n->kind != syck_seq_kind );
|
24
|
+
CuAssert( tc, "Allocated 'str' node reporting as 'map'.", n->kind != syck_map_kind );
|
25
|
+
CuAssert( tc, "Allocated 'str' not reporting as 'str'.", n->kind == syck_str_kind );
|
26
|
+
CuAssertStrEquals( tc, "YAML", syck_str_read( n ) );
|
27
|
+
|
28
|
+
syck_free_node( n );
|
29
|
+
}
|
30
|
+
|
31
|
+
//
|
32
|
+
// Test building a simple sequence
|
33
|
+
//
|
34
|
+
void
|
35
|
+
TestSyckSeqAlloc( CuTest *tc )
|
36
|
+
{
|
37
|
+
SyckNode *n;
|
38
|
+
SYMID id;
|
39
|
+
|
40
|
+
n = syck_new_seq( 1 );
|
41
|
+
for ( id = 11001; id < 23000; id += 24 )
|
42
|
+
{
|
43
|
+
syck_seq_add( n, id );
|
44
|
+
}
|
45
|
+
|
46
|
+
CuAssert( tc, "Invalid value at '0'", 1 == syck_seq_read( n, 0 ) );
|
47
|
+
CuAssert( tc, "Invalid value at '1'", 11001 == syck_seq_read( n, 1 ) );
|
48
|
+
CuAssert( tc, "Invalid value at '200'", 15801 == syck_seq_read( n, 201 ) );
|
49
|
+
|
50
|
+
syck_free_node( n );
|
51
|
+
}
|
52
|
+
|
53
|
+
//
|
54
|
+
// Test building a simple map
|
55
|
+
//
|
56
|
+
void
|
57
|
+
TestSyckMapAlloc( CuTest *tc )
|
58
|
+
{
|
59
|
+
SyckNode *n;
|
60
|
+
|
61
|
+
n = syck_new_map( 24556, 24557 );
|
62
|
+
syck_map_add( n, 24558, 24559 );
|
63
|
+
syck_map_add( n, 24658, 24659 );
|
64
|
+
syck_map_add( n, 24758, 24759 );
|
65
|
+
syck_map_add( n, 24858, 24859 );
|
66
|
+
syck_map_add( n, 24958, 24959 );
|
67
|
+
syck_map_add( n, 24058, 24059 );
|
68
|
+
syck_map_add( n, 24158, 24159 );
|
69
|
+
|
70
|
+
CuAssert( tc, "Invalid key at '0'.", 24556 == syck_map_read( n, map_key, 0 ) );
|
71
|
+
CuAssert( tc, "Invalid key at '1'.", 24558 == syck_map_read( n, map_key, 1 ) );
|
72
|
+
CuAssert( tc, "Invalid key at '2'.", 24658 == syck_map_read( n, map_key, 2 ) );
|
73
|
+
CuAssert( tc, "Invalid key at '3'.", 24758 == syck_map_read( n, map_key, 3 ) );
|
74
|
+
CuAssert( tc, "Invalid key at '4'.", 24858 == syck_map_read( n, map_key, 4 ) );
|
75
|
+
CuAssert( tc, "Invalid key at '5'.", 24958 == syck_map_read( n, map_key, 5 ) );
|
76
|
+
CuAssert( tc, "Invalid key at '6'.", 24058 == syck_map_read( n, map_key, 6 ) );
|
77
|
+
CuAssert( tc, "Invalid key at '7'.", 24158 == syck_map_read( n, map_key, 7 ) );
|
78
|
+
CuAssert( tc, "Invalid value at '0'", 24557 == syck_map_read( n, map_value, 0 ) );
|
79
|
+
CuAssert( tc, "Invalid value at '1'", 24559 == syck_map_read( n, map_value, 1 ) );
|
80
|
+
CuAssert( tc, "Invalid value at '2'", 24659 == syck_map_read( n, map_value, 2 ) );
|
81
|
+
CuAssert( tc, "Invalid value at '3'", 24759 == syck_map_read( n, map_value, 3 ) );
|
82
|
+
CuAssert( tc, "Invalid value at '4'", 24859 == syck_map_read( n, map_value, 4 ) );
|
83
|
+
CuAssert( tc, "Invalid value at '5'", 24959 == syck_map_read( n, map_value, 5 ) );
|
84
|
+
CuAssert( tc, "Invalid value at '6'", 24059 == syck_map_read( n, map_value, 6 ) );
|
85
|
+
CuAssert( tc, "Invalid value at '7'", 24159 == syck_map_read( n, map_value, 7 ) );
|
86
|
+
|
87
|
+
syck_free_node( n );
|
88
|
+
}
|
89
|
+
|
90
|
+
//
|
91
|
+
// Test building a simple map
|
92
|
+
//
|
93
|
+
void
|
94
|
+
TestSyckMapUpdate( CuTest *tc )
|
95
|
+
{
|
96
|
+
SyckNode *n1, *n2;
|
97
|
+
|
98
|
+
n1 = syck_new_map( 51116, 51117 );
|
99
|
+
syck_map_add( n1, 51118, 51119 );
|
100
|
+
n2 = syck_new_map( 51126, 51127 );
|
101
|
+
syck_map_add( n2, 51128, 51129 );
|
102
|
+
|
103
|
+
syck_map_update( n1, n2 );
|
104
|
+
CuAssert( tc, "Invalid key at '2'", 51126 == syck_map_read( n1, map_key, 2 ) );
|
105
|
+
CuAssert( tc, "Invalid key at '3'", 51128 == syck_map_read( n1, map_key, 3 ) );
|
106
|
+
CuAssert( tc, "Invalid value at '2'", 51127 == syck_map_read( n1, map_value, 2 ) );
|
107
|
+
CuAssert( tc, "Invalid value at '3'", 51129 == syck_map_read( n1, map_value, 3 ) );
|
108
|
+
|
109
|
+
syck_free_node( n2 );
|
110
|
+
syck_free_node( n1 );
|
111
|
+
}
|
112
|
+
|
113
|
+
CuSuite *
|
114
|
+
SyckGetSuite()
|
115
|
+
{
|
116
|
+
CuSuite *suite = CuSuiteNew();
|
117
|
+
SUITE_ADD_TEST( suite, TestSyckNodeAlloc );
|
118
|
+
SUITE_ADD_TEST( suite, TestSyckSeqAlloc );
|
119
|
+
SUITE_ADD_TEST( suite, TestSyckMapAlloc );
|
120
|
+
SUITE_ADD_TEST( suite, TestSyckMapUpdate );
|
121
|
+
return suite;
|
122
|
+
}
|
123
|
+
|
124
|
+
int main(void)
|
125
|
+
{
|
126
|
+
CuString *output = CuStringNew();
|
127
|
+
CuSuite* suite = SyckGetSuite();
|
128
|
+
int count;
|
129
|
+
|
130
|
+
CuSuiteRun(suite);
|
131
|
+
CuSuiteSummary(suite, output);
|
132
|
+
CuSuiteDetails(suite, output);
|
133
|
+
|
134
|
+
printf("%s\n", output->buffer);
|
135
|
+
count = suite->failCount;
|
136
|
+
|
137
|
+
CuStringFree( output );
|
138
|
+
CuSuiteFree( suite );
|
139
|
+
|
140
|
+
return count;
|
141
|
+
}
|