From 22699a4b215049df7a11cf8ab50de9f41dfd5f66 Mon Sep 17 00:00:00 2001 From: George Kiagiadakis <george.kiagiadakis@collabora.com> Date: Thu, 27 Jun 2019 18:26:05 +0300 Subject: [PATCH] config: allow module property blocks to span multiple lines So now we can do: --- load-module C foo { "property": <"value"> } --- The starting brace is still required to be on the same line as the load-module. --- src/main.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/main.c b/src/main.c index 968233b1..c375324d 100644 --- a/src/main.c +++ b/src/main.c @@ -100,8 +100,8 @@ parse_commands_file (struct WpDaemonData *d, GInputStream * stream, gssize bytes_read; gchar *cur, *linestart, *saveptr; gchar *cmd, *abi, *module, *props; - gint lineno = 1; - gboolean eof = FALSE; + gint lineno = 1, block_lines = 1; + gboolean eof = FALSE, in_block = FALSE; GVariant *properties; linestart = cur = buffer; @@ -121,8 +121,23 @@ parse_commands_file (struct WpDaemonData *d, GInputStream * stream, bytes_read += (cur - linestart); while (cur - buffer < bytes_read) { - while (cur - buffer < bytes_read && *cur != '\n') + /* advance cur to the end of the line that is at the end of the block */ + while (cur - buffer < bytes_read && (in_block || *cur != '\n')) { + switch (*cur) { + case '{': + in_block = TRUE; + break; + case '}': + in_block = FALSE; + break; + case '\n': // found a newline inside a block + block_lines++; + break; + default: + break; + } cur++; + } if (*cur == '\n') { /* found the end of a line */ @@ -155,7 +170,7 @@ parse_commands_file (struct WpDaemonData *d, GInputStream * stream, if (!properties) { context = g_variant_parse_error_print_context (tmperr, props); g_set_error (error, WP_DOMAIN_DAEMON, WP_CODE_INVALID_ARGUMENT, - "GVariant parse error:\n%s", context); + "GVariant parse error after line %i:\n%s", lineno, context); return FALSE; } } else { @@ -173,7 +188,8 @@ parse_commands_file (struct WpDaemonData *d, GInputStream * stream, /* continue with the next line */ linestart = ++cur; - lineno++; + lineno += block_lines; + block_lines = 1; } } -- GitLab