summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYukihiro Matsumoto <[email protected]>2012-05-12 23:43:09 +0900
committerYukihiro Matsumoto <[email protected]>2012-05-12 23:43:09 +0900
commit260f41ed630dab4ae012084ce655b926e4ca5e58 (patch)
tree2e4b268d4510a5e8b32edb47427e4a476f263c5b
parent96819cf88188704f87746198a5fcc515d17a4676 (diff)
downloadmruby-260f41ed630dab4ae012084ce655b926e4ca5e58.tar.gz
mruby-260f41ed630dab4ae012084ce655b926e4ca5e58.zip
no #include unistd.h stdbool; close #124
-rw-r--r--tools/mirb/mirb.c48
1 files changed, 25 insertions, 23 deletions
diff --git a/tools/mirb/mirb.c b/tools/mirb/mirb.c
index bfd81d582..b2dbead0d 100644
--- a/tools/mirb/mirb.c
+++ b/tools/mirb/mirb.c
@@ -7,9 +7,6 @@
*/
#include <string.h>
-#include <stdbool.h>
-#include <unistd.h>
-#include <fcntl.h>
#include <mruby.h>
#include <mruby/proc.h>
@@ -18,8 +15,10 @@
/* Guess if the user might want to enter more
* or if he wants an evaluation of his code now */
-bool is_code_block_open(struct mrb_parser_state *parser) {
- bool code_block_open = false;
+int
+is_code_block_open(struct mrb_parser_state *parser)
+{
+ int code_block_open = FALSE;
switch (parser->lstate) {
@@ -28,32 +27,32 @@ bool is_code_block_open(struct mrb_parser_state *parser) {
case EXPR_BEG:
// an expression was just started,
// we can't end it like this
- code_block_open = true;
+ code_block_open = TRUE;
break;
case EXPR_DOT:
// a message dot was the last token,
// there has to come more
- code_block_open = true;
+ code_block_open = TRUE;
break;
case EXPR_CLASS:
// a class keyword is not enough!
// we need also a name of the class
- code_block_open = true;
+ code_block_open = TRUE;
break;
case EXPR_FNAME:
// a method name is necessary
- code_block_open = true;
+ code_block_open = TRUE;
break;
case EXPR_VALUE:
// if, elsif, etc. without condition
- code_block_open = true;
+ code_block_open = TRUE;
break;
// now all the states which are closed
case EXPR_ARG:
// an argument is the last token
- code_block_open = false;
+ code_block_open = FALSE;
break;
// all states which are unsure
@@ -93,25 +92,25 @@ bool is_code_block_open(struct mrb_parser_state *parser) {
if (strcmp(parser->error_buffer[0].message,
"syntax error, unexpected $end, expecting ';' or '\\n'") == 0) {
- code_block_open = true;
+ code_block_open = TRUE;
} else if (strcmp(parser->error_buffer[0].message,
"syntax error, unexpected $end, expecting keyword_end") == 0) {
- code_block_open = true;
+ code_block_open = TRUE;
} else if (strcmp(parser->error_buffer[0].message,
"syntax error, unexpected $end, expecting '<' or ';' or '\\n'") == 0) {
- code_block_open = true;
+ code_block_open = TRUE;
} else if (strcmp(parser->error_buffer[0].message,
"syntax error, unexpected keyword_end") == 0) {
- code_block_open = true;
+ code_block_open = TRUE;
} else if (strcmp(parser->error_buffer[0].message,
"syntax error, unexpected $end, expecting keyword_then or ';' or '\\n'") == 0) {
- code_block_open = true;
+ code_block_open = TRUE;
} else if (strcmp(parser->error_buffer[0].message,
"syntax error, unexpected tREGEXP_BEG") == 0) {
- code_block_open = true;
+ code_block_open = TRUE;
} else if (strcmp(parser->error_buffer[0].message,
"unterminated string meets end of file") == 0) {
- code_block_open = true;
+ code_block_open = TRUE;
}
}
} else {
@@ -131,7 +130,9 @@ void print_hint(void)
}
/* Print the command line prompt of the REPL */
-void print_cmdline(bool code_block_open) {
+void
+print_cmdline(int code_block_open)
+{
if (code_block_open) {
printf("* ");
} else {
@@ -139,7 +140,8 @@ void print_cmdline(bool code_block_open) {
}
}
-int main(void)
+int
+main(void)
{
char last_char, ruby_code[1024], last_code_line[1024];
int char_index;
@@ -147,7 +149,7 @@ int main(void)
mrb_state *mrb_interpreter;
mrb_value mrb_return_value;
int byte_code;
- bool code_block_open = false;
+ int code_block_open = FALSE;
print_hint();
@@ -156,7 +158,7 @@ int main(void)
memset(ruby_code, 0, sizeof(*ruby_code));
memset(last_code_line, 0, sizeof(*last_code_line));
- while (true) {
+ while (TRUE) {
print_cmdline(code_block_open);
char_index = 0;
@@ -174,7 +176,7 @@ int main(void)
if (strcmp(last_code_line, "exit") == 0) {
if (code_block_open) {
// cancel the current block and reset
- code_block_open = false;
+ code_block_open = FALSE;
memset(ruby_code, 0, sizeof(*ruby_code));
memset(last_code_line, 0, sizeof(*last_code_line));
continue;