aboutsummaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
Diffstat (limited to 'cli')
-rw-r--r--cli/mmcli-common.c38
-rw-r--r--cli/mmcli-common.h3
-rw-r--r--cli/mmcli-modem-location.c9
-rw-r--r--cli/mmcli-modem.c42
4 files changed, 49 insertions, 43 deletions
diff --git a/cli/mmcli-common.c b/cli/mmcli-common.c
index ff02b572..600939ae 100644
--- a/cli/mmcli-common.c
+++ b/cli/mmcli-common.c
@@ -19,6 +19,7 @@
*/
#include <stdlib.h>
+#include <string.h>
#include <libmm-glib.h>
@@ -1110,3 +1111,40 @@ mmcli_get_common_sms_string (void)
{
return sms_str;
}
+
+gchar *
+mmcli_prefix_newlines (const gchar *prefix,
+ const gchar *str)
+{
+ GString *prefixed_string = NULL;
+ const gchar *line_start = str;
+ const gchar *line_end;
+
+ while ((line_end = strchr (line_start, '\n'))) {
+ gssize line_length;
+
+ line_length = line_end - line_start;
+ if (line_start[line_length - 1] == '\r')
+ line_length--;
+
+ if (line_length > 0) {
+ if (prefixed_string) {
+ /* If not the first line, add the prefix */
+ g_string_append_printf (prefixed_string,
+ "\n%s", prefix);
+ } else {
+ prefixed_string = g_string_new ("");
+ }
+
+ g_string_append_len (prefixed_string,
+ line_start,
+ line_length);
+ }
+
+ line_start = line_end + 1;
+ }
+
+ return (prefixed_string ?
+ g_string_free (prefixed_string, FALSE) :
+ NULL);
+}
diff --git a/cli/mmcli-common.h b/cli/mmcli-common.h
index 5541a719..6d7b3ba7 100644
--- a/cli/mmcli-common.h
+++ b/cli/mmcli-common.h
@@ -85,4 +85,7 @@ const gchar *mmcli_get_common_bearer_string (void);
const gchar *mmcli_get_common_sim_string (void);
const gchar *mmcli_get_common_sms_string (void);
+gchar *mmcli_prefix_newlines (const gchar *prefix,
+ const gchar *str);
+
#endif /* _MMCLI_COMMON_H_ */
diff --git a/cli/mmcli-modem-location.c b/cli/mmcli-modem-location.c
index efa2c63d..51382538 100644
--- a/cli/mmcli-modem-location.c
+++ b/cli/mmcli-modem-location.c
@@ -342,10 +342,13 @@ get_location_process_reply (MMLocation3gpp *location_3gpp,
full = mm_location_gps_nmea_build_full (location_gps_nmea);
if (full) {
+ gchar *prefixed;
+
+ prefixed = mmcli_prefix_newlines (" | ", full);
g_print (" -------------------------\n"
- " GPS NMEA traces |\n"
- " %s\n",
- full);
+ " GPS NMEA traces | %s\n",
+ prefixed);
+ g_free (prefixed);
g_free (full);
} else
g_print (" -------------------------\n"
diff --git a/cli/mmcli-modem.c b/cli/mmcli-modem.c
index c960ec06..f58ec39f 100644
--- a/cli/mmcli-modem.c
+++ b/cli/mmcli-modem.c
@@ -23,7 +23,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
-#include <string.h>
#include <glib.h>
#include <gio/gio.h>
@@ -216,43 +215,6 @@ cancelled (GCancellable *cancellable)
mmcli_async_operation_done ();
}
-static gchar *
-prefix_newlines (const gchar *prefix,
- const gchar *str)
-{
- GString *prefixed_string = NULL;
- const gchar *line_start = str;
- const gchar *line_end;
-
- while ((line_end = strchr (line_start, '\n'))) {
- gssize line_length;
-
- line_length = line_end - line_start;
- if (line_start[line_length - 1] == '\r')
- line_length--;
-
- if (line_length > 0) {
- if (prefixed_string) {
- /* If not the first line, add the prefix */
- g_string_append_printf (prefixed_string,
- "\n%s", prefix);
- } else {
- prefixed_string = g_string_new ("");
- }
-
- g_string_append_len (prefixed_string,
- line_start,
- line_length);
- }
-
- line_start = line_end + 1;
- }
-
- return (prefixed_string ?
- g_string_free (prefixed_string, FALSE) :
- NULL);
-}
-
static void
print_bearer_short_info (MMBearer *bearer)
{
@@ -316,8 +278,8 @@ print_modem_info (void)
own_numbers_string = NULL;
/* Rework possible multiline strings */
- prefixed_revision = prefix_newlines (" | ",
- mm_modem_get_revision (ctx->modem));
+ prefixed_revision = mmcli_prefix_newlines (" | ",
+ mm_modem_get_revision (ctx->modem));
/* Global IDs */
g_print ("\n"