cli: handle multiline revision strings
This commit is contained in:
@@ -129,6 +129,43 @@ mmcli_modem_shutdown (void)
|
|||||||
g_object_unref (ctxt.modem);
|
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
|
static void
|
||||||
get_info_process_reply (gboolean result,
|
get_info_process_reply (gboolean result,
|
||||||
const GError *error,
|
const GError *error,
|
||||||
@@ -136,12 +173,17 @@ get_info_process_reply (gboolean result,
|
|||||||
const gchar *model,
|
const gchar *model,
|
||||||
const gchar *revision)
|
const gchar *revision)
|
||||||
{
|
{
|
||||||
|
gchar *prefixed_revision;
|
||||||
|
|
||||||
if (!result) {
|
if (!result) {
|
||||||
g_printerr ("couldn't get info from modem: '%s'\n",
|
g_printerr ("couldn't get info from modem: '%s'\n",
|
||||||
error ? error->message : "unknown error");
|
error ? error->message : "unknown error");
|
||||||
exit (EXIT_FAILURE);
|
exit (EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prefixed_revision = prefix_newlines (" | ",
|
||||||
|
revision);
|
||||||
|
|
||||||
g_print ("\n"
|
g_print ("\n"
|
||||||
"%s\n"
|
"%s\n"
|
||||||
" -------------------------\n"
|
" -------------------------\n"
|
||||||
@@ -152,7 +194,9 @@ get_info_process_reply (gboolean result,
|
|||||||
ctxt.modem_str,
|
ctxt.modem_str,
|
||||||
manufacturer,
|
manufacturer,
|
||||||
model,
|
model,
|
||||||
revision);
|
prefixed_revision ? prefixed_revision : revision);
|
||||||
|
|
||||||
|
g_free (prefixed_revision);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Reference in New Issue
Block a user