2
* Copyright (c) 1993-2009, Paul Mattes.
3
* Copyright (c) 2005, Don Russell.
4
* Copyright (c) 1990, Jeff Sparkes.
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions are met:
9
* * Redistributions of source code must retain the above copyright
10
* notice, this list of conditions and the following disclaimer.
11
* * Redistributions in binary form must reproduce the above copyright
12
* notice, this list of conditions and the following disclaimer in the
13
* documentation and/or other materials provided with the distribution.
14
* * Neither the names of Paul Mattes, Don Russell, Jeff Sparkes nor the
15
* names of their contributors may be used to endorse or promote
16
* products derived from this software without specific prior written
19
* THIS SOFTWARE IS PROVIDED BY PAUL MATTES, DON RUSSELL AND JEFF SPARKES
20
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PAUL MATTES, DON RUSSELL OR JEFF
23
* SPARKES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
* POSSIBILITY OF SUCH DAMAGE.
34
* Common definitions for x3270, c3270, s3270 and tcl3270.
37
/* Autoconf settings. */
38
#include "conf.h" /* autoconf settings */
39
#if defined(X3270_TN3270E) && !defined(X3270_ANSI) /*[*/
40
#define X3270_ANSI 1 /* RFC2355 requires NVT mode */
42
#if defined(HAVE_VASPRINTF) && !defined(_GNU_SOURCE) /*[*/
43
#define _GNU_SOURCE /* vasprintf isn't POSIX */
47
* OS-specific #defines. Except for the blocking-connect workarounds, these
48
* should be replaced with autoconf probes as soon as possible.
52
* BLOCKING_CONNECT_ONLY
53
* Use only blocking sockets.
55
#if defined(sco) /*[*/
56
#define BLOCKING_CONNECT_ONLY 1
59
#if defined(apollo) /*[*/
60
#define BLOCKING_CONNECT_ONLY 1
64
* Compiler-specific #defines.
67
/* '_is_unused' explicitly flags an unused parameter */
68
#if defined(__GNUC__) /*[*/
69
#define _is_unused __attribute__((__unused__))
70
#define printflike(s,f) __attribute__ ((__format__ (__printf__, s, f)))
72
#define _is_unused /* nothing */
73
#define printflike(s, f) /* nothing */
77
* Prerequisite #includes.
79
#include <stdio.h> /* Unix standard I/O library */
80
#include <stdlib.h> /* Other Unix library functions */
81
#if !defined(_MSC_VER) /*[*/
82
#include <unistd.h> /* Unix system calls */
84
#include <ctype.h> /* Character classes */
85
#include <string.h> /* String manipulations */
86
#include <sys/types.h> /* Basic system data types */
87
#if !defined(_MSC_VER) /*[*/
88
#include <sys/time.h> /* System time-related data types */
90
#include <time.h> /* C library time functions */
91
#include "localdefs.h" /* {s,tcl,c}3270-specific defines */
96
#if defined(_MSC_VER) /*[*/
97
#include <winsock2.h> /* for struct timeval */
98
extern int gettimeofday(struct timeval *, void *);
100
#define strcasecmp _stricmp
101
#define strncasecmp _strnicmp
105
* Locale-related definitions.
106
* Note that USE_ICONV can be used to override __STDC_ISO_10646__, so that
107
* development of iconv-based logic can be done on 10646-compliant systems.
109
#if defined(__STDC_ISO_10646__) && !defined(USE_ICONV) /*[*/
110
#define UNICODE_WCHAR 1
112
#if !defined(_WIN32) && !defined(UNICODE_WCHAR) /*[*/
119
* Unicode UCS-4 characters are (hopefully) 32 bits.
120
* EBCDIC (including DBCS) is (hopefully) 16 bits.
122
typedef unsigned int ucs4_t;
123
typedef unsigned short ebc_t;
126
* Cancel out contradictory parts.
128
#if !defined(X3270_DISPLAY) /*[*/
132
#if defined(C3270) && defined(X3270_DBCS) && !defined(CURSES_WIDE) /*[*/
136
/* Local process (-e) header files. */
137
#if defined(X3270_LOCAL_PROCESS) && defined(HAVE_FORKPTY) /*[*/
138
#define LOCAL_PROCESS 1
140
#if defined(HAVE_PTY_H) /*[*/
143
#if defined(HAVE_LIBUTIL_H) /*[*/
146
#if defined(HAVE_UTIL_H) /*[*/
151
/* Functions we may need to supply. */
152
#if defined(NEED_STRTOK_R) /*[*/
153
extern char *strtok_r(char *str, const char *sep, char **last);
156
/* Stop conflicting with curses' COLS, even if we don't link with it. */
159
/* Simple global variables */
161
extern int COLS; /* current */
163
extern int maxCOLS; /* maximum */
165
extern int defROWS; /* default (EraseWrite) */
167
extern int altROWS; /* alternate (EraseWriteAlternate) */
169
#if defined(X3270_DISPLAY) /*[*/
170
extern Atom a_3270, a_registry, a_encoding;
171
extern XtAppContext appcontext;
173
extern const char *build;
174
extern const char *build_rpq_timestamp;
175
extern const char *build_rpq_version;
177
extern char *connected_lu;
178
extern char *connected_type;
179
extern char *current_host;
180
extern unsigned short current_port;
181
#if defined(X3270_DBCS) /*[*/
184
#if defined(X3270_FT) /*[*/
185
extern int dft_buffersize;
187
extern char *efontname;
188
extern Boolean ever_3270;
189
extern Boolean exiting;
190
#if defined(X3270_DISPLAY) /*[*/
191
extern Boolean *extended_3270font;
193
extern Boolean *font_8bit;
195
extern Boolean flipped;
196
extern char *full_current_host;
197
extern char *full_efontname;
198
#if defined(X3270_DBCS) /*[*/
199
extern char *full_efontname_dbcs;
201
extern char full_model_name[];
202
extern char *funky_font;
203
extern char *hostname;
204
#if defined(X3270_DBCS) /*[*/
205
#if defined(X3270_DISPLAY) /*[*/
206
extern char *locale_name;
209
extern char luname[];
210
#if defined(LOCAL_PROCESS) /*[*/
211
extern Boolean local_process;
213
extern char *model_name;
214
extern int model_num;
215
extern Boolean no_login_host;
216
extern Boolean non_tn3270e_host;
217
extern int ov_cols, ov_rows;
218
extern Boolean ov_auto;
219
extern Boolean passthru_host;
220
extern const char *programname;
221
extern char *qualified_host;
222
extern char *reconnect_host;
223
extern int screen_depth;
224
extern Boolean scroll_initted;
225
#if defined(HAVE_LIBSSL) /*[*/
226
extern Boolean secure_connection;
228
extern Boolean shifted;
229
extern Boolean ssl_host;
230
extern Boolean *standard_font;
231
extern Boolean std_ds_host;
232
extern char *termtype;
233
extern Widget toplevel;
234
extern Boolean visible_control;
235
extern int *xtra_width;
237
#if defined(X3270_DISPLAY) /*[*/
238
extern Atom a_delete_me;
239
extern Atom a_save_yourself;
241
extern Display *display;
243
extern Pixel keypadbg_pixel;
244
extern XrmDatabase rdb;
245
extern Window root_window;
246
extern char *user_title;
249
#if defined(_WIN32) && (defined(C3270) || defined(S3270)) /*[*/
250
extern char *instdir;
251
extern char *myappdata;
254
#if defined(_WIN32) && defined(C3270) /*[*/
255
extern int is_installed;
258
/* Data types and complex global variables */
260
/* connection state */
262
NOT_CONNECTED, /* no socket, unknown mode */
263
RESOLVING, /* resolving hostname */
264
PENDING, /* connection pending */
265
CONNECTED_INITIAL, /* connected, no mode yet */
266
CONNECTED_ANSI, /* connected in NVT ANSI mode */
267
CONNECTED_3270, /* connected in old-style 3270 mode */
268
CONNECTED_INITIAL_E, /* connected in TN3270E mode, unnegotiated */
269
CONNECTED_NVT, /* connected in TN3270E mode, NVT mode */
270
CONNECTED_SSCP, /* connected in TN3270E mode, SSCP-LU mode */
271
CONNECTED_TN3270E /* connected in TN3270E mode, 3270 mode */
273
extern enum cstate cstate;
275
#define PCONNECTED ((int)cstate >= (int)RESOLVING)
276
#define HALF_CONNECTED (cstate == RESOLVING || cstate == PENDING)
277
#define CONNECTED ((int)cstate >= (int)CONNECTED_INITIAL)
278
#define IN_NEITHER (cstate == CONNECTED_INITIAL)
279
#define IN_ANSI (cstate == CONNECTED_ANSI || cstate == CONNECTED_NVT)
280
#define IN_3270 (cstate == CONNECTED_3270 || cstate == CONNECTED_TN3270E || cstate == CONNECTED_SSCP)
281
#define IN_SSCP (cstate == CONNECTED_SSCP)
282
#define IN_TN3270E (cstate == CONNECTED_TN3270E)
283
#define IN_E (cstate >= CONNECTED_INITIAL_E)
285
/* keyboard modifer bitmap */
286
#define ShiftKeyDown 0x01
287
#define MetaKeyDown 0x02
288
#define AltKeyDown 0x04
295
extern struct toggle_name toggle_names[];
297
/* extended attributes */
299
unsigned char cc; /* EBCDIC or ASCII character code */
300
unsigned char fa; /* field attribute, it nonzero */
301
unsigned char fg; /* foreground color (0x00 or 0xf<n>) */
302
unsigned char bg; /* background color (0x00 or 0xf<n>) */
303
unsigned char gr; /* ANSI graphics rendition bits */
304
unsigned char cs; /* character set (GE flag, or 0..2) */
305
unsigned char ic; /* input control (DBCS) */
306
unsigned char db; /* DBCS state */
308
#define GR_BLINK 0x01
309
#define GR_REVERSE 0x02
310
#define GR_UNDERLINE 0x04
311
#define GR_INTENSIFY 0x08
313
#define CS_MASK 0x03 /* mask for specific character sets */
314
#define CS_BASE 0x00 /* base character set (X'00') */
315
#define CS_APL 0x01 /* APL character set (X'01' or GE) */
316
#define CS_LINEDRAW 0x02 /* DEC line-drawing character set (ANSI) */
317
#define CS_DBCS 0x03 /* DBCS character set (X'F8') */
318
#define CS_GE 0x04 /* cs flag for Graphic Escape */
320
/* translation lists */
326
struct trans_list *next;
328
extern struct trans_list *trans_list;
331
enum keytype { KT_STD, KT_GE };
334
#define ST_RESOLVING 1
335
#define ST_HALF_CONNECT 2
337
#define ST_3270_MODE 4
338
#define ST_LINE_MODE 5
345
/* Naming convention for private actions. */
348
/* Shorthand macros */
350
#define CN ((char *) NULL)
351
#define PN ((XtPointer) NULL)
352
#define Replace(var, value) { Free(var); var = (value); }
354
/* Configuration change masks. */
355
#define NO_CHANGE 0x0000 /* no change */
356
#define MODEL_CHANGE 0x0001 /* screen dimensions changed */
357
#define FONT_CHANGE 0x0002 /* emulator font changed */
358
#define COLOR_CHANGE 0x0004 /* color scheme or 3278/9 mode changed */
359
#define SCROLL_CHANGE 0x0008 /* scrollbar snapped on or off */
360
#define CHARSET_CHANGE 0x0010 /* character set changed */
361
#define ALL_CHANGE 0xffff /* everything changed */
363
/* Portability macros */
365
/* Equivalent of setlinebuf */
367
#if defined(_IOLBF) /*[*/
368
#define SETLINEBUF(s) setvbuf(s, (char *)NULL, _IOLBF, BUFSIZ)
370
#define SETLINEBUF(s) setlinebuf(s)
373
/* Motorola version of gettimeofday */
375
#if defined(MOTOROLA)
376
#define gettimeofday(tp,tz) gettimeofday(tp)
379
/* Default DFT file transfer buffer size. */
380
#if defined(X3270_FT) && !defined(DFT_BUF) /*[*/
381
#define DFT_BUF (4 * 1024)
384
/* DBCS Preedit Types */
385
#if defined(X3270_DBCS) /*[*/
386
#define PT_ROOT "Root"
387
#define PT_OVER_THE_SPOT "OverTheSpot"
388
#define PT_OFF_THE_SPOT "OffTheSpot"
389
#define PT_ON_THE_SPOT "OnTheSpot"