OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [expect/] [exp_win.c] - Blame information for rev 1772

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
/* exp_win.c - window support
2
 
3
Written by: Don Libes, NIST, 10/25/93
4
 
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.
7
 
8
*/
9
 
10
#include "expect_cf.h"
11
#include "tcl.h"
12
 
13
#ifdef NO_STDLIB_H
14
#include "../compat/stdlib.h"
15
#else
16
#include <stdlib.h>
17
#endif
18
 
19
/* _IBCS2 required on some Intel platforms to allow the include files */
20
/* to produce a definition for winsize. */
21
#define _IBCS2 1
22
 
23
/*
24
 * get everyone's window size definitions
25
 *
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
31
 */
32
 
33
#ifdef HAVE_TERMIOS
34
#  include <termios.h>
35
#else
36
#  include <sys/ioctl.h>
37
#endif
38
 
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>
44
#endif
45
 
46
/* SCO defines window size structure in PTEM and TIOCGWINSZ in termio.h */
47
/* Sigh... */
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 */
53
 
54
#include "exp_tty.h"
55
#include "exp_win.h"
56
 
57
#ifdef TIOCGWINSZ
58
typedef struct winsize exp_winsize;
59
#define columns ws_col
60
#define rows ws_row
61
#define EXP_WIN
62
#endif
63
 
64
#if !defined(EXP_WIN) && defined(TIOCGSIZE)
65
typedef struct ttysize exp_winsize;
66
#define columns ts_cols
67
#define rows ts_lines
68
#define EXP_WIN
69
#endif
70
 
71
#if !defined(EXP_WIN)
72
typedef struct {
73
        int columns;
74
        int rows;
75
} exp_winsize;
76
#endif
77
 
78
static exp_winsize winsize = {0, 0};
79
static exp_winsize win2size = {0, 0};
80
 
81
int exp_window_size_set(fd)
82
int fd;
83
{
84
#ifdef TIOCSWINSZ
85
        ioctl(fd,TIOCSWINSZ,&winsize);
86
#endif
87
#if defined(TIOCSSIZE) && !defined(TIOCSWINSZ)
88
        ioctl(fd,TIOCSSIZE,&winsize);
89
#endif
90
}
91
 
92
int exp_window_size_get(fd)
93
int fd;
94
{
95
#ifdef TIOCGWINSZ
96
        ioctl(fd,TIOCGWINSZ,&winsize);
97
#endif
98
#if defined(TIOCGSIZE) && !defined(TIOCGWINSZ)
99
        ioctl(fd,TIOCGSIZE,&winsize);
100
#endif
101
#if !defined(EXP_WIN)
102
        winsize.rows = 0;
103
        winsize.columns = 0;
104
#endif
105
}
106
 
107
void
108
exp_win_rows_set(rows)
109
char *rows;
110
{
111
        winsize.rows = atoi(rows);
112
        exp_window_size_set(exp_dev_tty);
113
}
114
 
115
void
116
exp_win_rows_get(rows)
117
char *rows;
118
{
119
        exp_window_size_get(exp_dev_tty);
120
        sprintf(rows,"%d",winsize.rows);
121
}
122
 
123
void
124
exp_win_columns_set(columns)
125
char *columns;
126
{
127
        winsize.columns = atoi(columns);
128
        exp_window_size_set(exp_dev_tty);
129
}
130
 
131
void
132
exp_win_columns_get(columns)
133
char *columns;
134
{
135
        exp_window_size_get(exp_dev_tty);
136
        sprintf(columns,"%d",winsize.columns);
137
}
138
 
139
/*
140
 * separate copy of everything above - used for handling user stty requests
141
 */
142
 
143
int exp_win2_size_set(fd)
144
int fd;
145
{
146
#ifdef TIOCSWINSZ
147
                        ioctl(fd,TIOCSWINSZ,&win2size);
148
#endif
149
#if defined(TIOCSSIZE) && !defined(TIOCSWINSZ)
150
                        ioctl(fd,TIOCSSIZE,&win2size);
151
#endif
152
}
153
 
154
int exp_win2_size_get(fd)
155
int fd;
156
{
157
#ifdef TIOCGWINSZ
158
        ioctl(fd,TIOCGWINSZ,&win2size);
159
#endif
160
#if defined(TIOCGSIZE) && !defined(TIOCGWINSZ)
161
        ioctl(fd,TIOCGSIZE,&win2size);
162
#endif
163
}
164
 
165
void
166
exp_win2_rows_set(fd,rows)
167
int fd;
168
char *rows;
169
{
170
        exp_win2_size_get(fd);
171
        win2size.rows = atoi(rows);
172
        exp_win2_size_set(fd);
173
}
174
 
175
void
176
exp_win2_rows_get(fd,rows)
177
int fd;
178
char *rows;
179
{
180
        exp_win2_size_get(fd);
181
        sprintf(rows,"%d",win2size.rows);
182
#if !defined(EXP_WIN)
183
        win2size.rows = 0;
184
        win2size.columns = 0;
185
#endif
186
}
187
 
188
void
189
exp_win2_columns_set(fd,columns)
190
int fd;
191
char *columns;
192
{
193
        exp_win2_size_get(fd);
194
        win2size.columns = atoi(columns);
195
        exp_win2_size_set(fd);
196
}
197
 
198
void
199
exp_win2_columns_get(fd,columns)
200
int fd;
201
char *columns;
202
{
203
        exp_win2_size_get(fd);
204
        sprintf(columns,"%d",win2size.columns);
205
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.