From c7df570d1bab4a353836ad8d9523851c0b9a523c Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Eli=C3=A1n=20Hanisch?= <lambdae2@gmail.com>
Date: Wed, 16 Sep 2009 10:48:56 -0300
Subject: [PATCH] fix arguement passing when there are several commands in a single alias

---
 src/plugins/alias/alias.c |   83 ++++++++------------------------------------
 1 files changed, 15 insertions(+), 68 deletions(-)

diff --git a/src/plugins/alias/alias.c b/src/plugins/alias/alias.c
index dde3bf8..48897c9 100644
--- a/src/plugins/alias/alias.c
+++ b/src/plugins/alias/alias.c
@@ -237,9 +237,8 @@ alias_cb (void *data, struct t_gui_buffer *buffer, int argc, char **argv,
           char **argv_eol)
 {
     struct t_alias *ptr_alias;
-    char **commands, **ptr_cmd, **ptr_next_cmd;
+    char **commands, **ptr_cmd;
     char *args_replaced, *alias_command;
-    int some_args_replaced, length1, length2;
     
     /* make C compiler happy */
     (void) buffer;
@@ -258,93 +257,41 @@ alias_cb (void *data, struct t_gui_buffer *buffer, int argc, char **argv,
         return WEECHAT_RC_ERROR;
     }
     else
-    {		
-        /* an alias can contain many commands separated by ';' */
-        commands = weechat_string_split_command (ptr_alias->command, ';');
-        if (commands)
+    {
+        args_replaced = alias_replace_args (ptr_alias->command,
+                                            (argc > 1) ? argv_eol[1] : "");
+        if (args_replaced)
         {
-            some_args_replaced = 0;
-            ptr_alias->running = 1;
-            for (ptr_cmd = commands; *ptr_cmd; ptr_cmd++)
+            /* an alias can contain many commands separated by ';' */
+            commands = weechat_string_split_command (args_replaced, ';');
+            if (commands)
             {
-                ptr_next_cmd = ptr_cmd;
-                ptr_next_cmd++;
-                
-                args_replaced = alias_replace_args (*ptr_cmd,
-                                                    (argc > 1) ? argv_eol[1] : "");
-                if (args_replaced)
+                ptr_alias->running = 1;
+                for (ptr_cmd = commands; *ptr_cmd; ptr_cmd++)
                 {
-                    some_args_replaced = 1;
                     if (*ptr_cmd[0] == '/')
                     {
                         alias_run_command (weechat_current_buffer (),
-                                           args_replaced);
+                                           *ptr_cmd);
                     }
                     else
                     {
-                        alias_command = malloc (1 + strlen(args_replaced) + 1);
+                        alias_command = malloc (1 + strlen(*ptr_cmd) + 1);
                         if (alias_command)
                         {
                             strcpy (alias_command, "/");
-                            strcat (alias_command, args_replaced);
-                            alias_run_command (weechat_current_buffer (),
-                                               alias_command);
-                            free (alias_command);
-                        }
-                    }
-                    free (args_replaced);
-                }
-                else
-                {
-                    /* if alias has arguments, they are now
-                       arguments of the last command in the list (if no $1,$2,..$*) was found */
-                    if ((*ptr_next_cmd == NULL) && argv_eol[1] && (!some_args_replaced))
-                    {
-                        length1 = strlen (*ptr_cmd);
-                        length2 = strlen (argv_eol[1]);
-                        
-                        alias_command = malloc (1 + length1 + 1 + length2 + 1);
-                        if (alias_command)
-                        {
-                            if (*ptr_cmd[0] != '/')
-                                strcpy (alias_command, "/");
-                            else
-                                strcpy (alias_command, "");
-                            
                             strcat (alias_command, *ptr_cmd);
-                            strcat (alias_command, " ");
-                            strcat (alias_command, argv_eol[1]);
-                            
                             alias_run_command (weechat_current_buffer (),
                                                alias_command);
                             free (alias_command);
                         }
                     }
-                    else
-                    {
-                        if (*ptr_cmd[0] == '/')
-                        {
-                            alias_run_command (weechat_current_buffer (),
-                                               *ptr_cmd);
-                        }
-                        else
-                        {
-                            alias_command = malloc (1 + strlen (*ptr_cmd) + 1);
-                            if (alias_command)
-                            {
-                                strcpy (alias_command, "/");
-                                strcat (alias_command, *ptr_cmd);
-                                alias_run_command (weechat_current_buffer (),
-                                                   alias_command);
-                                free (alias_command);
-                            }
-                        }
-                    }
                 }
+                weechat_string_free_split_command (commands);
             }
-            ptr_alias->running = 0;
-            weechat_string_free_split_command (commands);
+            free (args_replaced);
         }
+        ptr_alias->running = 0;
     }
     return WEECHAT_RC_OK;
 }
-- 
1.6.0.4

