Commit 2d2fad33 authored by Benoit Perrot's avatar Benoit Perrot
Browse files

Index: ChangeLog

from  Benoît Perrot  <benoit@lrde.epita.fr>

	* src/shell/shell.cc: Move readline wrapper to...
	* src/misc/readline.hh: This file.
	* src/misc/Makefile.am: Distribute readline.hh
parent 9bc677cd
2004-07-18 Benot Perrot <benoit@lrde.epita.fr>
* src/shell/shell.cc: Move readline wrapper to...
* src/misc/readline.hh: This file.
* src/misc/Makefile.am: Distribute readline.hh
2004-07-15 Benot Perrot <benoit@lrde.epita.fr>
* tests/runtime/address-load.s, tests/runtime/address-store.s:
......@@ -10,7 +16,7 @@
Make the MMU responsible of address translation and exception
raising.
* src/vm/cp0.hh (raise_addr_load, raise_addr_store): Add address
load and store exception.
load and store exceptions.
* src/vm/virtual_machine.hh (execute): Stop execution on fatal
exceptions.
......
......@@ -6,4 +6,5 @@ noinst_HEADERS = \
escape.hh \
has.hh \
counted_ptr.hh \
select_const.hh
select_const.hh \
readline.hh
//
// This file is part of Nolimips, a MIPS simulator with unlimited registers
// Copyright (C) 2004 Benoit Perrot <benoit@lrde.epita.fr>
//
// Nolimips is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// Nolimips is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
#include "config.h"
#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
#include <string>
#include <iostream>
namespace misc
{
/// Get a line from the user, returning false on EOF
inline 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;
getline(std::cin, line);
return !std::cin.eof();
#endif // HAVE_READLINE_READLINE_H
}
} // namespace misc
......@@ -17,54 +17,14 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
#include "config.h"
#include "misc/readline.hh"
#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;
getline(std::cin, line);
return !std::cin.eof();
#endif // HAVE_READLINE_READLINE_H
}
// --------------------------------------------------------------------------
// Shell
// --------------------------------------------------------------------------
......@@ -138,7 +98,7 @@ namespace shell
Cmd *command = new Cmd(Cmd::cmd_null, *this);
std::string line;
while ((command->execute() == 0) && shell::readline("(nolimips) ", line))
while ((command->execute() == 0) && misc::readline("(nolimips) ", line))
{
display();
......
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