]> git.sur5r.net Git - glabels/blob - glabels2/src/debug.c
2009-09-17 Jim Evins <evins@snaught.com>
[glabels] / glabels2 / src / debug.c
1 /*
2  *  debug.c
3  *  Copyright (C) 2001-2009  Jim Evins <evins@snaught.com>.
4  *
5  *  This file is part of gLabels.
6  *
7  *  gLabels is free software: you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation, either version 3 of the License, or
10  *  (at your option) any later version.
11  *
12  *  gLabels is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with gLabels.  If not, see <http://www.gnu.org/licenses/>.
19  */
20
21 /*
22  * This file is based on gedit-debug.c from gedit2:
23  *
24  * Copyright (C) 1998, 1999 Alex Roberts, Evan Lawrence
25  * Copyright (C) 2000, 2001 Chema Celorio, Paolo Maggi 
26  *
27  */
28
29 #include "debug.h"
30
31 #include <glib.h>
32
33
34 glDebugSection debug_flags = GLABELS_DEBUG_NONE;
35
36
37 /****************************************************************************/
38 /* Initialize debug flags, based on environmental variables.                */
39 /****************************************************************************/
40 void
41 gl_debug_init (void)
42 {
43         if (g_getenv ("GLABELS_DEBUG") != NULL)
44         {
45                 /* enable all debugging */
46                 debug_flags = ~GLABELS_DEBUG_NONE;
47                 return;
48         }
49
50         if (g_getenv ("GLABELS_DEBUG_VIEW") != NULL)
51                 debug_flags |= GLABELS_DEBUG_VIEW;
52         if (g_getenv ("GLABELS_DEBUG_ITEM") != NULL)
53                 debug_flags |= GLABELS_DEBUG_ITEM;
54         if (g_getenv ("GLABELS_DEBUG_PRINT") != NULL)
55                 debug_flags |= GLABELS_DEBUG_PRINT;
56         if (g_getenv ("GLABELS_DEBUG_PREFS") != NULL)
57                 debug_flags |= GLABELS_DEBUG_PREFS;
58         if (g_getenv ("GLABELS_DEBUG_FILE") != NULL)
59                 debug_flags |= GLABELS_DEBUG_FILE;
60         if (g_getenv ("GLABELS_DEBUG_LABEL") != NULL)
61                 debug_flags |= GLABELS_DEBUG_LABEL;
62         if (g_getenv ("GLABELS_DEBUG_TEMPLATE") != NULL)
63                 debug_flags |= GLABELS_DEBUG_TEMPLATE;
64         if (g_getenv ("GLABELS_DEBUG_PAPER") != NULL)
65                 debug_flags |= GLABELS_DEBUG_PAPER;
66         if (g_getenv ("GLABELS_DEBUG_XML") != NULL)
67                 debug_flags |= GLABELS_DEBUG_XML;
68         if (g_getenv ("GLABELS_DEBUG_MERGE") != NULL)
69                 debug_flags |= GLABELS_DEBUG_MERGE;
70         if (g_getenv ("GLABELS_DEBUG_UNDO") != NULL)
71                 debug_flags |= GLABELS_DEBUG_UNDO;
72         if (g_getenv ("GLABELS_DEBUG_RECENT") != NULL)
73                 debug_flags |= GLABELS_DEBUG_RECENT;
74         if (g_getenv ("GLABELS_DEBUG_COMMANDS") != NULL)
75                 debug_flags |= GLABELS_DEBUG_COMMANDS;
76         if (g_getenv ("GLABELS_DEBUG_WINDOW") != NULL)
77                 debug_flags |= GLABELS_DEBUG_WINDOW;
78         if (g_getenv ("GLABELS_DEBUG_UI") != NULL)
79                 debug_flags |= GLABELS_DEBUG_UI;
80         if (g_getenv ("GLABELS_DEBUG_PROPERTY_BAR") != NULL)
81                 debug_flags |= GLABELS_DEBUG_PROPERTY_BAR;
82         if (g_getenv ("GLABELS_DEBUG_MEDIA_SELECT") != NULL)
83                 debug_flags |= GLABELS_DEBUG_MEDIA_SELECT;
84         if (g_getenv ("GLABELS_DEBUG_MINI_PREVIEW") != NULL)
85                 debug_flags |= GLABELS_DEBUG_MINI_PREVIEW;
86         if (g_getenv ("GLABELS_DEBUG_PIXBUF_CACHE") != NULL)
87                 debug_flags |= GLABELS_DEBUG_PIXBUF_CACHE;
88         if (g_getenv ("GLABELS_DEBUG_EDITOR") != NULL)
89                 debug_flags |= GLABELS_DEBUG_EDITOR;
90         if (g_getenv ("GLABELS_DEBUG_WDGT") != NULL)
91                 debug_flags |= GLABELS_DEBUG_WDGT;
92         if (g_getenv ("GLABELS_DEBUG_PATH") != NULL)
93                 debug_flags |= GLABELS_DEBUG_PATH;
94         if (g_getenv ("GLABELS_DEBUG_MERGE_MENU") != NULL)
95                 debug_flags |= GLABELS_DEBUG_MERGE_MENU;
96 }
97
98
99 /****************************************************************************/
100 /* Print debugging information.                                             */
101 /****************************************************************************/
102 void
103 gl_debug (glDebugSection  section,
104           const gchar    *file,
105           gint            line,
106           const gchar    *function,
107           const gchar    *format,
108           ...)
109 {
110         if  (debug_flags & section)
111         {
112                 va_list  args;
113                 gchar   *msg;
114
115                 g_return_if_fail (format != NULL);
116
117                 va_start (args, format);
118                 msg = g_strdup_vprintf (format, args);
119                 va_end (args);
120
121                 g_print ("%s:%d (%s) %s\n", file, line, function, msg);
122
123                 g_free (msg);
124         }
125         
126 }
127
128
129
130 /*
131  * Local Variables:       -- emacs
132  * mode: C                -- emacs
133  * c-basic-offset: 8      -- emacs
134  * tab-width: 8           -- emacs
135  * indent-tabs-mode: nil  -- emacs
136  * End:                   -- emacs
137  */