3 Commits 9dd4e7aef0 ... 27575bed37

Author SHA1 Message Date
  Héctor García 27575bed37 Documenting changes 7 years ago
  Héctor García da3f60d820 Now support aliases + hosts on command line at the same time 7 years ago
  Héctor García 2fdfe0bc67 Added support to define more than one alias on command line 7 years ago
2 changed files with 23 additions and 15 deletions
  1. 6 0
      ChangeLog
  2. 17 15
      src/mssh.c

+ 6 - 0
ChangeLog

@@ -1,3 +1,9 @@
+2017-10-24 Héctor García  <[email protected]>
+
+	Support to more than one alias on command line with multiple -a
+
+	Support to define alias and hosts on command line
+
 2017-10-03 Héctor García  <[email protected]>
 
 	Migrated from vte_terminal_spawn_sync to vte_terminal_spawn_async

+ 17 - 15
src/mssh.c

@@ -236,7 +236,7 @@ int main(int argc, char* argv[], char* env[])
     long cols = 0;
     GData **aliases = NULL;
     GData **commands = NULL;
-    GArray *hosts = NULL;
+    GArray *hosts = NULL, *tmp_hosts = NULL;
 
     static struct option long_options[] =
     {
@@ -274,12 +274,17 @@ int main(int argc, char* argv[], char* env[])
         switch(c)
         {
         case 'a':
-            if(aliases && (hosts = g_datalist_get_data(aliases,
+            if(aliases && (tmp_hosts = g_datalist_get_data(aliases,
                 optarg)) == NULL)
             {
                 fprintf(stderr, "Alias '%s' not found\n\n", optarg);
                 usage(argv[0]);
             }
+            if (hosts == NULL) {
+                hosts = tmp_hosts;
+            } else {
+                g_array_append_vals (hosts, tmp_hosts->data, tmp_hosts->len);
+            }
             break;
         case 'c':
             errno = 0;
@@ -332,23 +337,20 @@ int main(int argc, char* argv[], char* env[])
         }
     }
 
-    if(hosts == NULL)
-    {
-        hosts = g_array_new(FALSE, TRUE, sizeof(char*));
-        if (optind < argc)
-        {
-            while (optind < argc)
-            {
-                char *host = strdup(argv[optind++]);
-                g_array_append_val(hosts, host);
-            }
+    if (optind < argc) {
+        if (hosts == NULL) {
+            hosts = g_array_new(FALSE, TRUE, sizeof(char*));
         }
-        else
+        while (optind < argc)
         {
-            fprintf(stderr, "No hosts specified\n\n");
-            usage(argv[0]);
+            char *host = strdup(argv[optind++]);
+            g_array_append_val(hosts, host);
         }
     }
+    if (hosts == NULL) {
+        fprintf(stderr, "No hosts specified\n\n");
+        usage(argv[0]);
+    }
 
     gtk_init(&argc, &argv);