2 * Copyright (C) 2008 - 2016 The Geeqie Team
4 * Authors: Vladimir Nadvornik, Laurent Monin
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include "logwindow.h"
25 #include "ui_fileops.h"
27 #include <glib/gprintf.h>
33 static gchar *regexp = NULL;
35 static gboolean log_msg_cb(gpointer data)
38 log_window_append(buf, LOG_MSG);
43 static gboolean log_normal_cb(gpointer data)
46 log_window_append(buf, LOG_NORMAL);
51 void log_domain_print_message(const gchar *domain, gchar *buf)
55 gint ret_comp, ret_exec;
57 buf_nl = g_strconcat(buf, "\n", NULL);
59 if (regexp && command_line)
61 ret_comp = regcomp(®ex, regexp, 0);
64 ret_exec = regexec(®ex, buf_nl, 0, NULL, 0);
69 if (strcmp(domain, DOMAIN_INFO) == 0)
70 g_idle_add(log_normal_cb, buf_nl);
72 g_idle_add(log_msg_cb, buf_nl);
80 if (strcmp(domain, DOMAIN_INFO) == 0)
81 g_idle_add(log_normal_cb, buf_nl);
83 g_idle_add(log_msg_cb, buf_nl);
88 void log_domain_print_debug(const gchar *domain, const gchar *file_name,
89 int line_number, const gchar *format, ...)
97 message = g_strdup_vprintf(format, ap);
100 location = g_strdup_printf("%s:%d:", file_name, line_number);
101 buf = g_strconcat(location, message, NULL);
102 log_domain_print_message(domain,buf);
107 void log_domain_printf(const gchar *domain, const gchar *format, ...)
112 va_start(ap, format);
113 buf = g_strdup_vprintf(format, ap);
116 log_domain_print_message(domain, buf);
120 * Debugging only functions
125 static gint debug_level = DEBUG_LEVEL_MIN;
128 gint get_debug_level(void)
133 void set_debug_level(gint new_level)
135 debug_level = CLAMP(new_level, DEBUG_LEVEL_MIN, DEBUG_LEVEL_MAX);
138 void debug_level_add(gint delta)
140 set_debug_level(debug_level + delta);
143 gint required_debug_level(gint level)
145 return (debug_level >= level);
148 static gint timeval_delta(struct timeval *result, struct timeval *x, struct timeval *y)
150 if (x->tv_usec < y->tv_usec)
152 gint nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1;
153 y->tv_usec -= 1000000 * nsec;
157 if (x->tv_usec - y->tv_usec > 1000000)
159 gint nsec = (x->tv_usec - y->tv_usec) / 1000000;
160 y->tv_usec += 1000000 * nsec;
164 result->tv_sec = x->tv_sec - y->tv_sec;
165 result->tv_usec = x->tv_usec - y->tv_usec;
167 return x->tv_sec < y->tv_sec;
170 const gchar *get_exec_time(void)
172 static gchar timestr[30];
173 static struct timeval start_tv = {0, 0};
174 static struct timeval previous = {0, 0};
175 static gint started = 0;
177 struct timeval tv = {0, 0};
178 static struct timeval delta = {0, 0};
180 gettimeofday(&tv, NULL);
182 if (start_tv.tv_sec == 0) start_tv = tv;
184 tv.tv_sec -= start_tv.tv_sec;
185 if (tv.tv_usec >= start_tv.tv_usec)
186 tv.tv_usec -= start_tv.tv_usec;
189 tv.tv_usec += 1000000 - start_tv.tv_usec;
193 if (started) timeval_delta(&delta, &tv, &previous);
198 g_snprintf(timestr, sizeof(timestr), "%5d.%06d (+%05d.%06d)", (gint)tv.tv_sec, (gint)tv.tv_usec, (gint)delta.tv_sec, (gint)delta.tv_usec);
203 void init_exec_time(void)
208 void set_regexp(gchar *cmd_regexp)
210 regexp = g_strdup(cmd_regexp);
213 gchar *get_regexp(void)
215 return g_strdup(regexp);
219 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */