[master] 6b2a3a3 Fix rst option generation

Martin Blix Grydeland martin at varnish-cache.org
Thu Jun 13 14:47:47 CEST 2013


commit 6b2a3a3909275a6cc0dbeccbb5356c732f176c9c
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date:   Thu Jun 13 14:47:26 2013 +0200

    Fix rst option generation

diff --git a/include/vapi/vapi_options.h b/include/vapi/vapi_options.h
index a6f316a..df3dc83 100644
--- a/include/vapi/vapi_options.h
+++ b/include/vapi/vapi_options.h
@@ -60,7 +60,7 @@
 	)
 
 #define VSL_OPT_g							\
-	VOPT("g:", "[-g {session|request|vxid|raw}]", "Grouping mode",	\
+	VOPT("g:", "[-g <session|request|vxid|raw>]", "Grouping mode",	\
 	    "The grouping of the log records. The default is to group"	\
 	    " by request."						\
 	)
@@ -74,7 +74,7 @@
 	)
 
 #define VSL_OPT_I							\
-	VOPT("I:", "[-I [tag:]regex]", "Include by regex",		\
+	VOPT("I:", "[-I <[tag:]regex>]", "Include by regex",		\
 	    "Include by regex matching. Output only records matching"	\
 	    " tag and regular expression. Applies to any tag if tag"	\
 	    " is * or empty.\n"						\
@@ -115,7 +115,7 @@
 	)
 
 #define VSL_OPT_X							\
-	VOPT("X:", "[-X [tag:]regex]", "Exclude by regex",		\
+	VOPT("X:", "[-X <[tag:]regex>]", "Exclude by regex",		\
 	    "Exclude by regex matching. Do not output records matching"	\
 	    " tag and regular expression. Applies to any tag if tag"	\
 	    " is * or empty."						\
diff --git a/lib/libvarnishtools/opt2rst.c b/lib/libvarnishtools/opt2rst.c
index 1ed08e0..68d5200 100644
--- a/lib/libvarnishtools/opt2rst.c
+++ b/lib/libvarnishtools/opt2rst.c
@@ -30,17 +30,29 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include <ctype.h>
 
 #include "vapi/voptget.h"
 
 static void
 print_nobrackets(const char *s)
 {
-	for (; *s; s++) {
-		if (strchr("[]", *s))
-			continue;
-		printf("%c", *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



More information about the varnish-commit mailing list