summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <Alan.Coopersmith@sun.com>2004-05-23 20:03:49 +0000
committerAlan Coopersmith <Alan.Coopersmith@sun.com>2004-05-23 20:03:49 +0000
commitbbcc481006d4b5f4e8d1276db2220cf96a355985 (patch)
treea8ed4d72a4d49a50d493c6fc60ff1847cdcdb112
parented6ab3f1b45a5101a4cddfca754291b4523520a1 (diff)
xc/programs/xcalc/math.c
xcalc -rpn mode errors (Geoffery Coram)
-rw-r--r--math.c39
-rw-r--r--xcalc.man5
2 files changed, 31 insertions, 13 deletions
diff --git a/math.c b/math.c
index b222e4b..913e81f 100644
--- a/math.c
+++ b/math.c
@@ -1,5 +1,7 @@
-/* $XConsortium: math.c,v 1.17 91/07/25 17:51:34 rws Exp $
+/* $XConsortium: math.c,v 1.17 91/07/25 17:51:34 rws Exp $
+ * $MIT: contrib/programs/xcalc/math.c,v 3.2 1999/12/14 18:53:00 gjcoram Exp$
* $XFree86: xc/programs/xcalc/math.c,v 1.5tsi Exp $
+ * $XdotOrg: $
*
* math.c - mathematics functions for a hand calculator under X
*
@@ -14,6 +16,8 @@
* original calculator, and it still needs to be rewritten. The HP
* functionality should be separated from the TI functionality.
* Beware the HP functions: there are still errors here.
+ *
+ * Geoffrey Coram fixed most of the HP mode bugs.
*/
#include <stdio.h>
@@ -163,8 +167,8 @@ int pre_op(keynum)
#ifndef IEEE
/* cannot assign result of setjmp under ANSI C, use global instead */
-static int SignalKind;
-static int SignalCode;
+static volatile int SignalKind;
+static volatile int SignalCode;
void fail_op()
{
@@ -323,8 +327,8 @@ numeric(keynum)
case kSTO:
mem[cell] = dnum;
lift_enabled = 1;
- entered = 2;
- clrdisp++;
+ entered = 2;
+ clrdisp++;
break;
case kRCL:
PushNum(dnum);
@@ -332,13 +336,13 @@ numeric(keynum)
sprintf(dispstr, "%.8g", dnum);
lift_enabled = 1;
entered = 1;
- clrdisp = 0;
+ clrdisp++;
break;
case kSUM:
mem[cell] += dnum;
lift_enabled = 1;
- entered = 2;
- clrdisp++;
+ entered = 2;
+ clrdisp++;
break;
}
memop = kCLR;
@@ -376,6 +380,7 @@ numeric(keynum)
DrawDisplay();
if (clrdisp && keynum != kZERO)
clrdisp=0; /*no leading 0s*/
+ memop = keynum;
entered=1;
lift_enabled = 0;
}
@@ -388,10 +393,21 @@ bkspf(void)
if (! flagINV)
{
- if (entered!=1 || clrdisp)
+ if (entered!=1) {
+ clearf();
+ return;
+ }
+ if (clrdisp)
return;
- if ((int) strlen(dispstr) > 0)
+ if ((int) strlen(dispstr) > 0) {
+ if (dispstr[strlen(dispstr)-1] == '.')
+ Dpoint=0;
+#ifdef X_LOCALE
+ if (dispstr[strlen(dispstr)-1] == localeconv()->decimal_point)
+ Dpoint=0;
+#endif
dispstr[strlen(dispstr)-1] = 0;
+ }
if (strlen(dispstr) == 0) {
strcat(dispstr, "0");
clrdisp++;
@@ -412,7 +428,7 @@ decf(void)
{
flagINV=0;
if (clrdisp) {
- if (rpn)
+ if (rpn && lift_enabled)
PushNum(dnum);
strcpy(dispstr,"0");
}
@@ -822,6 +838,7 @@ oneop(int keynum)
return;
}
+ memop = keynum;
entered=2;
clrdisp=1;
flagINV=0;
diff --git a/xcalc.man b/xcalc.man
index a0bfc79..14d856e 100644
--- a/xcalc.man
+++ b/xcalc.man
@@ -1,4 +1,5 @@
.\" $XConsortium: xcalc.man,v 1.10 94/04/17 20:43:32 matt Exp $
+.\" $XdotOrg: $
.\" Copyright (c) 1994 X Consortium
.\"
.\" Permission is hereby granted, free of charge, to any person obtaining
@@ -425,8 +426,8 @@ customization file:
X(__miscmansuffix__), xrdb(1), the Athena Widget Set
.SH BUGS
.PP
-HP mode: A bug report claims that the sequence of keys 5, ENTER, <-
-should clear the display, but it doesn't.
+HP mode is not completely debugged. In particular, the stack is
+not handled properly after errors.
.SH COPYRIGHT
Copyright 1994 X Consortium
.br