uses "isatty" to check if executes stdin line by line or as a file.

This commit is contained in:
Roberto Ierusalimschy 1995-10-23 11:54:11 -02:00
parent ebcf546a55
commit b5745d11cd
1 changed files with 12 additions and 1 deletions

13
lua.c
View File

@ -3,7 +3,7 @@
** Linguagem para Usuarios de Aplicacao ** 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 <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@ -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 int lua_argc;
static char **lua_argv; 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. %F Allow Lua code to access argv strings.
%i Receive from Lua the argument number (starting with 1). %i Receive from Lua the argument number (starting with 1).
@ -34,11 +40,16 @@ static void lua_getargv (void)
static void manual_input (void) static void manual_input (void)
{
if (isatty(fileno(stdin)))
{ {
char buffer[250]; char buffer[250];
while (gets(buffer) != 0) while (gets(buffer) != 0)
lua_dostring(buffer); lua_dostring(buffer);
} }
else
lua_dofile(NULL); /* executes stdin as a file */
}
int main (int argc, char *argv[]) int main (int argc, char *argv[])