[haiku-commits] haiku: hrev44401 - in src/apps/debugger/user_interface/cli: . src/apps/debugger

  • From: ingo_weinhold@xxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 25 Jul 2012 00:11:43 +0200 (CEST)

hrev44401 adds 1 changeset to branch 'master'
old head: b866f1fa5493c354c9425b17e6563aac540406ab
new head: aacf2782d8022d7178125948daac67533ef3e473

----------------------------------------------------------------------------

aacf278: Debugger: Switch from readline to libedit

                                    [ Ingo Weinhold <ingo_weinhold@xxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev44401
Commit:      aacf2782d8022d7178125948daac67533ef3e473
URL:         http://cgit.haiku-os.org/haiku/commit/?id=aacf278
Author:      Ingo Weinhold <ingo_weinhold@xxxxxx>
Date:        Tue Jul 24 22:11:14 2012 UTC

----------------------------------------------------------------------------

3 files changed, 55 insertions(+), 11 deletions(-)
src/apps/debugger/Jamfile                          |    8 +--
.../cli/CommandLineUserInterface.cpp               |   52 ++++++++++++++--
.../user_interface/cli/CommandLineUserInterface.h  |    6 ++

----------------------------------------------------------------------------

diff --git a/src/apps/debugger/Jamfile b/src/apps/debugger/Jamfile
index 62aa4c3..335827b 100644
--- a/src/apps/debugger/Jamfile
+++ b/src/apps/debugger/Jamfile
@@ -3,12 +3,10 @@ SubDir HAIKU_TOP src apps debugger ;
 CCFLAGS +=  -Werror ;
 C++FLAGS += -Werror ;
 
+UseHeaders [ FDirName $(HAIKU_TOP) headers compatibility bsd ] : true ;
 UsePrivateHeaders app debug interface kernel shared libroot ;
 UsePrivateSystemHeaders ;
 
-# Use gdb's readline. It would be better to use an optional build feature.
-UseHeaders [ FDirName $(HAIKU_TOP) src bin gdb ] : true ;
-
 SEARCH_SOURCE += [ FDirName $(SUBDIR) arch ] ;
 SEARCH_SOURCE += [ FDirName $(SUBDIR) arch x86 ] ;
 SEARCH_SOURCE += [ FDirName $(SUBDIR) debug_info ] ;
@@ -286,11 +284,11 @@ Application Debugger :
        libshared.a
        libexpression_parser.a
        libmapm.a
-       <gdb>libreadline.a
+       libedit.a
        libtermcap.a
 
        $(TARGET_LIBSTDC++)
-       be tracker libdebug.so
+       be tracker libbsd.so libdebug.so
 
        : Debugger.rdef
 ;
diff --git a/src/apps/debugger/user_interface/cli/CommandLineUserInterface.cpp 
b/src/apps/debugger/user_interface/cli/CommandLineUserInterface.cpp
index e45995f..a381d67 100644
--- a/src/apps/debugger/user_interface/cli/CommandLineUserInterface.cpp
+++ b/src/apps/debugger/user_interface/cli/CommandLineUserInterface.cpp
@@ -11,9 +11,6 @@
 
 #include <algorithm>
 
-#include <readline/history.h>
-#include <readline/readline.h>
-
 #include <ArgumentVector.h>
 #include <AutoDeleter.h>
 #include <Referenceable.h>
@@ -23,6 +20,13 @@
 #include "CliThreadsCommand.h"
 
 
+static const char*
+get_prompt(EditLine* editLine)
+{
+       return "debugger> ";
+}
+
+
 // #pragma mark - CommandEntry
 
 
@@ -79,6 +83,8 @@ private:
 CommandLineUserInterface::CommandLineUserInterface()
        :
        fCommands(20, true),
+       fEditLine(NULL),
+       fHistory(NULL),
        fShowSemaphore(-1),
        fShown(false),
        fTerminating(false)
@@ -90,6 +96,12 @@ CommandLineUserInterface::~CommandLineUserInterface()
 {
        if (fShowSemaphore >= 0)
                delete_sem(fShowSemaphore);
+
+       if (fEditLine != NULL)
+               el_end(fEditLine);
+
+       if (fHistory != NULL)
+               history_end(fHistory);
 }
 
 
@@ -113,6 +125,21 @@ CommandLineUserInterface::Init(Team* team, 
UserInterfaceListener* listener)
        if (fShowSemaphore < 0)
                return fShowSemaphore;
 
+       fEditLine = el_init("Debugger", stdin, stdout, stderr);
+       if (fEditLine == NULL)
+               return B_ERROR;
+
+       fHistory = history_init();
+       if (fHistory == NULL)
+               return B_ERROR;
+
+       HistEvent historyEvent;
+       history(fHistory, &historyEvent, H_SETSIZE, 100);
+
+       el_set(fEditLine, EL_HIST, &history, fHistory);
+       el_set(fEditLine, EL_EDITOR, "emacs");
+       el_set(fEditLine, EL_PROMPT, &get_prompt);
+
        return B_OK;
 }
 
@@ -141,6 +168,16 @@ CommandLineUserInterface::Terminate()
                delete_sem(fShowSemaphore);
                fShowSemaphore = -1;
        }
+
+       if (fEditLine != NULL) {
+               el_end(fEditLine);
+               fEditLine = NULL;
+       }
+
+       if (fHistory != NULL) {
+               history_end(fHistory);
+               fHistory = NULL;
+       }
 }
 
 
@@ -205,10 +242,10 @@ CommandLineUserInterface::_InputLoop()
 {
        while (!fTerminating) {
                // read a command line
-               char* line = readline("debugger> ");
+               int count;
+               const char* line = el_gets(fEditLine, &count);
                if (line == NULL)
                        break;
-               MemoryDeleter lineDeleter(line);
 
                // parse the command line
                ArgumentVector args;
@@ -231,8 +268,11 @@ CommandLineUserInterface::_InputLoop()
                if (args.ArgumentCount() == 0)
                        continue;
 
-               add_history(line);
+               // add line to history
+               HistEvent historyEvent;
+               history(fHistory, &historyEvent, H_ENTER, line);
 
+               // execute command
                _ExecuteCommand(args.ArgumentCount(), args.Arguments());
        }
 
diff --git a/src/apps/debugger/user_interface/cli/CommandLineUserInterface.h 
b/src/apps/debugger/user_interface/cli/CommandLineUserInterface.h
index f6a1c8b..fb5da34 100644
--- a/src/apps/debugger/user_interface/cli/CommandLineUserInterface.h
+++ b/src/apps/debugger/user_interface/cli/CommandLineUserInterface.h
@@ -7,6 +7,10 @@
 #define COMMAND_LINE_USER_INTERFACE_H
 
 
+#include <sys/cdefs.h>
+       // Needed in histedit.h.
+#include <histedit.h>
+
 #include <ObjectList.h>
 #include <String.h>
 
@@ -69,6 +73,8 @@ private:
 private:
                        CliContext                      fContext;
                        CommandList                     fCommands;
+                       EditLine*                       fEditLine;
+                       History*                        fHistory;
                        sem_id                          fShowSemaphore;
                        bool                            fShown;
                        bool                            fTerminating;


Other related posts:

  • » [haiku-commits] haiku: hrev44401 - in src/apps/debugger/user_interface/cli: . src/apps/debugger - ingo_weinhold