2014-09-24 16:55:59 +02:00
|
|
|
void test();
|
|
|
|
|
2014-02-11 11:26:28 +01:00
|
|
|
//
|
|
|
|
void nop()
|
|
|
|
{
|
2015-05-19 17:51:03 +02:00
|
|
|
// nop
|
2014-02-11 11:26:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void good_bye()
|
|
|
|
{
|
2015-05-19 17:51:03 +02:00
|
|
|
ERR_CONTEXT(ret_good_bye);
|
2014-02-11 11:26:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void verbose()
|
|
|
|
{
|
2015-05-19 17:51:03 +02:00
|
|
|
MIN_ARGUMENTS(1);
|
|
|
|
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
2017-04-19 23:31:18 +02:00
|
|
|
|
2017-04-21 13:58:44 +02:00
|
|
|
int verbose = int(((number*)_stack->pop_back())->_value);
|
2017-04-19 23:31:18 +02:00
|
|
|
g_verbose = verbose;
|
2014-02-11 11:26:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void help()
|
|
|
|
{
|
2017-04-20 23:06:49 +02:00
|
|
|
// software name
|
2015-05-19 17:51:03 +02:00
|
|
|
cout<<endl;
|
2015-03-02 21:20:56 +01:00
|
|
|
cout<<ATTR_BOLD<<uname<<ATTR_OFF<<endl;
|
2015-05-19 17:51:03 +02:00
|
|
|
cout<<endl;
|
2014-09-24 16:55:59 +02:00
|
|
|
|
2017-04-20 23:06:49 +02:00
|
|
|
// description
|
2017-04-23 15:02:46 +02:00
|
|
|
cout<<description<<endl<<endl;
|
2017-04-20 23:06:49 +02:00
|
|
|
|
2015-05-19 17:51:03 +02:00
|
|
|
// syntax
|
2017-04-20 23:06:49 +02:00
|
|
|
cout<<syntax<<endl;
|
2015-02-23 17:33:05 +01:00
|
|
|
|
|
|
|
// keywords
|
2014-02-12 11:26:26 +01:00
|
|
|
for(unsigned int i=0; i<sizeof(_keywords)/sizeof(_keywords[0]); i++)
|
2015-07-23 13:35:02 +02:00
|
|
|
{
|
2015-05-19 17:51:03 +02:00
|
|
|
if (_keywords[i].comment.size() != 0)
|
2015-07-23 13:35:02 +02:00
|
|
|
{
|
|
|
|
// titles in bold
|
|
|
|
if (_keywords[i].type==cmd_undef)
|
|
|
|
cout<<ATTR_BOLD;
|
|
|
|
// show title or keyword + comment
|
2015-05-19 17:51:03 +02:00
|
|
|
cout<<_keywords[i].name<<"\t"<<_keywords[i].comment<<endl;
|
2015-07-23 13:35:02 +02:00
|
|
|
if (_keywords[i].type==cmd_undef)
|
|
|
|
cout<<ATTR_OFF;
|
|
|
|
}
|
|
|
|
}
|
2015-05-19 17:51:03 +02:00
|
|
|
cout<<endl;
|
|
|
|
|
|
|
|
// different modes
|
|
|
|
cout<<"Current verbosity is "<<g_verbose<<endl;
|
|
|
|
|
|
|
|
cout<<"Current float mode is ";
|
|
|
|
switch(number::s_mode)
|
|
|
|
{
|
|
|
|
case number::std: cout << "'std'"; break;
|
|
|
|
case number::fix: cout << "'fix'"; break;
|
|
|
|
case number::sci: cout << "'sci'"; break;
|
|
|
|
default: cout << "unknown"; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
cout<<endl<<"Current float precision is "<<number::s_current_precision<<endl;
|
|
|
|
|
|
|
|
cout<<"Current binary mode is ";
|
|
|
|
switch(binary::s_mode)
|
|
|
|
{
|
|
|
|
case binary::dec: cout << "'dec'"; break;
|
|
|
|
case binary::hex: cout << "'hex'"; break;
|
|
|
|
case binary::oct: cout << "'oct'"; break;
|
|
|
|
case binary::bin: cout << "'bin'"; break;
|
|
|
|
default: cout << "unknown"; break;
|
|
|
|
}
|
|
|
|
cout<<endl<<endl;
|
2014-02-11 11:26:28 +01:00
|
|
|
}
|
|
|
|
|
2014-09-05 09:49:39 +02:00
|
|
|
void std()
|
|
|
|
{
|
2015-05-19 17:51:03 +02:00
|
|
|
if (stack_size()>=1)
|
|
|
|
{
|
|
|
|
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
2017-04-19 23:31:18 +02:00
|
|
|
|
2017-04-21 13:58:44 +02:00
|
|
|
int precision = int(((number*)_stack->pop_back())->_value);
|
2017-04-19 23:31:18 +02:00
|
|
|
number::s_default_precision = int(precision);
|
2015-05-19 17:51:03 +02:00
|
|
|
}
|
2017-04-18 22:53:55 +02:00
|
|
|
|
2015-05-19 17:51:03 +02:00
|
|
|
number::s_current_precision = number::s_default_precision;
|
|
|
|
number::s_mode = number::std;
|
|
|
|
|
2017-04-18 22:53:55 +02:00
|
|
|
// format for mpfr_printf
|
|
|
|
stringstream ss;
|
|
|
|
ss << number::s_current_precision;
|
|
|
|
s_mpfr_printf_format = s_mpfr_printf_format_beg + ss.str() + s_mpfr_printf_format_std;
|
2014-09-05 09:49:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void fix()
|
|
|
|
{
|
2015-05-19 17:51:03 +02:00
|
|
|
MIN_ARGUMENTS(1);
|
|
|
|
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
2014-09-05 09:49:39 +02:00
|
|
|
|
2017-04-21 13:58:44 +02:00
|
|
|
int precision = int(((number*)_stack->pop_back())->_value);
|
2017-04-19 23:31:18 +02:00
|
|
|
number::s_current_precision = int(precision);
|
|
|
|
|
2015-05-19 17:51:03 +02:00
|
|
|
number::s_mode = number::fix;
|
2014-09-06 22:31:01 +02:00
|
|
|
|
2017-04-18 22:53:55 +02:00
|
|
|
// format for mpfr_printf
|
|
|
|
stringstream ss;
|
|
|
|
ss << number::s_current_precision;
|
|
|
|
s_mpfr_printf_format = s_mpfr_printf_format_beg + ss.str() + s_mpfr_printf_format_fix;
|
2014-09-05 09:49:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void sci()
|
|
|
|
{
|
2015-05-19 17:51:03 +02:00
|
|
|
MIN_ARGUMENTS(1);
|
|
|
|
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
2014-09-05 09:49:39 +02:00
|
|
|
|
2017-04-21 13:58:44 +02:00
|
|
|
int precision = int(((number*)_stack->pop_back())->_value);
|
2017-04-19 23:31:18 +02:00
|
|
|
number::s_current_precision = int(precision);
|
|
|
|
|
2015-05-19 17:51:03 +02:00
|
|
|
number::s_mode = number::sci;
|
2014-09-06 22:31:01 +02:00
|
|
|
|
2017-04-18 22:53:55 +02:00
|
|
|
// format for mpfr_printf
|
|
|
|
stringstream ss;
|
|
|
|
ss << number::s_current_precision;
|
|
|
|
s_mpfr_printf_format = s_mpfr_printf_format_beg + ss.str() + s_mpfr_printf_format_sci;
|
2014-09-05 09:49:39 +02:00
|
|
|
}
|
2014-09-24 16:55:59 +02:00
|
|
|
|
|
|
|
void rpn_version()
|
|
|
|
{
|
2015-03-02 18:20:21 +01:00
|
|
|
int naked_entry_len;
|
|
|
|
int obj_len;
|
|
|
|
ostring* str;
|
|
|
|
|
|
|
|
// entry length without prefix / postfix
|
|
|
|
naked_entry_len = (int)strlen(version);
|
|
|
|
|
|
|
|
// total object length
|
|
|
|
obj_len = sizeof(ostring)+naked_entry_len+1;
|
|
|
|
|
|
|
|
// allocate object
|
|
|
|
str = (ostring*)malloc(obj_len);
|
|
|
|
|
|
|
|
// set it
|
|
|
|
str->set(version, naked_entry_len);
|
|
|
|
|
|
|
|
// push in stack
|
|
|
|
_stack->push_back(str, str->size(), cmd_string);
|
|
|
|
free(str);
|
2014-09-24 16:55:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void rpn_uname()
|
|
|
|
{
|
2015-03-02 18:20:21 +01:00
|
|
|
int naked_entry_len;
|
|
|
|
int obj_len;
|
|
|
|
ostring* str;
|
|
|
|
|
|
|
|
// entry length without prefix / postfix
|
|
|
|
naked_entry_len = (int)strlen(uname);
|
|
|
|
|
|
|
|
// total object length
|
|
|
|
obj_len = sizeof(ostring)+naked_entry_len+1;
|
|
|
|
|
|
|
|
// allocate object
|
|
|
|
str = (ostring*)malloc(obj_len);
|
|
|
|
|
|
|
|
// set it
|
|
|
|
str->set(uname, naked_entry_len);
|
|
|
|
|
|
|
|
// push in stack
|
|
|
|
_stack->push_back(str, str->size(), cmd_string);
|
|
|
|
free(str);
|
2014-09-24 16:55:59 +02:00
|
|
|
}
|
2017-04-22 22:17:51 +02:00
|
|
|
|
|
|
|
void type()
|
|
|
|
{
|
|
|
|
MIN_ARGUMENTS(1);
|
|
|
|
|
|
|
|
int type = _stack->seq_type(_stack->size()-1);
|
|
|
|
if (type < 0 || type >= (int)cmd_max)
|
|
|
|
type = (int)cmd_undef;
|
|
|
|
|
|
|
|
unsigned int string_size = strlen(cmd_type_string[type]);
|
|
|
|
unsigned int size = sizeof(symbol)+string_size+1;
|
|
|
|
symbol* sym = (symbol*)allocate_back(size, cmd_symbol);
|
|
|
|
sym->set(cmd_type_string[type], string_size);
|
|
|
|
}
|
2017-04-23 15:02:46 +02:00
|
|
|
|
|
|
|
void rpn_default()
|
|
|
|
{
|
|
|
|
program::apply_default();
|
|
|
|
}
|