Switch clang-query to use the lineeditor library.

Differential Revision: http://llvm-reviews.chandlerc.com/D2262

llvm-svn: 200603
GitOrigin-RevId: c31176da0265ee3b47c76e3a6af8273d5dd26561
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 02ca7c0..a0d5e2e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,6 +1,3 @@
-include(CheckLibraryExists)
-check_library_exists(edit el_init "" HAVE_LIBEDIT)
-
 add_subdirectory(clang-apply-replacements)
 add_subdirectory(clang-modernize)
 add_subdirectory(clang-query)
diff --git a/clang-query/CMakeLists.txt b/clang-query/CMakeLists.txt
index ae74836..0fb8c3c 100644
--- a/clang-query/CMakeLists.txt
+++ b/clang-query/CMakeLists.txt
@@ -1,5 +1,6 @@
 set(LLVM_LINK_COMPONENTS
-  Support
+  lineeditor
+  support
   )
 
 add_clang_library(clangQuery
diff --git a/clang-query/tool/ClangQuery.cpp b/clang-query/tool/ClangQuery.cpp
index bac86b0..0150d41 100644
--- a/clang-query/tool/ClangQuery.cpp
+++ b/clang-query/tool/ClangQuery.cpp
@@ -33,11 +33,11 @@
 #include "clang/Tooling/CompilationDatabase.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/OwningPtr.h"
+#include "llvm/LineEditor/LineEditor.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Signals.h"
 #include <fstream>
-#include <histedit.h>
 #include <string>
 
 using namespace clang;
@@ -61,11 +61,6 @@
                                          cl::desc("<source0> [... <sourceN>]"),
                                          cl::OneOrMore);
 
-static char *ReturnPrompt(EditLine *EL) {
-  static char Prompt[] = "clang-query> ";
-  return Prompt;
-}
-
 int main(int argc, const char **argv) {
   llvm::sys::PrintStackTraceOnErrorSignal();
   cl::ParseCommandLineOptions(argc, argv);
@@ -124,30 +119,11 @@
       }
     }
   } else {
-    History *Hist = history_init();
-    HistEvent Event;
-    history(Hist, &Event, H_SETSIZE, 100);
-
-    EditLine *EL = el_init("clang-query", stdin, stdout, stderr);
-    el_set(EL, EL_PROMPT, ReturnPrompt);
-    el_set(EL, EL_EDITOR, "emacs");
-    el_set(EL, EL_HIST, history, Hist);
-
-    int Count;
-    while (const char *Line = el_gets(EL, &Count)) {
-      if (Count == 0)
-        break;
-
-      history(Hist, &Event, H_ENTER, Line);
-
-      QueryRef Q = ParseQuery(Line);
+    LineEditor LE("clang-query");
+    while (llvm::Optional<std::string> Line = LE.readLine()) {
+      QueryRef Q = ParseQuery(*Line);
       Q->run(llvm::outs(), QS);
     }
-
-    history_end(Hist);
-    el_end(EL);
-
-    llvm::outs() << "\n";
   }
 
   llvm::DeleteContainerPointers(ASTs);