Fix build with LTO
[geeqie.git] / src / debug.cc
index ae5f692..1e7c110 100644 (file)
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#include "main.h"
 #include "debug.h"
 
+#include <regex.h>
+#include <sys/time.h>
+
+#include <cstdarg>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+
+#include <config.h>
+
+#if HAVE_EXECINFO_H
+#  include <execinfo.h>
+#endif
+
 #include "filedata.h"
+#include "intl.h"
 #include "logwindow.h"
+#include "main-defines.h"
+#include "main.h"
 #include "misc.h"
+#include "options.h"
 #include "ui-fileops.h"
 
-#ifdef HAVE_EXECINFO_H
-#include <execinfo.h>
-#endif
-
-#include <regex.h>
-
 /*
  * Logging functions
  */
-static gchar *regexp = NULL;
+static gchar *regexp = nullptr;
 
 static gboolean log_msg_cb(gpointer data)
 {
@@ -84,7 +95,8 @@ void log_domain_print_message(const gchar *domain, gchar *buf)
 {
        gchar *buf_nl;
        regex_t regex;
-       gint ret_comp, ret_exec;
+       gint ret_comp;
+       gint ret_exec;
 
        buf_nl = g_strconcat(buf, "\n", NULL);
 
@@ -93,7 +105,7 @@ void log_domain_print_message(const gchar *domain, gchar *buf)
                        ret_comp = regcomp(&regex, regexp, 0);
                        if (!ret_comp)
                                {
-                               ret_exec = regexec(&regex, buf_nl, 0, NULL, 0);
+                               ret_exec = regexec(&regex, buf_nl, 0, nullptr, 0);
 
                                if (!ret_exec)
                                        {
@@ -117,8 +129,7 @@ void log_domain_print_message(const gchar *domain, gchar *buf)
        g_free(buf);
 }
 
-void log_domain_print_debug(const gchar *domain, const gchar *file_name, const gchar *function_name,
-                                                                       int line_number, const gchar *format, ...)
+void log_domain_print_debug(const gchar *domain, const gchar *file_name, int line_number, const gchar *function_name, const gchar *format, ...)
 {
        va_list ap;
        gchar *message;
@@ -131,12 +142,11 @@ void log_domain_print_debug(const gchar *domain, const gchar *file_name, const g
 
        if (options && options->log_window.timer_data)
                {
-               location = g_strdup_printf("%s:%s:%s:%d:", get_exec_time(), file_name,
-                                                                                               function_name, line_number);
+               location = g_strdup_printf("%s:%s:%d:%s:", get_exec_time(), file_name, line_number, function_name);
                }
        else
                {
-               location = g_strdup_printf("%s:%s:%d:", file_name, function_name, line_number);
+               location = g_strdup_printf("%s:%d:%s:", file_name, line_number, function_name);
                }
 
        buf = g_strconcat(location, message, NULL);
@@ -166,7 +176,7 @@ void log_domain_printf(const gchar *domain, const gchar *format, ...)
 static gint debug_level = DEBUG_LEVEL_MIN;
 
 
-gint get_debug_level(void)
+gint get_debug_level()
 {
        return debug_level;
 }
@@ -208,7 +218,7 @@ static gint timeval_delta(struct timeval *result, struct timeval *x, struct time
        return x->tv_sec < y->tv_sec;
 }
 
-const gchar *get_exec_time(void)
+const gchar *get_exec_time()
 {
        static gchar timestr[30];
        static struct timeval start_tv = {0, 0};
@@ -218,7 +228,7 @@ const gchar *get_exec_time(void)
        struct timeval tv = {0, 0};
        static struct timeval delta = {0, 0};
 
-       gettimeofday(&tv, NULL);
+       gettimeofday(&tv, nullptr);
 
        if (start_tv.tv_sec == 0) start_tv = tv;
 
@@ -241,7 +251,7 @@ const gchar *get_exec_time(void)
        return timestr;
 }
 
-void init_exec_time(void)
+void init_exec_time()
 {
        get_exec_time();
 }
@@ -251,12 +261,12 @@ void set_regexp(const gchar *cmd_regexp)
        regexp = g_strdup(cmd_regexp);
 }
 
-gchar *get_regexp(void)
+gchar *get_regexp()
 {
        return g_strdup(regexp);
 }
 
-#ifdef HAVE_EXECINFO_H
+#if HAVE_EXECINFO_H
 /**
  * @brief Backtrace of geeqie files
  * @param file
@@ -268,10 +278,10 @@ gchar *get_regexp(void)
  * Format printed is: \n
  * <full path to source file>:<line number>
  *
- * The log window F1 command and options->log_window.action may be used
- * to open an editor at a backtrace location.
+ * The log window F1 command and Edit/Preferences/Behavior/Log Window F1
+ * Command may be used to open an editor at a backtrace location.
  */
-void log_print_backtrace(const gchar *file, const gchar *function, gint line)
+void log_print_backtrace(const gchar *file, gint line, const gchar *function)
 {
        FILE *fp;
        char **bt_syms;
@@ -279,7 +289,7 @@ void log_print_backtrace(const gchar *file, const gchar *function, gint line)
        gchar *address_offset;
        gchar *cmd_line;
        gchar *exe_path;
-       gchar *function_name = NULL;
+       gchar *function_name = nullptr;
        gchar *paren_end;
        gchar *paren_start;
        gint bt_size;
@@ -307,18 +317,18 @@ void log_print_backtrace(const gchar *file, const gchar *function, gint line)
                                cmd_line = g_strconcat("addr2line -p -f -C -e ", gq_executable_path, " ", address_offset, NULL);
 
                                fp = popen(cmd_line, "r");
-                               if (fp == NULL)
+                               if (fp == nullptr)
                                        {
                                        log_printf("Failed to run command: %s", cmd_line);
                                        }
                                else
                                        {
-                                       while (fgets(path, sizeof(path), fp) != NULL)
+                                       while (fgets(path, sizeof(path), fp) != nullptr)
                                                {
                                                /* Remove redundant newline */
                                                path[strlen(path) - 1] = '\0';
 
-                                               if (g_strstr_len(path, strlen(path), "(") != NULL)
+                                               if (g_strstr_len(path, strlen(path), "(") != nullptr)
                                                        {
                                                        function_name = g_strndup(path, g_strstr_len(path, strlen(path), "(") - path);
                                                        }
@@ -345,7 +355,7 @@ void log_print_backtrace(const gchar *file, const gchar *function, gint line)
                }
 }
 #else
-void log_print_backtrace(const gchar *file, const gchar *function, gint line)
+void log_print_backtrace(const gchar *, gint, const gchar *)
 {
 }
 #endif