From 9d0d61cf8c85b815b90a3a3ae2e1da2b5dbf214c Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Fri, 10 Feb 2017 10:14:02 +0100 Subject: [PATCH] libopkg: line-wrap descriptions only on interactive terminals Various programs call opkg and extract information from its list and info commands. To simplify parsing the output, do not line-wrap long description lines if opkg is not talking to a tty. Signed-off-by: Jo-Philipp Wich --- libopkg/pkg_parse.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/libopkg/pkg_parse.c b/libopkg/pkg_parse.c index b54ad9a..5337f34 100644 --- a/libopkg/pkg_parse.c +++ b/libopkg/pkg_parse.c @@ -20,6 +20,7 @@ #include #include +#include #include "pkg.h" #include "opkg_utils.h" @@ -239,10 +240,16 @@ pkg_parse_line(void *ptr, const char *line, uint mask) case ' ': if ((mask & PFM_DESCRIPTION) && reading_description) { - pkg->description = xrealloc(pkg->description, - strlen(pkg->description) - + 1 + strlen(line) + 1); - strcat(pkg->description, "\n"); + if (isatty(1)) { + pkg->description = xrealloc(pkg->description, + strlen(pkg->description) + + 1 + strlen(line) + 1); + strcat(pkg->description, "\n"); + } else { + pkg->description = xrealloc(pkg->description, + strlen(pkg->description) + + 1 + strlen(line)); + } strcat(pkg->description, (line)); goto dont_reset_flags; } else if ((mask & PFM_CONFFILES) && reading_conffiles) { -- 2.25.1