Commit 17c471c9 authored by Christoffer Ackelman's avatar Christoffer Ackelman

Added co_debug. By default debug_print is quiet, messages are only printed if variable DEBUG=1.

parent f9e0c628
......@@ -41,8 +41,9 @@
#include <sys/stat.h>
#include "co_cdh.h"
#include "co_dcli_msg.h"
#include "co_dcli.h"
#include "co_dcli_msg.h"
#include "co_debug.h"
#include "co_string.h"
typedef enum {
......@@ -61,7 +62,7 @@ void dcli_set_default_directory(char* dir)
int dcli_get_defaultfilename(const char* inname, char* outname, const char* ext)
{
char filename[80];
char *s, *s2;
const char *s, *s2;
if (strchr(inname, '/'))
str_Strcpy(outname, inname);
......@@ -173,11 +174,9 @@ int dcli_replace_env(const char* str, char* newstr)
str_ToLower(lower_symbol, symbol);
if ((value = getenv(lower_symbol)) == NULL) {
/* It was no symbol */
#ifdef DEBUG
if (str_StartsWith(str, "$pwr")) {
fprintf(stderr, "Warning! Could not resolve environment variable $%s\n", lower_symbol);
debug_print("Warning! Could not resolve environment variable $%s\n", lower_symbol);
}
#endif
*t = *s;
t++;
} else {
......@@ -207,11 +206,9 @@ int dcli_replace_env(const char* str, char* newstr)
str_ToLower(lower_symbol, symbol);
if ((value = getenv(lower_symbol)) == NULL) {
/* It was no symbol */
#ifdef DEBUG
if (str_StartsWith(str, "$pwr")) {
fprintf(stderr, "Warning! Could not resolve environment variable $%s\n", lower_symbol);
debug_print("Warning! Could not resolve environment variable $%s\n", lower_symbol);
}
#endif
*t = 0;
} else {
/* Symbol found */
......
#include "co_debug.h"
#include <stdarg.h>
#include <string.h>
#include <time.h>
int DEBUG = 0;
void print_time(FILE* stream, int fulldate)
{
time_t t;
struct tm* tm;
char Date[11], Time[11];
time(&t);
tm = localtime(&t);
if (fulldate) {
strftime(Date, 11, "%Y-%m-%d", tm);
fprintf(stream, "%s ", Date);
}
strftime(Time, 11, "%H:%M:%S", tm);
fprintf(stream, "%s", Time);
}
void dbg_print(const char* file, int line, const char* fmt, ...)
{
if (DEBUG) {
// 1. print timestamp
print_time(stderr);
// 2. print filename only, without path
const char* file2 = strrchr(file, '/');
file2 = file2 ? (file2 + 1) : file;
fprintf(stderr, " %s:%d: ", file2, line);
// 3. print the actual debug message
va_list args;
va_start(args, fmt);
vfprintf(stderr, fmt, args);
va_end(args);
}
}
\ No newline at end of file
#ifndef CO_DEBUG
#define CO_DEBUG
#include <stdio.h>
void print_time(FILE* stream, int fulldate = 0);
void dbg_print(const char* file, int line, const char* fmt, ...);
#define debug_print(fmt, args...) dbg_print(__FILE__, __LINE__, fmt, ##args);
#endif
\ No newline at end of file
......@@ -501,13 +501,16 @@ else
echo ""
echo "Gui Qt/Gtk:"
if [ ! -z $pwre_conf_qt ]; then
pwre_config_check_lib qt QT qt qt 0 "/usr/lib/libQtGui.so:/usr/lib/$hwpl-linux-$gnu/libQtGui.so"
pwre_config_check_include qt QT 1 "/usr/include/qt4/QtGui"
pwre_config_check_include qt QT 1 "/usr/include/qt4/QtCore/QtCore"
pwre_config_check_include qt QT 1 "/usr/include/qt4/QtGui/QtGui"
pwre_config_check_include qt QT 1 "/usr/include/qt4/QtNetwork/QtNetwork"
else
pwre_config_check_lib gtk GTK gtk gtk 0 "/usr/lib/libgtk-x11-2.0.so:/usr/lib/$hwpl-linux-$gnu/libgtk-x11-2.0.so"
pwre_config_check_include gtk GTK 1 "/usr/local/include/gtk-2.0/gtk.h:/usr/local/include/gtk-2.0/gtk/gtk.h:/usr/include/gtk-2.0/gtk/gtk.h"
fi
echo ""
echo "Optional :"
......
......@@ -46,52 +46,6 @@
#include <QTimer>
#include <QToolButton>
void print_time(FILE* stream, int fulldate)
{
time_t t;
struct tm* tm;
char Date[11], Time[11];
time(&t);
tm = localtime(&t);
if (fulldate) {
strftime(Date, 11, "%Y-%m-%d", tm);
fprintf(stream, "%s ", Date);
}
strftime(Time, 11, "%H:%M:%S", tm);
fprintf(stream, "%s", Time);
}
void dbg_print(const char* file, int line, const char* fmt, ...)
{
if (DEBUG) {
// 1. print timestamp
print_time(stderr);
// 2. print filename only, without path
const char* file2 = strrchr(file, '/');
file2 = file2 ? (file2 + 1) : file;
fprintf(stderr, " %s:%d: ", file2, line);
// 3. print the actual debug message
va_list args;
va_start(args, fmt);
vfprintf(stderr, fmt, args);
va_end(args);
}
}
void dbg_print(const char* file, int line, QString str)
{
if (DEBUG) {
// 1. print timestamp
print_time(stderr);
// 2. print filename only, without path
const char* file2 = strrchr(file, '/');
file2 = file2 ? (file2 + 1) : file;
fprintf(stderr, " %s:%d: ", file2, line);
// 3. print the actual debug message
fprintf(stderr, "%s\n", qPrintable(str));
}
}
QString fl(const char* text)
{
return QString::fromLocal8Bit(text);
......
......@@ -37,6 +37,8 @@
#ifndef QT_HELPERS_H
#define QT_HELPERS_H
#include "co_debug.h"
#include <QAction>
#include <QComboBox>
#include <QLabel>
......@@ -45,28 +47,6 @@
#include <QString>
#include <QToolBar>
void print_time(FILE* stream, int fulldate = 0);
#define DEBUG 1
void dbg_print(const char* file, int line, const char* fmt, ...);
void dbg_print(const char* file, int line, QString str);
#define debug_print(fmt, args...) \
do { \
if (DEBUG) { \
dbg_print(__FILE__, __LINE__, fmt, ##args); \
} \
} while (0)
#define debug_print2(qstr) \
do { \
if (DEBUG) { \
dbg_print(__FILE__, __LINE__, qstr); \
} \
} while (0)
/*
* Qt Helper functions
*/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment