Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
9a41db6f
Commit
9a41db6f
authored
Nov 27, 2015
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2950 from mattn/mirb-file-args
mirb should take filename and arguments.
parents
5c405dea
e20c2d78
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
2 deletions
+43
-2
mrbgems/mruby-bin-mirb/tools/mirb/mirb.c
mrbgems/mruby-bin-mirb/tools/mirb/mirb.c
+43
-2
No files found.
mrbgems/mruby-bin-mirb/tools/mirb/mirb.c
View file @
9a41db6f
...
...
@@ -194,6 +194,7 @@ is_code_block_open(struct mrb_parser_state *parser)
}
struct
_args
{
FILE
*
rfp
;
mrb_bool
verbose
:
1
;
int
argc
;
char
**
argv
;
...
...
@@ -251,12 +252,30 @@ parse_args(mrb_state *mrb, int argc, char **argv, struct _args *args)
return
EXIT_FAILURE
;
}
}
if
(
args
->
rfp
==
NULL
)
{
if
(
*
argv
!=
NULL
)
{
args
->
rfp
=
fopen
(
argv
[
0
],
"r"
);
if
(
args
->
rfp
==
NULL
)
{
printf
(
"Cannot open program file. (%s)
\n
"
,
*
argv
);
return
EXIT_FAILURE
;
}
argc
--
;
argv
++
;
}
}
args
->
argv
=
(
char
**
)
mrb_realloc
(
mrb
,
args
->
argv
,
sizeof
(
char
*
)
*
(
argc
+
1
));
memcpy
(
args
->
argv
,
argv
,
(
argc
+
1
)
*
sizeof
(
char
*
));
args
->
argc
=
argc
;
return
EXIT_SUCCESS
;
}
static
void
cleanup
(
mrb_state
*
mrb
,
struct
_args
*
args
)
{
if
(
args
->
rfp
)
fclose
(
args
->
rfp
);
mrb_free
(
mrb
,
args
->
argv
);
mrb_close
(
mrb
);
}
...
...
@@ -323,7 +342,9 @@ main(int argc, char **argv)
mrb_state
*
mrb
;
mrb_value
result
;
struct
_args
args
;
mrb_value
ARGV
;
int
n
;
int
i
;
mrb_bool
code_block_open
=
FALSE
;
int
ai
;
unsigned
int
stack_keep
=
0
;
...
...
@@ -334,7 +355,6 @@ main(int argc, char **argv)
fputs
(
"Invalid mrb interpreter, exiting mirb
\n
"
,
stderr
);
return
EXIT_FAILURE
;
}
mrb_define_global_const
(
mrb
,
"ARGV"
,
mrb_ary_new_capa
(
mrb
,
0
));
n
=
parse_args
(
mrb
,
argc
,
argv
,
&
args
);
if
(
n
==
EXIT_FAILURE
)
{
...
...
@@ -343,6 +363,16 @@ main(int argc, char **argv)
return
n
;
}
ARGV
=
mrb_ary_new_capa
(
mrb
,
args
.
argc
);
for
(
i
=
0
;
i
<
args
.
argc
;
i
++
)
{
char
*
utf8
=
mrb_utf8_from_locale
(
args
.
argv
[
i
],
-
1
);
if
(
utf8
)
{
mrb_ary_push
(
mrb
,
ARGV
,
mrb_str_new_cstr
(
mrb
,
utf8
));
mrb_utf8_free
(
utf8
);
}
}
mrb_define_global_const
(
mrb
,
"ARGV"
,
ARGV
);
#ifdef ENABLE_READLINE
history_path
=
get_history_path
(
mrb
);
if
(
history_path
==
NULL
)
{
...
...
@@ -366,8 +396,17 @@ main(int argc, char **argv)
ai
=
mrb_gc_arena_save
(
mrb
);
while
(
TRUE
)
{
#ifdef ENABLE_READLINE
char
*
line
;
#endif
char
*
utf8
;
if
(
args
.
rfp
)
{
if
(
fgets
(
last_code_line
,
sizeof
(
last_code_line
)
-
1
,
args
.
rfp
)
!=
NULL
)
goto
done
;
break
;
}
#ifndef ENABLE_READLINE
print_cmdline
(
code_block_open
);
...
...
@@ -388,7 +427,7 @@ main(int argc, char **argv)
last_code_line
[
char_index
++
]
=
'\n'
;
last_code_line
[
char_index
]
=
'\0'
;
#else
char
*
line
=
MIRB_READLINE
(
code_block_open
?
"* "
:
"> "
);
line
=
MIRB_READLINE
(
code_block_open
?
"* "
:
"> "
);
if
(
line
==
NULL
)
{
printf
(
"
\n
"
);
break
;
...
...
@@ -403,6 +442,8 @@ main(int argc, char **argv)
free
(
line
);
#endif
done:
if
(
code_block_open
)
{
if
(
strlen
(
ruby_code
)
+
strlen
(
last_code_line
)
>
sizeof
(
ruby_code
)
-
1
)
{
fputs
(
"concatenated input string too long
\n
"
,
stderr
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment