pline.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818
  1. /** @file pline.c
  2. */
  3. #include <stdlib.h>
  4. #include <stdint.h>
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include <assert.h>
  8. #include <faux/faux.h>
  9. #include <faux/str.h>
  10. #include <faux/list.h>
  11. #include <faux/argv.h>
  12. #include <sysrepo.h>
  13. #include <sysrepo/xpath.h>
  14. #include <sysrepo/values.h>
  15. #include <libyang/tree_edit.h>
  16. #include "sr_copypaste.h"
  17. #include "pline.h"
  18. #define NODETYPE_CONF (LYS_CONTAINER | LYS_LIST | LYS_LEAF | LYS_LEAFLIST)
  19. static pexpr_t *pexpr_new(void)
  20. {
  21. pexpr_t *pexpr = NULL;
  22. pexpr = faux_zmalloc(sizeof(*pexpr));
  23. assert(pexpr);
  24. if (!pexpr)
  25. return NULL;
  26. // Initialize
  27. pexpr->xpath = NULL;
  28. pexpr->value = NULL;
  29. pexpr->active = BOOL_FALSE;
  30. pexpr->pat = PAT_NONE;
  31. return pexpr;
  32. }
  33. static void pexpr_free(pexpr_t *pexpr)
  34. {
  35. if (!pexpr)
  36. return;
  37. faux_str_free(pexpr->xpath);
  38. faux_str_free(pexpr->value);
  39. free(pexpr);
  40. }
  41. static pcompl_t *pcompl_new(void)
  42. {
  43. pcompl_t *pcompl = NULL;
  44. pcompl = faux_zmalloc(sizeof(*pcompl));
  45. assert(pcompl);
  46. if (!pcompl)
  47. return NULL;
  48. // Initialize
  49. pcompl->type = PCOMPL_NODE;
  50. pcompl->node = NULL;
  51. pcompl->xpath = NULL;
  52. return pcompl;
  53. }
  54. static void pcompl_free(pcompl_t *pcompl)
  55. {
  56. if (!pcompl)
  57. return;
  58. faux_str_free(pcompl->xpath);
  59. free(pcompl);
  60. }
  61. pline_t *pline_new(sr_session_ctx_t *sess)
  62. {
  63. pline_t *pline = NULL;
  64. pline = faux_zmalloc(sizeof(*pline));
  65. assert(pline);
  66. if (!pline)
  67. return NULL;
  68. // Init
  69. pline->sess = sess;
  70. pline->invalid = BOOL_FALSE;
  71. pline->exprs = faux_list_new(FAUX_LIST_UNSORTED, FAUX_LIST_NONUNIQUE,
  72. NULL, NULL, (faux_list_free_fn)pexpr_free);
  73. pline->compls = faux_list_new(FAUX_LIST_UNSORTED, FAUX_LIST_NONUNIQUE,
  74. NULL, NULL, (faux_list_free_fn)pcompl_free);
  75. return pline;
  76. }
  77. void pline_free(pline_t *pline)
  78. {
  79. if (!pline)
  80. return;
  81. faux_list_free(pline->exprs);
  82. faux_list_free(pline->compls);
  83. faux_free(pline);
  84. }
  85. static pexpr_t *pline_add_expr(pline_t *pline, const char *xpath)
  86. {
  87. pexpr_t *pexpr = NULL;
  88. assert(pline);
  89. pexpr = pexpr_new();
  90. if (xpath)
  91. pexpr->xpath = faux_str_dup(xpath);
  92. faux_list_add(pline->exprs, pexpr);
  93. return pexpr;
  94. }
  95. static pexpr_t *pline_current_expr(pline_t *pline)
  96. {
  97. assert(pline);
  98. if (faux_list_len(pline->exprs) == 0)
  99. pline_add_expr(pline, NULL);
  100. return (pexpr_t *)faux_list_data(faux_list_tail(pline->exprs));
  101. }
  102. static void pline_add_compl(pline_t *pline,
  103. pcompl_type_e type, const struct lysc_node *node, char *xpath)
  104. {
  105. pcompl_t *pcompl = NULL;
  106. assert(pline);
  107. pcompl = pcompl_new();
  108. pcompl->type = type;
  109. pcompl->node = node;
  110. if (xpath)
  111. pcompl->xpath = faux_str_dup(xpath);
  112. faux_list_add(pline->compls, pcompl);
  113. }
  114. static void pline_add_compl_subtree(pline_t *pline, const struct lys_module *module,
  115. const struct lysc_node *node)
  116. {
  117. const struct lysc_node *subtree = NULL;
  118. const struct lysc_node *iter = NULL;
  119. assert(pline);
  120. assert(module);
  121. if (node)
  122. subtree = lysc_node_child(node);
  123. else
  124. subtree = module->compiled->data;
  125. LY_LIST_FOR(subtree, iter) {
  126. if (!(iter->nodetype & NODETYPE_CONF))
  127. continue;
  128. if (!(iter->flags & LYS_CONFIG_W))
  129. continue;
  130. pline_add_compl(pline, PCOMPL_NODE, iter, NULL);
  131. }
  132. }
  133. void pline_debug(pline_t *pline)
  134. {
  135. faux_list_node_t *iter = NULL;
  136. pexpr_t *pexpr = NULL;
  137. pcompl_t *pcompl = NULL;
  138. printf("====== Pline:\n\n");
  139. printf("invalid = %s\n", pline->invalid ? "true" : "false");
  140. printf("\n");
  141. printf("=== Expressions:\n\n");
  142. iter = faux_list_head(pline->exprs);
  143. while ((pexpr = (pexpr_t *)faux_list_each(&iter))) {
  144. char *pat = NULL;
  145. printf("pexpr.xpath = %s\n", pexpr->xpath ? pexpr->xpath : "NULL");
  146. printf("pexpr.value = %s\n", pexpr->value ? pexpr->value : "NULL");
  147. printf("pexpr.active = %s\n", pexpr->active ? "true" : "false");
  148. switch (pexpr->pat) {
  149. case 0x0001:
  150. pat = "NONE";
  151. break;
  152. case 0x0002:
  153. pat = "CONTAINER";
  154. break;
  155. case 0x0004:
  156. pat = "LIST";
  157. break;
  158. case 0x0008:
  159. pat = "LIST_KEY";
  160. break;
  161. case 0x0010:
  162. pat = "LIST_KEY_INCOMPLETED";
  163. break;
  164. case 0x0020:
  165. pat = "LEAF";
  166. break;
  167. case 0x0040:
  168. pat = "LEAF_VALUE";
  169. break;
  170. case 0x0080:
  171. pat = "LEAF_EMPTY";
  172. break;
  173. case 0x0100:
  174. pat = "LEAFLIST";
  175. break;
  176. case 0x0200:
  177. pat = "LEAFLIST_VALUE";
  178. break;
  179. default:
  180. pat = "UNKNOWN";
  181. break;
  182. }
  183. printf("pexpr.pat = %s\n", pat);
  184. printf("\n");
  185. }
  186. printf("=== Completions:\n\n");
  187. iter = faux_list_head(pline->compls);
  188. while ((pcompl = (pcompl_t *)faux_list_each(&iter))) {
  189. printf("pcompl.type = %s\n", (pcompl->type == PCOMPL_NODE) ?
  190. "PCOMPL_NODE" : "PCOMPL_TYPE");
  191. printf("pcompl.node = %s\n", pcompl->node ? pcompl->node->name : "NULL");
  192. printf("pcompl.xpath = %s\n", pcompl->xpath ? pcompl->xpath : "NULL");
  193. printf("\n");
  194. }
  195. }
  196. // Don't use standard lys_find_child() because it checks given module to be
  197. // equal to found node's module. So augmented nodes will not be found.
  198. static const struct lysc_node *find_child(const struct lysc_node *node,
  199. const char *name)
  200. {
  201. const struct lysc_node *iter = NULL;
  202. if (!node)
  203. return NULL;
  204. LY_LIST_FOR(node, iter) {
  205. if (!(iter->nodetype & NODETYPE_CONF))
  206. continue;
  207. if (!(iter->flags & LYS_CONFIG_W))
  208. continue;
  209. if (!faux_str_cmp(iter->name, name))
  210. return iter;
  211. }
  212. return NULL;
  213. }
  214. static struct lysc_ident *find_ident(struct lysc_ident *ident, const char *name)
  215. {
  216. LY_ARRAY_COUNT_TYPE u = 0;
  217. if (!ident)
  218. return NULL;
  219. if (!ident->derived) {
  220. if (!faux_str_cmp(name, ident->name))
  221. return ident;
  222. return NULL;
  223. }
  224. LY_ARRAY_FOR(ident->derived, u) {
  225. struct lysc_ident *identity = find_ident(ident->derived[u], name);
  226. if (identity)
  227. return identity;
  228. }
  229. return NULL;
  230. }
  231. static const char *identityref_prefix(struct lysc_type_identityref *type,
  232. const char *name)
  233. {
  234. LY_ARRAY_COUNT_TYPE u = 0;
  235. assert(type);
  236. LY_ARRAY_FOR(type->bases, u) {
  237. struct lysc_ident *identity = find_ident(type->bases[u], name);
  238. if (identity)
  239. return identity->module->name;
  240. }
  241. return NULL;
  242. }
  243. static bool_t pline_parse_module(const struct lys_module *module, faux_argv_t *argv,
  244. pline_t *pline)
  245. {
  246. faux_argv_node_t *arg = faux_argv_iter(argv);
  247. const struct lysc_node *node = NULL;
  248. char *rollback_xpath = NULL;
  249. // Rollback is a mechanism to roll to previous node while
  250. // oneliners parsing
  251. bool_t rollback = BOOL_FALSE;
  252. pexpr_t *first_pexpr = NULL;
  253. // It's necessary because upper function can use the same pline object
  254. // for another modules before. It uses the same object to collect
  255. // possible completions. But pline is really invalid only when all
  256. // modules don't recognize argument.
  257. pline->invalid = BOOL_FALSE;
  258. do {
  259. pexpr_t *pexpr = pline_current_expr(pline);
  260. const char *str = (const char *)faux_argv_current(arg);
  261. bool_t is_rollback = rollback;
  262. bool_t next_arg = BOOL_TRUE;
  263. rollback = BOOL_FALSE;
  264. if (node && !is_rollback) {
  265. char *tmp = NULL;
  266. // Save rollback Xpath (for oneliners) before leaf node
  267. // Only leaf and leaf-list node allows to "rollback"
  268. // the path and add additional statements
  269. if (node->nodetype & (LYS_LEAF | LYS_LEAFLIST)) {
  270. faux_str_free(rollback_xpath);
  271. rollback_xpath = faux_str_dup(pexpr->xpath);
  272. }
  273. // Add current node to Xpath
  274. tmp = faux_str_sprintf("/%s:%s",
  275. node->module->name, node->name);
  276. faux_str_cat(&pexpr->xpath, tmp);
  277. faux_str_free(tmp);
  278. // Activate current expression. Because it really has
  279. // new component
  280. pexpr->active = BOOL_TRUE;
  281. }
  282. // Root of the module
  283. if (!node) {
  284. // Completion
  285. if (!str) {
  286. pline_add_compl_subtree(pline, module, node);
  287. break;
  288. }
  289. // Next element
  290. node = find_child(module->compiled->data, str);
  291. if (!node)
  292. break;
  293. // Container
  294. } else if (node->nodetype & LYS_CONTAINER) {
  295. pexpr->pat = PAT_CONTAINER;
  296. // Completion
  297. if (!str) {
  298. pline_add_compl_subtree(pline, module, node);
  299. break;
  300. }
  301. // Next element
  302. node = find_child(lysc_node_child(node), str);
  303. // List
  304. } else if (node->nodetype & LYS_LIST) {
  305. const struct lysc_node *iter = NULL;
  306. pexpr->pat = PAT_LIST;
  307. // Next element
  308. if (!is_rollback) {
  309. bool_t break_upper_loop = BOOL_FALSE;
  310. LY_LIST_FOR(lysc_node_child(node), iter) {
  311. char *tmp = NULL;
  312. struct lysc_node_leaf *leaf =
  313. (struct lysc_node_leaf *)iter;
  314. if (!(iter->nodetype & LYS_LEAF))
  315. continue;
  316. if (!(iter->flags & LYS_KEY))
  317. continue;
  318. assert (leaf->type->basetype != LY_TYPE_EMPTY);
  319. // Completion
  320. if (!str) {
  321. char *tmp = NULL;
  322. tmp = faux_str_sprintf("%s/%s",
  323. pexpr->xpath, leaf->name);
  324. pline_add_compl(pline,
  325. PCOMPL_TYPE, iter, tmp);
  326. faux_str_free(tmp);
  327. break_upper_loop = BOOL_TRUE;
  328. break;
  329. }
  330. tmp = faux_str_sprintf("[%s='%s']",
  331. leaf->name, str);
  332. faux_str_cat(&pexpr->xpath, tmp);
  333. faux_str_free(tmp);
  334. faux_argv_each(&arg);
  335. str = (const char *)faux_argv_current(arg);
  336. pexpr->pat = PAT_LIST_KEY_INCOMPLETED;
  337. }
  338. if (break_upper_loop)
  339. break;
  340. }
  341. pexpr->pat = PAT_LIST_KEY;
  342. // Completion
  343. if (!str) {
  344. pline_add_compl_subtree(pline, module, node);
  345. break;
  346. }
  347. // Next element
  348. node = find_child(lysc_node_child(node), str);
  349. // Leaf
  350. } else if (node->nodetype & LYS_LEAF) {
  351. struct lysc_node_leaf *leaf =
  352. (struct lysc_node_leaf *)node;
  353. // Next element
  354. if (LY_TYPE_EMPTY == leaf->type->basetype) {
  355. pexpr->pat = PAT_LEAF_EMPTY;
  356. // Completion
  357. if (!str) {
  358. pline_add_compl_subtree(pline,
  359. module, node->parent);
  360. break;
  361. }
  362. // Don't get next argument when argument is not
  363. // really consumed
  364. next_arg = BOOL_FALSE;
  365. } else {
  366. pexpr->pat = PAT_LEAF;
  367. // Completion
  368. if (!str) {
  369. pline_add_compl(pline,
  370. PCOMPL_TYPE, node, NULL);
  371. break;
  372. }
  373. pexpr->pat = PAT_LEAF_VALUE;
  374. // Idenity must have prefix
  375. if (LY_TYPE_IDENT == leaf->type->basetype) {
  376. const char *prefix = NULL;
  377. prefix = identityref_prefix(
  378. (struct lysc_type_identityref *)
  379. leaf->type, str);
  380. if (prefix)
  381. pexpr->value = faux_str_sprintf(
  382. "%s:", prefix);
  383. }
  384. faux_str_cat(&pexpr->value, str);
  385. }
  386. // Expression was completed
  387. // So rollback (for oneliners)
  388. node = node->parent;
  389. pline_add_expr(pline, rollback_xpath);
  390. rollback = BOOL_TRUE;
  391. // Leaf-list
  392. } else if (node->nodetype & LYS_LEAFLIST) {
  393. char *tmp = NULL;
  394. const char *prefix = NULL;
  395. struct lysc_node_leaflist *leaflist =
  396. (struct lysc_node_leaflist *)node;
  397. pexpr->pat = PAT_LEAFLIST;
  398. // Completion
  399. if (!str) {
  400. pline_add_compl(pline,
  401. PCOMPL_TYPE, node, pexpr->xpath);
  402. break;
  403. }
  404. pexpr->pat = PAT_LEAFLIST_VALUE;
  405. // Idenity must have prefix
  406. if (LY_TYPE_IDENT == leaflist->type->basetype) {
  407. prefix = identityref_prefix(
  408. (struct lysc_type_identityref *)
  409. leaflist->type, str);
  410. }
  411. tmp = faux_str_sprintf("[.='%s%s%s']",
  412. prefix ? prefix : "", prefix ? ":" : "", str);
  413. faux_str_cat(&pexpr->xpath, tmp);
  414. faux_str_free(tmp);
  415. // Expression was completed
  416. // So rollback (for oneliners)
  417. node = node->parent;
  418. pline_add_expr(pline, rollback_xpath);
  419. rollback = BOOL_TRUE;
  420. }
  421. // Current argument was not consumed.
  422. // Break before getting next arg.
  423. if (!node && !rollback)
  424. break;
  425. if (next_arg)
  426. faux_argv_each(&arg);
  427. } while (BOOL_TRUE);
  428. // There is not-consumed argument so whole pline is invalid
  429. if (faux_argv_current(arg))
  430. pline->invalid = BOOL_TRUE;
  431. faux_str_free(rollback_xpath);
  432. first_pexpr = (pexpr_t *)faux_list_data(faux_list_head(pline->exprs));
  433. if (!first_pexpr || !first_pexpr->xpath)
  434. return BOOL_FALSE; // Not found
  435. return BOOL_TRUE;
  436. }
  437. pline_t *pline_parse(sr_session_ctx_t *sess, faux_argv_t *argv, uint32_t flags)
  438. {
  439. const struct ly_ctx *ctx = NULL;
  440. struct lys_module *module = NULL;
  441. pline_t *pline = NULL;
  442. uint32_t i = 0;
  443. assert(sess);
  444. if (!sess)
  445. return NULL;
  446. pline = pline_new(sess);
  447. if (!pline)
  448. return NULL;
  449. ctx = sr_session_acquire_context(pline->sess);
  450. if (!ctx)
  451. return NULL;
  452. // Iterate all modules
  453. i = 0;
  454. while ((module = ly_ctx_get_module_iter(ctx, &i))) {
  455. if (sr_module_is_internal(module))
  456. continue;
  457. if (!module->compiled)
  458. continue;
  459. if (!module->implemented)
  460. continue;
  461. if (!module->compiled->data)
  462. continue;
  463. if (pline_parse_module(module, argv, pline))
  464. break; // Found
  465. }
  466. sr_session_release_context(pline->sess);
  467. return pline;
  468. }
  469. static void identityref(struct lysc_ident *ident)
  470. {
  471. LY_ARRAY_COUNT_TYPE u = 0;
  472. if (!ident)
  473. return;
  474. if (!ident->derived) {
  475. printf("%s\n", ident->name);
  476. return;
  477. }
  478. LY_ARRAY_FOR(ident->derived, u) {
  479. identityref(ident->derived[u]);
  480. }
  481. }
  482. static void pline_print_type_completions(const struct lysc_type *type)
  483. {
  484. assert(type);
  485. switch (type->basetype) {
  486. case LY_TYPE_BOOL: {
  487. printf("true\nfalse\n");
  488. break;
  489. }
  490. case LY_TYPE_ENUM: {
  491. const struct lysc_type_enum *t =
  492. (const struct lysc_type_enum *)type;
  493. LY_ARRAY_COUNT_TYPE u = 0;
  494. LY_ARRAY_FOR(t->enums, u) {
  495. printf("%s\n",t->enums[u].name);
  496. }
  497. break;
  498. }
  499. case LY_TYPE_IDENT: {
  500. struct lysc_type_identityref *t =
  501. (struct lysc_type_identityref *)type;
  502. LY_ARRAY_COUNT_TYPE u = 0;
  503. LY_ARRAY_FOR(t->bases, u) {
  504. identityref(t->bases[u]);
  505. }
  506. break;
  507. }
  508. case LY_TYPE_UNION: {
  509. struct lysc_type_union *t =
  510. (struct lysc_type_union *)type;
  511. LY_ARRAY_COUNT_TYPE u = 0;
  512. LY_ARRAY_FOR(t->types, u) {
  513. pline_print_type_completions(t->types[u]);
  514. }
  515. break;
  516. }
  517. default:
  518. break;
  519. }
  520. }
  521. static void pline_print_type_help(const struct lysc_node *node,
  522. const struct lysc_type *type)
  523. {
  524. assert(type);
  525. if (type->basetype != LY_TYPE_UNION)
  526. printf("%s\n", node->name);
  527. switch (type->basetype) {
  528. case LY_TYPE_UINT8: {
  529. printf("Unsigned integer 8bit\n");
  530. break;
  531. }
  532. case LY_TYPE_UINT16: {
  533. printf("Unsigned integer 16bit\n");
  534. break;
  535. }
  536. case LY_TYPE_UINT32: {
  537. printf("Unsigned integer 32bit\n");
  538. break;
  539. }
  540. case LY_TYPE_UINT64: {
  541. printf("Unsigned integer 64bit\n");
  542. break;
  543. }
  544. case LY_TYPE_INT8: {
  545. printf("Integer 8bit\n");
  546. break;
  547. }
  548. case LY_TYPE_INT16: {
  549. printf("Integer 16bit\n");
  550. break;
  551. }
  552. case LY_TYPE_INT32: {
  553. printf("Integer 32bit\n");
  554. break;
  555. }
  556. case LY_TYPE_INT64: {
  557. printf("Integer 64bit\n");
  558. break;
  559. }
  560. case LY_TYPE_STRING: {
  561. printf("String\n");
  562. break;
  563. }
  564. case LY_TYPE_BOOL: {
  565. printf("Boolean true/false\n");
  566. break;
  567. }
  568. case LY_TYPE_DEC64: {
  569. printf("Signed decimal number\n");
  570. break;
  571. }
  572. case LY_TYPE_ENUM: {
  573. printf("Enumerated choice\n");
  574. break;
  575. }
  576. case LY_TYPE_IDENT: {
  577. printf("Identity\n");
  578. break;
  579. }
  580. case LY_TYPE_UNION: {
  581. struct lysc_type_union *t =
  582. (struct lysc_type_union *)type;
  583. LY_ARRAY_COUNT_TYPE u = 0;
  584. LY_ARRAY_FOR(t->types, u) {
  585. pline_print_type_help(node, t->types[u]);
  586. }
  587. break;
  588. }
  589. default:
  590. printf("Unknown\n");
  591. break;
  592. }
  593. }
  594. void pline_print_completions(const pline_t *pline, bool_t help)
  595. {
  596. faux_list_node_t *iter = NULL;
  597. pcompl_t *pcompl = NULL;
  598. iter = faux_list_head(pline->compls);
  599. while ((pcompl = (pcompl_t *)faux_list_each(&iter))) {
  600. struct lysc_type *type = NULL;
  601. const struct lysc_node *node = pcompl->node;
  602. if (pcompl->xpath && !help) {
  603. sr_val_t *vals = NULL;
  604. size_t val_num = 0;
  605. size_t i = 0;
  606. sr_get_items(pline->sess, pcompl->xpath,
  607. 0, 0, &vals, &val_num);
  608. for (i = 0; i < val_num; i++) {
  609. char *tmp = sr_val_to_str(&vals[i]);
  610. if (!tmp)
  611. continue;
  612. printf("%s\n", tmp);
  613. free(tmp);
  614. }
  615. }
  616. if (!node)
  617. continue;
  618. // Node
  619. if (PCOMPL_NODE == pcompl->type) {
  620. printf("%s\n", node->name);
  621. if (help) {
  622. if (!node->dsc) {
  623. printf("%s\n", node->name);
  624. } else {
  625. char *dsc = faux_str_getline(node->dsc,
  626. NULL);
  627. printf("%s\n", dsc);
  628. faux_str_free(dsc);
  629. }
  630. }
  631. continue;
  632. }
  633. // Type
  634. if (node->nodetype & LYS_LEAF)
  635. type = ((struct lysc_node_leaf *)node)->type;
  636. else if (node->nodetype & LYS_LEAFLIST)
  637. type = ((struct lysc_node_leaflist *)node)->type;
  638. else
  639. continue;
  640. if (help)
  641. pline_print_type_help(node, type);
  642. else
  643. pline_print_type_completions(type);
  644. }
  645. }