home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Fred Fish Collection 1.5
/
ffcollection-1-5-1992-11.iso
/
ff_disks
/
600-699
/
ff634.lha
/
APIG
/
apig33.lzh
/
addressbook.rexx
< prev
next >
Wrap
OS/2 REXX Batch file
|
1992-03-05
|
19KB
|
544 lines
/* Example of simple AddressBook Database */
/* Not perfect, could use some additional edit checks */
/* But you get the idea ... */
x = addlib("apig.library",0,-30,0) /* make the lib avaiable */
x = addlib("RexxRMF.library",0,-30,0) /* make the lib avaiable */
call SET_APIG_GLOBALS()
firstGADID = 1
lastGADID = 2
addrGADID = 3
cityGADID = 4
stateGADID = 5
zipGADID = 6
hmphGADID = 7
areaGADID = 8
workphGADID = 9
workareaGADID = 10
dobGADID = 11
cardGADID = 12
listGADID = 50
addGADID = 80
chgGADID = 90
delGADID = 100
addrrecord = " firstname lastname street city state zipcode areacode "
addrrecord = addrrecord "phonenumber dob sendcard wareacode wphonenumber"
/* the data file will be indexed on six fields */
/* index 0 - lastname - */
/* index 1 - state - */
/* index 2 - zipcode - */
/* index 3 - areacode - */
/* index 4 - dob - */
/* index 5 - sendcard - */
specialrba = " @rba *0treenode %nfields "
specialrecn = " =0recnum0 =1recnum1 =2recnum2 =3recnum3 =4recnum4 =5recnum5 "
specialoccr = " #0occr0 #1occr1 #2occr2 #3occr3 #4occr4 #5occr5 "
specialkey = " &0key0 &1key1 &2key2 &3key3 &4key4 &5key5 "
addrrecord = specialrba specialkey addrrecord specialrecn specialoccr
addrchange = specialrba specialkey addrrecord specialrecn specialoccr
addrdelete = specialrba specialkey addrrecord specialrecn specialoccr
ix = OPEN_RMF("addrbook")
if ix = '0000 0000'x then /* if NULL did not open */
do
say "Index did not open"
exit
end
call dowindow()
x = CLOSE_RMF(ix)
exit
/* -------------------------------------------------------- */
/* -------------------------------------------------------- */
addarecord: procedure expose addrrecord recnum0
parse arg ix,firstname,lastname,street,city,state,zipcode,phonenumber,
,areacode,dob,sendcard,wareacode,wphonenumber
if length(lastname) < 1 then return 0
treenode = null() /* treenode is returned as a special variable */
primekey = upper(lastname) /* gonna use upper case for our keys */
key1 = upper(state)
key2 = upper(zipcode)
key3 = upper(areacode)
key4 = upper(dob)
key5 = upper(sendcard)
x = WRITE_RMF_RECORD(ix,addrrecord,primekey,1,key1,2,key2,3,key3,4,key4,5,key5)
if x < 1 then return 0
call SET_DATA(treenode,0,lastname)
call SET_DATA(treenode,1,firstname)
return recnum0 /* recnum0 is returned as a special variable */
/* -------------------------------------------------------- */
/* -------------------------------------------------------- */
changearecord: procedure expose addrrecord recnum0
parse arg ix,updrecnum,firstname,lastname,street,city,state,zipcode,
,phonenumber,areacode,dob,sendcard,wareacode,wphonenumber
if length(lastname) < 1 then return 0
treenode = null() /* treenode is returned as a special variable */
primekey = upper(lastname) /* gonna use upper case for our keys */
key1 = upper(state)
key2 = upper(zipcode)
key3 = upper(areacode)
key4 = upper(dob)
key5 = upper(sendcard)
x = UPDATE_RMF_RECORD(ix,addrrecord,updrecnum,1,key1,2,key2,3,key3,4,key4,5,key5)
if x < 1 then return 0
call SET_DATA(treenode,0,lastname)
call SET_DATA(treenode,1,firstname)
return recnum0 /* recnum0 is returned as a special variable */
/* -------------------------------------------------------- */
/* -------------------------------------------------------- */
deletearecord: procedure expose addrrecord recnum0
parse arg ix,recordnum
x = DELETE_RMF_RECORD(ix,0,addrrecord,recordnum,'R')
return x
/* -------------------------------------------------------- */
/* -------------------------------------------------------- */
dowindow:
scr = LOCKPUBSCREEN("Workbench")
scrvinfo = GETVISUALINFO(scr)
scrfont = GETVALUE(scr,40,4,'p')
glistpointer = ALLOCVEC(4,MEMF_CLEAR)
conxgad = CREATECONTEXT(glistpointer)
previousgadget = conxgad
newgadx = MAKENEWGADGET(scrvinfo,scrfont,65,20,145,12,"First:",
,PLACETEXT_LEFT,firstGADID,null())
previousgadget = CREATEGADGET(STRING_KIND,previousgadget,newgadx,
,GTST_MAXCHARS,20,TAG_DONE,0)
call SETNEWGADGET(newgadx,scrvinfo,scrfont,65,32,145,12,"Last:",
,PLACETEXT_LEFT,lastGADID,null())
previousgadget = CREATEGADGET(STRING_KIND,previousgadget,newgadx,
,GTST_MAXCHARS,20,TAG_DONE,0)
call SETNEWGADGET(newgadx,scrvinfo,scrfont,65,44,145,12,"Addr:",
,PLACETEXT_LEFT,addrGADID,null())
previousgadget = CREATEGADGET(STRING_KIND,previousgadget,newgadx,
,GTST_MAXCHARS,20,TAG_DONE,0)
call SETNEWGADGET(newgadx,scrvinfo,scrfont,65,56,145,12,"City:",
,PLACETEXT_LEFT,cityGADID,null())
previousgadget = CREATEGADGET(STRING_KIND,previousgadget,newgadx,
,GTST_MAXCHARS,20,TAG_DONE,0)
call SETNEWGADGET(newgadx,scrvinfo,scrfont,65,68,145,12,"State:",
,PLACETEXT_LEFT,stateGADID,null())
previousgadget = CREATEGADGET(STRING_KIND,previousgadget,newgadx,
,GTST_MAXCHARS,20,TAG_DONE,0)
call SETNEWGADGET(newgadx,scrvinfo,scrfont,65,80,145,12,"Zip:",
,PLACETEXT_LEFT,zipGADID,null())
previousgadget = CREATEGADGET(STRING_KIND,previousgadget,newgadx,
,GTST_MAXCHARS,20,TAG_DONE,0)
call SETNEWGADGET(newgadx,scrvinfo,scrfont,65,92,51,12,"Hm. Ph:",
,PLACETEXT_LEFT,areaGADID,null())
previousgadget = CREATEGADGET(STRING_KIND,previousgadget,newgadx,
,GTST_MAXCHARS,3,TAG_DONE,0)
call SETNEWGADGET(newgadx,scrvinfo,scrfont,116,92,94,12,"",
,0,hmphGADID,null())
previousgadget = CREATEGADGET(STRING_KIND,previousgadget,newgadx,
,GTST_MAXCHARS,20,TAG_DONE,0)
call SETNEWGADGET(newgadx,scrvinfo,scrfont,65,104,51,12,"Wk. Ph:",
,PLACETEXT_LEFT,workareaGADID,null())
previousgadget = CREATEGADGET(STRING_KIND,previousgadget,newgadx,
,GTST_MAXCHARS,3,TAG_DONE,0)
call SETNEWGADGET(newgadx,scrvinfo,scrfont,116,104,94,12,"",
,0,workphGADID,null())
previousgadget = CREATEGADGET(STRING_KIND,previousgadget,newgadx,
,GTST_MAXCHARS,20,TAG_DONE,0)
call SETNEWGADGET(newgadx,scrvinfo,scrfont,65,116,145,12,"dob:",
,PLACETEXT_LEFT,dobGADID,null())
previousgadget = CREATEGADGET(STRING_KIND,previousgadget,newgadx,
,GTST_MAXCHARS,12,TAG_DONE,0)
call SETNEWGADGET(newgadx,scrvinfo,scrfont,65,128,245,12,"card:",
,PLACETEXT_LEFT,cardGADID,null())
previousgadget = CREATEGADGET(STRING_KIND,previousgadget,newgadx,
,GTST_MAXCHARS,3,TAG_DONE,0)
mylist = allocmem(14,MEMF_CLEAR)
call NEWLIST(mylist)
treenode = null()
do i = 1 to 200
x = READ_RMF_RECORD(ix,0,addrrecord,i,'R')
if x = 0 then leave
if treenode = null() then leave
call SET_DATA(treenode,0,lastname)
call SET_DATA(treenode,1,firstname)
lstring = lastname || ', ' || firstname
lnode = ADD_LIST_NODE(mylist,lstring)
end
call SETNEWGADGET(newgadx,scrvinfo,scrfont,320,20,195,120," PHONE LIST ",
,PLACETEXT_ABOVE,listGADID,null())
previousgadget = CREATEGADGET(LISTVIEW_KIND,previousgadget,newgadx,
,GTLV_LABELS,mylist,LAYOUTA_SPACING,3,
,GTLV_ShowSelected,null(),TAG_DONE,0)
lvgad = previousgadget
call SETNEWGADGET(newgadx,scrvinfo,scrfont,233,45,64,12,"ADD",
,PLACETEXT_IN,addGADID,null())
previousgadget = CREATEGADGET(BUTTON_KIND,previousgadget,newgadx,
,GTST_MAXCHARS,20,TAG_DONE,0)
call SETNEWGADGET(newgadx,scrvinfo,scrfont,233,77,64,12,"CHG",
,PLACETEXT_IN,chgGADID,null())
previousgadget = CREATEGADGET(BUTTON_KIND,previousgadget,newgadx,
,GTST_MAXCHARS,20,TAG_DONE,0)
call SETNEWGADGET(newgadx,scrvinfo,scrfont,233,109,64,12,"DEL",
,PLACETEXT_IN,delGADID,null())
previousgadget = CREATEGADGET(BUTTON_KIND,previousgadget,newgadx,
,GTST_MAXCHARS,20,TAG_DONE,0)
wintitle = "APIG PHONEBOOK"
winidcmp = CLOSEWINDOW+GADGETUP+GADGETDOWN+MOUSEMOVE
winflags = WINDOWCLOSE+WINDOWDRAG+WINDOWSIZING+WINDOWDEPTH+GIMMEZEROZERO,
+ACTIVATE
/* open window */
portname = "apigaddrbook_port"
p = openport(portname)
w1 = OPENWINDOW(portname,0,30,640,200,2,4,winidcmp,winflags,wintitle,
,scr,0,null(),null(),conxgad)
call GT_REFRESHWINDOW(w1,null())
rpw1 = GETWINDOWRASTPORT(w1)
exitme = 0
do while exitme = 0
x = waitpkt(portname)
do forever
msg = getpkt(portname)
if msg = '0000 0000'x then leave
msgclass = getarg(msg,0)
msgcode = getarg(msg,1)
msgqual = getarg(msg,2)
msgmx = getarg(msg,3)
msgmy = getarg(msg,4)
msgsecs = getarg(msg,5)
msgmics = getarg(msg,6)
msgwinadr = getarg(msg,7)
msggadadr = getarg(msg,8)
msggadid = getarg(msg,9)
x = reply(msg,0)
/*
say "class =" msgclass
say "code =" msgcode
say "qual =" msgqual
say "mx =" msgmx
say "my =" msgmy
say "secs =" msgsecs
say "mics =" msgmics
say "winadr =" c2x(msgwinadr)
say "gadadr =" c2x(msggadadr)
say "gadid =" msggadid
*/
select
when msgclass = CLOSEWINDOW then exitme = 1
when msgclass = GADGETUP then
do
select
when msggadid = listGADID then
do
firstname = ''
lastname = ''
street = ''
city = ''
state = ''
zipcode = ''
phonenumber = ''
areacode = ''
dob = ''
sendcard = ''
wareacode = ''
wphonenumber = ''
recn = msgcode + 1
x = READ_RMF_RECORD(ix,0,addrrecord,recn,'R')
if x = 1 then
do
call SETSTRGADID(w1,firstGADID,firstname,null())
call SETSTRGADID(w1,lastGADID,lastname,null())
call SETSTRGADID(w1,addrGADID,street,null())
call SETSTRGADID(w1,cityGADID,city,null())
call SETSTRGADID(w1,stateGADID,state,null())
call SETSTRGADID(w1,zipGADID,zipcode,null())
call SETSTRGADID(w1,hmphGADID,phonenumber,null())
call SETSTRGADID(w1,areaGADID,areacode,null())
call SETSTRGADID(w1,dobGADID,dob,null())
call SETSTRGADID(w1,cardGADID,sendcard,null())
call SETSTRGADID(w1,workareaGADID,wareacode,null())
call SETSTRGADID(w1,workphGADID,wphonenumber,null())
call REFRESHGLIST(conxgad,w1,null(),-1)
end
end
when msggadid = chgGADID then
do
if recn > 0 then
do
fnode = mylist
do x = 1 to recn
fnode = next(fnode)
end
call GT_SETGADGETATTRS(lvgad,w1,null(),
,GTLV_Labels,'ffffffff'x,
,TAG_DONE,0)
call REMOVE(fnode)
call FREE_EXEC_NODE(fnode)
end
firstname = GETSTRGAD(w1,firstGADID,null())
lastname = GETSTRGAD(w1,lastGADID,null())
street = GETSTRGAD(w1,addrGADID,null())
city = GETSTRGAD(w1,cityGADID,null())
state = GETSTRGAD(w1,stateGADID,null())
zipcode = GETSTRGAD(w1,zipGADID,null())
phonenumber = GETSTRGAD(w1,hmphGADID,null())
areacode = GETSTRGAD(w1,areaGADID,null())
dob = GETSTRGAD(w1,dobGADID,null())
sendcard = GETSTRGAD(w1,cardGADID,null())
wareacode = GETSTRGAD(w1,workareaGADID,null())
wphonenumber = GETSTRGAD(w1,workphGADID,null())
nr = changearecord(ix,recn,firstname,lastname,street,
,city,state,zipcode,phonenumber,
,areacode,dob,sendcard,wareacode,
,wphonenumber)
if nr > 0 then
do
lstring = lastname || ', ' || firstname
lnode = ADD_LIST_NODE(mylist,lstring,nr,0,nr)
recn = nr - 1
end
call GT_SETGADGETATTRS(lvgad,w1,null(),
,GTLV_Labels,mylist,
,GTLV_Top,recn,
,GTLV_Selected,recn,
,TAG_DONE,0)
call REFRESHGLIST(conxgad,w1,null(),-1)
end
when msggadid = delGADID then
do
if recn > 0 then
do
fnode = mylist
do x = 1 to recn
fnode = next(fnode)
end
call GT_SETGADGETATTRS(lvgad,w1,null(),
,GTLV_Labels,'ffffffff'x,
,TAG_DONE,0)
call REMOVE(fnode)
call FREE_EXEC_NODE(fnode)
call deletearecord(ix,recn)
nr = recn - 1
x = READ_RMF_RECORD(ix,0,addrrecord,nr,'R')
call SETSTRGADID(w1,firstGADID,firstname,null())
call SETSTRGADID(w1,lastGADID,lastname,null())
call SETSTRGADID(w1,addrGADID,street,null())
call SETSTRGADID(w1,cityGADID,city,null())
call SETSTRGADID(w1,stateGADID,state,null())
call SETSTRGADID(w1,zipGADID,zipcode,null())
call SETSTRGADID(w1,hmphGADID,phonenumber,null())
call SETSTRGADID(w1,areaGADID,areacode,null())
call SETSTRGADID(w1,dobGADID,dob,null())
call SETSTRGADID(w1,cardGADID,sendcard,null())
call SETSTRGADID(w1,workareaGADID,wareacode,null())
call SETSTRGADID(w1,workphGADID,wphonenumber,null())
if nr > 0 then
nr = nr - 1
call GT_SETGADGETATTRS(lvgad,w1,null(),
,GTLV_Labels,mylist,
,GTLV_Top,nr,
,GTLV_Selected,nr,
,TAG_DONE,0)
call REFRESHGLIST(conxgad,w1,null(),-1)
end
end
when msggadid = addGADID then
do
firstname = GETSTRGAD(w1,firstGADID,null())
lastname = GETSTRGAD(w1,lastGADID,null())
street = GETSTRGAD(w1,addrGADID,null())
city = GETSTRGAD(w1,cityGADID,null())
state = GETSTRGAD(w1,stateGADID,null())
zipcode = GETSTRGAD(w1,zipGADID,null())
phonenumber = GETSTRGAD(w1,hmphGADID,null())
areacode = GETSTRGAD(w1,areaGADID,null())
dob = GETSTRGAD(w1,dobGADID,null())
sendcard = GETSTRGAD(w1,cardGADID,null())
wareacode = GETSTRGAD(w1,workareaGADID,null())
wphonenumber = GETSTRGAD(w1,workphGADID,null())
nr = addarecord(ix,firstname,lastname,street,
,city,state,zipcode,phonenumber,
,areacode,dob,sendcard,wareacode,
,wphonenumber)
if nr > 0 then
do
call GT_SETGADGETATTRS(lvgad,w1,null(),
,GTLV_Labels,'ffffffff'x,
,TAG_DONE,0)
lstring = lastname || ', ' || firstname
lnode = ADD_LIST_NODE(mylist,lstring,nr,0,nr)
call GT_SETGADGETATTRS(lvgad,w1,null(),
,GTLV_Labels,mylist,
,GTLV_Top,(nr-1),
,GTLV_Selected,(nr-1),
,TAG_DONE,0)
call REFRESHGLIST(conxgad,w1,null(),-1)
end
end
otherwise nop
end
end
otherwise nop
end
end
if exitme = 1 then leave
end
call CLOSEWINDOW(w1)
call FREEGADGETS(conxgad)
call FREETHIS(newgadx)
call FREEVEC(glistpointer)
call FREE_EXEC_LIST(mylist)
return 1
loaddatafile: procedure expose ix addrrecord
treenode = null()
do forever
x = open(infile,"datafile",'R')
line = readln(infile)
if eof(infile) = 1 then leave
parse var line firstname ',' lastname ',' street ',' city ',' state ',',
zipcode ',' areacode ',' phonenumber ',' dob ',' sendcard
wareacode = "000"
wphonenumber = "000-0000"
primekey = upper(lastname)
statekey = upper(state)
sendkey = upper(sendcard)
x = WRITE_RMF_RECORD(ix,addrrecord,primekey,1,statekey,2,zipcode,
,3,areacode,4,dob,5,sendkey)
call SET_DATA(treenode,0,lastname)
call SET_DATA(treenode,1,firstname)
end
x = close(infile)
return 1