libsmartcols: implement scols_table_print_range_to_string
Reference: https://github.com/karelzak/util-linux/issues/283 Signed-off-by: Igor Gnatenko <i.gnatenko.brain@gmail.com>
This commit is contained in:
parent
12ca9cb1f5
commit
cfa185721e
|
@ -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 <kzak@redhat.com></holder>
|
||||
</copyright>
|
||||
</bookinfo>
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue