help message

This commit is contained in:
Roberto Ierusalimschy
1997-12-22 16:05:23 -02:00
parent fae0b52825
commit 43461d267f

49
lua.c
View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lua.c,v 1.9 1997/12/11 17:00:21 roberto Exp roberto $ ** $Id: lua.c,v 1.10 1997/12/19 18:34:23 roberto Exp roberto $
** Lua stand-alone interpreter ** Lua stand-alone interpreter
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -25,16 +25,20 @@
#define isatty(x) (x==0) /* assume stdin is a tty */ #define isatty(x) (x==0) /* assume stdin is a tty */
#endif #endif
/* command line options:
** -v print version information (banner). static void print_message (void)
** -d debug on {
** -e dostring on next arg fprintf(stderr,
** a=b sets global 'a' with string 'b' "Lua: command line options:\n"
** -q interactive mode without prompt " -v print version information\n"
** -i interactive mode with prompt " -d turn debug on\n"
** - executes stdin as a file " -e stat dostring `stat'\n"
** name dofile "name" " -q interactive mode without prompt\n"
*/ " -i interactive mode with prompt\n"
" - executes stdin as a file\n"
" a=b sets global `a' with string `b'\n"
" name dofile `name'\n\n");
}
static void assign (char *arg) static void assign (char *arg)
@@ -104,23 +108,34 @@ int main (int argc, char *argv[])
lua_dofile(NULL); /* executes stdin as a file */ lua_dofile(NULL); /* executes stdin as a file */
} }
else for (i=1; i<argc; i++) { else for (i=1; i<argc; i++) {
if (strcmp(argv[i], "-") == 0) if (argv[i][0] == '-') { /* option? */
switch (argv[i][1]) {
case 0:
lua_dofile(NULL); /* executes stdin as a file */ lua_dofile(NULL); /* executes stdin as a file */
else if (strcmp(argv[i], "-i") == 0) break;
case 'i':
manual_input(1); manual_input(1);
else if (strcmp(argv[i], "-q") == 0) break;
case 'q':
manual_input(0); manual_input(0);
else if (strcmp(argv[i], "-d") == 0) break;
case 'd':
lua_debug = 1; lua_debug = 1;
else if (strcmp(argv[i], "-v") == 0) break;
case 'v':
printf("%s %s\n(written by %s)\n\n", printf("%s %s\n(written by %s)\n\n",
LUA_VERSION, LUA_COPYRIGHT, LUA_AUTHORS); LUA_VERSION, LUA_COPYRIGHT, LUA_AUTHORS);
else if (strcmp(argv[i], "-e") == 0) { break;
case 'e':
i++; i++;
if (lua_dostring(argv[i]) != 0) { if (lua_dostring(argv[i]) != 0) {
fprintf(stderr, "lua: error running argument `%s'\n", argv[i]); fprintf(stderr, "lua: error running argument `%s'\n", argv[i]);
return 1; return 1;
} }
break;
default:
print_message();
}
} }
else if (strchr(argv[i], '=')) else if (strchr(argv[i], '='))
assign(argv[i]); assign(argv[i]);