[master] 6635286 Make the option documentation be generated from the option tables.

Martin Blix Grydeland martin at varnish-cache.org
Thu Jun 13 12:41:24 CEST 2013


commit 66352862f15cf08fc4ac433293af00d0b81acb7a
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date:   Fri May 24 15:22:32 2013 +0200

    Make the option documentation be generated from the option tables.

diff --git a/bin/varnishlog/Makefile.am b/bin/varnishlog/Makefile.am
index 500d941..f8a63af 100644
--- a/bin/varnishlog/Makefile.am
+++ b/bin/varnishlog/Makefile.am
@@ -23,9 +23,23 @@ varnishlog_LDADD = \
 	$(top_builddir)/lib/libvarnishapi/libvarnishapi.la \
 	${RT_LIBS} ${LIBM} ${PTHREAD_LIBS}
 
-varnishlog.1: $(top_srcdir)/doc/sphinx/reference/varnishlog.rst
+noinst_PROGRAMS = varnishlog_opt2rst
+varnishlog_opt2rst_CFLAGS = -DOPT2RST_INC="varnishlog_options.h"
+varnishlog_opt2rst_SOURCES = \
+	opt2rst.c
+
+BUILT_SOURCES = varnishlog_options.rst
+
+EXTRA_DIST = varnishlog_options.rst
+
+varnishlog_options.rst: varnishlog_opt2rst
+	./varnishlog_opt2rst > $@
+
+varnishlog.1: \
+	$(top_srcdir)/doc/sphinx/reference/varnishlog.rst \
+	varnishlog_options.rst
 if HAVE_RST2MAN
-	${RST2MAN} $? $@
+	${RST2MAN} $< $@
 else
 	@echo "========================================"
 	@echo "You need rst2man installed to make dist"
diff --git a/bin/varnishlog/opt2rst.c b/bin/varnishlog/opt2rst.c
new file mode 100644
index 0000000..ab854ef
--- /dev/null
+++ b/bin/varnishlog/opt2rst.c
@@ -0,0 +1,89 @@
+/*-
+ * Copyright (c) 2006 Verdens Gang AS
+ * Copyright (c) 2006-2013 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 <stdio.h>
+#include <string.h>
+
+#ifndef OPT2RST_INC
+#error "OPT2RST_INC undefined"
+#endif
+
+#define STRINGIFY(x) #x
+#define TOSTRING(x) STRINGIFY(x)
+
+#define VOPT_SYNOPSIS
+#define VOPT_FULL
+#define VOPT_INC TOSTRING(OPT2RST_INC)
+#include "vapi/voptget.h"
+
+static void
+print_nobrackets(const char *s)
+{
+	for (; *s; s++) {
+		if (strchr("[]", *s))
+			continue;
+		printf("%c", *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_full *opt)
+{
+	print_nobrackets(opt->synopsis);
+	printf("\n\n");
+	print_tabbed(opt->ldesc, 1);
+	printf("\n\n");
+}
+
+int
+main(int argc, char * const *argv)
+{
+	int i;
+
+	(void)argc;
+	(void)argv;
+	for (i = 0; i < sizeof vopt_full / sizeof vopt_full[0]; i++)
+		print_opt(&vopt_full[i]);
+
+	return (0);
+}
diff --git a/doc/sphinx/reference/varnishlog.rst b/doc/sphinx/reference/varnishlog.rst
index 1210b24..3e761f8 100644
--- a/doc/sphinx/reference/varnishlog.rst
+++ b/doc/sphinx/reference/varnishlog.rst
@@ -28,9 +28,7 @@ OPTIONS
 
 The following options are available:
 
--a
-
-	When writing to a file, append to it rather than overwrite it.
+.. include:: ../../../bin/varnishlog/varnishlog_options.rst
 
 -b
 
@@ -58,24 +56,6 @@ The following options are available:
 
 	XXX: Not yet implemented
 
--d
-
-	Process old log entries on startup. Nomally, varnishlog will
-	only process entries which are written to the log after it
-	starts.
-
--g {session|request|vxid|raw}
-
-	The grouping of the log records. The default is to group by
-	request.
-
--i tag
-
-	Output only this tag. Multiple -i options may be given.
-
-	If an -i option is the first of any -ix options, all tags are
-	disabled for output before -ix processing.
-
 -I [tag:]regex
 
 	Output only records matching this regular expression. If tag
@@ -91,22 +71,12 @@ The following options are available:
 
 	XXX: Not yet implemented
 
--n
-
-	Specifies the name of the varnishd instance to get logs
-	from. If -n is not specified, the host name is used.
-
-
 -P file
 
 	Write the process' PID to the specified file.
 
 	XXX: Not yet implemented
 
--r file
-
-	Read log entries from file instaed of shared memory
-
 -s num
 
 	Skip the first num log transactions (or log records if
@@ -120,35 +90,12 @@ The following options are available:
 
 	XXX: Not yet implemented
 
--v
-
-	Use verbose output on set output, giving the VXID on every log
-	line. Without this option, the VXID will only be given on the
-	header of that transaction.
-
 -V
 
 	Display the version number and exit.
 
 	XXX: Not yet implemented
 
--w file
-
-	Write log entries to file instead of displaying them.  The
-   	file will be overwritten unless the -a option was
-   	specified. If varnishlog receives a SIGHUP while writing to a
-   	file, it will reopen the file, allowing the old one to be
-   	rotated away.
-
-	XXX: Log rotation not yet implemented
-
--x tag
-
-	Exclude log records of this tag. Multiple -x options may be
-	given.
-
-	If an -x option is the first of any -ix options, all tags are
-	enabled for output before -ix processing.
 
 -X [tag:]regex
 



More information about the varnish-commit mailing list