[gnome-commander/issue_107] Added missing string parsing and remove double output of path name




commit 22990b8478779bc2f4a9f2bf1b230dbc47ad2cfa
Author: Maik Pertermann <maik tapse gmx de>
Date:   Sun Dec 19 19:20:05 2021 +0100

    Added missing string parsing and remove double output of path name

 src/gnome-cmd-file-popmenu.cc | 41 +++++++--------------------------
 src/gnome-cmd-user-actions.cc | 53 +++++++++++++++++++++----------------------
 src/utils.cc                  | 14 +++++++++++-
 3 files changed, 47 insertions(+), 61 deletions(-)
---
diff --git a/src/gnome-cmd-file-popmenu.cc b/src/gnome-cmd-file-popmenu.cc
index ebd8e0dc..9430d190 100644
--- a/src/gnome-cmd-file-popmenu.cc
+++ b/src/gnome-cmd-file-popmenu.cc
@@ -74,57 +74,32 @@ static void do_mime_exec_multiple (gpointer *args)
 {
     auto gnomeCmdApp = static_cast<GnomeCmdApp*> (args[0]);
     auto files = static_cast<GList*> (args[1]);
-
     if (files)
     {
         if(gnomeCmdApp->gAppInfo != nullptr)
         {
-            // gio app
+            // gio app default by system
             DEBUG('g', "Launching \"%s\"\n", g_app_info_get_commandline(gnomeCmdApp->gAppInfo));
             g_app_info_launch(gnomeCmdApp->gAppInfo, files, nullptr, nullptr);
         }
         else
         {
-            // own app
+            // own app by user defined
             string cmdString = gnome_cmd_app_get_command (gnomeCmdApp);
-
             set<string> dirs;
-
             for (auto files_tmp = files; files_tmp; files_tmp = files_tmp->next)
             {
                 auto gFile = (GFile *) files_tmp->data;
-
-                if (g_file_has_uri_scheme(gFile, "file"))
-                {
-                    auto localpath = g_file_get_path(gFile);
-
-                    cmdString += ' ';
-                    cmdString += stringify (g_shell_quote (localpath));
-
-                    auto dpath = g_path_get_dirname (localpath);
-
-                    if (dpath)
-                        dirs.insert (stringify (dpath));
-
-                    g_free(localpath);
-                }
-                else
-                {
-                    auto uri = g_file_get_uri(gFile);
-                    cmdString += ' ';
-                    cmdString += stringify (g_shell_quote (uri));
-                }
+                auto localpath = g_file_get_path(gFile);
+                auto dpath = g_path_get_dirname (localpath);
+                if (dpath)
+                    dirs.insert (stringify (dpath));
+                g_free(localpath);
             }
-
-            if (dirs.size()==1)
-                run_command_indir (cmdString.c_str(), dirs.begin()->c_str(), 
gnome_cmd_app_get_requires_terminal (gnomeCmdApp));
-            else
-                run_command_indir (cmdString.c_str(), nullptr, gnome_cmd_app_get_requires_terminal 
(gnomeCmdApp));
+            run_command_indir (cmdString.c_str(), dirs.begin()->c_str(), gnome_cmd_app_get_requires_terminal 
(gnomeCmdApp));
         }
-
         g_list_free (files);
     }
-
     gnome_cmd_app_free (gnomeCmdApp);
     g_free (args);
 }
diff --git a/src/gnome-cmd-user-actions.cc b/src/gnome-cmd-user-actions.cc
index 0b525b62..952d43be 100644
--- a/src/gnome-cmd-user-actions.cc
+++ b/src/gnome-cmd-user-actions.cc
@@ -2073,35 +2073,34 @@ int parse_command(string *cmd, const gchar *command)
     cmdcap = cmd->capacity();
     cmdlen = cmd->length();
 
-    for (auto s = command; *s; ++s)
+    for (auto s = command; *s; ++s) // loop over chars of command-string set by user
     {
-        if (!percent)
+        if (!percent) // check if % not found
         {
-            percent = (*s == '%');
-
-            if (!percent)
-           {
-               if (cmdcap < cmdlen + 1)
-               {
-                   cmd->reserve(cmdlen +1);
-                   cmdcap = cmd->capacity();
-               }
-               if (blcheck) // copy letter by letter, but remove trailing blanks
-                   *cmd += *s;
-               else
-               {
-                   if (*s == ' ' || *s == '\t')
-                   {
-                       continue;
-                   }
-                   else
-                   {
-                       blcheck = TRUE;
-                       *cmd += *s;
-                   }
-               }
-               cmdlen = cmd->length();
-           }
+            percent = (*s == '%'); // true: if s=%, false: if s!=%
+            if (!percent) // check if % not found
+            {
+                if (cmdcap < cmdlen + 1)
+                {
+                    cmd->reserve(cmdlen +1);
+                    cmdcap = cmd->capacity();
+                }
+                if (blcheck) // copy letter by letter, but remove trailing blanks
+                    *cmd += *s;
+                else
+                {
+                    if (*s == ' ' || *s == '\t')
+                    {
+                    continue;
+                    }
+                    else
+                    {
+                    blcheck = TRUE;
+                    *cmd += *s;
+                    }
+                }
+                cmdlen = cmd->length();
+            }
 
             continue;
         }
diff --git a/src/utils.cc b/src/utils.cc
index f68f65b2..48c3d418 100644
--- a/src/utils.cc
+++ b/src/utils.cc
@@ -32,6 +32,7 @@
 #include "gnome-cmd-data.h"
 #include "imageloader.h"
 #include "gnome-cmd-main-win.h"
+#include "gnome-cmd-user-actions.h"
 
 using namespace std;
 
@@ -126,7 +127,18 @@ void run_command_indir (const gchar *in_command, const gchar *dpath, gboolean te
     gchar **argv;
     GError *error = NULL;
 
-    g_shell_parse_argv (command, &argc, &argv, NULL);
+    // check if command includes % and replace
+    string cmd;
+       cmd.reserve(2000);
+       if (parse_command(&cmd, (const gchar*) command) == 0)
+       {
+           DEBUG ('g', "run_command_indir: command is not valid.\n");
+           gnome_cmd_show_message (*main_win, _("No valid command given."));
+           return;
+       }
+
+    //g_shell_parse_argv (command, &argc, &argv, NULL);
+    g_shell_parse_argv (cmd.c_str(), &argc, &argv, NULL); // include parse_command
     if (!g_spawn_async (dpath, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &error))
         gnome_cmd_error_message (_("Unable to execute command."), error);
 


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