]> git.sur5r.net Git - glabels/blobdiff - glabels2/src/debug.c
2009-09-22 Jim Evins <evins@snaught.com>
[glabels] / glabels2 / src / debug.c
index d5492eab9f2da22104f3ce2b337bc5a9aabe9c04..ce53820a018497c1078f91f32e9620a7f8ed9aa9 100644 (file)
@@ -1,23 +1,21 @@
 /*
- *  (GLABELS) Label and Business Card Creation program for GNOME
+ *  debug.c
+ *  Copyright (C) 2001-2009  Jim Evins <evins@snaught.com>.
  *
- *  debug.c:  GLabels debug module
+ *  This file is part of gLabels.
  *
- *  Copyright (C) 2001-2002  Jim Evins <evins@snaught.com>.
- *
- *  This program is free software; you can redistribute it and/or modify
+ *  gLabels is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
+ *  the Free Software Foundation, either version 3 of the License, or
  *  (at your option) any later version.
  *
- *  This program is distributed in the hope that it will be useful,
+ *  gLabels is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
  *
  *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ *  along with gLabels.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 /*
  * Copyright (C) 2000, 2001 Chema Celorio, Paolo Maggi 
  *
  */
-#include <glib.h>
 
 #include "debug.h"
 
-/* External debug options, used here and in glabels.c */
-gint gl_debug_all = 0;
-gint gl_debug_view = 0;
-gint gl_debug_item = 0;
-gint gl_debug_prefs = 0;
-gint gl_debug_print = 0;
-gint gl_debug_file = 0;
-gint gl_debug_label = 0;
-gint gl_debug_template = 0;
-gint gl_debug_paper = 0;
-gint gl_debug_xml = 0;
-gint gl_debug_merge = 0;
-gint gl_debug_commands = 0;
-gint gl_debug_undo = 0;
-gint gl_debug_recent = 0;
-gint gl_debug_window = 0;
-gint gl_debug_ui = 0;
-gint gl_debug_property_bar = 0;
-gint gl_debug_media_select = 0;
-gint gl_debug_mini_preview = 0;
-gint gl_debug_pixbuf_cache = 0;
-gint gl_debug_wdgt = 0;
+#include <glib.h>
+
+
+glDebugSection debug_flags = GLABELS_DEBUG_NONE;
+
+
+/****************************************************************************/
+/* Initialize debug flags, based on environmental variables.                */
+/****************************************************************************/
+void
+gl_debug_init (void)
+{
+       if (g_getenv ("GLABELS_DEBUG") != NULL)
+       {
+               /* enable all debugging */
+               debug_flags = ~GLABELS_DEBUG_NONE;
+               return;
+       }
+
+       if (g_getenv ("GLABELS_DEBUG_VIEW") != NULL)
+               debug_flags |= GLABELS_DEBUG_VIEW;
+       if (g_getenv ("GLABELS_DEBUG_ITEM") != NULL)
+               debug_flags |= GLABELS_DEBUG_ITEM;
+       if (g_getenv ("GLABELS_DEBUG_PRINT") != NULL)
+               debug_flags |= GLABELS_DEBUG_PRINT;
+       if (g_getenv ("GLABELS_DEBUG_PREFS") != NULL)
+               debug_flags |= GLABELS_DEBUG_PREFS;
+       if (g_getenv ("GLABELS_DEBUG_FILE") != NULL)
+               debug_flags |= GLABELS_DEBUG_FILE;
+       if (g_getenv ("GLABELS_DEBUG_LABEL") != NULL)
+               debug_flags |= GLABELS_DEBUG_LABEL;
+       if (g_getenv ("GLABELS_DEBUG_TEMPLATE") != NULL)
+               debug_flags |= GLABELS_DEBUG_TEMPLATE;
+       if (g_getenv ("GLABELS_DEBUG_PAPER") != NULL)
+               debug_flags |= GLABELS_DEBUG_PAPER;
+       if (g_getenv ("GLABELS_DEBUG_XML") != NULL)
+               debug_flags |= GLABELS_DEBUG_XML;
+       if (g_getenv ("GLABELS_DEBUG_MERGE") != NULL)
+               debug_flags |= GLABELS_DEBUG_MERGE;
+       if (g_getenv ("GLABELS_DEBUG_UNDO") != NULL)
+               debug_flags |= GLABELS_DEBUG_UNDO;
+       if (g_getenv ("GLABELS_DEBUG_RECENT") != NULL)
+               debug_flags |= GLABELS_DEBUG_RECENT;
+       if (g_getenv ("GLABELS_DEBUG_COMMANDS") != NULL)
+               debug_flags |= GLABELS_DEBUG_COMMANDS;
+       if (g_getenv ("GLABELS_DEBUG_WINDOW") != NULL)
+               debug_flags |= GLABELS_DEBUG_WINDOW;
+       if (g_getenv ("GLABELS_DEBUG_UI") != NULL)
+               debug_flags |= GLABELS_DEBUG_UI;
+       if (g_getenv ("GLABELS_DEBUG_PROPERTY_BAR") != NULL)
+               debug_flags |= GLABELS_DEBUG_PROPERTY_BAR;
+       if (g_getenv ("GLABELS_DEBUG_MEDIA_SELECT") != NULL)
+               debug_flags |= GLABELS_DEBUG_MEDIA_SELECT;
+       if (g_getenv ("GLABELS_DEBUG_MINI_PREVIEW") != NULL)
+               debug_flags |= GLABELS_DEBUG_MINI_PREVIEW;
+       if (g_getenv ("GLABELS_DEBUG_PIXBUF_CACHE") != NULL)
+               debug_flags |= GLABELS_DEBUG_PIXBUF_CACHE;
+       if (g_getenv ("GLABELS_DEBUG_EDITOR") != NULL)
+               debug_flags |= GLABELS_DEBUG_EDITOR;
+       if (g_getenv ("GLABELS_DEBUG_WDGT") != NULL)
+               debug_flags |= GLABELS_DEBUG_WDGT;
+       if (g_getenv ("GLABELS_DEBUG_PATH") != NULL)
+               debug_flags |= GLABELS_DEBUG_PATH;
+       if (g_getenv ("GLABELS_DEBUG_MERGE_MENU") != NULL)
+               debug_flags |= GLABELS_DEBUG_MERGE_MENU;
+}
+
 
 /****************************************************************************/
 /* Print debugging information.                                             */
 /****************************************************************************/
 void
-gl_debug (gint   section,
-         gchar *file,
-         gint   line,
-         gchar *function,
-         gchar *format,
+gl_debug (glDebugSection  section,
+         const gchar    *file,
+         gint            line,
+         const gchar    *function,
+         const gchar    *format,
          ...)
 {
-       va_list  args;
-       gchar   *msg;
-
-       g_return_if_fail (format != NULL);
-
-       va_start (args, format);
-       msg = g_strdup_vprintf (format, args);
-       va_end (args);
-
-       if (gl_debug_all ||
-           (gl_debug_view         && section == GL_DEBUG_VIEW)           ||
-           (gl_debug_item         && section == GL_DEBUG_ITEM)           ||
-           (gl_debug_print        && section == GL_DEBUG_PRINT)          ||
-           (gl_debug_prefs        && section == GL_DEBUG_PREFS)          ||
-           (gl_debug_file         && section == GL_DEBUG_FILE)           ||
-           (gl_debug_label        && section == GL_DEBUG_LABEL)          ||
-           (gl_debug_template     && section == GL_DEBUG_TEMPLATE)       ||
-           (gl_debug_paper        && section == GL_DEBUG_PAPER)          ||
-           (gl_debug_xml          && section == GL_DEBUG_XML)            ||
-           (gl_debug_merge        && section == GL_DEBUG_MERGE)          ||
-           (gl_debug_commands     && section == GL_DEBUG_COMMANDS)       ||
-           (gl_debug_undo         && section == GL_DEBUG_UNDO)           ||
-           (gl_debug_recent       && section == GL_DEBUG_RECENT)         ||
-           (gl_debug_window       && section == GL_DEBUG_WINDOW)         ||
-           (gl_debug_ui           && section == GL_DEBUG_UI)             ||
-           (gl_debug_property_bar && section == GL_DEBUG_PROPERTY_BAR)   ||
-           (gl_debug_media_select && section == GL_DEBUG_MEDIA_SELECT)   ||
-           (gl_debug_mini_preview && section == GL_DEBUG_MINI_PREVIEW)   ||
-           (gl_debug_pixbuf_cache && section == GL_DEBUG_PIXBUF_CACHE)   ||
-           (gl_debug_wdgt         && section == GL_DEBUG_WDGT) )
+       if  (debug_flags & section)
+       {
+               va_list  args;
+               gchar   *msg;
+
+               g_return_if_fail (format != NULL);
+
+               va_start (args, format);
+               msg = g_strdup_vprintf (format, args);
+               va_end (args);
+
                g_print ("%s:%d (%s) %s\n", file, line, function, msg);
+
+               g_free (msg);
+       }
        
-       g_free (msg);
 }
+
+
+
+/*
+ * Local Variables:       -- emacs
+ * mode: C                -- emacs
+ * c-basic-offset: 8      -- emacs
+ * tab-width: 8           -- emacs
+ * indent-tabs-mode: nil  -- emacs
+ * End:                   -- emacs
+ */