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 */
|
1999-11-17 10:59:06 -08:00
|
|
|
/* en Automatique. All rights reserved. This file is distributed */
|
2001-12-07 05:41:02 -08:00
|
|
|
/* under the terms of the GNU Library General Public License, with */
|
|
|
|
/* the special exception on linking described in file ../LICENSE. */
|
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"
|
|
|
|
|
2001-08-13 06:53:51 -07:00
|
|
|
#define Uninitialised (Val_int(0))
|
|
|
|
#define Bad_term (Val_int(1))
|
1998-09-02 11:20:53 -07:00
|
|
|
#define Good_term_tag 0
|
|
|
|
|
2000-10-27 05:55:48 -07:00
|
|
|
#if defined (HAS_TERMCAP) && !defined (NATIVE_CODE)
|
1995-05-04 03:15:53 -07:00
|
|
|
|
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;
|
|
|
|
|
2004-01-01 08:42:43 -08:00
|
|
|
CAMLprim value caml_terminfo_setup (value vchan)
|
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];
|
2002-08-13 10:16:32 -07:00
|
|
|
char *term;
|
1998-09-02 11:20:53 -07:00
|
|
|
|
|
|
|
chan = Channel (vchan);
|
|
|
|
|
2002-08-13 10:16:32 -07:00
|
|
|
term = getenv ("TERM");
|
|
|
|
if (term == NULL) return Bad_term;
|
|
|
|
if (tgetent(buffer, term) != 1) return Bad_term;
|
1998-09-02 11:20:53 -07:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2003-12-29 14:15:02 -08:00
|
|
|
result = caml_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
|
|
|
}
|
|
|
|
|
2004-01-01 08:42:43 -08:00
|
|
|
CAMLprim value caml_terminfo_backup (value lines)
|
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
|
|
|
|
2004-01-01 08:42:43 -08:00
|
|
|
CAMLprim value caml_terminfo_standout (value start)
|
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
|
|
|
}
|
|
|
|
|
2004-01-01 08:42:43 -08:00
|
|
|
CAMLprim value caml_terminfo_resume (value lines)
|
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;
|
|
|
|
}
|
|
|
|
|
2000-10-27 05:55:48 -07:00
|
|
|
#else /* defined (HAS_TERMCAP) && !defined (NATIVE_CODE) */
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2004-01-01 08:42:43 -08:00
|
|
|
CAMLexport value caml_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
|
|
|
}
|
|
|
|
|
2004-01-01 08:42:43 -08:00
|
|
|
CAMLexport value caml_terminfo_backup (value lines)
|
1995-05-04 03:15:53 -07:00
|
|
|
{
|
2004-01-01 08:42:43 -08:00
|
|
|
caml_invalid_argument("Terminfo.backup");
|
1995-05-04 03:15:53 -07:00
|
|
|
return Val_unit;
|
|
|
|
}
|
|
|
|
|
2004-01-01 08:42:43 -08:00
|
|
|
CAMLexport value caml_terminfo_standout (value start)
|
1995-05-04 03:15:53 -07:00
|
|
|
{
|
2004-01-01 08:42:43 -08:00
|
|
|
caml_invalid_argument("Terminfo.standout");
|
1995-05-04 03:15:53 -07:00
|
|
|
return Val_unit;
|
|
|
|
}
|
|
|
|
|
2004-01-01 08:42:43 -08:00
|
|
|
CAMLexport value caml_terminfo_resume (value lines)
|
1995-05-04 03:15:53 -07:00
|
|
|
{
|
2004-01-01 08:42:43 -08:00
|
|
|
caml_invalid_argument("Terminfo.resume");
|
1996-11-02 10:00:46 -08:00
|
|
|
return Val_unit;
|
1995-05-04 03:15:53 -07:00
|
|
|
}
|
|
|
|
|
2000-10-27 05:55:48 -07:00
|
|
|
#endif /* defined (HAS_TERMCAP) && !defined (NATIVE_CODE) */
|