commit b39747133860cfedc975ba3d794bf85d8a1a482f
parent 6d60ecc40b583ea75164052258497fa7c2412885
Author: Louis Burda <quent.burda@gmail.com>
Date: Fri, 19 May 2023 14:36:16 +0200
Make separating search args by space optional
Diffstat:
1 file changed, 16 insertions(+), 8 deletions(-)
diff --git a/tquery.c b/tquery.c
@@ -47,6 +47,7 @@ static size_t inputlen = 0;
static char errbuf[1024] = { 0 };
static int errtimer = 0;
+static bool separate_args = false;
static bool single_out = false;
static bool debug = false;
static char delim = '\n';
@@ -200,7 +201,7 @@ findbin(const char *name)
}
static void
-spawn(const char **prefix, const char *search_args)
+spawn(const char **prefix, const char *query)
{
struct dvec argv;
const char **arg;
@@ -229,14 +230,19 @@ spawn(const char **prefix, const char *search_args)
*(const char **)dvec_back(&argv) = *arg;
}
- ntok = tok = search_args;
- while (ntok && *ntok) {
- ntok = strchr(tok, ' ');
- end = ntok ? ntok : tok + strlen(tok);
+ if (separate_args) {
+ ntok = tok = query;
+ while (ntok && *ntok) {
+ ntok = strchr(tok, ' ');
+ end = ntok ? ntok : tok + strlen(tok);
+ dvec_add_back(&argv, 1);
+ *(const char **)dvec_back(&argv)
+ = strndup(tok, (size_t) (end - tok));
+ tok = ntok + 1;
+ }
+ } else {
dvec_add_back(&argv, 1);
- *(const char **)dvec_back(&argv)
- = strndup(tok, (size_t) (end - tok));
- tok = ntok + 1;
+ *(const char **)dvec_back(&argv) = query;
}
dvec_add_back(&argv, 1);
@@ -429,6 +435,8 @@ parse(int argc, const char **argv)
single_out = true;
} else if (!strcmp(*arg, "-d")) {
debug = true;
+ } else if (!strcmp(*arg, "-a")) {
+ separate_args = true;
} else if (!strcmp(*arg, "-c")) {
delim = **++arg;
} else if (!strcmp(*arg, "--")) {