Skip to content

Commit

Permalink
printer NEW lys_print_path() function
Browse files Browse the repository at this point in the history
  • Loading branch information
michalvasko committed Sep 20, 2018
1 parent 13b20f9 commit b725543
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/printer.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>

Expand Down Expand Up @@ -400,6 +401,29 @@ lys_print_file(FILE *f, const struct lys_module *module, LYS_OUTFORMAT format, c
return lys_print_(&out, module, format, target_node, line_length, options);
}

API int
lys_print_path(const char *path, const struct lys_module *module, LYS_OUTFORMAT format, const char *target_node,
int line_length, int options)
{
FILE *f;
int ret;

if (!path || !module) {
LOGARG;
return EXIT_FAILURE;
}

f = fopen(path, "w");
if (!f) {
LOGERR(module->ctx, LY_ESYS, "Failed to open file \"%s\" (%s).", path, strerror(errno));
return EXIT_FAILURE;
}

ret = lys_print_file(f, module, format, target_node, line_length, options);
fclose(f);
return ret;
}

API int
lys_print_fd(int fd, const struct lys_module *module, LYS_OUTFORMAT format, const char *target_node,
int line_length, int options)
Expand Down
15 changes: 15 additions & 0 deletions src/tree_schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -2537,6 +2537,21 @@ int lys_print_fd(int fd, const struct lys_module *module, LYS_OUTFORMAT format,
int lys_print_file(FILE *f, const struct lys_module *module, LYS_OUTFORMAT format, const char *target_node,
int line_length, int options);

/**
* @brief Print schema tree in the specified format into a file.
*
* @param[in] path File where to print the schema.
* @param[in] module Schema tree to print.
* @param[in] format Schema output format.
* @param[in] target_node Optional parameter. It specifies which particular node/subtree in the module will be printed.
* Only for #LYS_OUT_INFO and #LYS_OUT_TREE formats. Use fully qualified schema path (@ref howtoxpath).
* @param[in] line_length Maximum characters to be printed on a line, 0 for unlimited. Only for #LYS_OUT_TREE printer.
* @param[in] options Schema output options (see @ref schemaprinterflags).
* @return 0 on success, 1 on failure (#ly_errno is set).
*/
int lys_print_path(const char *path, const struct lys_module *module, LYS_OUTFORMAT format, const char *target_node,
int line_length, int options);

/**
* @brief Print schema tree in the specified format using a provided callback.
*
Expand Down

0 comments on commit b725543

Please sign in to comment.