aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2013-10-13 12:44:12 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2013-10-13 12:48:04 +0300
commit23f262e8c6181465347c3bb47644f9d86fcb7432 (patch)
treecdf5ac3a861395ade00b71e7b8cdd641db67032c
parent510fc646f13b843d046323e3477edb6c1bc2258d (diff)
downloadvmod-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.am10
-rw-r--r--src/binlogcat.c34
-rw-r--r--src/err.c62
-rw-r--r--src/err.h21
-rw-r--r--tests/.gitignore1
-rw-r--r--tests/Makefile.am7
-rw-r--r--tests/binpack.c86
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
17AM_CPPFLAGS = -I$(VARNISHSRC)/include -I$(VARNISHSRC) 17AM_CPPFLAGS = -I$(VARNISHSRC)/include -I$(VARNISHSRC)
18 18
19noinst_LIBRARIES = libbinlog.a
20libbinlog_a_SOURCES = pack.c err.c
21libbinlog_a_CFLAGS = $(AM_CFLAGS)
22
19bin_PROGRAMS = binlogcat 23bin_PROGRAMS = binlogcat
20binlogcat_SOURCES = binlogcat.c pack.c 24binlogcat_SOURCES = binlogcat.c
21binlogcat_CFLAGS = $(AM_CFLAGS) 25binlogcat_LDADD = ./libbinlog.a
22 26
23vmoddir = $(VMODDIR) 27vmoddir = $(VMODDIR)
24vmod_LTLIBRARIES = libvmod_binlog.la 28vmod_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
35noinst_HEADERS = pack.h 39noinst_HEADERS = pack.h err.h
36 40
37BUILT_SOURCES = vcc_if.c vcc_if.h 41BUILT_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
30char *progname;
31char *timefmt = "%c"; 31char *timefmt = "%c";
32int number_option; 32int number_option;
33int verbose_option; 33int verbose_option;
34int timediff_option; 34int timediff_option;
35 35
36void 36void
37verror(const char *fmt, va_list ap)
38{
39 fprintf(stderr, "%s: ", progname);
40 vfprintf(stderr, fmt, ap);
41 fputc('\n', stderr);
42}
43
44void
45error(const char *fmt, ...)
46{
47 va_list ap;
48
49 va_start(ap, fmt);
50 verror(fmt, ap);
51 va_end(ap);
52}
53
54void
55packerror(const char *fmt, ...)
56{
57 va_list ap;
58
59 va_start(ap, fmt);
60 verror(fmt, ap);
61 va_end(ap);
62}
63
64void
65catlog(const char *fname) 37catlog(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()
176int 148int
177main(int argc, char **argv) 149main(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
23const char *progname;
24
25void
26setprogname(const char *arg)
27{
28 char *p = strrchr(arg, '/');
29 if (p)
30 progname = p + 1;
31 else
32 progname = arg;
33}
34
35void
36verror(const char *fmt, va_list ap)
37{
38 fprintf(stderr, "%s: ", progname);
39 vfprintf(stderr, fmt, ap);
40 fputc('\n', stderr);
41}
42
43void
44error(const char *fmt, ...)
45{
46 va_list ap;
47
48 va_start(ap, fmt);
49 verror(fmt, ap);
50 va_end(ap);
51}
52
53void
54packerror(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*/
17extern const char *progname;
18
19void setprogname(const char *);
20void error(const char *fmt, ...);
21void 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 @@
1atconfig 1atconfig
2atlocal 2atlocal
3binpack
3package.m4 4package.m4
4testsuite 5testsuite
5testsuite.dir 6testsuite.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
68check_PROGRAMS = binpack
69binpack_SOURCES = binpack.c
70binpack_LDADD = ../src/libbinlog.a
71
72binpack_CFLAGS = $(AM_CFLAGS)
73
74AM_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
</