commit 7b8e89563f05d76f6b16d5726283a8f3ec35244c
parent ecff3e563688a7736b19d2ef72db598a34eee0d0
Author: Christian Grothoff <christian@grothoff.org>
Date: Mon, 30 Jul 2012 13:21:24 +0000
log functions for LE
Diffstat:
3 files changed, 144 insertions(+), 3 deletions(-)
diff --git a/src/main/Makefile.am b/src/main/Makefile.am
@@ -40,13 +40,14 @@ EXTRA_DIST = \
libextractor_la_CPPFLAGS = -DPLUGINDIR=\"@RPLUGINDIR@\" -DPLUGININSTDIR=\"${plugindir}\" $(AM_CPPFLAGS)
libextractor_la_SOURCES = \
- extractor_metatypes.c \
- extractor_print.c \
extractor_common.c extractor_common.h \
extractor_datasource.c extractor_datasource.h \
+ $(EXTRACTOR_IPC) extractor_ipc.c extractor_ipc.h \
+ extractor_logging.c extractor_logging.h \
+ extractor_metatypes.c \
extractor_plugpath.c extractor_plugpath.h \
extractor_plugins.c extractor_plugins.h \
- $(EXTRACTOR_IPC) extractor_ipc.c extractor_ipc.h \
+ extractor_print.c \
extractor_plugin_main.c extractor_plugin_main.h \
extractor.c
diff --git a/src/main/extractor_logging.c b/src/main/extractor_logging.c
@@ -0,0 +1,68 @@
+/*
+ This file is part of libextractor.
+ (C) 2012 Vidyut Samanta and Christian Grothoff
+
+ libextractor is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3, or (at your
+ option) any later version.
+
+ libextractor is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with libextractor; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+ */
+/**
+ * @file main/extractor_logging.c
+ * @brief logging API for GNU libextractor
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "extractor_logging.h"
+
+#if DEBUG
+/**
+ * Log function.
+ *
+ * @param file name of file with the error
+ * @param line line number with the error
+ * @param ... log message and arguments
+ */
+void
+EXTRACTOR_log_ (const char *file, int line, const char *format, ...)
+{
+ va_list va;
+
+ fprintf (stderr,
+ sizeof (file_line),
+ "EXTRACTOR %s:%d ");
+ va_start (va, format);
+ vfprintf (stderr, format, va);
+ va_end (va);
+ fflush (stderr);
+}
+#endif
+
+
+/**
+ * Abort the program reporting an assertion failure
+ *
+ * @param file filename with the failure
+ * @param line line number with the failure
+ */
+void
+EXTRACTOR_abort_ (const char *file,
+ int line)
+{
+#if DEBUG
+ EXTRACTOR_log_ (file, line, "Assertion failed.\n");
+#endif
+ abort ();
+}
+
+/* end of extractor_logging.c */
diff --git a/src/main/extractor_logging.h b/src/main/extractor_logging.h
@@ -0,0 +1,72 @@
+/*
+ This file is part of libextractor.
+ (C) 2012 Vidyut Samanta and Christian Grothoff
+
+ libextractor is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3, or (at your
+ option) any later version.
+
+ libextractor is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with libextractor; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+ */
+/**
+ * @file main/extractor_logging.h
+ * @brief logging API for GNU libextractor
+ * @author Christian Grothoff
+ */
+#ifndef EXTRACTOR_LOGGING_H
+#define EXTRACTOR_LOGGING_H
+
+#define DEBUG 1
+
+#if DEBUG
+
+/**
+ * Log function.
+ *
+ * @param file name of file with the error
+ * @param line line number with the error
+ * @param ... log message and arguments
+ */
+void
+EXTRACTOR_log_ (const char *file, int line, const char *format, ...);
+
+/**
+ * Log a message.
+ *
+ * @param fmt format string
+ * @param ... arguments for fmt (printf-style)
+ */
+#define LOG(fmt, ...) EXTRACTOR_log_ (__FILE__, __LINE__, fmt, __VA_ARGS__)
+#else
+#define LOG(...)
+#endif
+
+
+/**
+ * Abort the program reporting an assertion failure
+ *
+ * @param file filename with the failure
+ * @param line line number with the failure
+ */
+void
+EXTRACTOR_abort_ (const char *file,
+ int line);
+
+/**
+ * Abort program if assertion fails.
+ *
+ * @param cond assertion that must hold.
+ */
+#define ASSERT(cond) do { if (! (cond)) EXTRACTOR_abort_ (__FILE__, __LINE__); } while (0)
+
+
+#endif