1 /*
2 * Copyright (C) 2014 Karel Zak <kzak@redhat.com>
3 *
4 * This file may be redistributed under the terms of the
5 * GNU Lesser General Public License.
6 */
7
8 /**
9 * SECTION: init
10 * @title: Library initialization
11 * @short_description: initialize debugging
12 *
13 * The library debug stuff.
14 */
15
16 #include <stdarg.h>
17
18 #include "smartcolsP.h"
19
20 UL_DEBUG_DEFINE_MASK(libsmartcols);
21 UL_DEBUG_DEFINE_MASKNAMES(libsmartcols) =
22 {
23 { "all", SCOLS_DEBUG_ALL, "info about all subsystems" },
24 { "buff", SCOLS_DEBUG_BUFF, "output buffer utils" },
25 { "cell", SCOLS_DEBUG_CELL, "table cell utils" },
26 { "col", SCOLS_DEBUG_COL, "cols utils" },
27 { "help", SCOLS_DEBUG_HELP, "this help" },
28 { "group", SCOLS_DEBUG_GROUP, "lines grouping utils" },
29 { "line", SCOLS_DEBUG_LINE, "table line utils" },
30 { "tab", SCOLS_DEBUG_TAB, "table utils" },
31 { NULL, 0, NULL }
32 };
33
34 /**
35 * scols_init_debug:
36 * @mask: debug mask (0xffff to enable full debugging)
37 *
38 * If the @mask is not specified, then this function reads
39 * the LIBSMARTCOLS_DEBUG environment variable to get the mask.
40 *
41 * Already initialized debugging stuff cannot be changed. Calling
42 * this function twice has no effect.
43 */
44 void scols_init_debug(int mask)
45 {
46 if (libsmartcols_debug_mask)
47 return;
48
49 __UL_INIT_DEBUG_FROM_ENV(libsmartcols, SCOLS_DEBUG_, mask, LIBSMARTCOLS_DEBUG);
50
51 if (libsmartcols_debug_mask != SCOLS_DEBUG_INIT
52 && libsmartcols_debug_mask != (SCOLS_DEBUG_HELP|SCOLS_DEBUG_INIT)) {
53 const char *ver = NULL;
54
55 scols_get_library_version(&ver);
56
57 DBG(INIT, ul_debug("library debug mask: 0x%04x", libsmartcols_debug_mask));
58 DBG(INIT, ul_debug("library version: %s", ver));
59 }
60 ON_DBG(HELP, ul_debug_print_masks("LIBSMARTCOLS_DEBUG",
61 UL_DEBUG_MASKNAMES(libsmartcols)));
62 }