diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main/Makefile.am | 7 | ||||
-rw-r--r-- | src/main/extractor_logging.c | 68 | ||||
-rw-r--r-- | src/main/extractor_logging.h | 72 |
3 files changed, 144 insertions, 3 deletions
diff --git a/src/main/Makefile.am b/src/main/Makefile.am index 1fe415d..2d32ca6 100644 --- a/src/main/Makefile.am +++ b/src/main/Makefile.am | |||
@@ -40,13 +40,14 @@ EXTRA_DIST = \ | |||
40 | libextractor_la_CPPFLAGS = -DPLUGINDIR=\"@RPLUGINDIR@\" -DPLUGININSTDIR=\"${plugindir}\" $(AM_CPPFLAGS) | 40 | libextractor_la_CPPFLAGS = -DPLUGINDIR=\"@RPLUGINDIR@\" -DPLUGININSTDIR=\"${plugindir}\" $(AM_CPPFLAGS) |
41 | 41 | ||
42 | libextractor_la_SOURCES = \ | 42 | libextractor_la_SOURCES = \ |
43 | extractor_metatypes.c \ | ||
44 | extractor_print.c \ | ||
45 | extractor_common.c extractor_common.h \ | 43 | extractor_common.c extractor_common.h \ |
46 | extractor_datasource.c extractor_datasource.h \ | 44 | extractor_datasource.c extractor_datasource.h \ |
45 | $(EXTRACTOR_IPC) extractor_ipc.c extractor_ipc.h \ | ||
46 | extractor_logging.c extractor_logging.h \ | ||
47 | extractor_metatypes.c \ | ||
47 | extractor_plugpath.c extractor_plugpath.h \ | 48 | extractor_plugpath.c extractor_plugpath.h \ |
48 | extractor_plugins.c extractor_plugins.h \ | 49 | extractor_plugins.c extractor_plugins.h \ |
49 | $(EXTRACTOR_IPC) extractor_ipc.c extractor_ipc.h \ | 50 | extractor_print.c \ |
50 | extractor_plugin_main.c extractor_plugin_main.h \ | 51 | extractor_plugin_main.c extractor_plugin_main.h \ |
51 | extractor.c | 52 | extractor.c |
52 | 53 | ||
diff --git a/src/main/extractor_logging.c b/src/main/extractor_logging.c new file mode 100644 index 0000000..449ffbe --- /dev/null +++ b/src/main/extractor_logging.c | |||
@@ -0,0 +1,68 @@ | |||
1 | /* | ||
2 | This file is part of libextractor. | ||
3 | (C) 2012 Vidyut Samanta and Christian Grothoff | ||
4 | |||
5 | libextractor is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | libextractor is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with libextractor; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | /** | ||
21 | * @file main/extractor_logging.c | ||
22 | * @brief logging API for GNU libextractor | ||
23 | * @author Christian Grothoff | ||
24 | */ | ||
25 | #include "platform.h" | ||
26 | #include "extractor_logging.h" | ||
27 | |||
28 | #if DEBUG | ||
29 | /** | ||
30 | * Log function. | ||
31 | * | ||
32 | * @param file name of file with the error | ||
33 | * @param line line number with the error | ||
34 | * @param ... log message and arguments | ||
35 | */ | ||
36 | void | ||
37 | EXTRACTOR_log_ (const char *file, int line, const char *format, ...) | ||
38 | { | ||
39 | va_list va; | ||
40 | |||
41 | fprintf (stderr, | ||
42 | sizeof (file_line), | ||
43 | "EXTRACTOR %s:%d "); | ||
44 | va_start (va, format); | ||
45 | vfprintf (stderr, format, va); | ||
46 | va_end (va); | ||
47 | fflush (stderr); | ||
48 | } | ||
49 | #endif | ||
50 | |||
51 | |||
52 | /** | ||
53 | * Abort the program reporting an assertion failure | ||
54 | * | ||
55 | * @param file filename with the failure | ||
56 | * @param line line number with the failure | ||
57 | */ | ||
58 | void | ||
59 | EXTRACTOR_abort_ (const char *file, | ||
60 | int line) | ||
61 | { | ||
62 | #if DEBUG | ||
63 | EXTRACTOR_log_ (file, line, "Assertion failed.\n"); | ||
64 | #endif | ||
65 | abort (); | ||
66 | } | ||
67 | |||
68 | /* end of extractor_logging.c */ | ||
diff --git a/src/main/extractor_logging.h b/src/main/extractor_logging.h new file mode 100644 index 0000000..2e589e1 --- /dev/null +++ b/src/main/extractor_logging.h | |||
@@ -0,0 +1,72 @@ | |||
1 | /* | ||
2 | This file is part of libextractor. | ||
3 | (C) 2012 Vidyut Samanta and Christian Grothoff | ||
4 | |||
5 | libextractor is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | libextractor is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with libextractor; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | /** | ||
21 | * @file main/extractor_logging.h | ||
22 | * @brief logging API for GNU libextractor | ||
23 | * @author Christian Grothoff | ||
24 | */ | ||
25 | #ifndef EXTRACTOR_LOGGING_H | ||
26 | #define EXTRACTOR_LOGGING_H | ||
27 | |||
28 | #define DEBUG 1 | ||
29 | |||
30 | #if DEBUG | ||
31 | |||
32 | /** | ||
33 | * Log function. | ||
34 | * | ||
35 | * @param file name of file with the error | ||
36 | * @param line line number with the error | ||
37 | * @param ... log message and arguments | ||
38 | */ | ||
39 | void | ||
40 | EXTRACTOR_log_ (const char *file, int line, const char *format, ...); | ||
41 | |||
42 | /** | ||
43 | * Log a message. | ||
44 | * | ||
45 | * @param fmt format string | ||
46 | * @param ... arguments for fmt (printf-style) | ||
47 | */ | ||
48 | #define LOG(fmt, ...) EXTRACTOR_log_ (__FILE__, __LINE__, fmt, __VA_ARGS__) | ||
49 | #else | ||
50 | #define LOG(...) | ||
51 | #endif | ||
52 | |||
53 | |||
54 | /** | ||
55 | * Abort the program reporting an assertion failure | ||
56 | * | ||
57 | * @param file filename with the failure | ||
58 | * @param line line number with the failure | ||
59 | */ | ||
60 | void | ||
61 | EXTRACTOR_abort_ (const char *file, | ||
62 | int line); | ||
63 | |||
64 | /** | ||
65 | * Abort program if assertion fails. | ||
66 | * | ||
67 | * @param cond assertion that must hold. | ||
68 | */ | ||
69 | #define ASSERT(cond) do { if (! (cond)) EXTRACTOR_abort_ (__FILE__, __LINE__); } while (0) | ||
70 | |||
71 | |||
72 | #endif | ||