home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 2
/
amigaformatcd02.iso
/
pd
/
text
/
alphaspell_suite
/
varexx
/
demo
/
address.rexx
next >
Wrap
OS/2 REXX Batch file
|
1996-05-20
|
9KB
|
335 lines
/*************************************************************************/
/* $VER: Address.rexx 1.0 (5.12.95) */
/* Demo of varexx */
/* Usage: rx address ADRESSFILE */
/*************************************************************************/
guifile = 'address.gui'
addressbook = arg(1)
path = pragma( 'd' )
mod = FALSE
liston = FALSE
IF EXISTS("libs:rexxsupport.library") THEN DO
IF ~SHOW("L","rexxsupport.library") THEN
IF ~ADDLIB("rexxsupport.library",0,-30,0) THEN EXIT
END
ELSE EXIT
IF EXISTS("libs:rexxreqtools.library") THEN DO
IF ~SHOW("L","rexxreqtools.library") THEN
IF ~ADDLIB("rexxreqtools.library",0,-30) THEN EXIT
END
ELSE EXIT
OPTIONS RESULTS
OPTIONS FAILAT 20
SIGNAL ON SYNTAX
SIGNAL ON FAILURE
/* Check Varexx is loaded if not load it */
IF SHOW( 'p', 'VAREXX' ) ~= 1 THEN DO
ADDRESS COMMAND "run >NIL: varexx"
ADDRESS COMMAND "WaitForPort VAREXX"
launchvarexx = TRUE
END; ELSE
launchvarexx = FALSE
ADDRESS VAREXX
'version'
IF rc ~= 0 THEN DO
SAY 'This script requires varexx 1.3 or later'
EXIT
END
IF OPENPORT("HOLLY") = 0 THEN DO
CALL rtezrequest "Could not open a port.",, "Varexx Error"
EXIT
END
'load 'guifile' HOLLY'
edithost = RESULT
ADDRESS VALUE edithost
'spawn HOLLY'
listhost = RESULT
call LoadBook( arg(1) )
'show edit'
current = 0
/**************************************************************************/
/* MAIN LOOP -- Check for GUI events */
/**************************************************************************/
DO FOREVER
CALL WAITPKT("HOLLY")
packet = GETPKT("HOLLY")
IF packet ~= '00000000'x THEN DO
class = GETARG(packet)
SELECT
WHEN class = closewindow THEN LEAVE
WHEN word(class,1) = closewindow THEN DO
address value listhost
'hide'
liston = FALSE
address
END
WHEN class = FORWARDS THEN DO
current = current + 1
call DisplayEntry( current )
END
WHEN class = BACK THEN DO
current = current - 1
call DisplayEntry( current )
END
WHEN class = CLEAR THEN call clearentry()
WHEN class = UPDATE THEN call updateentry()
WHEN class = DELETE THEN call deleteentry()
WHEN class = SEARCH THEN call listentries()
WHEN word(class,1) = list THEN DO
address value listhost
read list number
current = result
address value edithost
call DisplayEntry( current )
END
OTHERWISE NOP
END
END
END
'hide unload'
address value listhost
'hide unload'
IF mod = TRUE THEN DO
IF rtezrequest('Save modified address book ?','Yes|No','Address Book',,
'rt_reqpos = reqpos_centerscr') = 1 THEN DO
call savebook()
END
END
CALL CLOSEPORT( "HOLLY" )
IF launchvarexx = TRUE THEN ADDRESS command vxc
EXIT
SaveBook :
ask=FALSE
IF addressbook = "" THEN ask = TRUE
IF ~Exists( addressbook ) THEN ask = TRUE
IF ask = TRUE THEN DO
addressbook = rtfilerequest( path, ,'Save as' , , 'rt_reqpos = reqpos_centerscr' )
END
IF open( infile, addressbook, 'w' ) THEN DO
DO n = 1 to add.count
IF add.n.del = FALSE THEN DO
line = add.n.sname'#'add.n.fname'#'add.n.add'#'add.n.pc'#'add.n.ph'#'add.n.type'#'add.n.email
call writeln( infile, line )
END
END
call close( infile )
address command
'sort 'addressbook' to t:temp'
'copy t:temp to 'addressbook
'delete t:temp quiet'
address
END
return
LoadBook :
ask = FALSE
IF addressbook = "" THEN ask = TRUE
IF ~Exists( addressbook ) THEN ask = TRUE
IF ask = TRUE THEN DO
addressbook = rtfilerequest( path, ,'Select a addressbook' , , 'rt_reqpos = reqpos_centerscr' )
END
IF open( infile, addressbook, 'r' ) THEN DO
n = 1
DO forever
line = readln( infile )
IF line = '' THEN leave
parse var line add.n.sname '#' add.n.fname '#' add.n.add '#' add.n.pc '#' add.n.ph '#' add.n.type '#' add.n.email
add.n.del = FALSE
n = n + 1
END
add.count = n - 1
call close( infile )
END; else DO
add.count = 0
END
return
ClearEntry :
settext name
settext surname
settext address
settext postcode
settext phone
setnum type 0
settext email
current = 0
set name surname address postcode phone type email update enable
set delete disable
settext new New Entry
return
DisplayEntry:
n = arg(1)
IF add.count = 0 THEN return
set forwards back enable
IF n >= add.count THEN DO
n = add.count
set Forwards disable
end
IF n <= 1 THEN do
n = 1
set back disable
end
current = n
settext name add.n.fname
settext surname add.n.sname
settext address add.n.add
settext postcode add.n.pc
settext phone add.n.ph
setnum type add.n.type
settext email add.n.email
IF add.n.del = TRUE THEN DO
set name surname address postcode phone type email update disable
END; else DO
set name surname address postcode phone type email update enable
END
set delete enable
if current ~=0 then settext new
return
updateentry:
busy set
read surname
nsurname = result
read name
nfname = result
read address
nadd = result
read postcode
npc = result
read phone
nph = result
read type
ntype = result
read email
nemail= result
IF current ~= 0 THEN DO
n = current
call DisplayEntry( n )
IF rtezrequest('Update this entry ?','Yes|No','Address Book',,
'rt_reqpos = reqpos_centerscr') = 1 THEN DO
add.n.sname = nsurname
add.n.fname = nfname
add.n.add = nadd
add.n.pc = npc
add.n.ph = nph
add.n.type = ntype
add.n.email = nemail
call DisplayEntry( n )
mod = TRUE
if liston = TRUE then call filllist()
busy
return
END
END
n = add.count + 1
IF rtezrequest('Add a new entry ?','Yes|No','Address Book',,
'rt_reqpos = reqpos_centerscr') = 1 THEN DO
add.n.sname = nsurname
add.n.fname = nfname
add.n.add = nadd
add.n.pc = npc
add.n.ph = nph
add.n.type = ntype
add.n.email = nemail
add.count = n
add.n.del = FALSE
call DisplayEntry( n )
mod = TRUE
END
if liston = TRUE then call filllist()
busy
return
DeleteEntry:
busy set
IF current = 0 THEN return
call DisplayEntry( current )
IF add.current.del = TRUE THEN DO
IF rtezrequest('Undelete this entry ?','Yes|No','Address Book',,
'rt_reqpos = reqpos_centerscr') = 1 THEN DO
add.current.del = FALSE
call DisplayEntry( current )
mod = TRUE
END
END; else DO
IF rtezrequest('Delete this entry ?','Yes|No','Address Book',,
'rt_reqpos = reqpos_centerscr') = 1 THEN DO
add.current.del = TRUE
call DisplayEntry( current )
mod = TRUE
END
END
busy
return
filllist:
drop t
DO n = 1 to add.count
t.n = add.n.fname add.n.sname
END
t.count = add.count
address value listhost
setlist list stem t clear
address value edithost
return
return
listentries:
address value listhost
show list
call filllist()
liston = TRUE
address value edithost
return
/* Error messages */
failure:
SAY "Error code" rc "-- Line" SIGL
SAY EXTERNERROR
'hide unload'
CALL CLOSEPORT ("HOLLY")
EXIT
syntax:
SAY "Error" rc "-- Line" SIGL
SAY ERRORTEXT( rc )
'hide unload'
CALL CLOSEPORT ("HOLLY")
EXIT