#45: added command type

This commit is contained in:
Louis Rubet 2017-04-22 22:17:51 +02:00
parent c388572fa8
commit 335d6f493f
2 changed files with 15 additions and 0 deletions

View file

@ -16,6 +16,7 @@ program::keyword_t program::_keywords[] =
{ cmd_keyword, "sci", &program::sci, "scientific floating point representation. ex: 20 sci" },
{ cmd_keyword, "version", &program::rpn_version, "show rpn version" },
{ cmd_keyword, "uname", &program::rpn_uname, "show rpn complete identification string" },
{ cmd_keyword, "type", &program::type, "show first stack entry type" },
//REAL
{ cmd_undef, "", NULL, "\nREAL"},

View file

@ -172,3 +172,17 @@ void rpn_uname()
_stack->push_back(str, str->size(), cmd_string);
free(str);
}
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);
}