1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
/* Read and output terminal commands */
#include "config.h"
#include "alloc.h"
#include "fail.h"
#include "io.h"
#include "mlvalues.h"
#ifdef HAS_TERMINFO
#undef getch
#include <curses.h>
#include <term.h>
value terminfo_setup(unit) /* ML */
value unit;
{
if (setupterm(NULL, 1, 1) != 1) failwith("Terminfo.setupterm");
return Val_unit;
}
value terminfo_getstr(capa) /* ML */
value capa;
{
char * res = (char *) tigetstr(String_val(capa));
if (res == (char *)(-1)) raise_not_found();
return copy_string(res);
}
value terminfo_getnum(capa) /* ML */
value capa;
{
int res = tigetnum(String_val(capa));
if (res == -2) raise_not_found();
return Val_int(res);
}
#else
#ifdef HAS_TERMCAP
#define _BSD /* For DEC OSF1 */
#undef getch
#include <curses.h>
value terminfo_setup(unit)
value unit;
{
static buffer[1024];
if (tgetent(buffer, getenv("TERM")) != 1) failwith("Terminfo.setupterm");
return Val_unit;
}
value terminfo_getstr(capa)
value capa;
{
char buff[1024];
char * p = buff;
if (tgetstr(String_val(capa), &p) == 0) raise_not_found();
return copy_string(buff);
}
value terminfo_getnum(capa)
value capa;
{
int res = tgetnum(String_val(capa));
if (res == -1) raise_not_found();
return Val_int(res);
}
#else
value terminfo_setup(unit)
value unit;
{
failwith("Terminfo.setupterm");
return Val_unit;
}
value terminfo_getstr(capa)
value capa;
{
raise_not_found();
return Val_unit;
}
value terminfo_getnum(capa)
value capa;
{
raise_not_found();
return Val_unit;
}
#endif
#endif
#if defined HAS_TERMINFO || defined HAS_TERMCAP
static struct channel * terminfo_putc_channel;
static int terminfo_putc(c)
int c;
{
putch(terminfo_putc_channel, c);
return c;
}
value terminfo_puts(chan, str, count) /* ML */
struct channel * chan;
value str, count;
{
terminfo_putc_channel = chan;
tputs(String_val(str), Int_val(count), terminfo_putc);
return Val_unit;
}
#else
value terminfo_puts(chan, str, count)
struct channel * chan;
value str, count;
{
invalid_argument("Terminfo.puts");
}
#endif
|