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

@ -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;