[master] f6cae5a75 Generate an array of lines for the varnishstat help

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Wed Apr 1 07:49:08 UTC 2020


commit f6cae5a756beac1cacb2cee9b38e3d7240880ffd
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Thu Mar 5 12:26:41 2020 +0100

    Generate an array of lines for the varnishstat help
    
    Refs #2990

diff --git a/.gitignore b/.gitignore
index 5872c9a6b..c476a47dc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -88,6 +88,8 @@ cscope.*out
 /bin/varnishlog/varnishlog
 /bin/varnishncsa/varnishncsa
 /bin/varnishstat/varnishstat
+/bin/varnishstat/varnishstat_help_gen
+/bin/varnishstat/varnishstat_curses_help.c
 /bin/varnishstat/vsc2rst
 /bin/varnishtest/teken_state.h
 /bin/varnishtest/varnishtest
diff --git a/bin/varnishstat/Makefile.am b/bin/varnishstat/Makefile.am
index 2e29e7932..6721d3437 100644
--- a/bin/varnishstat/Makefile.am
+++ b/bin/varnishstat/Makefile.am
@@ -4,15 +4,26 @@ AM_CPPFLAGS = \
 	-I$(top_srcdir)/include \
 	-I$(top_builddir)/include
 
-bin_PROGRAMS = varnishstat
+bin_PROGRAMS = varnishstat varnishstat_help_gen
 
 varnishstat_SOURCES = \
 	varnishstat.h \
 	varnishstat.c \
 	varnishstat_bindings.h \
 	varnishstat_curses.c \
+	varnishstat_curses_help.c \
 	varnishstat_options.h
 
+BUILT_SOURCES = varnishstat_curses_help.c
+
+varnishstat_help_gen_SOURCES = \
+	varnishstat_help_gen.c \
+	varnishstat_bindings.h
+
+varnishstat_curses_help.c: varnishstat_help_gen
+	$(AM_V_GEN) ./varnishstat_help_gen >$@_
+	@mv $@_ $@
+
 varnishstat_CFLAGS = \
 	@SAN_CFLAGS@
 
@@ -20,3 +31,7 @@ varnishstat_LDADD = \
 	$(top_builddir)/lib/libvarnishapi/libvarnishapi.la \
 	@SAN_LDFLAGS@ \
 	@CURSES_LIBS@ ${RT_LIBS} ${LIBM} ${PTHREAD_LIBS}
+
+varnishstat_help_gen_LDADD = \
+	$(top_builddir)/lib/libvarnish/libvarnish.la \
+	@SAN_LDFLAGS@
diff --git a/bin/varnishstat/varnishstat.h b/bin/varnishstat/varnishstat.h
index 4b0377864..2785407d6 100644
--- a/bin/varnishstat/varnishstat.h
+++ b/bin/varnishstat/varnishstat.h
@@ -38,3 +38,6 @@
 #include "vcs.h"
 
 void do_curses(struct vsm *,  struct vsc *);
+
+extern const char *const bindings_help[];
+extern const int bindings_help_len;
diff --git a/bin/varnishstat/varnishstat_help_gen.c b/bin/varnishstat/varnishstat_help_gen.c
new file mode 100644
index 000000000..1c189bcd8
--- /dev/null
+++ b/bin/varnishstat/varnishstat_help_gen.c
@@ -0,0 +1,86 @@
+/*-
+ * Copyright (c) 2020 Varnish Software AS
+ * All rights reserved.
+ *
+ * Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stddef.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <vdef.h>
+#include <vas.h>
+#include <vsb.h>
+
+static const char help[] = "\n\n"
+#define BINDING_KEY(key, name, next) "<" name ">" next
+#define BINDING(name, desc) "\n\n" desc "\n\n"
+#include "varnishstat_bindings.h"
+;
+
+int
+main(void)
+{
+	struct vsb vsb[1];
+	const char *p, *n;
+	unsigned u;
+
+	AN(VSB_new(vsb, NULL, 0, VSB_AUTOEXTEND));
+	VSB_cat(vsb,
+	    "/*\n"
+	    " * NB:  This file is machine generated, DO NOT EDIT!\n"
+	    " *\n"
+	    " * Edit varnishstat_bindings.h and run make instead\n"
+	    " */\n"
+	    "\n"
+	    "#include <stddef.h>\n"
+	    "\n"
+	    "const char *const bindings_help[] = {\n");
+
+	n = help;
+	u = 0;
+	do {
+		p = n + 1;
+		n = strchr(p, '\n');
+		if (n != NULL) {
+			VSB_putc(vsb, '\t');
+			VSB_quote(vsb, p, (int)(n - p), VSB_QUOTE_CSTR);
+			VSB_cat(vsb, ",\n");
+			u++;
+		}
+	} while (n != NULL);
+
+	VSB_printf(vsb,
+	    "\tNULL\n"
+	    "};\n"
+	    "\n"
+	    "const int bindings_help_len = %u;\n", u);
+	AZ(VSB_finish(vsb));
+	AZ(VSB_tofile(vsb, STDOUT_FILENO));
+	VSB_delete(vsb);
+	return (0);
+}


More information about the varnish-commit mailing list