diff options
author | Kaleb Keithley <kaleb@freedesktop.org> | 2003-11-14 16:48:58 +0000 |
---|---|---|
committer | Kaleb Keithley <kaleb@freedesktop.org> | 2003-11-14 16:48:58 +0000 |
commit | 411b0e9e319550a394b0a5945543f39a5affc6a6 (patch) | |
tree | bb2e05052300714f7c46ddfa880fc05a77fb91c1 |
Initial revisionXORG-STABLE
-rw-r--r-- | XCalc-color.ad | 102 | ||||
-rw-r--r-- | XCalc.ad | 528 | ||||
-rw-r--r-- | actions.c | 551 | ||||
-rw-r--r-- | actions.h | 94 | ||||
-rw-r--r-- | math.c | 1007 | ||||
-rw-r--r-- | xcalc.c | 402 | ||||
-rw-r--r-- | xcalc.h | 123 | ||||
-rw-r--r-- | xcalc.man | 439 |
8 files changed, 3246 insertions, 0 deletions
diff --git a/XCalc-color.ad b/XCalc-color.ad new file mode 100644 index 0000000..1335596 --- /dev/null +++ b/XCalc-color.ad @@ -0,0 +1,102 @@ +#include "XCalc" + +XCalc*ti.backgroundPixmap: gray3?foreground=gray70&background=gray85 +XCalc*ti.bevel.background: gray80 +XCalc*ti.bevel.displayList: foreground gray90;lines -1,0,0,0,0,-1;lines 3,-4,-4,-4,-4,3 + +XCalc*ti.bevel.borderColor: gray60 +XCalc*ti.bevel.borderWidth: 1 +XCalc*ti.bevel.vertDistance: 4 +XCalc*ti.bevel.defaultDistance: 4 +XCalc*ti.bevel.screen.vertDistance: 4 +XCalc*ti.bevel.screen.horizDistance: 4 +XCalc*ti.bevel.screen*left: chainLeft +XCalc*ti.bevel.screen*right: chainRight +XCalc*ti.bevel.screen*top: chainTop +XCalc*ti.bevel.screen*bottom: chainBottom +XCalc*ti.bevel.screen*background: rgb:9/a/9 +XCalc*ti.bevel.screen.borderColor: gray50 +XCalc*ti.bevel.screen*LCD.foreground: gray20 +XCalc*ti.bevel.screen*INV.vertDistance: 2 + +XCalc*ti.Command.shapeStyle: roundedRectangle +XCalc*ti.Command.displayList: foreground rgb:a/b/c;segments 8,-4,-9,-4,-4,-9,-4,8;draw-arc -14,-14,-4,-4,270,90 + +XCalc*ti.Command.borderColor: rgb:8/9/a +XCalc*ti.Command.background: rgb:c/d/e +XCalc*ti.Command.foreground: gray5 + +XCalc*ti.button20.foreground: gray5 +XCalc*ti.button20.background: rgb:e/d/c +XCalc*ti.button20.displayList: foreground rgb:a/9/8;segments 8,-4,-9,-4,-4,-9,-4,8;draw-arc -14,-14,-4,-4,270,90 +XCalc*ti.button20.borderColor: rgb:9/8/7 + +XCalc*ti.button25.foreground: gray5 +XCalc*ti.button25.background: rgb:e/d/c +XCalc*ti.button25.displayList: foreground rgb:a/9/8;segments 8,-4,-9,-4,-4,-9,-4,8;draw-arc -14,-14,-4,-4,270,90 +XCalc*ti.button25.borderColor: rgb:9/8/7 + +XCalc*ti.button30.foreground: gray5 +XCalc*ti.button30.background: rgb:e/d/c +XCalc*ti.button30.displayList: foreground rgb:a/9/8;segments 8,-4,-9,-4,-4,-9,-4,8;draw-arc -14,-14,-4,-4,270,90 +XCalc*ti.button30.borderColor: rgb:9/8/7 + +XCalc*ti.button35.foreground: gray5 +XCalc*ti.button35.background: rgb:e/d/c +XCalc*ti.button35.displayList: foreground rgb:a/9/8;segments 8,-4,-9,-4,-4,-9,-4,8;draw-arc -14,-14,-4,-4,270,90 +XCalc*ti.button35.borderColor: rgb:9/8/7 + +XCalc*ti.button40.foreground: gray5 +XCalc*ti.button40.background: rgb:e/d/c +XCalc*ti.button40.displayList: foreground rgb:a/9/8;segments 8,-4,-9,-4,-4,-9,-4,8;draw-arc -14,-14,-4,-4,270,90 +XCalc*ti.button40.borderColor: rgb:9/8/7 + + + +XCalc*ti.button22.background: gray95 +XCalc*ti.button22.displayList: foreground gray75;segments 8,-4,-9,-4,-4,-9,-4,8;draw-arc -14,-14,-4,-4,270,90 +XCalc*ti.button22.borderColor: gray65 + +XCalc*ti.button23.background: gray95 +XCalc*ti.button23.displayList: foreground gray75;segments 8,-4,-9,-4,-4,-9,-4,8;draw-arc -14,-14,-4,-4,270,90 +XCalc*ti.button23.borderColor: gray65 + +XCalc*ti.button24.background: gray95 +XCalc*ti.button24.displayList: foreground gray75;segments 8,-4,-9,-4,-4,-9,-4,8;draw-arc -14,-14,-4,-4,270,90 +XCalc*ti.button24.borderColor: gray65 + +XCalc*ti.button27.background: gray95 +XCalc*ti.button27.displayList: foreground gray75;segments 8,-4,-9,-4,-4,-9,-4,8;draw-arc -14,-14,-4,-4,270,90 +XCalc*ti.button27.borderColor: gray65 + +XCalc*ti.button28.background: gray95 +XCalc*ti.button28.displayList: foreground gray75;segments 8,-4,-9,-4,-4,-9,-4,8;draw-arc -14,-14,-4,-4,270,90 +XCalc*ti.button28.borderColor: gray65 + +XCalc*ti.button29.background: gray95 +XCalc*ti.button29.displayList: foreground gray75;segments 8,-4,-9,-4,-4,-9,-4,8;draw-arc -14,-14,-4,-4,270,90 +XCalc*ti.button29.borderColor: gray65 + +XCalc*ti.button32.background: gray95 +XCalc*ti.button32.displayList: foreground gray75;segments 8,-4,-9,-4,-4,-9,-4,8;draw-arc -14,-14,-4,-4,270,90 +XCalc*ti.button32.borderColor: gray65 + +XCalc*ti.button33.background: gray95 +XCalc*ti.button33.displayList: foreground gray75;segments 8,-4,-9,-4,-4,-9,-4,8;draw-arc -14,-14,-4,-4,270,90 +XCalc*ti.button33.borderColor: gray65 + +XCalc*ti.button34.background: gray95 +XCalc*ti.button34.displayList: foreground gray75;segments 8,-4,-9,-4,-4,-9,-4,8;draw-arc -14,-14,-4,-4,270,90 +XCalc*ti.button34.borderColor: gray65 + +XCalc*ti.button37.background: gray95 +XCalc*ti.button37.displayList: foreground gray75;segments 8,-4,-9,-4,-4,-9,-4,8;draw-arc -14,-14,-4,-4,270,90 +XCalc*ti.button37.borderColor: gray65 + +XCalc*ti.button38.background: gray95 +XCalc*ti.button38.displayList: foreground gray75;segments 8,-4,-9,-4,-4,-9,-4,8;draw-arc -14,-14,-4,-4,270,90 +XCalc*ti.button38.borderColor: gray65 + +XCalc*ti.button39.background: gray95 +XCalc*ti.button39.displayList: foreground gray75;segments 8,-4,-9,-4,-4,-9,-4,8;draw-arc -14,-14,-4,-4,270,90 +XCalc*ti.button39.borderColor: gray65 diff --git a/XCalc.ad b/XCalc.ad new file mode 100644 index 0000000..0107978 --- /dev/null +++ b/XCalc.ad @@ -0,0 +1,528 @@ +! $XConsortium: XCalc.ad,v 1.13 94/03/03 19:19:32 converse Exp $ +! XCalc application class resource file + +XCalc.Title: Calculator +XCalc.IconName: Calc +XCalc.IconPixmap: calculator + +XCalc*Cursor: hand2 +XCalc*Font: 8x13 +XCalc*ShapeStyle: rectangle +XCalc*Command.horizDistance: 2 +XCalc*Command.vertDistance: 2 +XCalc*Command.width: 40 +XCalc*Command.height: 26 +XCalc*Command.internalWidth: 1 + +XCalc*bevel.background: black +XCalc*bevel.horizDistance: 4 +XCalc*bevel.vertDistance: 2 + +XCalc*bevel.screen.horizDistance: 6 +XCalc*bevel.screen.vertDistance: 2 +XCalc*bevel.screen.defaultDistance: 0 + +XCalc*bevel.screen.Label.horizDistance: 4 +XCalc*bevel.screen.Label.vertDistance: 2 +XCalc*bevel.screen.Label.internalHeight: 1 +XCalc*bevel.screen.Label.internalWidth: 1 +XCalc*bevel.screen.LCD.label: 88888888888 +XCalc*bevel.screen.LCD.fromHoriz: M +XCalc*bevel.screen.LCD.horizDistance: 4 +XCalc*bevel.screen.LCD.vertDistance: 2 +XCalc*bevel.screen.INV.fromVert: LCD +XCalc*bevel.screen.INV.vertDistance: 4 +XCalc*bevel.screen.DEG.fromHoriz: INV +XCalc*bevel.screen.DEG.fromVert: LCD +XCalc*bevel.screen.DEG.horizDistance: 1 +XCalc*bevel.screen.RAD.fromHoriz: DEG +XCalc*bevel.screen.RAD.fromVert: LCD +XCalc*bevel.screen.GRAD.fromHoriz: RAD +XCalc*bevel.screen.GRAD.fromVert: LCD +XCalc*bevel.screen.P.label: () +XCalc*bevel.screen.P.fromHoriz: GRAD +XCalc*bevel.screen.P.fromVert: LCD +XCalc*bevel.screen.P.horizDistance: 2 + +!XCalc*ti.Geometry: 171x252 +XCalc*ti.bevel.screen.LCD.width: 186 + +XCalc*ti.bevel.screen.LCD.translations: #replace\n\ + Ctrl<Key>c:quit()\n\ + Ctrl<Key>h:clear()\n\ + None<Key>0:digit(0)\n\ + None<Key>1:digit(1)\n\ + None<Key>2:digit(2)\n\ + None<Key>3:digit(3)\n\ + None<Key>4:digit(4)\n\ + None<Key>5:digit(5)\n\ + None<Key>6:digit(6)\n\ + None<Key>7:digit(7)\n\ + None<Key>8:digit(8)\n\ + None<Key>9:digit(9)\n\ + <Key>KP_0:digit(0)\n\ + <Key>KP_1:digit(1)\n\ + <Key>KP_2:digit(2)\n\ + <Key>KP_3:digit(3)\n\ + <Key>KP_4:digit(4)\n\ + <Key>KP_5:digit(5)\n\ + <Key>KP_6:digit(6)\n\ + <Key>KP_7:digit(7)\n\ + <Key>KP_8:digit(8)\n\ + <Key>KP_9:digit(9)\n\ + <Key>KP_Enter:equal()\n\ + <Key>KP_Equal:equal()\n\ + <Key>KP_Multiply:multiply()\n\ + <Key>KP_Add:add()\n\ + <Key>KP_Subtract:subtract()\n\ + <Key>KP_Decimal:decimal()\n\ + <Key>KP_Divide:divide()\n\ + <Key>KP_Tab:equal()\n\ + <Key>Clear:clear()\n\ + :<Key>.:decimal()\n\ + :<Key>+:add()\n\ + :<Key>-:subtract()\n\ + :<Key>*:multiply()\n\ + :<Key>/:divide()\n\ + :<Key>(:leftParen()\n\ + :<Key>):rightParen()\n\ + :<Key>!:factorial()\n\ + <Key>e:e()\n\ + :<Key>^:power()\n\ + <Key>p:pi()\n\ + <Key>i:inverse()\n\ + <Key>s:sine()\n\ + <Key>c:cosine()\n\ + <Key>t:tangent()\n\ + <Key>d:degree()\n\ + <Key>l:naturalLog()\n\ + :<Key>=:equal()\n\ + <Key>n:negate()\n\ + <Key>r:squareRoot()\n\ + <Key>space:clear()\n\ + <Key>q:quit()\n\ + <Key>Delete:clear()\n\ + <Key>BackSpace:clear()\n\ + <Btn1Down>,<Btn1Up>:toggle()selection()\n + +XCalc*ti.button1.label: 1/x +XCalc*ti.button1.translations: #override<Btn1Down>,<Btn1Up>:reciprocal()unset() +XCalc*ti.button2.label: x\262 +XCalc*ti.button2.translations: #override<Btn1Down>,<Btn1Up>:square()unset() +XCalc*ti.button3.font: -adobe-symbol-*-*-*-*-*-120-*-*-*-*-*-* +XCalc*ti.button3.label: \326\140 +XCalc*ti.button3.translations: #override<Btn1Down>,<Btn1Up>:squareRoot()unset() +XCalc*ti.button4.label: CE/C +XCalc*ti.button4.translations: #override<Btn1Down>,<Btn1Up>:clear()unset() +XCalc*ti.button5.label: AC +XCalc*ti.button5.translations: #override<Btn1Down>,<Btn1Up>:off()unset()\n\ + <Btn3Down>,<Btn3Up>:quit() + +XCalc*ti.button6.label: INV +XCalc*ti.button6.translations: #override<Btn1Down>,<Btn1Up>:inverse()unset() +XCalc*ti.button7.label: sin +XCalc*ti.button7.translations: #override<Btn1Down>,<Btn1Up>:sine()unset() +XCalc*ti.button8.label: cos +XCalc*ti.button8.translations: #override<Btn1Down>,<Btn1Up>:cosine()unset() +XCalc*ti.button9.label: tan +XCalc*ti.button9.translations: #override<Btn1Down>,<Btn1Up>:tangent()unset() +XCalc*ti.button10.label: DRG +XCalc*ti.button10.translations: #override<Btn1Down>,<Btn1Up>:degree()unset() + +XCalc*ti.button11.label: e +XCalc*ti.button11.translations: #override<Btn1Down>,<Btn1Up>:e()unset() +XCalc*ti.button12.label: EE +XCalc*ti.button12.translations: #override<Btn1Down>,<Btn1Up>:scientific()unset() +XCalc*ti.button13.label: log +XCalc*ti.button13.translations: #override<Btn1Down>,<Btn1Up>:logarithm()unset() +XCalc*ti.button14.label: ln +XCalc*ti.button14.translations: #override<Btn1Down>,<Btn1Up>:naturalLog()unset() +XCalc*ti.button15.label: y^x +XCalc*ti.button15.translations: #override<Btn1Down>,<Btn1Up>:power()unset() + +XCalc*ti.button16.font: -adobe-symbol-*-*-*-*-*-120-*-*-*-*-*-* +XCalc*ti.button16.label: \160 +XCalc*ti.button16.translations: #override<Btn1Down>,<Btn1Up>:pi()unset() +XCalc*ti.button17.label: x! +XCalc*ti.button17.translations: #override<Btn1Down>,<Btn1Up>:factorial()unset() +XCalc*ti.button18.label: ( +XCalc*ti.button18.translations: #override<Btn1Down>,<Btn1Up>:leftParen()unset() +XCalc*ti.button19.label: ) +XCalc*ti.button19.translations: #override<Btn1Down>,<Btn1Up>:rightParen()unset() +XCalc*ti.button20.font: -adobe-symbol-*-*-*-*-*-120-*-*-*-*-*-* +XCalc*ti.button20.label: \270 +XCalc*ti.button20.translations: #override<Btn1Down>,<Btn1Up>:divide()unset() + +XCalc*ti.button21.label: STO +XCalc*ti.button21.translations: #override<Btn1Down>,<Btn1Up>:store()unset() +XCalc*ti.button22.label: 7 +XCalc*ti.button22.translations: #override<Btn1Down>,<Btn1Up>:digit(7)unset() +XCalc*ti.button23.label: 8 +XCalc*ti.button23.translations: #override<Btn1Down>,<Btn1Up>:digit(8)unset() +XCalc*ti.button24.label: 9 +XCalc*ti.button24.translations: #override<Btn1Down>,<Btn1Up>:digit(9)unset() +XCalc*ti.button25.label: * +XCalc*ti.button25.translations: #override<Btn1Down>,<Btn1Up>:multiply()unset() + +XCalc*ti.button26.label: RCL +XCalc*ti.button26.translations: #override<Btn1Down>,<Btn1Up>:recall()unset() +XCalc*ti.button27.label: 4 +XCalc*ti.button27.translations: #override<Btn1Down>,<Btn1Up>:digit(4)unset() +XCalc*ti.button28.label: 5 +XCalc*ti.button28.translations: #override<Btn1Down>,<Btn1Up>:digit(5)unset() +XCalc*ti.button29.label: 6 +XCalc*ti.button29.translations: #override<Btn1Down>,<Btn1Up>:digit(6)unset() +XCalc*ti.button30.label: - +XCalc*ti.button30.translations: #override<Btn1Down>,<Btn1Up>:subtract()unset() + +XCalc*ti.button31.label: SUM +XCalc*ti.button31.translations: #override<Btn1Down>,<Btn1Up>:sum()unset() +XCalc*ti.button32.label: 1 +XCalc*ti.button32.translations: #override<Btn1Down>,<Btn1Up>:digit(1)unset() +XCalc*ti.button33.label: 2 +XCalc*ti.button33.translations: #override<Btn1Down>,<Btn1Up>:digit(2)unset() +XCalc*ti.button34.label: 3 +XCalc*ti.button34.translations: #override<Btn1Down>,<Btn1Up>:digit(3)unset() +XCalc*ti.button35.label: + +XCalc*ti.button35.translations: #override<Btn1Down>,<Btn1Up>:add()unset() + +XCalc*ti.button36.label: EXC +XCalc*ti.button36.translations: #override<Btn1Down>,<Btn1Up>:exchange()unset() +XCalc*ti.button37.label: 0 +XCalc*ti.button37.translations: #override<Btn1Down>,<Btn1Up>:digit(0)unset() +XCalc*ti.button38.label: . +XCalc*ti.button38.translations: #override<Btn1Down>,<Btn1Up>:decimal()unset() +XCalc*ti.button39.label: +/- +XCalc*ti.button39.translations: #override<Btn1Down>,<Btn1Up>:negate()unset() +XCalc*ti.button40.label: = +XCalc*ti.button40.translations: #override<Btn1Down>,<Btn1Up>:equal()unset() + +XCalc*ti.button1.horizDistance: 4 +XCalc*ti.button1.vertDistance: 12 +XCalc*ti.button1.fromVert: bevel +XCalc*ti.button2.fromHoriz: button1 +XCalc*ti.button2.fromVert: bevel +XCalc*ti.button2.vertDistance: 12 +XCalc*ti.button3.fromHoriz: button2 +XCalc*ti.button3.fromVert: bevel +XCalc*ti.button3.vertDistance: 12 +XCalc*ti.button4.fromHoriz: button3 +XCalc*ti.button4.fromVert: bevel +XCalc*ti.button4.vertDistance: 12 +XCalc*ti.button5.fromHoriz: button4 +XCalc*ti.button5.fromVert: bevel +XCalc*ti.button5.vertDistance: 12 + +XCalc*ti.button6.horizDistance: 4 +XCalc*ti.button6.fromVert: button1 +XCalc*ti.button7.fromHoriz: button6 +XCalc*ti.button7.fromVert: button2 +XCalc*ti.button8.fromHoriz: button7 +XCalc*ti.button8.fromVert: button3 +XCalc*ti.button9.fromHoriz: button8 +XCalc*ti.button9.fromVert: button4 +XCalc*ti.button10.fromHoriz: button9 +XCalc*ti.button10.fromVert: button5 + +XCalc*ti.button11.horizDistance: 4 +XCalc*ti.button11.fromVert: button6 +XCalc*ti.button12.fromHoriz: button11 +XCalc*ti.button12.fromVert: button7 +XCalc*ti.button13.fromHoriz: button12 +XCalc*ti.button13.fromVert: button8 +XCalc*ti.button14.fromHoriz: button13 +XCalc*ti.button14.fromVert: button9 +XCalc*ti.button15.fromHoriz: button14 +XCalc*ti.button15.fromVert: button10 + +XCalc*ti.button16.horizDistance: 4 +XCalc*ti.button16.fromVert: button11 +XCalc*ti.button17.fromHoriz: button16 +XCalc*ti.button17.fromVert: button12 +XCalc*ti.button18.fromHoriz: button17 +XCalc*ti.button18.fromVert: button13 +XCalc*ti.button19.fromHoriz: button18 +XCalc*ti.button19.fromVert: button14 +XCalc*ti.button20.fromHoriz: button19 +XCalc*ti.button20.fromVert: button15 + +XCalc*ti.button21.horizDistance: 4 +XCalc*ti.button21.fromVert: button16 +XCalc*ti.button22.fromHoriz: button21 +XCalc*ti.button22.fromVert: button17 +XCalc*ti.button23.fromHoriz: button22 +XCalc*ti.button23.fromVert: button18 +XCalc*ti.button24.fromHoriz: button23 +XCalc*ti.button24.fromVert: button19 +XCalc*ti.button25.fromHoriz: button24 +XCalc*ti.button25.fromVert: button20 + +XCalc*ti.button26.horizDistance: 4 +XCalc*ti.button26.fromVert: button21 +XCalc*ti.button27.fromHoriz: button26 +XCalc*ti.button27.fromVert: button22 +XCalc*ti.button28.fromHoriz: button27 +XCalc*ti.button28.fromVert: button23 +XCalc*ti.button29.fromHoriz: button28 +XCalc*ti.button29.fromVert: button24 +XCalc*ti.button30.fromHoriz: button29 +XCalc*ti.button30.fromVert: button25 + +XCalc*ti.button31.horizDistance: 4 +XCalc*ti.button31.fromVert: button26 +XCalc*ti.button32.fromHoriz: button31 +XCalc*ti.button32.fromVert: button27 +XCalc*ti.button33.fromHoriz: button32 +XCalc*ti.button33.fromVert: button28 +XCalc*ti.button34.fromHoriz: button33 +XCalc*ti.button34.fromVert: button29 +XCalc*ti.button35.fromHoriz: button34 +XCalc*ti.button35.fromVert: button30 + +XCalc*ti.button36.horizDistance: 4 +XCalc*ti.button36.fromVert: button31 +XCalc*ti.button37.fromHoriz: button36 +XCalc*ti.button37.fromVert: button32 +XCalc*ti.button38.fromHoriz: button37 +XCalc*ti.button38.fromVert: button33 +XCalc*ti.button39.fromHoriz: button38 +XCalc*ti.button39.fromVert: button34 +XCalc*ti.button40.fromHoriz: button39 +XCalc*ti.button40.fromVert: button35 + + +!XCalc*hp.Geometry: 336x164 +XCalc*hp.bevel.screen.LCD.width: 186 + +XCalc*hp.bevel.screen.LCD.translations: #replace\n\ + Ctrl<Key>c:quit()\n\ + Ctrl<Key>h:back()\n\ + None<Key>0:digit(0)\n\ + None<Key>1:digit(1)\n\ + None<Key>2:digit(2)\n\ + None<Key>3:digit(3)\n\ + None<Key>4:digit(4)\n\ + None<Key>5:digit(5)\n\ + None<Key>6:digit(6)\n\ + None<Key>7:digit(7)\n\ + None<Key>8:digit(8)\n\ + None<Key>9:digit(9)\n\ + <Key>KP_0:digit(0)\n\ + <Key>KP_1:digit(1)\n\ + <Key>KP_2:digit(2)\n\ + <Key>KP_3:digit(3)\n\ + <Key>KP_4:digit(4)\n\ + <Key>KP_5:digit(5)\n\ + <Key>KP_6:digit(6)\n\ + <Key>KP_7:digit(7)\n\ + <Key>KP_8:digit(8)\n\ + <Key>KP_9:digit(9)\n\ + <Key>KP_Enter:enter()\n\ + <Key>KP_Multiply:multiply()\n\ + <Key>KP_Add:add()\n\ + <Key>KP_Subtract:subtract()\n\ + <Key>KP_Decimal:decimal()\n\ + <Key>KP_Divide:divide()\n\ + :<Key>.:decimal()\n\ + :<Key>+:add()\n\ + :<Key>-:subtract()\n\ + :<Key>*:multiply()\n\ + :<Key>/:divide()\n\ + :<Key>!:factorial()\n\ + <Key>e:e()\n\ + :<Key>^:power()\n\ + <Key>p:pi()\n\ + <Key>i:inverse()\n\ + <Key>s:sine()\n\ + <Key>c:cosine()\n\ + <Key>t:tangent()\n\ + <Key>d:degree()\n\ + <Key>l:naturalLog()\n\ + <Key>n:negate()\n\ + <Key>r:squareRoot()\n\ + <Key>space:clear()\n\ + <Key>q:quit()\n\ + <Key>Delete:back()\n\ + <Key>Return:enter()\n\ + <Key>Linefeed:enter()\n\ + <Key>x:XexchangeY()\n\ + <Key>BackSpace:back()\n\ + <Btn1Down>,<Btn1Up>:toggle()selection()\n + +XCalc*hp.button1.font: -adobe-symbol-*-*-*-*-*-120-*-*-*-*-*-* +XCalc*hp.button1.label: \326\140 +XCalc*hp.button1.translations: #override<Btn1Down>,<Btn1Up>:squareRoot()unset() +XCalc*hp.button2.label: e^x +XCalc*hp.button2.translations: #override<Btn1Down>,<Btn1Up>:epower()unset() +XCalc*hp.button3.label: 10^x +XCalc*hp.button3.translations: #override<Btn1Down>,<Btn1Up>:tenpower()unset() +XCalc*hp.button4.label: y^x +XCalc*hp.button4.translations: #override<Btn1Down>,<Btn1Up>:power()unset() +XCalc*hp.button5.label: 1/x +XCalc*hp.button5.translations: #override<Btn1Down>,<Btn1Up>:reciprocal()unset() +XCalc*hp.button6.label: CHS +XCalc*hp.button6.translations: #override<Btn1Down>,<Btn1Up>:negate()unset() +XCalc*hp.button7.label: 7 +XCalc*hp.button7.translations: #override<Btn1Down>,<Btn1Up>:digit(7)unset() +XCalc*hp.button8.label: 8 +XCalc*hp.button8.translations: #override<Btn1Down>,<Btn1Up>:digit(8)unset() +XCalc*hp.button9.label: 9 +XCalc*hp.button9.translations: #override<Btn1Down>,<Btn1Up>:digit(9)unset() +XCalc*hp.button10.font: -adobe-symbol-*-*-*-*-*-120-*-*-*-*-*-* +XCalc*hp.button10.label: \270 +XCalc*hp.button10.translations: #override<Btn1Down>,<Btn1Up>:divide()unset() + +XCalc*hp.button11.label: x! +XCalc*hp.button11.translations: #override<Btn1Down>,<Btn1Up>:factorial()unset() +XCalc*hp.button12.font: -adobe-symbol-*-*-*-*-*-120-*-*-*-*-*-* +XCalc*hp.button12.label: \160 +XCalc*hp.button12.translations: #override<Btn1Down>,<Btn1Up>:pi()unset() +XCalc*hp.button13.label: sin +XCalc*hp.button13.translations: #override<Btn1Down>,<Btn1Up>:sine()unset() +XCalc*hp.button14.label: cos +XCalc*hp.button14.translations: #override<Btn1Down>,<Btn1Up>:cosine()unset() +XCalc*hp.button15.label: tan +XCalc*hp.button15.translations: #override<Btn1Down>,<Btn1Up>:tangent()unset() +XCalc*hp.button16.label: EEX +XCalc*hp.button16.translations: #override<Btn1Down>,<Btn1Up>:scientific()unset() +XCalc*hp.button17.label: 4 +XCalc*hp.button17.translations: #override<Btn1Down>,<Btn1Up>:digit(4)unset() +XCalc*hp.button18.label: 5 +XCalc*hp.button18.translations: #override<Btn1Down>,<Btn1Up>:digit(5)unset() +XCalc*hp.button19.label: 6 +XCalc*hp.button19.translations: #override<Btn1Down>,<Btn1Up>:digit(6)unset() +XCalc*hp.button20.label: * +XCalc*hp.button20.translations: #override<Btn1Down>,<Btn1Up>:multiply()unset() + +XCalc*hp.button21.mappedWhenManaged: False +XCalc*hp.button22.mappedWhenManaged: False +XCalc*hp.button23.label: Rv +XCalc*hp.button23.translations: #override<Btn1Down>,<Btn1Up>:roll()unset() +XCalc*hp.button24.label: x:y +XCalc*hp.button24.translations: #override<Btn1Down>,<Btn1Up>:XexchangeY()unset() +XCalc*hp.button25.label: <- +XCalc*hp.button25.translations: #override<Btn1Down>,<Btn1Up>:back()unset() +XCalc*hp.button26.label: E\nN\nT\nE\nR +XCalc*hp.button26.translations: #override<Btn1Down>,<Btn1Up>:enter()unset() +XCalc*hp.button27.label: 1 +XCalc*hp.button27.translations: #override<Btn1Down>,<Btn1Up>:digit(1)unset() +XCalc*hp.button28.label: 2 +XCalc*hp.button28.translations: #override<Btn1Down>,<Btn1Up>:digit(2)unset() +XCalc*hp.button29.label: 3 +XCalc*hp.button29.translations: #override<Btn1Down>,<Btn1Up>:digit(3)unset() +XCalc*hp.button30.label: - +XCalc*hp.button30.translations: #override<Btn1Down>,<Btn1Up>:subtract()unset() + +XCalc*hp.button31.label: ON +XCalc*hp.button31.translations: #override<Btn1Down>,<Btn1Up>:off()unset()\n\ + <Btn3Down>,<Btn3Up>:quit() +XCalc*hp.button32.label: DRG +XCalc*hp.button32.translations: #override<Btn1Down>,<Btn1Up>:degree()unset() +XCalc*hp.button33.label: INV +XCalc*hp.button33.translations: #override<Btn1Down>,<Btn1Up>:inverse()unset() +XCalc*hp.button34.label: STO +XCalc*hp.button34.translations: #override<Btn1Down>,<Btn1Up>:store()unset() +XCalc*hp.button35.label: RCL +XCalc*hp.button35.translations: #override<Btn1Down>,<Btn1Up>:recall()unset() +XCalc*hp.button36.label: 0 +XCalc*hp.button36.translations: #override<Btn1Down>,<Btn1Up>:digit(0)unset() +XCalc*hp.button37.label: . +XCalc*hp.button37.translations: #override<Btn1Down>,<Btn1Up>:decimal()unset() +XCalc*hp.button38.label: SUM +XCalc*hp.button38.translations: #override<Btn1Down>,<Btn1Up>:sum()unset() +XCalc*hp.button39.label: + +XCalc*hp.button39.translations: #override<Btn1Down>,<Btn1Up>:add()unset() + +XCalc*hp.button1.horizDistance: 4 +XCalc*hp.button1.vertDistance: 12 +XCalc*hp.button1.fromVert: bevel +XCalc*hp.button2.fromHoriz: button1 +XCalc*hp.button2.fromVert: bevel +XCalc*hp.button2.vertDistance: 12 +XCalc*hp.button3.fromHoriz: button2 +XCalc*hp.button3.fromVert: bevel +XCalc*hp.button3.vertDistance: 12 +XCalc*hp.button4.fromHoriz: button3 +XCalc*hp.button4.fromVert: bevel +XCalc*hp.button4.vertDistance: 12 +XCalc*hp.button5.fromHoriz: button4 +XCalc*hp.button5.fromVert: bevel +XCalc*hp.button5.vertDistance: 12 +XCalc*hp.button6.fromHoriz: button5 +XCalc*hp.button6.fromVert: bevel +XCalc*hp.button6.vertDistance: 12 +XCalc*hp.button7.fromHoriz: button6 +XCalc*hp.button7.fromVert: bevel +XCalc*hp.button7.vertDistance: 12 +XCalc*hp.button8.fromHoriz: button7 +XCalc*hp.button8.fromVert: bevel +XCalc*hp.button8.vertDistance: 12 +XCalc*hp.button9.fromHoriz: button8 +XCalc*hp.button9.fromVert: bevel +XCalc*hp.button9.vertDistance: 12 +XCalc*hp.button10.fromHoriz: button9 +XCalc*hp.button10.fromVert: bevel +XCalc*hp.button10.vertDistance: 12 + +XCalc*hp.button11.horizDistance: 4 +XCalc*hp.button11.fromVert: button1 +XCalc*hp.button12.fromHoriz: button11 +XCalc*hp.button12.fromVert: button2 +XCalc*hp.button13.fromHoriz: button12 +XCalc*hp.button13.fromVert: button3 +XCalc*hp.button14.fromHoriz: button13 +XCalc*hp.button14.fromVert: button4 +XCalc*hp.button15.fromHoriz: button14 +XCalc*hp.button15.fromVert: button5 +XCalc*hp.button16.fromHoriz: button15 +XCalc*hp.button16.fromVert: button6 +XCalc*hp.button17.fromHoriz: button16 +XCalc*hp.button17.fromVert: button7 +XCalc*hp.button18.fromHoriz: button17 +XCalc*hp.button18.fromVert: button8 +XCalc*hp.button19.fromHoriz: button18 +XCalc*hp.button19.fromVert: button9 +XCalc*hp.button20.fromHoriz: button19 +XCalc*hp.button20.fromVert: button10 + +XCalc*hp.button21.horizDistance: 4 +XCalc*hp.button21.fromVert: button11 +XCalc*hp.button22.fromHoriz: button21 +XCalc*hp.button22.fromVert: button12 +XCalc*hp.button23.fromHoriz: button22 +XCalc*hp.button23.fromVert: button13 +XCalc*hp.button24.fromHoriz: button23 +XCalc*hp.button24.fromVert: button14 +XCalc*hp.button25.fromHoriz: button24 +XCalc*hp.button25.fromVert: button15 +XCalc*hp.button26.fromHoriz: button25 +XCalc*hp.button26.fromVert: button16 +XCalc*hp.button26.font: 6x12 +XCalc*hp.button26.height: 56 +XCalc*hp.button27.fromHoriz: button26 +XCalc*hp.button27.fromVert: button17 +XCalc*hp.button28.fromHoriz: button27 +XCalc*hp.button28.fromVert: button18 +XCalc*hp.button29.fromHoriz: button28 +XCalc*hp.button29.fromVert: button19 +XCalc*hp.button30.fromHoriz: button29 +XCalc*hp.button30.fromVert: button20 + +XCalc*hp.button31.horizDistance: 4 +XCalc*hp.button31.fromVert: button21 +XCalc*hp.button32.fromHoriz: button31 +XCalc*hp.button32.fromVert: button22 +XCalc*hp.button33.fromHoriz: button32 +XCalc*hp.button33.fromVert: button23 +XCalc*hp.button34.fromHoriz: button33 +XCalc*hp.button34.fromVert: button24 +XCalc*hp.button35.fromHoriz: button34 +XCalc*hp.button35.fromVert: button25 +XCalc*hp.button36.fromHoriz: button26 +XCalc*hp.button36.fromVert: button27 +XCalc*hp.button37.fromHoriz: button36 +XCalc*hp.button37.fromVert: button28 +XCalc*hp.button38.fromHoriz: button37 +XCalc*hp.button38.fromVert: button29 +XCalc*hp.button39.fromHoriz: button38 +XCalc*hp.button39.fromVert: button30 diff --git a/actions.c b/actions.c new file mode 100644 index 0000000..37c5736 --- /dev/null +++ b/actions.c @@ -0,0 +1,551 @@ +/* $XConsortium: actions.c,v 1.9 94/04/17 20:43:30 converse Exp $ */ +/* + +Copyright (c) 1989 X Consortium + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of the X Consortium shall +not be used in advertising or otherwise to promote the sale, use or +other dealings in this Software without prior written authorization +from the X Consortium. + +*/ + +/* + * actions.c - externally available procedures for xcalc + * + * Author: Donna Converse, MIT X Consortium + */ + +#include <X11/Intrinsic.h> +#include <setjmp.h> +#include "xcalc.h" +extern int rpn; +extern Atom wm_delete_window; +extern int pre_op(); +extern void post_op(), Quit(), ringbell(), do_select(); + +#ifndef IEEE +extern jmp_buf env; +extern void fail_op(); +#define XCALC_PRE_OP(keynum) { if (pre_op(keynum)) return; \ + if (setjmp (env)) {fail_op(); return;}} +#else +#define XCALC_PRE_OP(keynum) if (pre_op(keynum)) return; +#endif + +/*ARGSUSED*/ +void add(w, e, vector, count) + Widget w; + XEvent *e; + String *vector; + Cardinal *count; +{ + XCALC_PRE_OP(kADD); + rpn ? twof(kADD) : twoop(kADD); + post_op(); +} + +/*ARGSUSED*/ +void back(w, e, vector, count) + Widget w; + XEvent *e; + String *vector; + Cardinal *count; +{ + XCALC_PRE_OP(kBKSP); + bkspf(); + post_op(); +} + +/*ARGSUSED*/ +void bell(w, e, vector, count) + Widget w; + XEvent *e; + String *vector; + Cardinal *count; +{ + ringbell(); +} + +/*ARGSUSED*/ +void clearit(w, e, vector, count) + Widget w; + XEvent *e; + String *vector; + Cardinal *count; +{ + XCALC_PRE_OP(kCLR); + clearf(); + post_op(); +} + +/*ARGSUSED*/ +void cosine(w, e, vector, count) + Widget w; + XEvent *e; + String *vector; + Cardinal *count; +{ + XCALC_PRE_OP(kCOS); + oneop(kCOS); + post_op(); +} + +/*ARGSUSED*/ +void decimal(w, e, vector, count) + Widget w; + XEvent *e; + String *vector; + Cardinal *count; +{ + XCALC_PRE_OP(kDEC); + decf(); + post_op(); +} + +/*ARGSUSED*/ +void degree(w, e, vector, count) + Widget w; + XEvent *e; + String *vector; + Cardinal *count; +{ + XCALC_PRE_OP(kDRG); + drgf(); + post_op(); +} + +/*ARGSUSED*/ +void digit(w, e, vector, count) + Widget w; + XEvent *e; + String *vector; + Cardinal *count; +{ + switch (vector[0][0]) + { + case '1': XCALC_PRE_OP(kONE); numeric(kONE); break; + case '2': XCALC_PRE_OP(kTWO); numeric(kTWO); break; + case '3': XCALC_PRE_OP(kTHREE); numeric(kTHREE); break; + case '4': XCALC_PRE_OP(kFOUR); numeric(kFOUR); break; + case '5': XCALC_PRE_OP(kFIVE); numeric(kFIVE); break; + case '6': XCALC_PRE_OP(kSIX); numeric(kSIX); break; + case '7': XCALC_PRE_OP(kSEVEN); numeric(kSEVEN); break; + case '8': XCALC_PRE_OP(kEIGHT); numeric(kEIGHT); break; + case '9': XCALC_PRE_OP(kNINE); numeric(kNINE); break; + case '0': XCALC_PRE_OP(kZERO); numeric(kZERO); break; + } + post_op(); +} + +/*ARGSUSED*/ +void divide(w, e, vector, count) + Widget w; + XEvent *e; + String *vector; + Cardinal *count; +{ + XCALC_PRE_OP(kDIV); + rpn ? twof(kDIV) : twoop(kDIV); + post_op(); +} + +/*ARGSUSED*/ +void e(w, ev, vector, count) + Widget w; + XEvent *ev; + String *vector; + Cardinal *count; +{ + XCALC_PRE_OP(kE); + oneop(kE); + post_op(); +} + +/*ARGSUSED*/ +void enter(w, e, vector, count) + Widget w; + XEvent *e; + String *vector; + Cardinal *count; +{ + XCALC_PRE_OP(kENTR); + entrf(); + post_op(); +} + +/*ARGSUSED*/ +void epower(w, e, vector, count) + Widget w; + XEvent *e; + String *vector; + Cardinal *count; +{ + XCALC_PRE_OP(kEXP); + oneop(kEXP); + post_op(); +} + +/*ARGSUSED*/ +void equal(w, e, vector, count) + Widget w; + XEvent *e; + String *vector; + Cardinal *count; +{ + XCALC_PRE_OP(kEQU); + equf(); + post_op(); +} + +/*ARGSUSED*/ +void exchange(w, e, vector, count) + Widget w; + XEvent *e; + String *vector; + Cardinal *count; +{ + XCALC_PRE_OP(kEXC); + oneop(kEXC); + post_op(); +} + +/*ARGSUSED*/ +void factorial(w, e, vector, count) + Widget w; + XEvent *e; + String *vector; + Cardinal *count; +{ + XCALC_PRE_OP(kFACT); + oneop(kFACT); + post_op(); +} + +/*ARGSUSED*/ +void inverse(w, e, vector, count) + Widget w; + XEvent *e; + String *vector; + Cardinal *count; +{ + XCALC_PRE_OP(kINV); + invf(); + post_op(); +} + +/*ARGSUSED*/ +void leftParen(w, e, vector, count) + Widget w; + XEvent *e; + String *vector; + Cardinal *count; +{ + XCALC_PRE_OP(kLPAR); + lparf(); + post_op(); +} + +/*ARGSUSED*/ +void logarithm(w, e, vector, count) + Widget w; + XEvent *e; + String *vector; + Cardinal *count; +{ + XCALC_PRE_OP(kLOG); + oneop(kLOG); + post_op(); +} + +/*ARGSUSED*/ +void multiply(w, e, vector, count) + Widget w; + XEvent *e; + String *vector; + Cardinal *count; +{ + XCALC_PRE_OP(kMUL); + rpn ? twof(kMUL) : twoop(kMUL); + post_op(); +} + +/*ARGSUSED*/ +void naturalLog(w, e, vector, count) + Widget w; + XEvent *e; + String *vector; + Cardinal *count; +{ + XCALC_PRE_OP(kLN); + oneop(kLN); + post_op(); +} + +/*ARGSUSED*/ +void negate(w, e, vector, count) + Widget w; + XEvent *e; + String *vector; + Cardinal *count; +{ + XCALC_PRE_OP(kNEG); + negf(); + post_op(); +} + +/*ARGSUSED*/ +void nop(w, e, vector, count) + Widget w; + XEvent *e; + String *vector; + Cardinal *count; +{ + ringbell(); +} + +/*ARGSUSED*/ +void off(w, e, vector, count) + Widget w; + XEvent *e; + String *vector; + Cardinal *count; +{ + XCALC_PRE_OP(kOFF); + offf(); + post_op(); +} + +/*ARGSUSED*/ +void pi(w, e, vector, count) + Widget w; + XEvent *e; + String *vector; + Cardinal *count; +{ + XCALC_PRE_OP(kPI); + oneop(kPI); + post_op(); +} + +/*ARGSUSED*/ +void power(w, e, vector, count) + Widget w; + XEvent *e; + String *vector; + Cardinal *count; +{ + XCALC_PRE_OP(kPOW); + rpn ? twof(kPOW) : twoop(kPOW); + post_op(); +} + +/*ARGSUSED*/ +void quit(w, e, vector, count) + Widget w; + XEvent *e; + String *vector; + Cardinal *count; +{ + if (e->type == ClientMessage && e->xclient.data.l[0] != wm_delete_window) + ringbell(); + else + Quit(); +} + +/*ARGSUSED*/ +void recall(w, e, vector, count) + Widget w; + XEvent *e; + String *vector; + Cardinal *count; +{ + XCALC_PRE_OP(kRCL); + rpn ? memf(kRCL) : oneop(kRCL); + post_op(); +} + +/*ARGSUSED*/ +void reciprocal(w, e, vector, count) + Widget w; + XEvent *e; + String *vector; + Cardinal *count; +{ + XCALC_PRE_OP(kRECIP); + oneop(kRECIP); + post_op(); +} + +/*ARGSUSED*/ +void rightParen(w, e, vector, count) + Widget w; + XEvent *e; + String *vector; + Cardinal *count; +{ + XCALC_PRE_OP(kRPAR); + rparf(); + post_op(); +} + +/*ARGSUSED*/ +void roll(w, e, vector, count) + Widget w; + XEvent *e; + String *vector; + Cardinal *count; +{ + XCALC_PRE_OP(kROLL); + rollf(); + post_op(); +} + +/*ARGSUSED*/ +void scientific(w, e, vector, count) + Widget w; + XEvent *e; + String *vector; + Cardinal *count; +{ + XCALC_PRE_OP(kEE); + eef(); + post_op(); +} + +/*ARGSUSED*/ +void selection(w, e, vector, count) + Widget w; + XEvent *e; + String *vector; + Cardinal *count; +{ + do_select(((XButtonReleasedEvent *)e)->time); +} + +/*ARGSUSED*/ +void sine(w, e, vector, count) + Widget w; + XEvent *e; + String *vector; + Cardinal *count; +{ + XCALC_PRE_OP(kSIN); + oneop(kSIN); + post_op(); +} + +/*ARGSUSED*/ +void square(w, e, vector, count) + Widget w; + XEvent *e; + String *vector; + Cardinal *count; +{ + XCALC_PRE_OP(kSQR); + oneop(kSQR); + post_op(); +} + +/*ARGSUSED*/ +void squareRoot(w, e, vector, count) + Widget w; + XEvent *e; + String *vector; + Cardinal *count; +{ + XCALC_PRE_OP(kSQRT); + oneop(kSQRT); + post_op(); +} + +/*ARGSUSED*/ +void store(w, e, vector, count) + Widget w; + XEvent *e; + String *vector; + Cardinal *count; +{ + XCALC_PRE_OP(kSTO); + rpn ? memf(kSTO) : oneop(kSTO); + post_op(); +} + +/*ARGSUSED*/ +void subtract(w, e, vector, count) + Widget w; + XEvent *e; + String *vector; + Cardinal *count; +{ + XCALC_PRE_OP(kSUB); + rpn ? twof(kSUB) : twoop(kSUB); + post_op(); +} + +/*ARGSUSED*/ +void sum(w, e, vector, count) + Widget w; + XEvent *e; + String *vector; + Cardinal *count; +{ + XCALC_PRE_OP(kSUM); + rpn ? memf(kSUM) : oneop(kSUM); + post_op(); +} + +/*ARGSUSED*/ +void tangent(w, e, vector, count) + Widget w; + XEvent *e; + String *vector; + Cardinal *count; +{ + XCALC_PRE_OP(kTAN); + oneop(kTAN); + post_op(); +} + +/*ARGSUSED*/ +void tenpower(w, e, vector, count) + Widget w; + XEvent *e; + String *vector; + Cardinal *count; +{ + XCALC_PRE_OP(k10X); + oneop(k10X); + post_op(); +} + +/*ARGSUSED*/ +void XexchangeY(w, e, vector, count) + Widget w; + XEvent *e; + String *vector; + Cardinal *count; +{ + XCALC_PRE_OP(kXXY); + twof(kXXY); + post_op(); +} diff --git a/actions.h b/actions.h new file mode 100644 index 0000000..69f1983 --- /dev/null +++ b/actions.h @@ -0,0 +1,94 @@ +/* $XConsortium: actions.h,v 1.6 94/04/17 20:43:31 rws Exp $ */ +/* + +Copyright (c) 1989 X Consortium + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of the X Consortium shall +not be used in advertising or otherwise to promote the sale, use or +other dealings in this Software without prior written authorization +from the X Consortium. + +*/ + +/* + * actions.h - action table declaring externally available procedures for xcalc + * + * Author: Donna Converse, MIT X Consortium + */ + +extern void + add(), back(), bell(), clearit(), cosine(), decimal(), + degree(), digit(), divide(), e(), enter(), epower(), equal(), + exchange(), factorial(), + inverse(), leftParen(), logarithm(), multiply(), naturalLog(), + negate(), nop(), off(), pi(), power(), quit(), recall(), + reciprocal(), rightParen(), roll(), scientific(), selection(), sine(), + square(), squareRoot(), store(), subtract(), sum(), + tangent(), tenpower(), XexchangeY(); + +/* + * calculator action table + */ + +XtActionsRec Actions[] = { +{"add", add}, /* addition */ +{"back", back}, /* HP-specific backspace */ +{"bell", bell}, /* ring bell */ +{"clear", clearit}, /* TI-specific clear calculator state */ +{"cosine", cosine}, /* trigonometric function cosine */ +{"decimal", decimal}, /* decimal point */ +{"degree", degree}, /* degree, radian, grad switch */ +{"digit", digit}, /* numeric key */ +{"divide", divide}, /* division */ +{"e", e}, /* the natural number e */ +{"enter", enter}, /* HP-specific enter */ +{"epower", epower}, /* e raised to a power */ +{"equal", equal}, /* TI-specific = */ +{"exchange", exchange}, /* TI-specific exchange memory and display */ +{"factorial", factorial}, /* factorial function */ +{"inverse", inverse}, /* inverse */ +{"leftParen", leftParen}, /* TI-specific left parenthesis */ +{"logarithm", logarithm}, /* logarithm base 10 */ +{"multiply", multiply}, /* multiplication */ +{"naturalLog", naturalLog}, /* natural logarithm base e */ +{"negate", negate}, /* change sign */ +{"nop", nop}, /* no operation, rings bell */ +{"off", off}, /* clear state */ +{"pi", pi}, /* the number pi */ +{"power", power}, /* raise to an arbitrary power */ +{"quit", quit}, /* quit */ +{"recall", recall}, /* memory recall */ +{"reciprocal", reciprocal}, /* reciprocal function */ +{"rightParen", rightParen}, /* TI-specific left parenthesis */ +{"roll", roll}, /* HP-specific roll stack */ +{"scientific", scientific}, /* scientfic notation (EE) */ +{"selection", selection}, /* copy selection */ +{"sine", sine}, /* trigonometric function sine */ +{"square", square}, /* square */ +{"squareRoot", squareRoot}, /* square root */ +{"store", store}, /* memory store */ +{"subtract", subtract}, /* subtraction */ +{"sum", sum}, /* memory summation */ +{"tangent", tangent}, /* trigonometric function tangent */ +{"tenpower", tenpower}, /* 10 raised to to an arbitrary power */ +{"XexchangeY", XexchangeY} /* HP-specific exchange X and Y registers */ +}; @@ -0,0 +1,1007 @@ +/* $XConsortium: math.c,v 1.17 91/07/25 17:51:34 rws Exp $ + * $XFree86: xc/programs/xcalc/math.c,v 1.5 2001/10/28 03:34:26 tsi Exp $ + * + * math.c - mathematics functions for a hand calculator under X + * + * Author: John H. Bradley, University of Pennsylvania + * (bradley@cis.upenn.edu) + * March, 1987 + * + * RPN mode added and port to X11 by Mark Rosenstein, MIT Project Athena + * + * Modified to be a client of the Xt toolkit and the Athena widget set by + * Donna Converse, MIT X Consortium. This is all that remains of the + * 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. + */ + +#include <stdio.h> +#include <X11/Xos.h> +#include <math.h> +#include <signal.h> +#if !defined(IEEE) && defined(SVR4) +#include <siginfo.h> +#endif +#include <setjmp.h> +#include "xcalc.h" +#include <errno.h> +#include <X11/Xlocale.h> + +#ifdef _CRAY /* kludge around Cray STDC compiler */ +double (*log_p)() = log; +#define log ((*log_p)) +double (*exp_p)() = exp; +#define exp ((*exp_p)) +double (*sqrt_p)() = sqrt; +#define sqrt ((*sqrt_p)) +double (*log10_p)() = log10; +#define log10 ((*log10_p)) +double (*atan2_p)() = atan2; +#define atan2 ((*atan2_p)) +double (*asin_p)() = asin; +#define asin ((*asin_p)) +double (*acos_p)() = acos; +#define acos ((*acos_p)) +double (*atan_p)() = atan; +#define atan ((*atan_p)) +double (*sin_p)() = sin; +#define sin ((*sin_p)) +double (*cos_p)() = cos; +#define cos ((*cos_p)) +double (*tan_p)() = tan; +#define tan ((*tan_p)) +double (*pow_p)() = pow; +#define pow ((*pow_p)) +#endif /* _CRAY */ + +#ifndef PI /* sometimes defined in math.h */ +#define PI 3.14159265358979 +#endif +#define E 2.71828182845904 +#define MAXDISP 11 +#define DEG 0 /* DRG mode. used for trig calculations */ +#define RAD 1 +#define GRAD 2 +#define min(a,b) ((a) < (b) ? (a) : (b)) +#define max(a,b) ((a) > (b) ? (a) : (b)) +#define True 1 +#define False 0 + +extern int rpn; +extern char dispstr[]; +extern void draw(); +extern void ringbell(); +extern void setflag(); +extern void Quit(); + +#ifndef IEEE + jmp_buf env; +#endif + + +/* This section is all of the state machine that implements the calculator + * functions. Much of it is shared between the infix and rpn modes. + */ + +int flagINV, flagPAREN, flagM, drgmode; /* display flags */ + +static double drg2rad=PI/180.0; /* Conversion factors for trig funcs */ +static double rad2drg=180.0/PI; +static int entered=1; /* true if display contains a valid number. + if==2, then use 'dnum', rather than the string + stored in the display. (for accuracy) + if==3, then error occurred, only CLR & AC work */ +/* entered seems to be overloaded - dmc */ +static int lift_enabled = 0; /* for rpn mode only */ + +static int CLR =0; /* CLR clears display. if 1, clears acc, also */ +static int OFF =0; /* once clears mem, twice quits */ +static int Dpoint=0; /* to prevent using decimal pt twice in a # */ +static int clrdisp=1; /* if true clears display before entering # */ +static int accset =0; +static int lastop =kCLR; +static int memop =kCLR; +static int exponent=0; +static double acc =0.0; +static double dnum=0.0; +#define XCALC_MEMORY 10 +static double mem[XCALC_MEMORY] = { 0.0 }; + +static void DrawDisplay(void); +static void PushOp(int op); +static int PopOp(void); +static int isopempty(void); +#ifdef DEBUG +static void showstack(char *string); +#endif +static void PushNum(double num); +static double PopNum(void); +static void RollNum(int dir); +static void ClearStacks(void); +static int priority(int op); + +/* + * The following is to deal with the unfortunate assumption that if errno + * is non-zero then an error has occurred. On some systems (e.g. Ultrix), + * sscanf will call lower level routines that will set errno. + */ + +static void +parse_double (src, fmt, dp) + char *src; + char *fmt; + double *dp; +{ + int olderrno = errno; + + (void) sscanf (src, fmt, dp); + errno = olderrno; + return; +} + + +/*********************************/ +int pre_op(keynum) + int keynum; +{ + if (keynum==-1) return(0); + + errno = 0; /* for non-IEEE machines */ + + if ( (entered==3) && !(keynum==kCLR || keynum==kOFF)) { + if (rpn) { + clrdisp++; + } else { + ringbell(); + return(1); /* the intent was probably not to do the operation */ + } + } + + if (keynum != kCLR) CLR=0; + if (keynum != kOFF) OFF=0; + return(0); +} + +#ifndef IEEE + +/* cannot assign result of setjmp under ANSI C, use global instead */ +static int SignalKind; +static int SignalCode; + +void fail_op() +{ + if (SignalKind == SIGFPE) + switch (SignalCode) { +#ifdef SVR4 + case FPE_INTDIV: /* integer divide by zero */ + case FPE_FLTDIV: /* floating point divide by zero */ + strcpy(dispstr, "divide by 0"); + break; + case FPE_INTOVF: /* integer overflow */ + case FPE_FLTOVF: /* floating point overflow */ + strcpy(dispstr, "overflow"); + break; + case FPE_FLTUND: /* floating point underflow */ + strcpy(dispstr, "underflow"); + break; + case FPE_FLTRES: /* floating point inexact result */ + strcpy(dispstr, "inexact result"); + break; + case FPE_FLTINV: /* invalid floating point operation */ + strcpy(dispstr, "invalid op"); + break; + case FPE_FLTSUB: /* subscript out of range */ + strcpy(dispstr, "out of range"); + break; + +#endif /*SVR4*/ + +#ifdef FPE_FLTDIV_TRAP + case FPE_FLTDIV_TRAP: strcpy(dispstr,"div by zero"); break; +#endif +#ifdef FPE_FLTDIV_FAULT + case FPE_FLTDIV_FAULT: strcpy(dispstr,"div by zero"); break; +#endif +#ifdef FPE_FLTOVF_TRAP + case FPE_FLTOVF_TRAP: strcpy(dispstr,"overflow"); break; +#endif +#ifdef FPE_FLTOVF_FAULT + case FPE_FLTOVF_FAULT: strcpy(dispstr,"overflow"); break; +#endif +#ifdef FPE_FLTUND_TRAP + case FPE_FLTUND_TRAP: strcpy(dispstr,"underflow"); break; +#endif +#ifdef FPE_FLTUND_FAULT + case FPE_FLTUND_FAULT: strcpy(dispstr,"underflow"); break; +#endif + default: strcpy(dispstr,"error"); + } + else + if (SignalKind == SIGILL) + strcpy(dispstr, "illegal operand"); + + entered=3; + DrawDisplay(); + return; +} + + +/* keep SVR4 compiler from complaining about scope of arg declaration below */ +typedef struct sigcontext * sigcontextstructp; +/*ARGSUSED*/ +signal_t fperr(sig,code,scp) + int sig,code; + sigcontextstructp scp; +{ +#if defined(SYSV) || defined(SVR4) || defined(linux) + signal(SIGFPE,(signal_t (*)())fperr); +#endif + SignalKind = sig; + SignalCode = code; + longjmp(env,1); +} + +/* for VAX BSD4.3 */ +/*ARGSUSED*/ +signal_t illerr(sig,code,scp) + int sig,code; + sigcontextstructp scp; +{ + /* not reset when caught? */ + signal(SIGILL,(signal_t (*)())illerr); + + SignalKind = sig; + SignalCode = code; + longjmp(env,1); +} + +#endif /* not IEEE */ + + +void post_op() +{ +#ifdef DEBUG + showstack("\0"); +#endif +#ifndef IEEE + if (errno) { + strcpy(dispstr,"error"); + DrawDisplay(); + entered=3; + errno=0; + } +#endif +} +/*-------------------------------------------------------------------------*/ +static void +DrawDisplay(void) +{ + if ((int) strlen(dispstr) > 12) { /* strip out some decimal digits */ + char tmp[32]; + char *estr = index(dispstr,'e'); /* search for exponent part */ + if (!estr) dispstr[12]='\0'; /* no exp, just trunc. */ + else { + if ((int) strlen(estr) <= 4) + sprintf(tmp,"%.8s",dispstr); /* leftmost 8 chars */ + else + sprintf(tmp,"%.7s",dispstr); /* leftmost 7 chars */ + strcat (tmp,estr); /* plus exponent */ + strcpy (dispstr,tmp); + } + } + draw(dispstr); + setflag(XCalc_MEMORY, (flagM)); + setflag(XCalc_INVERSE, (flagINV)); + setflag(XCalc_DEGREE, (drgmode==DEG)); + setflag(XCalc_RADIAN, (drgmode==RAD)); + setflag(XCalc_GRADAM, (drgmode==GRAD)); + setflag(XCalc_PAREN, (flagPAREN)); +} + +/*-------------------------------------------------------------------------*/ +void +numeric(keynum) + int keynum; +{ + char st[2]; + int cell = 0; + + flagINV=0; + + if (rpn && (memop == kSTO || memop == kRCL || memop == kSUM)) { + switch (keynum) { + case kONE: cell = 1; break; + case kTWO: cell = 2; break; + case kTHREE: cell = 3; break; + case kFOUR: cell = 4; break; + case kFIVE: cell = 5; break; + case kSIX: cell = 6; break; + case kSEVEN: cell = 7; break; + case kEIGHT: cell = 8; break; + case kNINE: cell = 9; break; + case kZERO: cell = 0; break; + } + switch (memop) { + case kSTO: + mem[cell] = dnum; + lift_enabled = 1; + entered = 2; + clrdisp++; + break; + case kRCL: + PushNum(dnum); + dnum = mem[cell]; + sprintf(dispstr, "%.8g", dnum); + lift_enabled = 1; + entered = 1; + clrdisp = 0; + break; + case kSUM: + mem[cell] += dnum; + lift_enabled = 1; + entered = 2; + clrdisp++; + break; + } + memop = kCLR; + DrawDisplay(); + return; + } + + if (clrdisp) { + dispstr[0]='\0'; + exponent=Dpoint=0; +/* if (rpn && entered==2) + PushNum(dnum); + */ + if (rpn & lift_enabled) + PushNum(dnum); + } + if ((int) strlen(dispstr) >= MAXDISP) + return; + + switch (keynum){ + case kONE: st[0] = '1'; break; + case kTWO: st[0] = '2'; break; + case kTHREE: st[0] = '3'; break; + case kFOUR: st[0] = '4'; break; + case kFIVE: st[0] = '5'; break; + case kSIX: st[0] = '6'; break; + case kSEVEN: st[0] = '7'; break; + case kEIGHT: st[0] = '8'; break; + case kNINE: st[0] = '9'; break; + case kZERO: st[0] = '0'; break; + } + st[1] = '\0'; + strcat(dispstr,st); + + DrawDisplay(); + if (clrdisp && keynum != kZERO) + clrdisp=0; /*no leading 0s*/ + entered=1; + lift_enabled = 0; +} + +void +bkspf(void) +{ + + lift_enabled = 0; + + if (! flagINV) + { + if (entered!=1 || clrdisp) + return; + if ((int) strlen(dispstr) > 0) + dispstr[strlen(dispstr)-1] = 0; + if (strlen(dispstr) == 0) { + strcat(dispstr, "0"); + clrdisp++; + } + } + else + { + strcpy(dispstr, "0"); + dnum = 0.0; + clrdisp++; + flagINV = 0; + } + DrawDisplay(); +} + +void +decf(void) +{ + flagINV=0; + if (clrdisp) { + if (rpn) + PushNum(dnum); + strcpy(dispstr,"0"); + } + if (!Dpoint) { +#ifndef X_LOCALE + strcat(dispstr, localeconv()->decimal_point); +#else + strcat(dispstr, "."); +#endif + DrawDisplay(); + Dpoint++; + } + clrdisp=0; + entered=1; +} + +void +eef(void) +{ + flagINV=0; + if (clrdisp) { + if (rpn && lift_enabled) + PushNum(dnum); + strcpy(dispstr, rpn ? "1" : "0"); + } + if (!exponent) { + strcat(dispstr,"E+"); + DrawDisplay(); + exponent=strlen(dispstr)-1; /* where the '-' goes */ + } + clrdisp=0; + entered=1; +} + +void +clearf(void) +{ + flagINV=0; + if (CLR && !rpn) { /* clear all */ + ClearStacks(); + flagPAREN=0; + } + CLR++; + exponent=Dpoint=0; + clrdisp=1; + entered=1; + strcpy(dispstr,"0"); + DrawDisplay(); +} + +void +negf(void) +{ + flagINV=0; + if (exponent) { /* neg the exponent */ + if (dispstr[exponent]=='-') + dispstr[exponent]='+'; + else + dispstr[exponent]='-'; + DrawDisplay(); + return; + } + + if (strcmp("0",dispstr)==0) + return; /* don't neg a zero */ + if (dispstr[0]=='-') /* already neg-ed */ + strcpy(dispstr,dispstr+1); /* move str left once */ + else { /* not neg-ed. add a '-' */ + char tmp[32]; + sprintf(tmp,"-%s",dispstr); + strcpy(dispstr,tmp); + } + if (entered==2) + dnum = -1.0 * dnum; + DrawDisplay(); +} + +/* Two operand functions for infix calc */ +void +twoop(int keynum) +{ + if (flagINV) { + flagINV=0; + DrawDisplay(); + } + + if (!entered) { /* something like "5+*" */ + if (!isopempty()) + (void) PopOp(); /* replace the prev op */ + PushOp(keynum); /* with the new one */ + return; + } + + if (entered==1) + parse_double(dispstr,"%lf",&dnum); + + clrdisp=CLR=1; + entered=Dpoint=exponent=0; + + if (!isopempty()) { /* there was a previous op */ + lastop=PopOp(); /* get it */ + + if (lastop==kLPAR) { /* put it back */ + PushOp(kLPAR); + PushOp(keynum); + PushNum(dnum); + return; + } + + /* now, if the current op (keynum) is of + higher priority than the lastop, the current + op and number are just pushed on top + Priorities: (Y^X) > *,/ > +,- */ + + if (priority(keynum) > priority(lastop)) { + PushNum(dnum); + PushOp(lastop); + PushOp(keynum); + } else { /* execute lastop on lastnum and dnum, push + result and current op on stack */ + acc=PopNum(); + switch (lastop) { /* perform the operation */ + case kADD: acc += dnum; break; + case kSUB: acc -= dnum; break; + case kMUL: acc *= dnum; break; + case kDIV: acc /= dnum; break; + case kPOW: acc = pow(acc,dnum); break; + } + PushNum(acc); + PushOp(keynum); + sprintf(dispstr,"%.8g",acc); + DrawDisplay(); + dnum=acc; + } + } + else { /* op stack is empty, push op and num */ + PushOp(keynum); + PushNum(dnum); + } +} + +/* Two operand functions for rpn calc */ +void +twof(int keynum) +{ + if (flagINV) { + flagINV=0; + DrawDisplay(); + } + if (!entered) + return; + if (entered==1) + parse_double(dispstr, "%lf", &dnum); + acc = PopNum(); + switch(keynum) { + case kADD: acc += dnum; break; + case kSUB: acc -= dnum; break; + case kMUL: acc *= dnum; break; + case kDIV: acc /= dnum; break; + case kPOW: acc = pow(acc,dnum); break; + case kXXY: PushNum(dnum); + } + sprintf(dispstr, "%.8g", acc); + DrawDisplay(); + clrdisp++; + Dpoint = exponent = 0; + entered = 2; + lift_enabled = 1; + dnum = acc; +} + +void +entrf(void) +{ + flagINV=0; + if (!entered) + return; + + clrdisp=CLR=1; + Dpoint=exponent=0; + + if (entered==1) + parse_double(dispstr,"%lf",&dnum); + entered=2; + memop = kENTR; + PushNum(dnum); + lift_enabled = 0; +} + +void +equf(void) +{ + flagINV=0; + if (!entered) + return; + + clrdisp=CLR=1; + Dpoint=exponent=0; + + if (entered==1) + parse_double(dispstr,"%lf",&dnum); + entered=2; + + PushNum(dnum); + + while (!isopempty()) { /* do all pending ops */ + dnum=PopNum(); + acc=PopNum(); + lastop=PopOp(); + switch (lastop) { + case kADD: acc += dnum; + break; + case kSUB: acc -= dnum; + break; + case kMUL: acc *= dnum; + break; + case kDIV: acc /= dnum; + break; + case kPOW: acc = pow(acc,dnum); + break; + case kLPAR: flagPAREN--; + PushNum(acc); + break; + } + dnum=acc; + PushNum(dnum); + } + + sprintf(dispstr,"%.8g",dnum); + DrawDisplay(); +} + +void +lparf(void) +{ + flagINV=0; + PushOp(kLPAR); + flagPAREN++; + DrawDisplay(); +} + +void +rollf(void) +{ + if (!entered) + return; + if (entered==1) + parse_double(dispstr, "%lf", &dnum); + entered = 2; + lift_enabled = 1; + RollNum(flagINV); + flagINV=0; + clrdisp++; + sprintf(dispstr, "%.8g", dnum); + DrawDisplay(); +} + +void +rparf(void) +{ + flagINV=0; + if (!entered) + return; + + if (!flagPAREN) + return; + + clrdisp++; + Dpoint=exponent=0; + + if (entered==1) + parse_double(dispstr,"%lf",&dnum); + entered=2; + + PushNum(dnum); + while (!isopempty() && (lastop=PopOp())!=kLPAR) { + /* do all pending ops, back to left paren */ + dnum=PopNum(); + acc=PopNum(); + switch (lastop) { + case kADD: acc += dnum; + break; + case kSUB: acc -= dnum; + break; + case kMUL: acc *= dnum; + break; + case kDIV: acc /= dnum; + break; + case kPOW: acc = pow(acc,dnum); + break; + } + dnum=acc; + PushNum(dnum); + } + (void) PopNum(); + flagPAREN--; + entered=2; + sprintf(dispstr,"%.8g",dnum); + DrawDisplay(); +} + +void +drgf(void) +{ + if (flagINV) { + if (entered==1) + parse_double(dispstr,"%lf",&dnum); + switch (drgmode) { + case DEG: dnum=dnum*PI/180.0; break; + case RAD: dnum=dnum*200.0/PI; break; + case GRAD: dnum=dnum*90.0/100.0; break; + } + entered=2; + clrdisp=1; + flagINV=0; + sprintf(dispstr,"%.8g",dnum); + } + + flagINV=0; + drgmode = (drgmode + 1) % 3; + switch (drgmode) { + case DEG: drg2rad=PI / 180.0; + rad2drg=180.0 / PI; + break; + case RAD: drg2rad=1.0; + rad2drg=1.0; + break; + case GRAD: drg2rad=PI / 200.0; + rad2drg=200.0 / PI; + break; + } + DrawDisplay(); +} + +void +invf(void) +{ + flagINV = ~flagINV; + DrawDisplay(); +} + +void +memf(int keynum) +{ + memop = keynum; + if (entered==1) + parse_double(dispstr,"%lf",&dnum); + entered = 2; + clrdisp++; + lift_enabled = 0; +} + +void +oneop(int keynum) +{ + int i,j; + double dtmp; + + if (entered==1) + parse_double(dispstr,"%lf",&dnum); + entered = 2; + + switch (keynum) { /* do the actual math fn. */ + case kE: if (rpn && memop != kENTR) PushNum(dnum); dnum=E; break; + case kPI: if (rpn && memop != kENTR) PushNum(dnum); dnum=PI; break; + case kRECIP: dnum=1.0/dnum; break; + case kSQR: flagINV = !flagINV; /* fall through to */ + case kSQRT: if (flagINV) dnum=dnum*dnum; + else dnum=sqrt(dnum); + break; + case k10X: flagINV = !flagINV; /* fall through to */ + case kLOG: if (flagINV) dnum=pow(10.0,dnum); + else dnum=log10(dnum); + break; + case kEXP: flagINV = !flagINV; /* fall through to */ + case kLN: if (flagINV) dnum=exp(dnum); + else dnum=log(dnum); + break; + case kSIN: if (flagINV) dnum=asin(dnum)*rad2drg; + else dnum=sin(dnum*drg2rad); + break; + case kCOS: if (flagINV) dnum=acos(dnum)*rad2drg; + else dnum=cos(dnum*drg2rad); + break; + case kTAN: if (flagINV) dnum=atan(dnum)*rad2drg; + else dnum=tan(dnum*drg2rad); + break; + case kSTO: mem[0]=dnum; flagM=!(mem[0]==0.0); break; + case kRCL: if (rpn && lift_enabled) PushNum(dnum); + dnum=mem[0]; flagM=!(mem[0]==0.0); break; + case kSUM: mem[0]+=dnum; flagM=!(mem[0]==0.0); break; + case kEXC: dtmp=dnum; dnum=mem[0]; mem[0]=dtmp; + flagM=!(mem[0]==0.0); break; + case kFACT: if (floor(dnum)!=dnum || dnum<0.0 || dnum>500.0) { + strcpy(dispstr,"error"); + entered=3; + break; + } + i=(int) (floor(dnum)); + for (j=1,dnum=1.0; j<=i; j++) + dnum*=(float) j; + break; + } + + if (entered==3) { /* error */ + DrawDisplay(); + return; + } + + entered=2; + clrdisp=1; + flagINV=0; + lift_enabled = 1; + sprintf(dispstr,"%.8g",dnum); + DrawDisplay(); +} + +void +offf(void) +{ + /* full reset */ + int i; + ResetCalc(); + entered=clrdisp=1; + lift_enabled = 0; + dnum=mem[0]=0.0; + if (rpn) + for (i=1; i < XCALC_MEMORY; i++) + mem[i]=0.0; + accset=exponent=Dpoint=0; + DrawDisplay(); +} + + +#define STACKMAX 32 +static int opstack[STACKMAX]; +static int opsp; +static double numstack[STACKMAX]; +static int numsp; + + +/*******/ +static void +PushOp(op) + int op; +/*******/ +{ + if (opsp==STACKMAX) {strcpy(dispstr,"stack error"); entered=3;} + else opstack[opsp++]=op; +} + +/*******/ +static int +PopOp(void) +/*******/ +{ + if (opsp==0) { + strcpy(dispstr,"stack error"); + entered=3; + return(kNOP); + } else + return(opstack[--opsp]); +} + +/*******/ +static int +isopempty(void) +/*******/ +{ + return( opsp ? 0 : 1 ); +} + +#ifdef DEBUG +static void +showstack(string) + char *string; +{ + fprintf(stderr, "%s: %lf %lf %lf\n", string, numstack[0], numstack[1], + numstack[2]); +} +#endif + +/*******/ +static void +PushNum(num) + double num; +/*******/ +{ + if (rpn) { + numstack[2] = numstack[1]; + numstack[1] = numstack[0]; + numstack[0] = num; + return; + } + if (numsp==STACKMAX) { + strcpy(dispstr,"stack error"); + entered=3; + } else + numstack[numsp++]=num; +} + +/*******/ +static double +PopNum(void) +/*******/ +{ + if (rpn) { + double tmp = numstack[0]; + numstack[0] = numstack[1]; + numstack[1] = numstack[2]; + return(tmp); + } + if (numsp==0) { + strcpy(dispstr,"stack error"); + entered=3; + return 0.0; + } else + return(numstack[--numsp]); +} + +/*******/ +static void +RollNum(int dir) +/*******/ +{ + double tmp; + + if (dir) { /* roll up */ + tmp = dnum; + dnum = numstack[2]; + numstack[2] = numstack[1]; + numstack[1] = numstack[0]; + numstack[0] = tmp; + } else { /* roll down */ + tmp = dnum; + dnum = numstack[0]; + numstack[0] = numstack[1]; + numstack[1] = numstack[2]; + numstack[2] = tmp; + } +} + + +/*******/ +static void +ClearStacks(void) +/*******/ +{ + if (rpn) + numstack[0] = numstack[1] = numstack[2] = 0.; + opsp=numsp=0; +} + + +/*******/ +static int +priority(op) + int op; +/*******/ +{ + switch (op) { + case kPOW: return(2); + case kMUL: + case kDIV: return(1); + case kADD: + case kSUB: return(0); + } + return 0; +} + + +/********/ +void +ResetCalc(void) +/********/ +{ + flagM=flagINV=flagPAREN=0; drgmode=DEG; + setflag(XCalc_MEMORY, False); + setflag(XCalc_INVERSE, False); + setflag(XCalc_PAREN, False); + setflag(XCalc_RADIAN, False); + setflag(XCalc_GRADAM, False); + setflag(XCalc_DEGREE, True); + strcpy(dispstr,"0"); + draw(dispstr); + ClearStacks(); + drg2rad=PI/180.0; + rad2drg=180.0/PI; +} @@ -0,0 +1,402 @@ +/* $XConsortium: xcalc.c,v 1.16 94/04/17 20:43:31 converse Exp $ */ +/* + +Copyright (c) 1989 X Consortium + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of the X Consortium shall +not be used in advertising or otherwise to promote the sale, use or +other dealings in this Software without prior written authorization +from the X Consortium. + +*/ +/* $XFree86: xc/programs/xcalc/xcalc.c,v 1.2 2000/05/11 18:14:41 tsi Exp $ */ + +/* + * xcalc.c - a hand calculator for the X Window system + * + * Original Author: John H. Bradley, University of Pennsylvania + * (bradley@cis.upenn.edu) March, 1987 + * RPN mode added and port to X11 by Mark Rosenstein, MIT Project Athena + * Rewritten to be an Xaw and Xt client by Donna Converse, MIT X Consortium + */ + +#include <stdio.h> +#include <math.h> +#include <signal.h> +#include <X11/Intrinsic.h> +#include <X11/StringDefs.h> +#include <X11/Xatom.h> +#include <X11/Shell.h> +#include <X11/Xaw/Cardinals.h> +#include <X11/Xaw/Form.h> +#include <X11/Xaw/Label.h> +#include <X11/Xaw/Command.h> +#include <X11/Xaw/Toggle.h> +#include <X11/cursorfont.h> +#include "xcalc.h" +#include "actions.h" + +#ifndef IEEE +extern signal_t fperr(); +extern signal_t illerr(); +#endif + +/* + * global data + */ +int rpn = 0; /* Reverse Polish Notation (HP mode) flag */ +#define LCD_STR_LEN 32 +char dispstr[LCD_STR_LEN]; /* string to show up in the LCD */ +Atom wm_delete_window; /* see ICCCM section 5.2.2 */ + +/* + * local data + */ +static Display *dpy = NULL; /* connection to the X server */ +static Widget toplevel=NULL; /* top level shell widget */ +static Widget calculator=NULL; /* an underlying form widget */ +static Widget LCD = NULL; /* liquid crystal display */ +static Widget ind[6]; /* mode indicators in the screen */ +static char selstr[LCD_STR_LEN]; /* storage for selections from the LCD */ + /* checkerboard used in mono mode */ +static XtAppContext xtcontext; /* Toolkit application context */ +#define check_width 16 +#define check_height 16 +static unsigned char check_bits[] = { + 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa, + 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa, + 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa}; + +/* command line options specific to the application */ +static XrmOptionDescRec Options[] = { +{"-rpn", "rpn", XrmoptionNoArg, (XtPointer)"on"}, +{"-stipple", "stipple", XrmoptionNoArg, (XtPointer)"on"} +}; + +/* resources specific to the application */ +static struct resources { + Boolean rpn; /* reverse polish notation (HP mode) */ + Boolean stipple; /* background stipple */ + Cursor cursor; +} appResources; + +#define offset(field) XtOffsetOf(struct resources, field) +static XtResource Resources[] = { +{"rpn", "Rpn", XtRBoolean, sizeof(Boolean), + offset(rpn), XtRImmediate, (XtPointer) False}, +{"stipple", "Stipple", XtRBoolean, sizeof(Boolean), + offset(stipple), XtRImmediate, (XtPointer) False}, +{"cursor", "Cursor", XtRCursor, sizeof(Cursor), + offset(cursor), XtRCursor, (XtPointer)NULL} +}; +#undef offset + + +int +main(argc, argv) + int argc; + char **argv; +{ + Arg args[3]; + + void create_calculator(); + void Quit(), Syntax(); + + + XtSetLanguageProc(NULL, (XtLanguageProc) NULL, NULL); + + toplevel = XtAppInitialize(&xtcontext, "XCalc", Options, XtNumber(Options), + &argc, argv, NULL, NULL, 0); + if (argc != 1) Syntax(argc, argv); + + XtSetArg(args[0], XtNinput, True); + XtSetValues(toplevel, args, ONE); + + XtGetApplicationResources(toplevel, (XtPointer)&appResources, Resources, + XtNumber(Resources), (ArgList) NULL, ZERO); + + create_calculator(toplevel); + + XtAppAddActions(xtcontext, Actions, XtNumber(Actions)); + + XtOverrideTranslations(toplevel, + XtParseTranslationTable("<Message>WM_PROTOCOLS: quit()\n")); + + XtRealizeWidget(toplevel); + + dpy = XtDisplay(toplevel); + wm_delete_window = XInternAtom(dpy, "WM_DELETE_WINDOW", False); + (void) XSetWMProtocols(dpy, XtWindow(toplevel), &wm_delete_window, 1); + XDefineCursor(dpy, XtWindow(toplevel), appResources.cursor); + + if (appResources.stipple || (CellsOfScreen(XtScreen(toplevel)) <= 2)) + { + Screen *screen = XtScreen(toplevel); + Pixmap backgroundPix; + + backgroundPix = XCreatePixmapFromBitmapData + (dpy, XtWindow(toplevel), + (char *)check_bits, check_width, check_height, + WhitePixelOfScreen(screen), BlackPixelOfScreen(screen), + DefaultDepthOfScreen(screen)); + XtSetArg(args[0], XtNbackgroundPixmap, backgroundPix); + XtSetValues(calculator, args, ONE); + } + +#ifndef IEEE + signal(SIGFPE,fperr); + signal(SIGILL,illerr); +#endif + ResetCalc(); + XtAppMainLoop(xtcontext); + + return 0; +} + +void create_calculator(shell) + Widget shell; +{ + void create_display(); + void create_keypad(); + + rpn = appResources.rpn; + calculator = XtCreateManagedWidget(rpn ? "hp" : "ti", formWidgetClass, + shell, (ArgList) NULL, ZERO); + create_display(calculator); + create_keypad(calculator); + XtSetKeyboardFocus(calculator, LCD); +} + +/* + * Do the calculator data display widgets. + */ +void create_display(parent) + Widget parent; +{ + Widget bevel, screen; + static Arg args[] = { + {XtNborderWidth, (XtArgVal)0}, + {XtNjustify, (XtArgVal)XtJustifyRight} + }; + + /* the frame surrounding the calculator display */ + bevel = XtCreateManagedWidget("bevel", formWidgetClass, parent, + (ArgList) NULL, ZERO); + + /* the screen of the calculator */ + screen = XtCreateManagedWidget("screen", formWidgetClass, bevel, + (ArgList) NULL, ZERO); + + /* M - the memory indicator */ + ind[XCalc_MEMORY] = XtCreateManagedWidget("M", labelWidgetClass, screen, + args, XtNumber(args)); + + /* liquid crystal display */ + LCD = XtCreateManagedWidget("LCD", toggleWidgetClass, screen, args, + XtNumber(args)); + + /* INV - the inverse function indicator */ + ind[XCalc_INVERSE] = XtCreateManagedWidget("INV", labelWidgetClass, + screen, args, XtNumber(args)); + + /* DEG - the degrees switch indicator */ + ind[XCalc_DEGREE] = XtCreateManagedWidget("DEG", labelWidgetClass, screen, + args, XtNumber(args)); + + /* RAD - the radian switch indicator */ + ind[XCalc_RADIAN] = XtCreateManagedWidget("RAD", labelWidgetClass, screen, + args, XtNumber(args)); + + /* GRAD - the grad switch indicator */ + ind[XCalc_GRADAM] = XtCreateManagedWidget("GRAD", labelWidgetClass, screen, + args, XtNumber(args)); + + /* () - the parenthesis indicator */ + ind[XCalc_PAREN] = XtCreateManagedWidget("P", labelWidgetClass, screen, + args, XtNumber(args)); +} + +/* + * Do all the buttons. The application defaults file will give the + * default button placement, default button labels, and default + * actions connected to the buttons. The user can change any of + * these defaults in an environment-specific resource file. + */ + +void create_keypad(parent) + Widget parent; +{ + static char *Keyboard[] = { + "button1", "button2", "button3", "button4", "button5", + "button6", "button7", "button8", "button9", "button10", + "button11","button12","button13","button14","button15", + "button16","button17","button18","button19","button20", + "button21","button22","button23","button24","button25", + "button26","button27","button28","button29","button30", + "button31","button32","button33","button34","button35", + "button36","button37","button38","button39","button40" + }; + register int i; + int n = XtNumber(Keyboard); + + if (appResources.rpn) n--; /* HP has 39 buttons, TI has 40 */ + + for (i=0; i < n; i++) + XtCreateManagedWidget(Keyboard[i], commandWidgetClass, parent, + (ArgList) NULL, ZERO); +} + +/* + * Miscellaneous utility routines that interact with the widgets. + */ + +/* + * called by math routines to write to the liquid crystal display. + */ +void draw(string) + char *string; +{ + Arg args[1]; + + XtSetArg(args[0], XtNlabel, string); + XtSetValues(LCD, args, ONE); +} +/* + * called by math routines to turn on and off the display indicators. + */ +void setflag(indicator, on) + int indicator; + Boolean on; +{ + if (on) XtMapWidget(ind[indicator]); + else XtUnmapWidget(ind[indicator]); +} + +/* + * ring the bell. + */ +void ringbell() +{ + XBell(dpy, 0); +} + +/* + * die. + */ +void Quit() +{ + extern void exit(); + XtDestroyApplicationContext(xtcontext); + exit(0); +} + +/* + * recite and die. + */ +void Syntax(argc, argv) + int argc; + char **argv; +{ + register int i; + extern void exit(); + (void) fprintf(stderr, "%s: unknown options:", argv[0]); + for (i=1; i <argc; i++) + (void) fprintf(stderr, " %s", argv[i]); + (void) fprintf(stderr, "\n\n"); + (void) fprintf(stderr, "Usage: %s", argv[0]); + for (i=0; i < XtNumber(Options); i++) + (void) fprintf(stderr, " [%s]", Options[i].option); + (void) fprintf(stderr, "\n"); + XtDestroyApplicationContext(xtcontext); + exit(1); +} + +/* + * I use actions on the toggle widget to support selections. This + * means that the user may not do a partial selection of the number + * displayed in the `liquid crystal display.' Copying numbers into + * the calculator is also not supported. So all you can do is copy + * the entire number from the calculator display. + */ + +/*ARGSUSED*/ +Boolean convert(w, selection, target, type, value, length, format) + Widget w; + Atom *selection; + Atom *target; + Atom *type; + XtPointer *value; + unsigned long *length; + int *format; +{ + if (*target == XA_STRING) + { + *type = XA_STRING; + *length = strlen(dispstr); + strncpy(selstr, dispstr, (int)(*length)); + *value = selstr; + *format = 8; + return True; + } + return False; +} + +/* + * called when xcalc loses ownership of the selection. + */ +/*ARGSUSED*/ +void lose(w, selection) + Widget w; + Atom *selection; +{ + XawToggleUnsetCurrent(LCD); +} + +/* + * called when some other client got the selection. + */ +/*ARGSUSED*/ +void done(w, selection, target) + Widget w; + Atom *selection; + Atom *target; +{ + selstr[0] = '\0'; +} + +/* + * called by the selection() action routine, in response to user action. + */ +void do_select(time) + Time time; +{ + Boolean state; + Arg args[1]; + + XtSetArg(args[0], XtNstate, &state); + XtGetValues(LCD, args, 1); + + if (state) + XtOwnSelection(LCD, XA_PRIMARY, time, convert, lose, done); + else + selstr[0] = '\0'; +} @@ -0,0 +1,123 @@ +/* $XConsortium: xcalc.h,v 1.4 94/04/17 20:43:32 converse Exp $ */ +/* + +Copyright (c) 1989 X Consortium + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of the X Consortium shall +not be used in advertising or otherwise to promote the sale, use or +other dealings in this Software without prior written authorization +from the X Consortium. + +*/ +/* $XFree86: xc/programs/xcalc/xcalc.h,v 1.2 2001/08/01 00:45:02 tsi Exp $ */ + +/* + * xcalc.h - symbolic constants for xcalc + * + * Author: Donna Converse, MIT X Consortium + */ + +#ifndef _XCALC_H_ +#define _XCALC_H_ + +#ifdef SIGNALRETURNSINT +#define signal_t int +#else +#define signal_t void +#endif + +#define kRECIP 0 /* reciprocal */ +#define kSQR 1 /* square */ +#define kSQRT 2 /* square root */ +#define kCLR 3 /* clear */ +#define kOFF 4 /* clear and quit */ +#define kINV 5 /* inverse */ +#define kSIN 6 /* sine */ +#define kCOS 7 /* cosine */ +#define kTAN 8 /* tangent */ +#define kDRG 9 /* degree radian grad */ +#define kE 10 /* the natural number e */ +#define kEE 11 /* scientific notation */ +#define kLOG 12 /* logarithm */ +#define kLN 13 /* natural logarithm */ +#define kPOW 14 /* power */ +#define kPI 15 /* pi */ +#define kFACT 16 /* factorial */ +#define kLPAR 17 /* left paren */ +#define kRPAR 18 /* right paren */ +#define kDIV 19 /* division */ +#define kSTO 20 /* store */ +#define kSEVEN 21 /* 7 */ +#define kEIGHT 22 /* 8 */ +#define kNINE 23 /* 9 */ +#define kMUL 24 /* multiplication */ +#define kRCL 25 /* recall */ +#define kFOUR 26 /* 4 */ +#define kFIVE 27 /* 5 */ +#define kSIX 28 /* 6 */ +#define kSUB 29 /* subtraction */ +#define kSUM 30 /* summation */ +#define kONE 31 /* 1 */ +#define kTWO 32 /* 2 */ +#define kTHREE 33 /* 3 */ +#define kADD 34 /* addition */ +#define kEXC 35 /* exchange display and memory */ +#define kZERO 36 /* 0 */ +#define kDEC 37 /* decimal point */ +#define kNEG 38 /* negation */ +#define kEQU 39 /* equals */ +#define kENTR 40 /* enter */ +#define kXXY 41 /* exchange X and Y registers */ +#define kEXP 42 /* exponent */ +#define k10X 43 /* 10 raised to a power */ +#define kROLL 44 /* roll stack */ +#define kNOP 45 /* no operation */ +#define kBKSP 46 /* backspace */ + +#define XCalc_MEMORY 0 /* memory indicator */ +#define XCalc_INVERSE 1 /* inverse function indicator */ +#define XCalc_DEGREE 2 /* degree indicator */ +#define XCalc_RADIAN 3 /* radian indicator */ +#define XCalc_GRADAM 4 /* grad indicator */ +#define XCalc_PAREN 5 /* parenthesis indicator */ + +extern void numeric(int keynum); +extern void bkspf(void); +extern void decf(void); +extern void eef(void); +extern void clearf(void); +extern void negf(void); +extern void twoop(int keynum); +extern void twof(int keynum); +extern void entrf(void); +extern void equf(void); +extern void lparf(void); +extern void rollf(void); +extern void rparf(void); +extern void drgf(void); +extern void invf(void); +extern void memf(int keynum); +extern void oneop(int keynum); +extern void offf(void); +extern void ResetCalc(void); + +#endif diff --git a/xcalc.man b/xcalc.man new file mode 100644 index 0000000..3f367bd --- /dev/null +++ b/xcalc.man @@ -0,0 +1,439 @@ +.\" $XConsortium: xcalc.man,v 1.10 94/04/17 20:43:32 matt Exp $ +.\" Copyright (c) 1994 X Consortium +.\" +.\" Permission is hereby granted, free of charge, to any person obtaining +.\" a copy of this software and associated documentation files (the +.\" "Software"), to deal in the Software without restriction, including +.\" without limitation the rights to use, copy, modify, merge, publish, +.\" distribute, sublicense, and/or sell copies of the Software, and to +.\" permit persons to whom the Software is furnished to do so, subject to +.\" the following conditions: +.\" +.\" The above copyright notice and this permission notice shall be included +.\" in all copies or substantial portions of the Software. +.\" +.\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +.\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +.\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +.\" IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR +.\" OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +.\" ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +.\" OTHER DEALINGS IN THE SOFTWARE. +.\" +.\" Except as contained in this notice, the name of the X Consortium shall +.\" not be used in advertising or otherwise to promote the sale, use or +.\" other dealings in this Software without prior written authorization +.\" from the X Consortium. +.\" +.\" $XFree86: xc/programs/xcalc/xcalc.man,v 1.4 2002/10/12 16:06:46 herrb Exp $ +.\" +.de EX \"Begin example +.ne 5 +.if n .sp 1 +.if t .sp .5 +.nf +.in +.5i +.. +.de EE +.fi +.in -.5i +.if n .sp 1 +.if t .sp .5 +.. +.TH XCALC 1 __xorgversion__ +.SH NAME +xcalc \- scientific calculator for X +.SH SYNOPSIS +.B xcalc +[-stipple] [-rpn] [-\fItoolkitoption...\fP] +.SH DESCRIPTION +.I xcalc +is a scientific calculator desktop accessory that can emulate a TI-30 +or an HP-10C. +.SH OPTIONS +.PP +\fIxcalc\fP accepts all of the standard toolkit command line options along +with two additional options: +.PP +.TP 8 +.B \-stipple +This option indicates that the background of the calculator should be +drawn using a stipple of the foreground and background colors. On monochrome +displays improves the appearance. +.PP +.TP 8 +.B \-rpn +This option indicates that Reverse Polish Notation should be used. In this +mode the calculator will look and behave like an HP-10C. Without this flag, +it will emulate a TI-30. +.SH OPERATION +.PP +.I Pointer Usage: +Operations may be performed with pointer button 1, or in some cases, +with the keyboard. +Many common calculator operations have keyboard accelerators. +To quit, press pointer button 3 on the AC key of the TI calculator, +or the ON key of the HP calculator. +.PP +.I Calculator Key Usage (TI mode): +The numbered keys, the +/- key, and the +, -, *, /, and = keys all do exactly +what you would expect them to. It should be noted that the operators obey +the standard rules of precedence. Thus, entering "3+4*5=" results in "23", +not "35". The parentheses can be used to override this. For example, +"(1+2+3)*(4+5+6)=" results in "6*15=90". +.PP +The entire number in the calculator display can be selected, in order to +paste the result of a calculation into text. +.PP +The action procedures associated with each function are given below. These +are useful if you are interested in defining a custom calculator. +The action used for all digit keys is \fBdigit(\fIn\fP)\fR, where \fIn\fR +is the corresponding digit, 0..9. +.TP 10 +.B 1/x +Replaces the number in the display with its reciprocal. +The corresponding action procedure is \fBreciprocal()\fR. +.TP 10 +.B x^2 +Squares the number in the display. +The corresponding action procedure is \fBsquare()\fR. +.TP 10 +.B SQRT +Takes the square root of the number in the display. +The corresponding action procedure is \fBsquareRoot()\fR. +.TP 10 +.B CE/C +When pressed once, clears the number in the display without clearing the state +of the machine. Allows you to re-enter a number if you make a mistake. +Pressing it twice clears the state, also. +The corresponding action procedure for TI mode is \fBclear()\fR. +.TP 10 +.B AC +Clears the display, the state, and the memory. Pressing it with the third +pointer button turns off the calculator, in that it exits the program. +The action procedure to clear the state is \fBoff()\fR; to quit, \fBquit()\fR. +.TP 10 +.B INV +Invert function. See the individual function keys for details. +The corresponding action procedure is \fBinverse()\fR. +.TP 10 +.B sin +Computes the sine of the number in the display, as interpreted by the current +DRG mode (see DRG, below). If inverted, it computes the arcsine. +The corresponding action procedure is \fBsine()\fR. +.TP 10 +.B cos +Computes the cosine, or arccosine when inverted. +The corresponding action procedure is \fBcosine()\fP. +.TP 10 +.B tan +Computes the tangent, or arctangent when inverted. +The corresponding action procedure is \fBtangent()\fP. +.TP 10 +.B DRG +Changes the DRG mode, as indicated by 'DEG', 'RAD', or 'GRAD' at the bottom of +of the calculator ``liquid crystal'' display. +When in 'DEG' mode, numbers in the display are taken as being +degrees. In 'RAD' mode, numbers are in radians, and in 'GRAD' mode, numbers +are in grads. When inverted, the DRG key has a feature of +converting degrees to radians to grads and vice-versa. Example: put the +calculator into 'DEG' mode, and enter "45 INV DRG". The display should now +show something along the lines of ".785398", which is 45 degrees converted to +radians. +The corresponding action procedure is \fBdegree()\fP. +.TP 10 +.B e +The constant 'e'. (2.7182818...). +The corresponding action procedure is \fBe()\fR. +.TP 10 +.B EE +Used for entering exponential numbers. For example, to get "-2.3E-4" you'd +enter "2 . 3 +/- EE 4 +/-". +The corresponding action procedure is \fBscientific()\fR. +.TP 10 +.B log +Calculates the log (base 10) of the number in the display. When inverted, +it raises "10.0" to the number in the display. +For example, entering "3 INV log" should result in "1000". +The corresponding action procedure is \fBlogarithm()\fP. +.TP 10 +.B ln +Calculates the log (base e) of the number in the display. When inverted, +it raises "e" to the number in the display. For example, entering "e ln" +should result in "1". +The corresponding action procedure is \fBnaturalLog()\fR. +.TP 10 +.B y^x +Raises the number on the left to the power of the number on the right. For +example "2 y^x 3 =" results in "8", which is 2^3. For a further example, +"(1+2+3) y^x (1+2) =" equals "6 y^x 3" which equals "216". +The corresponding action procedure is \fBpower()\fR. +.TP 10 +.B PI +The constant 'pi'. (3.1415927....) +The corresponding action procedure is \fBpi()\fR. +.TP 10 +.B x! +Computes the factorial of the number in the display. The number in the display +must be an integer in the range 0-500, though, depending on your math library, +it might overflow long before that. +The corresponding action procedure is \fBfactorial()\fR. +.TP 10 +.B ( +Left parenthesis. The corresponding action procedure for TI calculators +is \fBleftParen()\fR. +.TP 10 +.B ) +Right parenthesis. The corresponding action procedure for TI calculators +is \fBrightParen()\fR. +.TP 10 +.B / +Division. The corresponding action procedure is \fBdivide()\fR. +.TP 10 +.B * +Multiplication. The corresponding action procedure is \fBmultiply()\fR. +.TP 10 +.B - +Subtraction. The corresponding action procedure is \fBsubtract()\fR. +.TP 10 +.B + +Addition. The corresponding action procedure is \fBadd()\fR. +.TP 10 +.B = +Perform calculation. The TI-specific action procedure is \fBequal()\fR. +.TP 10 +.B STO +Copies the number in the display to the memory location. +The corresponding action procedure is \fBstore()\fR. +.TP 10 +.B RCL +Copies the number from the memory location to the display. +The corresponding action procedure is \fBrecall()\fR. +.TP 10 +.B SUM +Adds the number in the display to the number in the memory location. +The corresponding action procedure is \fBsum()\fR. +.TP 10 +.B EXC +Swaps the number in the display with the number in the memory location. +The corresponding action procedure for the TI calculator is \fBexchange()\fR. +.TP 10 +.B +/- +Negate; change sign. The corresponding action procedure is \fBnegate()\fR. +.TP 10 +.B . +Decimal point. The action procedure is \fBdecimal()\fP. +.sp +.PP +.I Calculator Key Usage (RPN mode): +The number keys, CHS (change sign), +, -, *, /, and ENTR keys all do exactly +what you would expect them to do. Many of the remaining keys are the same as +in TI mode. The differences are detailed below. The action procedure +for the ENTR key is \fBenter()\fR. +.sp +.TP 10 +.B <- +This is a backspace key that can be used if you make a mistake while entering +a number. It will erase digits from the display. (See BUGS). +Inverse backspace will clear the X register. +The corresponding action procedure is \fBback()\fR. +.TP 10 +.B ON +Clears the display, the state, and the memory. Pressing it with the third +pointer button turns off the calculator, in that it exits the program. +To clear state, the action procedure is \fBoff\fR; to quit, \fBquit()\fR. +.TP 10 +.B INV +Inverts the meaning of the function keys. This would be the \fIf\fR key +on an HP calculator, but \fIxcalc\fR does not display +multiple legends on each key. See the individual function keys for details. +.TP 10 +.B 10^x +Raises "10.0" to the number in the top of the stack. +When inverted, it calculates the log (base 10) of the number in the display. +The corresponding action procedure is \fBtenpower()\fR. +.TP 10 +.B e^x +Raises "e" to the number in the top of the stack. +When inverted, it calculates the log (base e) of the number in the display. +The action procedure is \fBepower()\fR. +.TP 10 +.B STO +Copies the number in the top of the stack to a memory location. There are 10 +memory locations. The desired memory is specified by following this +key with a digit key. +.TP 10 +.B RCL +Pushes the number from the specified memory location onto the stack. +.TP 10 +.B SUM +Adds the number on top of the stack to the number in the specified +memory location. +.TP 10 +.B x:y +Exchanges the numbers in the top two stack positions, the X and Y registers. +The corresponding action procedure is \fBXexchangeY()\fR. +.TP 10 +.B R v +Rolls the stack downward. When inverted, it rolls the stack upward. +The corresponding action procedure is \fBroll()\fR. +.TP 10 +.I blank +These keys were used for programming functions on the HP-10C. Their +functionality has not been duplicated in \fIxcalc\fR. +.PP +Finally, there are two additional action procedures: +\fBbell()\fR, which rings the bell; +and \fBselection()\fR, which performs a cut on the +entire number in the calculator's ``liquid crystal'' display. +.SH ACCELERATORS +.PP +Accelerators are shortcuts for entering commands. \fIxcalc\fP provides +some sample keyboard accelerators; also users can customize accelerators. +The numeric keypad accelerators provided by \fIxcalc\fP +should be intuitively correct. +The accelerators defined by \fIxcalc\fP on the main keyboard are given below: +.PP +.nf +.ta .5i 1.0i 1.5i 2.0i 2.5i 3.0i 3.5i 4.0i 4.5i 5.0i 5.5i 6.0i 6.5i 7.0i + TI Key HP Key Keyboard Accelerator TI Function HP Function + + SQRT SQRT r squareRoot() squareRoot() + AC ON space clear() clear() + AC <- Delete clear() back() + AC <- Backspace clear() back() + AC <- Control-H clear() back() + AC Clear clear() + AC ON q quit() quit() + AC ON Control-C quit() quit() + + INV i i inverse() inverse() + sin s s sine() sine() + cos c c cosine() cosine() + tan t t tangent() tangent() + DRG DRG d degree() degree() + + e e e() + ln ln l naturalLog() naturalLog() + y^x y^x ^ power() power() + + PI PI p pi() pi() + x! x! ! factorial() factorial() + ( ( leftParen() + ) ) rightParen() + + / / / divide() divide() + * * * multiply() multiply() + - - - subtract() subtract() + + + + add() add() + = = equal() + + 0..9 0..9 0..9 digit() digit() + . . . decimal() decimal() + +/- CHS n negate() negate() + + x:y x XexchangeY() + ENTR Return enter() + ENTR Linefeed enter() +.fi +.PP +.SH CUSTOMIZATION +The application class name is XCalc. +.PP +\fIxcalc\fP has an enormous application defaults file which specifies +the position, label, and function of each key on the calculator. +It also gives translations to serve as keyboard accelerators. +Because these resources are not specified in the source code, you can create +a customized calculator by writing a private application defaults file, +using the Athena Command and Form widget resources to specify the size and +position of buttons, the label for each button, and the function of +each button. +.PP +The foreground and background colors of each calculator key can be +individually specified. +For the TI calculator, a classical color resource specification might be: +.sp +.br +XCalc.ti.Command.background: gray50 +.br +XCalc.ti.Command.foreground: white +.sp +For each of buttons 20, 25, 30, 35, and 40, specify: +.br +XCalc.ti.button20.background: black +.br +XCalc.ti.button20.foreground: white +.sp +For each of buttons 22, 23, 24, 27, 28, 29, 32, 33, 34, 37, 38, and 39: +.br +XCalc.ti.button22.background: white +.br +XCalc.ti.button22.foreground: black +.SH WIDGET HIERARCHY +In order to specify resources, it is useful to know the hierarchy of +the widgets which compose \fIxcalc\fR. In the notation below, +indentation indicates hierarchical structure. The widget class name +is given first, followed by the widget instance name. +.nf +.ta .5i 1.0i 1.5i 2.0i 2.5i 3.0i 3.5i 4.0i 4.5i 5.0i 5.5i 6.0i 6.5i 7.0i +.sp +XCalc xcalc + Form ti \fIor\fR hp \fI(the name depends on the mode)\fR + Form bevel + Form screen + Label M + Toggle LCD + Label INV + Label DEG + Label RAD + Label GRAD + Label P + Command button1 + Command button2 + Command button3 +\fIand so on, ...\fR + Command button38 + Command button39 + Command button40 +.fi +.SH APPLICATION RESOURCES +.PP +.TP 8 +\fBrpn\fR (Class \fBRpn\fR) +Specifies that the rpn mode should be used. The default is TI mode. +.TP 8 +\fBstipple\fR (Class \fBStipple\fR) +Indicates that the background should be stippled. The default is ``on'' +for monochrome displays, and ``off'' for color displays. +.TP 8 +\fBcursor\fR (Class \fBCursor\fR) +The name of the symbol used to represent the pointer. +The default is ``hand2''. +.fi +.SH COLORS +If you would like xcalc to use its ti colors, include the following +in the #ifdef COLOR section of the file you read with xrdb: +.sp 1 +*customization: -color +.sp 1 +.br +This will cause xcalc to pick up the colors in the app-defaults color +customization file: +.IR __apploaddir__/XCalc-color . +.fi +.SH "SEE ALSO" +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. +.SH COPYRIGHT +Copyright ([\d,\s]*) X Consortium +.br +See \fIX(__miscmansuffix__)\fP for a full statement of rights and permissions. +.SH AUTHORS +John Bradley, University of Pennsylvania +.br +Mark Rosenstein, MIT Project Athena +.br +Donna Converse, MIT X Consortium |