putty.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. #define MAY_REFER_TO_GTK_IN_HEADERS
  12. #include "putty.h"
  13. #include "ssh.h"
  14. #include "storage.h"
  15. #include "gtkcompat.h"
  16. #ifndef NOT_X_WINDOWS
  17. #include <gdk/gdkx.h>
  18. #endif
  19. /*
  20. * Stubs to avoid pty.c needing to be linked in.
  21. */
  22. const bool use_pty_argv = false;
  23. char **pty_argv; /* never used */
  24. char *pty_osx_envrestore_prefix;
  25. /*
  26. * Clean up and exit.
  27. */
  28. void cleanup_exit(int code)
  29. {
  30. /*
  31. * Clean up.
  32. */
  33. sk_cleanup();
  34. random_save_seed();
  35. exit(code);
  36. }
  37. const struct BackendVtable *select_backend(Conf *conf)
  38. {
  39. const struct BackendVtable *vt =
  40. backend_vt_from_proto(conf_get_int(conf, CONF_protocol));
  41. assert(vt != NULL);
  42. return vt;
  43. }
  44. void initial_config_box(Conf *conf, post_dialog_fn_t after, void *afterctx)
  45. {
  46. char *title = dupcat(appname, " Configuration");
  47. create_config_box(title, conf, false, 0, after, afterctx);
  48. sfree(title);
  49. }
  50. const bool use_event_log = true, new_session = true, saved_sessions = true;
  51. const bool dup_check_launchable = true;
  52. /*
  53. * X11-forwarding-related things suitable for Gtk app.
  54. */
  55. char *platform_get_x_display(void) {
  56. const char *display;
  57. #ifndef NOT_X_WINDOWS
  58. /* Try to take account of --display and what have you. */
  59. if (!GDK_IS_X11_DISPLAY(gdk_display_get_default()) ||
  60. !(display = gdk_get_display()))
  61. #endif
  62. /* fall back to traditional method */
  63. display = getenv("DISPLAY");
  64. return dupstr(display);
  65. }
  66. const bool share_can_be_downstream = true;
  67. const bool share_can_be_upstream = true;
  68. const unsigned cmdline_tooltype =
  69. TOOLTYPE_HOST_ARG |
  70. TOOLTYPE_PORT_ARG |
  71. TOOLTYPE_NO_VERBOSE_OPTION;
  72. void setup(bool single)
  73. {
  74. sk_init();
  75. enable_dit();
  76. settings_set_default_protocol(be_default_protocol);
  77. /* Find the appropriate default port. */
  78. {
  79. const struct BackendVtable *vt =
  80. backend_vt_from_proto(be_default_protocol);
  81. settings_set_default_port(0); /* illegal */
  82. if (vt)
  83. settings_set_default_port(vt->default_port);
  84. }
  85. }