LD=ld
CFLAGS=-Wall -O2 -g -fPIC
-LOG-PLOTTER_OBJS = baud.o main.o options.o
+LOG-PLOTTER_OBJS = baud.o main.o options.o debug.o
ALL_OBJS = $(LOG-PLOTTER_OBJS)
ALL_DEBS = $(patsubst %.o,.%.o.d,$(ALL_OBJS))
--- /dev/null
+#include <stdio.h>
+#include <stdarg.h>
+
+#include "debug.h"
+
+int trace_level = TRACE_INFO;
+
+void print_trace(const char *file, int line, int l,
+ const char *fmt, ...)
+{
+ FILE *out_file;
+ va_list args;
+
+ if (l > trace_level)
+ return;
+
+ if (l == TRACE_ERR)
+ out_file = stderr;
+ else
+ out_file = stdout;
+
+ va_start(args, fmt);
+ vfprintf(out_file, fmt, args);
+ va_end(args);
+}
--- /dev/null
+#ifndef __DEBUG_H
+#define __DEBUG_H
+
+extern int trace_level;
+
+enum {
+ TRACE_ERR = 1,
+ TRACE_WARN,
+ TRACE_INFO,
+ TRACE_DEBUG,
+ TRACE_MAX,
+};
+
+void __attribute__ ((__format__ (__printf__, 4, 5)))
+print_trace(const char *file, int line, int l,
+ const char *fmt, ...);
+
+#define pr_err(arg...) print_trace(__FILE__, __LINE__, TRACE_ERR, arg)
+#define pr_warn(arg...) print_trace(__FILE__, __LINE__, TRACE_WARN, arg)
+#define pr_info(arg...) print_trace(__FILE__, __LINE__, TRACE_INFO, arg)
+#define pr_debug(arg...) print_trace(__FILE__, __LINE__, TRACE_DEBUG, arg)
+
+#endif