mirror of
https://github.com/louisrubet/rpn
synced 2024-12-29 10:23:59 +01:00
Manage cmdline
This commit is contained in:
parent
2c859363f2
commit
d0947b73a0
2 changed files with 42 additions and 9 deletions
|
@ -18,6 +18,9 @@ void verbose()
|
|||
|
||||
void help()
|
||||
{
|
||||
cout<<"rpn - HP28S reverse polish notation language simulator"<<endl;
|
||||
cout<<"syntax: rpn [command]"<<endl;
|
||||
cout<<"with optional command = list of commands"<<endl;
|
||||
for(unsigned int i=0; i<sizeof(_keywords)/sizeof(_keywords[0]); i++)
|
||||
if (_keywords[i].comment.size() != 0)
|
||||
cout<<_keywords[i].name<<"\t"<<_keywords[i].comment<<endl;
|
||||
|
|
48
src/rpn.cpp
48
src/rpn.cpp
|
@ -697,24 +697,54 @@ int _tmain(int argc, _TCHAR* argv[])
|
|||
{
|
||||
heap hp;
|
||||
stack st;
|
||||
int ret = 0;
|
||||
|
||||
//
|
||||
cout << setprecision(16);
|
||||
|
||||
//
|
||||
for (;;)
|
||||
// run with interactive prompt
|
||||
if (argc == 1)
|
||||
{
|
||||
program prog;
|
||||
if (program::entry(prog) == ret_good_bye)
|
||||
break;
|
||||
else
|
||||
//
|
||||
for (;;)
|
||||
{
|
||||
if (prog.run(st, hp) == ret_good_bye)
|
||||
// make program from interactive entry
|
||||
program prog;
|
||||
if (program::entry(prog) == ret_good_bye)
|
||||
break;
|
||||
else
|
||||
program::show_stack(st);
|
||||
{
|
||||
// run it
|
||||
if (prog.run(st, hp) == ret_good_bye)
|
||||
break;
|
||||
else
|
||||
program::show_stack(st);
|
||||
}
|
||||
}
|
||||
}
|
||||
// run with cmd line arguments
|
||||
else
|
||||
{
|
||||
program prog;
|
||||
string entry;
|
||||
int i;
|
||||
|
||||
// entry
|
||||
for (i=1; i<argc; i++)
|
||||
{
|
||||
entry += argv[i];
|
||||
entry += ' ';
|
||||
}
|
||||
|
||||
// make program
|
||||
ret = program::parse(entry, prog);
|
||||
if (ret == ret_ok)
|
||||
{
|
||||
// run it
|
||||
ret = prog.run(st, hp);
|
||||
program::show_stack(st);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue