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