aboutsummaryrefslogtreecommitdiff
path: root/lua.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2010-01-21 14:31:06 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2010-01-21 14:31:06 -0200
commitc8ab34ab7ac24c1b3f3778ab596db3666a7f8fa0 (patch)
tree1b156a44bc5333b1287f4a25ce72b475c9178faf /lua.c
parent36ab1ee10c557efe625bfab76eeea9fc6e0b7ab9 (diff)
downloadlua-c8ab34ab7ac24c1b3f3778ab596db3666a7f8fa0.tar.gz
lua-c8ab34ab7ac24c1b3f3778ab596db3666a7f8fa0.tar.bz2
lua-c8ab34ab7ac24c1b3f3778ab596db3666a7f8fa0.zip
better messages for invalid options
Diffstat (limited to 'lua.c')
-rw-r--r--lua.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/lua.c b/lua.c
index fec928ad..9e83025a 100644
--- a/lua.c
+++ b/lua.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lua.c,v 1.181 2009/12/22 15:32:50 roberto Exp roberto $ 2** $Id: lua.c,v 1.182 2009/12/22 16:47:12 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,18 +102,19 @@ static void laction (int i) {
102} 102}
103 103
104 104
105static void print_usage (void) { 105static void print_usage (char badoption) {
106 fprintf(stderr, 106 fprintf(stderr,
107 "%s: unrecognized option '-%c'\n"
107 "usage: %s [options] [script [args]]\n" 108 "usage: %s [options] [script [args]]\n"
108 "Available options are:\n" 109 "Available options are:\n"
109 " -e stat execute string " LUA_QL("stat") "\n" 110 " -e stat execute string " LUA_QL("stat") "\n"
110 " -l name require library " LUA_QL("name") "\n"
111 " -i enter interactive mode after executing " LUA_QL("script") "\n" 111 " -i enter interactive mode after executing " LUA_QL("script") "\n"
112 " -l name require library " LUA_QL("name") "\n"
112 " -v show version information\n" 113 " -v show version information\n"
113 " -- stop handling options\n" 114 " -- stop handling options\n"
114 " - execute stdin and stop handling options\n" 115 " - stop handling options and execute stdin\n"
115 , 116 ,
116 progname); 117 progname, badoption, progname);
117 fflush(stderr); 118 fflush(stderr);
118} 119}
119 120
@@ -359,7 +360,8 @@ static int collectargs (char **argv, int *pi, int *pv, int *pe) {
359 if (argv[i] == NULL) return -1; 360 if (argv[i] == NULL) return -1;
360 } 361 }
361 break; 362 break;
362 default: return -1; /* invalid option */ 363 default: /* invalid option; return the offendind character as a... */
364 return -(unsigned char)argv[i][1]; /* ...negative value */
363 } 365 }
364 } 366 }
365 return 0; 367 return 0;
@@ -412,8 +414,8 @@ static int pmain (lua_State *L) {
412 int has_i = 0, has_v = 0, has_e = 0; 414 int has_i = 0, has_v = 0, has_e = 0;
413 if (argv[0] && argv[0][0]) progname = argv[0]; 415 if (argv[0] && argv[0][0]) progname = argv[0];
414 script = collectargs(argv, &has_i, &has_v, &has_e); 416 script = collectargs(argv, &has_i, &has_v, &has_e);
415 if (script < 0) { /* invalid args? */ 417 if (script < 0) { /* invalid arg? */
416 print_usage(); 418 print_usage(-script); /* '-script' is the offending argument */
417 return 0; 419 return 0;
418 } 420 }
419 if (has_v) print_version(); 421 if (has_v) print_version();