Putting Readline code inside #ifdefs

This commit is contained in:
Haitham Gad 2013-03-09 23:18:49 -05:00 committed by Paul Beckingham
parent 60a7d2128e
commit a5f55bf2f4
6 changed files with 23 additions and 20 deletions

View file

@ -121,12 +121,7 @@ configure_file (
add_subdirectory (src)
add_subdirectory (src/commands)
add_subdirectory (src/columns)
# Doesn't make sense to build shell without Readline.
if (HAVE_READLINE)
add_subdirectory (src/shell)
endif (HAVE_READLINE)
add_subdirectory (doc)
add_subdirectory (i18n)
add_subdirectory (scripts)

View file

@ -45,6 +45,9 @@ Override PACKAGE_LANGUAGE, then
/* Found the GnuTLS library */
#cmakedefine HAVE_LIBGNUTLS
/* Found the Readline library */
#cmakedefine HAVE_READLINE
/* Found the pthread library */
#cmakedefine HAVE_LIBPTHREAD

View file

@ -29,20 +29,37 @@
#include <iostream>
#include <unistd.h>
#include <cmake.h>
#include <Readline.h>
#ifdef HAVE_READLINE
#include <readline/readline.h>
#include <readline/history.h>
#endif
////////////////////////////////////////////////////////////////////////////////
std::string Readline::gets (const std::string& prompt)
{
#ifdef HAVE_READLINE
// Get a line from the user.
char *line_read = rl::readline (prompt.c_str ());
char *line_read = readline (prompt.c_str ());
#else
std::string line_read;
std::cout << prompt;
std::getline (std::cin, line_read);
#endif
#ifdef HAVE_READLINE
// If the line has any text in it, save it on the history.
if (line_read && *line_read)
rl::add_history (line_read);
add_history (line_read);
#endif
std::string ret (line_read);
#ifdef HAVE_READLINE
free (line_read);
#endif
return ret;
}

View file

@ -33,17 +33,6 @@
#include <stdio.h>
#include <wordexp.h>
namespace rl
{
// Wrapping readline.h in a namespace to
// avoid cluttering the global namespace.
extern "C"
{
#include <readline/readline.h>
#include <readline/history.h>
}
}
// Static class that offers a C++ API to readline C functions.
class Readline
{

View file

@ -42,7 +42,6 @@
#include <i18n.h>
#include <Color.h>
#include <Context.h>
#include <cmake.h>
#include <Readline.h>
Context context;

View file

@ -42,7 +42,7 @@ if (open my $fh, '>', 'shell.rc')
}
# Test the prompt.
my $output = qx{printf "rc:test.rc add foo\nquit" | ../src/shell/tasksh 2>&1};
my $output = qx{printf "rc:shell.rc add foo\nquit" | ../src/shell/tasksh 2>&1};
like ($output, qr/testprompt>/, 'custom prompt is being used');
# Test a simple add, then info.