libopkg: line-wrap descriptions only on interactive terminals
authorJo-Philipp Wich <jo@mein.io>
Fri, 10 Feb 2017 09:14:02 +0000 (10:14 +0100)
committerJo-Philipp Wich <jo@mein.io>
Fri, 10 Feb 2017 09:14:02 +0000 (10:14 +0100)
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 <jo@mein.io>
libopkg/pkg_parse.c

index b54ad9aead061af2bc51c33a16dbe464f76c83fc..5337f349841b5c11a047af8c1babbec45d541cf9 100644 (file)
@@ -20,6 +20,7 @@
 
 #include <stdio.h>
 #include <ctype.h>
+#include <unistd.h>
 
 #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) {