Ruby
2.1.3p242(2014-09-19revision47630)
Main Page
Modules
Data Structures
Files
File List
Globals
goruby.c
Go to the documentation of this file.
1
void
Init_golf
(
void
);
2
#define ruby_options goruby_options
3
#define ruby_run_node goruby_run_node
4
#include "
main.c
"
5
#undef ruby_options
6
#undef ruby_run_node
7
8
#if defined _WIN32
9
#include <
io.h
>
10
#include <fcntl.h>
11
#define pipe(p) _pipe(p, 32L, _O_NOINHERIT)
12
#elif defined HAVE_UNISTD_H
13
#include <
unistd.h
>
14
#endif
15
16
RUBY_EXTERN
void
*
ruby_options
(
int
argc
,
char
**
argv
);
17
RUBY_EXTERN
int
ruby_run_node
(
void
*);
18
RUBY_EXTERN
void
ruby_init_ext
(
const
char
*
name
,
void
(*init)(
void
));
19
20
static
VALUE
21
init_golf
(
VALUE
arg
)
22
{
23
ruby_init_ext
(
"golf.so"
,
Init_golf
);
24
return
arg
;
25
}
26
27
void
*
28
goruby_options
(
int
argc
,
char
**
argv
)
29
{
30
static
const
char
cmd[] =
"END{require 'irb';IRB.start}"
;
31
int
rw[2], infd;
32
void
*ret;
33
34
if
((isatty(0) && isatty(1) && isatty(2)) && (pipe(rw) == 0)) {
35
infd = dup(0);
36
dup2
(rw[0], 0);
37
close(rw[0]);
38
write(rw[1], cmd,
sizeof
(cmd) - 1);
39
close(rw[1]);
40
ret =
ruby_options
(argc, argv);
41
dup2
(infd, 0);
42
close(infd);
43
return
ret;
44
}
45
else
{
46
return
ruby_options
(argc, argv);
47
}
48
}
49
50
int
51
goruby_run_node
(
void
*
arg
)
52
{
53
int
state;
54
if
(
NIL_P
(
rb_protect
(
init_golf
,
Qtrue
, &state))) {
55
return
state ==
EXIT_SUCCESS
?
EXIT_FAILURE
: state;
56
}
57
return
ruby_run_node
(arg);
58
}
59
Generated on Mon Sep 22 2014 11:05:32 for Ruby by
1.8.2