1995-08-09 08:06:35 -07:00
|
|
|
/***********************************************************************/
|
|
|
|
/* */
|
1996-04-30 07:53:58 -07:00
|
|
|
/* Objective Caml */
|
1995-08-09 08:06:35 -07:00
|
|
|
/* */
|
|
|
|
/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
|
|
|
|
/* */
|
1996-04-30 07:53:58 -07:00
|
|
|
/* Copyright 1996 Institut National de Recherche en Informatique et */
|
1998-09-02 11:20:53 -07:00
|
|
|
/* en Automatique. Distributed only by permission. */
|
1995-08-09 08:06:35 -07:00
|
|
|
/* */
|
|
|
|
/***********************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
/* Read and output terminal commands */
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "alloc.h"
|
|
|
|
#include "fail.h"
|
|
|
|
#include "io.h"
|
|
|
|
#include "mlvalues.h"
|
|
|
|
|
1998-09-02 11:20:53 -07:00
|
|
|
#define Uninitialised Val_int(0)
|
|
|
|
#define Bad_term Val_int(1)
|
|
|
|
#define Good_term_tag 0
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
#ifdef HAS_TERMCAP
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
extern int tgetent (char * buffer, char * name);
|
1997-10-24 08:52:05 -07:00
|
|
|
extern char * tgetstr (char * id, char ** area);
|
1997-09-02 05:55:01 -07:00
|
|
|
extern int tgetnum (char * id);
|
|
|
|
extern int tputs (char * str, int count, int (*outchar)(int c));
|
1995-05-04 03:15:53 -07:00
|
|
|
|
1998-09-02 11:20:53 -07:00
|
|
|
static struct channel *chan;
|
|
|
|
static char area [1024];
|
|
|
|
static char *area_p = area;
|
|
|
|
static int num_lines;
|
|
|
|
static char *up = NULL;
|
|
|
|
static char *down = NULL;
|
|
|
|
static char *standout = NULL;
|
|
|
|
static char *standend = NULL;
|
|
|
|
|
|
|
|
value terminfo_setup (value vchan) /* ML */
|
1995-05-04 03:15:53 -07:00
|
|
|
{
|
1998-09-02 11:20:53 -07:00
|
|
|
value result;
|
1996-09-12 05:41:48 -07:00
|
|
|
static char buffer[1024];
|
1998-09-02 11:20:53 -07:00
|
|
|
|
|
|
|
chan = Channel (vchan);
|
|
|
|
|
|
|
|
if (tgetent(buffer, getenv("TERM")) != 1) return Bad_term;
|
|
|
|
|
|
|
|
num_lines = tgetnum ("li");
|
|
|
|
up = tgetstr ("up", &area_p);
|
|
|
|
down = tgetstr ("do", &area_p);
|
|
|
|
standout = tgetstr ("us", &area_p);
|
|
|
|
standend = tgetstr ("ue", &area_p);
|
|
|
|
if (standout == NULL || standend == NULL){
|
|
|
|
standout = tgetstr ("so", &area_p);
|
|
|
|
standend = tgetstr ("se", &area_p);
|
|
|
|
}
|
|
|
|
Assert (area_p <= area + 1024);
|
|
|
|
if (num_lines == -1 || up == NULL || down == NULL
|
|
|
|
|| standout == NULL || standend == NULL){
|
|
|
|
return Bad_term;
|
|
|
|
}
|
1998-10-26 11:19:32 -08:00
|
|
|
result = alloc_small (1, Good_term_tag);
|
1998-09-02 11:20:53 -07:00
|
|
|
Field (result, 0) = Val_int (num_lines);
|
|
|
|
return result;
|
1995-05-04 03:15:53 -07:00
|
|
|
}
|
|
|
|
|
1998-09-02 11:20:53 -07:00
|
|
|
static int terminfo_putc (int c)
|
1995-05-04 03:15:53 -07:00
|
|
|
{
|
1998-09-02 11:20:53 -07:00
|
|
|
putch (chan, c);
|
|
|
|
return c;
|
1995-05-04 03:15:53 -07:00
|
|
|
}
|
|
|
|
|
1998-09-02 11:20:53 -07:00
|
|
|
value terminfo_backup (value lines) /* ML */
|
1995-05-04 03:15:53 -07:00
|
|
|
{
|
1998-09-02 11:20:53 -07:00
|
|
|
int i;
|
1995-05-04 03:15:53 -07:00
|
|
|
|
1998-09-02 11:20:53 -07:00
|
|
|
for (i = 0; i < Int_val (lines); i++){
|
|
|
|
tputs (up, 1, terminfo_putc);
|
|
|
|
}
|
|
|
|
return Val_unit;
|
|
|
|
}
|
1995-08-08 05:17:31 -07:00
|
|
|
|
1998-09-02 11:20:53 -07:00
|
|
|
value terminfo_standout (value start) /* ML */
|
1995-08-08 05:17:31 -07:00
|
|
|
{
|
1998-09-02 11:20:53 -07:00
|
|
|
tputs (Bool_val (start) ? standout : standend, 1, terminfo_putc);
|
|
|
|
return Val_unit;
|
1995-08-08 05:17:31 -07:00
|
|
|
}
|
|
|
|
|
1998-09-02 11:20:53 -07:00
|
|
|
value terminfo_resume (value lines) /* ML */
|
1995-08-08 05:17:31 -07:00
|
|
|
{
|
1998-09-02 11:20:53 -07:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < Int_val (lines); i++){
|
|
|
|
tputs (down, 1, terminfo_putc);
|
|
|
|
}
|
1995-08-08 05:17:31 -07:00
|
|
|
return Val_unit;
|
|
|
|
}
|
|
|
|
|
1998-10-02 06:02:32 -07:00
|
|
|
#else /* HAS_TERMCAP */
|
1995-05-04 03:15:53 -07:00
|
|
|
|
1998-10-02 06:02:32 -07:00
|
|
|
value terminfo_setup (value vchan)
|
1995-05-04 03:15:53 -07:00
|
|
|
{
|
1998-09-02 11:20:53 -07:00
|
|
|
return Bad_term;
|
1995-05-04 03:15:53 -07:00
|
|
|
}
|
|
|
|
|
1998-09-02 11:20:53 -07:00
|
|
|
value terminfo_backup (value lines)
|
1995-05-04 03:15:53 -07:00
|
|
|
{
|
1998-09-02 11:20:53 -07:00
|
|
|
invalid_argument("Terminfo.backup");
|
1995-05-04 03:15:53 -07:00
|
|
|
return Val_unit;
|
|
|
|
}
|
|
|
|
|
1998-09-02 11:20:53 -07:00
|
|
|
value terminfo_standout (value start)
|
1995-05-04 03:15:53 -07:00
|
|
|
{
|
1998-09-02 11:20:53 -07:00
|
|
|
invalid_argument("Terminfo.standout");
|
1995-05-04 03:15:53 -07:00
|
|
|
return Val_unit;
|
|
|
|
}
|
|
|
|
|
1998-09-02 11:20:53 -07:00
|
|
|
value terminfo_resume (value lines)
|
1995-05-04 03:15:53 -07:00
|
|
|
{
|
1998-09-02 11:20:53 -07:00
|
|
|
invalid_argument("Terminfo.resume");
|
1996-11-02 10:00:46 -08:00
|
|
|
return Val_unit;
|
1995-05-04 03:15:53 -07:00
|
|
|
}
|
|
|
|
|
1998-10-02 06:02:32 -07:00
|
|
|
#endif /* HAS_TERMCAP */
|