summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2014-05-15 12:07:02 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2014-05-15 12:07:02 +0900
commit0651051ded8bd731556ac6adb3d000e031034e8c (patch)
tree5c2b976877bb24f29cced47c5077547357cfd2aa
parent6f6f50d5296656da9ff49169d2998a84ce28a0bf (diff)
downloadmruby-0651051ded8bd731556ac6adb3d000e031034e8c.tar.gz
mruby-0651051ded8bd731556ac6adb3d000e031034e8c.zip
allow quit/exit to work within mirb; fix #2253 close #2254
also allow spaces around quit/exit.
-rw-r--r--mrbgems/mruby-bin-mirb/tools/mirb/mirb.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c b/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c
index b1b8767bc..5c9524161 100644
--- a/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c
+++ b/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c
@@ -9,6 +9,7 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
+#include <ctype.h>
#ifdef ENABLE_READLINE
#include <readline/readline.h>
@@ -250,6 +251,29 @@ print_cmdline(int code_block_open)
void mrb_codedump_all(mrb_state*, struct RProc*);
+static int
+check_keyword(const char *buf, const char *word)
+{
+ const char *p = buf;
+ size_t len = strlen(word);
+
+ /* skip preceding spaces */
+ while (*p && isspace(*p)) {
+ p++;
+ }
+ /* check keyword */
+ if (strncmp(p, word, len) != 0) {
+ return 0;
+ }
+ p += len;
+ /* skip trailing spaces */
+ while (*p) {
+ if (!isspace(*p)) return 0;
+ p++;
+ }
+ return 1;
+}
+
int
main(int argc, char **argv)
{
@@ -356,7 +380,7 @@ main(int argc, char **argv)
strcat(ruby_code, last_code_line);
}
else {
- if ((strcmp(last_code_line, "quit") == 0) || (strcmp(last_code_line, "exit") == 0)) {
+ if (check_keyword(last_code_line, "quit") || check_keyword(last_code_line, "exit")) {
break;
}
strcpy(ruby_code, last_code_line);