mirror of
https://github.com/louisrubet/rpn
synced 2025-01-01 18:20:06 +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()
|
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++)
|
for(unsigned int i=0; i<sizeof(_keywords)/sizeof(_keywords[0]); i++)
|
||||||
if (_keywords[i].comment.size() != 0)
|
if (_keywords[i].comment.size() != 0)
|
||||||
cout<<_keywords[i].name<<"\t"<<_keywords[i].comment<<endl;
|
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;
|
heap hp;
|
||||||
stack st;
|
stack st;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
//
|
//
|
||||||
cout << setprecision(16);
|
cout << setprecision(16);
|
||||||
|
|
||||||
//
|
// run with interactive prompt
|
||||||
for (;;)
|
if (argc == 1)
|
||||||
{
|
{
|
||||||
program prog;
|
//
|
||||||
if (program::entry(prog) == ret_good_bye)
|
for (;;)
|
||||||
break;
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
if (prog.run(st, hp) == ret_good_bye)
|
// make program from interactive entry
|
||||||
|
program prog;
|
||||||
|
if (program::entry(prog) == ret_good_bye)
|
||||||
break;
|
break;
|
||||||
else
|
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