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
|
/***********************************************************************/
/* */
/* Objective Caml */
/* */
/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
/* */
/* Copyright 1996 Institut National de Recherche en Informatique et */
/* Automatique. Distributed only by permission. */
/* */
/***********************************************************************/
/* $Id$ */
/* Read and output terminal commands */
#include "config.h"
#include "alloc.h"
#include "fail.h"
#include "io.h"
#include "mlvalues.h"
#ifdef HAS_TERMCAP
extern int tgetent P((char * buffer, char * name));
extern int tgetstr P((char * id, char ** area));
extern int tgetnum P((char * id));
extern int tputs P((char * str, int count, int (*outchar)(int c)));
value terminfo_setup(unit) /* ML */
value unit;
{
static char buffer[1024];
if (tgetent(buffer, getenv("TERM")) != 1) failwith("Terminfo.setupterm");
return Val_unit;
}
value terminfo_getstr(capa) /* ML */
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) /* ML */
value capa;
{
int res = tgetnum(String_val(capa));
if (res == -1) raise_not_found();
return Val_int(res);
}
static struct channel * terminfo_putc_channel;
static int terminfo_putc(c)
int c;
{
putch(terminfo_putc_channel, c);
return c;
}
value terminfo_puts(vchan, str, count) /* ML */
value vchan, str, count;
{
terminfo_putc_channel = Channel(vchan);
tputs(String_val(str), Int_val(count), terminfo_putc);
return Val_unit;
}
#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;
}
value terminfo_puts(vchan, str, count)
value vchan, str, count;
{
invalid_argument("Terminfo.puts");
return Val_unit;
}
#endif
|