Added command edit

This commit is contained in:
Louis 2015-03-04 18:21:11 +01:00
parent f27efe58d8
commit cc009e8787
4 changed files with 22 additions and 5 deletions

View file

@ -88,6 +88,7 @@ program::keyword_t program::_keywords[] =
{ cmd_keyword, "rcl", &program::rcl, "recall a variable. ex: 'name' rcl" },
{ cmd_keyword, "purge", &program::purge, "delete a variable. ex: 'name' purge" },
{ cmd_keyword, "vars", &program::vars, "list all variables" },
{ cmd_keyword, "edit", &program::edit, "edit a vriable content" },
//PROGRAM
{ cmd_undef, "", NULL, "\nPROGRAM"},

View file

@ -54,7 +54,6 @@ void eval(void)
if (program::parse(prog_text.c_str(), prog) == ret_ok)
{
// run it
cout<<"eval: avant run: _local_heap.size = "<<_local_heap.size()<<endl;//lru
prog.run(*_stack, *_global_heap, &_local_heap);
}
}

View file

@ -33,6 +33,23 @@ void rcl(void)
ERR_CONTEXT(ret_unknown_variable);
}
void edit(void)
{
MIN_ARGUMENTS(1);
// re-write stack objet in a stream
stringstream out;
((object*)_stack->back())->show(out);
_stack->pop_back();
// edit: stuff chars using readline facility
string str = out.str();
for(int i=0;i<str.size();i++)
rl_stuff_char(str[i]);
}
// carefull : this is not a langage command
void auto_rcl(symbol* symb)
{

View file

@ -302,9 +302,9 @@ void object::show(ostream& stream)
cout << "# ";
switch(((binary*)this)->s_mode)
{
case binary::dec: cout<<std::right<<std::setw(8)<<std::dec<<((binary*)this)->_value<<" d"; break;
case binary::hex: cout<<std::right<<std::setw(16)<<std::hex<<((binary*)this)->_value<<" h"; break;
case binary::oct: cout<<std::right<<std::setw(16)<<std::oct<<((binary*)this)->_value<<" o"; break;
case binary::dec: stream<<std::right<<std::setw(8)<<std::dec<<((binary*)this)->_value<<" d"; break;
case binary::hex: stream<<std::right<<std::setw(16)<<std::hex<<((binary*)this)->_value<<" h"; break;
case binary::oct: stream<<std::right<<std::setw(16)<<std::oct<<((binary*)this)->_value<<" o"; break;
case binary::bin:
{
string mybin;
@ -315,7 +315,7 @@ void object::show(ostream& stream)
else
mybin+='0';
}
cout<<std::right<<std::setw(20)<<std::oct<<mybin<<" b";
stream<<std::right<<std::setw(20)<<std::oct<<mybin<<" b";
}
break;
}