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
1e34b12a
Commit
1e34b12a
authored
Oct 06, 2014
by
kyab
Committed by
Yasuhiro Matsumoto
Dec 26, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mirb: Don't exit on Ctrl-C
parent
76d44b1b
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 @
1e34b12a
...
...
@@ -11,6 +11,9 @@
#include <stdio.h>
#include <ctype.h>
#include <signal.h>
#include <setjmp.h>
#ifdef ENABLE_READLINE
#include <readline/readline.h>
#include <readline/history.h>
...
...
@@ -29,6 +32,16 @@
#define MIRB_USING_HISTORY()
#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/array.h>
#include <mruby/proc.h>
...
...
@@ -326,6 +339,23 @@ check_keyword(const char *buf, const char *word)
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
main
(
int
argc
,
char
**
argv
)
{
...
...
@@ -336,6 +366,7 @@ main(int argc, char **argv)
size_t
char_index
;
#else
char
*
history_path
;
char
*
line
;
#endif
mrbc_context
*
cxt
;
struct
mrb_parser_state
*
parser
;
...
...
@@ -410,6 +441,7 @@ main(int argc, char **argv)
#ifndef ENABLE_READLINE
print_cmdline
(
code_block_open
);
signal
(
SIGINT
,
ctrl_c_handler
);
char_index
=
0
;
while
((
last_char
=
getchar
())
!=
'\n'
)
{
if
(
last_char
==
EOF
)
break
;
...
...
@@ -419,6 +451,15 @@ main(int argc, char **argv)
}
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
)
{
fputs
(
"
\n
"
,
stdout
);
break
;
...
...
@@ -427,7 +468,19 @@ main(int argc, char **argv)
last_code_line
[
char_index
++
]
=
'\n'
;
last_code_line
[
char_index
]
=
'\0'
;
#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
?
"* "
:
"> "
);
signal
(
SIGINT
,
SIG_DFL
);
if
(
line
==
NULL
)
{
printf
(
"
\n
"
);
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