Commit 843bf15e authored by Benoit Perrot's avatar Benoit Perrot
Browse files

Index: ChangeLog

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

	* src/shell/shell.hh, src/shell.cc: Normalize string stream use.
	
parent 2d2fad33
2004-07-18 Benot Perrot <benoit@lrde.epita.fr>
* src/shell/shell.hh, src/shell.cc: Normalize string stream use.
2004-07-18 Benot Perrot <benoit@lrde.epita.fr>
* src/shell/shell.cc: Move readline wrapper to...
......
......@@ -30,8 +30,7 @@ namespace shell
// --------------------------------------------------------------------------
Shell::Shell():
vm_(true, false),
pos_(0)
vm_(true, false)
{
map_token_["run"] = RUN;
......@@ -116,28 +115,27 @@ namespace shell
Cmd*
Shell::build_cmd(const std::string &str)
{
pos_ = 0;
cmd_buf_ = str;
std::istringstream iss(str);
Cmd* command = 0;
switch (eat_word())
switch (eat_word(iss))
{
case QUIT:
return new Cmd(Cmd::cmd_quit, *this);
case RUN:
{
command = new Cmd(Cmd::cmd_run, *this);
std::string tmp = get_next_word();
std::string tmp = get_next_word(iss);
while (0 < tmp.length())
{
command->push_arg(tmp);
tmp = get_next_word();
tmp = get_next_word(iss);
}
return command;
}
case BREAK:
{
command = new Cmd(Cmd::cmd_break, *this);
std::string tmp = get_next_word();
std::string tmp = get_next_word(iss);
if (tmp.empty())
{
delete command;
......@@ -161,7 +159,7 @@ namespace shell
case LOAD:
{
command = new Cmd(Cmd::cmd_load, *this);
std::string tmp = get_next_word();
std::string tmp = get_next_word(iss);
if (tmp.empty())
{
delete command;
......@@ -173,7 +171,7 @@ namespace shell
case PRINT:
{
command = new Cmd(Cmd::cmd_print, *this);
std::string tmp = get_next_word();
std::string tmp = get_next_word(iss);
if (tmp.empty())
{
delete command;
......@@ -191,7 +189,7 @@ namespace shell
case DISPLAY:
{
command = new Cmd(Cmd::cmd_display, *this);
std::string tmp = get_next_word();
std::string tmp = get_next_word(iss);
if (tmp.empty())
{
delete command;
......@@ -209,7 +207,7 @@ namespace shell
case UNDISPLAY:
{
command = new Cmd(Cmd::cmd_undisplay, *this);
std::string tmp = get_next_word();
std::string tmp = get_next_word(iss);
if (tmp.empty())
{
delete command;
......@@ -227,7 +225,7 @@ namespace shell
case MEM:
{
command = new Cmd(Cmd::cmd_mem, *this);
std::string tmp = get_next_word();
std::string tmp = get_next_word(iss);
if (tmp.empty())
{
delete command;
......
......@@ -23,6 +23,8 @@
#ifndef SHELL_SHELL_HH
# define SHELL_SHELL_HH
# include <ctype.h>
# include <list>
# include <map>
# include <string>
......@@ -163,48 +165,46 @@ namespace shell
return true;
}
/// Skip blank characters
void skip_blank(std::istringstream &iss)
{
while (isblank(iss.peek()))
iss.get();
}
/// Get the next word in the command line.
std::string get_next_word()
std::string get_next_word(std::istringstream &iss)
{
std::stringstream strb;
while (cmd_buf_[pos_] == ' ')
++pos_;
while (cmd_buf_[pos_] && (cmd_buf_[pos_] != ' '))
strb << cmd_buf_[pos_++];
if ((strb.str().length() == 0) && (cmd_buf_[pos_] == 0))
return std::string(); // FIXME: awkward!
if (cmd_buf_[pos_] != 0)
++pos_;
return std::string(strb.str());
skip_blank(iss);
std::string res;
while (!isblank(iss.peek()))
{
char c = static_cast<char>(iss.get());
if (iss.eof())
break;
res += c;
}
return res;
}
/// Eat a word in the command line and return the corresponding keyword.
shell_token_type eat_word()
shell_token_type eat_word(std::istringstream &iss)
{
std::stringstream strb;
while (cmd_buf_[pos_] == ' ')
++pos_;
while (cmd_buf_[pos_] && (cmd_buf_[pos_] != ' '))
strb << cmd_buf_[pos_++];
if ((strb.str().length() == 0) && (cmd_buf_[pos_] == 0))
std::string cmd = get_next_word(iss);
if (cmd.empty())
return EOL;
if (map_token_.find(strb.str()) == map_token_.end())
return TERROR;
if (cmd_buf_[pos_] != 0)
++pos_;
return map_token_[strb.str()];
map_token_type::const_iterator it = map_token_.find(cmd);
if (it != map_token_.end())
return it->second;
return TERROR;
}
private:
/// virtual machine link.
vm::VirtualMachine vm_;
/// command line link.
std::string cmd_buf_;
/// position in the command line parsing.
int pos_;
/// map of token word.
map_token_type map_token_;
/// map of register.
......
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