]> jfr.im git - irc/weechat/weechat.git/commitdiff
script: fix autoload of multiple scripts at once with `/script autoload` (closes...
authorSébastien Helleu <redacted>
Wed, 20 Sep 2023 18:05:49 +0000 (20:05 +0200)
committerSébastien Helleu <redacted>
Wed, 20 Sep 2023 18:05:49 +0000 (20:05 +0200)
ChangeLog.adoc
src/plugins/plugin-script.c

index 75a8ae88803d616247f11e13beb40f1501c7d336..27734bb99930d27c5258ffa94b5ffea745bb672e 100644 (file)
@@ -68,6 +68,7 @@ Bug fixes::
   * irc: add missing "account-tag" in list of supported capabilities
   * irc: add channel in "autojoin" server option only when the channel is actually joined (issue #1990)
   * relay: synchronize nick modes with IRC client upon connection (issue #1984)
+  * script: fix autoload of multiple scripts at once with `/script autoload` (issue #2018)
   * script: fix crash when a `/script` command triggers another `/script` command (issue #923)
   * script: add local key bindings during the buffer creation
   * script: add parameters up/down/go in `/help script` and command completion
index 860b352239547c50188d4abf6f251ba1e1bcea9c..0ed7e2ab2839371a74d74c53ed5262acef75e9ff 100644 (file)
@@ -1217,7 +1217,7 @@ plugin_script_action_install (struct t_weechat_plugin *weechat_plugin,
                               char **list)
 {
     char **argv, *name, *ptr_base_name, *base_name, *new_path, *autoload_path;
-    char *symlink_path, str_signal[128], *ptr_list, *weechat_data_dir, *dir_separator;
+    char *symlink_path, str_signal[128], *ptr_name, *weechat_data_dir, *dir_separator;
     int argc, i, length, rc, autoload, existing_script, script_loaded;
     struct t_plugin_script *ptr_script;
 
@@ -1227,30 +1227,7 @@ plugin_script_action_install (struct t_weechat_plugin *weechat_plugin,
     /* create again directories, just in case they have been removed */
     plugin_script_create_dirs (weechat_plugin);
 
-    ptr_list = *list;
-    autoload = 0;
-    *quiet = 0;
-
-    while ((ptr_list[0] == ' ') || (ptr_list[0] == '-'))
-    {
-        if (ptr_list[0] == ' ')
-            ptr_list++;
-        else
-        {
-            switch (ptr_list[1])
-            {
-                case 'a': /* autoload */
-                    autoload = 1;
-                    break;
-                case 'q': /* quiet mode */
-                    *quiet = 1;
-                    break;
-            }
-            ptr_list += 2;
-        }
-    }
-
-    argv = weechat_string_split (ptr_list, ",", NULL,
+    argv = weechat_string_split (*list, ",", NULL,
                                  WEECHAT_STRING_SPLIT_STRIP_LEFT
                                  | WEECHAT_STRING_SPLIT_STRIP_RIGHT
                                  | WEECHAT_STRING_SPLIT_COLLAPSE_SEPS,
@@ -1259,7 +1236,30 @@ plugin_script_action_install (struct t_weechat_plugin *weechat_plugin,
     {
         for (i = 0; i < argc; i++)
         {
-            name = strdup (argv[i]);
+            autoload = 0;
+            *quiet = 0;
+            ptr_name = argv[i];
+            while ((ptr_name[0] == ' ') || (ptr_name[0] == '-'))
+            {
+                if (ptr_name[0] == ' ')
+                {
+                    ptr_name++;
+                }
+                else
+                {
+                    switch (ptr_name[1])
+                    {
+                        case 'a': /* autoload */
+                            autoload = 1;
+                            break;
+                        case 'q': /* quiet mode */
+                            *quiet = 1;
+                            break;
+                    }
+                    ptr_name += 2;
+                }
+            }
+            name = strdup (ptr_name);
             if (name)
             {
                 ptr_base_name = basename (name);
@@ -1351,6 +1351,13 @@ plugin_script_action_install (struct t_weechat_plugin *weechat_plugin,
                     free (base_name);
                     if (weechat_data_dir)
                         free (weechat_data_dir);
+
+                    /* send signal */
+                    snprintf (str_signal, sizeof (str_signal),
+                              "%s_script_installed", weechat_plugin->name);
+                    (void) weechat_hook_signal_send (str_signal,
+                                                     WEECHAT_HOOK_SIGNAL_STRING,
+                                                     name);
                 }
                 free (name);
             }
@@ -1360,11 +1367,6 @@ plugin_script_action_install (struct t_weechat_plugin *weechat_plugin,
 
     *quiet = 0;
 
-    snprintf (str_signal, sizeof (str_signal),
-              "%s_script_installed", weechat_plugin->name);
-    (void) weechat_hook_signal_send (str_signal, WEECHAT_HOOK_SIGNAL_STRING,
-                                     ptr_list);
-
     free (*list);
     *list = NULL;
 }
@@ -1384,7 +1386,7 @@ plugin_script_action_remove (struct t_weechat_plugin *weechat_plugin,
                              int *quiet,
                              char **list)
 {
-    char **argv, str_signal[128], *ptr_list;
+    char **argv, str_signal[128], *ptr_name;
     int argc, i;
     struct t_plugin_script *ptr_script;
 
@@ -1394,15 +1396,7 @@ plugin_script_action_remove (struct t_weechat_plugin *weechat_plugin,
     /* create again directories, just in case they have been removed */
     plugin_script_create_dirs (weechat_plugin);
 
-    ptr_list = *list;
-    *quiet = 0;
-    if (strncmp (ptr_list, "-q ", 3) == 0)
-    {
-        *quiet = 1;
-        ptr_list += 3;
-    }
-
-    argv = weechat_string_split (ptr_list, ",", NULL,
+    argv = weechat_string_split (*list, ",", NULL,
                                  WEECHAT_STRING_SPLIT_STRIP_LEFT
                                  | WEECHAT_STRING_SPLIT_STRIP_RIGHT
                                  | WEECHAT_STRING_SPLIT_COLLAPSE_SEPS,
@@ -1411,25 +1405,35 @@ plugin_script_action_remove (struct t_weechat_plugin *weechat_plugin,
     {
         for (i = 0; i < argc; i++)
         {
+            ptr_name = argv[i];
+            *quiet = 0;
+            if (strncmp (ptr_name, "-q ", 3) == 0)
+            {
+                *quiet = 1;
+                ptr_name += 3;
+            }
+
             /* unload script, if script is loaded */
-            ptr_script = plugin_script_search_by_full_name (scripts, argv[i]);
+            ptr_script = plugin_script_search_by_full_name (scripts, ptr_name);
             if (ptr_script)
                 (*script_unload) (ptr_script);
 
             /* remove script file(s) */
-            (void) plugin_script_remove_file (weechat_plugin, argv[i],
+            (void) plugin_script_remove_file (weechat_plugin, ptr_name,
                                               *quiet, 1);
+
+            /* send signal */
+            snprintf (str_signal, sizeof (str_signal),
+                      "%s_script_removed", weechat_plugin->name);
+            (void) weechat_hook_signal_send (str_signal,
+                                             WEECHAT_HOOK_SIGNAL_STRING,
+                                             ptr_name);
         }
         weechat_string_free_split (argv);
     }
 
     *quiet = 0;
 
-    snprintf (str_signal, sizeof (str_signal),
-              "%s_script_removed", weechat_plugin->name);
-    (void) weechat_hook_signal_send (str_signal, WEECHAT_HOOK_SIGNAL_STRING,
-                                     ptr_list);
-
     free (*list);
     *list = NULL;
 }
@@ -1444,7 +1448,7 @@ plugin_script_action_autoload (struct t_weechat_plugin *weechat_plugin,
                                char **list)
 {
     char **argv, *name, *ptr_base_name, *base_name, *autoload_path;
-    char *symlink_path, *ptr_list, *weechat_data_dir, *dir_separator;
+    char *symlink_path, *ptr_name, *weechat_data_dir, *dir_separator;
     int argc, i, length, rc, autoload;
 
     if (!*list)
@@ -1453,30 +1457,7 @@ plugin_script_action_autoload (struct t_weechat_plugin *weechat_plugin,
     /* create again directories, just in case they have been removed */
     plugin_script_create_dirs (weechat_plugin);
 
-    ptr_list = *list;
-    autoload = 0;
-    *quiet = 0;
-
-    while ((ptr_list[0] == ' ') || (ptr_list[0] == '-'))
-    {
-        if (ptr_list[0] == ' ')
-            ptr_list++;
-        else
-        {
-            switch (ptr_list[1])
-            {
-                case 'a': /* no autoload */
-                    autoload = 1;
-                    break;
-                case 'q': /* quiet mode */
-                    *quiet = 1;
-                    break;
-            }
-            ptr_list += 2;
-        }
-    }
-
-    argv = weechat_string_split (ptr_list, ",", NULL,
+    argv = weechat_string_split (*list, ",", NULL,
                                  WEECHAT_STRING_SPLIT_STRIP_LEFT
                                  | WEECHAT_STRING_SPLIT_STRIP_RIGHT
                                  | WEECHAT_STRING_SPLIT_COLLAPSE_SEPS,
@@ -1485,7 +1466,30 @@ plugin_script_action_autoload (struct t_weechat_plugin *weechat_plugin,
     {
         for (i = 0; i < argc; i++)
         {
-            name = strdup (argv[i]);
+            ptr_name = argv[i];
+            autoload = 0;
+            *quiet = 0;
+            while ((ptr_name[0] == ' ') || (ptr_name[0] == '-'))
+            {
+                if (ptr_name[0] == ' ')
+                {
+                    ptr_name++;
+                }
+                else
+                {
+                    switch (ptr_name[1])
+                    {
+                        case 'a': /* no autoload */
+                            autoload = 1;
+                            break;
+                        case 'q': /* quiet mode */
+                            *quiet = 1;
+                            break;
+                    }
+                    ptr_name += 2;
+                }
+            }
+            name = strdup (ptr_name);
             if (name)
             {
                 ptr_base_name = basename (name);