diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-10-13 12:44:12 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-10-13 12:48:04 +0300 |
commit | 23f262e8c6181465347c3bb47644f9d86fcb7432 (patch) | |
tree | cdf5ac3a861395ade00b71e7b8cdd641db67032c | |
parent | 510fc646f13b843d046323e3477edb6c1bc2258d (diff) | |
download | vmod-binlog-23f262e8c6181465347c3bb47644f9d86fcb7432.tar.gz vmod-binlog-23f262e8c6181465347c3bb47644f9d86fcb7432.tar.bz2 |
* src/Makefile.am: New convenience library libbinlog.a
* src/binlogcat.c: Use functions from libbinlog.a
* src/err.h: New file.
* src/err.c: New file.
* tests/.gitignore: Add binpack.c
* tests/Makefile.am: Build binpack.c
* tests/binpack.c: New file.
-rw-r--r-- | src/Makefile.am | 10 | ||||
-rw-r--r-- | src/binlogcat.c | 34 | ||||
-rw-r--r-- | src/err.c | 62 | ||||
-rw-r--r-- | src/err.h | 21 | ||||
-rw-r--r-- | tests/.gitignore | 1 | ||||
-rw-r--r-- | tests/Makefile.am | 7 | ||||
-rw-r--r-- | tests/binpack.c | 86 |
7 files changed, 187 insertions, 34 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 9ce519f..4e31e89 100644 --- a/src/Makefile.am +++ b/src/Makefile.am | |||
@@ -16,9 +16,13 @@ | |||
16 | 16 | ||
17 | AM_CPPFLAGS = -I$(VARNISHSRC)/include -I$(VARNISHSRC) | 17 | AM_CPPFLAGS = -I$(VARNISHSRC)/include -I$(VARNISHSRC) |
18 | 18 | ||
19 | noinst_LIBRARIES = libbinlog.a | ||
20 | libbinlog_a_SOURCES = pack.c err.c | ||
21 | libbinlog_a_CFLAGS = $(AM_CFLAGS) | ||
22 | |||
19 | bin_PROGRAMS = binlogcat | 23 | bin_PROGRAMS = binlogcat |
20 | binlogcat_SOURCES = binlogcat.c pack.c | 24 | binlogcat_SOURCES = binlogcat.c |
21 | binlogcat_CFLAGS = $(AM_CFLAGS) | 25 | binlogcat_LDADD = ./libbinlog.a |
22 | 26 | ||
23 | vmoddir = $(VMODDIR) | 27 | vmoddir = $(VMODDIR) |
24 | vmod_LTLIBRARIES = libvmod_binlog.la | 28 | vmod_LTLIBRARIES = libvmod_binlog.la |
@@ -32,7 +36,7 @@ libvmod_binlog_la_SOURCES = \ | |||
32 | vmod-binlog.h\ | 36 | vmod-binlog.h\ |
33 | vcc_if.c vcc_if.h | 37 | vcc_if.c vcc_if.h |
34 | 38 | ||
35 | noinst_HEADERS = pack.h | 39 | noinst_HEADERS = pack.h err.h |
36 | 40 | ||
37 | BUILT_SOURCES = vcc_if.c vcc_if.h | 41 | BUILT_SOURCES = vcc_if.c vcc_if.h |
38 | 42 | ||
diff --git a/src/binlogcat.c b/src/binlogcat.c index 8cdfaaa..bdeb992 100644 --- a/src/binlogcat.c +++ b/src/binlogcat.c | |||
@@ -26,42 +26,14 @@ | |||
26 | #include <string.h> | 26 | #include <string.h> |
27 | #include "vmod-binlog.h" | 27 | #include "vmod-binlog.h" |
28 | #include "pack.h" | 28 | #include "pack.h" |
29 | #include "err.h" | ||
29 | 30 | ||
30 | char *progname; | ||
31 | char *timefmt = "%c"; | 31 | char *timefmt = "%c"; |
32 | int number_option; | 32 | int number_option; |
33 | int verbose_option; | 33 | int verbose_option; |
34 | int timediff_option; | 34 | int timediff_option; |
35 | 35 | ||
36 | void | 36 | void |
37 | verror(const char *fmt, va_list ap) | ||
38 | { | ||
39 | fprintf(stderr, "%s: ", progname); | ||
40 | vfprintf(stderr, fmt, ap); | ||
41 | fputc('\n', stderr); | ||
42 | } | ||
43 | |||
44 | void | ||
45 | error(const char *fmt, ...) | ||
46 | { | ||
47 | va_list ap; | ||
48 | |||
49 | va_start(ap, fmt); | ||
50 | verror(fmt, ap); | ||
51 | va_end(ap); | ||
52 | } | ||
53 | |||
54 | void | ||
55 | packerror(const char *fmt, ...) | ||
56 | { | ||
57 | va_list ap; | ||
58 | |||
59 | va_start(ap, fmt); | ||
60 | verror(fmt, ap); | ||
61 | va_end(ap); | ||
62 | } | ||
63 | |||
64 | void | ||
65 | catlog(const char *fname) | 37 | catlog(const char *fname) |
66 | { | 38 | { |
67 | FILE *fp; | 39 | FILE *fp; |
@@ -98,7 +70,7 @@ catlog(const char *fname) | |||
98 | } | 70 | } |
99 | 71 | ||
100 | if (header.version != BINLOG_VERSION) { | 72 | if (header.version != BINLOG_VERSION) { |
101 | error("%s: unknown version", progname, fname); | 73 | error("%s: unknown version", fname); |
102 | exit(1); | 74 | exit(1); |
103 | } | 75 | } |
104 | 76 | ||
@@ -176,9 +148,9 @@ help() | |||
176 | int | 148 | int |
177 | main(int argc, char **argv) | 149 | main(int argc, char **argv) |
178 | { | 150 | { |
179 | progname = argv[0]; | ||
180 | int c; | 151 | int c; |
181 | 152 | ||
153 | setprogname(argv[0]); | ||
182 | while ((c = getopt(argc, argv, "dht:nv")) != EOF) | 154 | while ((c = getopt(argc, argv, "dht:nv")) != EOF) |
183 | switch (c) { | 155 | switch (c) { |
184 | case 'd': | 156 | case 'd': |
diff --git a/src/err.c b/src/err.c new file mode 100644 index 0000000..73aaba7 --- /dev/null +++ b/src/err.c | |||
@@ -0,0 +1,62 @@ | |||
1 | /* This file is part of vmod-binlog | ||
2 | Copyright (C) 2013 Sergey Poznyakoff | ||
3 | |||
4 | Vmod-binlog is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 3, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | Vmod-binlog is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with vmod-binlog. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | #include <config.h> | ||
18 | #include <stdio.h> | ||
19 | #include <stdarg.h> | ||
20 | #include <string.h> | ||
21 | #include "err.h" | ||
22 | |||
23 | const char *progname; | ||
24 | |||
25 | void | ||
26 | setprogname(const char *arg) | ||
27 | { | ||
28 | char *p = strrchr(arg, '/'); | ||
29 | if (p) | ||
30 | progname = p + 1; | ||
31 | else | ||
32 | progname = arg; | ||
33 | } | ||
34 | |||
35 | void | ||
36 | verror(const char *fmt, va_list ap) | ||
37 | { | ||
38 | fprintf(stderr, "%s: ", progname); | ||
39 | vfprintf(stderr, fmt, ap); | ||
40 | fputc('\n', stderr); | ||
41 | } | ||
42 | |||
43 | void | ||
44 | error(const char *fmt, ...) | ||
45 | { | ||
46 | va_list ap; | ||
47 | |||
48 | va_start(ap, fmt); | ||
49 | verror(fmt, ap); | ||
50 | va_end(ap); | ||
51 | } | ||
52 | |||
53 | void | ||
54 | packerror(const char *fmt, ...) | ||
55 | { | ||
56 | va_list ap; | ||
57 | |||
58 | va_start(ap, fmt); | ||
59 | verror(fmt, ap); | ||
60 | va_end(ap); | ||
61 | } | ||
62 | |||
diff --git a/src/err.h b/src/err.h new file mode 100644 index 0000000..69139fd --- /dev/null +++ b/src/err.h | |||
@@ -0,0 +1,21 @@ | |||
1 | /* This file is part of vmod-binlog | ||
2 | Copyright (C) 2013 Sergey Poznyakoff | ||
3 | |||
4 | Vmod-binlog is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 3, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | Vmod-binlog is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with vmod-binlog. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | extern const char *progname; | ||
18 | |||
19 | void setprogname(const char *); | ||
20 | void error(const char *fmt, ...); | ||
21 | void packerror(const char *fmt, ...); | ||
diff --git a/tests/.gitignore b/tests/.gitignore index 93f8f46..f689f0d 100644 --- a/tests/.gitignore +++ b/tests/.gitignore | |||
@@ -1,5 +1,6 @@ | |||
1 | atconfig | 1 | atconfig |
2 | atlocal | 2 | atlocal |
3 | binpack | ||
3 | package.m4 | 4 | package.m4 |
4 | testsuite | 5 | testsuite |
5 | testsuite.dir | 6 | testsuite.dir |
diff --git a/tests/Makefile.am b/tests/Makefile.am index 7f24aeb..4e3bc7b 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am | |||
@@ -65,6 +65,13 @@ check-local: atconfig atlocal $(TESTSUITE) | |||
65 | #installcheck-local: | 65 | #installcheck-local: |
66 | # $(SHELL) $(TESTSUITE) AUTOTEST_PATH=$(exec_prefix)/bin | 66 | # $(SHELL) $(TESTSUITE) AUTOTEST_PATH=$(exec_prefix)/bin |
67 | 67 | ||
68 | check_PROGRAMS = binpack | ||
69 | binpack_SOURCES = binpack.c | ||
70 | binpack_LDADD = ../src/libbinlog.a | ||
71 | |||
72 | binpack_CFLAGS = $(AM_CFLAGS) | ||
73 | |||
74 | AM_CPPFLAGS = -I$(top_srcdir)/src | ||
68 | 75 | ||
69 | 76 | ||
70 | 77 | ||
diff --git a/tests/binpack.c b/tests/binpack.c new file mode 100644 index 0000000..b54ed80 --- /dev/null +++ b/tests/binpack.c | |||
@@ -0,0 +1,86 @@ | |||
1 | /* This file is part of vmod-binlog | ||
2 | Copyright (C) 2013 Sergey Poznyakoff | ||
3 | |||
4 | Vmod-binlog is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 3, or (at your option) | ||
7 | any later version. | ||
8 | |||