uxputty.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * Unix PuTTY main program.
  3. */
  4. #include <stdio.h>
  5. #include <ctype.h>
  6. #include <stdlib.h>
  7. #include <assert.h>
  8. #include <unistd.h>
  9. #include <gtk/gtk.h>
  10. #include <gdk/gdk.h>
  11. #include "putty.h"
  12. #include "storage.h"
  13. #include "gtkcompat.h"
  14. /*
  15. * Stubs to avoid uxpty.c needing to be linked in.
  16. */
  17. const int use_pty_argv = FALSE;
  18. char **pty_argv; /* never used */
  19. char *pty_osx_envrestore_prefix;
  20. /*
  21. * Clean up and exit.
  22. */
  23. void cleanup_exit(int code)
  24. {
  25. /*
  26. * Clean up.
  27. */
  28. sk_cleanup();
  29. random_save_seed();
  30. exit(code);
  31. }
  32. Backend *select_backend(Conf *conf)
  33. {
  34. Backend *back = backend_from_proto(conf_get_int(conf, CONF_protocol));
  35. assert(back != NULL);
  36. return back;
  37. }
  38. int cfgbox(Conf *conf)
  39. {
  40. char *title = dupcat(appname, " Configuration", NULL);
  41. int ret = do_config_box(title, conf, 0, 0);
  42. sfree(title);
  43. return ret;
  44. }
  45. static int got_host = 0;
  46. const int use_event_log = 1, new_session = 1, saved_sessions = 1;
  47. const int dup_check_launchable = 1;
  48. int process_nonoption_arg(const char *arg, Conf *conf, int *allow_launch)
  49. {
  50. char *argdup, *p, *q;
  51. argdup = dupstr(arg);
  52. q = argdup;
  53. if (got_host) {
  54. /*
  55. * If we already have a host name, treat this argument as a
  56. * port number. NB we have to treat this as a saved -P
  57. * argument, so that it will be deferred until it's a good
  58. * moment to run it.
  59. */
  60. int ret = cmdline_process_param("-P", argdup, 1, conf);
  61. assert(ret == 2);
  62. } else if (!strncmp(q, "telnet:", 7)) {
  63. /*
  64. * If the hostname starts with "telnet:",
  65. * set the protocol to Telnet and process
  66. * the string as a Telnet URL.
  67. */
  68. char c;
  69. q += 7;
  70. if (q[0] == '/' && q[1] == '/')
  71. q += 2;
  72. conf_set_int(conf, CONF_protocol, PROT_TELNET);
  73. p = q;
  74. p += host_strcspn(p, ":/");
  75. c = *p;
  76. if (*p)
  77. *p++ = '\0';
  78. if (c == ':')
  79. conf_set_int(conf, CONF_port, atoi(p));
  80. else
  81. conf_set_int(conf, CONF_port, -1);
  82. conf_set_str(conf, CONF_host, q);
  83. got_host = 1;
  84. } else {
  85. /*
  86. * Otherwise, treat this argument as a host name.
  87. */
  88. p = argdup;
  89. while (*p && !isspace((unsigned char)*p))
  90. p++;
  91. if (*p)
  92. *p++ = '\0';
  93. conf_set_str(conf, CONF_host, q);
  94. got_host = 1;
  95. }
  96. if (got_host)
  97. *allow_launch = TRUE;
  98. sfree(argdup);
  99. return 1;
  100. }
  101. char *make_default_wintitle(char *hostname)
  102. {
  103. return dupcat(hostname, " - ", appname, NULL);
  104. }
  105. /*
  106. * X11-forwarding-related things suitable for Gtk app.
  107. */
  108. char *platform_get_x_display(void) {
  109. const char *display;
  110. /* Try to take account of --display and what have you. */
  111. if (!(display = gdk_get_display()))
  112. /* fall back to traditional method */
  113. display = getenv("DISPLAY");
  114. return dupstr(display);
  115. }
  116. const int share_can_be_downstream = TRUE;
  117. const int share_can_be_upstream = TRUE;
  118. void setup(int single)
  119. {
  120. sk_init();
  121. flags = FLAG_VERBOSE | FLAG_INTERACTIVE;
  122. default_protocol = be_default_protocol;
  123. /* Find the appropriate default port. */
  124. {
  125. Backend *b = backend_from_proto(default_protocol);
  126. default_port = 0; /* illegal */
  127. if (b)
  128. default_port = b->default_port;
  129. }
  130. }