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

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