]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MINOR] config: provide a function to quote args in a more friendly way
authorWilly Tarreau <w@1wt.eu>
Mon, 14 Jun 2010 17:09:21 +0000 (19:09 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 14 Jun 2010 17:09:21 +0000 (19:09 +0200)
The quote_arg() function can be used to quote an argument or indicate
"end of line" if it's null or empty. It should be useful to more precisely
report location of problems in the configuration.

include/common/standard.h
src/standard.c

index eff47e749443c9791ac347c5f7330c3841264d6d..2366f9e43b30d13ba203d8123a4069e6cb870dad 100644 (file)
@@ -384,4 +384,10 @@ int word_match(const char *sample, int slen, const char *word, int wlen);
  */
 int buf2ip(const char *buf, size_t len, struct in_addr *dst);
 
+/* To be used to quote config arg positions. Returns the string at <ptr>
+ * surrounded by simple quotes if <ptr> is valid and non-empty, or "end of line"
+ * if ptr is NULL or empty. The string is locally allocated.
+ */
+const char *quote_arg(const char *ptr);
+
 #endif /* _COMMON_STANDARD_H */
index 3f3e6bd0e634c692495f4e755fd05b5596dce08a..12954b0c7c5787feb1be66f57d4cac119469900e 100644 (file)
@@ -1059,6 +1059,25 @@ int buf2ip(const char *buf, size_t len, struct in_addr *dst)
        return addr - cp;
 }
 
+/* To be used to quote config arg positions. Returns the short string at <ptr>
+ * surrounded by simple quotes if <ptr> is valid and non-empty, or "end of line"
+ * if ptr is NULL or empty. The string is locally allocated.
+ */
+const char *quote_arg(const char *ptr)
+{
+       static char val[32];
+       int i;
+
+       if (!ptr || !*ptr)
+               return "end of line";
+       val[0] = '\'';
+       for (i = 1; i < sizeof(val) - 1 && *ptr; i++)
+               val[i] = *ptr++;
+       val[i++] = '\'';
+       val[i] = '\0';
+       return val;
+}
+
 /*
  * Local variables:
  *  c-indent-level: 8