source: trunk/minix/lib/curses/cursesio.c@ 10

Last change on this file since 10 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 5.5 KB
Line 
1#include <stdlib.h>
2#include <termcap.h>
3#include <sys/types.h>
4#include <sys/ioctl.h>
5#include <curses.h>
6#include "curspriv.h"
7
8struct termios _orig_tty, _tty;
9cursv _cursvar;
10
11WINDOW *stdscr, *curscr;
12int LINES, COLS;
13bool NONL;
14
15char termcap[1024]; /* termcap buffer */
16char tc[200]; /* area to hold string capabilities */
17char *ttytype; /* terminal type from env */
18static char *arp; /* pointer for use in tgetstr */
19char *cp; /* character pointer */
20
21char *cl; /* clear screen capability */
22char *cm; /* cursor motion capability */
23char *so; /* start standout capability */
24char *se; /* end standout capability */
25char *mr; /* start of reverse */
26char *me; /* revert to normal */
27char *mb; /* start of blink */
28char *md; /* start of bold */
29char *us; /* start of underscore */
30char *ue; /* end of underscore */
31char *vi; /* cursor invisible */
32char *ve; /* cursor normal */
33char *vs; /* cursor good visible */
34char *as; /* alternative charset start */
35char *ae; /* alternative charset end */
36char *bl; /* ring the bell */
37char *vb; /* visual bell */
38
39/* fatal - report error and die. Never returns */
40void fatal(s)
41char *s;
42{
43 (void) fprintf(stderr, "curses: %s\n", s);
44 exit(1);
45}
46
47/* Outc - call putchar, necessary because putchar is a macro. */
48void outc(c)
49int c;
50{
51 putchar(c);
52}
53
54/* Move cursor to r,c */
55void poscur(r, c)
56int r, c;
57{
58 tputs(tgoto(cm, c, r), 1, outc);
59}
60
61/* Clear the screen */
62void clrscr()
63{
64 tputs(cl, 1, outc);
65}
66
67/* This are terminal independent characters which can be used in curses */
68
69unsigned int ACS_ULCORNER;
70unsigned int ACS_LLCORNER;
71unsigned int ACS_URCORNER;
72unsigned int ACS_LRCORNER;
73unsigned int ACS_RTEE;
74unsigned int ACS_LTEE;
75unsigned int ACS_BTEE;
76unsigned int ACS_TTEE;
77unsigned int ACS_HLINE;
78unsigned int ACS_VLINE;
79unsigned int ACS_PLUS;
80unsigned int ACS_S1;
81unsigned int ACS_S9;
82unsigned int ACS_DIAMOND;
83unsigned int ACS_CKBOARD;
84unsigned int ACS_DEGREE;
85unsigned int ACS_PLMINUS;
86unsigned int ACS_BULLET;
87unsigned int ACS_LARROW;
88unsigned int ACS_RARROW;
89unsigned int ACS_DARROW;
90unsigned int ACS_UARROW;
91unsigned int ACS_BOARD;
92unsigned int ACS_LANTERN;
93unsigned int ACS_BLOCK;
94
95/* These defines describe the full set of grafic block characters which
96 * can be defined via termcap.
97 */
98
99#define RIGHTARROW 0
100#define LEFTARROW 1
101#define DOWNARROW 2
102#define UPARROW 3
103#define FULLSQUARE 4
104#define GREYSQUARE 5
105#define EMPTYSQUARE 6
106#define LATERN 7
107#define DIAMOND 8
108#define DEGREE 9
109#define PLUSMINUS 10
110#define DOWNRIGHT 11
111#define UPRIGHT 12
112#define UPLEFT 13
113#define DOWNLEFT 14
114#define CROSS 15
115#define UPLINE 16
116#define UPMIDLINE 17
117#define MIDLINE 18
118#define DOMIDLINE 19
119#define DOWNLINE 20
120#define TEELEFT 21
121#define TEERIGHT 22
122#define TEEHEAD 23
123#define TEENORMAL 24
124#define VERTLINE 25
125#define PARAGRAPH 26
126
127unsigned int _cursgraftable[27] =
128{
129 '>', '<', 'v', '^', '#', ':', ' ', '#', '+', '\'', '#', '+', '+',
130 '+', '+', '+', '-', ' ', '-', ' ', '_', '+', '+', '+', '+', '|'
131};
132char _cursident[28] = "+,.-0ahI`fgjklmnopqrstuvwx~";
133
134int setterm(type)
135char *type;
136{
137 unsigned char *ac;
138 int i;
139#ifdef TIOCGWINSZ
140 struct winsize wsize;
141#endif
142
143 if (tgetent(termcap, type) != 1) return ERR;
144
145#ifdef TIOCGWINSZ
146 if (ioctl(0, TIOCGWINSZ, &wsize) == 0) {
147 LINES = wsize.ws_row != 0 ? wsize.ws_row : tgetnum("li");
148 COLS = wsize.ws_col != 0 ? wsize.ws_col : tgetnum("co");
149 } else {
150#endif
151 LINES = tgetnum("li");
152 COLS = tgetnum("co");
153#ifdef TIOCGWINSZ
154 }
155#endif
156 arp = tc;
157 cl = tgetstr("cl", &arp);
158 so = tgetstr("so", &arp);
159 se = tgetstr("se", &arp);
160 cm = tgetstr("cm", &arp);
161 mr = tgetstr("mr", &arp);
162 me = tgetstr("me", &arp);
163 mb = tgetstr("mb", &arp);
164 md = tgetstr("md", &arp);
165 us = tgetstr("us", &arp);
166 ue = tgetstr("ue", &arp);
167 vi = tgetstr("vi", &arp);
168 ve = tgetstr("ve", &arp);
169 vs = tgetstr("vs", &arp);
170 as = tgetstr("as", &arp);
171 ae = tgetstr("ae", &arp);
172 ac = (unsigned char *) tgetstr("ac", &arp);
173 bl = tgetstr("bl", &arp);
174 vb = tgetstr("vb", &arp);
175
176 if (ac) {
177 while (*ac) {
178 i = 0;
179 while (*ac != _cursident[i]) i++;
180 _cursgraftable[i] = *++ac | A_ALTCHARSET;
181 ac++;
182 }
183 }
184
185 ACS_ULCORNER = _cursgraftable[UPLEFT];
186 ACS_LLCORNER = _cursgraftable[DOWNLEFT];
187 ACS_URCORNER = _cursgraftable[UPRIGHT];
188 ACS_LRCORNER = _cursgraftable[DOWNRIGHT];
189 ACS_RTEE = _cursgraftable[TEERIGHT];
190 ACS_LTEE = _cursgraftable[TEELEFT];
191 ACS_BTEE = _cursgraftable[TEEHEAD];
192 ACS_TTEE = _cursgraftable[TEENORMAL];
193 ACS_HLINE = _cursgraftable[MIDLINE];
194 ACS_VLINE = _cursgraftable[VERTLINE];
195 ACS_PLUS = _cursgraftable[CROSS];
196 ACS_S1 = _cursgraftable[UPLINE];
197 ACS_S9 = _cursgraftable[DOWNLINE];
198 ACS_DIAMOND = _cursgraftable[DIAMOND];
199 ACS_CKBOARD = _cursgraftable[GREYSQUARE];
200 ACS_DEGREE = _cursgraftable[DEGREE];
201 ACS_PLMINUS = _cursgraftable[PLUSMINUS];
202 ACS_BULLET = 'o'; /* where the hell is a bullet defined in
203 * termcap ??? */
204 ACS_LARROW = _cursgraftable[LEFTARROW];
205 ACS_RARROW = _cursgraftable[RIGHTARROW];
206 ACS_DARROW = _cursgraftable[DOWNARROW];
207 ACS_UARROW = _cursgraftable[UPARROW];
208 ACS_BOARD = _cursgraftable[EMPTYSQUARE];
209 ACS_LANTERN = _cursgraftable[LATERN];
210 ACS_BLOCK = _cursgraftable[FULLSQUARE];
211 /* Wow, I got it! */
212 return OK;
213}
214
215void gettmode()
216{
217 tcgetattr(0, &_orig_tty);
218 tcgetattr(0, &_tty);
219 _cursvar.echoit = (_tty.c_lflag & ECHO) != 0;
220 _cursvar.rawmode = (_tty.c_lflag & (ICANON|ISIG)) == 0;
221 _cursvar.cbrkmode = (_tty.c_lflag & (ICANON|ISIG)) == ISIG;
222 NONL = (_tty.c_iflag & ICRNL) != 0;
223}
Note: See TracBrowser for help on using the repository browser.