Commit 5090881f authored by Benoit Perrot's avatar Benoit Perrot
Browse files

Index: ChangeLog

from  Benoît Perrot  <benoit@lrde.epita.fr>
        * src/shell/shell.cc:
        Use std::cin when readline library cannot be used. Add history to
        readline.
parent 363c8a4a
2004-05-01 Benot Perrot <benoit@lrde.epita.fr>
* src/shell/shell.cc:
Use std::cin when readline library cannot be used. Add history to
readline.
2004-05-01 Benot Perrot <benoit@lrde.epita.fr>
* configure.ac, config/readline.m4,
......
......@@ -2,22 +2,21 @@
(Created-By-Prcs-Version 1 3 2)
(Project-Description "")
(Project-Version mipsy 0 92)
(Parent-Version mipsy 0 91)
(Project-Version mipsy 0 93)
(Parent-Version mipsy 0 92)
(Version-Log
"Index: ChangeLog
from Benot Perrot <benoit@lrde.epita.fr>
* configure.ac, config/readline.m4,
* src/Makefile.am, src/shell/Makefile.am:
Improve readline detection and related information use.
* src/shell/shell.cc:
Use std::cin when readline library cannot be used. Add history to
readline.
")
(New-Version-Log
"")
(Checkin-Time "Sun, 02 May 2004 15:33:28 +0200")
(Checkin-Time "Sun, 02 May 2004 15:35:43 +0200")
(Checkin-Login benoit)
(Files
......@@ -25,7 +24,7 @@ from Beno
;; ./
(AUTHORS (mipsy/0_AUTHORS 1.2 644))
(COPYING (mipsy/1_COPYING 1.1 644))
(ChangeLog (mipsy/2_ChangeLog 1.86 604))
(ChangeLog (mipsy/2_ChangeLog 1.87 604))
(INSTALL (mipsy/b/12_INSTALL 1.1 604))
(Makefile.am (mipsy/3_Makefile.a 1.9 604))
(NEWS (mipsy/b/25_NEWS 1.10 604))
......@@ -103,7 +102,7 @@ from Beno
(src/shell/cmd.hh (mipsy/b/18_cmd.hh 1.3 644))
(src/shell/shell-tasks.cc (mipsy/b/19_shell-task 1.1 644))
(src/shell/shell-tasks.hh (mipsy/c/22_shell-task 1.2 644))
(src/shell/shell.cc (mipsy/c/23_shell.cc 1.3 644))
(src/shell/shell.cc (mipsy/c/23_shell.cc 1.4 644))
(src/shell/shell.hh (mipsy/c/24_shell.hh 1.3 644))
;; ./src/task/
......
......@@ -17,15 +17,58 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
#include "shell.hh"
#include "cmd.hh"
#include "config.h"
#include <readline/readline.h>
#include <readline/history.h>
#include "shell/shell.hh"
#include "shell/cmd.hh"
#ifdef HAVE_READLINE_READLINE_H
# include <readline/readline.h>
// #ifdef HAVE_READLINE_HISTORY_H
# include <readline/history.h>
// #endif HAVE_READLINE_HISTORY_H
#endif // HAVE_READLINE_READLINE_H
namespace shell
{
static bool readline(const std::string &prompt, std::string &line);
// Get a line from the user, returning false on EOF
static
bool
readline(const std::string &prompt, std::string &line)
{
#ifdef HAVE_READLINE_READLINE_H
char *str = ::readline(prompt.c_str());
if (!str)
return false;
// #ifdef HAVE_READLINE_HISTORY_H
// If the line has any text in it, save it on the history.
if (*str)
add_history(str);
// #endif // HAVE_READLINE_HISTORY_H
line = str;
free(str);
return true;
#else // !HAVE_READLINE_READLINE_H
std::cout << prompt;
std::cin >> line;
return !std::cin.eof();
#endif // HAVE_READLINE_READLINE_H
}
// --------------------------------------------------------------------------
// Shell
// --------------------------------------------------------------------------
Shell::Shell():
vm_(true, false),
pos_(0)
......@@ -92,39 +135,22 @@ namespace shell
void
Shell::run()
{
char* res = 0;
Cmd* command = new Cmd(Cmd::cmd_null, *this);
Cmd* old_command = command;
bool ndone = true;
Cmd *command = new Cmd(Cmd::cmd_null, *this);
while (ndone)
std::string line;
while ((command->execute() == 0) && shell::readline("(mipsy) ", line))
{
if (res)
//delete res;
free(res); // Readline uses malloc
display();
res = readline("(mipsy) ");
if (res && strlen(res) != 0)
if (!line.empty())
{
delete old_command;
command = build_cmd(res);
delete command;
command = build_cmd(line);
}
else
command = old_command;
ndone = command->execute() == 0;
old_command = command;
command = 0;
}
if (res)
//delete res;
free(res); // Readline uses malloc
if (command)
if (command) // FIXME: seems useless
delete command;
if (old_command)
delete old_command;
}
Cmd*
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment