Commit 03d32796 authored by NARUSE, Yui's avatar NARUSE, Yui

Support mruby -e'p 1'.

mruby supports already -e 'p 1' (-e, space, command), but hadn't
supported no space version.
parent 73d7000b
...@@ -51,12 +51,14 @@ parse_args(mrb_state *mrb, int argc, char **argv, struct _args *args) ...@@ -51,12 +51,14 @@ parse_args(mrb_state *mrb, int argc, char **argv, struct _args *args)
memset(args, 0, sizeof(*args)); memset(args, 0, sizeof(*args));
for (argc--,argv++; argc > 0; argc--,argv++) { for (argc--,argv++; argc > 0; argc--,argv++) {
char *item;
if (argv[0][0] != '-') break; if (argv[0][0] != '-') break;
if (strlen(*argv) <= 1) if (strlen(*argv) <= 1)
return -1; return -1;
switch ((*argv)[1]) { item = argv[0] + 1;
switch (*item++) {
case 'b': case 'b':
args->mrbfile = 1; args->mrbfile = 1;
break; break;
...@@ -64,19 +66,24 @@ parse_args(mrb_state *mrb, int argc, char **argv, struct _args *args) ...@@ -64,19 +66,24 @@ parse_args(mrb_state *mrb, int argc, char **argv, struct _args *args)
args->check_syntax = 1; args->check_syntax = 1;
break; break;
case 'e': case 'e':
if (argc > 1) { if (item[0]) {
goto append_cmdline;
}
else if (argc > 1) {
argc--; argv++; argc--; argv++;
item = argv[0];
append_cmdline:
if (!args->cmdline) { if (!args->cmdline) {
char *buf; char *buf;
buf = mrb_malloc(mrb, strlen(argv[0])+1); buf = mrb_malloc(mrb, strlen(item)+1);
strcpy(buf, argv[0]); strcpy(buf, item);
args->cmdline = buf; args->cmdline = buf;
} }
else { else {
args->cmdline = mrb_realloc(mrb, args->cmdline, strlen(args->cmdline)+strlen(argv[0])+2); args->cmdline = mrb_realloc(mrb, args->cmdline, strlen(args->cmdline)+strlen(item)+2);
strcat(args->cmdline, "\n"); strcat(args->cmdline, "\n");
strcat(args->cmdline, argv[0]); strcat(args->cmdline, item);
} }
} }
else { else {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment