From a5f55bf2f4f9cf3950c0d4c38817d6acdd65a3c5 Mon Sep 17 00:00:00 2001 From: Haitham Gad Date: Sat, 9 Mar 2013 23:18:49 -0500 Subject: [PATCH] Putting Readline code inside #ifdefs --- CMakeLists.txt | 5 ----- cmake.h.in | 3 +++ src/shell/Readline.cpp | 21 +++++++++++++++++++-- src/shell/Readline.h | 11 ----------- src/shell/main.cpp | 1 - test/shell.t | 2 +- 6 files changed, 23 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bfc632885..ec8fb778d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/cmake.h.in b/cmake.h.in index 0cac3a2f4..41d418e93 100644 --- a/cmake.h.in +++ b/cmake.h.in @@ -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 diff --git a/src/shell/Readline.cpp b/src/shell/Readline.cpp index e4f98fc3d..c2d5d5290 100644 --- a/src/shell/Readline.cpp +++ b/src/shell/Readline.cpp @@ -29,20 +29,37 @@ #include #include +#include #include +#ifdef HAVE_READLINE +#include +#include +#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; } diff --git a/src/shell/Readline.h b/src/shell/Readline.h index 4a6cab7fa..436bcafe6 100644 --- a/src/shell/Readline.h +++ b/src/shell/Readline.h @@ -33,17 +33,6 @@ #include #include -namespace rl -{ - // Wrapping readline.h in a namespace to - // avoid cluttering the global namespace. - extern "C" - { - #include - #include - } -} - // Static class that offers a C++ API to readline C functions. class Readline { diff --git a/src/shell/main.cpp b/src/shell/main.cpp index 912f3d2b5..5dddf62d2 100644 --- a/src/shell/main.cpp +++ b/src/shell/main.cpp @@ -42,7 +42,6 @@ #include #include #include -#include #include Context context; diff --git a/test/shell.t b/test/shell.t index 0140bb85b..9043e9417 100755 --- a/test/shell.t +++ b/test/shell.t @@ -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.