shell_tinyxml_read.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  1. ////////////////////////////////////////
  2. // shell_tinyxml_read.cpp
  3. //
  4. // This file implements the means to read an XML encoded file and populate the
  5. // CLI tree based on the contents.
  6. ////////////////////////////////////////
  7. extern "C" {
  8. #include "private.h"
  9. #include "lub/string.h"
  10. #include "lub/ctype.h"
  11. }
  12. /*lint +libh(tinyxml/tinyxml.h) Add this to the library file list */
  13. #include "tinyxml/tinyxml.h"
  14. #include <string.h>
  15. #include <assert.h>
  16. typedef void (PROCESS_FN) (clish_shell_t * instance,
  17. TiXmlElement * element, void *parent);
  18. // Define a control block for handling the decode of an XML file
  19. typedef struct clish_xml_cb_s clish_xml_cb_t;
  20. struct clish_xml_cb_s {
  21. const char *element;
  22. PROCESS_FN *handler;
  23. };
  24. // forward declare the handler functions
  25. static PROCESS_FN
  26. process_clish_module,
  27. process_startup,
  28. process_view,
  29. process_command,
  30. process_param,
  31. process_action,
  32. process_ptype,
  33. process_overview, process_detail, process_namespace, process_config;
  34. static clish_xml_cb_t xml_elements[] = {
  35. {"CLISH_MODULE", process_clish_module},
  36. {"STARTUP", process_startup},
  37. {"VIEW", process_view},
  38. {"COMMAND", process_command},
  39. {"PARAM", process_param},
  40. {"ACTION", process_action},
  41. {"PTYPE", process_ptype},
  42. {"OVERVIEW", process_overview},
  43. {"DETAIL", process_detail},
  44. {"NAMESPACE", process_namespace},
  45. {"CONFIG", process_config},
  46. {NULL, NULL}
  47. };
  48. ///////////////////////////////////////
  49. // This function reads an element from the XML stream and processes it.
  50. ///////////////////////////////////////
  51. static void process_node(clish_shell_t * shell, TiXmlNode * node, void *parent)
  52. {
  53. switch (node->Type()) {
  54. case TiXmlNode::DOCUMENT:
  55. break;
  56. case TiXmlNode::ELEMENT:
  57. clish_xml_cb_t * cb;
  58. for (cb = &xml_elements[0]; cb->element; cb++) {
  59. if (0 == strcmp(node->Value(), cb->element)) {
  60. TiXmlElement *element = (TiXmlElement *) node;
  61. #ifdef DEBUG
  62. fprintf(stderr, "NODE:");
  63. element->Print(stderr, 0);
  64. fprintf(stderr, "\n***\n");
  65. #endif
  66. // process the elements at this level
  67. cb->handler(shell, element, parent);
  68. break;
  69. }
  70. }
  71. break;
  72. case TiXmlNode::COMMENT:
  73. case TiXmlNode::TEXT:
  74. case TiXmlNode::DECLARATION:
  75. case TiXmlNode::TYPECOUNT:
  76. case TiXmlNode::UNKNOWN:
  77. default:
  78. break;
  79. }
  80. }
  81. ///////////////////////////////////////
  82. static void
  83. process_children(clish_shell_t * shell,
  84. TiXmlElement * element, void *parent = NULL)
  85. {
  86. for (TiXmlNode * node = element->FirstChild();
  87. NULL != node; node = element->IterateChildren(node)) {
  88. // Now deal with all the contained elements
  89. process_node(shell, node, parent);
  90. }
  91. }
  92. ///////////////////////////////////////
  93. static void
  94. process_clish_module(clish_shell_t * shell, TiXmlElement * element, void *)
  95. {
  96. // create the global view
  97. if (!shell->global)
  98. shell->global =
  99. clish_shell_find_create_view(shell, "global", "");
  100. process_children(shell, element, shell->global);
  101. }
  102. ///////////////////////////////////////
  103. static void process_view(clish_shell_t * shell, TiXmlElement * element, void *)
  104. {
  105. clish_view_t *view;
  106. const char *name = element->Attribute("name");
  107. const char *prompt = element->Attribute("prompt");
  108. const char *depth = element->Attribute("depth");
  109. const char *restore = element->Attribute("restore");
  110. // re-use a view if it already exists
  111. view = clish_shell_find_create_view(shell, name, prompt);
  112. if ((depth != NULL) && (*depth != '\0') && (lub_ctype_isdigit(*depth))) {
  113. unsigned res = atoi(depth);
  114. clish_view__set_depth(view, res);
  115. }
  116. if (restore) {
  117. if (!lub_string_nocasecmp(restore, "depth"))
  118. clish_view__set_restore(view, CLISH_RESTORE_DEPTH);
  119. else if (!lub_string_nocasecmp(restore, "view"))
  120. clish_view__set_restore(view, CLISH_RESTORE_VIEW);
  121. else
  122. clish_view__set_restore(view, CLISH_RESTORE_NONE);
  123. }
  124. process_children(shell, element, view);
  125. }
  126. ///////////////////////////////////////
  127. static void process_ptype(clish_shell_t * shell, TiXmlElement * element, void *)
  128. {
  129. clish_ptype_method_e method;
  130. clish_ptype_preprocess_e preprocess;
  131. clish_ptype_t *ptype;
  132. const char *name = element->Attribute("name");
  133. const char *help = element->Attribute("help");
  134. const char *pattern = element->Attribute("pattern");
  135. const char *method_name = element->Attribute("method");
  136. const char *preprocess_name = element->Attribute("preprocess");
  137. assert(name);
  138. assert(pattern);
  139. method = clish_ptype_method_resolve(method_name);
  140. preprocess = clish_ptype_preprocess_resolve(preprocess_name);
  141. ptype = clish_shell_find_create_ptype(shell,
  142. name, help, pattern, method, preprocess);
  143. assert(ptype);
  144. }
  145. ///////////////////////////////////////
  146. static void
  147. process_overview(clish_shell_t * shell, TiXmlElement * element, void *)
  148. {
  149. // read the following text element
  150. TiXmlNode *text = element->FirstChild();
  151. if (NULL != text) {
  152. assert(TiXmlNode::TEXT == text->Type());
  153. // set the overview text for this view
  154. assert(NULL == shell->overview);
  155. // store the overview
  156. shell->overview = lub_string_dup(text->Value());
  157. }
  158. }
  159. ////////////////////////////////////////
  160. static void
  161. process_command(clish_shell_t * shell, TiXmlElement * element, void *parent)
  162. {
  163. clish_view_t *v = (clish_view_t *) parent;
  164. clish_command_t *cmd = NULL;
  165. bool allowed = true;
  166. clish_command_t *old;
  167. char *alias_name = NULL;
  168. clish_view_t *alias_view = NULL;
  169. const char *access = element->Attribute("access");
  170. const char *name = element->Attribute("name");
  171. const char *help = element->Attribute("help");
  172. const char *view = element->Attribute("view");
  173. const char *viewid = element->Attribute("viewid");
  174. const char *escape_chars = element->Attribute("escape_chars");
  175. const char *args_name = element->Attribute("args");
  176. const char *args_help = element->Attribute("args_help");
  177. const char *lock = element->Attribute("lock");
  178. const char *interrupt = element->Attribute("interrupt");
  179. const char *ref = element->Attribute("ref");
  180. if (NULL != access) {
  181. allowed = false; // err on the side of caution
  182. if (shell->client_hooks->access_fn) {
  183. // get the client to authenticate
  184. allowed =
  185. shell->client_hooks->access_fn(shell,
  186. access) ? true :
  187. false;
  188. }
  189. }
  190. if (!allowed)
  191. return;
  192. old = clish_view_find_command(v, name, BOOL_FALSE);
  193. // check this command doesn't already exist
  194. if (old) {
  195. // flag the duplication then ignore further definition
  196. printf("DUPLICATE COMMAND: %s\n",
  197. clish_command__get_name(old));
  198. return;
  199. }
  200. assert(name);
  201. assert(help);
  202. /* Reference 'ref' field */
  203. if (ref) {
  204. char *saveptr;
  205. const char *delim = "@";
  206. char *view_name = NULL;
  207. char *cmd = NULL;
  208. char *str = lub_string_dup(ref);
  209. cmd = strtok_r(str, delim, &saveptr);
  210. if (!cmd) {
  211. printf("EMPTY REFERENCE COMMAND: %s\n", name);
  212. lub_string_free(str);
  213. return;
  214. }
  215. alias_name = lub_string_dup(cmd);
  216. view_name = strtok_r(NULL, delim, &saveptr);
  217. if (!view_name)
  218. alias_view = v;
  219. else
  220. alias_view = clish_shell_find_create_view(shell,
  221. view_name, NULL);
  222. lub_string_free(str);
  223. }
  224. /* create a command */
  225. cmd = clish_view_new_command(v, name, help);
  226. assert(cmd);
  227. clish_command__set_pview(cmd, v);
  228. if (NULL != escape_chars) {
  229. /* define some specialist escape characters */
  230. clish_command__set_escape_chars(cmd,
  231. escape_chars);
  232. }
  233. if (NULL != args_name) {
  234. /* define a "rest of line" argument */
  235. clish_param_t *param;
  236. clish_ptype_t *tmp = NULL;
  237. assert(NULL != args_help);
  238. tmp = clish_shell_find_create_ptype(shell,
  239. "internal_ARGS",
  240. "Arguments", "[^\\]+",
  241. CLISH_PTYPE_REGEXP,
  242. CLISH_PTYPE_NONE);
  243. assert(tmp);
  244. param =
  245. clish_param_new(args_name, args_help, tmp);
  246. clish_command__set_args(cmd, param);
  247. }
  248. // define the view which this command changes to
  249. if (NULL != view) {
  250. clish_view_t *next =
  251. clish_shell_find_create_view(shell, view,
  252. NULL);
  253. // reference the next view
  254. clish_command__set_view(cmd, next);
  255. }
  256. // define the view id which this command changes to
  257. if (NULL != viewid) {
  258. clish_command__set_viewid(cmd, viewid);
  259. }
  260. /* lock field */
  261. if (lock && (lub_string_nocasecmp(lock, "false") == 0))
  262. clish_command__set_lock(cmd, BOOL_FALSE);
  263. else
  264. clish_command__set_lock(cmd, BOOL_TRUE);
  265. /* interrupt field */
  266. if (interrupt && (lub_string_nocasecmp(interrupt, "true") == 0))
  267. clish_command__set_interrupt(cmd, BOOL_TRUE);
  268. else
  269. clish_command__set_interrupt(cmd, BOOL_FALSE);
  270. /* Set alias */
  271. if (alias_name) {
  272. clish_command__set_alias(cmd, alias_name);
  273. assert(alias_view);
  274. clish_command__set_alias_view(cmd, alias_view);
  275. lub_string_free(alias_name);
  276. }
  277. process_children(shell, element, cmd);
  278. }
  279. ///////////////////////////////////////
  280. static void
  281. process_startup(clish_shell_t * shell, TiXmlElement * element, void *parent)
  282. {
  283. clish_view_t *v = (clish_view_t *) parent;
  284. clish_command_t *cmd = NULL;
  285. const char *view = element->Attribute("view");
  286. const char *viewid = element->Attribute("viewid");
  287. const char *default_shebang = element->Attribute("default_shebang");
  288. assert(NULL == shell->startup);
  289. assert(view);
  290. /* create a command with NULL help */
  291. cmd = clish_view_new_command(v, "startup", NULL);
  292. clish_command__set_lock(cmd, BOOL_FALSE);
  293. // define the view which this command changes to
  294. clish_view_t *next = clish_shell_find_create_view(shell, view, NULL);
  295. // reference the next view
  296. clish_command__set_view(cmd, next);
  297. // define the view id which this command changes to
  298. if (NULL != viewid) {
  299. clish_command__set_viewid(cmd, viewid);
  300. }
  301. if (NULL != default_shebang)
  302. clish_shell__set_default_shebang(shell, default_shebang);
  303. // remember this command
  304. shell->startup = cmd;
  305. process_children(shell, element, cmd);
  306. }
  307. ///////////////////////////////////////
  308. static void
  309. process_param(clish_shell_t * shell, TiXmlElement * element, void *parent)
  310. {
  311. clish_command_t *cmd = NULL;
  312. clish_param_t *p_param = NULL;
  313. if (0 == lub_string_nocasecmp(element->Parent()->Value(), "PARAM"))
  314. p_param = (clish_param_t *) parent;
  315. else
  316. cmd = (clish_command_t *) parent;
  317. if ((NULL != cmd) || (NULL != p_param)) {
  318. assert((!cmd) || (cmd != shell->startup));
  319. const char *name = element->Attribute("name");
  320. const char *help = element->Attribute("help");
  321. const char *ptype = element->Attribute("ptype");
  322. const char *prefix = element->Attribute("prefix");
  323. const char *defval = element->Attribute("default");
  324. const char *mode = element->Attribute("mode");
  325. const char *optional = element->Attribute("optional");
  326. const char *value = element->Attribute("value");
  327. const char *hidden = element->Attribute("hidden");
  328. const char *test = element->Attribute("test");
  329. clish_param_t *param;
  330. clish_ptype_t *tmp = NULL;
  331. // create a command
  332. assert(name);
  333. assert(help);
  334. assert(ptype);
  335. if (ptype && *ptype) {
  336. tmp = clish_shell_find_create_ptype(shell, ptype,
  337. NULL, NULL,
  338. CLISH_PTYPE_REGEXP,
  339. CLISH_PTYPE_NONE);
  340. assert(tmp);
  341. }
  342. param = clish_param_new(name, help, tmp);
  343. /* If prefix is set clish will emulate old optional
  344. * command syntax over newer optional command mechanism.
  345. * It will create nested PARAM.
  346. */
  347. if (NULL != prefix) {
  348. const char *ptype_name = "__SUBCOMMAND";
  349. clish_param_t *opt_param = NULL;
  350. /* Create a ptype for prefix-named subcommand that
  351. * will contain the nested optional parameter. The
  352. * name of ptype is hardcoded. It's not good but
  353. * it's only the service ptype.
  354. */
  355. tmp = (clish_ptype_t *)lub_bintree_find(
  356. &shell->ptype_tree, ptype_name);
  357. if (!tmp)
  358. tmp = clish_shell_find_create_ptype(shell,
  359. ptype_name, "Option", "[^\\]+",
  360. CLISH_PTYPE_REGEXP, CLISH_PTYPE_NONE);
  361. assert(tmp);
  362. opt_param = clish_param_new(prefix, help, tmp);
  363. clish_param__set_mode(opt_param,
  364. CLISH_PARAM_SUBCOMMAND);
  365. clish_param__set_optional(opt_param, BOOL_TRUE);
  366. if (NULL != test)
  367. clish_param__set_test(opt_param, test);
  368. if (cmd)
  369. // add the parameter to the command
  370. clish_command_insert_param(cmd, opt_param);
  371. if (p_param)
  372. // add the parameter to the param
  373. clish_param_insert_param(p_param, opt_param);
  374. /* Unset cmd and set parent param to opt_param */
  375. cmd = NULL;
  376. p_param = opt_param;
  377. }
  378. if (NULL != defval) {
  379. clish_param__set_default(param, defval);
  380. }
  381. if (hidden && (lub_string_nocasecmp(hidden, "true") == 0))
  382. clish_param__set_hidden(param, BOOL_TRUE);
  383. else
  384. clish_param__set_hidden(param, BOOL_FALSE);
  385. if (NULL != mode) {
  386. if (!lub_string_nocasecmp(mode, "switch")) {
  387. clish_param__set_mode(param,
  388. CLISH_PARAM_SWITCH);
  389. /* Force hidden attribute */
  390. clish_param__set_hidden(param, BOOL_TRUE);
  391. } else if (!lub_string_nocasecmp(mode, "subcommand"))
  392. clish_param__set_mode(param,
  393. CLISH_PARAM_SUBCOMMAND);
  394. else
  395. clish_param__set_mode(param,
  396. CLISH_PARAM_COMMON);
  397. }
  398. if (optional && (lub_string_nocasecmp(optional, "true") == 0))
  399. clish_param__set_optional(param, BOOL_TRUE);
  400. else
  401. clish_param__set_optional(param, BOOL_FALSE);
  402. if (NULL != value) {
  403. clish_param__set_value(param, value);
  404. /* Force mode to subcommand */
  405. clish_param__set_mode(param,
  406. CLISH_PARAM_SUBCOMMAND);
  407. }
  408. if ((NULL != test) && (NULL == prefix))
  409. clish_param__set_test(param, test);
  410. if (cmd)
  411. // add the parameter to the command
  412. clish_command_insert_param(cmd, param);
  413. if (p_param)
  414. // add the parameter to the param
  415. clish_param_insert_param(p_param, param);
  416. process_children(shell, element, param);
  417. }
  418. }
  419. ////////////////////////////////////////
  420. static void
  421. process_action(clish_shell_t * shell, TiXmlElement * element, void *parent)
  422. {
  423. clish_command_t *cmd = (clish_command_t *) parent;
  424. if (NULL != cmd) {
  425. // read the following text element
  426. TiXmlNode *text = element->FirstChild();
  427. const char *builtin = element->Attribute("builtin");
  428. const char *shebang = element->Attribute("shebang");
  429. if (NULL != text) {
  430. assert(TiXmlNode::TEXT == text->Type());
  431. // store the action
  432. clish_command__set_action(cmd, text->Value());
  433. }
  434. if (NULL != builtin) {
  435. // store the action
  436. clish_command__set_builtin(cmd, builtin);
  437. }
  438. if (NULL != shebang)
  439. clish_command__set_shebang(cmd, shebang);
  440. }
  441. }
  442. ////////////////////////////////////////
  443. static void
  444. process_detail(clish_shell_t * shell, TiXmlElement * element, void *parent)
  445. {
  446. clish_command_t *cmd = (clish_command_t *) parent;
  447. // read the following text element
  448. TiXmlNode *text = element->FirstChild();
  449. if ((NULL != cmd) && (NULL != text)) {
  450. assert(TiXmlNode::TEXT == text->Type());
  451. // store the action
  452. clish_command__set_detail(cmd, text->Value());
  453. }
  454. }
  455. ///////////////////////////////////////
  456. static void
  457. process_namespace(clish_shell_t * shell, TiXmlElement * element, void *parent)
  458. {
  459. clish_view_t *v = (clish_view_t *) parent;
  460. clish_nspace_t *nspace = NULL;
  461. const char *view = element->Attribute("ref");
  462. const char *prefix = element->Attribute("prefix");
  463. const char *prefix_help = element->Attribute("prefix_help");
  464. const char *help = element->Attribute("help");
  465. const char *completion = element->Attribute("completion");
  466. const char *context_help = element->Attribute("context_help");
  467. const char *inherit = element->Attribute("inherit");
  468. assert(view);
  469. clish_view_t *ref_view =
  470. clish_shell_find_create_view(shell, view, NULL);
  471. assert(ref_view);
  472. nspace = clish_nspace_new(ref_view);
  473. assert(nspace);
  474. clish_view_insert_nspace(v, nspace);
  475. if (NULL != prefix) {
  476. clish_nspace__set_prefix(nspace, prefix);
  477. if (prefix_help)
  478. clish_nspace_create_prefix_cmd(nspace,
  479. "prefix",
  480. prefix_help);
  481. else
  482. clish_nspace_create_prefix_cmd(nspace,
  483. "prefix",
  484. "Prefix for the imported commands.");
  485. }
  486. if (help && (lub_string_nocasecmp(help, "true") == 0))
  487. clish_nspace__set_help(nspace, BOOL_TRUE);
  488. else
  489. clish_nspace__set_help(nspace, BOOL_FALSE);
  490. if (completion && (lub_string_nocasecmp(completion, "false") == 0))
  491. clish_nspace__set_completion(nspace, BOOL_FALSE);
  492. else
  493. clish_nspace__set_completion(nspace, BOOL_TRUE);
  494. if (context_help && (lub_string_nocasecmp(context_help, "true") == 0))
  495. clish_nspace__set_context_help(nspace, BOOL_TRUE);
  496. else
  497. clish_nspace__set_context_help(nspace, BOOL_FALSE);
  498. if (inherit && (lub_string_nocasecmp(inherit, "false") == 0))
  499. clish_nspace__set_inherit(nspace, BOOL_FALSE);
  500. else
  501. clish_nspace__set_inherit(nspace, BOOL_TRUE);
  502. }
  503. ////////////////////////////////////////
  504. static void
  505. process_config(clish_shell_t * shell, TiXmlElement * element, void *parent)
  506. {
  507. clish_command_t *cmd = (clish_command_t *) parent;
  508. if (NULL == cmd)
  509. return;
  510. // read the following text element
  511. const char *operation = element->Attribute("operation");
  512. const char *priority = element->Attribute("priority");
  513. const char *pattern = element->Attribute("pattern");
  514. const char *file = element->Attribute("file");
  515. const char *splitter = element->Attribute("splitter");
  516. const char *seq = element->Attribute("sequence");
  517. const char *unique = element->Attribute("unique");
  518. const char *cfg_depth = element->Attribute("depth");
  519. if (operation && !lub_string_nocasecmp(operation, "unset"))
  520. clish_command__set_cfg_op(cmd, CLISH_CONFIG_UNSET);
  521. else if (operation && !lub_string_nocasecmp(operation, "none"))
  522. clish_command__set_cfg_op(cmd, CLISH_CONFIG_NONE);
  523. else if (operation && !lub_string_nocasecmp(operation, "dump"))
  524. clish_command__set_cfg_op(cmd, CLISH_CONFIG_DUMP);
  525. else {
  526. clish_command__set_cfg_op(cmd, CLISH_CONFIG_SET);
  527. /* The priority if no clearly specified */
  528. clish_command__set_priority(cmd, 0x7f00);
  529. }
  530. if ((priority != NULL) && (*priority != '\0')) {
  531. long val = 0;
  532. char *endptr;
  533. unsigned short pri;
  534. val = strtol(priority, &endptr, 0);
  535. if (endptr == priority)
  536. pri = 0;
  537. else if (val > 0xffff)
  538. pri = 0xffff;
  539. else if (val < 0)
  540. pri = 0;
  541. else
  542. pri = (unsigned short)val;
  543. clish_command__set_priority(cmd, pri);
  544. }
  545. if (pattern != NULL)
  546. clish_command__set_pattern(cmd, pattern);
  547. else
  548. clish_command__set_pattern(cmd, "^${__cmd}");
  549. if (file != NULL)
  550. clish_command__set_file(cmd, file);
  551. if (splitter && (lub_string_nocasecmp(splitter, "false") == 0))
  552. clish_command__set_splitter(cmd, BOOL_FALSE);
  553. else
  554. clish_command__set_splitter(cmd, BOOL_TRUE);
  555. if (unique && (lub_string_nocasecmp(unique, "false") == 0))
  556. clish_command__set_unique(cmd, BOOL_FALSE);
  557. else
  558. clish_command__set_unique(cmd, BOOL_TRUE);
  559. if (seq != NULL)
  560. clish_command__set_seq(cmd, seq);
  561. else
  562. /* The entries without sequence cannot be non-unique */
  563. clish_command__set_unique(cmd, BOOL_TRUE);
  564. if (cfg_depth != NULL)
  565. clish_command__set_cfg_depth(cmd, cfg_depth);
  566. }
  567. ///////////////////////////////////////
  568. int clish_shell_xml_read(clish_shell_t * shell, const char *filename)
  569. {
  570. int ret = -1;
  571. TiXmlDocument doc;
  572. // keep the white space
  573. TiXmlBase::SetCondenseWhiteSpace(false);
  574. if (doc.LoadFile(filename)) {
  575. TiXmlNode *child = 0;
  576. while ((child = doc.IterateChildren(child))) {
  577. process_node(shell, child, NULL);
  578. }
  579. ret = 0;
  580. } else {
  581. printf("Unable to open %s\n", filename);
  582. }
  583. return ret;
  584. }
  585. ///////////////////////////////////////