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 >
OS/2 REXX Batch file  |  1992-03-05  |  19KB  |  544 lines

  1.  
  2. /* Example of simple AddressBook Database             */
  3. /* Not perfect, could use some additional edit checks */
  4. /* But you get the idea ...                           */
  5.  
  6. x = addlib("apig.library",0,-30,0)     /* make the lib avaiable */
  7.  
  8. x = addlib("RexxRMF.library",0,-30,0)  /* make the lib avaiable */
  9.  
  10. call SET_APIG_GLOBALS()
  11.  
  12. firstGADID    = 1
  13. lastGADID     = 2
  14. addrGADID     = 3
  15. cityGADID     = 4
  16. stateGADID    = 5
  17. zipGADID      = 6
  18. hmphGADID     = 7
  19. areaGADID     = 8
  20. workphGADID   = 9
  21. workareaGADID = 10
  22. dobGADID      = 11
  23. cardGADID     = 12
  24. listGADID     = 50
  25. addGADID      = 80
  26. chgGADID      = 90
  27. delGADID      = 100
  28.  
  29. addrrecord = " firstname lastname street city state zipcode areacode " 
  30. addrrecord = addrrecord "phonenumber dob sendcard wareacode wphonenumber"
  31.  
  32. /* the data file will be indexed on six fields */
  33. /* index 0 - lastname - */
  34. /* index 1 - state    - */
  35. /* index 2 - zipcode  - */
  36. /* index 3 - areacode - */
  37. /* index 4 - dob      - */
  38. /* index 5 - sendcard - */
  39.  
  40. specialrba  = " @rba *0treenode %nfields "
  41. specialrecn = " =0recnum0 =1recnum1 =2recnum2 =3recnum3 =4recnum4 =5recnum5 "
  42.  
  43. specialoccr = " #0occr0 #1occr1 #2occr2 #3occr3 #4occr4 #5occr5 "
  44.  
  45. specialkey  = " &0key0 &1key1 &2key2 &3key3 &4key4 &5key5 "
  46.  
  47. addrrecord  = specialrba specialkey addrrecord specialrecn specialoccr 
  48. addrchange  = specialrba specialkey addrrecord specialrecn specialoccr 
  49. addrdelete  = specialrba specialkey addrrecord specialrecn specialoccr 
  50.  
  51. ix = OPEN_RMF("addrbook")
  52. if ix = '0000 0000'x then  /* if NULL did not open */
  53.    do
  54.       say "Index did not open"
  55.       exit
  56.    end
  57.    
  58. call dowindow()
  59.  
  60. x = CLOSE_RMF(ix)
  61.  
  62. exit
  63.  
  64. /* -------------------------------------------------------- */
  65. /* -------------------------------------------------------- */
  66.  
  67. addarecord: procedure expose addrrecord recnum0
  68.  
  69. parse arg ix,firstname,lastname,street,city,state,zipcode,phonenumber,
  70.           ,areacode,dob,sendcard,wareacode,wphonenumber
  71.  
  72. if length(lastname) < 1 then  return 0
  73.  
  74. treenode  = null()          /* treenode is returned as a special variable */
  75.  
  76. primekey  = upper(lastname) /* gonna use upper case for our keys */
  77.  
  78. key1      = upper(state)
  79. key2      = upper(zipcode)
  80. key3      = upper(areacode)
  81. key4      = upper(dob)
  82. key5      = upper(sendcard)
  83.  
  84. x = WRITE_RMF_RECORD(ix,addrrecord,primekey,1,key1,2,key2,3,key3,4,key4,5,key5)
  85. if x < 1 then return 0
  86.  
  87. call SET_DATA(treenode,0,lastname)
  88. call SET_DATA(treenode,1,firstname)
  89.  
  90. return recnum0              /* recnum0 is returned as a special variable */
  91.  
  92. /* -------------------------------------------------------- */
  93. /* -------------------------------------------------------- */
  94.  
  95. changearecord: procedure expose addrrecord recnum0
  96.  
  97. parse arg ix,updrecnum,firstname,lastname,street,city,state,zipcode,
  98.           ,phonenumber,areacode,dob,sendcard,wareacode,wphonenumber
  99.  
  100. if length(lastname) < 1 then  return 0
  101.  
  102. treenode  = null()          /* treenode is returned as a special variable */
  103.  
  104. primekey  = upper(lastname) /* gonna use upper case for our keys */
  105.  
  106. key1      = upper(state)
  107. key2      = upper(zipcode)
  108. key3      = upper(areacode)
  109. key4      = upper(dob)
  110. key5      = upper(sendcard)
  111.  
  112. x = UPDATE_RMF_RECORD(ix,addrrecord,updrecnum,1,key1,2,key2,3,key3,4,key4,5,key5) 
  113. if x < 1 then return 0
  114.  
  115. call SET_DATA(treenode,0,lastname)
  116. call SET_DATA(treenode,1,firstname)
  117.  
  118. return recnum0              /* recnum0 is returned as a special variable */
  119.  
  120. /* -------------------------------------------------------- */
  121. /* -------------------------------------------------------- */
  122.  
  123. deletearecord: procedure expose addrrecord recnum0
  124.  
  125. parse arg ix,recordnum
  126.  
  127. x = DELETE_RMF_RECORD(ix,0,addrrecord,recordnum,'R')
  128.  
  129. return x
  130.  
  131. /* -------------------------------------------------------- */
  132. /* -------------------------------------------------------- */
  133.  
  134. dowindow:
  135.  
  136. scr          = LOCKPUBSCREEN("Workbench")
  137. scrvinfo     = GETVISUALINFO(scr)
  138. scrfont      = GETVALUE(scr,40,4,'p')
  139. glistpointer = ALLOCVEC(4,MEMF_CLEAR)
  140.  
  141. conxgad      = CREATECONTEXT(glistpointer)
  142.  
  143. previousgadget = conxgad
  144.  
  145.  
  146. newgadx = MAKENEWGADGET(scrvinfo,scrfont,65,20,145,12,"First:",
  147.                         ,PLACETEXT_LEFT,firstGADID,null())
  148.  
  149. previousgadget = CREATEGADGET(STRING_KIND,previousgadget,newgadx,
  150.                                  ,GTST_MAXCHARS,20,TAG_DONE,0)
  151.  
  152. call SETNEWGADGET(newgadx,scrvinfo,scrfont,65,32,145,12,"Last:",
  153.                   ,PLACETEXT_LEFT,lastGADID,null())
  154.  
  155. previousgadget = CREATEGADGET(STRING_KIND,previousgadget,newgadx,
  156.                                  ,GTST_MAXCHARS,20,TAG_DONE,0)
  157.  
  158. call SETNEWGADGET(newgadx,scrvinfo,scrfont,65,44,145,12,"Addr:",
  159.                   ,PLACETEXT_LEFT,addrGADID,null())
  160.  
  161. previousgadget = CREATEGADGET(STRING_KIND,previousgadget,newgadx,
  162.                                  ,GTST_MAXCHARS,20,TAG_DONE,0)
  163.  
  164. call SETNEWGADGET(newgadx,scrvinfo,scrfont,65,56,145,12,"City:",
  165.                   ,PLACETEXT_LEFT,cityGADID,null())
  166.  
  167. previousgadget = CREATEGADGET(STRING_KIND,previousgadget,newgadx,
  168.                                  ,GTST_MAXCHARS,20,TAG_DONE,0)
  169.  
  170. call SETNEWGADGET(newgadx,scrvinfo,scrfont,65,68,145,12,"State:",
  171.                   ,PLACETEXT_LEFT,stateGADID,null())
  172.  
  173. previousgadget = CREATEGADGET(STRING_KIND,previousgadget,newgadx,
  174.                                  ,GTST_MAXCHARS,20,TAG_DONE,0)
  175.  
  176. call SETNEWGADGET(newgadx,scrvinfo,scrfont,65,80,145,12,"Zip:",
  177.                   ,PLACETEXT_LEFT,zipGADID,null())
  178.  
  179. previousgadget = CREATEGADGET(STRING_KIND,previousgadget,newgadx,
  180.                                  ,GTST_MAXCHARS,20,TAG_DONE,0)
  181.  
  182. call SETNEWGADGET(newgadx,scrvinfo,scrfont,65,92,51,12,"Hm. Ph:",
  183.                   ,PLACETEXT_LEFT,areaGADID,null())
  184.  
  185. previousgadget = CREATEGADGET(STRING_KIND,previousgadget,newgadx,
  186.                                  ,GTST_MAXCHARS,3,TAG_DONE,0)
  187.  
  188. call SETNEWGADGET(newgadx,scrvinfo,scrfont,116,92,94,12,"",
  189.                   ,0,hmphGADID,null())
  190.  
  191. previousgadget = CREATEGADGET(STRING_KIND,previousgadget,newgadx,
  192.                                  ,GTST_MAXCHARS,20,TAG_DONE,0)
  193.  
  194. call SETNEWGADGET(newgadx,scrvinfo,scrfont,65,104,51,12,"Wk. Ph:",
  195.                   ,PLACETEXT_LEFT,workareaGADID,null())
  196.  
  197. previousgadget = CREATEGADGET(STRING_KIND,previousgadget,newgadx,
  198.                                  ,GTST_MAXCHARS,3,TAG_DONE,0)
  199.  
  200. call SETNEWGADGET(newgadx,scrvinfo,scrfont,116,104,94,12,"",
  201.                   ,0,workphGADID,null())
  202.  
  203. previousgadget = CREATEGADGET(STRING_KIND,previousgadget,newgadx,
  204.                                  ,GTST_MAXCHARS,20,TAG_DONE,0)
  205.  
  206. call SETNEWGADGET(newgadx,scrvinfo,scrfont,65,116,145,12,"dob:",
  207.                   ,PLACETEXT_LEFT,dobGADID,null())
  208.  
  209. previousgadget = CREATEGADGET(STRING_KIND,previousgadget,newgadx,
  210.                                  ,GTST_MAXCHARS,12,TAG_DONE,0)
  211.  
  212. call SETNEWGADGET(newgadx,scrvinfo,scrfont,65,128,245,12,"card:",
  213.                   ,PLACETEXT_LEFT,cardGADID,null())
  214.  
  215. previousgadget = CREATEGADGET(STRING_KIND,previousgadget,newgadx,
  216.                                  ,GTST_MAXCHARS,3,TAG_DONE,0)
  217.  
  218. mylist = allocmem(14,MEMF_CLEAR)
  219. call NEWLIST(mylist)
  220. treenode = null()
  221. do i = 1 to 200
  222.    x = READ_RMF_RECORD(ix,0,addrrecord,i,'R') 
  223.    if x = 0 then leave
  224.    if treenode = null() then leave
  225.    call SET_DATA(treenode,0,lastname)
  226.    call SET_DATA(treenode,1,firstname)
  227.    lstring = lastname || ', ' || firstname 
  228.    lnode = ADD_LIST_NODE(mylist,lstring)
  229. end
  230.  
  231. call SETNEWGADGET(newgadx,scrvinfo,scrfont,320,20,195,120," PHONE LIST ",
  232.                   ,PLACETEXT_ABOVE,listGADID,null())
  233.  
  234. previousgadget = CREATEGADGET(LISTVIEW_KIND,previousgadget,newgadx,
  235.                                  ,GTLV_LABELS,mylist,LAYOUTA_SPACING,3,
  236.                                  ,GTLV_ShowSelected,null(),TAG_DONE,0)
  237. lvgad = previousgadget
  238.  
  239.  
  240.  
  241. call SETNEWGADGET(newgadx,scrvinfo,scrfont,233,45,64,12,"ADD",
  242.                   ,PLACETEXT_IN,addGADID,null())
  243.  
  244. previousgadget = CREATEGADGET(BUTTON_KIND,previousgadget,newgadx,
  245.                                  ,GTST_MAXCHARS,20,TAG_DONE,0)
  246.  
  247. call SETNEWGADGET(newgadx,scrvinfo,scrfont,233,77,64,12,"CHG",
  248.                   ,PLACETEXT_IN,chgGADID,null())
  249.  
  250. previousgadget = CREATEGADGET(BUTTON_KIND,previousgadget,newgadx,
  251.                                  ,GTST_MAXCHARS,20,TAG_DONE,0)
  252.  
  253. call SETNEWGADGET(newgadx,scrvinfo,scrfont,233,109,64,12,"DEL",
  254.                   ,PLACETEXT_IN,delGADID,null())
  255.  
  256. previousgadget = CREATEGADGET(BUTTON_KIND,previousgadget,newgadx,
  257.                                  ,GTST_MAXCHARS,20,TAG_DONE,0)
  258.  
  259. wintitle = "APIG PHONEBOOK"
  260. winidcmp = CLOSEWINDOW+GADGETUP+GADGETDOWN+MOUSEMOVE
  261. winflags = WINDOWCLOSE+WINDOWDRAG+WINDOWSIZING+WINDOWDEPTH+GIMMEZEROZERO,
  262.            +ACTIVATE
  263.  
  264. /* open window */
  265.  
  266. portname = "apigaddrbook_port"
  267.  
  268. p = openport(portname)
  269.  
  270. w1  = OPENWINDOW(portname,0,30,640,200,2,4,winidcmp,winflags,wintitle,
  271.                  ,scr,0,null(),null(),conxgad)
  272.  
  273. call GT_REFRESHWINDOW(w1,null())
  274.  
  275. rpw1 = GETWINDOWRASTPORT(w1) 
  276.  
  277. exitme = 0
  278. do while exitme = 0
  279.  
  280.      x = waitpkt(portname)
  281.      do forever 
  282.   
  283.         msg = getpkt(portname)
  284.         if msg = '0000 0000'x then leave
  285.  
  286.         msgclass  = getarg(msg,0)
  287.         msgcode   = getarg(msg,1)
  288.         msgqual   = getarg(msg,2)
  289.         msgmx     = getarg(msg,3)
  290.         msgmy     = getarg(msg,4)
  291.         msgsecs   = getarg(msg,5)
  292.         msgmics   = getarg(msg,6)
  293.         msgwinadr = getarg(msg,7)
  294.         msggadadr = getarg(msg,8)
  295.         msggadid  = getarg(msg,9)
  296.  
  297.         x = reply(msg,0)  
  298.         /*
  299.         say "class  =" msgclass
  300.         say "code   =" msgcode 
  301.         say "qual   =" msgqual 
  302.         say "mx     =" msgmx   
  303.         say "my     =" msgmy   
  304.         say "secs   =" msgsecs 
  305.         say "mics   =" msgmics 
  306.         say "winadr =" c2x(msgwinadr)
  307.         say "gadadr =" c2x(msggadadr)
  308.         say "gadid  =" msggadid 
  309.         */
  310.  
  311.        select
  312.  
  313.            when msgclass = CLOSEWINDOW then exitme = 1
  314.  
  315.            when msgclass = GADGETUP then
  316.              do
  317.  
  318.                select
  319.  
  320.                  when msggadid = listGADID then
  321.                    do
  322.                       firstname = ''
  323.                       lastname = ''
  324.                       street = ''
  325.                       city = ''
  326.                       state = ''
  327.                       zipcode = ''
  328.                       phonenumber = ''
  329.                       areacode = ''
  330.                       dob = ''
  331.                       sendcard = ''
  332.                       wareacode = ''
  333.                       wphonenumber = ''
  334.  
  335.                       recn = msgcode + 1
  336.                       x = READ_RMF_RECORD(ix,0,addrrecord,recn,'R')
  337.                       if x = 1 then 
  338.                          do
  339.                             call SETSTRGADID(w1,firstGADID,firstname,null())
  340.                             call SETSTRGADID(w1,lastGADID,lastname,null())
  341.                             call SETSTRGADID(w1,addrGADID,street,null())
  342.                             call SETSTRGADID(w1,cityGADID,city,null())
  343.                             call SETSTRGADID(w1,stateGADID,state,null())
  344.                             call SETSTRGADID(w1,zipGADID,zipcode,null())
  345.                             call SETSTRGADID(w1,hmphGADID,phonenumber,null())
  346.                             call SETSTRGADID(w1,areaGADID,areacode,null())
  347.                             call SETSTRGADID(w1,dobGADID,dob,null())
  348.                             call SETSTRGADID(w1,cardGADID,sendcard,null())
  349.                             call SETSTRGADID(w1,workareaGADID,wareacode,null())
  350.                             call SETSTRGADID(w1,workphGADID,wphonenumber,null())
  351.                             call REFRESHGLIST(conxgad,w1,null(),-1)
  352.                          end
  353.                    end
  354.  
  355.                  when msggadid = chgGADID then
  356.                    do
  357.                        if recn > 0 then
  358.                           do
  359.                               fnode = mylist
  360.                               do x = 1 to recn
  361.                                   fnode = next(fnode)
  362.                               end
  363.                               call GT_SETGADGETATTRS(lvgad,w1,null(),
  364.                                                      ,GTLV_Labels,'ffffffff'x,
  365.                                                      ,TAG_DONE,0)
  366.                               call REMOVE(fnode)
  367.                               call FREE_EXEC_NODE(fnode)
  368.                           end
  369.  
  370.                        firstname    = GETSTRGAD(w1,firstGADID,null())
  371.                        lastname     = GETSTRGAD(w1,lastGADID,null())
  372.                        street       = GETSTRGAD(w1,addrGADID,null())
  373.                        city         = GETSTRGAD(w1,cityGADID,null())
  374.                        state        = GETSTRGAD(w1,stateGADID,null())
  375.                        zipcode      = GETSTRGAD(w1,zipGADID,null())
  376.                        phonenumber  = GETSTRGAD(w1,hmphGADID,null())
  377.                        areacode     = GETSTRGAD(w1,areaGADID,null())
  378.                        dob          = GETSTRGAD(w1,dobGADID,null())
  379.                        sendcard     = GETSTRGAD(w1,cardGADID,null())
  380.                        wareacode    = GETSTRGAD(w1,workareaGADID,null())
  381.                        wphonenumber = GETSTRGAD(w1,workphGADID,null())
  382.  
  383.                        nr = changearecord(ix,recn,firstname,lastname,street,
  384.                                        ,city,state,zipcode,phonenumber,
  385.                                        ,areacode,dob,sendcard,wareacode,
  386.                                        ,wphonenumber)
  387.  
  388.                        if nr > 0 then
  389.                           do
  390.                               lstring = lastname || ', ' || firstname
  391.                               lnode = ADD_LIST_NODE(mylist,lstring,nr,0,nr)
  392.                               recn = nr - 1
  393.                           end
  394.  
  395.                        call GT_SETGADGETATTRS(lvgad,w1,null(),
  396.                                               ,GTLV_Labels,mylist,
  397.                                               ,GTLV_Top,recn,
  398.                                               ,GTLV_Selected,recn,
  399.                                               ,TAG_DONE,0)
  400.  
  401.                        call REFRESHGLIST(conxgad,w1,null(),-1)
  402.  
  403.                    end
  404.  
  405.                  when msggadid = delGADID then
  406.                    do
  407.                        if recn > 0 then
  408.                           do
  409.                               fnode = mylist
  410.                               do x = 1 to recn
  411.                                   fnode = next(fnode)
  412.                               end
  413.                               call GT_SETGADGETATTRS(lvgad,w1,null(),
  414.                                                      ,GTLV_Labels,'ffffffff'x,
  415.                                                      ,TAG_DONE,0)
  416.                               call REMOVE(fnode)
  417.                               call FREE_EXEC_NODE(fnode)
  418.  
  419.                               call deletearecord(ix,recn)
  420.  
  421.  
  422.                               nr = recn - 1
  423.                               x = READ_RMF_RECORD(ix,0,addrrecord,nr,'R')
  424.                               call SETSTRGADID(w1,firstGADID,firstname,null())
  425.                               call SETSTRGADID(w1,lastGADID,lastname,null())
  426.                               call SETSTRGADID(w1,addrGADID,street,null())
  427.                               call SETSTRGADID(w1,cityGADID,city,null())
  428.                               call SETSTRGADID(w1,stateGADID,state,null())
  429.                               call SETSTRGADID(w1,zipGADID,zipcode,null())
  430.                               call SETSTRGADID(w1,hmphGADID,phonenumber,null())
  431.                               call SETSTRGADID(w1,areaGADID,areacode,null())
  432.                               call SETSTRGADID(w1,dobGADID,dob,null())
  433.                               call SETSTRGADID(w1,cardGADID,sendcard,null())
  434.                               call SETSTRGADID(w1,workareaGADID,wareacode,null())
  435.                               call SETSTRGADID(w1,workphGADID,wphonenumber,null())
  436.  
  437.                               if nr > 0 then
  438.                                  nr = nr - 1 
  439.  
  440.                               call GT_SETGADGETATTRS(lvgad,w1,null(),
  441.                                                      ,GTLV_Labels,mylist,
  442.                                                      ,GTLV_Top,nr,
  443.                                                      ,GTLV_Selected,nr,
  444.                                                      ,TAG_DONE,0)
  445.  
  446.                               call REFRESHGLIST(conxgad,w1,null(),-1)
  447.                           end
  448.  
  449.                    end
  450.  
  451.                  when msggadid = addGADID then
  452.                    do
  453.                        firstname    = GETSTRGAD(w1,firstGADID,null())
  454.                        lastname     = GETSTRGAD(w1,lastGADID,null())
  455.                        street       = GETSTRGAD(w1,addrGADID,null())
  456.                        city         = GETSTRGAD(w1,cityGADID,null())
  457.                        state        = GETSTRGAD(w1,stateGADID,null())
  458.                        zipcode      = GETSTRGAD(w1,zipGADID,null())
  459.                        phonenumber  = GETSTRGAD(w1,hmphGADID,null())
  460.                        areacode     = GETSTRGAD(w1,areaGADID,null())
  461.                        dob          = GETSTRGAD(w1,dobGADID,null())
  462.                        sendcard     = GETSTRGAD(w1,cardGADID,null())
  463.                        wareacode    = GETSTRGAD(w1,workareaGADID,null())
  464.                        wphonenumber = GETSTRGAD(w1,workphGADID,null())
  465.  
  466.                        nr = addarecord(ix,firstname,lastname,street,
  467.                                        ,city,state,zipcode,phonenumber,
  468.                                        ,areacode,dob,sendcard,wareacode,
  469.                                        ,wphonenumber)
  470.  
  471.                        if nr > 0 then
  472.                           do
  473.                               call GT_SETGADGETATTRS(lvgad,w1,null(),
  474.                                                      ,GTLV_Labels,'ffffffff'x,
  475.                                                      ,TAG_DONE,0)
  476.  
  477.                               lstring = lastname || ', ' || firstname
  478.                               lnode = ADD_LIST_NODE(mylist,lstring,nr,0,nr)
  479.  
  480.                               call GT_SETGADGETATTRS(lvgad,w1,null(),
  481.                                                      ,GTLV_Labels,mylist,
  482.                                                      ,GTLV_Top,(nr-1),
  483.                                                      ,GTLV_Selected,(nr-1),
  484.                                                      ,TAG_DONE,0)
  485.  
  486.                               call REFRESHGLIST(conxgad,w1,null(),-1)
  487.                           end
  488.                    end
  489.                    otherwise nop
  490.                end
  491.  
  492.              end
  493.              otherwise nop
  494.         end
  495.         
  496.      end  
  497.    if exitme = 1 then leave
  498. end
  499.  
  500. call CLOSEWINDOW(w1)
  501.  
  502. call FREEGADGETS(conxgad)
  503.  
  504. call FREETHIS(newgadx)
  505.  
  506. call FREEVEC(glistpointer)
  507.  
  508. call FREE_EXEC_LIST(mylist)
  509.  
  510. return 1
  511.  
  512.  
  513. loaddatafile: procedure expose ix addrrecord 
  514.  
  515.  treenode = null()
  516.  
  517.  do forever
  518.  
  519.     x = open(infile,"datafile",'R')
  520.     line = readln(infile)
  521.     if eof(infile) = 1 then leave
  522.  
  523.     parse var line firstname ',' lastname ',' street ',' city ',' state ',',
  524.                    zipcode ',' areacode ',' phonenumber ',' dob ',' sendcard
  525.  
  526.     wareacode = "000"
  527.     wphonenumber = "000-0000"
  528.  
  529.     primekey = upper(lastname)
  530.     statekey = upper(state)
  531.     sendkey  = upper(sendcard)
  532.  
  533.     x = WRITE_RMF_RECORD(ix,addrrecord,primekey,1,statekey,2,zipcode,
  534.                          ,3,areacode,4,dob,5,sendkey) 
  535.  
  536.     call SET_DATA(treenode,0,lastname)
  537.     call SET_DATA(treenode,1,firstname)
  538. end
  539.  
  540. x = close(infile)
  541.  
  542. return 1
  543.  
  544.