]> git.sur5r.net Git - glabels/blob - src/debug.c
Imported Upstream version 3.0.0
[glabels] / 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_SVG_CACHE") != NULL)
89                 debug_flags |= GLABELS_DEBUG_SVG_CACHE;
90         if (g_getenv ("GLABELS_DEBUG_EDITOR") != NULL)
91                 debug_flags |= GLABELS_DEBUG_EDITOR;
92         if (g_getenv ("GLABELS_DEBUG_WDGT") != NULL)
93                 debug_flags |= GLABELS_DEBUG_WDGT;
94         if (g_getenv ("GLABELS_DEBUG_PATH") != NULL)
95                 debug_flags |= GLABELS_DEBUG_PATH;
96         if (g_getenv ("GLABELS_DEBUG_FIELD_BUTTON") != NULL)
97                 debug_flags |= GLABELS_DEBUG_FIELD_BUTTON;
98         if (g_getenv ("GLABELS_DEBUG_BARCODE") != NULL)
99                 debug_flags |= GLABELS_DEBUG_BARCODE;
100 }
101
102
103 /****************************************************************************/
104 /* Print debugging information.                                             */
105 /****************************************************************************/
106 void
107 gl_debug (glDebugSection  section,
108           const gchar    *file,
109           gint            line,
110           const gchar    *function,
111           const gchar    *format,
112           ...)
113 {
114         if  (debug_flags & section)
115         {
116                 va_list  args;
117                 gchar   *msg;
118
119                 g_return_if_fail (format != NULL);
120
121                 va_start (args, format);
122                 msg = g_strdup_vprintf (format, args);
123                 va_end (args);
124
125                 g_print ("%s:%d (%s) %s\n", file, line, function, msg);
126
127                 g_free (msg);
128         }
129         
130 }
131
132
133
134 /*
135  * Local Variables:       -- emacs
136  * mode: C                -- emacs
137  * c-basic-offset: 8      -- emacs
138  * tab-width: 8           -- emacs
139  * indent-tabs-mode: nil  -- emacs
140  * End:                   -- emacs
141  */