Add support for resetting the terminal modes on stderr to something sensible
[u/mdw/putty] / unix / unix.h
... / ...
CommitLineData
1#ifndef PUTTY_UNIX_H
2#define PUTTY_UNIX_H
3
4#ifdef HAVE_CONFIG_H
5# include "uxconfig.h" /* Space to hide it from mkfiles.pl */
6#endif
7
8#include <stdio.h> /* for FILENAME_MAX */
9#include "charset.h"
10
11struct Filename {
12 char path[FILENAME_MAX];
13};
14FILE *f_open(struct Filename, char const *, int);
15
16struct FontSpec {
17 char name[256];
18};
19
20typedef void *Context; /* FIXME: probably needs changing */
21
22typedef int OSSocket;
23#define OSSOCKET_DEFINED /* stop network.h using its default */
24
25extern Backend pty_backend;
26
27/*
28 * Under GTK, we send MA_CLICK _and_ MA_2CLK, or MA_CLICK _and_
29 * MA_3CLK, when a button is pressed for the second or third time.
30 */
31#define MULTICLICK_ONLY_EVENT 0
32
33/*
34 * Under GTK, there is no context help available.
35 */
36#define HELPCTX(x) P(NULL)
37#define FILTER_KEY_FILES NULL /* FIXME */
38
39/*
40 * Under X, selection data must not be NUL-terminated.
41 */
42#define SELECTION_NUL_TERMINATED 0
43
44/*
45 * Under X, copying to the clipboard terminates lines with just LF.
46 */
47#define SEL_NL { 10 }
48
49/* Simple wraparound timer function */
50unsigned long getticks(void); /* based on gettimeofday(2) */
51#define GETTICKCOUNT getticks
52#define TICKSPERSEC 1000 /* we choose to use milliseconds */
53#define CURSORBLINK 450 /* no standard way to set this */
54/* getticks() works using gettimeofday(), so it's vulnerable to system clock
55 * changes causing chaos. Therefore, we provide a compensation mechanism. */
56#define TIMING_SYNC
57#define TIMING_SYNC_ANOW
58extern long tickcount_offset;
59
60#define WCHAR wchar_t
61#define BYTE unsigned char
62
63/*
64 * Unix-specific global flag
65 *
66 * FLAG_STDERR_TTY indicates that standard error might be a terminal and
67 * might get its configuration munged, so anything trying to output plain
68 * text (i.e. with newlines in it) will need to put it back into cooked
69 * mode first. Applications setting this flag should also call
70 * stderr_tty_init() before messing with any terminal modes, and can call
71 * premsg() before outputting text to stderr and postmsg() afterwards.
72 */
73#define FLAG_STDERR_TTY 0x1000
74
75/* Things pty.c needs from pterm.c */
76char *get_x_display(void *frontend);
77int font_dimension(void *frontend, int which);/* 0 for width, 1 for height */
78long get_windowid(void *frontend);
79
80/* Things gtkdlg.c needs from pterm.c */
81void *get_window(void *frontend); /* void * to avoid depending on gtk.h */
82
83/* Things pterm.c needs from gtkdlg.c */
84int do_config_box(const char *title, Config *cfg,
85 int midsession, int protcfginfo);
86void fatal_message_box(void *window, char *msg);
87void about_box(void *window);
88void *eventlogstuff_new(void);
89void showeventlog(void *estuff, void *parentwin);
90void logevent_dlg(void *estuff, const char *string);
91int reallyclose(void *frontend);
92
93/* Things pterm.c needs from {ptermm,uxputty}.c */
94char *make_default_wintitle(char *hostname);
95int process_nonoption_arg(char *arg, Config *cfg, int *allow_launch);
96
97/* pterm.c needs this special function in xkeysym.c */
98int keysym_to_unicode(int keysym);
99
100/* Things uxstore.c needs from pterm.c */
101char *x_get_default(const char *key);
102
103/* Things uxstore.c provides to pterm.c */
104void provide_xrm_string(char *string);
105
106/* Things provided by uxcons.c */
107struct termios;
108void stderr_tty_init(void);
109void premsg(struct termios *);
110void postmsg(struct termios *);
111
112/* The interface used by uxsel.c */
113void uxsel_init(void);
114typedef int (*uxsel_callback_fn)(int fd, int event);
115void uxsel_set(int fd, int rwx, uxsel_callback_fn callback);
116void uxsel_del(int fd);
117int select_result(int fd, int event);
118int first_fd(int *state, int *rwx);
119int next_fd(int *state, int *rwx);
120/* The following are expected to be provided _to_ uxsel.c by the frontend */
121int uxsel_input_add(int fd, int rwx); /* returns an id */
122void uxsel_input_remove(int id);
123
124/* uxcfg.c */
125struct controlbox;
126void unix_setup_config_box(struct controlbox *b, int midsession, int protocol);
127
128/* gtkcfg.c */
129void gtk_setup_config_box(struct controlbox *b, int midsession, void *window);
130
131/*
132 * In the Unix Unicode layer, DEFAULT_CODEPAGE is a special value
133 * which causes mb_to_wc and wc_to_mb to call _libc_ rather than
134 * libcharset. That way, we can interface the various charsets
135 * supported by libcharset with the one supported by mbstowcs and
136 * wcstombs (which will be the character set in which stuff read
137 * from the command line or config files is assumed to be encoded).
138 */
139#define DEFAULT_CODEPAGE 0xFFFF
140#define CP_UTF8 CS_UTF8 /* from libcharset */
141
142#define strnicmp strncasecmp
143#define stricmp strcasecmp
144
145/* BSD-semantics version of signal(), and another helpful function */
146void (*putty_signal(int sig, void (*func)(int)))(int);
147void block_signal(int sig, int block_it);
148
149/* uxmisc.c */
150int cloexec(int);
151
152/*
153 * Exports from unicode.c.
154 */
155struct unicode_data;
156int init_ucs(struct unicode_data *ucsdata, char *line_codepage,
157 int utf8_override, int font_charset, int vtmode);
158
159/*
160 * Spare function exported directly from uxnet.c.
161 */
162void *sk_getxdmdata(void *sock, int *lenp);
163
164/*
165 * General helpful Unix stuff: more helpful version of the FD_SET
166 * macro, which also handles maxfd.
167 */
168#define FD_SET_MAX(fd, max, set) do { \
169 FD_SET(fd, &set); \
170 if (max < fd + 1) max = fd + 1; \
171} while (0)
172
173/*
174 * Exports from winser.c.
175 */
176extern Backend serial_backend;
177
178#endif