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
6218b2e0
Commit
6218b2e0
authored
Dec 26, 2015
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3061 from mattn/fix-ctrl-c
mirb: Don't exit on Ctrl-C
parents
76d44b1b
1e34b12a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
0 deletions
+53
-0
mrbgems/mruby-bin-mirb/tools/mirb/mirb.c
mrbgems/mruby-bin-mirb/tools/mirb/mirb.c
+53
-0
No files found.
mrbgems/mruby-bin-mirb/tools/mirb/mirb.c
View file @
6218b2e0
...
@@ -11,6 +11,9 @@
...
@@ -11,6 +11,9 @@
#include <stdio.h>
#include <stdio.h>
#include <ctype.h>
#include <ctype.h>
#include <signal.h>
#include <setjmp.h>
#ifdef ENABLE_READLINE
#ifdef ENABLE_READLINE
#include <readline/readline.h>
#include <readline/readline.h>
#include <readline/history.h>
#include <readline/history.h>
...
@@ -29,6 +32,16 @@
...
@@ -29,6 +32,16 @@
#define MIRB_USING_HISTORY()
#define MIRB_USING_HISTORY()
#endif
#endif
#ifndef _WIN32
#define MIRB_SIGSETJMP(env) sigsetjmp(env, 1)
#define MIRB_SIGLONGJMP(env, val) siglongjmp(env, val)
#define SIGJMP_BUF sigjmp_buf
#else
#define MIRB_SIGSETJMP(env) setjmp(env)
#define MIRB_SIGLONGJMP(env, val) longjmp(env, val)
#define SIGJMP_BUF jmp_buf
#endif
#include <mruby.h>
#include <mruby.h>
#include <mruby/array.h>
#include <mruby/array.h>
#include <mruby/proc.h>
#include <mruby/proc.h>
...
@@ -326,6 +339,23 @@ check_keyword(const char *buf, const char *word)
...
@@ -326,6 +339,23 @@ check_keyword(const char *buf, const char *word)
return
1
;
return
1
;
}
}
#ifndef ENABLE_READLINE
volatile
sig_atomic_t
input_canceled
=
0
;
void
ctrl_c_handler
(
int
signo
)
{
input_canceled
=
1
;
}
#else
SIGJMP_BUF
ctrl_c_buf
;
void
ctrl_c_handler
(
int
signo
)
{
MIRB_SIGLONGJMP
(
ctrl_c_buf
,
1
);
}
#endif
int
int
main
(
int
argc
,
char
**
argv
)
main
(
int
argc
,
char
**
argv
)
{
{
...
@@ -336,6 +366,7 @@ main(int argc, char **argv)
...
@@ -336,6 +366,7 @@ main(int argc, char **argv)
size_t
char_index
;
size_t
char_index
;
#else
#else
char
*
history_path
;
char
*
history_path
;
char
*
line
;
#endif
#endif
mrbc_context
*
cxt
;
mrbc_context
*
cxt
;
struct
mrb_parser_state
*
parser
;
struct
mrb_parser_state
*
parser
;
...
@@ -410,6 +441,7 @@ main(int argc, char **argv)
...
@@ -410,6 +441,7 @@ main(int argc, char **argv)
#ifndef ENABLE_READLINE
#ifndef ENABLE_READLINE
print_cmdline
(
code_block_open
);
print_cmdline
(
code_block_open
);
signal
(
SIGINT
,
ctrl_c_handler
);
char_index
=
0
;
char_index
=
0
;
while
((
last_char
=
getchar
())
!=
'\n'
)
{
while
((
last_char
=
getchar
())
!=
'\n'
)
{
if
(
last_char
==
EOF
)
break
;
if
(
last_char
==
EOF
)
break
;
...
@@ -419,6 +451,15 @@ main(int argc, char **argv)
...
@@ -419,6 +451,15 @@ main(int argc, char **argv)
}
}
last_code_line
[
char_index
++
]
=
last_char
;
last_code_line
[
char_index
++
]
=
last_char
;
}
}
signal
(
SIGINT
,
SIG_DFL
);
if
(
input_canceled
)
{
ruby_code
[
0
]
=
'\0'
;
last_code_line
[
0
]
=
'\0'
;
code_block_open
=
FALSE
;
puts
(
"^C"
);
input_canceled
=
0
;
continue
;
}
if
(
last_char
==
EOF
)
{
if
(
last_char
==
EOF
)
{
fputs
(
"
\n
"
,
stdout
);
fputs
(
"
\n
"
,
stdout
);
break
;
break
;
...
@@ -427,7 +468,19 @@ main(int argc, char **argv)
...
@@ -427,7 +468,19 @@ main(int argc, char **argv)
last_code_line
[
char_index
++
]
=
'\n'
;
last_code_line
[
char_index
++
]
=
'\n'
;
last_code_line
[
char_index
]
=
'\0'
;
last_code_line
[
char_index
]
=
'\0'
;
#else
#else
if
(
MIRB_SIGSETJMP
(
ctrl_c_buf
)
==
0
)
{
;
}
else
{
ruby_code
[
0
]
=
'\0'
;
last_code_line
[
0
]
=
'\0'
;
code_block_open
=
FALSE
;
puts
(
"^C"
);
}
signal
(
SIGINT
,
ctrl_c_handler
);
line
=
MIRB_READLINE
(
code_block_open
?
"* "
:
"> "
);
line
=
MIRB_READLINE
(
code_block_open
?
"* "
:
"> "
);
signal
(
SIGINT
,
SIG_DFL
);
if
(
line
==
NULL
)
{
if
(
line
==
NULL
)
{
printf
(
"
\n
"
);
printf
(
"
\n
"
);
break
;
break
;
...
...
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