]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libsmartcols: implement scols_table_print_range_to_string
authorIgor Gnatenko <i.gnatenko.brain@gmail.com>
Sun, 21 Feb 2016 20:13:50 +0000 (21:13 +0100)
committerIgor Gnatenko <i.gnatenko.brain@gmail.com>
Sun, 21 Feb 2016 20:13:50 +0000 (21:13 +0100)
Reference: https://github.com/karelzak/util-linux/issues/283
Signed-off-by: Igor Gnatenko <i.gnatenko.brain@gmail.com>
libsmartcols/docs/libsmartcols-docs.xml
libsmartcols/docs/libsmartcols-sections.txt
libsmartcols/src/libsmartcols.h.in
libsmartcols/src/libsmartcols.sym
libsmartcols/src/table_print.c

index b8e02242afd524170741f8d832a0fb3b5873cda6..d118bbb5a9bc698105c9509293a2bc170cec3360 100644 (file)
@@ -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>
index c9bbec45b4db471e85ca73a20c681933f8f8c079..75ff0eb2c483be6ccd02b1ddc4ad4a5f7eda2e03 100644 (file)
@@ -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>
index 664822e77e1a22879a301cc77533a417f0b35fb2..b2a750f1b13b9ba67f77295073c7e9039f5295fd 100644 (file)
@@ -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
 }
index 8f64c09c9f6be2535e8606aed269fc308c672c68..862262c8cb5565007e773c1a20e818e8cc1bbd99 100644 (file)
@@ -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;
index 75e828eddccaad5d2667ed5af61705baa5b80440..f65cce38327bd07578d601e6a81cb926de26752a 100644 (file)
@@ -1351,6 +1351,50 @@ done:
        return rc;
 }
 
+/**
+ * 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