aboutsummaryrefslogtreecommitdiff
path: root/cli/mmcli-modem.c
diff options
context:
space:
mode:
Diffstat (limited to 'cli/mmcli-modem.c')
-rw-r--r--cli/mmcli-modem.c46
1 files changed, 45 insertions, 1 deletions
diff --git a/cli/mmcli-modem.c b/cli/mmcli-modem.c
index d536346b..9e937359 100644
--- a/cli/mmcli-modem.c
+++ b/cli/mmcli-modem.c
@@ -129,6 +129,43 @@ mmcli_modem_shutdown (void)
g_object_unref (ctxt.modem);
}
+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
get_info_process_reply (gboolean result,
const GError *error,
@@ -136,12 +173,17 @@ get_info_process_reply (gboolean result,
const gchar *model,
const gchar *revision)
{
+ gchar *prefixed_revision;
+
if (!result) {
g_printerr ("couldn't get info from modem: '%s'\n",
error ? error->message : "unknown error");
exit (EXIT_FAILURE);
}
+ prefixed_revision = prefix_newlines (" | ",
+ revision);
+
g_print ("\n"
"%s\n"
" -------------------------\n"
@@ -152,7 +194,9 @@ get_info_process_reply (gboolean result,
ctxt.modem_str,
manufacturer,
model,
- revision);
+ prefixed_revision ? prefixed_revision : revision);
+
+ g_free (prefixed_revision);
}
static void