]> granicus.if.org Git - jq/commitdiff
No args default w/ tty stdout, not tty stdin #220
authorNicolas Williams <nico@cryptonector.com>
Tue, 17 Jun 2014 02:28:30 +0000 (21:28 -0500)
committerNicolas Williams <nico@cryptonector.com>
Tue, 17 Jun 2014 03:34:50 +0000 (22:34 -0500)
configure.ac
main.c

index 238405e99b915ff8eec30e46dd085f8554a1842f..e8dfed42b756e67d82a621ff883fe24899d05865 100644 (file)
@@ -79,6 +79,9 @@ EOF
 
 AM_CONDITIONAL([ENABLE_DOCS], [test "x$enable_docs" != xno])
 
+AC_FIND_FUNC([isatty], [c], [#include <unistd.h>], [0])
+AC_FIND_FUNC([_isatty], [c], [#include <io.h>], [0])
+
 AC_ARG_ENABLE([pthread-tls],
               [AC_HELP_STRING([--enable-pthread-tls],
                               [Enable use of pthread thread local storage])],
diff --git a/main.c b/main.c
index 066cc7e3c1d799e8b3f9a9be18554678e153e7f9..7a7a6ec49ad16f470eabe2b5bc2db558baf5f070 100644 (file)
--- a/main.c
+++ b/main.c
@@ -237,6 +237,18 @@ int main(int argc, char* argv[]) {
       die();
     }
   }
+
+#if (!defined(WIN32) && defined(HAVE_ISATTY)) || defined(HAVE__ISATTY)
+
+#if defined(HAVE__ISATTY) && defined(isatty)
+#undef isatty
+#define isatty _isatty
+#endif
+
+  if (!program && isatty(STDOUT_FILENO) && !isatty(STDIN_FILENO))
+    program = ".";
+#endif
+
   if (!program) usage();
   if (ninput_files == 0) current_input = stdin;