You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

apic.go 22 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746
  1. //
  2. // Copyright (c) 2011-2019 Canonical Ltd
  3. // Copyright (c) 2006-2010 Kirill Simonov
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy of
  6. // this software and associated documentation files (the "Software"), to deal in
  7. // the Software without restriction, including without limitation the rights to
  8. // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  9. // of the Software, and to permit persons to whom the Software is furnished to do
  10. // so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in all
  13. // copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. // SOFTWARE.
  22. package yaml
  23. import (
  24. "io"
  25. )
  26. func yaml_insert_token(parser *yaml_parser_t, pos int, token *yaml_token_t) {
  27. //fmt.Println("yaml_insert_token", "pos:", pos, "typ:", token.typ, "head:", parser.tokens_head, "len:", len(parser.tokens))
  28. // Check if we can move the queue at the beginning of the buffer.
  29. if parser.tokens_head > 0 && len(parser.tokens) == cap(parser.tokens) {
  30. if parser.tokens_head != len(parser.tokens) {
  31. copy(parser.tokens, parser.tokens[parser.tokens_head:])
  32. }
  33. parser.tokens = parser.tokens[:len(parser.tokens)-parser.tokens_head]
  34. parser.tokens_head = 0
  35. }
  36. parser.tokens = append(parser.tokens, *token)
  37. if pos < 0 {
  38. return
  39. }
  40. copy(parser.tokens[parser.tokens_head+pos+1:], parser.tokens[parser.tokens_head+pos:])
  41. parser.tokens[parser.tokens_head+pos] = *token
  42. }
  43. // Create a new parser object.
  44. func yaml_parser_initialize(parser *yaml_parser_t) bool {
  45. *parser = yaml_parser_t{
  46. raw_buffer: make([]byte, 0, input_raw_buffer_size),
  47. buffer: make([]byte, 0, input_buffer_size),
  48. }
  49. return true
  50. }
  51. // Destroy a parser object.
  52. func yaml_parser_delete(parser *yaml_parser_t) {
  53. *parser = yaml_parser_t{}
  54. }
  55. // String read handler.
  56. func yaml_string_read_handler(parser *yaml_parser_t, buffer []byte) (n int, err error) {
  57. if parser.input_pos == len(parser.input) {
  58. return 0, io.EOF
  59. }
  60. n = copy(buffer, parser.input[parser.input_pos:])
  61. parser.input_pos += n
  62. return n, nil
  63. }
  64. // Reader read handler.
  65. func yaml_reader_read_handler(parser *yaml_parser_t, buffer []byte) (n int, err error) {
  66. return parser.input_reader.Read(buffer)
  67. }
  68. // Set a string input.
  69. func yaml_parser_set_input_string(parser *yaml_parser_t, input []byte) {
  70. if parser.read_handler != nil {
  71. panic("must set the input source only once")
  72. }
  73. parser.read_handler = yaml_string_read_handler
  74. parser.input = input
  75. parser.input_pos = 0
  76. }
  77. // Set a file input.
  78. func yaml_parser_set_input_reader(parser *yaml_parser_t, r io.Reader) {
  79. if parser.read_handler != nil {
  80. panic("must set the input source only once")
  81. }
  82. parser.read_handler = yaml_reader_read_handler
  83. parser.input_reader = r
  84. }
  85. // Set the source encoding.
  86. func yaml_parser_set_encoding(parser *yaml_parser_t, encoding yaml_encoding_t) {
  87. if parser.encoding != yaml_ANY_ENCODING {
  88. panic("must set the encoding only once")
  89. }
  90. parser.encoding = encoding
  91. }
  92. // Create a new emitter object.
  93. func yaml_emitter_initialize(emitter *yaml_emitter_t) {
  94. *emitter = yaml_emitter_t{
  95. buffer: make([]byte, output_buffer_size),
  96. raw_buffer: make([]byte, 0, output_raw_buffer_size),
  97. states: make([]yaml_emitter_state_t, 0, initial_stack_size),
  98. events: make([]yaml_event_t, 0, initial_queue_size),
  99. }
  100. }
  101. // Destroy an emitter object.
  102. func yaml_emitter_delete(emitter *yaml_emitter_t) {
  103. *emitter = yaml_emitter_t{}
  104. }
  105. // String write handler.
  106. func yaml_string_write_handler(emitter *yaml_emitter_t, buffer []byte) error {
  107. *emitter.output_buffer = append(*emitter.output_buffer, buffer...)
  108. return nil
  109. }
  110. // yaml_writer_write_handler uses emitter.output_writer to write the
  111. // emitted text.
  112. func yaml_writer_write_handler(emitter *yaml_emitter_t, buffer []byte) error {
  113. _, err := emitter.output_writer.Write(buffer)
  114. return err
  115. }
  116. // Set a string output.
  117. func yaml_emitter_set_output_string(emitter *yaml_emitter_t, output_buffer *[]byte) {
  118. if emitter.write_handler != nil {
  119. panic("must set the output target only once")
  120. }
  121. emitter.write_handler = yaml_string_write_handler
  122. emitter.output_buffer = output_buffer
  123. }
  124. // Set a file output.
  125. func yaml_emitter_set_output_writer(emitter *yaml_emitter_t, w io.Writer) {
  126. if emitter.write_handler != nil {
  127. panic("must set the output target only once")
  128. }
  129. emitter.write_handler = yaml_writer_write_handler
  130. emitter.output_writer = w
  131. }
  132. // Set the output encoding.
  133. func yaml_emitter_set_encoding(emitter *yaml_emitter_t, encoding yaml_encoding_t) {
  134. if emitter.encoding != yaml_ANY_ENCODING {
  135. panic("must set the output encoding only once")
  136. }
  137. emitter.encoding = encoding
  138. }
  139. // Set the canonical output style.
  140. func yaml_emitter_set_canonical(emitter *yaml_emitter_t, canonical bool) {
  141. emitter.canonical = canonical
  142. }
  143. // Set the indentation increment.
  144. func yaml_emitter_set_indent(emitter *yaml_emitter_t, indent int) {
  145. if indent < 2 || indent > 9 {
  146. indent = 2
  147. }
  148. emitter.best_indent = indent
  149. }
  150. // Set the preferred line width.
  151. func yaml_emitter_set_width(emitter *yaml_emitter_t, width int) {
  152. if width < 0 {
  153. width = -1
  154. }
  155. emitter.best_width = width
  156. }
  157. // Set if unescaped non-ASCII characters are allowed.
  158. func yaml_emitter_set_unicode(emitter *yaml_emitter_t, unicode bool) {
  159. emitter.unicode = unicode
  160. }
  161. // Set the preferred line break character.
  162. func yaml_emitter_set_break(emitter *yaml_emitter_t, line_break yaml_break_t) {
  163. emitter.line_break = line_break
  164. }
  165. ///*
  166. // * Destroy a token object.
  167. // */
  168. //
  169. //YAML_DECLARE(void)
  170. //yaml_token_delete(yaml_token_t *token)
  171. //{
  172. // assert(token); // Non-NULL token object expected.
  173. //
  174. // switch (token.type)
  175. // {
  176. // case YAML_TAG_DIRECTIVE_TOKEN:
  177. // yaml_free(token.data.tag_directive.handle);
  178. // yaml_free(token.data.tag_directive.prefix);
  179. // break;
  180. //
  181. // case YAML_ALIAS_TOKEN:
  182. // yaml_free(token.data.alias.value);
  183. // break;
  184. //
  185. // case YAML_ANCHOR_TOKEN:
  186. // yaml_free(token.data.anchor.value);
  187. // break;
  188. //
  189. // case YAML_TAG_TOKEN:
  190. // yaml_free(token.data.tag.handle);
  191. // yaml_free(token.data.tag.suffix);
  192. // break;
  193. //
  194. // case YAML_SCALAR_TOKEN:
  195. // yaml_free(token.data.scalar.value);
  196. // break;
  197. //
  198. // default:
  199. // break;
  200. // }
  201. //
  202. // memset(token, 0, sizeof(yaml_token_t));
  203. //}
  204. //
  205. ///*
  206. // * Check if a string is a valid UTF-8 sequence.
  207. // *
  208. // * Check 'reader.c' for more details on UTF-8 encoding.
  209. // */
  210. //
  211. //static int
  212. //yaml_check_utf8(yaml_char_t *start, size_t length)
  213. //{
  214. // yaml_char_t *end = start+length;
  215. // yaml_char_t *pointer = start;
  216. //
  217. // while (pointer < end) {
  218. // unsigned char octet;
  219. // unsigned int width;
  220. // unsigned int value;
  221. // size_t k;
  222. //
  223. // octet = pointer[0];
  224. // width = (octet & 0x80) == 0x00 ? 1 :
  225. // (octet & 0xE0) == 0xC0 ? 2 :
  226. // (octet & 0xF0) == 0xE0 ? 3 :
  227. // (octet & 0xF8) == 0xF0 ? 4 : 0;
  228. // value = (octet & 0x80) == 0x00 ? octet & 0x7F :
  229. // (octet & 0xE0) == 0xC0 ? octet & 0x1F :
  230. // (octet & 0xF0) == 0xE0 ? octet & 0x0F :
  231. // (octet & 0xF8) == 0xF0 ? octet & 0x07 : 0;
  232. // if (!width) return 0;
  233. // if (pointer+width > end) return 0;
  234. // for (k = 1; k < width; k ++) {
  235. // octet = pointer[k];
  236. // if ((octet & 0xC0) != 0x80) return 0;
  237. // value = (value << 6) + (octet & 0x3F);
  238. // }
  239. // if (!((width == 1) ||
  240. // (width == 2 && value >= 0x80) ||
  241. // (width == 3 && value >= 0x800) ||
  242. // (width == 4 && value >= 0x10000))) return 0;
  243. //
  244. // pointer += width;
  245. // }
  246. //
  247. // return 1;
  248. //}
  249. //
  250. // Create STREAM-START.
  251. func yaml_stream_start_event_initialize(event *yaml_event_t, encoding yaml_encoding_t) {
  252. *event = yaml_event_t{
  253. typ: yaml_STREAM_START_EVENT,
  254. encoding: encoding,
  255. }
  256. }
  257. // Create STREAM-END.
  258. func yaml_stream_end_event_initialize(event *yaml_event_t) {
  259. *event = yaml_event_t{
  260. typ: yaml_STREAM_END_EVENT,
  261. }
  262. }
  263. // Create DOCUMENT-START.
  264. func yaml_document_start_event_initialize(
  265. event *yaml_event_t,
  266. version_directive *yaml_version_directive_t,
  267. tag_directives []yaml_tag_directive_t,
  268. implicit bool,
  269. ) {
  270. *event = yaml_event_t{
  271. typ: yaml_DOCUMENT_START_EVENT,
  272. version_directive: version_directive,
  273. tag_directives: tag_directives,
  274. implicit: implicit,
  275. }
  276. }
  277. // Create DOCUMENT-END.
  278. func yaml_document_end_event_initialize(event *yaml_event_t, implicit bool) {
  279. *event = yaml_event_t{
  280. typ: yaml_DOCUMENT_END_EVENT,
  281. implicit: implicit,
  282. }
  283. }
  284. // Create ALIAS.
  285. func yaml_alias_event_initialize(event *yaml_event_t, anchor []byte) bool {
  286. *event = yaml_event_t{
  287. typ: yaml_ALIAS_EVENT,
  288. anchor: anchor,
  289. }
  290. return true
  291. }
  292. // Create SCALAR.
  293. func yaml_scalar_event_initialize(event *yaml_event_t, anchor, tag, value []byte, plain_implicit, quoted_implicit bool, style yaml_scalar_style_t) bool {
  294. *event = yaml_event_t{
  295. typ: yaml_SCALAR_EVENT,
  296. anchor: anchor,
  297. tag: tag,
  298. value: value,
  299. implicit: plain_implicit,
  300. quoted_implicit: quoted_implicit,
  301. style: yaml_style_t(style),
  302. }
  303. return true
  304. }
  305. // Create SEQUENCE-START.
  306. func yaml_sequence_start_event_initialize(event *yaml_event_t, anchor, tag []byte, implicit bool, style yaml_sequence_style_t) bool {
  307. *event = yaml_event_t{
  308. typ: yaml_SEQUENCE_START_EVENT,
  309. anchor: anchor,
  310. tag: tag,
  311. implicit: implicit,
  312. style: yaml_style_t(style),
  313. }
  314. return true
  315. }
  316. // Create SEQUENCE-END.
  317. func yaml_sequence_end_event_initialize(event *yaml_event_t) bool {
  318. *event = yaml_event_t{
  319. typ: yaml_SEQUENCE_END_EVENT,
  320. }
  321. return true
  322. }
  323. // Create MAPPING-START.
  324. func yaml_mapping_start_event_initialize(event *yaml_event_t, anchor, tag []byte, implicit bool, style yaml_mapping_style_t) {
  325. *event = yaml_event_t{
  326. typ: yaml_MAPPING_START_EVENT,
  327. anchor: anchor,
  328. tag: tag,
  329. implicit: implicit,
  330. style: yaml_style_t(style),
  331. }
  332. }
  333. // Create MAPPING-END.
  334. func yaml_mapping_end_event_initialize(event *yaml_event_t) {
  335. *event = yaml_event_t{
  336. typ: yaml_MAPPING_END_EVENT,
  337. }
  338. }
  339. // Destroy an event object.
  340. func yaml_event_delete(event *yaml_event_t) {
  341. *event = yaml_event_t{}
  342. }
  343. ///*
  344. // * Create a document object.
  345. // */
  346. //
  347. //YAML_DECLARE(int)
  348. //yaml_document_initialize(document *yaml_document_t,
  349. // version_directive *yaml_version_directive_t,
  350. // tag_directives_start *yaml_tag_directive_t,
  351. // tag_directives_end *yaml_tag_directive_t,
  352. // start_implicit int, end_implicit int)
  353. //{
  354. // struct {
  355. // error yaml_error_type_t
  356. // } context
  357. // struct {
  358. // start *yaml_node_t
  359. // end *yaml_node_t
  360. // top *yaml_node_t
  361. // } nodes = { NULL, NULL, NULL }
  362. // version_directive_copy *yaml_version_directive_t = NULL
  363. // struct {
  364. // start *yaml_tag_directive_t
  365. // end *yaml_tag_directive_t
  366. // top *yaml_tag_directive_t
  367. // } tag_directives_copy = { NULL, NULL, NULL }
  368. // value yaml_tag_directive_t = { NULL, NULL }
  369. // mark yaml_mark_t = { 0, 0, 0 }
  370. //
  371. // assert(document) // Non-NULL document object is expected.
  372. // assert((tag_directives_start && tag_directives_end) ||
  373. // (tag_directives_start == tag_directives_end))
  374. // // Valid tag directives are expected.
  375. //
  376. // if (!STACK_INIT(&context, nodes, INITIAL_STACK_SIZE)) goto error
  377. //
  378. // if (version_directive) {
  379. // version_directive_copy = yaml_malloc(sizeof(yaml_version_directive_t))
  380. // if (!version_directive_copy) goto error
  381. // version_directive_copy.major = version_directive.major
  382. // version_directive_copy.minor = version_directive.minor
  383. // }
  384. //
  385. // if (tag_directives_start != tag_directives_end) {
  386. // tag_directive *yaml_tag_directive_t
  387. // if (!STACK_INIT(&context, tag_directives_copy, INITIAL_STACK_SIZE))
  388. // goto error
  389. // for (tag_directive = tag_directives_start
  390. // tag_directive != tag_directives_end; tag_directive ++) {
  391. // assert(tag_directive.handle)
  392. // assert(tag_directive.prefix)
  393. // if (!yaml_check_utf8(tag_directive.handle,
  394. // strlen((char *)tag_directive.handle)))
  395. // goto error
  396. // if (!yaml_check_utf8(tag_directive.prefix,
  397. // strlen((char *)tag_directive.prefix)))
  398. // goto error
  399. // value.handle = yaml_strdup(tag_directive.handle)
  400. // value.prefix = yaml_strdup(tag_directive.prefix)
  401. // if (!value.handle || !value.prefix) goto error
  402. // if (!PUSH(&context, tag_directives_copy, value))
  403. // goto error
  404. // value.handle = NULL
  405. // value.prefix = NULL
  406. // }
  407. // }
  408. //
  409. // DOCUMENT_INIT(*document, nodes.start, nodes.end, version_directive_copy,
  410. // tag_directives_copy.start, tag_directives_copy.top,
  411. // start_implicit, end_implicit, mark, mark)
  412. //
  413. // return 1
  414. //
  415. //error:
  416. // STACK_DEL(&context, nodes)
  417. // yaml_free(version_directive_copy)
  418. // while (!STACK_EMPTY(&context, tag_directives_copy)) {
  419. // value yaml_tag_directive_t = POP(&context, tag_directives_copy)
  420. // yaml_free(value.handle)
  421. // yaml_free(value.prefix)
  422. // }
  423. // STACK_DEL(&context, tag_directives_copy)
  424. // yaml_free(value.handle)
  425. // yaml_free(value.prefix)
  426. //
  427. // return 0
  428. //}
  429. //
  430. ///*
  431. // * Destroy a document object.
  432. // */
  433. //
  434. //YAML_DECLARE(void)
  435. //yaml_document_delete(document *yaml_document_t)
  436. //{
  437. // struct {
  438. // error yaml_error_type_t
  439. // } context
  440. // tag_directive *yaml_tag_directive_t
  441. //
  442. // context.error = YAML_NO_ERROR // Eliminate a compiler warning.
  443. //
  444. // assert(document) // Non-NULL document object is expected.
  445. //
  446. // while (!STACK_EMPTY(&context, document.nodes)) {
  447. // node yaml_node_t = POP(&context, document.nodes)
  448. // yaml_free(node.tag)
  449. // switch (node.type) {
  450. // case YAML_SCALAR_NODE:
  451. // yaml_free(node.data.scalar.value)
  452. // break
  453. // case YAML_SEQUENCE_NODE:
  454. // STACK_DEL(&context, node.data.sequence.items)
  455. // break
  456. // case YAML_MAPPING_NODE:
  457. // STACK_DEL(&context, node.data.mapping.pairs)
  458. // break
  459. // default:
  460. // assert(0) // Should not happen.
  461. // }
  462. // }
  463. // STACK_DEL(&context, document.nodes)
  464. //
  465. // yaml_free(document.version_directive)
  466. // for (tag_directive = document.tag_directives.start
  467. // tag_directive != document.tag_directives.end
  468. // tag_directive++) {
  469. // yaml_free(tag_directive.handle)
  470. // yaml_free(tag_directive.prefix)
  471. // }
  472. // yaml_free(document.tag_directives.start)
  473. //
  474. // memset(document, 0, sizeof(yaml_document_t))
  475. //}
  476. //
  477. ///**
  478. // * Get a document node.
  479. // */
  480. //
  481. //YAML_DECLARE(yaml_node_t *)
  482. //yaml_document_get_node(document *yaml_document_t, index int)
  483. //{
  484. // assert(document) // Non-NULL document object is expected.
  485. //
  486. // if (index > 0 && document.nodes.start + index <= document.nodes.top) {
  487. // return document.nodes.start + index - 1
  488. // }
  489. // return NULL
  490. //}
  491. //
  492. ///**
  493. // * Get the root object.
  494. // */
  495. //
  496. //YAML_DECLARE(yaml_node_t *)
  497. //yaml_document_get_root_node(document *yaml_document_t)
  498. //{
  499. // assert(document) // Non-NULL document object is expected.
  500. //
  501. // if (document.nodes.top != document.nodes.start) {
  502. // return document.nodes.start
  503. // }
  504. // return NULL
  505. //}
  506. //
  507. ///*
  508. // * Add a scalar node to a document.
  509. // */
  510. //
  511. //YAML_DECLARE(int)
  512. //yaml_document_add_scalar(document *yaml_document_t,
  513. // tag *yaml_char_t, value *yaml_char_t, length int,
  514. // style yaml_scalar_style_t)
  515. //{
  516. // struct {
  517. // error yaml_error_type_t
  518. // } context
  519. // mark yaml_mark_t = { 0, 0, 0 }
  520. // tag_copy *yaml_char_t = NULL
  521. // value_copy *yaml_char_t = NULL
  522. // node yaml_node_t
  523. //
  524. // assert(document) // Non-NULL document object is expected.
  525. // assert(value) // Non-NULL value is expected.
  526. //
  527. // if (!tag) {
  528. // tag = (yaml_char_t *)YAML_DEFAULT_SCALAR_TAG
  529. // }
  530. //
  531. // if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error
  532. // tag_copy = yaml_strdup(tag)
  533. // if (!tag_copy) goto error
  534. //
  535. // if (length < 0) {
  536. // length = strlen((char *)value)
  537. // }
  538. //
  539. // if (!yaml_check_utf8(value, length)) goto error
  540. // value_copy = yaml_malloc(length+1)
  541. // if (!value_copy) goto error
  542. // memcpy(value_copy, value, length)
  543. // value_copy[length] = '\0'
  544. //
  545. // SCALAR_NODE_INIT(node, tag_copy, value_copy, length, style, mark, mark)
  546. // if (!PUSH(&context, document.nodes, node)) goto error
  547. //
  548. // return document.nodes.top - document.nodes.start
  549. //
  550. //error:
  551. // yaml_free(tag_copy)
  552. // yaml_free(value_copy)
  553. //
  554. // return 0
  555. //}
  556. //
  557. ///*
  558. // * Add a sequence node to a document.
  559. // */
  560. //
  561. //YAML_DECLARE(int)
  562. //yaml_document_add_sequence(document *yaml_document_t,
  563. // tag *yaml_char_t, style yaml_sequence_style_t)
  564. //{
  565. // struct {
  566. // error yaml_error_type_t
  567. // } context
  568. // mark yaml_mark_t = { 0, 0, 0 }
  569. // tag_copy *yaml_char_t = NULL
  570. // struct {
  571. // start *yaml_node_item_t
  572. // end *yaml_node_item_t
  573. // top *yaml_node_item_t
  574. // } items = { NULL, NULL, NULL }
  575. // node yaml_node_t
  576. //
  577. // assert(document) // Non-NULL document object is expected.
  578. //
  579. // if (!tag) {
  580. // tag = (yaml_char_t *)YAML_DEFAULT_SEQUENCE_TAG
  581. // }
  582. //
  583. // if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error
  584. // tag_copy = yaml_strdup(tag)
  585. // if (!tag_copy) goto error
  586. //
  587. // if (!STACK_INIT(&context, items, INITIAL_STACK_SIZE)) goto error
  588. //
  589. // SEQUENCE_NODE_INIT(node, tag_copy, items.start, items.end,
  590. // style, mark, mark)
  591. // if (!PUSH(&context, document.nodes, node)) goto error
  592. //
  593. // return document.nodes.top - document.nodes.start
  594. //
  595. //error:
  596. // STACK_DEL(&context, items)
  597. // yaml_free(tag_copy)
  598. //
  599. // return 0
  600. //}
  601. //
  602. ///*
  603. // * Add a mapping node to a document.
  604. // */
  605. //
  606. //YAML_DECLARE(int)
  607. //yaml_document_add_mapping(document *yaml_document_t,
  608. // tag *yaml_char_t, style yaml_mapping_style_t)
  609. //{
  610. // struct {
  611. // error yaml_error_type_t
  612. // } context
  613. // mark yaml_mark_t = { 0, 0, 0 }
  614. // tag_copy *yaml_char_t = NULL
  615. // struct {
  616. // start *yaml_node_pair_t
  617. // end *yaml_node_pair_t
  618. // top *yaml_node_pair_t
  619. // } pairs = { NULL, NULL, NULL }
  620. // node yaml_node_t
  621. //
  622. // assert(document) // Non-NULL document object is expected.
  623. //
  624. // if (!tag) {
  625. // tag = (yaml_char_t *)YAML_DEFAULT_MAPPING_TAG
  626. // }
  627. //
  628. // if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error
  629. // tag_copy = yaml_strdup(tag)
  630. // if (!tag_copy) goto error
  631. //
  632. // if (!STACK_INIT(&context, pairs, INITIAL_STACK_SIZE)) goto error
  633. //
  634. // MAPPING_NODE_INIT(node, tag_copy, pairs.start, pairs.end,
  635. // style, mark, mark)
  636. // if (!PUSH(&context, document.nodes, node)) goto error
  637. //
  638. // return document.nodes.top - document.nodes.start
  639. //
  640. //error:
  641. // STACK_DEL(&context, pairs)
  642. // yaml_free(tag_copy)
  643. //
  644. // return 0
  645. //}
  646. //
  647. ///*
  648. // * Append an item to a sequence node.
  649. // */
  650. //
  651. //YAML_DECLARE(int)
  652. //yaml_document_append_sequence_item(document *yaml_document_t,
  653. // sequence int, item int)
  654. //{
  655. // struct {
  656. // error yaml_error_type_t
  657. // } context
  658. //
  659. // assert(document) // Non-NULL document is required.
  660. // assert(sequence > 0
  661. // && document.nodes.start + sequence <= document.nodes.top)
  662. // // Valid sequence id is required.
  663. // assert(document.nodes.start[sequence-1].type == YAML_SEQUENCE_NODE)
  664. // // A sequence node is required.
  665. // assert(item > 0 && document.nodes.start + item <= document.nodes.top)
  666. // // Valid item id is required.
  667. //
  668. // if (!PUSH(&context,
  669. // document.nodes.start[sequence-1].data.sequence.items, item))
  670. // return 0
  671. //
  672. // return 1
  673. //}
  674. //
  675. ///*
  676. // * Append a pair of a key and a value to a mapping node.
  677. // */
  678. //
  679. //YAML_DECLARE(int)
  680. //yaml_document_append_mapping_pair(document *yaml_document_t,
  681. // mapping int, key int, value int)
  682. //{
  683. // struct {
  684. // error yaml_error_type_t
  685. // } context
  686. //
  687. // pair yaml_node_pair_t
  688. //
  689. // assert(document) // Non-NULL document is required.
  690. // assert(mapping > 0
  691. // && document.nodes.start + mapping <= document.nodes.top)
  692. // // Valid mapping id is required.
  693. // assert(document.nodes.start[mapping-1].type == YAML_MAPPING_NODE)
  694. // // A mapping node is required.
  695. // assert(key > 0 && document.nodes.start + key <= document.nodes.top)
  696. // // Valid key id is required.
  697. // assert(value > 0 && document.nodes.start + value <= document.nodes.top)
  698. // // Valid value id is required.
  699. //
  700. // pair.key = key
  701. // pair.value = value
  702. //
  703. // if (!PUSH(&context,
  704. // document.nodes.start[mapping-1].data.mapping.pairs, pair))
  705. // return 0
  706. //
  707. // return 1
  708. //}
  709. //
  710. //