From cdc0c0a01acbe400fc6006453550237eeee15fca Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 12 Jan 2014 14:49:42 -0500 Subject: [PATCH] Readline - Made use of readline wordexp conditional upon the presence of wordexp.h, which is correct, but excludes certain BSDs. --- CMakeLists.txt | 3 +++ cmake.h.in | 3 +++ src/shell/Readline.cpp | 22 +++++++++++++++++++--- src/shell/Readline.h | 6 ++++++ 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 90662f307..f1718df39 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,7 @@ cmake_minimum_required (VERSION 2.8) set(CMAKE_LEGACY_CYGWIN_WIN32 0) # Remove when CMake >= 2.8.4 is required +include (CheckIncludeFiles) include (CheckFunctionExists) include (CheckStructHasMember) @@ -89,6 +90,8 @@ if (READLINE_FOUND) set (TASK_LIBRARIES ${TASK_LIBRARIES} ${READLINE_LIBRARIES}) endif (READLINE_FOUND) +check_include_files (wordexp.h HAVE_WORDEXP_H) + check_function_exists (timegm HAVE_TIMEGM) check_function_exists (get_current_dir_name HAVE_GET_CURRENT_DIR_NAME) diff --git a/cmake.h.in b/cmake.h.in index 5739d4fdf..984f920f8 100644 --- a/cmake.h.in +++ b/cmake.h.in @@ -67,6 +67,9 @@ /* Found uuid_unparse_lower in the uuid library */ #cmakedefine HAVE_UUID_UNPARSE_LOWER +/* Found wordexp.h in the libreadline library */ +#cmakedefine HAVE_WORDEXP_H + /* Undefine this to eliminate the execute command */ #define HAVE_EXECUTE 1 diff --git a/src/shell/Readline.cpp b/src/shell/Readline.cpp index f7bfc74fb..b7508ee2d 100644 --- a/src/shell/Readline.cpp +++ b/src/shell/Readline.cpp @@ -77,33 +77,49 @@ bool Readline::interactiveMode (const std::istream& in) //////////////////////////////////////////////////////////////////////////////// Wordexp::Wordexp (const std::string &str) { - std::string tmpStr(str); - escapeSpecialChars(tmpStr); - wordexp (tmpStr.c_str (), &_p, 0); + _input = str; + escapeSpecialChars(_input); +#ifdef HAVE_WORDEXP_H + wordexp (_input.c_str (), &_p, 0); +#endif } //////////////////////////////////////////////////////////////////////////////// Wordexp::~Wordexp () { +#ifdef HAVE_WORDEXP_H wordfree (&_p); +#endif } //////////////////////////////////////////////////////////////////////////////// int Wordexp::argc () { +#ifdef HAVE_WORDEXP_H return _p.we_wordc; +#else + return 1; +#endif } //////////////////////////////////////////////////////////////////////////////// char** Wordexp::argv () { +#ifdef HAVE_WORDEXP_H return _p.we_wordv; +#else + return (char**)_input.c_str (); +#endif } //////////////////////////////////////////////////////////////////////////////// char* Wordexp::argv (int i) { +#ifdef HAVE_WORDEXP_H return _p.we_wordv[i]; +#else + return (char*)_input.c_str (); +#endif } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/shell/Readline.h b/src/shell/Readline.h index 655afdfb7..263a67f20 100644 --- a/src/shell/Readline.h +++ b/src/shell/Readline.h @@ -30,7 +30,9 @@ #include #include +#ifdef HAVE_WORDEXP_H #include +#endif // Static class that offers a C++ API to readline C functions. class Readline @@ -61,7 +63,11 @@ public: void escapeSpecialChars(std::string& str); private: +#ifdef HAVE_WORDEXP_H wordexp_t _p; +#else + std::string _input; +#endif }; #endif