printers FEATURE submodule print
Also some refactorization included,
which consists mostly of removing
compiled import structure as it is
not needed in a compiled module and
is not even really viable because
of submodules.
diff --git a/src/printer_yin.c b/src/printer_yin.c
index d825733..460285c 100644
--- a/src/printer_yin.c
+++ b/src/printer_yin.c
@@ -45,7 +45,7 @@
struct lysp_ext_instance *ext, int *flag, LY_ARRAY_COUNT_TYPE count);
static void
-ypr_open(struct ypr_ctx *ctx, const char *elem_name, const char *attr_name, const char *attr_value, int flag)
+ypr_open(struct ypr_ctx *ctx, const char *elem_name, const char *attr_name, const char *attr_value, int flag)
{
ly_print(ctx->out, "%*s<%s", INDENT, elem_name);
@@ -90,8 +90,6 @@
ly_print(ctx->out, "</%s>\n", arg);
}
-
-
static void
ypr_substmt(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index, const char *text, void *ext)
{
@@ -1000,7 +998,6 @@
ypr_close(ctx, "augment", 1);
}
-
static void
yprp_uses(struct ypr_ctx *ctx, const struct lysp_node *node)
{
@@ -1186,53 +1183,17 @@
ypr_close(ctx, "deviation", 1);
}
-/**
- * @brief Minimal print of a schema.
- *
- * To print parsed schema when the parsed form was already removed
- */
-static LY_ERR
-ypr_missing_format(struct ypr_ctx *ctx, const struct lys_module *module)
-{
- /* module-header-stmts */
- if (module->version) {
- if (module->version) {
- ypr_substmt(ctx, LYEXT_SUBSTMT_VERSION, 0, module->version == LYS_VERSION_1_1 ? "1.1" : "1", NULL);
- }
- }
- ypr_substmt(ctx, LYEXT_SUBSTMT_NAMESPACE, 0, module->ns, NULL);
- ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, module->prefix, NULL);
-
- /* meta-stmts */
- if (module->org || module->contact || module->dsc || module->ref) {
- ly_print(ctx->out, "\n");
- }
- ypr_substmt(ctx, LYEXT_SUBSTMT_ORGANIZATION, 0, module->org, NULL);
- ypr_substmt(ctx, LYEXT_SUBSTMT_CONTACT, 0, module->contact, NULL);
- ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, module->dsc, NULL);
- ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, module->ref, NULL);
-
- /* revision-stmts */
- if (module->revision) {
- ypr_open(ctx, "revision", "date", module->revision, -1);
- }
-
- LEVEL--;
- ypr_close(ctx, "module", 1);
- ly_print_flush(ctx->out);
-
- return LY_SUCCESS;
-}
-
static void
ypr_xmlns(struct ypr_ctx *ctx, const struct lys_module *module, unsigned int indent)
{
- LY_ARRAY_COUNT_TYPE u;
-
ly_print(ctx->out, "%*sxmlns=\"%s\"", indent + INDENT, YIN_NS_URI);
ly_print(ctx->out, "\n%*sxmlns:%s=\"%s\"", indent + INDENT, module->prefix, module->ns);
+}
- struct lysp_module *modp = module->parsed;
+static void
+ypr_import_xmlns(struct ypr_ctx *ctx, const struct lysp_module *modp, unsigned int indent)
+{
+ LY_ARRAY_COUNT_TYPE u;
LY_ARRAY_FOR(modp->imports, u){
ly_print(ctx->out, "\n%*sxmlns:%s=\"%s\"", indent + INDENT, modp->imports[u].prefix, modp->imports[u].module->ns);
@@ -1417,38 +1378,13 @@
}
}
-LY_ERR
-yin_print_parsed(struct ly_out *out, const struct lys_module *module)
+static void
+yin_print_parsed_linkage(struct ypr_ctx *ctx, const struct lysp_module *modp)
{
- unsigned int u;
- struct lysp_node *data;
- struct lysp_module *modp = module->parsed;
- struct ypr_ctx ctx_ = {.out = out, .level = 0, .module = module}, *ctx = &ctx_;
+ LY_ARRAY_COUNT_TYPE u;
- ly_print(ctx->out, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
- ly_print(ctx->out, "%*s<module name=\"%s\"\n", INDENT, module->name);
- ypr_xmlns(ctx, module, 8);
- ly_print(ctx->out, ">\n");
-
- LEVEL++;
-
- if (!modp) {
- ly_print(ctx->out, "%*s<!-- PARSED INFORMATION ARE NOT FULLY PRESENT -->\n", INDENT);
- return ypr_missing_format(ctx, module);
- }
-
- /* module-header-stmts */
- if (module->version) {
- if (module->version) {
- ypr_substmt(ctx, LYEXT_SUBSTMT_VERSION, 0, module->version == LYS_VERSION_1_1 ? "1.1" : "1", modp->exts);
- }
- }
- ypr_substmt(ctx, LYEXT_SUBSTMT_NAMESPACE, 0, module->ns, modp->exts);
- ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, module->prefix, modp->exts);
-
- /* linkage-stmts */
LY_ARRAY_FOR(modp->imports, u) {
- ypr_open(ctx, "import", "module", modp->imports[u].module->name, 1);
+ ypr_open(ctx, "import", "module", modp->imports[u].name, 1);
LEVEL++;
yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, modp->imports[u].exts, NULL, 0);
ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, modp->imports[u].prefix, modp->imports[u].exts);
@@ -1462,7 +1398,7 @@
}
LY_ARRAY_FOR(modp->includes, u) {
if (modp->includes[u].rev[0] || modp->includes[u].dsc || modp->includes[u].ref || modp->includes[u].exts) {
- ypr_open(ctx, "include", "module", modp->includes[u].submodule->name, 1);
+ ypr_open(ctx, "include", "module", modp->includes[u].name, 1);
LEVEL++;
yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, modp->includes[u].exts, NULL, 0);
if (modp->includes[u].rev[0]) {
@@ -1471,36 +1407,26 @@
ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, modp->includes[u].dsc, modp->includes[u].exts);
ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, modp->includes[u].ref, modp->includes[u].exts);
LEVEL--;
- ly_print(out, "%*s}\n", INDENT);
+ ly_print(ctx->out, "%*s}\n", INDENT);
} else {
- ypr_open(ctx, "include", "module", modp->includes[u].submodule->name, -1);
+ ypr_open(ctx, "include", "module", modp->includes[u].name, -1);
}
}
+}
- /* meta-stmts */
- if (module->org || module->contact || module->dsc || module->ref) {
- ly_print(out, "\n");
- }
- ypr_substmt(ctx, LYEXT_SUBSTMT_ORGANIZATION, 0, module->org, modp->exts);
- ypr_substmt(ctx, LYEXT_SUBSTMT_CONTACT, 0, module->contact, modp->exts);
- ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, module->dsc, modp->exts);
- ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, module->ref, modp->exts);
+static void
+yin_print_parsed_body(struct ypr_ctx *ctx, const struct lysp_module *modp)
+{
+ LY_ARRAY_COUNT_TYPE u;
+ struct lysp_node *data;
- /* revision-stmts */
- if (modp->revs) {
- ly_print(out, "\n");
- }
- LY_ARRAY_FOR(modp->revs, u) {
- yprp_revision(ctx, &modp->revs[u]);
- }
- /* body-stmts */
LY_ARRAY_FOR(modp->extensions, u) {
- ly_print(out, "\n");
+ ly_print(ctx->out, "\n");
yprp_extension(ctx, &modp->extensions[u]);
}
if (modp->exts) {
- ly_print(out, "\n");
- yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, module->parsed->exts, NULL, 0);
+ ly_print(ctx->out, "\n");
+ yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, modp->exts, NULL, 0);
}
LY_ARRAY_FOR(modp->features, u) {
@@ -1538,6 +1464,51 @@
LY_ARRAY_FOR(modp->deviations, u) {
yprp_deviation(ctx, &modp->deviations[u]);
}
+}
+
+LY_ERR
+yin_print_parsed_module(struct ly_out *out, const struct lys_module *module, const struct lysp_module *modp)
+{
+ LY_ARRAY_COUNT_TYPE u;
+ struct ypr_ctx ctx_ = {.out = out, .level = 0, .module = module}, *ctx = &ctx_;
+
+ ly_print(ctx->out, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
+ ly_print(ctx->out, "%*s<module name=\"%s\"\n", INDENT, module->name);
+ ypr_xmlns(ctx, module, 8);
+ ypr_import_xmlns(ctx, modp, 8);
+ ly_print(ctx->out, ">\n");
+
+ LEVEL++;
+
+ /* module-header-stmts */
+ if (module->version) {
+ ypr_substmt(ctx, LYEXT_SUBSTMT_VERSION, 0, module->version == LYS_VERSION_1_1 ? "1.1" : "1", modp->exts);
+ }
+ ypr_substmt(ctx, LYEXT_SUBSTMT_NAMESPACE, 0, module->ns, modp->exts);
+ ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, module->prefix, modp->exts);
+
+ /* linkage-stmts (import/include) */
+ yin_print_parsed_linkage(ctx, modp);
+
+ /* meta-stmts */
+ if (module->org || module->contact || module->dsc || module->ref) {
+ ly_print(out, "\n");
+ }
+ ypr_substmt(ctx, LYEXT_SUBSTMT_ORGANIZATION, 0, module->org, modp->exts);
+ ypr_substmt(ctx, LYEXT_SUBSTMT_CONTACT, 0, module->contact, modp->exts);
+ ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, module->dsc, modp->exts);
+ ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, module->ref, modp->exts);
+
+ /* revision-stmts */
+ if (modp->revs) {
+ ly_print(out, "\n");
+ }
+ LY_ARRAY_FOR(modp->revs, u) {
+ yprp_revision(ctx, &modp->revs[u]);
+ }
+
+ /* body-stmts */
+ yin_print_parsed_body(ctx, modp);
LEVEL--;
ly_print(out, "%*s</module>\n", INDENT);
@@ -1546,3 +1517,63 @@
return LY_SUCCESS;
}
+static void
+yprp_belongsto(struct ypr_ctx *ctx, const struct lysp_submodule *submodp)
+{
+ ypr_open(ctx, "belongs-to", "module", submodp->belongsto, 1);
+ LEVEL++;
+ yprp_extension_instances(ctx, LYEXT_SUBSTMT_BELONGSTO, 0, submodp->exts, NULL, 0);
+ ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, submodp->prefix, submodp->exts);
+ LEVEL--;
+ ypr_close(ctx, "belongs-to", 1);
+}
+
+LY_ERR
+yin_print_parsed_submodule(struct ly_out *out, const struct lys_module *module, const struct lysp_submodule *submodp)
+{
+ LY_ARRAY_COUNT_TYPE u;
+ struct ypr_ctx ctx_ = {.out = out, .level = 0, .module = module}, *ctx = &ctx_;
+
+ ly_print(ctx->out, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
+ ly_print(ctx->out, "%*s<submodule name=\"%s\"\n", INDENT, submodp->name);
+ ypr_xmlns(ctx, module, 8);
+ ypr_import_xmlns(ctx, (struct lysp_module *)submodp, 8);
+ ly_print(ctx->out, ">\n");
+
+ LEVEL++;
+
+ /* submodule-header-stmts */
+ if (submodp->version) {
+ ypr_substmt(ctx, LYEXT_SUBSTMT_VERSION, 0, submodp->version == LYS_VERSION_1_1 ? "1.1" : "1", submodp->exts);
+ }
+ yprp_belongsto(ctx, submodp);
+
+ /* linkage-stmts (import/include) */
+ yin_print_parsed_linkage(ctx, (struct lysp_module *)submodp);
+
+ /* meta-stmts */
+ if (submodp->org || submodp->contact || submodp->dsc || submodp->ref) {
+ ly_print(out, "\n");
+ }
+ ypr_substmt(ctx, LYEXT_SUBSTMT_ORGANIZATION, 0, submodp->org, submodp->exts);
+ ypr_substmt(ctx, LYEXT_SUBSTMT_CONTACT, 0, submodp->contact, submodp->exts);
+ ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, submodp->dsc, submodp->exts);
+ ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, submodp->ref, submodp->exts);
+
+ /* revision-stmts */
+ if (submodp->revs) {
+ ly_print(out, "\n");
+ }
+ LY_ARRAY_FOR(submodp->revs, u) {
+ yprp_revision(ctx, &submodp->revs[u]);
+ }
+
+ /* body-stmts */
+ yin_print_parsed_body(ctx, (struct lysp_module *)submodp);
+
+ LEVEL--;
+ ly_print(out, "%*s</submodule>\n", INDENT);
+ ly_print_flush(out);
+
+ return LY_SUCCESS;
+}