diff options
-rw-r--r-- | libsmartcols/docs/libsmartcols-sections.txt | 14 | ||||
-rw-r--r-- | libsmartcols/src/Makemodule.am | 4 | ||||
-rw-r--r-- | libsmartcols/src/init.c | 41 | ||||
-rw-r--r-- | libsmartcols/src/libsmartcols.h.in | 7 | ||||
-rw-r--r-- | libsmartcols/src/libsmartcols.sym | 3 | ||||
-rw-r--r-- | libsmartcols/src/smartcolsP.h | 14 | ||||
-rw-r--r-- | libsmartcols/src/table.c | 3 | ||||
-rw-r--r-- | libsmartcols/src/test.c | 2 | ||||
-rw-r--r-- | libsmartcols/src/version.c | 62 |
9 files changed, 146 insertions, 4 deletions
diff --git a/libsmartcols/docs/libsmartcols-sections.txt b/libsmartcols/docs/libsmartcols-sections.txt index dc2203702..a8dc884ab 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 </SECTION> + +<SECTION> +<FILE>version</FILE> +scols_parse_version_string +scols_get_library_version +LIBSMARTCOLS_VERSION +</SECTION> + +<SECTION> +<FILE>init</FILE> +scols_init_debug +</SECTION> diff --git a/libsmartcols/src/Makemodule.am b/libsmartcols/src/Makemodule.am index 6bebfbde9..8a2b1c6b0 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 000000000..97e088059 --- /dev/null +++ b/libsmartcols/src/init.c @@ -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)); + } +} diff --git a/libsmartcols/src/libsmartcols.h.in b/libsmartcols/src/libsmartcols.h.in index 98d3e4c28..579a28a7e 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 40cc12c86..3984751cf 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 431b91b8b..b7f1f2b6d 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 @@ -25,6 +28,17 @@ #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 */ struct libscols_iter { diff --git a/libsmartcols/src/table.c b/libsmartcols/src/table.c index 7b08bc3d6..1fa7d05f0 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 19d35f00a..fff3f47e0 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 000000000..76ba3ec2c --- /dev/null +++ b/libsmartcols/src/version.c @@ -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); +} + |