Remove #ifdef around use of sigsetjmp().
[mmh] / uip / termsbr.c
1 /*
2 ** termsbr.c -- termcap support
3 **
4 ** This code is Copyright (c) 2002, by the authors of nmh.  See the
5 ** COPYRIGHT file in the root directory of the nmh distribution for
6 ** complete copyright information.
7 */
8
9 #include <h/mh.h>
10
11 #include <termios.h>
12
13 #ifdef HAVE_TERMCAP_H
14 # include <termcap.h>
15 #endif
16
17 /* <sys/ioctl.h> is need anyway for ioctl()
18 #ifdef GWINSZ_IN_SYS_IOCTL
19 */
20 # include <sys/ioctl.h>
21 /*
22 #endif
23 */
24
25 #ifdef WINSIZE_IN_PTEM
26 # include <sys/stream.h>
27 # include <sys/ptem.h>
28 #endif
29
30 #if BUFSIZ<2048
31 # define TXTSIZ 2048
32 #else
33 # define TXTSIZ BUFSIZ
34 #endif
35
36 static long speedcode;
37
38 static int initCO = 0;
39
40 static int CO = 80;      /* number of colums */
41
42 static char termcap[TXTSIZ];
43
44
45 static void
46 read_termcap(void)
47 {
48         char *bp, *cp;
49         char *term;
50
51 #ifndef TGETENT_ACCEPTS_NULL
52         char termbuf[TXTSIZ];
53 #endif
54
55         struct termios tio;
56         static int inited = 0;
57
58         if (inited++)
59                 return;
60
61         if (!(term = getenv("TERM")))
62                 return;
63
64 /*
65 ** If possible, we let tgetent allocate its own termcap buffer
66 */
67 #ifdef TGETENT_ACCEPTS_NULL
68         if (tgetent(NULL, term) != TGETENT_SUCCESS)
69                 return;
70 #else
71         if (tgetent(termbuf, term) != TGETENT_SUCCESS)
72                 return;
73 #endif
74
75         speedcode = cfgetospeed(&tio);
76
77         if (!initCO && (CO = tgetnum("co")) <= 0)
78                 CO = 80;
79
80         cp = termcap;
81         if ((bp = tgetstr("pc", &cp)))
82                 PC = *bp;
83 }
84
85
86 int
87 sc_width(void)
88 {
89 #ifdef TIOCGWINSZ
90         struct winsize win;
91         int width;
92
93         if (ioctl(fileno(stderr), TIOCGWINSZ, &win) != NOTOK
94                         && (width = win.ws_col) > 0) {
95                 CO = width;
96                 initCO++;
97         } else
98 #endif /* TIOCGWINSZ */
99                 read_termcap();
100
101         return CO;
102 }