1 /* exp_win.c - window support
3 Written by: Don Libes, NIST, 10/25/93
5 This file is in the public domain. However, the author and NIST
6 would appreciate credit if you use this file or parts of it.
10 #include "expect_cf.h"
14 #include "../compat/stdlib.h"
19 /* _IBCS2 required on some Intel platforms to allow the include files */
20 /* to produce a definition for winsize. */
24 * get everyone's window size definitions
26 note that this is tricky because (of course) everyone puts them in
27 different places. Worse, on some systems, some .h files conflict
28 and cannot both be included even though both exist. This is the
29 case, for example, on SunOS 4.1.3 using gcc where termios.h
30 conflicts with sys/ioctl.h
36 # include <sys/ioctl.h>
39 /* Sigh. On AIX 2.3, termios.h exists but does not define TIOCGWINSZ */
40 /* Instead, it has to come from ioctl.h. However, As I said above, this */
41 /* can't be cavalierly included on all machines, even when it exists. */
42 #if defined(HAVE_TERMIOS) && !defined(HAVE_TIOCGWINSZ_IN_TERMIOS_H)
43 # include <sys/ioctl.h>
46 /* SCO defines window size structure in PTEM and TIOCGWINSZ in termio.h */
48 #if defined(HAVE_SYS_PTEM_H)
49 # include <sys/types.h> /* for stream.h's caddr_t */
50 # include <sys/stream.h> /* for ptem.h's mblk_t */
51 # include <sys/ptem.h>
52 #endif /* HAVE_SYS_PTEM_H */
54 #include "exp_tty_in.h"
58 typedef struct winsize exp_winsize;
59 #define columns ws_col
64 #if !defined(EXP_WIN) && defined(TIOCGSIZE)
65 typedef struct ttysize exp_winsize;
66 #define columns ts_cols
78 static exp_winsize winsize = {0, 0};
79 static exp_winsize win2size = {0, 0};
81 int exp_window_size_set(fd)
85 ioctl(fd,TIOCSWINSZ,&winsize);
87 #if defined(TIOCSSIZE) && !defined(TIOCSWINSZ)
88 ioctl(fd,TIOCSSIZE,&winsize);
92 int exp_window_size_get(fd)
96 ioctl(fd,TIOCGWINSZ,&winsize);
98 #if defined(TIOCGSIZE) && !defined(TIOCGWINSZ)
99 ioctl(fd,TIOCGSIZE,&winsize);
101 #if !defined(EXP_WIN)
108 exp_win_rows_set(rows)
111 winsize.rows = atoi(rows);
112 exp_window_size_set(exp_dev_tty);
118 static char rows [20];
119 exp_window_size_get(exp_dev_tty);
120 sprintf(rows,"%d",winsize.rows);
125 exp_win_columns_set(columns)
128 winsize.columns = atoi(columns);
129 exp_window_size_set(exp_dev_tty);
133 exp_win_columns_get()
135 static char columns [20];
136 exp_window_size_get(exp_dev_tty);
137 sprintf(columns,"%d",winsize.columns);
142 * separate copy of everything above - used for handling user stty requests
145 int exp_win2_size_set(fd)
149 ioctl(fd,TIOCSWINSZ,&win2size);
151 #if defined(TIOCSSIZE) && !defined(TIOCSWINSZ)
152 ioctl(fd,TIOCSSIZE,&win2size);
156 int exp_win2_size_get(fd)
160 ioctl(fd,TIOCGWINSZ,&win2size);
162 #if defined(TIOCGSIZE) && !defined(TIOCGWINSZ)
163 ioctl(fd,TIOCGSIZE,&win2size);
168 exp_win2_rows_set(fd,rows)
172 exp_win2_size_get(fd);
173 win2size.rows = atoi(rows);
174 exp_win2_size_set(fd);
178 exp_win2_rows_get(fd)
181 static char rows [20];
182 exp_win2_size_get(fd);
183 sprintf(rows,"%d",win2size.rows);
184 #if !defined(EXP_WIN)
186 win2size.columns = 0;
192 exp_win2_columns_set(fd,columns)
196 exp_win2_size_get(fd);
197 win2size.columns = atoi(columns);
198 exp_win2_size_set(fd);
202 exp_win2_columns_get(fd)
205 static char columns [20];
206 exp_win2_size_get(fd);
207 sprintf(columns,"%d",win2size.columns);