home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
AmigActive 13
/
AACD13.ISO
/
AACD
/
Resources
/
System
/
BoingBag1
/
Contributions
/
Workbench
/
RexxArpLib3p6
/
rexx
/
Rexxcalc.rexx
< prev
next >
Wrap
OS/2 REXX Batch file
|
1991-04-25
|
3KB
|
142 lines
/*
** This implements a simple calculator in REXX with intuition interface.
** Intended to serve as an example for RexxArpLib 2.0 and later, NOT as
** an example of how to write a calculator...
**
** By W.G.J. Langeveld, november 1988.
*/
/*
* Set up a host
*/
runwsh "'x = CreateHost(REXXCALCHOST, REXXCALCPORT)'"
/*
* Wait until it is ready. It times out after a while, so do a few of them.
* May not be necessary, try it on your system for best results.
*/
WaitForPort REXXCALCHOST
WaitForPort REXXCALCHOST
WaitForPort REXXCALCHOST
/*
* Open the window
*/
idcmp = 'CLOSEWINDOW+GADGETUP'
flags = 'WINDOWCLOSE+WINDOWDRAG+WINDOWDEPTH+BACKFILL'
call OpenWindow(REXXCALCHOST, 50, 50, 180, 130, idcmp, flags)
/*
* Add all the gadgets
*/
do i = 7 to 9
call AddGadget(REXXCALCHOST, 20+(i-7)*32, 50, i, i, i)
end
do i = 4 to 6
call AddGadget(REXXCALCHOST, 20+(i-4)*32, 70, i, i, i)
end
do i = 1 to 3
call AddGadget(REXXCALCHOST, 20+(i-1)*32, 90, i, i, i)
end
call AddGadget(REXXCALCHOST, 20, 110, 0, " 0 ", 0)
call AddGadget(REXXCALCHOST, 84, 110, ".", ".", ".")
call AddGadget(REXXCALCHOST, 120, 70, "X", "X", "*")
call AddGadget(REXXCALCHOST, 152, 70, "/", "/", "/")
call AddGadget(REXXCALCHOST, 120, 90, "+", "+", "+")
call AddGadget(REXXCALCHOST, 152, 90, "-", "-", "-")
call AddGadget(REXXCALCHOST, 120, 50, "C", " CLR ", "C")
call AddGadget(REXXCALCHOST, 120, 110, "=", " = ", "=")
/*
* Draw the dialogue area
*/
call SetDrMd(REXXCALCHOST, JAM1)
call SetAPen(REXXCALCHOST, 2)
call RectFill(REXXCALCHOST, 10, 20, 170, 40)
call SetAPen(REXXCALCHOST, 1)
call RectFill(REXXCALCHOST, 15, 25, 165, 35)
call SetReqColor(REXXCALCHOST, PROMPTPEN, 3)
call SetReqColor(REXXCALCHOST, BACKPEN, 1)
/*
* Initialize some things first. Make sure we trap errors.
*/
signal on syntax
quitflag = 0
register = 0
number = 0
newnum = 1
call WindowText(REXXCALCHOST, "\ "||number)
/*
* This is the part that waits for messages.
* Study carefully: you have to be sure to get ALL messages.
*/
mp = openport(REXXCALCPORT)
start:
do forever
if quitflag = 1 then leave
t = waitpkt(REXXCALCPORT)
do forever
p = getpkt(REXXCALCPORT)
if c2d(p) = 0 then leave
arg = getarg(p)
t = reply(p, 0)
/*
* Phew! Got a message. Handle it. All this is trivial...
*/
if arg = CLOSEWINDOW then do
call CloseWindow(REXXCALCHOST)
quitflag = 1
end
else if index("1234567890.", arg) ~= 0 then do
if newnum = 1 then do
number = arg
newnum = 0
end
else number = number||arg
end
else if arg = "C" then do
register = 0
number = 0
newnum = 1
end
else if index("+-/*", arg) ~= 0 then do
oper = arg
register = number
newnum = 1
end
else if arg = "=" then do
interpret "register"||arg||register||oper||number
number = register
newnum = 1
end
else nop
/*
* Update the dialogue area
*/
if quitflag ~= 1 then call WindowText(REXXCALCHOST, "\ "||number)
end
end
exit
/*
* Error trapping:
*/
syntax:
call WindowText(REXXCALCHOST, "\ Error")
newnum = 1
signal on syntax
signal start