Debian Codegraph @

libsrc/os/unix/winsize.c

raw
1 /*===========================================================================
2 Copyright (C) 1995-2009 European Southern Observatory (ESO)
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as
6 published by the Free Software Foundation; either version 2 of
7 the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public
15 License along with this program; if not, write to the Free
16 Software Foundation, Inc., 675 Massachusetts Ave, Cambridge,
17 MA 02139, USA.
18
19 Correspondence concerning ESO-MIDAS should be addressed as follows:
20 Internet e-mail: [email protected]
21 Postal address: European Southern Observatory
22 Data Management Division
23 Karl-Schwarzschild-Strasse 2
24 D 85748 Garching bei Muenchen
25 GERMANY
26 ===========================================================================*/
27
28 /*++++++++++++++++++++
29 .TYPE Module
30 .IDENTIFICATION winsize
31 .AUTHOR Carlos Guirao
32 .LANGUAGE C
33 .KEYWORDS Terminal i/o
34 .ENVIRONMENT Unix (Non-Posix compliant)
35 .COMMENTS Used by "ost" interface to get the window size.
36 .VERSION 1.0 05-Apr-1993: Creation
37
38 090324 last modif
39 ----------------------------------------------------------------------------*/
40
41 #include <fcntl.h>
42 #include <proto_os.h> /* ANSI-C prototyping */
43 #include <termios.h>
44 #ifndef TIOCGWINSZ
45 #include <sys/ioctl.h>
46 #endif
47
48 #ifdef PC_SCO /* PC/SCO needs the following incl. */
49 # include <sys/types.h>
50 # include <sys/stream.h>
51 # include <sys/ptem.h>
52 #endif
53
54
55 void winsize(fd,col,row)
56 /*++++++++++++
57 .PURPOSE Get the window size in columns and rows.
58 .RETURNS void
59 .REMARKS If window size unknown, col and row are set to 0.
60 -------------*/
61 int fd; /* IN: File descriptor */
62 unsigned short *col; /* OUT: Number of columns */
63 unsigned short *row; /* OUT: Number of rows */
64 {
65 #ifdef TIOCGWINSZ /* This ioctl seems to exist only in BSD */
66 struct winsize tw;
67 #endif
68
69 *row = 0;
70 *col = 0;
71 #ifdef TIOCGWINSZ
72 if (ioctl(fd,TIOCGWINSZ,&tw) == -1) { /* Get Window Size */
73 *row = 0;
74 *col = 0;
75 }
76 else {
77 *row = tw.ws_row;
78 *col = tw.ws_col;
79 }
80 #else
81 *row = 0;
82 *col = 0;
83 #endif /* TIOCGWINSZ */
84 }