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
8f8c22ac
Commit
8f8c22ac
authored
Mar 27, 2013
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1084 from kano4/pr-add-simple-usage-message-for-mirb
Add simple usage message for mirb
parents
6e48f272
5a22c6da
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
72 additions
and
3 deletions
+72
-3
tools/mirb/mirb.c
tools/mirb/mirb.c
+72
-3
No files found.
tools/mirb/mirb.c
View file @
8f8c22ac
...
...
@@ -132,6 +132,67 @@ is_code_block_open(struct mrb_parser_state *parser)
return
code_block_open
;
}
void
mrb_show_version
(
mrb_state
*
);
void
mrb_show_copyright
(
mrb_state
*
);
struct
_args
{
int
argc
;
char
**
argv
;
};
static
void
usage
(
const
char
*
name
)
{
static
const
char
*
const
usage_msg
[]
=
{
"switches:"
,
"--version print the version"
,
"--copyright print the copyright"
,
NULL
};
const
char
*
const
*
p
=
usage_msg
;
printf
(
"Usage: %s [switches]
\n
"
,
name
);
while
(
*
p
)
printf
(
" %s
\n
"
,
*
p
++
);
}
static
int
parse_args
(
mrb_state
*
mrb
,
int
argc
,
char
**
argv
,
struct
_args
*
args
)
{
static
const
struct
_args
args_zero
=
{
0
};
*
args
=
args_zero
;
for
(
argc
--
,
argv
++
;
argc
>
0
;
argc
--
,
argv
++
)
{
char
*
item
;
if
(
argv
[
0
][
0
]
!=
'-'
)
break
;
item
=
argv
[
0
]
+
1
;
switch
(
*
item
++
)
{
case
'-'
:
if
(
strcmp
((
*
argv
)
+
2
,
"version"
)
==
0
)
{
mrb_show_version
(
mrb
);
exit
(
0
);
}
else
if
(
strcmp
((
*
argv
)
+
2
,
"copyright"
)
==
0
)
{
mrb_show_copyright
(
mrb
);
exit
(
0
);
}
else
return
-
3
;
default:
return
-
4
;
}
}
return
0
;
}
static
void
cleanup
(
mrb_state
*
mrb
,
struct
_args
*
args
)
{
mrb_close
(
mrb
);
}
/* Print a short remark for the user */
static
void
print_hint
(
void
)
...
...
@@ -154,7 +215,7 @@ print_cmdline(int code_block_open)
}
int
main
(
void
)
main
(
int
argc
,
char
**
argv
)
{
char
ruby_code
[
1024
]
=
{
0
};
char
last_code_line
[
1024
]
=
{
0
};
...
...
@@ -166,12 +227,11 @@ main(void)
struct
mrb_parser_state
*
parser
;
mrb_state
*
mrb
;
mrb_value
result
;
struct
_args
args
;
int
n
;
int
code_block_open
=
FALSE
;
int
ai
;
print_hint
();
/* new interpreter instance */
mrb
=
mrb_open
();
if
(
mrb
==
NULL
)
{
...
...
@@ -179,6 +239,15 @@ main(void)
return
EXIT_FAILURE
;
}
n
=
parse_args
(
mrb
,
argc
,
argv
,
&
args
);
if
(
n
<
0
)
{
cleanup
(
mrb
,
&
args
);
usage
(
argv
[
0
]);
return
n
;
}
print_hint
();
cxt
=
mrbc_context_new
(
mrb
);
cxt
->
capture_errors
=
1
;
...
...
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