[master] 32670d7 Somehow I lost half the changed to get rid of opt2rst programs.

Poul-Henning Kamp phk at FreeBSD.org
Tue May 10 12:04:08 CEST 2016


commit 32670d7d50b21dfa842f17ef1b52adeae3434a8c
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue May 10 10:02:40 2016 +0000

    Somehow I lost half the changed to get rid of opt2rst programs.
    
    Here it is.

diff --git a/.gitignore b/.gitignore
index fe1e27e..1f5e586 100644
--- a/.gitignore
+++ b/.gitignore
@@ -83,7 +83,6 @@ cscope.*out
 /man/*.7
 /doc/sphinx/include
 /doc/sphinx/*/*generated.rst
-/bin/varnish*/varnish*_opt2rst
 /bin/varnishadm/varnishadm
 /bin/varnishd/varnishd
 /bin/varnishhist/varnishhist
diff --git a/bin/varnishhist/Makefile.am b/bin/varnishhist/Makefile.am
index e4d5e97..c8d2820 100644
--- a/bin/varnishhist/Makefile.am
+++ b/bin/varnishhist/Makefile.am
@@ -25,9 +25,3 @@ varnishhist_LDADD = \
 	-lm \
 	@SAN_LDFLAGS@ \
 	@CURSES_LIB@ ${RT_LIBS} ${PTHREAD_LIBS}
-
-noinst_PROGRAMS = varnishhist_opt2rst
-varnishhist_opt2rst_SOURCES = \
-	varnishhist_options.h \
-	varnishhist_options.c \
-	$(top_srcdir)/lib/libvarnishtools/opt2rst.c
diff --git a/bin/varnishhist/varnishhist.c b/bin/varnishhist/varnishhist.c
index f279dc3..31a40af 100644
--- a/bin/varnishhist/varnishhist.c
+++ b/bin/varnishhist/varnishhist.c
@@ -385,9 +385,7 @@ main(int argc, char **argv)
 	struct profile cli_p = {0};
 	cli_p.name = 0;
 
-	VUT_Init(progname);
-	if (0)
-		(void)usage;
+	VUT_Init(progname, argc, argv);
 
 	/* only client requests */
 	assert(VUT_Arg('c', NULL));
diff --git a/bin/varnishlog/Makefile.am b/bin/varnishlog/Makefile.am
index d291d62..80c7ed2 100644
--- a/bin/varnishlog/Makefile.am
+++ b/bin/varnishlog/Makefile.am
@@ -26,9 +26,3 @@ varnishlog_LDADD = \
 	$(top_builddir)/lib/libvarnishapi/libvarnishapi.la \
 	@SAN_LDFLAGS@ \
 	${RT_LIBS} ${LIBM} ${PTHREAD_LIBS}
-
-noinst_PROGRAMS = varnishlog_opt2rst
-varnishlog_opt2rst_SOURCES = \
-	varnishlog_options.h \
-	varnishlog_options.c \
-	$(top_srcdir)/lib/libvarnishtools/opt2rst.c
diff --git a/bin/varnishlog/varnishlog.c b/bin/varnishlog/varnishlog.c
index bc4a915..d8be34f 100644
--- a/bin/varnishlog/varnishlog.c
+++ b/bin/varnishlog/varnishlog.c
@@ -121,8 +121,8 @@ main(int argc, char * const *argv)
 {
 	int opt;
 
+	VUT_Init(progname, argc, argv);
 	memset(&LOG, 0, sizeof LOG);
-	VUT_Init(progname);
 
 	while ((opt = getopt(argc, argv, vopt_optstring)) != -1) {
 		switch (opt) {
diff --git a/bin/varnishncsa/Makefile.am b/bin/varnishncsa/Makefile.am
index 077b33c..dcdd7b2 100644
--- a/bin/varnishncsa/Makefile.am
+++ b/bin/varnishncsa/Makefile.am
@@ -28,9 +28,3 @@ varnishncsa_LDADD = \
 	$(top_builddir)/lib/libvarnishapi/libvarnishapi.la \
 	@SAN_LDFLAGS@ \
 	${RT_LIBS} ${LIBM}
-
-noinst_PROGRAMS = varnishncsa_opt2rst
-varnishncsa_opt2rst_SOURCES = \
-	varnishncsa_options.h \
-	varnishncsa_options.c \
-	$(top_srcdir)/lib/libvarnishtools/opt2rst.c
diff --git a/bin/varnishncsa/varnishncsa.c b/bin/varnishncsa/varnishncsa.c
index 5827458..13e28d9 100644
--- a/bin/varnishncsa/varnishncsa.c
+++ b/bin/varnishncsa/varnishncsa.c
@@ -1126,6 +1126,7 @@ main(int argc, char * const *argv)
 	signed char opt;
 	char *format = NULL;
 
+	VUT_Init(progname, argc, argv);
 	memset(&CTX, 0, sizeof CTX);
 	VTAILQ_INIT(&CTX.format);
 	VTAILQ_INIT(&CTX.watch_vcl_log);
@@ -1135,7 +1136,6 @@ main(int argc, char * const *argv)
 	CTX.vsb = VSB_new_auto();
 	AN(CTX.vsb);
 	VB64_init();
-	VUT_Init(progname);
 
 	while ((opt = getopt(argc, argv, vopt_optstring)) != -1) {
 		switch (opt) {
diff --git a/bin/varnishtop/Makefile.am b/bin/varnishtop/Makefile.am
index afed891..4757839 100644
--- a/bin/varnishtop/Makefile.am
+++ b/bin/varnishtop/Makefile.am
@@ -26,9 +26,3 @@ varnishtop_LDADD = \
 	$(top_builddir)/lib/libvarnishapi/libvarnishapi.la \
 	@SAN_LDFLAGS@ \
 	@CURSES_LIB@ ${RT_LIBS} ${LIBM} ${PTHREAD_LIBS}
-
-noinst_PROGRAMS = varnishtop_opt2rst
-varnishtop_opt2rst_SOURCES = \
-	varnishtop_options.h \
-	varnishtop_options.c \
-	$(top_srcdir)/lib/libvarnishtools/opt2rst.c
diff --git a/bin/varnishtop/varnishtop.c b/bin/varnishtop/varnishtop.c
index 9c555cc..e91f825 100644
--- a/bin/varnishtop/varnishtop.c
+++ b/bin/varnishtop/varnishtop.c
@@ -329,7 +329,7 @@ main(int argc, char **argv)
 	int o, once = 0;
 	pthread_t thr;
 
-	VUT_Init(progname);
+	VUT_Init(progname, argc, argv);
 
 	while ((o = getopt(argc, argv, vopt_optstring)) != -1) {
 		switch (o) {
diff --git a/include/vut.h b/include/vut.h
index 241aa94..fe99095 100644
--- a/include/vut.h
+++ b/include/vut.h
@@ -74,7 +74,7 @@ int VUT_Arg(int opt, const char *arg);
 
 void VUT_Setup(void);
 
-void VUT_Init(const char *progname);
+void VUT_Init(const char *progname, int argc, char * const *argv);
 
 void VUT_Fini(void);
 
diff --git a/lib/libvarnishtools/Makefile.am b/lib/libvarnishtools/Makefile.am
index 1a14212..5fffe27 100644
--- a/lib/libvarnishtools/Makefile.am
+++ b/lib/libvarnishtools/Makefile.am
@@ -1,5 +1,4 @@
 #
 
 EXTRA_DIST = \
-	vut.c \
-	opt2rst.c
+	vut.c
diff --git a/lib/libvarnishtools/opt2rst.c b/lib/libvarnishtools/opt2rst.c
deleted file mode 100644
index efaf10c..0000000
--- a/lib/libvarnishtools/opt2rst.c
+++ /dev/null
@@ -1,104 +0,0 @@
-/*-
- * Copyright (c) 2006 Verdens Gang AS
- * Copyright (c) 2006-2014 Varnish Software AS
- * All rights reserved.
- *
- * Author: Martin Blix Grydeland <martin at varnish-software.com>
- *
- * 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 <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <ctype.h>
-
-#include "vapi/voptget.h"
-
-static void
-print_nobrackets(const char *s)
-{
-	const char *e;
-
-	/* Remove whitespace */
-	while (isspace(*s))
-		s++;
-	e = s + strlen(s);
-	while (e > s && isspace(e[-1]))
-		e--;
-
-	/* Remove outer layer brackets if present */
-	if (e > s && *s == '[' && e[-1] == ']') {
-		s++;
-		e--;
-	}
-
-	printf("%.*s", (int)(e - s), s);
-}
-
-static void
-print_tabbed(const char *string, int tabs)
-{
-	int i;
-	const char *c;
-
-	for (c = string; *c; c++) {
-		if (c == string || *(c - 1) == '\n')
-			for (i = 0; i < tabs; i++)
-				printf("\t");
-		printf("%c", *c);
-	}
-}
-
-static void
-print_opt(const struct vopt_list *opt)
-{
-	print_nobrackets(opt->synopsis);
-	printf("\n\n");
-	print_tabbed(opt->ldesc, 1);
-	printf("\n\n");
-}
-
-static void
-usage(void)
-{
-	fprintf(stderr, "Usage: opt2rst {synopsis|options}\n");
-	exit(1);
-}
-
-int
-main(int argc, char * const *argv)
-{
-	int i;
-
-	if (argc != 2)
-		usage();
-	if (!strcmp(argv[1], "synopsis"))
-		printf(".. |synopsis| replace:: %s\n", vopt_synopsis);
-	else if (!strcmp(argv[1], "options"))
-		for (i = 0; i < vopt_list_n; i++)
-			print_opt(&vopt_list[i]);
-	else
-		usage();
-
-	return (0);
-}
diff --git a/lib/libvarnishtools/vut.c b/lib/libvarnishtools/vut.c
index f534266..e62c128 100644
--- a/lib/libvarnishtools/vut.c
+++ b/lib/libvarnishtools/vut.c
@@ -31,6 +31,7 @@
 
 #include "config.h"
 
+#include <ctype.h>
 #include <stdint.h>
 #include <stdarg.h>
 #include <stdlib.h>
@@ -56,6 +57,9 @@
 
 struct VUT VUT;
 
+static int vut_synopsis(void);
+static int vut_options(void);
+
 static void
 vut_vpf_remove(void)
 {
@@ -201,8 +205,14 @@ VUT_Arg(int opt, const char *arg)
 }
 
 void
-VUT_Init(const char *progname)
+VUT_Init(const char *progname, int argc, char * const *argv)
 {
+
+	if (argc == 2 && !strcmp(argv[1], "--synopsis"))
+		exit(vut_synopsis());
+	if (argc == 2 && !strcmp(argv[1], "--options"))
+		exit(vut_options());
+
 	VUT.progname = progname;
 	REPLACE(VUT.name, "");
 	VUT.g_arg = VSL_g_vxid;
@@ -421,3 +431,69 @@ VUT_Main(void)
 
 	return (i);
 }
+
+/**********************************************************************/
+
+
+#include "vapi/voptget.h"
+
+static void
+print_nobrackets(const char *s)
+{
+	const char *e;
+
+	/* Remove whitespace */
+	while (isspace(*s))
+		s++;
+	e = s + strlen(s);
+	while (e > s && isspace(e[-1]))
+		e--;
+
+	/* Remove outer layer brackets if present */
+	if (e > s && *s == '[' && e[-1] == ']') {
+		s++;
+		e--;
+	}
+
+	printf("%.*s", (int)(e - s), s);
+}
+
+static void
+print_tabbed(const char *string, int tabs)
+{
+	int i;
+	const char *c;
+
+	for (c = string; *c; c++) {
+		if (c == string || *(c - 1) == '\n')
+			for (i = 0; i < tabs; i++)
+				printf("\t");
+		printf("%c", *c);
+	}
+}
+
+static void
+print_opt(const struct vopt_list *opt)
+{
+	print_nobrackets(opt->synopsis);
+	printf("\n\n");
+	print_tabbed(opt->ldesc, 1);
+	printf("\n\n");
+}
+
+static int
+vut_synopsis(void)
+{
+	printf(".. |synopsis| replace:: %s\n", vopt_synopsis);
+	return (0);
+}
+
+static int
+vut_options(void)
+{
+	int i;
+
+	for (i = 0; i < vopt_list_n; i++)
+		print_opt(&vopt_list[i]);
+	return (0);
+}



More information about the varnish-commit mailing list