1 /* GIMP - The GNU Image Manipulation Program
2  * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef __GIMP_LOG_H__
19 #define __GIMP_LOG_H__
20 
21 
22 typedef guint *GimpLogHandler;
23 
24 
25 typedef enum
26 {
27   GIMP_LOG_TOOL_EVENTS        = 1 << 0,
28   GIMP_LOG_TOOL_FOCUS         = 1 << 1,
29   GIMP_LOG_DND                = 1 << 2,
30   GIMP_LOG_HELP               = 1 << 3,
31   GIMP_LOG_DIALOG_FACTORY     = 1 << 4,
32   GIMP_LOG_MENUS              = 1 << 5,
33   GIMP_LOG_SAVE_DIALOG        = 1 << 6,
34   GIMP_LOG_IMAGE_SCALE        = 1 << 7,
35   GIMP_LOG_SHADOW_TILES       = 1 << 8,
36   GIMP_LOG_SCALE              = 1 << 9,
37   GIMP_LOG_WM                 = 1 << 10,
38   GIMP_LOG_FLOATING_SELECTION = 1 << 11,
39   GIMP_LOG_SHM                = 1 << 12,
40   GIMP_LOG_TEXT_EDITING       = 1 << 13,
41   GIMP_LOG_KEY_EVENTS         = 1 << 14,
42   GIMP_LOG_AUTO_TAB_STYLE     = 1 << 15,
43   GIMP_LOG_INSTANCES          = 1 << 16,
44   GIMP_LOG_RECTANGLE_TOOL     = 1 << 17,
45   GIMP_LOG_BRUSH_CACHE        = 1 << 18,
46   GIMP_LOG_PROJECTION         = 1 << 19,
47   GIMP_LOG_XCF                = 1 << 20,
48   GIMP_LOG_MAGIC_MATCH        = 1 << 21
49 } GimpLogFlags;
50 
51 
52 extern GimpLogFlags gimp_log_flags;
53 
54 
55 void             gimp_log_init           (void);
56 void             gimp_log                (GimpLogFlags    flags,
57                                           const gchar    *function,
58                                           gint            line,
59                                           const gchar    *format,
60                                           ...) G_GNUC_PRINTF (4, 5);
61 void             gimp_logv               (GimpLogFlags    flags,
62                                           const gchar    *function,
63                                           gint            line,
64                                           const gchar    *format,
65                                           va_list         args) G_GNUC_PRINTF (4, 0);
66 
67 GimpLogHandler   gimp_log_set_handler    (gboolean        global,
68                                           GLogLevelFlags  log_levels,
69                                           GLogFunc        log_func,
70                                           gpointer        user_data);
71 void             gimp_log_remove_handler (GimpLogHandler  handler);
72 
73 
74 #ifdef G_HAVE_ISO_VARARGS
75 
76 #define GIMP_LOG(type, ...) \
77         G_STMT_START { \
78         if (gimp_log_flags & GIMP_LOG_##type) \
79           gimp_log (GIMP_LOG_##type, G_STRFUNC, __LINE__, __VA_ARGS__);       \
80         } G_STMT_END
81 
82 #elif defined(G_HAVE_GNUC_VARARGS)
83 
84 #define GIMP_LOG(type, format...) \
85         G_STMT_START { \
86         if (gimp_log_flags & GIMP_LOG_##type) \
87           gimp_log (GIMP_LOG_##type, G_STRFUNC, __LINE__, format);  \
88         } G_STMT_END
89 
90 #else /* no varargs macros */
91 
92 /* need to expand all the short forms
93  * to make them known constants at compile time
94  */
95 #define TOOL_EVENTS        GIMP_LOG_TOOL_EVENTS
96 #define TOOL_FOCUS         GIMP_LOG_TOOL_FOCUS
97 #define DND                GIMP_LOG_DND
98 #define HELP               GIMP_LOG_HELP
99 #define DIALOG_FACTORY     GIMP_LOG_DIALOG_FACTORY
100 #define MENUS              GIMP_LOG_MENUS
101 #define SAVE_DIALOG        GIMP_LOG_SAVE_DIALOG
102 #define IMAGE_SCALE        GIMP_LOG_IMAGE_SCALE
103 #define SHADOW_TILES       GIMP_LOG_SHADOW_TILES
104 #define SCALE              GIMP_LOG_SCALE
105 #define WM                 GIMP_LOG_WM
106 #define FLOATING_SELECTION GIMP_LOG_FLOATING_SELECTION
107 #define SHM                GIMP_LOG_SHM
108 #define TEXT_EDITING       GIMP_LOG_TEXT_EDITING
109 #define KEY_EVENTS         GIMP_LOG_KEY_EVENTS
110 #define AUTO_TAB_STYLE     GIMP_LOG_AUTO_TAB_STYLE
111 #define INSTANCES          GIMP_LOG_INSTANCES
112 #define RECTANGLE_TOOL     GIMP_LOG_RECTANGLE_TOOL
113 #define BRUSH_CACHE        GIMP_LOG_BRUSH_CACHE
114 #define PROJECTION         GIMP_LOG_PROJECTION
115 #define XCF                GIMP_LOG_XCF
116 
117 #if 0 /* last resort */
118 #  define GIMP_LOG /* nothing => no varargs, no log */
119 #endif
120 
121 static void
GIMP_LOG(GimpLogFlags flags,const gchar * format,...)122 GIMP_LOG (GimpLogFlags flags,
123           const gchar *format,
124           ...)
125 {
126   va_list args;
127   va_start (args, format);
128   if (gimp_log_flags & flags)
129     gimp_logv (type, "", 0, format, args);
130   va_end (args);
131 }
132 
133 #endif  /* !__GNUC__ */
134 
135 #define geimnum(vienna)  gimp_l##vienna##l_dialog()
136 #define fnord(kosmoso)   void gimp_##kosmoso##bl_dialog(void);
137 
138 #endif /* __GIMP_LOG_H__ */
139