From 335d6f493f93fdd03e9b3fb15af8f5390f057ca0 Mon Sep 17 00:00:00 2001 From: Louis Rubet Date: Sat, 22 Apr 2017 22:17:51 +0200 Subject: [PATCH] #45: added command type --- src/rpn-cmd.h | 1 + src/rpn-general.h | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/rpn-cmd.h b/src/rpn-cmd.h index 84f344a..bfcc59a 100644 --- a/src/rpn-cmd.h +++ b/src/rpn-cmd.h @@ -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"}, diff --git a/src/rpn-general.h b/src/rpn-general.h index 062e52f..e0f9c56 100644 --- a/src/rpn-general.h +++ b/src/rpn-general.h @@ -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); +}