[gnome-builder] libide/foundry: add append_formatted and append_parsed helpers



commit f603aa828e9b19635516bb1e386b43586d3c971d
Author: Christian Hergert <chergert redhat com>
Date:   Thu Sep 15 17:00:53 2022 -0700

    libide/foundry: add append_formatted and append_parsed helpers
    
    This is just more symmetry for porting build systems to using run commands
    instead of launchers.

 src/libide/foundry/ide-run-command.c | 37 ++++++++++++++++++++++++++++++++++++
 src/libide/foundry/ide-run-command.h |  8 ++++++++
 2 files changed, 45 insertions(+)
---
diff --git a/src/libide/foundry/ide-run-command.c b/src/libide/foundry/ide-run-command.c
index 59c43be79..85850b268 100644
--- a/src/libide/foundry/ide-run-command.c
+++ b/src/libide/foundry/ide-run-command.c
@@ -806,3 +806,40 @@ ide_run_command_append_args (IdeRunCommand      *self,
   priv->argv = g_strv_builder_end (builder);
   g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_ARGV]);
 }
+
+void
+ide_run_command_append_formatted (IdeRunCommand *self,
+                                  const char    *format,
+                                  ...)
+{
+  g_autofree char *arg = NULL;
+  va_list args;
+
+  g_return_if_fail (IDE_IS_RUN_COMMAND (self));
+  g_return_if_fail (format != NULL);
+
+  va_start (args, format);
+  arg = g_strdup_vprintf (format, args);
+  va_end (args);
+
+  ide_run_command_append_argv (self, arg);
+}
+
+gboolean
+ide_run_command_append_parsed (IdeRunCommand  *self,
+                               const char     *args,
+                               GError        **error)
+{
+  g_auto(GStrv) argv = NULL;
+  int argc;
+
+  g_return_val_if_fail (IDE_IS_RUN_COMMAND (self), FALSE);
+  g_return_val_if_fail (args != NULL, FALSE);
+
+  if (!g_shell_parse_argv (args, &argc, &argv, error))
+    return FALSE;
+
+  ide_run_command_append_args (self, (const char * const *)argv);
+
+  return TRUE;
+}
diff --git a/src/libide/foundry/ide-run-command.h b/src/libide/foundry/ide-run-command.h
index 3434e6f4c..7d9ebd47d 100644
--- a/src/libide/foundry/ide-run-command.h
+++ b/src/libide/foundry/ide-run-command.h
@@ -83,6 +83,14 @@ IDE_AVAILABLE_IN_ALL
 void                ide_run_command_append_argv      (IdeRunCommand      *self,
                                                       const char         *arg);
 IDE_AVAILABLE_IN_ALL
+void                ide_run_command_append_formatted (IdeRunCommand      *self,
+                                                      const char         *format,
+                                                      ...) G_GNUC_PRINTF (2, 3);
+IDE_AVAILABLE_IN_ALL
+gboolean            ide_run_command_append_parsed    (IdeRunCommand      *self,
+                                                      const char         *args,
+                                                      GError            **error);
+IDE_AVAILABLE_IN_ALL
 const char * const *ide_run_command_get_environ      (IdeRunCommand      *self);
 IDE_AVAILABLE_IN_ALL
 void                ide_run_command_set_environ      (IdeRunCommand      *self,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]