tree FEATURE allow enable/disable features in schemas
New public functions ly_features_enable() and ly_features_disable()
to change state of the features defined in the module. The feature
state changes if the schema subtree is printed in tree format.
Currently, non-interactive part of yanglint set all features to enable,
but interactive works with disabled features (default behavior of libyang).
TODO: add feature control into the interactive yanglint.
diff --git a/src/tree.c b/src/tree.c
index bbca51a..c5680b5 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -1494,3 +1494,75 @@
free(module);
}
+
+/*
+ * op: 1 - enable, 0 - disable
+ */
+static int
+ly_features_change(struct ly_module *module, const char *name, int op)
+{
+ int all = 0;
+ int i, j, k;
+
+ if (!module || !name || !strlen(name)) {
+ return EXIT_FAILURE;
+ }
+
+ if (!strcmp(name, "*")) {
+ /* enable all */
+ all = 1;
+ }
+
+ /* module itself */
+ for (i = 0; i < module->features_size; i++) {
+ if (all || !strcmp(module->features[i].name, name)) {
+ if (op) {
+ module->features[i].flags |= LY_NODE_FENABLED;
+ /* enable referenced features (recursion) */
+ for (k = 0; k < module->features[i].features_size; k++) {
+ ly_features_change(module->features[i].features[k]->module,
+ module->features[i].features[k]->name, op);
+ }
+ } else {
+ module->features[i].flags &= ~LY_NODE_FENABLED;
+ }
+ if (!all) {
+ return EXIT_SUCCESS;
+ }
+ }
+ }
+
+ /* submodules */
+ for (j = 0; j < module->inc_size; j++) {
+ for (i = 0; i < module->inc[j].submodule->features_size; i++) {
+ if (all || !strcmp(module->inc[j].submodule->features[i].name, name)) {
+ if (op) {
+ module->inc[j].submodule->features[i].flags |= LY_NODE_FENABLED;
+ } else {
+ module->inc[j].submodule->features[i].flags &= ~LY_NODE_FENABLED;
+ }
+ if (!all) {
+ return EXIT_SUCCESS;
+ }
+ }
+ }
+ }
+
+ if (all) {
+ return EXIT_SUCCESS;
+ } else {
+ return EXIT_FAILURE;
+ }
+}
+
+API int
+ly_features_enable(struct ly_module *module, const char *name)
+{
+ return ly_features_change(module, name, 1);
+}
+
+API int
+ly_features_disable(struct ly_module *module, const char *name)
+{
+ return ly_features_change(module, name, 1);
+}