diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-02-09 09:58:57 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-02-09 09:58:57 -0200 |
commit | a838b3b4968ec627513b7cad434497c749ba2bcd (patch) | |
tree | 17d570520ac09079a5531c90fdde2a9eaa3eb176 /lua.c | |
parent | 4c54cd3a107d1b394d7591f8c3ecd0b79885ff30 (diff) | |
download | lua-a838b3b4968ec627513b7cad434497c749ba2bcd.tar.gz lua-a838b3b4968ec627513b7cad434497c749ba2bcd.tar.bz2 lua-a838b3b4968ec627513b7cad434497c749ba2bcd.zip |
better usage messages, showing entire offending argument
Diffstat (limited to 'lua.c')
-rw-r--r-- | lua.c | 19 |
1 files changed, 11 insertions, 8 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lua.c,v 1.183 2010/01/21 16:31:06 roberto Exp roberto $ | 2 | ** $Id: lua.c,v 1.184 2010/01/21 16:49:21 roberto Exp roberto $ |
3 | ** Lua stand-alone interpreter | 3 | ** Lua stand-alone interpreter |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -102,9 +102,12 @@ static void laction (int i) { | |||
102 | } | 102 | } |
103 | 103 | ||
104 | 104 | ||
105 | static void print_usage (char badoption) { | 105 | static void print_usage (const char *badoption) { |
106 | if (badoption[1] == 'e' || badoption[1] == 'l') | ||
107 | fprintf(stderr, "%s: '%s' needs argument\n", progname, badoption); | ||
108 | else | ||
109 | fprintf(stderr, "%s: unrecognized option '%s'\n", progname, badoption); | ||
106 | fprintf(stderr, | 110 | fprintf(stderr, |
107 | "%s: unrecognized option '-%c'\n" | ||
108 | "usage: %s [options] [script [args]]\n" | 111 | "usage: %s [options] [script [args]]\n" |
109 | "Available options are:\n" | 112 | "Available options are:\n" |
110 | " -e stat execute string " LUA_QL("stat") "\n" | 113 | " -e stat execute string " LUA_QL("stat") "\n" |
@@ -114,7 +117,7 @@ static void print_usage (char badoption) { | |||
114 | " -- stop handling options\n" | 117 | " -- stop handling options\n" |
115 | " - stop handling options and execute stdin\n" | 118 | " - stop handling options and execute stdin\n" |
116 | , | 119 | , |
117 | progname, badoption, progname); | 120 | progname); |
118 | fflush(stderr); | 121 | fflush(stderr); |
119 | } | 122 | } |
120 | 123 | ||
@@ -357,11 +360,11 @@ static int collectargs (char **argv, int *pi, int *pv, int *pe) { | |||
357 | case 'l': | 360 | case 'l': |
358 | if (argv[i][2] == '\0') { | 361 | if (argv[i][2] == '\0') { |
359 | i++; | 362 | i++; |
360 | if (argv[i] == NULL) return -1; | 363 | if (argv[i] == NULL) return -(i - 1); |
361 | } | 364 | } |
362 | break; | 365 | break; |
363 | default: /* invalid option; return the offendind character as a... */ | 366 | default: /* invalid option; return its index... */ |
364 | return -(unsigned char)argv[i][1]; /* ...negative value */ | 367 | return -i; /* ...as a negative value */ |
365 | } | 368 | } |
366 | } | 369 | } |
367 | return 0; | 370 | return 0; |
@@ -415,7 +418,7 @@ static int pmain (lua_State *L) { | |||
415 | if (argv[0] && argv[0][0]) progname = argv[0]; | 418 | if (argv[0] && argv[0][0]) progname = argv[0]; |
416 | script = collectargs(argv, &has_i, &has_v, &has_e); | 419 | script = collectargs(argv, &has_i, &has_v, &has_e); |
417 | if (script < 0) { /* invalid arg? */ | 420 | if (script < 0) { /* invalid arg? */ |
418 | print_usage(-script); /* '-script' is the offending argument */ | 421 | print_usage(argv[-script]); |
419 | return 0; | 422 | return 0; |
420 | } | 423 | } |
421 | if (has_v) print_version(); | 424 | if (has_v) print_version(); |