Skip to content

Commit

Permalink
Wire up MVM_HAS_READLINE and --no-readline
Browse files Browse the repository at this point in the history
  • Loading branch information
gerdr authored and zhuomingliang committed Aug 23, 2013
1 parent 15c2b0f commit 6de9acd
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 5 deletions.
14 changes: 14 additions & 0 deletions Configure.pl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
cc=s ld=s make=s
build=s host=s
big-endian
no-readline
)) or die "See --help for further information\n";

pod2usage(1) if $args{help};
Expand All @@ -41,6 +42,8 @@
$args{instrument} //= 0;

$args{'big-endian'} //= 0;
# disable GNU Readline
$args{'no-readline'} //= 0;

# fill in C<%defaults>
if (exists $args{build} || exists $args{host}) {
Expand All @@ -53,6 +56,8 @@
}

$config{name} = $NAME;
$config{hasreadline} = 0
if $args{'no-readline'};

# set options that take priority over all others
my @keys = qw( cc ld make );
Expand Down Expand Up @@ -122,6 +127,8 @@
build::auto::detect_native(\%config, \%defaults);
}

$config{hasreadline} //= 0;

# dump configuration
print "\n", <<TERM, "\n";
make: $config{make}
Expand Down Expand Up @@ -424,6 +431,7 @@ =head1 SYNOPSIS
[--toolchain <toolchain>] [--compiler <compiler>]
[--cc <cc>] [--ld <ld>] [--make <make>]
[--debug] [--optimize] [--instrument]
[--no-readline]
./Configure.pl --build <build-triple> --host <host-triple>
[--cc <cc>] [--ld <ld>] [--make <make>]
Expand Down Expand Up @@ -494,6 +502,12 @@ =head1 OPTIONS
Explicitly set the make tool without affecting other configuration
options.
=item --no-readline
Disable GNU Readline auto-detection and force use of Linenoise.
This flag is important if you create derivative work based on MoarVM
that you wish to distribute under a license other than the GNU GPL.
=item --build <build-triple> --host <host-triple>
Set up cross-compilation.
Expand Down
11 changes: 6 additions & 5 deletions build/auto.pm
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ sub detect_native {
}

# detect readline and use it instead of linenoise
if ($defaults->{-toolchain} eq 'gnu') {
print ::dots(' auto-detecting readline library');
if ($defaults->{-toolchain} eq 'gnu' && !defined $config->{hasreadline}) {
print ::dots(' auto-detecting GNU readline');

my $cc = $config->{cc};
qx{echo '#include <readline/readline.h>' | $cc -E - 2>&1};
Expand All @@ -43,9 +43,10 @@ sub detect_native {
print "YES\n";
$config->{ldlibs} = '-lreadline ' . $config->{ldlibs};

# TODO: disable linenoise build
# print ::dots(' disable linenoise build');
# print "OK\n";
print ::dots(' disable Linenoise build');
$defaults->{-thirdparty}->{ln} = undef;
$config->{hasreadline} = 1;
print "OK\n";
}
else { print "NO\n" }
}
Expand Down
3 changes: 3 additions & 0 deletions build/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@

/* stuff for uthash */
#define uthash_fatal(msg) MVM_exception_throw_adhoc(tc, "internal hash error: " msg)

/* Readline detection */
#define MVM_HAS_READLINE @hasreadline@
42 changes: 42 additions & 0 deletions src/io/fileops.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,48 @@ MVMString * MVM_file_readline_fh(MVMThreadContext *tc, MVMObject *oshandle) {
return result;
}

/* reads a line from a filehandle. */
MVMString * MVM_file_readline_interactive_fh(MVMThreadContext *tc, MVMObject *oshandle, MVMString *prompt) {
MVMString *return_str = NULL;
MVMOSHandle *handle;
char *line;
char * const prompt_str = MVM_string_utf8_encode_C_string(tc, prompt);

verify_filehandle_type(tc, oshandle, &handle, "read from filehandle");

#if MVM_HAS_READLINE
line = readline(prompt_str);

free(prompt_str);

if (line) {
if (*line)
add_history(line);

return_str = MVM_decode_C_buffer_to_string(tc, tc->instance->VMString, line, strlen(line), handle->body.encoding_type);

free(line);
}

#else /* !MVM_HAS_READLINE */
line = linenoise(prompt_str);

free(prompt_str);

if (line) {
if (*line) {
linenoiseHistoryAdd(line);
}

return_str = MVM_decode_C_buffer_to_string(tc, tc->instance->VMString, line, strlen(line), handle->body.encoding_type);

free(line);
}
#endif /* MVM_HAS_READLINE */

return return_str;
}

/* reads a string from a filehandle. */
MVMString * MVM_file_read_fhs(MVMThreadContext *tc, MVMObject *oshandle, MVMint64 length) {
MVMString *result;
Expand Down

0 comments on commit 6de9acd

Please sign in to comment.