From fa19b2b9b1412d3eeb515afe41c55ac414acc982 Mon Sep 17 00:00:00 2001 From: Teemu Ikonen Date: Thu, 26 Aug 2021 17:02:10 +0300 Subject: cli, location: Fix multi-sentence NMEA message output Multi-sentence NMEA messages were printed as is, that is with linebreaks, which made mmcli --location-get output look broken. Split NMEA sentences with linebreaks to separate output list items, so that they line up correctly. --- cli/mmcli-output.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'cli/mmcli-output.c') diff --git a/cli/mmcli-output.c b/cli/mmcli-output.c index 0d1fbf63..6e88792d 100644 --- a/cli/mmcli-output.c +++ b/cli/mmcli-output.c @@ -487,6 +487,42 @@ mmcli_output_string_array_take (MmcF field, output_item_new_take_multiple (field, strv, multiline); } +void +mmcli_output_string_array_multiline_take (MmcF field, + gchar **strv) +{ + gchar **merged; + GPtrArray *pointers; + + merged = NULL; + if (strv) { + guint i; + + pointers = g_ptr_array_new (); + for (i = 0; strv[i]; i++) { + gchar **split; + + split = strv[i] ? g_strsplit (strv[i], "\n", -1) : NULL; + if (split) { + guint n; + + for (n = 0; split[n]; n++) { + if (split[n][0]) { + g_strstrip (split[n]); + g_ptr_array_add (pointers, g_strdup (split[n])); + } + } + g_strfreev (split); + } + } + g_strfreev (strv); + g_ptr_array_add (pointers, NULL); + merged = (gchar **)g_ptr_array_free (pointers, FALSE); + } + + output_item_new_take_multiple (field, merged, TRUE); +} + void mmcli_output_string (MmcF field, const gchar *str) -- cgit v1.2.3-70-g09d2