[gegl] bin: add argvs_eval_argv function



commit 4d634721acf5d97f3372bcefc92c50471ee382e6
Author: Øyvind Kolås <pippin gimp org>
Date:   Sun Jan 27 03:19:46 2019 +0100

    bin: add argvs_eval_argv function

 bin/argvs.c | 35 +++++++++++++++++++++++++++++++----
 bin/argvs.h |  1 +
 2 files changed, 32 insertions(+), 4 deletions(-)
---
diff --git a/bin/argvs.c b/bin/argvs.c
index 32f28f224..c4b56d90d 100644
--- a/bin/argvs.c
+++ b/bin/argvs.c
@@ -282,6 +282,37 @@ static char *string_chop_head (char *orig) /* return pointer to reset after arg
   return NULL;
 }
 
+
+int argvs_eval_argv (char **cargv, int cargc);
+int argvs_eval_argv (char **cargv, int cargc)
+{
+  CmdIterator *ci = cmd_iterator_new (NULL);
+  CmdEntry *command;
+  int ret = -1;
+
+  if (cargc <= 0)
+  {
+    for (char **arg = cargv; *arg; arg++, cargc++);
+  }
+
+  while ((command = cmd_iterator_next (ci)))
+    if (!strcmp (cargv[0], command->name))
+      {
+        if (command->req_args > cargc - 1)
+          {
+            printf ("command '%s' needs %i args, %i given\n",
+                command->name, command->req_args, cargc - 1);
+          }
+        else
+          ret = command->fun (cargc, cargv, NULL);
+        if (ret)
+          printf ("%s returned: %i\n", command->name, ret);
+        cmd_iterator_stop (ci);
+        break;
+      }
+  return ret;
+}
+
 int argvs_eval (const char *cmdline)
 {
   char *cargv[32];
@@ -331,10 +362,6 @@ int argvs_eval (const char *cmdline)
 b:
         if (cargv[0][0] && !found)
           {
-            //XXX: somehow pipe this back into the ui
-            //fprintf (stdout, "unknown command '%s'\n", cargv[0]);
-            //fflush (NULL);
-            //sleep (1);
             printf ("unknown command '%s' use ? for a list of registered commands\n", cargv[0]);
           }
       }
diff --git a/bin/argvs.h b/bin/argvs.h
index 2887f2942..bd28f14a9 100644
--- a/bin/argvs.h
+++ b/bin/argvs.h
@@ -11,6 +11,7 @@ void argvs_add   (int (*fun)(COMMAND_ARGS),
                   int         required_arguments,
                   const char *argument_help,
                   const char *help);
+int argvs_eval_argv (char **cargv, int cargc);
 int argvs_eval   (const char *cmdline); /* this evals one command,
                                            no newlines or semicolons are taken into account. */
 int argvs_source (const char *path);


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