summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Doligez <damien.doligez-inria.fr>1998-09-02 18:20:53 +0000
committerDamien Doligez <damien.doligez-inria.fr>1998-09-02 18:20:53 +0000
commit87bbb5a88068ae04f1ae52f0c2cc44c131bdbbc3 (patch)
tree0ab85b396ddfd6393b11b5836548b75a0de986fe
parentd23ee048f30459db621ca427723eedf78d68d079 (diff)
downloadocaml-87bbb5a88068ae04f1ae52f0c2cc44c131bdbbc3.tar.gz
terminfo: changement du jeu de primitives en vue du portage Mac
weak: cosmetique git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@2088 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
-rw-r--r--byterun/terminfo.c96
-rw-r--r--byterun/weak.c4
2 files changed, 67 insertions, 33 deletions
diff --git a/byterun/terminfo.c b/byterun/terminfo.c
index d74b2e59ca..c535ed87e3 100644
--- a/byterun/terminfo.c
+++ b/byterun/terminfo.c
@@ -5,7 +5,7 @@
/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
/* */
/* Copyright 1996 Institut National de Recherche en Informatique et */
-/* Automatique. Distributed only by permission. */
+/* en Automatique. Distributed only by permission. */
/* */
/***********************************************************************/
@@ -19,6 +19,10 @@
#include "io.h"
#include "mlvalues.h"
+#define Uninitialised Val_int(0)
+#define Bad_term Val_int(1)
+#define Good_term_tag 0
+
#ifdef HAS_TERMCAP
extern int tgetent (char * buffer, char * name);
@@ -26,67 +30,97 @@ extern char * tgetstr (char * id, char ** area);
extern int tgetnum (char * id);
extern int tputs (char * str, int count, int (*outchar)(int c));
-value terminfo_setup(value unit) /* ML */
+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 */
{
+ value result;
static char buffer[1024];
- if (tgetent(buffer, getenv("TERM")) != 1) failwith("Terminfo.setupterm");
- return Val_unit;
+
+ 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;
+ }
+ result = alloc (1, Good_term_tag);
+ Field (result, 0) = Val_int (num_lines);
+ return result;
}
-value terminfo_getstr(value capa) /* ML */
+static int terminfo_putc (int c)
{
- char buff[1024];
- char * p = buff;
- char * s = tgetstr(String_val(capa), &p);
- if (s == NULL) raise_not_found();
- return copy_string(s);
+ putch (chan, c);
+ return c;
}
-value terminfo_getnum(value capa) /* ML */
+value terminfo_backup (value lines) /* ML */
{
- int res = tgetnum(String_val(capa));
- if (res == -1) raise_not_found();
- return Val_int(res);
-}
+ int i;
-static struct channel * terminfo_putc_channel;
+ for (i = 0; i < Int_val (lines); i++){
+ tputs (up, 1, terminfo_putc);
+ }
+ return Val_unit;
+}
-static int terminfo_putc(int c)
+value terminfo_standout (value start) /* ML */
{
- putch(terminfo_putc_channel, c);
- return c;
+ tputs (Bool_val (start) ? standout : standend, 1, terminfo_putc);
+ return Val_unit;
}
-value terminfo_puts(value vchan, value str, value count) /* ML */
+value terminfo_resume (value lines) /* ML */
{
- terminfo_putc_channel = Channel(vchan);
- tputs(String_val(str), Int_val(count), terminfo_putc);
+ int i;
+
+ for (i = 0; i < Int_val (lines); i++){
+ tputs (down, 1, terminfo_putc);
+ }
return Val_unit;
}
#else
-value terminfo_setup(value unit)
+value terminfo_setup (value unit)
{
- failwith("Terminfo.setupterm");
- return Val_unit;
+ return Bad_term;
}
-value terminfo_getstr(value capa)
+value terminfo_backup (value lines)
{
- raise_not_found();
+ invalid_argument("Terminfo.backup");
return Val_unit;
}
-value terminfo_getnum(value capa)
+value terminfo_standout (value start)
{
- raise_not_found();
+ invalid_argument("Terminfo.standout");
return Val_unit;
}
-value terminfo_puts(value vchan, value str, value count)
+value terminfo_resume (value lines)
{
- invalid_argument("Terminfo.puts");
+ invalid_argument("Terminfo.resume");
return Val_unit;
}
diff --git a/byterun/weak.c b/byterun/weak.c
index b6ed1d8fbc..3bf2d9804b 100644
--- a/byterun/weak.c
+++ b/byterun/weak.c
@@ -5,7 +5,7 @@
/* Damien Doligez, projet Para, INRIA Rocquencourt */
/* */
/* Copyright 1997 Institut National de Recherche en Informatique et */
-/* Automatique. Distributed only by permission. */
+/* en Automatique. Distributed only by permission. */
/* */
/***********************************************************************/
@@ -34,7 +34,7 @@ value weak_create (value len) /* ML */
return res;
}
-#define None_val 1
+#define None_val Val_int(0)
#define Some_tag 0
value weak_set (value ar, value n, value el) /* ML */