Skip to content

Commit 81e4cbc

Browse files
committed
printer data REFACTOR shorten printer flags
1 parent 66225c5 commit 81e4cbc

37 files changed

+225
-225
lines changed

src/out.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ lyd_node_should_print(const struct lyd_node *node, uint32_t options)
5656
return 0;
5757
}
5858
} else if (lysc_is_np_cont(node->schema)) {
59-
if (options & LYD_PRINT_KEEPEMPTYCONT) {
59+
if (options & LYD_PRINT_EMPTY_CONT) {
6060
/* explicit request to print, redundant to check */
6161
return 1;
6262
}
@@ -71,7 +71,7 @@ lyd_node_should_print(const struct lyd_node *node, uint32_t options)
7171
return 0;
7272
}
7373
} else if ((node->flags & LYD_DEFAULT) && (node->schema->nodetype == LYS_CONTAINER)) {
74-
if (options & LYD_PRINT_KEEPEMPTYCONT) {
74+
if (options & LYD_PRINT_EMPTY_CONT) {
7575
/* explicit request to print */
7676
return 1;
7777
}

src/printer_data.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ lyd_print_(struct ly_out *out, const struct lyd_node *root, LYD_FORMAT format, u
5050
LIBYANG_API_DEF LY_ERR
5151
lyd_print_all(struct ly_out *out, const struct lyd_node *root, LYD_FORMAT format, uint32_t options)
5252
{
53-
LY_CHECK_ARG_RET(NULL, out, !(options & LYD_PRINT_WITHSIBLINGS), LY_EINVAL);
53+
LY_CHECK_ARG_RET(NULL, out, !(options & LYD_PRINT_SIBLINGS), LY_EINVAL);
5454

5555
/* reset the number of printed bytes */
5656
out->func_printed = 0;
@@ -66,15 +66,15 @@ lyd_print_all(struct ly_out *out, const struct lyd_node *root, LYD_FORMAT format
6666
}
6767

6868
/* print each top-level sibling */
69-
LY_CHECK_RET(lyd_print_(out, root, format, options | LYD_PRINT_WITHSIBLINGS));
69+
LY_CHECK_RET(lyd_print_(out, root, format, options | LYD_PRINT_SIBLINGS));
7070

7171
return LY_SUCCESS;
7272
}
7373

7474
LIBYANG_API_DEF LY_ERR
7575
lyd_print_tree(struct ly_out *out, const struct lyd_node *root, LYD_FORMAT format, uint32_t options)
7676
{
77-
LY_CHECK_ARG_RET(NULL, out, !(options & LYD_PRINT_WITHSIBLINGS), LY_EINVAL);
77+
LY_CHECK_ARG_RET(NULL, out, !(options & LYD_PRINT_SIBLINGS), LY_EINVAL);
7878

7979
/* reset the number of printed bytes */
8080
out->func_printed = 0;

src/printer_data.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ struct ly_out;
4949
*
5050
* Proprietary binary format that is focused on efficiency. Should always be used for best performance except for
5151
* cases when the YANG context used for printing may differ from the one used for parsing, such a scenario will fail.
52-
* Also, this format ignores most printing flags except for ::LYD_PRINT_WITH_SIBLINGS and ::LYD_PRINT_SHRINK
52+
* Also, this format ignores most printing flags except for ::LYD_PRINT_SIBLINGS and ::LYD_PRINT_SHRINK
5353
* (functionality differs from the text formats). In addition to storing the data, this format also stores all the
5454
* default values and data node flags meaning the loaded data can be used directly without any validation (unless
5555
* ::LYD_PRINT_SHRINK is used).
@@ -62,7 +62,7 @@ struct ly_out;
6262
* [output handler](@ref howtoOutput) introduced in libyang 2.0. In contrast to
6363
* [schema printers](@ref howtoSchemaPrinters), there is no limit of the functionality and the functions can be used
6464
* interchangeable. The only think to note is that the new functions ::lyd_print_all() and ::lyd_print_tree() does not
65-
* accept ::LYD_PRINT_WITHSIBLINGS [printer option](@ref dataprinterflags)) since this flag differentiate the functions
65+
* accept ::LYD_PRINT_SIBLINGS [printer option](@ref dataprinterflags)) since this flag differentiate the functions
6666
* themselves.
6767
*
6868
* Functions List
@@ -84,13 +84,13 @@ struct ly_out;
8484
*
8585
* @{
8686
*/
87-
#define LYD_PRINT_WITHSIBLINGS 0x01 /**< Flag for printing also the (following) sibling nodes of the data node.
87+
#define LYD_PRINT_SIBLINGS 0x01 /**< Flag for printing also the (following) sibling nodes of the data node.
8888
The flag is not allowed for ::lyd_print_all() and ::lyd_print_tree(). */
8989
#define LYD_PRINT_SHRINK LY_PRINT_SHRINK /**< Flag for output without indentation and formatting new lines for
9090
text formats. For the LYB format, this causes the printed data to
9191
be shrinked to include only the necessary data making them smaller
9292
but requiring validation. */
93-
#define LYD_PRINT_KEEPEMPTYCONT 0x04 /**< Preserve empty non-presence containers */
93+
#define LYD_PRINT_EMPTY_CONT 0x04 /**< Preserve empty non-presence containers */
9494
#define LYD_PRINT_EMPTY_LEAF_LIST 0x08 /**< Print even empty list and leaf-list instances, not possible for every
9595
data format (supported only for ::LYD_JSON). */
9696
#define LYD_PRINT_WD_MASK 0xF0 /**< Mask for with-defaults modes */

src/printer_json.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ json_print_any_content(struct jsonpr_ctx *pctx, struct lyd_node_any *any)
633633
prev_parent = pctx->parent;
634634
prev_opts = pctx->options;
635635
pctx->parent = &any->node;
636-
pctx->options &= ~LYD_PRINT_WITHSIBLINGS;
636+
pctx->options &= ~LYD_PRINT_SIBLINGS;
637637
LY_LIST_FOR(any->value.tree, iter) {
638638
ret = json_print_node(pctx, iter);
639639
LY_CHECK_ERR_RET(ret, LEVEL_DEC, ret);
@@ -804,7 +804,7 @@ json_print_array_is_last_inst(struct jsonpr_ctx *pctx, const struct lyd_node *no
804804
return 0;
805805
}
806806

807-
if ((pctx->root == node) && !(pctx->options & LYD_PRINT_WITHSIBLINGS)) {
807+
if ((pctx->root == node) && !(pctx->options & LYD_PRINT_SIBLINGS)) {
808808
/* the only printed instance */
809809
return 1;
810810
}
@@ -1168,7 +1168,7 @@ json_print_data(struct ly_out *out, const struct lyd_node *root, uint32_t option
11681168
LY_LIST_FOR(root, node) {
11691169
pctx.root = node;
11701170
LY_CHECK_RET(json_print_node(&pctx, node));
1171-
if (!(options & LYD_PRINT_WITHSIBLINGS)) {
1171+
if (!(options & LYD_PRINT_SIBLINGS)) {
11721172
break;
11731173
}
11741174
}

src/printer_lyb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1306,7 +1306,7 @@ lyb_print_siblings(const struct lyd_node *node, ly_bool is_root, struct lyd_lyb_
13061306

13071307
LY_CHECK_RET(lyb_print_node(&node, &sibling_ht, lybctx));
13081308

1309-
if (is_root && !(lybctx->print_options & LYD_PRINT_WITHSIBLINGS)) {
1309+
if (is_root && !(lybctx->print_options & LYD_PRINT_SIBLINGS)) {
13101310
break;
13111311
}
13121312
}

src/printer_xml.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ xml_print_anydata(struct xmlpr_ctx *pctx, const struct lyd_node_any *node)
456456
case LYD_ANYDATA_DATATREE:
457457
/* close opening tag and print data */
458458
prev_opts = pctx->options;
459-
pctx->options &= ~LYD_PRINT_WITHSIBLINGS;
459+
pctx->options &= ~LYD_PRINT_SIBLINGS;
460460
LEVEL_INC;
461461

462462
ly_print_(pctx->out, ">%s", DO_FORMAT ? "\n" : "");
@@ -618,7 +618,7 @@ xml_print_data(struct ly_out *out, const struct lyd_node *root, uint32_t options
618618
/* content */
619619
LY_LIST_FOR(root, node) {
620620
LY_CHECK_RET(xml_print_node(&pctx, node));
621-
if (!(options & LYD_PRINT_WITHSIBLINGS)) {
621+
if (!(options & LYD_PRINT_SIBLINGS)) {
622622
break;
623623
}
624624
}

src/tree_data_common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,7 @@ lyd_any_value_str(const struct lyd_node *any, char **value_str)
10411041

10421042
if (tree) {
10431043
/* print into a string */
1044-
ret = lyd_print_mem(value_str, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS);
1044+
ret = lyd_print_mem(value_str, tree, LYD_XML, LYD_PRINT_SIBLINGS);
10451045
LY_CHECK_GOTO(ret, cleanup);
10461046
} else {
10471047
assert(str);

tests/utests/basic/test_xpath.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,7 +1178,7 @@ test_trim(void **state)
11781178
assert_non_null(tree);
11791179

11801180
assert_int_equal(LY_SUCCESS, lyd_trim_xpath(&tree, "/a:c/ll/ll[a='key11']", NULL));
1181-
lyd_print_mem(&str1, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS);
1181+
lyd_print_mem(&str1, tree, LYD_XML, LYD_PRINT_SIBLINGS);
11821182
assert_string_equal(str1,
11831183
"<c xmlns=\"urn:tests:a\">\n"
11841184
" <ll>\n"
@@ -1198,7 +1198,7 @@ test_trim(void **state)
11981198
assert_non_null(tree);
11991199

12001200
assert_int_equal(LY_SUCCESS, lyd_trim_xpath(&tree, "/a:c/ll/ll[contains(.,'2')]", NULL));
1201-
lyd_print_mem(&str1, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS);
1201+
lyd_print_mem(&str1, tree, LYD_XML, LYD_PRINT_SIBLINGS);
12021202
assert_string_equal(str1,
12031203
"<c xmlns=\"urn:tests:a\">\n"
12041204
" <ll>\n"
@@ -1236,7 +1236,7 @@ test_trim(void **state)
12361236
assert_non_null(tree);
12371237

12381238
assert_int_equal(LY_SUCCESS, lyd_trim_xpath(&tree, "/l1[4]//.", NULL));
1239-
lyd_print_mem(&str1, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS);
1239+
lyd_print_mem(&str1, tree, LYD_XML, LYD_PRINT_SIBLINGS);
12401240
assert_string_equal(str1,
12411241
"<l1 xmlns=\"urn:tests:a\">\n"
12421242
" <a>a4</a>\n"

tests/utests/data/test_diff.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
CHECK_PARSE_LYD_PARAM(INPUT, LYD_XML, LYD_PARSE_ONLY, 0, LY_SUCCESS, OUTPUT)
2222

2323
#define CHECK_LYD_STRING(INPUT, TEXT) \
24-
CHECK_LYD_STRING_PARAM(INPUT, TEXT, LYD_XML, LYD_PRINT_WITHSIBLINGS)
24+
CHECK_LYD_STRING_PARAM(INPUT, TEXT, LYD_XML, LYD_PRINT_SIBLINGS)
2525

2626
#define CHECK_PARSE_LYD_DIFF(INPUT_1, INPUT_2, OPTS, OUT_DIFF) \
2727
assert_int_equal(LY_SUCCESS, lyd_diff_siblings(INPUT_1, INPUT_2, OPTS, &OUT_DIFF));\
@@ -1300,7 +1300,7 @@ test_wd(void **state)
13001300
" <dllist yang:operation=\"create\">4</dllist>\n"
13011301
"</df>\n";
13021302

1303-
CHECK_LYD_STRING_PARAM(diff1, diff1_out_1, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_ALL);
1303+
CHECK_LYD_STRING_PARAM(diff1, diff1_out_1, LYD_XML, LYD_PRINT_SIBLINGS | LYD_PRINT_WD_ALL);
13041304
assert_int_equal(lyd_diff_apply_all(&model_1, diff1), LY_SUCCESS);
13051305
CHECK_LYD(model_1, model_2);
13061306

@@ -1330,7 +1330,7 @@ test_wd(void **state)
13301330
" <dllist yang:operation=\"create\">4</dllist>\n"
13311331
"</df>\n";
13321332

1333-
CHECK_LYD_STRING_PARAM(diff1, diff1_out_2, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_ALL);
1333+
CHECK_LYD_STRING_PARAM(diff1, diff1_out_2, LYD_XML, LYD_PRINT_SIBLINGS | LYD_PRINT_WD_ALL);
13341334

13351335
lyd_free_all(model_1);
13361336
lyd_free_all(model_2);
@@ -1475,7 +1475,7 @@ test_userord_list_reverse(void **state)
14751475

14761476
lyd_diff_apply_all(&tree2, diff_reverse);
14771477

1478-
lyd_print_mem(&final_xml, tree2, LYD_XML, LYD_PRINT_WITHSIBLINGS);
1478+
lyd_print_mem(&final_xml, tree2, LYD_XML, LYD_PRINT_SIBLINGS);
14791479

14801480
assert_string_equal(final_xml, xml1);
14811481

@@ -1523,7 +1523,7 @@ test_userord_conflicting_replace_list(void **state)
15231523

15241524
lyd_diff_merge_all(&diff_tree1, diff_tree2, 0);
15251525

1526-
lyd_print_mem(&final_xml, diff_tree1, LYD_XML, LYD_PRINT_WITHSIBLINGS);
1526+
lyd_print_mem(&final_xml, diff_tree1, LYD_XML, LYD_PRINT_SIBLINGS);
15271527

15281528
char *result_xml =
15291529
"<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
@@ -1624,7 +1624,7 @@ test_userord_conflicting_replace_list2(void **state)
16241624

16251625
lyd_diff_apply_all(&tree3, diff3_1);
16261626

1627-
lyd_print_mem(&final_xml, tree3, LYD_XML, LYD_PRINT_WITHSIBLINGS);
1627+
lyd_print_mem(&final_xml, tree3, LYD_XML, LYD_PRINT_SIBLINGS);
16281628

16291629
assert_string_equal(final_xml, xml2);
16301630

@@ -1682,7 +1682,7 @@ test_userord_conflicting_replace_llist(void **state)
16821682

16831683
lyd_diff_apply_all(&tree3, diff3_1);
16841684

1685-
lyd_print_mem(&final_xml, tree3, LYD_XML, LYD_PRINT_WITHSIBLINGS);
1685+
lyd_print_mem(&final_xml, tree3, LYD_XML, LYD_PRINT_SIBLINGS);
16861686

16871687
assert_string_equal(final_xml, xml2);
16881688

tests/utests/data/test_lyb.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
CHECK_PARSE_LYD_PARAM(INPUT, LYD_XML, LYD_PARSE_ONLY | LYD_PARSE_STRICT, 0, LY_SUCCESS, OUT_NODE)
2222

2323
#define CHECK_LYD_STRING(MODEL, TEXT) \
24-
CHECK_LYD_STRING_PARAM(MODEL, TEXT, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_SHRINK)
24+
CHECK_LYD_STRING_PARAM(MODEL, TEXT, LYD_XML, LYD_PRINT_SIBLINGS | LYD_PRINT_SHRINK)
2525

2626
static void
2727
check_print_parse(void **state, const char *data_xml)
@@ -31,7 +31,7 @@ check_print_parse(void **state, const char *data_xml)
3131
char *lyb_out;
3232

3333
CHECK_PARSE_LYD(data_xml, tree_1);
34-
assert_int_equal(lyd_print_mem(&lyb_out, tree_1, LYD_LYB, LYD_PRINT_WITHSIBLINGS), 0);
34+
assert_int_equal(lyd_print_mem(&lyb_out, tree_1, LYD_LYB, LYD_PRINT_SIBLINGS), 0);
3535
assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(UTEST_LYCTX, lyb_out, LYD_LYB, LYD_PARSE_ONLY | LYD_PARSE_STRICT,
3636
0, &tree_2));
3737
assert_non_null(tree_2);
@@ -469,7 +469,7 @@ test_opaq(void **state)
469469
ly_in_free(in, 0);
470470
assert_int_equal(rc, LY_SUCCESS);
471471

472-
assert_int_equal(lyd_print_mem(&xml_out, tree_1, LYD_LYB, LYD_PRINT_WITHSIBLINGS), 0);
472+
assert_int_equal(lyd_print_mem(&xml_out, tree_1, LYD_LYB, LYD_PRINT_SIBLINGS), 0);
473473

474474
ly_in_new_memory(xml_out, &in);
475475
rc = lyd_parse_op(UTEST_LYCTX, NULL, in, LYD_LYB, LYD_TYPE_RPC_YANG, LYD_PARSE_STRICT, &tree_2, NULL);
@@ -2545,12 +2545,12 @@ test_shrink(void **state)
25452545
/* non-shrinked */
25462546
data_xml = "<cont xmlns=\"urn:mod\"/>";
25472547
CHECK_PARSE_LYD_PARAM(data_xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, tree1);
2548-
assert_int_equal(lyd_print_mem(&lyb_out, tree1, LYD_LYB, LYD_PRINT_WITHSIBLINGS), 0);
2548+
assert_int_equal(lyd_print_mem(&lyb_out, tree1, LYD_LYB, LYD_PRINT_SIBLINGS), 0);
25492549
assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(UTEST_LYCTX, lyb_out, LYD_LYB, LYD_PARSE_ONLY | LYD_PARSE_STRICT,
25502550
0, &tree2));
25512551
assert_non_null(tree2);
25522552

2553-
assert_int_equal(LY_SUCCESS, lyd_print_mem(&str, tree2, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_ALL | LYD_PRINT_SHRINK));
2553+
assert_int_equal(LY_SUCCESS, lyd_print_mem(&str, tree2, LYD_XML, LYD_PRINT_SIBLINGS | LYD_PRINT_WD_ALL | LYD_PRINT_SHRINK));
25542554
assert_non_null(str);
25552555
assert_string_equal(str, "<cont xmlns=\"urn:mod\"><l>25</l></cont>");
25562556
free(str);
@@ -2562,7 +2562,7 @@ test_shrink(void **state)
25622562
/* shrinked */
25632563
data_xml = "<cont xmlns=\"urn:mod\"/>";
25642564
CHECK_PARSE_LYD_PARAM(data_xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, tree1);
2565-
assert_int_equal(lyd_print_mem(&lyb_out, tree1, LYD_LYB, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_SHRINK), 0);
2565+
assert_int_equal(lyd_print_mem(&lyb_out, tree1, LYD_LYB, LYD_PRINT_SIBLINGS | LYD_PRINT_SHRINK), 0);
25662566
assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(UTEST_LYCTX, lyb_out, LYD_LYB, LYD_PARSE_ONLY | LYD_PARSE_STRICT,
25672567
0, &tree2));
25682568
assert_null(tree2);

0 commit comments

Comments
 (0)