mssh.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <getopt.h>
  5. #include <gtk/gtk.h>
  6. #include "config.h"
  7. #include "mssh-window.h"
  8. #define PKGINFO PACKAGE_NAME " " VERSION
  9. #define COPYRIGHT "Copyright (C) 2009 Bradley Smith <[email protected]>"
  10. static void on_mssh_destroy(GtkWidget *widget, gpointer data)
  11. {
  12. gtk_widget_hide(widget);
  13. gtk_main_quit();
  14. }
  15. void usage(const char *argv0)
  16. {
  17. fprintf(stderr, "%s\n", PKGINFO);
  18. fprintf(stderr, "%s\n", COPYRIGHT);
  19. fprintf(stderr, "An ssh client to issue the same commands to multiple servers\n\n");
  20. fprintf(stderr, "Usage: %s [OPTION]... [HOSTS]\n\n", argv0);
  21. fprintf(stderr,
  22. " -h, --help Display this help and exit\n");
  23. fprintf(stderr,
  24. " -V, --version Output version information and exit\n");
  25. fprintf(stderr, "\nReport bugs to <%s>.\n", PACKAGE_BUGREPORT);
  26. exit(EXIT_FAILURE);
  27. }
  28. int main(int argc, char* argv[], char* env[])
  29. {
  30. GtkWidget* window;
  31. int c, option_index = 0;
  32. int i, nhosts = 0;
  33. char **hosts = NULL;
  34. static struct option long_options[] =
  35. {
  36. {"help", no_argument, 0, 'h'},
  37. {"version", no_argument, 0, 'V'},
  38. {0, 0, 0, 0}
  39. };
  40. for(;;)
  41. {
  42. c = getopt_long(argc, argv, "hV", long_options, &option_index);
  43. if(c == -1)
  44. break;
  45. switch(c)
  46. {
  47. case 'h':
  48. usage(argv[0]);
  49. break;
  50. case 'V':
  51. printf("%s\n\n", PKGINFO);
  52. printf("%s\n\n", COPYRIGHT);
  53. printf("Redistribution and use in source and binary forms, with or without\n");
  54. printf("modification, are permitted provided that the following conditions are met:\n");
  55. printf("\n");
  56. printf(" 1. Redistributions of source code must retain the copyright notice,\n");
  57. printf(" this list of conditions and the following disclaimer.\n");
  58. printf(" 2. Redistributions in binary form must reproduce the copyright notice,\n");
  59. printf(" this list of conditions and the following disclaimer in the\n");
  60. printf(" documentation and/or other materials provided with the distribution.\n");
  61. printf(" 3. The name of the author may not be used to endorse or promote\n");
  62. printf(" products derived from this software without specific prior written\n");
  63. printf(" permission.\n");
  64. printf("\n");
  65. printf("THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\n");
  66. printf("IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n");
  67. printf("OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN\n");
  68. printf("NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n");
  69. printf("SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED\n");
  70. printf("TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n");
  71. printf("PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\n");
  72. printf("LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\n");
  73. printf("NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\n");
  74. printf("SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n");
  75. exit(EXIT_SUCCESS);
  76. break;
  77. case '?':
  78. printf("\n");
  79. usage(argv[0]);
  80. exit(EXIT_FAILURE);
  81. break;
  82. default:
  83. abort();
  84. }
  85. }
  86. if (optind < argc)
  87. {
  88. hosts = malloc(sizeof(char*) * (argc - optind));
  89. while (optind < argc)
  90. {
  91. hosts[nhosts++] = strdup(argv[optind++]);
  92. }
  93. }
  94. else
  95. {
  96. fprintf(stderr, "No hosts specified\n\n");
  97. usage(argv[0]);
  98. }
  99. gtk_init(&argc, &argv);
  100. window = GTK_WIDGET(mssh_window_new());
  101. g_signal_connect(G_OBJECT(window), "destroy",
  102. G_CALLBACK(on_mssh_destroy), NULL);
  103. mssh_window_new_session(MSSH_WINDOW(window), env, nhosts, hosts);
  104. gtk_widget_show_all(window);
  105. gtk_main();
  106. for(i = 0; i < nhosts; i++)
  107. free(hosts[i]);
  108. free(hosts);
  109. return 0;
  110. }