diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1995-10-23 11:54:11 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1995-10-23 11:54:11 -0200 |
| commit | b5745d11cdd93c819f8e881504eb534c7e13badd (patch) | |
| tree | b9c0642182f045da954d8ddb7e074753eb9bab45 | |
| parent | ebcf546a551cae37835af5ddf6105e2e97706047 (diff) | |
| download | lua-b5745d11cdd93c819f8e881504eb534c7e13badd.tar.gz lua-b5745d11cdd93c819f8e881504eb534c7e13badd.tar.bz2 lua-b5745d11cdd93c819f8e881504eb534c7e13badd.zip | |
uses "isatty" to check if executes stdin line by line or as a file.
| -rw-r--r-- | lua.c | 13 |
1 files changed, 12 insertions, 1 deletions
| @@ -3,7 +3,7 @@ | |||
| 3 | ** Linguagem para Usuarios de Aplicacao | 3 | ** Linguagem para Usuarios de Aplicacao |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | char *rcs_lua="$Id: lua.c,v 1.4 1995/02/07 16:04:15 lhf Exp roberto $"; | 6 | char *rcs_lua="$Id: lua.c,v 1.5 1995/10/06 14:11:40 roberto Exp roberto $"; |
| 7 | 7 | ||
| 8 | #include <stdio.h> | 8 | #include <stdio.h> |
| 9 | #include <string.h> | 9 | #include <string.h> |
| @@ -15,6 +15,12 @@ static int lua_argc; | |||
| 15 | static char **lua_argv; | 15 | static char **lua_argv; |
| 16 | 16 | ||
| 17 | /* | 17 | /* |
| 18 | ** although this function is POSIX, there is no standard header file that | ||
| 19 | ** defines it | ||
| 20 | */ | ||
| 21 | int isatty (int fd); | ||
| 22 | |||
| 23 | /* | ||
| 18 | %F Allow Lua code to access argv strings. | 24 | %F Allow Lua code to access argv strings. |
| 19 | %i Receive from Lua the argument number (starting with 1). | 25 | %i Receive from Lua the argument number (starting with 1). |
| 20 | %o Return to Lua the argument, or nil if it does not exist. | 26 | %o Return to Lua the argument, or nil if it does not exist. |
| @@ -35,9 +41,14 @@ static void lua_getargv (void) | |||
| 35 | 41 | ||
| 36 | static void manual_input (void) | 42 | static void manual_input (void) |
| 37 | { | 43 | { |
| 44 | if (isatty(fileno(stdin))) | ||
| 45 | { | ||
| 38 | char buffer[250]; | 46 | char buffer[250]; |
| 39 | while (gets(buffer) != 0) | 47 | while (gets(buffer) != 0) |
| 40 | lua_dostring(buffer); | 48 | lua_dostring(buffer); |
| 49 | } | ||
| 50 | else | ||
| 51 | lua_dofile(NULL); /* executes stdin as a file */ | ||
| 41 | } | 52 | } |
| 42 | 53 | ||
| 43 | 54 | ||
