aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/main.c b/src/main.c
index 3e48469..81fe189 100644
--- a/src/main.c
+++ b/src/main.c
@@ -40,10 +40,10 @@ typedef enum {
} bool_style_t;
static int rv;
-static bool interactive;
static bool_style_t bflag = BS_BINARY;
static tbl_style_t tflag = TS_UNSET;
+bool interactive;
const char *current_file;
static void astprocess_cli(asts_t);
@@ -70,7 +70,6 @@ main(int argc, char **argv)
{
argv[0] = basename(argv[0]);
setlocale(LC_ALL, "");
- interactive = isatty(STDIN_FILENO);
int opt;
const char *sflag = NULL;
@@ -131,6 +130,14 @@ usage:
if (sflag != NULL && argc != 0)
goto usage;
+ /* We’re considered to be interactive if stdin is a TTY (meaning it’s
+ not a pipe or something) and no files have been specified on the
+ command-line. We should also take care to check for -s, because
+ that implies non-interactive usage. We intentionally consider
+ ‘interactive’ usage with the command-line argument ‘-’ to not be
+ interactive. */
+ interactive = sflag == NULL && argc == 0 && isatty(STDIN_FILENO);
+
if (argc == 0) {
if (sflag != NULL &&
(yyin = fmemopen((char *)sflag, strlen(sflag), "r")) == NULL)