1 /*
2  * * Copyright (C) 2009-2011 Ali <aliov@xfce.org>
3  * * Copyright (C) 2012-2017 Simon Steinbeiß <ochosi@xfce.org>
4  * * Copyright (C) 2012-2020 Sean Davis <bluesabre@xfce.org>
5  *
6  * Licensed under the GNU General Public License Version 2
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21  */
22 
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26 
27 #include <stdio.h>
28 #include <string.h>
29 #include <stdarg.h>
30 
31 #include <glib.h>
32 #include <glib-object.h>
33 #include <glib/gprintf.h>
34 
35 #include "src/misc/parole-debug.h"
36 
37 #if defined(DEBUG) && defined(G_HAVE_ISO_VARARGS)
38 
39 /**
40  * parole_debug_enum:
41  * @func: calling function
42  * @file: calling file
43  * @line: calling line
44  * @text: text to display
45  * @v_enum: enum to evaluate
46  * @type: enum type
47  *
48  * A function to print debug information for an enum.
49  *
50  **/
parole_debug_enum(const gchar * func,const gchar * file,gint line,const gchar * text,gint v_enum,GType type)51 void parole_debug_enum(const gchar *func, const gchar *file, gint line,
52                        const gchar *text, gint v_enum, GType type) {
53     gchar *content = NULL;
54     GValue __value__ = { 0, };
55 
56     g_value_init(&__value__, type);
57     g_value_set_enum(&__value__, v_enum);
58 
59     content = g_strdup_value_contents(&__value__);
60 
61     fprintf(stdout, "TRACE[%s:%d] %s(): %s : %s", file, line , func, text, content);
62     fprintf(stdout, "\n");
63 
64     g_value_unset(&__value__);
65     g_free(content);
66 }
67 
68 /**
69  * parole_debug_enum_full:
70  * @func: calling function
71  * @file: calling file
72  * @line: calling line
73  * @v_enum: enum to evaluate
74  * @type: enum type
75  * @format: format string, followed by parameters to insert into the format string (as with printf())
76  * @...: parameters to insert into the format string
77  *
78  * A function to print debug information with extended content for an enum.
79  *
80  **/
parole_debug_enum_full(const gchar * func,const gchar * file,gint line,gint v_enum,GType type,const gchar * format,...)81 void parole_debug_enum_full(const gchar *func, const gchar *file, gint line,
82                             gint v_enum, GType type, const gchar *format, ...) {
83     va_list args;
84     gchar *buffer;
85 
86     gchar *content = NULL;
87     GValue __value__ = { 0, };
88 
89     g_value_init(&__value__, type);
90     g_value_set_enum(&__value__, v_enum);
91 
92     content = g_strdup_value_contents(&__value__);
93 
94     va_start(args, format);
95     g_vasprintf(&buffer, format, args);
96     va_end(args);
97 
98     fprintf(stdout, "TRACE[%s:%d] %s(): ", file, line, func);
99     fprintf(stdout, "%s: %s", buffer, content);
100     fprintf(stdout, "\n");
101 
102     g_value_unset(&__value__);
103     g_free(content);
104     g_free(buffer);
105 }
106 
107 #endif /*#if defined(DEBUG) && defined(G_HAVE_ISO_VARARGS)*/
108