summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libsmartcols/docs/libsmartcols-docs.xml2
-rw-r--r--libsmartcols/docs/libsmartcols-sections.txt1
-rw-r--r--libsmartcols/src/libsmartcols.h.in4
-rw-r--r--libsmartcols/src/libsmartcols.sym1
-rw-r--r--libsmartcols/src/table_print.c44
5 files changed, 51 insertions, 1 deletions
diff --git a/libsmartcols/docs/libsmartcols-docs.xml b/libsmartcols/docs/libsmartcols-docs.xml
index b8e02242a..d118bbb5a 100644
--- a/libsmartcols/docs/libsmartcols-docs.xml
+++ b/libsmartcols/docs/libsmartcols-docs.xml
@@ -9,7 +9,7 @@
<title>libsmartcols Reference Manual</title>
<releaseinfo>for libsmartcols version &version;</releaseinfo>
<copyright>
- <year>2014-2015</year>
+ <year>2014-2016</year>
<holder>Karel Zak &lt;kzak@redhat.com&gt;</holder>
</copyright>
</bookinfo>
diff --git a/libsmartcols/docs/libsmartcols-sections.txt b/libsmartcols/docs/libsmartcols-sections.txt
index c9bbec45b..75ff0eb2c 100644
--- a/libsmartcols/docs/libsmartcols-sections.txt
+++ b/libsmartcols/docs/libsmartcols-sections.txt
@@ -145,6 +145,7 @@ scols_unref_table
scols_print_table
scols_print_table_to_string
scols_table_print_range
+scols_table_print_range_to_string
</SECTION>
<SECTION>
diff --git a/libsmartcols/src/libsmartcols.h.in b/libsmartcols/src/libsmartcols.h.in
index 664822e77..b2a750f1b 100644
--- a/libsmartcols/src/libsmartcols.h.in
+++ b/libsmartcols/src/libsmartcols.h.in
@@ -250,6 +250,10 @@ extern int scols_print_table_to_string(struct libscols_table *tb, char **data);
extern int scols_table_print_range( struct libscols_table *tb,
struct libscols_line *start,
struct libscols_line *end);
+extern int scols_table_print_range_to_string( struct libscols_table *tb,
+ struct libscols_line *start,
+ struct libscols_line *end,
+ char **data);
#ifdef __cplusplus
}
diff --git a/libsmartcols/src/libsmartcols.sym b/libsmartcols/src/libsmartcols.sym
index 8f64c09c9..862262c8c 100644
--- a/libsmartcols/src/libsmartcols.sym
+++ b/libsmartcols/src/libsmartcols.sym
@@ -133,5 +133,6 @@ global:
scols_cell_get_flags;
scols_cell_set_flags;
scols_table_print_range;
+ scols_table_print_range_to_string;
scols_table_enable_nolinesep;
} SMARTCOLS_2.27;
diff --git a/libsmartcols/src/table_print.c b/libsmartcols/src/table_print.c
index 75e828edd..f65cce383 100644
--- a/libsmartcols/src/table_print.c
+++ b/libsmartcols/src/table_print.c
@@ -1352,6 +1352,50 @@ done:
}
/**
+ * scols_table_print_range_to_string:
+ * @tb: table
+ * @start: first printed line or NULL to print from the beggin of the table
+ * @end: last printed line or NULL to print all from start.
+ * @data: pointer to the beginning of a memory area to print to
+ *
+ * The same as scols_table_print_range(), but prints to @data instead of
+ * stream.
+ *
+ * Returns: 0, a negative value in case of an error.
+ */
+int scols_table_print_range_to_string( struct libscols_table *tb,
+ struct libscols_line *start,
+ struct libscols_line *end,
+ char **data)
+{
+#ifdef HAVE_OPEN_MEMSTREAM
+ FILE *stream, *old_stream;
+ size_t sz;
+ int rc;
+
+ if (!tb)
+ return -EINVAL;
+
+ DBG(TAB, ul_debugobj(tb, "printing range to string"));
+
+ /* create a stream for output */
+ stream = open_memstream(data, &sz);
+ if (!stream)
+ return -ENOMEM;
+
+ old_stream = scols_table_get_stream(tb);
+ scols_table_set_stream(tb, stream);
+ rc = scols_table_print_range(tb, start, end);
+ fclose(stream);
+ scols_table_set_stream(tb, old_stream);
+
+ return rc;
+#else
+ return -ENOSYS;
+#endif
+}
+
+/**
* scols_print_table:
* @tb: table
*