]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libsmartcols: add debug and version functions
authorKarel Zak <kzak@redhat.com>
Mon, 7 Apr 2014 11:43:50 +0000 (13:43 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 7 Apr 2014 11:43:50 +0000 (13:43 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
libsmartcols/docs/libsmartcols-sections.txt
libsmartcols/src/Makemodule.am
libsmartcols/src/init.c [new file with mode: 0644]
libsmartcols/src/libsmartcols.h.in
libsmartcols/src/libsmartcols.sym
libsmartcols/src/smartcolsP.h
libsmartcols/src/table.c
libsmartcols/src/test.c
libsmartcols/src/version.c [new file with mode: 0644]

index dc2203702b8f44675edf61721fc35e588685cd59..a8dc884abe0010316beee810551051d51c527e4f 100644 (file)
@@ -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>
index 6bebfbde9629dee3139eba3e8875672d5eeba662..8a2b1c6b02f5925db287b3c01afa5cfc3cf03cab 100644 (file)
@@ -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 (file)
index 0000000..97e0880
--- /dev/null
@@ -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));
+       }
+}
index 98d3e4c28dc5f9a41c8a5181dd04c47292d1940d..579a28a7ea032704787815e0dc632b6afe5bc1ce 100644 (file)
@@ -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);
index 40cc12c869cd4b54e8d530efe838b3d0bcd69a71..3984751cf2367dd09241d50739ffc07025ed7041 100644 (file)
@@ -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;
index 431b91b8b90080cd6d539de3c611c2b4cf383cd4..b7f1f2b6d00554253a43eed9417a96499629a027 100644 (file)
 #include "c.h"
 #include "list.h"
 #include "colors.h"
+#include "debug.h"
+
 #include "libsmartcols.h"
 
+/* features */
 #define CONFIG_LIBSMARTCOLS_ASSERT
 
 #ifdef CONFIG_LIBSMARTCOLS_ASSERT
 # 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
  */
index 7b08bc3d6fe02676b18bfb6d4bdd1569dd39475a..1fa7d05f01381592ff570ff70d94ecef85e9b382 100644 (file)
@@ -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.
  */
index 19d35f00a7584e603b9a3c7504c18590cdcc2ac0..fff3f47e0e764b2a1d20e9eef8e767a2f1a172fe 100644 (file)
@@ -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 (file)
index 0000000..76ba3ec
--- /dev/null
@@ -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);
+}
+