console.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Common pieces between the platform console frontend modules.
  3. */
  4. #include <stdbool.h>
  5. #include <stdarg.h>
  6. #include "putty.h"
  7. #include "misc.h"
  8. #include "console.h"
  9. const char console_abandoned_msg[] = "Connection abandoned.\n";
  10. const SeatDialogPromptDescriptions *console_prompt_descriptions(Seat *seat)
  11. {
  12. static const SeatDialogPromptDescriptions descs = {
  13. .hk_accept_action = "enter \"y\"",
  14. .hk_connect_once_action = "enter \"n\"",
  15. .hk_cancel_action = "press Return",
  16. .hk_cancel_action_Participle = "Pressing Return",
  17. .weak_accept_action = "enter \"y\"",
  18. .weak_cancel_action = "enter \"n\"",
  19. };
  20. return &descs;
  21. }
  22. bool console_batch_mode = false;
  23. bool console_set_batch_mode(bool newvalue)
  24. {
  25. console_batch_mode = newvalue;
  26. return true;
  27. }
  28. /*
  29. * Error message and/or fatal exit functions, all based on
  30. * console_print_error_msg which the platform front end provides.
  31. */
  32. void console_print_error_msg_fmt_v(
  33. const char *prefix, const char *fmt, va_list ap)
  34. {
  35. char *msg = dupvprintf(fmt, ap);
  36. console_print_error_msg(prefix, msg);
  37. sfree(msg);
  38. }
  39. void console_print_error_msg_fmt(const char *prefix, const char *fmt, ...)
  40. {
  41. va_list ap;
  42. va_start(ap, fmt);
  43. console_print_error_msg_fmt_v(prefix, fmt, ap);
  44. va_end(ap);
  45. }
  46. void modalfatalbox(const char *fmt, ...)
  47. {
  48. va_list ap;
  49. va_start(ap, fmt);
  50. console_print_error_msg_fmt_v("FATAL ERROR", fmt, ap);
  51. va_end(ap);
  52. cleanup_exit(1);
  53. }
  54. void nonfatal(const char *fmt, ...)
  55. {
  56. va_list ap;
  57. va_start(ap, fmt);
  58. console_print_error_msg_fmt_v("ERROR", fmt, ap);
  59. va_end(ap);
  60. }
  61. void console_connection_fatal(Seat *seat, const char *msg)
  62. {
  63. console_print_error_msg("FATAL ERROR", msg);
  64. cleanup_exit(1);
  65. }
  66. void console_nonfatal(Seat *seat, const char *msg)
  67. {
  68. console_print_error_msg("ERROR", msg);
  69. }
  70. /*
  71. * Console front ends redo their select() or equivalent every time, so
  72. * they don't need separate timer handling.
  73. */
  74. void timer_change_notify(unsigned long next)
  75. {
  76. }