unix.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. #ifndef PUTTY_UNIX_H
  2. #define PUTTY_UNIX_H
  3. #ifdef HAVE_CONFIG_H
  4. # include "uxconfig.h" /* Space to hide it from mkfiles.pl */
  5. #endif
  6. #include <stdio.h> /* for FILENAME_MAX */
  7. #include <stdint.h> /* C99 int types */
  8. #ifndef NO_LIBDL
  9. #include <dlfcn.h> /* Dynamic library loading */
  10. #endif /* NO_LIBDL */
  11. #include "charset.h"
  12. #ifdef OSX_GTK
  13. /*
  14. * Assorted tweaks to various parts of the GTK front end which all
  15. * need to be enabled when compiling on OS X. Because I might need the
  16. * same tweaks on other systems in future, I don't want to
  17. * conditionalise all of them on OSX_GTK directly, so instead, each
  18. * one has its own name and we enable them all centrally here if
  19. * OSX_GTK is defined at configure time.
  20. */
  21. #define NOT_X_WINDOWS /* of course, all the X11 stuff should be disabled */
  22. #define NO_PTY_PRE_INIT /* OS X gets very huffy if we try to set[ug]id */
  23. #define SET_NONBLOCK_VIA_OPENPT /* work around missing fcntl functionality */
  24. #define OSX_META_KEY_CONFIG /* two possible Meta keys to choose from */
  25. /* this potential one of the Meta keys needs manual handling */
  26. #define META_MANUAL_MASK (GDK_MOD1_MASK)
  27. #define JUST_USE_GTK_CLIPBOARD_UTF8 /* low-level gdk_selection_* fails */
  28. #define DEFAULT_CLIPBOARD GDK_SELECTION_CLIPBOARD /* OS X has no PRIMARY */
  29. #endif
  30. struct Filename {
  31. char *path;
  32. };
  33. FILE *f_open(const struct Filename *, char const *, int);
  34. struct FontSpec {
  35. char *name; /* may be "" to indicate no selected font at all */
  36. };
  37. struct FontSpec *fontspec_new(const char *name);
  38. typedef void *Context; /* FIXME: probably needs changing */
  39. extern Backend pty_backend;
  40. #define BROKEN_PIPE_ERROR_CODE EPIPE /* used in sshshare.c */
  41. typedef uint32_t uint32; /* C99: uint32_t defined in stdint.h */
  42. #define PUTTY_UINT32_DEFINED
  43. /*
  44. * Under GTK, we send MA_CLICK _and_ MA_2CLK, or MA_CLICK _and_
  45. * MA_3CLK, when a button is pressed for the second or third time.
  46. */
  47. #define MULTICLICK_ONLY_EVENT 0
  48. /*
  49. * Under GTK, there is no context help available.
  50. */
  51. #define HELPCTX(x) P(NULL)
  52. #define FILTER_KEY_FILES NULL /* FIXME */
  53. #define FILTER_DYNLIB_FILES NULL /* FIXME */
  54. /*
  55. * Under X, selection data must not be NUL-terminated.
  56. */
  57. #define SELECTION_NUL_TERMINATED 0
  58. /*
  59. * Under X, copying to the clipboard terminates lines with just LF.
  60. */
  61. #define SEL_NL { 10 }
  62. /* Simple wraparound timer function */
  63. unsigned long getticks(void); /* based on gettimeofday(2) */
  64. #define GETTICKCOUNT getticks
  65. #define TICKSPERSEC 1000 /* we choose to use milliseconds */
  66. #define CURSORBLINK 450 /* no standard way to set this */
  67. #define WCHAR wchar_t
  68. #define BYTE unsigned char
  69. /*
  70. * Unix-specific global flag
  71. *
  72. * FLAG_STDERR_TTY indicates that standard error might be a terminal and
  73. * might get its configuration munged, so anything trying to output plain
  74. * text (i.e. with newlines in it) will need to put it back into cooked
  75. * mode first. Applications setting this flag should also call
  76. * stderr_tty_init() before messing with any terminal modes, and can call
  77. * premsg() before outputting text to stderr and postmsg() afterwards.
  78. */
  79. #define FLAG_STDERR_TTY 0x1000
  80. /* The per-session frontend structure managed by gtkwin.c */
  81. struct gui_data;
  82. struct gui_data *new_session_window(Conf *conf, const char *geometry_string);
  83. /* Defined in gtkmain.c */
  84. void launch_duplicate_session(Conf *conf);
  85. void launch_new_session(void);
  86. void launch_saved_session(const char *str);
  87. #ifdef MAY_REFER_TO_GTK_IN_HEADERS
  88. GtkWidget *make_gtk_toplevel_window(void *frontend);
  89. #endif
  90. /* Defined in gtkcomm.c */
  91. void gtkcomm_setup(void);
  92. /* Things pty.c needs from pterm.c */
  93. const char *get_x_display(void *frontend);
  94. int font_dimension(void *frontend, int which);/* 0 for width, 1 for height */
  95. long get_windowid(void *frontend);
  96. int frontend_is_utf8(void *frontend);
  97. /* Things gtkdlg.c needs from pterm.c */
  98. void *get_window(void *frontend); /* void * to avoid depending on gtk.h */
  99. void post_main(void); /* called after any subsidiary gtk_main() */
  100. /* Things pterm.c needs from gtkdlg.c */
  101. int do_config_box(const char *title, Conf *conf,
  102. int midsession, int protcfginfo);
  103. void fatal_message_box(void *window, const char *msg);
  104. void nonfatal_message_box(void *window, const char *msg);
  105. void about_box(void *window);
  106. void *eventlogstuff_new(void);
  107. void showeventlog(void *estuff, void *parentwin);
  108. void logevent_dlg(void *estuff, const char *string);
  109. int reallyclose(void *frontend);
  110. #ifdef MAY_REFER_TO_GTK_IN_HEADERS
  111. int messagebox(GtkWidget *parentwin, const char *title,
  112. const char *msg, int minwid, int selectable, ...);
  113. #endif
  114. /* Things pterm.c needs from {ptermm,uxputty}.c */
  115. char *make_default_wintitle(char *hostname);
  116. int process_nonoption_arg(const char *arg, Conf *conf, int *allow_launch);
  117. /* pterm.c needs this special function in xkeysym.c */
  118. int keysym_to_unicode(int keysym);
  119. /* Things uxstore.c needs from pterm.c */
  120. char *x_get_default(const char *key);
  121. /* Things uxstore.c provides to pterm.c */
  122. void provide_xrm_string(char *string);
  123. /* Things provided by uxcons.c */
  124. struct termios;
  125. void stderr_tty_init(void);
  126. void premsg(struct termios *);
  127. void postmsg(struct termios *);
  128. /* The interface used by uxsel.c */
  129. typedef struct uxsel_id uxsel_id;
  130. void uxsel_init(void);
  131. typedef int (*uxsel_callback_fn)(int fd, int event);
  132. void uxsel_set(int fd, int rwx, uxsel_callback_fn callback);
  133. void uxsel_del(int fd);
  134. int select_result(int fd, int event);
  135. int first_fd(int *state, int *rwx);
  136. int next_fd(int *state, int *rwx);
  137. /* The following are expected to be provided _to_ uxsel.c by the frontend */
  138. uxsel_id *uxsel_input_add(int fd, int rwx); /* returns an id */
  139. void uxsel_input_remove(uxsel_id *id);
  140. /* uxcfg.c */
  141. struct controlbox;
  142. void unix_setup_config_box(struct controlbox *b, int midsession, int protocol);
  143. /* gtkcfg.c */
  144. void gtk_setup_config_box(struct controlbox *b, int midsession, void *window);
  145. /*
  146. * In the Unix Unicode layer, DEFAULT_CODEPAGE is a special value
  147. * which causes mb_to_wc and wc_to_mb to call _libc_ rather than
  148. * libcharset. That way, we can interface the various charsets
  149. * supported by libcharset with the one supported by mbstowcs and
  150. * wcstombs (which will be the character set in which stuff read
  151. * from the command line or config files is assumed to be encoded).
  152. */
  153. #define DEFAULT_CODEPAGE 0xFFFF
  154. #define CP_UTF8 CS_UTF8 /* from libcharset */
  155. #define strnicmp strncasecmp
  156. #define stricmp strcasecmp
  157. /* BSD-semantics version of signal(), and another helpful function */
  158. void (*putty_signal(int sig, void (*func)(int)))(int);
  159. void block_signal(int sig, int block_it);
  160. /* uxmisc.c */
  161. void cloexec(int);
  162. void noncloexec(int);
  163. int nonblock(int);
  164. int no_nonblock(int);
  165. char *make_dir_and_check_ours(const char *dirname);
  166. /*
  167. * Exports from unicode.c.
  168. */
  169. struct unicode_data;
  170. int init_ucs(struct unicode_data *ucsdata, char *line_codepage,
  171. int utf8_override, int font_charset, int vtmode);
  172. /*
  173. * Spare function exported directly from uxnet.c.
  174. */
  175. void *sk_getxdmdata(void *sock, int *lenp);
  176. /*
  177. * General helpful Unix stuff: more helpful version of the FD_SET
  178. * macro, which also handles maxfd.
  179. */
  180. #define FD_SET_MAX(fd, max, set) do { \
  181. FD_SET(fd, &set); \
  182. if (max < fd + 1) max = fd + 1; \
  183. } while (0)
  184. /*
  185. * Exports from winser.c.
  186. */
  187. extern Backend serial_backend;
  188. /*
  189. * uxpeer.c, wrapping getsockopt(SO_PEERCRED).
  190. */
  191. int so_peercred(int fd, int *pid, int *uid, int *gid);
  192. /*
  193. * Default font setting, which can vary depending on NOT_X_WINDOWS.
  194. */
  195. #ifdef NOT_X_WINDOWS
  196. #define DEFAULT_GTK_FONT "client:Monospace 12"
  197. #else
  198. #define DEFAULT_GTK_FONT "server:fixed"
  199. #endif
  200. #endif