|
|
@ -1,5 +1,5 @@ |
|
|
|
/*
|
|
|
|
** $Id: lua.c,v 1.183 2010/01/21 16:31:06 roberto Exp roberto $ |
|
|
|
** $Id: lua.c,v 1.184 2010/01/21 16:49:21 roberto Exp roberto $ |
|
|
|
** Lua stand-alone interpreter |
|
|
|
** See Copyright Notice in lua.h |
|
|
|
*/ |
|
|
@ -102,9 +102,12 @@ static void laction (int i) { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void print_usage (char badoption) { |
|
|
|
static void print_usage (const char *badoption) { |
|
|
|
if (badoption[1] == 'e' || badoption[1] == 'l') |
|
|
|
fprintf(stderr, "%s: '%s' needs argument\n", progname, badoption); |
|
|
|
else |
|
|
|
fprintf(stderr, "%s: unrecognized option '%s'\n", progname, badoption); |
|
|
|
fprintf(stderr, |
|
|
|
"%s: unrecognized option '-%c'\n" |
|
|
|
"usage: %s [options] [script [args]]\n" |
|
|
|
"Available options are:\n" |
|
|
|
" -e stat execute string " LUA_QL("stat") "\n" |
|
|
@ -114,7 +117,7 @@ static void print_usage (char badoption) { |
|
|
|
" -- stop handling options\n" |
|
|
|
" - stop handling options and execute stdin\n" |
|
|
|
, |
|
|
|
progname, badoption, progname); |
|
|
|
progname); |
|
|
|
fflush(stderr); |
|
|
|
} |
|
|
|
|
|
|
@ -357,11 +360,11 @@ static int collectargs (char **argv, int *pi, int *pv, int *pe) { |
|
|
|
case 'l': |
|
|
|
if (argv[i][2] == '\0') { |
|
|
|
i++; |
|
|
|
if (argv[i] == NULL) return -1; |
|
|
|
if (argv[i] == NULL) return -(i - 1); |
|
|
|
} |
|
|
|
break; |
|
|
|
default: /* invalid option; return the offendind character as a... */ |
|
|
|
return -(unsigned char)argv[i][1]; /* ...negative value */ |
|
|
|
default: /* invalid option; return its index... */ |
|
|
|
return -i; /* ...as a negative value */ |
|
|
|
} |
|
|
|
} |
|
|
|
return 0; |
|
|
@ -415,7 +418,7 @@ static int pmain (lua_State *L) { |
|
|
|
if (argv[0] && argv[0][0]) progname = argv[0]; |
|
|
|
script = collectargs(argv, &has_i, &has_v, &has_e); |
|
|
|
if (script < 0) { /* invalid arg? */ |
|
|
|
print_usage(-script); /* '-script' is the offending argument */ |
|
|
|
print_usage(argv[-script]); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
if (has_v) print_version(); |
|
|
|