From: "Richard W.M. Jones" <rjones(a)redhat.com>
It was jammed into the Progress module just for convenience.
(cherry picked from commit b56990ddf8aa4dc4db3da592783acfe055c05534)
(cherry picked from commit 93daf42b52446eb442c595592a053caaa740ba42)
---
po/POTFILES | 1 +
po/POTFILES-ml | 1 +
resize/Makefile.am | 7 ++++++-
resize/progress-c.c | 9 ---------
resize/progress.ml | 3 +--
resize/tTY.ml | 19 +++++++++++++++++++
resize/tTY.mli | 23 +++++++++++++++++++++++
resize/tty-c.c | 35 +++++++++++++++++++++++++++++++++++
sparsify/Makefile.am | 2 ++
9 files changed, 88 insertions(+), 12 deletions(-)
create mode 100644 resize/tTY.ml
create mode 100644 resize/tTY.mli
create mode 100644 resize/tty-c.c
diff --git a/po/POTFILES b/po/POTFILES
index e64492b..a98535e 100644
--- a/po/POTFILES
+++ b/po/POTFILES
@@ -220,6 +220,7 @@ python/guestfs-py.c
rescue/test-virt-rescue.pl
rescue/virt-rescue.c
resize/progress-c.c
+resize/tty-c.c
ruby/ext/guestfs/_guestfs.c
src/actions-0.c
src/actions-1.c
diff --git a/po/POTFILES-ml b/po/POTFILES-ml
index 566c6ae..34533ea 100644
--- a/po/POTFILES-ml
+++ b/po/POTFILES-ml
@@ -3,6 +3,7 @@ resize/common_utils.ml
resize/common_utils_tests.ml
resize/progress.ml
resize/resize.ml
+resize/tTY.ml
sparsify/sparsify.ml
sysprep/firstboot.ml
sysprep/main.ml
diff --git a/resize/Makefile.am b/resize/Makefile.am
index ca258b1..2431e34 100644
--- a/resize/Makefile.am
+++ b/resize/Makefile.am
@@ -32,16 +32,21 @@ SOURCES = \
progress-c.c \
progress.mli \
progress.ml \
- resize.ml
+ resize.ml \
+ tty-c.c \
+ tTY.mli \
+ tTY.ml
if HAVE_OCAML
# Note this list must be in dependency order.
OBJECTS = \
$(top_builddir)/fish/guestfish-progress.o \
+ tty-c.o \
progress-c.o \
common_gettext.cmx \
common_utils.cmx \
+ tTY.cmx \
progress.cmx \
resize.cmx
diff --git a/resize/progress-c.c b/resize/progress-c.c
index 2813d0c..67913eb 100644
--- a/resize/progress-c.c
+++ b/resize/progress-c.c
@@ -104,12 +104,3 @@ virt_resize_progress_bar_set (value barv,
CAMLreturn (Val_unit);
}
-
-/* RHEL 5-era ocaml didn't have Unix.isatty. */
-value
-virt_resize_isatty_stdout (value unitv)
-{
- CAMLparam1 (unitv);
-
- CAMLreturn (isatty(1) ? Val_true : Val_false);
-}
diff --git a/resize/progress.ml b/resize/progress.ml
index 1ff73c2..e53e693 100644
--- a/resize/progress.ml
+++ b/resize/progress.ml
@@ -28,13 +28,12 @@ external progress_bar_reset : progress_bar -> unit
= "virt_resize_progress_bar_reset"
external progress_bar_set : progress_bar -> int64 -> int64 -> unit
= "virt_resize_progress_bar_set"
-external isatty_stdout : unit -> bool = "virt_resize_isatty_stdout"
let set_up_progress_bar ?(machine_readable = false) (g : Guestfs.guestfs) =
(* Only display progress bars if the machine_readable flag is set or
* the output is a tty.
*)
- if machine_readable || isatty_stdout () then (
+ if machine_readable || TTY.isatty_stdout () then (
(* Initialize the C mini library. *)
let bar = progress_bar_init ~machine_readable in
diff --git a/resize/tTY.ml b/resize/tTY.ml
new file mode 100644
index 0000000..32c1f54
--- /dev/null
+++ b/resize/tTY.ml
@@ -0,0 +1,19 @@
+(* virt-resize
+ * Copyright (C) 2013 Red Hat Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *)
+
+external isatty_stdout : unit -> bool = "virt_resize_isatty_stdout"
diff --git a/resize/tTY.mli b/resize/tTY.mli
new file mode 100644
index 0000000..69441f1
--- /dev/null
+++ b/resize/tTY.mli
@@ -0,0 +1,23 @@
+(* virt-resize
+ * Copyright (C) 2013 Red Hat Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *)
+
+(** TTY utilities. *)
+
+val isatty_stdout : unit -> bool
+(** RHEL 5-era ocaml didn't have Unix.isatty. This is not needed in
+ recent OCaml. *)
diff --git a/resize/tty-c.c b/resize/tty-c.c
new file mode 100644
index 0000000..040a132
--- /dev/null
+++ b/resize/tty-c.c
@@ -0,0 +1,35 @@
+/* virt-resize - interface to isatty
+ * Copyright (C) 2013 Red Hat Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <caml/memory.h>
+#include <caml/mlvalues.h>
+
+/* RHEL 5-era ocaml didn't have Unix.isatty. */
+value
+virt_resize_isatty_stdout (value unitv)
+{
+ CAMLparam1 (unitv);
+
+ CAMLreturn (isatty (1) ? Val_true : Val_false);
+}
diff --git a/sparsify/Makefile.am b/sparsify/Makefile.am
index 61a560d..3bc1d0e 100644
--- a/sparsify/Makefile.am
+++ b/sparsify/Makefile.am
@@ -33,9 +33,11 @@ if HAVE_OCAML
# Note this list must be in dependency order.
OBJECTS = \
$(top_builddir)/fish/guestfish-progress.o \
+ $(top_builddir)/resize/tty-c.o \
$(top_builddir)/resize/progress-c.o \
$(top_builddir)/resize/common_gettext.cmx \
$(top_builddir)/resize/common_utils.cmx \
+ $(top_builddir)/resize/tTY.cmx \
$(top_builddir)/resize/progress.cmx \
sparsify.cmx
--
1.8.3.1