[nolimips: 117] Move readline wrapper to misc/

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 Index: src/shell/shell.cc --- src/shell/shell.cc (revision 116) +++ src/shell/shell.cc (working copy) @@ -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 @@ 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(); Index: src/misc/readline.hh --- src/misc/readline.hh (revision 0) +++ src/misc/readline.hh (revision 0) @@ -0,0 +1,63 @@ +// +// 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 Index: src/misc/Makefile.am --- src/misc/Makefile.am (revision 109) +++ src/misc/Makefile.am (working copy) @@ -6,4 +6,5 @@ escape.hh \ has.hh \ counted_ptr.hh \ - select_const.hh + select_const.hh \ + readline.hh
participants (1)
-
Noe