bxml.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. #include <stdlib.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4. #include "bxml.h"
  5. #include "ses.h"
  6. #define BXML_WS " \t\n\r"
  7. /* Strdup isn't ANSI C, just posix... :p so we need our own local version.*/
  8. static char * bxml_strdup(const char *str) {
  9. char * res = malloc(strlen(str) + 1);
  10. if(res) { strcpy(res, str); }
  11. return res;
  12. }
  13. /* Strdup isn't ANSI C, just posix... :p so we need our own local version.*/
  14. static char * bxml_strdup_size(const char *str, int size) {
  15. char * res = malloc(size + 1);
  16. if(res) {
  17. if (size < 0) {
  18. size = strlen(str);
  19. }
  20. strncpy(res, str, (size_t) size);
  21. res[size] = '\0';
  22. }
  23. return res;
  24. }
  25. /* Initializes a bxml attributes, sets no relationships! */
  26. BxmlAttribute *
  27. bxmlattribute_init_size(BxmlAttribute * me, char * name, int namesize, char * value, int valuesize) {
  28. if (!me) return NULL;
  29. me->name = bxml_strdup_size(name, namesize);
  30. if (!me->name) return NULL;
  31. me->value = bxml_strdup_size(value, valuesize);
  32. if (!me->value) {
  33. free(me->name);
  34. me->name = NULL;
  35. return NULL;
  36. }
  37. me->next = NULL;
  38. return me;
  39. }
  40. /* Initializes a bxml attributes, sets no relationships! */
  41. BxmlAttribute *
  42. bxmlattribute_init(BxmlAttribute * me, char * name, char * value) {
  43. return bxmlattribute_init_size(me, name, -1, value, -1);
  44. }
  45. /* Sets the value of an attribute. */
  46. BxmlAttribute * bxmlattribute_set_value_size(BxmlAttribute * me, char * value, int size) {
  47. if (!me) return NULL;
  48. free(me->value);
  49. me->value = bxml_strdup_size(value, size);
  50. if (!me->value) return NULL;
  51. return me;
  52. }
  53. BxmlAttribute * bxmlattribute_set_value(BxmlAttribute * me, char * value) {
  54. return bxmlattribute_set_value_size(me, value, -1);
  55. }
  56. /* Cleans up an attribute. Does nothing with linked attributes! */
  57. void bxmlattribute_done(BxmlAttribute * me) {
  58. if (!me) return;
  59. free(me->value);
  60. free(me->name);
  61. me->value = NULL;
  62. me->name = NULL;
  63. me->next = NULL;
  64. }
  65. /* Frees a bxmlattribute without doing anything to apotential next one. */
  66. void bxmlattribute_free_one(BxmlAttribute * me) {
  67. bxmlattribute_done(me);
  68. free(me);
  69. }
  70. /* Frees a linked list of bxml attributes */
  71. void bxmlattribute_free_list(BxmlAttribute * me) {
  72. BxmlAttribute * now, * aid;
  73. now = me;
  74. while (now) {
  75. aid = now->next;
  76. bxmlattribute_free_one(now);
  77. now = aid;
  78. }
  79. }
  80. /* Allocates a new bxmlattibute */
  81. BxmlAttribute * bxmlattribute_alloc(void) {
  82. return calloc(sizeof(BxmlAttribute), 1);
  83. }
  84. BxmlAttribute * bxmlattribute_new_size(char * name, int namesize, char * value, int valuesize) {
  85. return bxmlattribute_init_size(bxmlattribute_alloc(), name, namesize, value, valuesize);
  86. }
  87. BxmlAttribute * bxmlattribute_new(char * name, char * value) {
  88. return bxmlattribute_init(bxmlattribute_alloc(), name, value);
  89. }
  90. /* Appends or insterts an existing attribute to the list at me.
  91. * returns you on sucess or NULL on failure. */
  92. BxmlAttribute * bxmlattribute_insert(BxmlAttribute * me, BxmlAttribute * you) {
  93. BxmlAttribute * aid;
  94. if (!me) return NULL;
  95. if (!you) return NULL;
  96. aid = me->next;
  97. me->next = you;
  98. you->next = aid;
  99. return you;
  100. }
  101. /* Inserts a new attribute to the list after me. */
  102. BxmlAttribute *
  103. bxmlattribute_insert_new(BxmlAttribute * me, char * name, char * value) {
  104. return bxmlattribute_insert(me, bxmlattribute_new(name, value));
  105. }
  106. /* Inserts a new attribute to the list after me. */
  107. BxmlAttribute *
  108. bxmlattribute_insert_new_size(BxmlAttribute * me, char * name, int namesize, char * value, int valuesize) {
  109. return bxmlattribute_insert(me, bxmlattribute_new_size(name, namesize, value, valuesize));
  110. }
  111. /* Initializes a Bxml me. Does not set up any relationships nor
  112. * call strdup! */
  113. Bxml * bxml_init_all(Bxml * me, int kind, char * name, char * text) {
  114. if(!me) return NULL;
  115. me->parent = NULL;
  116. me->sibling = NULL;
  117. me->child = NULL;
  118. me->attributes = NULL;
  119. me->kind = kind;
  120. me->name = name;
  121. me->text = text;
  122. return me;
  123. }
  124. /* Initializes a bxml me based on it's kind. */
  125. Bxml * bxml_init_size_va(Bxml * me, int kind, int size, va_list args) {
  126. char * name = NULL;
  127. char * text = NULL;
  128. switch(kind) {
  129. case BXML_ROOT:
  130. return bxml_init_all(me, kind, NULL, NULL);
  131. case BXML_TAG:
  132. name = bxml_strdup_size(va_arg(args, char *), size);
  133. if (!name) return NULL;
  134. return bxml_init_all(me, kind, name, NULL);
  135. case BXML_TEXT:
  136. text = bxml_strdup_size(va_arg(args, char *), size);
  137. if (!text) return NULL;
  138. return bxml_init_all(me, kind, NULL, text);
  139. case BXML_COMMENT:
  140. text = bxml_strdup_size(va_arg(args, char *), size);
  141. if (!text) return NULL;
  142. return bxml_init_all(me, kind, NULL, text);
  143. default:
  144. return NULL;
  145. }
  146. }
  147. /* Initializes a bxml me based on it's kind. */
  148. Bxml * bxml_init_va(Bxml * me, int kind, va_list args) {
  149. return bxml_init_size_va(me, kind, -1, args);
  150. }
  151. /* Allocates a new Bxml node */
  152. Bxml * bxml_alloc() {
  153. return calloc(sizeof(Bxml), 1);
  154. }
  155. /* Allocates and initialzes a new Bxml node. */
  156. Bxml * bxml_new_size_va(int kind, int size, va_list args) {
  157. return bxml_init_size_va(bxml_alloc(), kind, size, args);
  158. }
  159. /* Allocates and initialzes a new Bxml node. */
  160. Bxml * bxml_new_va(int kind, va_list args) {
  161. return bxml_init_size_va(bxml_alloc(), kind, -1, args);
  162. }
  163. /** Appends text to the text of this tag */
  164. Bxml * bxml_append_buf(Bxml * me, char * buf, int bufsize) {
  165. if (!me->text) {
  166. me->text = bxml_strdup_size(buf, bufsize);
  167. if (!me->text) return NULL;
  168. } else {
  169. int oldsize = strlen(me->text);
  170. me->text = realloc(me->text, oldsize + bufsize + 1);
  171. strncpy(me->text + oldsize, buf, bufsize);
  172. me->text[oldsize+bufsize] = '\0';
  173. }
  174. return me;
  175. }
  176. /* Removes a child from parent. Does NOT free it, but returns it on success,
  177. * or NULL if no such child. Comparison is by address. */
  178. Bxml * bxml_remove_child(Bxml * parent, Bxml * child) {
  179. Bxml * index, * previous;
  180. /* First child as special case. */
  181. if (parent->child == child) {
  182. parent->child = parent->child->sibling;
  183. return child;
  184. }
  185. for (index = parent->child; index; index = index->sibling) {
  186. /* next up is the child... */
  187. if (index->sibling == child) {
  188. /* cut it from the linked list */
  189. index->sibling = index->sibling->sibling;
  190. return child;
  191. }
  192. }
  193. return NULL;
  194. }
  195. /* Merges two text tags and returns a newly allocated
  196. * test tag on success, or NULL on failure.
  197. */
  198. Bxml * bxml_merge_text(Bxml * text1, Bxml * text2) {
  199. Swis buffer;
  200. Bxml * result;
  201. if (!text1) return NULL;
  202. if (!text2) return NULL;
  203. if (text1->kind != BXML_TEXT) return NULL;
  204. if (text2->kind != BXML_TEXT) return NULL;
  205. if (!swis_init_cstr(&buffer, text1->text)) return NULL;
  206. if (!swis_append_cstr(&buffer, text2->text)) {
  207. swis_free(&buffer);
  208. return NULL;
  209. }
  210. result = bxml_new_size(BXML_TEXT, buffer.size, buffer.text);
  211. swis_free(&buffer);
  212. return result;
  213. }
  214. /* Merges two adjacent text tag, frees them and replaces them by the
  215. * merged tag.
  216. */
  217. Bxml * bxml_merge_adjacent_text(Bxml * text1, Bxml * text2) {
  218. Bxml * parent;
  219. Bxml * merged = bxml_merge_text(text1, text2);
  220. if (!merged) return NULL;
  221. parent = text1->parent;
  222. bxml_remove_child(parent, text1);
  223. bxml_free(text1);
  224. bxml_remove_child(parent, text2);
  225. bxml_free(text2);
  226. bxml_add_child(parent, merged);
  227. return merged;
  228. }
  229. /* Allocates and initialzes a new Bxml node. */
  230. Bxml * bxml_new(int kind, ...) {
  231. Bxml * result;
  232. va_list args;
  233. va_start(args, kind);
  234. result = bxml_new_va(kind, args);
  235. va_end(args);
  236. return result;
  237. }
  238. /* Allocates and initialzes a new Bxml node. */
  239. Bxml * bxml_new_size(int kind, int size, ...) {
  240. Bxml * result;
  241. va_list args;
  242. va_start(args, size);
  243. result = bxml_new_size_va(kind, size, args);
  244. va_end(args);
  245. return result;
  246. }
  247. /* Cleans up a Bxml node, freeing the children recursively. */
  248. Bxml * bxml_done(Bxml * me) {
  249. Bxml * aid = me->child;
  250. Bxml * next = NULL;
  251. while(aid) {
  252. next = aid->sibling; // get next, since aid will be destroyed.
  253. bxml_free(aid); // free first child
  254. aid = next; // move to next child.
  255. }
  256. bxmlattribute_free_list(me->attributes);
  257. free(me->name);
  258. free(me->text);
  259. return me;
  260. }
  261. /* Frees this node and cleans up its children recursively. returns NULL. */
  262. Bxml * bxml_free(Bxml * me) {
  263. if(!me) return NULL;
  264. bxml_done(me);
  265. free(me);
  266. return NULL;
  267. }
  268. /* Sets node siling to be the sibling node of this node, possibly inserting
  269. * between an existing sibling.
  270. * returns you if OK, NULL on error.
  271. **/
  272. Bxml * bxml_add_sibling(Bxml * me, Bxml * you) {
  273. Bxml * old_sibling;
  274. if(!me) return NULL;
  275. if(!you) return NULL;
  276. old_sibling = me->sibling;
  277. /* Ensure proper insertion. */
  278. you->sibling = old_sibling;
  279. me->sibling = you;
  280. return you;
  281. }
  282. /* Gets the last sibing of me, or NULL if no sibling. */
  283. Bxml * bxml_get_last_sibling(Bxml * me) {
  284. Bxml * aid;
  285. if (!me) return NULL;
  286. for (aid = me; aid->sibling ; aid = aid->sibling);
  287. return aid;
  288. }
  289. /* Adds a sibling to me, at the end of the sibling list. */
  290. Bxml * bxml_append_sibling(Bxml * me, Bxml * you) {
  291. Bxml * index;
  292. if (!me) return NULL;
  293. if (!you) return NULL;
  294. return bxml_add_sibling(bxml_get_last_sibling(me), you);
  295. }
  296. /* Returns the pos-th sibling of me */
  297. Bxml * bxml_get_sibling_at(Bxml * me, int pos) {
  298. int index = 0;
  299. Bxml * aid;
  300. if (!me) return NULL;
  301. for (aid = me; aid; aid = aid->sibling) {
  302. if (index == pos) return aid;
  303. index++;
  304. }
  305. return NULL;
  306. }
  307. /* Returns the pos-th child of me */
  308. Bxml * bxml_get_child_at(Bxml * me, int pos) {
  309. if (!me) return NULL;
  310. return bxml_get_sibling_at(me->child, pos);
  311. }
  312. /* Gets the last sibing of me, or NULL if no sibling. */
  313. Bxml * bxml_get_last_child(Bxml * me) {
  314. Bxml * aid;
  315. if (!me) return NULL;
  316. if (!me->child) return NULL;
  317. return bxml_get_last_sibling(me->child);
  318. }
  319. /* Adds attr as an attribute to the Bxml tag me.
  320. * Returns you if ok, NULL on error.
  321. */
  322. BxmlAttribute * bxml_add_attribute(Bxml * me, BxmlAttribute * you) {
  323. Bxml * oldnext;
  324. if (!me) return NULL;
  325. if (!you) return NULL;
  326. if (!me->last_attr) {
  327. me->attributes = you;
  328. me->last_attr = you;
  329. } else {
  330. bxmlattribute_insert(me->last_attr, you);
  331. }
  332. return you;
  333. }
  334. /** Makes a new attribute and adds it to me. */
  335. BxmlAttribute * bxml_new_attribute_size(Bxml * me, char * name, int namesize, char * value, int valuesize) {
  336. return bxml_add_attribute(me, bxmlattribute_new_size(name, namesize, value, valuesize));
  337. }
  338. /** Makes a new attribute and adds it to me. */
  339. BxmlAttribute * bxml_new_attribute(Bxml * me, char * name, char * value) {
  340. return bxml_add_attribute(me, bxmlattribute_new(name, value));
  341. }
  342. /** Gets the attribute of me with the given name, or NULL if no such attribute. */
  343. BxmlAttribute * bxml_get_attribute_pointer(Bxml * me, char * name) {
  344. BxmlAttribute * index;
  345. for(index = me->attributes; index ; index = index->next) {
  346. if (strcmp(name, index->name) == 0) {
  347. return index;
  348. }
  349. }
  350. return NULL;
  351. }
  352. /** Gets the value of the attribute of me with the given name, or NULL if no
  353. * such attribute. */
  354. char * bxml_get_attribute(Bxml * me, char * name) {
  355. BxmlAttribute * result;
  356. result = bxml_get_attribute_pointer(me, name);
  357. return result ? result->value : NULL;
  358. }
  359. /** Sets the attribute value of the given name. If the attribte already existed,
  360. * it will be overwritten, otherwise it will be made new. */
  361. BxmlAttribute * bxml_set_attribute(Bxml * me, char * name, char * value) {
  362. BxmlAttribute * attribute;
  363. attribute = bxml_get_attribute_pointer(me, name);
  364. if (attribute) {
  365. return bxmlattribute_set_value(attribute, value);
  366. }
  367. return bxml_new_attribute(me, name, value);
  368. }
  369. /* Adds child as a child node of the Bxml tag me.
  370. * Ensures that any siblings are connected correctly as well.
  371. * Returns child if OK, NULL on error.
  372. */
  373. Bxml * bxml_add_child(Bxml * me, Bxml * child) {
  374. if (!me) return NULL;
  375. if (!child) return NULL;
  376. child->parent = me;
  377. if (!me->child) {
  378. me->child = child;
  379. return child;
  380. } else {
  381. return bxml_append_sibling(me->child, child);
  382. }
  383. }
  384. Bxml * bxml_new_child_size_va(Bxml * me, int kind, int size, va_list args) {
  385. Bxml * child;
  386. child = bxml_new_size_va(kind, size, args);
  387. if (!bxml_add_child(me, child)) {
  388. bxml_free(child);
  389. return NULL;
  390. }
  391. return child;
  392. }
  393. Bxml * bxml_new_child_va(Bxml * me, int kind, va_list args) {
  394. return bxml_new_child_size_va(me, kind, -1, args);
  395. }
  396. /* Adds a new child initialized depending on kind.
  397. * Text nodes should pass the text of the node,
  398. * tags should pass the name of the tag.
  399. */
  400. Bxml * bxml_new_child_size(Bxml * me, int kind, int size, ...) {
  401. Bxml * result;
  402. va_list args;
  403. va_start(args, size);
  404. result = bxml_new_child_size_va(me, kind, size, args);
  405. va_end(args);
  406. return result;
  407. }
  408. /* Adds a new child initialized depending on kind.
  409. * Text nodes should pass the text of the node,
  410. * tags should pass the name of the tag.
  411. */
  412. Bxml * bxml_new_child(Bxml * me, int kind, ...) {
  413. Bxml * result;
  414. va_list args;
  415. va_start(args, kind);
  416. result = bxml_new_child_va(me, kind, args);
  417. va_end(args);
  418. return result;
  419. }
  420. /**
  421. * xml_print_element_names:
  422. * @a_node: the initial xml node to consider.
  423. *
  424. * Prints the names of the all the xml elements
  425. * that are siblings or children of a given xml node.
  426. */
  427. void bxml_print_element_names(Bxml * node) {
  428. Bxml * now = NULL;
  429. static int level = 0;
  430. for (now = node; now; now = now->sibling) {
  431. if (now->kind == BXML_TAG) {
  432. printf("node type: Element, %d, name: %s\n", level, now->name);
  433. } else {
  434. printf("node type: %d, %d, name: %s\n", node->kind, level, now->name);
  435. }
  436. level++;
  437. bxml_print_element_names(now->child);
  438. level--;
  439. }
  440. }
  441. /**
  442. * bxml_print_all_attributes: a debugging function to print all xml attributes
  443. */
  444. void bxml_print_all_attributes(Bxml * node) {
  445. BxmlAttribute * attr;
  446. printf("Node a%s attributes:", node->name);
  447. for(attr = node->attributes ; attr ; attr = attr->next) {
  448. printf(" %s=%s", attr->name, attr->value);
  449. }
  450. puts("");
  451. }
  452. int bxml_kind_is(Bxml * me, int kind) {
  453. if (!me) return 0;
  454. if (kind < 1) return !0;
  455. return (me->kind == kind);
  456. }
  457. int bxml_name_is(Bxml * me, char * name) {
  458. if (!name) return !0;
  459. if (!me) return 0;
  460. if (!me->name) return 0;
  461. return (strcmp(me->name, name) == 0);
  462. }
  463. int bxml_match_name_and_kind(Bxml * me, char * name, int kind) {
  464. return (bxml_kind_is(me, kind) && bxml_name_is(me, name));
  465. }
  466. /** Finds a sibling node. If name is not null
  467. or type is strictly positive, return matching nodes.
  468. Also searches node itself, so pass node->next if you don't want that.*/
  469. Bxml * bxml_find_next_kind(Bxml * node, const char * name, int kind) {
  470. Bxml * now;
  471. for (now = node; now; now = now->sibling) {
  472. if (bxml_match_name_and_kind(now, (char *)name, kind)) {
  473. return now;
  474. }
  475. }
  476. return NULL;
  477. }
  478. /** Shorthand for bxml_find_next_type(node, name, BXML_TAG */
  479. Bxml * bxml_find_next(Bxml * node, const char * name) {
  480. return bxml_find_next_kind(node, name, BXML_TAG);
  481. }
  482. /** Nonrecursively finds a BXML child node with the given name,
  483. * and kind including self. */
  484. Bxml * bxml_find_child_kind(Bxml * node, const char * name, int kind) {
  485. if (!node) return NULL;
  486. return bxml_find_next_kind(node->child, name, kind);
  487. }
  488. /** Nonrecursively finds a BXML child node with the given name, including self. */
  489. Bxml * bxml_find_child(Bxml * node, const char * name) {
  490. return bxml_find_child_kind(node, name, BXML_TAG);
  491. }
  492. /** Finds a child node with the given paths, pass null as last one */
  493. Bxml * bxml_find_child_deep_va(Bxml * node, va_list args) {
  494. const char * name = NULL;
  495. Bxml * res = NULL;
  496. Bxml * aid = node;
  497. for(name = va_arg(args, const char *); name && aid;
  498. name = va_arg(args, const char *)) {
  499. aid = bxml_find_child(aid, name);
  500. }
  501. res = aid;
  502. return res;
  503. }
  504. /** Finds a child node with the given paths, pass null as last one */
  505. Bxml * bxml_find_child_deep(Bxml * node, ...) {
  506. Bxml * result;
  507. va_list args;
  508. va_start(args, node);
  509. result = bxml_find_child_deep_va(node, args);
  510. va_end(args);
  511. return result;
  512. }
  513. /** Gets an integer property from the node and stores it into result,
  514. * returns result if ok, NULL if not a correct integer */
  515. long * bxml_get_attribute_long(Bxml * node, char * name, long * result) {
  516. long aid;
  517. char * prop = bxml_get_attribute(node, name);
  518. if (!prop) return false;
  519. errno = 0;
  520. aid = strtol(prop, NULL, 10);
  521. if (errno) { return NULL; }
  522. (*result) = aid;
  523. return result;
  524. }
  525. /** Gets an double property from the node and stores it into result,
  526. * returns result if ok, NULL if not a correct integer */
  527. double * bxml_get_attribute_double(Bxml * node, char * name, double * result) {
  528. double aid;
  529. char * prop = bxml_get_attribute(node, name);
  530. if (!prop) return false;
  531. errno = 0;
  532. aid = strtod(prop, NULL);
  533. if (errno) { return NULL; }
  534. (*result) = aid;
  535. return result;
  536. }
  537. /* Returns a reference to the first text node child of node */
  538. Bxml * bxml_get_text_tag_under(Bxml * node) {
  539. return bxml_find_child_kind(node, NULL, BXML_TEXT);
  540. }
  541. /** Returns a reference to the (first) text contents of an xml node.
  542. * this looks in the child node for the text.
  543. */
  544. char * bxml_get_text_under(Bxml * node) {
  545. Bxml * text_tag = bxml_get_text_tag_under(node);
  546. return text_tag->text;
  547. }
  548. /** Recursively outputs a debug rep of xml to file. */
  549. int bxml_show_to(Bxml * xml, FILE * out, int depth) {
  550. int index;
  551. for (index = 0; index < depth; index++) {
  552. fprintf(out, " ");
  553. }
  554. if (xml->kind == BXML_TAG) {
  555. fprintf(out, ">%s", xml->name);
  556. } else if (xml->kind == BXML_TEXT) {
  557. fprintf(out, ">#text: %s", xml->text);
  558. } else {
  559. fprintf(out, ">%s: %s", xml->name, xml->text);
  560. }
  561. if (xml->attributes) {
  562. BxmlAttribute * nattr = xml->attributes;
  563. fprintf(out, "(");
  564. while (nattr) {
  565. fprintf(out, " %s->%s", nattr->name, nattr->value);
  566. nattr = nattr->next;
  567. }
  568. fprintf(out, " )");
  569. }
  570. fprintf(out, "\n");
  571. if (xml->child) {
  572. bxml_show_to(xml->child, out, depth + 1);
  573. }
  574. if (xml->sibling) {
  575. bxml_show_to(xml->sibling, out, depth);
  576. }
  577. return depth;
  578. }