From b5745d11cdd93c819f8e881504eb534c7e13badd Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 23 Oct 1995 11:54:11 -0200 Subject: [PATCH] uses "isatty" to check if executes stdin line by line or as a file. --- lua.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lua.c b/lua.c index 834ebe49..e961d06b 100644 --- a/lua.c +++ b/lua.c @@ -3,7 +3,7 @@ ** Linguagem para Usuarios de Aplicacao */ -char *rcs_lua="$Id: lua.c,v 1.4 1995/02/07 16:04:15 lhf Exp roberto $"; +char *rcs_lua="$Id: lua.c,v 1.5 1995/10/06 14:11:40 roberto Exp roberto $"; #include #include @@ -14,6 +14,12 @@ char *rcs_lua="$Id: lua.c,v 1.4 1995/02/07 16:04:15 lhf Exp roberto $"; static int lua_argc; static char **lua_argv; +/* +** although this function is POSIX, there is no standard header file that +** defines it +*/ +int isatty (int fd); + /* %F Allow Lua code to access argv strings. %i Receive from Lua the argument number (starting with 1). @@ -35,9 +41,14 @@ static void lua_getargv (void) static void manual_input (void) { + if (isatty(fileno(stdin))) + { char buffer[250]; while (gets(buffer) != 0) lua_dostring(buffer); + } + else + lua_dofile(NULL); /* executes stdin as a file */ }