summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-bin-mruby/tools
diff options
context:
space:
mode:
authorKOBAYASHI Shuji <[email protected]>2019-11-27 19:51:43 +0900
committerKOBAYASHI Shuji <[email protected]>2019-11-27 19:51:43 +0900
commitf4b528e07a069b9acbbcb61cced2b04115e61db7 (patch)
tree2dadf39864a06751efd5b5320927ee83f86d77f9 /mrbgems/mruby-bin-mruby/tools
parent190649e591de2bc0b935a22066fc9e79e8ae8f9b (diff)
downloadmruby-f4b528e07a069b9acbbcb61cced2b04115e61db7.tar.gz
mruby-f4b528e07a069b9acbbcb61cced2b04115e61db7.zip
Support `--` (end of options) to `mruby` command
#### Before this patch: ``` $ bin/mruby -e 'p ARGV' -- -x bin/mruby: invalid option -- (-h will show valid options) ``` #### After this patch: ``` $ bin/mruby -e 'p ARGV' -- -x ["-x"] ```
Diffstat (limited to 'mrbgems/mruby-bin-mruby/tools')
-rw-r--r--mrbgems/mruby-bin-mruby/tools/mruby/mruby.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c b/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c
index 38ebccddc..aa1ea9b80 100644
--- a/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c
+++ b/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c
@@ -64,21 +64,33 @@ options_init(struct options *opts, int argc, char **argv)
static const char *
options_opt(struct options *opts)
{
+ /* concatenated short options (e.g. `-cv`) */
if (*opts->short_opt && *++opts->opt) {
short_opt:
opts->short_opt[0] = *opts->opt;
opts->short_opt[1] = 0;
return opts->short_opt;
}
+
while (++opts->argv, --opts->argc) {
opts->opt = *opts->argv;
+
+ /* empty || not start with `-` || `-` */
if (!opts->opt[0] || opts->opt[0] != '-' || !opts->opt[1]) return NULL;
+
if (opts->opt[1] == '-') {
+ /* `--` */
+ if (!opts->opt[2]) {
+ ++opts->argv, --opts->argc;
+ return NULL;
+ }
+ /* long option */
opts->opt += 2;
*opts->short_opt = 0;
return opts->opt;
}
else {
+ /* short option */
++opts->opt;
goto short_opt;
}
@@ -90,6 +102,7 @@ static const char *
options_arg(struct options *opts)
{
if (*opts->short_opt && opts->opt[1]) {
+ /* concatenated short option and option argument (e.g. `-rLIBRARY`) */
*opts->short_opt = 0;
return opts->opt + 1;
}