From 5c688c333ebed0308af78ebd9ad6eabbbabe1813 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Tue, 30 Jul 2013 11:44:47 +0100 Subject: [PATCH] resize: Move isatty_stdout function to separate module (TTY.isatty_stdout). 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 e64492bbf..a98535e95 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 566c6aee6..34533ea5c 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 ca258b167..2431e34c6 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 2813d0cf4..67913eb65 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 1ff73c225..e53e69362 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 000000000..32c1f542f --- /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 000000000..69441f1a7 --- /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 000000000..040a13228 --- /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 + +#include +#include +#include + +#include +#include + +/* 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 61a560ddb..3bc1d0e81 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