-
Notifications
You must be signed in to change notification settings - Fork 0
/
exp_win.c
217 lines (188 loc) · 4.04 KB
/
exp_win.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/* exp_win.c - window support
Written by: Don Libes, NIST, 10/25/93
This file is in the public domain. However, the author and NIST
would appreciate credit if you use this file or parts of it.
*/
#include "expect_cf.h"
#include "tcl.h"
#ifdef NO_STDLIB_H
#include "../compat/stdlib.h"
#else
#include <stdlib.h>
#endif
/* _IBCS2 required on some Intel platforms to allow the include files */
/* to produce a definition for winsize. */
#define _IBCS2 1
/*
* get everyone's window size definitions
*
note that this is tricky because (of course) everyone puts them in
different places. Worse, on some systems, some .h files conflict
and cannot both be included even though both exist. This is the
case, for example, on SunOS 4.1.3 using gcc where termios.h
conflicts with sys/ioctl.h
*/
#ifdef HAVE_TERMIOS
# include <termios.h>
#else
# include <sys/ioctl.h>
#endif
/* Sigh. On AIX 2.3, termios.h exists but does not define TIOCGWINSZ */
/* Instead, it has to come from ioctl.h. However, As I said above, this */
/* can't be cavalierly included on all machines, even when it exists. */
#if defined(HAVE_TERMIOS) && !defined(HAVE_TIOCGWINSZ_IN_TERMIOS_H)
# include <sys/ioctl.h>
#endif
/* SCO defines window size structure in PTEM and TIOCGWINSZ in termio.h */
/* Sigh... */
#if defined(HAVE_SYS_PTEM_H)
# include <sys/types.h> /* for stream.h's caddr_t */
# include <sys/stream.h> /* for ptem.h's mblk_t */
# include <sys/ptem.h>
#endif /* HAVE_SYS_PTEM_H */
#include "exp_tty_in.h"
#include "exp_win.h"
#ifdef TIOCGWINSZ
typedef struct winsize exp_winsize;
#define columns ws_col
#define rows ws_row
#define EXP_WIN
#endif
#if !defined(EXP_WIN) && defined(TIOCGSIZE)
typedef struct ttysize exp_winsize;
#define columns ts_cols
#define rows ts_lines
#define EXP_WIN
#endif
#if !defined(EXP_WIN)
typedef struct {
int columns;
int rows;
} exp_winsize;
#endif
static exp_winsize winsize = {0, 0};
static exp_winsize win2size = {0, 0};
int exp_window_size_set(fd)
int fd;
{
#ifdef TIOCSWINSZ
ioctl(fd,TIOCSWINSZ,&winsize);
#endif
#if defined(TIOCSSIZE) && !defined(TIOCSWINSZ)
ioctl(fd,TIOCSSIZE,&winsize);
#endif
}
int exp_window_size_get(fd)
int fd;
{
#ifdef TIOCGWINSZ
ioctl(fd,TIOCGWINSZ,&winsize);
#endif
#if defined(TIOCGSIZE) && !defined(TIOCGWINSZ)
ioctl(fd,TIOCGSIZE,&winsize);
#endif
#if !defined(EXP_WIN)
winsize.rows = 0;
winsize.columns = 0;
#endif
}
void
exp_win_rows_set(rows)
char *rows;
{
winsize.rows = atoi(rows);
exp_window_size_set(exp_dev_tty);
}
char*
exp_win_rows_get()
{
static char rows [20];
exp_window_size_get(exp_dev_tty);
sprintf(rows,"%d",winsize.rows);
return rows;
}
void
exp_win_columns_set(columns)
char *columns;
{
winsize.columns = atoi(columns);
exp_window_size_set(exp_dev_tty);
}
char*
exp_win_columns_get()
{
static char columns [20];
exp_window_size_get(exp_dev_tty);
sprintf(columns,"%d",winsize.columns);
return columns;
}
/*
* separate copy of everything above - used for handling user stty requests
*/
int exp_win2_size_set(fd)
int fd;
{
#ifdef TIOCSWINSZ
ioctl(fd,TIOCSWINSZ,&win2size);
#endif
#if defined(TIOCSSIZE) && !defined(TIOCSWINSZ)
ioctl(fd,TIOCSSIZE,&win2size);
#endif
}
int exp_win2_size_get(fd)
int fd;
{
#ifdef TIOCGWINSZ
ioctl(fd,TIOCGWINSZ,&win2size);
#endif
#if defined(TIOCGSIZE) && !defined(TIOCGWINSZ)
ioctl(fd,TIOCGSIZE,&win2size);
#endif
}
void
exp_win2_rows_set(fd,rows)
int fd;
char *rows;
{
exp_win2_size_get(fd);
win2size.rows = atoi(rows);
exp_win2_size_set(fd);
}
char*
exp_win2_rows_get(fd)
int fd;
{
static char rows [20];
exp_win2_size_get(fd);
sprintf(rows,"%d",win2size.rows);
#if !defined(EXP_WIN)
win2size.rows = 0;
win2size.columns = 0;
#endif
return rows;
}
void
exp_win2_columns_set(fd,columns)
int fd;
char *columns;
{
exp_win2_size_get(fd);
win2size.columns = atoi(columns);
exp_win2_size_set(fd);
}
char*
exp_win2_columns_get(fd)
int fd;
{
static char columns [20];
exp_win2_size_get(fd);
sprintf(columns,"%d",win2size.columns);
return columns;
}
/*
* Local Variables:
* mode: c
* c-basic-offset: 4
* fill-column: 78
* End:
*/