*/
#include "libbb.h"
+#include "common_bufsiz.h"
#include <math.h>
//usage:#define dc_trivial_usage
double stack[1];
} FIX_ALIASING;
enum { STACK_SIZE = (COMMON_BUFSIZE - offsetof(struct globals, stack)) / sizeof(double) };
-#define G (*(struct globals*)&bb_common_bufsiz1)
+#define G (*(struct globals*)bb_common_bufsiz1)
#define pointer (G.pointer )
#define base (G.base )
#define stack (G.stack )
#define INIT_G() do { \
+ setup_common_bufsiz(); \
base = 10; \
} while (0)
+static void check_under(void)
+{
+ if (pointer == 0)
+ bb_error_msg_and_die("stack underflow");
+}
+
static void push(double a)
{
if (pointer >= STACK_SIZE)
static double pop(void)
{
- if (pointer == 0)
- bb_error_msg_and_die("stack underflow");
+ check_under();
return stack[--pointer];
}
static void print_no_pop(void)
{
+ check_under();
print_base(stack[pointer-1]);
}
o = operators;
do {
- const size_t name_len = strlen(o->name);
- if (strncmp(o->name, argument, name_len) == 0) {
- argument += name_len;
+ char *after_name = is_prefixed_with(argument, o->name);
+ if (after_name) {
+ argument = after_name;
o->function();
goto next;
}