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

apic.go 21KB

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