if (optind < argc) {
dstr d = DSTR_INIT;
setup((f & f_warn) ? "WATCH -A+w" : "WATCH -A");
- dstr_puts(&d, argv[optind++]);
- while (optind < argc) {
- dstr_putc(&d, ' ');
- dstr_puts(&d, argv[optind++]);
- }
+ while (optind < argc)
+ u_quotify(&d, argv[optind++]);
dstr_putc(&d, '\n');
errno = EIO;
if (write(fd, d.buf, d.len) != d.len || shutdown(fd, 1))
#include <unistd.h>
#include <fcntl.h>
+#include <mLib/dstr.h>
+
#include "util.h"
#include <sys/ioctl.h>
/*----- Main code ---------------------------------------------------------*/
+/* --- @u_quotify@ --- *
+ *
+ * Arguments: @dstr *d@ = where to write the answer
+ * @const char *p@ = string to quotify
+ *
+ * Returns: ---
+ *
+ * Use: Quotes the given string if necessary, according to our
+ * quoting rules.
+ */
+
+void u_quotify(dstr *d, const char *p)
+{
+ if (d->len)
+ dstr_putc(d, ' ');
+ if (*p && !p[strcspn(p, "\"' \t\n\v")])
+ dstr_puts(d, p);
+ else {
+ dstr_putc(d, '\"');
+ while (*p) {
+ if (*p == '\\' || *p == '\"')
+ dstr_putc(d, '\\');
+ dstr_putc(d, *p++);
+ }
+ dstr_putc(d, '\"');
+ }
+}
+
/* --- @u_detach@ --- *
*
* Arguments: ---
/*----- Functions provided ------------------------------------------------*/
+/* --- @u_quotify@ --- *
+ *
+ * Arguments: @dstr *d@ = where to write the answer
+ * @const char *p@ = string to quotify
+ *
+ * Returns: ---
+ *
+ * Use: Quotes the given string if necessary, according to our
+ * quoting rules.
+ */
+
+extern void u_quotify(dstr */*d*/, const char */*p*/);
+
/* --- @u_detach@ --- *
*
* Arguments: ---
.SS "Use from scripts"
If arguments are given to
.BR tripectl ,
-they are concatenated with spaces between and submitted to the server
-after connection. Any
+they are quoted if necessary to protect spaces and other special
+characters, concatenated with spaces between, and submitted to the
+server after connection. Any
.B INFO
responses returned by the server are written to standard output (without
the
/*----- Utility functions -------------------------------------------------*/
-/* --- @quotify@ --- *
- *
- * Arguments: @dstr *d@ = where to write the answer
- * @const char *p@ = string to quotify
- *
- * Returns: ---
- *
- * Use: Quotes the given string if necessary, according to our
- * quoting rules.
- */
-
-static void quotify(dstr *d, const char *p)
-{
- if (d->len)
- dstr_putc(d, ' ');
- if (*p && !p[strcspn(p, "\"' \t\n\v")])
- dstr_puts(d, p);
- else {
- dstr_putc(d, '\"');
- while (*p) {
- if (*p == '\\' || *p == '\"')
- dstr_putc(d, '\\');
- dstr_putc(d, *p++);
- }
- dstr_putc(d, '\"');
- }
-}
-
/* --- @a_vformat@ --- *
*
* Arguments: @dstr *d@ = where to leave the formatted message
const addr *a = va_arg(ap, const addr *);
switch (a->sa.sa_family) {
case AF_INET:
- quotify(d, "INET");
- quotify(d, inet_ntoa(a->sin.sin_addr));
+ u_quotify(d, "INET");
+ u_quotify(d, inet_ntoa(a->sin.sin_addr));
dstr_putf(d, " %u", (unsigned)ntohs(a->sin.sin_port));
break;
default:
while (d->len && d->buf[d->len - 1] == '=') d->len--;
} else if (strcmp(fmt, "?TOKENS") == 0) {
const char *const *av = va_arg(ap, const char *const *);
- while (*av) quotify(d, *av++);
+ while (*av) u_quotify(d, *av++);
} else if (strcmp(fmt, "?PEER") == 0)
- quotify(d, p_name(va_arg(ap, peer *)));
+ u_quotify(d, p_name(va_arg(ap, peer *)));
else if (strcmp(fmt, "?ERRNO") == 0) {
dstr_putf(d, " E%d", errno);
- quotify(d, strerror(errno));
+ u_quotify(d, strerror(errno));
} else
abort();
} else {
if (*fmt == '!') fmt++;
DRESET(&dd);
dstr_vputf(&dd, fmt, &ap);
- quotify(d, dd.buf);
+ u_quotify(d, dd.buf);
}
fmt = va_arg(ap, const char *);
}
if (tag) dstr_puts(&d, "BG");
dstr_puts(&d, status);
- if (tag) quotify(&d, tag);
+ if (tag) u_quotify(&d, tag);
a_vformat(&d, fmt, ap);
dstr_putc(&d, '\n');
dosend(a, d.buf, d.len);