libsmartcols: add debug and version functions
Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
parent
8d0ce083b1
commit
4418714f47
|
@ -85,6 +85,7 @@ scols_ref_table
|
|||
scols_table_add_column
|
||||
scols_table_add_line
|
||||
scols_table_colors_wanted
|
||||
scols_table_enable_ascii
|
||||
scols_table_enable_colors
|
||||
scols_table_enable_export
|
||||
scols_table_enable_maxout
|
||||
|
@ -111,7 +112,6 @@ scols_table_remove_column
|
|||
scols_table_remove_columns
|
||||
scols_table_remove_line
|
||||
scols_table_remove_lines
|
||||
scols_table_set_ascii
|
||||
scols_table_set_stream
|
||||
scols_table_set_symbols
|
||||
scols_unref_table
|
||||
|
@ -122,3 +122,15 @@ scols_unref_table
|
|||
scols_print_table
|
||||
scols_print_table_to_string
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
<FILE>version</FILE>
|
||||
scols_parse_version_string
|
||||
scols_get_library_version
|
||||
LIBSMARTCOLS_VERSION
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
<FILE>init</FILE>
|
||||
scols_init_debug
|
||||
</SECTION>
|
||||
|
|
|
@ -16,7 +16,9 @@ libsmartcols_la_SOURCES= \
|
|||
libsmartcols/src/line.c \
|
||||
libsmartcols/src/table.c \
|
||||
libsmartcols/src/table_print.c \
|
||||
$(smartcolsinc_HEADERS)
|
||||
libsmartcols/src/version.c \
|
||||
libsmartcols/src/init.c \
|
||||
$(nodist_smartcolsinc_HEADERS)
|
||||
|
||||
nodist_libsmartcols_la_SOURCES = libsmartcols/src/smartcolsP.h
|
||||
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright (C) 2014 Karel Zak <kzak@redhat.com>
|
||||
*
|
||||
* This file may be redistributed under the terms of the
|
||||
* GNU Lesser General Public License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* SECTION: init
|
||||
* @title: Library initialization
|
||||
* @short_description: initialize debugging
|
||||
*/
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "smartcolsP.h"
|
||||
|
||||
UL_DEBUG_DEFINE_MASK(libsmartcols);
|
||||
|
||||
/**
|
||||
* scols_init_debug:
|
||||
* @mask: debug mask (0xffff to enable full debugging)
|
||||
*
|
||||
* If the @mask is not specified, then this function reads
|
||||
* the LIBSMARTCOLS_DEBUG environment variable to get the mask.
|
||||
*
|
||||
* Already initialized debugging stuff cannot be changed. Calling
|
||||
* this function twice has no effect.
|
||||
*/
|
||||
void scols_init_debug(int mask)
|
||||
{
|
||||
__UL_INIT_DEBUG(libsmartcols, SCOLS_DEBUG_, mask, LIBSMARTCOLS_DEBUG);
|
||||
|
||||
if (libsmartcols_debug_mask != SCOLS_DEBUG_INIT) {
|
||||
const char *ver = NULL;
|
||||
|
||||
scols_get_library_version(&ver);
|
||||
|
||||
DBG(INIT, ul_debug("library version: %s", ver));
|
||||
}
|
||||
}
|
|
@ -85,6 +85,13 @@ extern void scols_free_iter(struct libscols_iter *itr);
|
|||
extern void scols_reset_iter(struct libscols_iter *itr, int direction);
|
||||
extern int scols_iter_get_direction(struct libscols_iter *itr);
|
||||
|
||||
/* init.c */
|
||||
extern void scols_init_debug(int mask);
|
||||
|
||||
/* version.c */
|
||||
extern int scols_parse_version_string(const char *ver_string);
|
||||
extern int scols_get_library_version(const char **ver_string);
|
||||
|
||||
/* symbols.c */
|
||||
extern struct libscols_symbols *scols_new_symbols(void);
|
||||
extern void scols_ref_symbols(struct libscols_symbols *sy);
|
||||
|
|
|
@ -26,6 +26,8 @@ global:
|
|||
scols_copy_symbols;
|
||||
scols_copy_table;
|
||||
scols_free_iter;
|
||||
scols_get_library_version;
|
||||
scols_init_debug;
|
||||
scols_iter_get_direction;
|
||||
scols_line_add_child;
|
||||
scols_line_alloc_cells;
|
||||
|
@ -47,6 +49,7 @@ global:
|
|||
scols_new_line;
|
||||
scols_new_symbols;
|
||||
scols_new_table;
|
||||
scols_parse_version_string;
|
||||
scols_print_table;
|
||||
scols_print_table_to_string;
|
||||
scols_ref_column;
|
||||
|
|
|
@ -14,8 +14,11 @@
|
|||
#include "c.h"
|
||||
#include "list.h"
|
||||
#include "colors.h"
|
||||
#include "debug.h"
|
||||
|
||||
#include "libsmartcols.h"
|
||||
|
||||
/* features */
|
||||
#define CONFIG_LIBSMARTCOLS_ASSERT
|
||||
|
||||
#ifdef CONFIG_LIBSMARTCOLS_ASSERT
|
||||
|
@ -24,6 +27,17 @@
|
|||
# define assert(x)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Debug
|
||||
*/
|
||||
#define SCOLS_DEBUG_INIT (1 << 1)
|
||||
#define SCOLS_DEBUG_ALL 0xFFFF
|
||||
|
||||
UL_DEBUG_DECLARE_MASK(libsmartcols);
|
||||
#define DBG(m, x) __UL_DBG(libsmartcols, SCOLS_DEBUG_, m, x)
|
||||
#define ON_DBG(m, x) __UL_DBG_CALL(libsmartcols, SCOLS_DEBUG_, m, x)
|
||||
#define DBG_FLUSH __UL_DBG_FLUSH(libsmartcols, SCOLS_DEBUG_)
|
||||
|
||||
/*
|
||||
* Generic iterator
|
||||
*/
|
||||
|
|
|
@ -92,9 +92,8 @@ void scols_unref_table(struct libscols_table *tb)
|
|||
* scols_table_add_column:
|
||||
* @tb: a pointer to a struct libscols_table instance
|
||||
* @cl: a pointer to a struct libscols_column instance
|
||||
* @flags: a flag mask integer
|
||||
*
|
||||
* Adds @cl to @tb's column list, setting the appropriate flags to @flags.
|
||||
* Adds @cl to @tb's column list.
|
||||
*
|
||||
* Returns: 0, a negative number in case of an error.
|
||||
*/
|
||||
|
|
|
@ -40,6 +40,8 @@ int main(int argc, char *argv[])
|
|||
bindtextdomain(PACKAGE, LOCALEDIR);
|
||||
textdomain(PACKAGE);
|
||||
|
||||
scols_init_debug(0);
|
||||
|
||||
tb = scols_new_table();
|
||||
if (!tb)
|
||||
err(EXIT_FAILURE, "table initialization failed");
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* version.c - Return the version of the library
|
||||
*
|
||||
* Copyright (C) 2014 Karel Zak <kzak@redhat.com>
|
||||
*
|
||||
* See COPYING.libmount for the License of this software.
|
||||
*/
|
||||
|
||||
/**
|
||||
* SECTION: version
|
||||
* @title: Version functions
|
||||
* @short_description: functions to get the library version.
|
||||
*
|
||||
* Note that library version is not the same thing as SONAME verison. The
|
||||
* libsmarcols uses symbols versioning and SONAME is not modified for releases.
|
||||
*
|
||||
* The library version and symbols version follow util-linux package versioning.
|
||||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
#include "smartcolsP.h"
|
||||
|
||||
static const char *lib_version = LIBSMARTCOLS_VERSION;
|
||||
|
||||
/**
|
||||
* scols_parse_version_string:
|
||||
* @ver_string: version string (e.g "2.18.0")
|
||||
*
|
||||
* Returns: release version code.
|
||||
*/
|
||||
int scols_parse_version_string(const char *ver_string)
|
||||
{
|
||||
const char *cp;
|
||||
int version = 0;
|
||||
|
||||
assert(ver_string);
|
||||
|
||||
for (cp = ver_string; *cp; cp++) {
|
||||
if (*cp == '.')
|
||||
continue;
|
||||
if (!isdigit(*cp))
|
||||
break;
|
||||
version = (version * 10) + (*cp - '0');
|
||||
}
|
||||
return version;
|
||||
}
|
||||
|
||||
/**
|
||||
* scols_get_library_version:
|
||||
* @ver_string: return pointer to the static library version string if not NULL
|
||||
*
|
||||
* Returns: release version number.
|
||||
*/
|
||||
int scols_get_library_version(const char **ver_string)
|
||||
{
|
||||
if (ver_string)
|
||||
*ver_string = lib_version;
|
||||
|
||||
return scols_parse_version_string(lib_version);
|
||||
}
|
||||
|
Loading…
Reference in New Issue