Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
query: do not print empty line for purely multiline formats
Baptiste Daroussin committed 1 month ago
commit d12cf2bc9f6b8a6dd0eed061362123f6d174134f
parent d6fbc78
1 file changed +20 -1
modified src/query.c
@@ -385,6 +385,25 @@ format_str(struct pkg *pkg, xstring *dest, const char *qstr, const void *data)
	fflush(dest->fp);
}

+
static bool
+
query_has_nonmultiline(const char *qstr)
+
{
+
	while (*qstr) {
+
		if (*qstr == '%') {
+
			qstr++;
+
			for (unsigned int i = 0; i < NELEM(accepted_query_flags); i++) {
+
				if (*qstr == accepted_query_flags[i].flag &&
+
				    accepted_query_flags[i].multiline == 0) {
+
					return (true);
+
				}
+
			}
+
		}
+
		if (*qstr)
+
			qstr++;
+
	}
+
	return (false);
+
}
+

void
print_query(struct pkg *pkg, char *qstr, char multiline)
{
@@ -487,7 +506,7 @@ print_query(struct pkg *pkg, char *qstr, char multiline)
		printed = true;
		break;
	}
-
	if (!printed) {
+
	if (!printed && query_has_nonmultiline(qstr)) {
		format_str(pkg, output, qstr, NULL);
		printf("%s\n", output->buf);
	}