From: Karel Zak Date: Mon, 7 Apr 2014 11:43:50 +0000 (+0200) Subject: libsmartcols: add debug and version functions X-Git-Tag: v2.25-rc1~298 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4418714f471c9ce5a0054d2c7c51cd6d7ab85fef;p=thirdparty%2Futil-linux.git libsmartcols: add debug and version functions Signed-off-by: Karel Zak --- diff --git a/libsmartcols/docs/libsmartcols-sections.txt b/libsmartcols/docs/libsmartcols-sections.txt index dc2203702b..a8dc884abe 100644 --- a/libsmartcols/docs/libsmartcols-sections.txt +++ b/libsmartcols/docs/libsmartcols-sections.txt @@ -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 + +
+version +scols_parse_version_string +scols_get_library_version +LIBSMARTCOLS_VERSION +
+ +
+init +scols_init_debug +
diff --git a/libsmartcols/src/Makemodule.am b/libsmartcols/src/Makemodule.am index 6bebfbde96..8a2b1c6b02 100644 --- a/libsmartcols/src/Makemodule.am +++ b/libsmartcols/src/Makemodule.am @@ -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 diff --git a/libsmartcols/src/init.c b/libsmartcols/src/init.c new file mode 100644 index 0000000000..97e0880594 --- /dev/null +++ b/libsmartcols/src/init.c @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2014 Karel Zak + * + * 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 + +#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)); + } +} diff --git a/libsmartcols/src/libsmartcols.h.in b/libsmartcols/src/libsmartcols.h.in index 98d3e4c28d..579a28a7ea 100644 --- a/libsmartcols/src/libsmartcols.h.in +++ b/libsmartcols/src/libsmartcols.h.in @@ -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); diff --git a/libsmartcols/src/libsmartcols.sym b/libsmartcols/src/libsmartcols.sym index 40cc12c869..3984751cf2 100644 --- a/libsmartcols/src/libsmartcols.sym +++ b/libsmartcols/src/libsmartcols.sym @@ -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; diff --git a/libsmartcols/src/smartcolsP.h b/libsmartcols/src/smartcolsP.h index 431b91b8b9..b7f1f2b6d0 100644 --- a/libsmartcols/src/smartcolsP.h +++ b/libsmartcols/src/smartcolsP.h @@ -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 */ diff --git a/libsmartcols/src/table.c b/libsmartcols/src/table.c index 7b08bc3d6f..1fa7d05f01 100644 --- a/libsmartcols/src/table.c +++ b/libsmartcols/src/table.c @@ -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. */ diff --git a/libsmartcols/src/test.c b/libsmartcols/src/test.c index 19d35f00a7..fff3f47e0e 100644 --- a/libsmartcols/src/test.c +++ b/libsmartcols/src/test.c @@ -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"); diff --git a/libsmartcols/src/version.c b/libsmartcols/src/version.c new file mode 100644 index 0000000000..76ba3ec2c8 --- /dev/null +++ b/libsmartcols/src/version.c @@ -0,0 +1,62 @@ +/* + * version.c - Return the version of the library + * + * Copyright (C) 2014 Karel Zak + * + * 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 + +#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); +} +