home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / rexvim.zip / ABEDEMO.CMD next >
OS/2 REXX Batch file  |  1994-07-17  |  19KB  |  451 lines

  1. /** ABEDemo.cmd **/
  2. /**********************************************/
  3. /*                                            */
  4. /* Command line syntax:                       */
  5. /*                                            */
  6. /* ABEDemo  db_path user_password user_name   */
  7. /*                                            */
  8. /*                                            */
  9. /**********************************************/
  10. ARG db_path user_pw user_name
  11. '@echo off'
  12. '@cls'
  13. Say 'RexxVIM Address Book Entry Demonstration Program'
  14. Say
  15.  
  16. /* Unload the function upon error */
  17. SIGNAL ON ERROR NAME done
  18.  
  19. /* Prompt for the parameters if not passed on the */
  20. /* command line                                   */
  21. if LENGTH(STRIP(db_path)) = 0 then do
  22.    Say 'Enter Postoffice Directory -'
  23.    PARSE PULL db_path .
  24.    Say
  25.    Say 'Enter User Name -'
  26.    PARSE PULL user_name
  27.    Say 'Enter Password -'
  28.    PARSE PULL user_pw
  29. end  /* Do */
  30.  
  31.  
  32. /* Load the RexxVIM extensions to Rexx */
  33. rc = RxFuncAdd('RxVIMLoadFuncs', 'REXXVIM', 'RxVIMLoadFuncs')
  34. if rc <> 0 then do
  35.    Say
  36.    Say 'RexxVIM failed to load, return code' rc
  37.    Say
  38.    Say 'Functions have been released.  Retry program.'
  39.    signal done
  40. end  /* Do */
  41. call RxVIMLoadFuncs
  42. Say 'Functions are now loaded'
  43. Say
  44.  
  45.  
  46. /* Initialize the VIM subsystem */
  47. rc = RxVIMInitialize()
  48. if (rc > 0) then call vimerr
  49.  
  50. /* Open a session with the postoffice using the parameters */
  51. /* provided by the user                                    */
  52. rc = RxVIMOpenSession(db_path,user_name,user_pw,Session)
  53. if (rc > 0) then call vimerr
  54.  
  55.  
  56.      /* Enumerate the addressbooks */
  57.      pos = ''                           /* Start at the beginning */
  58.      skipcnt = 1                        /* Move forward one at a time */
  59.      acount  = 1                        /* Retrieve 1 addressbook for each call */
  60.      more    = ''                       /* Set the value of more to nul */
  61.      action  = 'N'                      /* Set the value of repeat loop indicator to N */
  62.  
  63.      AttrDesc.0 = 2                               /* Retrieve 2 attributes for each addressbook */
  64.      AttrDesc.1.Selector = 'VIMSEL_NAME'          /* 1st attribute is the addressbook name */
  65.      AttrDesc.1.Buffer   = 'AddrName'             /* store results in this stem variable */
  66.      AttrDesc.2.Selector = 'VIMSEL_TOTAL_ENTRIES' /* 2nd attribute is total entries */
  67.      AttrDesc.2.Buffer   = 'AddrTotal'            /* store results in this stem variable */
  68.  
  69.      /* Continue retrieving addressbook info until user enters X */
  70.  
  71.      rc = RxVIMEnumerateAddressBooks(Session,'pos',skipcnt,'AttrDesc','acount','more')
  72.      if (rc > 0) then call vimerr
  73.  
  74.      do until TRANSLATE(SUBSTR(action,1,1)) = 'X'
  75.  
  76.           /* Display results */
  77.          'cls'
  78.           Say 'RexxVIM - (c) Innovative Business Technologies, Inc'
  79.           Say
  80.           Say 'Address Book Demo'
  81.           Say
  82.           Say '--------------------------------------------------------'
  83.           Say '    Address Book Name =' AddrName.1
  84.           Say '    Total Entries     =' AddrTotal.1
  85.           Say '--------------------------------------------------------'
  86.           Say
  87.           Say
  88.           Say 'Select an action for this message'
  89.           Say
  90.           Say '   N - Go to next Address Book'
  91.           Say '   C - Create a new entry'
  92.           Say '   S - Search for an entry'
  93.           Say '   L - Change the location of an entry'
  94.           Say '   F - Create a new group'
  95.           Say '   G - Display all members of a group'
  96.           Say '   X - Exit demo now'
  97.           Say
  98.           Say 'Enter your selection below:'
  99.           PULL action
  100.  
  101.           /* Process the selection entered.  X will fall through the select statement */
  102.           select
  103.              when TRANSLATE(SUBSTR(action,1,1)) = 'N' then do
  104.                 /* Go to the next address book */
  105.  
  106.                 rc = RxVIMEnumerateAddressBooks(Session,'pos',skipcnt,'AttrDesc','acount','more')
  107.                 if (rc > 0) then call vimerr
  108.  
  109.              end  /* Do */
  110.              when TRANSLATE(SUBSTR(action,1,1)) = 'C' then do
  111.                 /* Create a new entry in this address book */
  112.  
  113.                 Say '--------------------------------------------------------'
  114.                 Say 'Enter the name'
  115.                 Pull ename
  116.                 Say 'Enter a comment'
  117.                 Pull ecomment
  118.                 Say 
  119.                 Say 'Adding' ename 'to the addressbook'
  120.                 Say '--------------------------------------------------------'
  121.  
  122.                 /* Open the addressbook */
  123.                 rc = RxVIMOpenAddressBook(Session,AddrName.1,'AddrBkPtr')
  124.                 if (rc > 0) then call vimerr
  125.  
  126.                 /* Create the description stem for the create */
  127.                 attrItem.0 = 3
  128.                 attrItem.1.Selector = 'VIMSEL_NAME'
  129.                 attrItem.1.Value    = ename
  130.                 attrItem.2.Selector = 'VIMSEL_COMMENTS'
  131.                 attrItem.2.Value    = ecomment
  132.                 attrItem.3.Selector = 'VIMSEL_LOCATION'
  133.                 attrItem.3.Value    = 'VIMSEL_REMOTE'
  134.  
  135.                 /* Add the entry to the address book */
  136.                 rc = RxVIMCreateAddressBookEntry(AddrBkPtr,'VIMSEL_ENTITY','attrItem')
  137.                 if (rc > 0) then call vimerr
  138.  
  139.                 /* Close the address book */
  140.                 rc = RxVIMCloseAddressBook(addrBkPtr)
  141.                 if (rc > 0) then call vimerr
  142.  
  143.              end  /* Do */
  144.              when TRANSLATE(SUBSTR(action,1,1)) = 'S' then do
  145.                 /* Search for an entry in this address book */
  146.  
  147.                 Say '--------------------------------------------------------'
  148.                 Say 'Enter the name for the search'
  149.                 Pull ename
  150.                 Say 
  151.                 Say 'Searching for' ename 'in the addressbook'
  152.  
  153.                 /* Open the addressbook */
  154.                 rc = RxVIMOpenAddressBook(Session,AddrName.1,'AddrBkPtr')
  155.                 if (rc > 0) then call vimerr
  156.  
  157.                 /* Create the description stem for the create */
  158.                 searchon = 'VIMSEL_NAME'
  159.                 epos     = ''
  160.                 matchby  = 'VIMSEL_FULL'
  161.                 enumb    = ''
  162.  
  163.                 /* Search for the entry in the address book */
  164.                 rc = RxVIMMatchAddressBook(AddrBkPtr,searchon,ename,matchby,'epos','enumb')
  165.                 if (rc > 0) then do
  166.                     /* Entry not found */
  167.                     Say '--------------------------------------------------------'
  168.                     Say '  Entry not found in the addressbook'
  169.                     Say '--------------------------------------------------------'
  170.                 end  /* Do */
  171.                 else do
  172.  
  173.                     /* Get additional info about specific entry */
  174.                     itemdesc.0 = 3
  175.                     itemdesc.1.selector = 'VIMSEL_LOCATION'
  176.                     itemdesc.1.buffer   = 'location'
  177.                     itemdesc.2.selector = 'VIMSEL_ADDRESS'
  178.                     itemdesc.2.buffer   = 'address'
  179.                     itemdesc.3.selector = 'VIMSEL_TYPE'
  180.                     itemdesc.3.buffer   = 'typebuf'
  181.  
  182.                     rc = RxVIMGetABEntryAttributes(addrBkPtr,epos,'','itemdesc')
  183.                     if (rc > 0) then call vimerr
  184.  
  185.                     Say '--------------------------------------------------------'
  186.                     Say '  Name     -' ename
  187.                     Say '  Ref No   -' epos
  188.                     Say
  189.                     Say '  Address  -' address
  190.                     Say '  Type     -' typebuf
  191.                     Say '  Location -' location
  192.                     Say '--------------------------------------------------------'
  193.                 end  /* Do */
  194.                 'pause'
  195.  
  196.                 /* Close the address book */
  197.                 rc = RxVIMCloseAddressBook(addrBkPtr)
  198.                 if (rc > 0) then call vimerr
  199.  
  200.              end  /* Do */
  201.              when TRANSLATE(SUBSTR(action,1,1)) = 'G' then do
  202.  
  203.                 /* Retrieve the name of the group to display */
  204.                 Say 'Enter the name of the group to display'
  205.                 PULL gname
  206.  
  207.                 /* Open the current address book */
  208.                 rc = RxVIMOpenAddressBook(Session,AddrName.1,'AddrBkPtr')
  209.                 if (rc > 0) then call vimerr
  210.  
  211.                 /* Enumerate the group member entries */
  212.                 epos = ''                           /* Start at the beginning */
  213.                 eskipcnt = 1                        /* Move forward one at a time */
  214.                 eacount  = 1                        /* Retrieve 1 group member for each call */
  215.                 emore    = ''                       /* Set the value of more to nul */
  216.                 eaction  = 'N'                      /* Set the value of repeat loop indicator to N */
  217.  
  218.                 ItemDesc.0 = 3                               /* Retrieve 3 attributes for each entry */
  219.                 ItemDesc.1.Selector = 'VIMSEL_REF'           /* 1st attribute is the reference number */
  220.                 ItemDesc.1.Buffer   = 'ABE_Ref'              /* store results in this stem variable */
  221.                 ItemDesc.2.Selector = 'VIMSEL_NAME'          /* 2nd attribute is the entry name */
  222.                 ItemDesc.2.Buffer   = 'ABE_Name'             /* store results in this stem variable */
  223.                 ItemDesc.3.Selector = 'VIMSEL_ADDRESS'       /* 3rd attribute is entry address */
  224.                 ItemDesc.3.Buffer   = 'ABE_Address'          /* store results in this stem variable */
  225.  
  226.                 do until TRANSLATE(SUBSTR(eaction,1,1)) = 'X'
  227.  
  228.                      /* Continue retrieving group member info until user enters X */
  229.  
  230.                      rc = RxVIMEnumerateGroupMembers(AddrBkPtr,'',gname,'epos',eskipcnt,,
  231.                                            'ItemDesc','eacount','emore')
  232.                      if (rc > 0) then call vimerr
  233.  
  234.                      /* Display results */
  235.                     'cls'
  236.                      Say 'RexxVIM - (c) Innovative Business Technologies, Inc'
  237.                      Say
  238.                      Say 'Group Member Information'
  239.                      Say
  240.                      Say '--------------------------------------------------------'
  241.                      Say '    Group Name =' gname
  242.                      Say '--------------------------------------------------------'
  243.                      Say '    Name =   ' ABE_Name.1
  244.                      Say '    Address =' ABE_Address.1
  245.                      Say '    Ref No  =' ABE_Ref.1
  246.                      Say '--------------------------------------------------------'
  247.                      Say
  248.                      Say
  249.                      Say 'Select an action for this message'
  250.                      Say
  251.                      Say '   N - Go to next Group Member entry'
  252.                      Say '   A - Add a new entry to the group'
  253.                      Say '   D - Delete this entry from the group'
  254.                      Say '   X - Exit to the main screen'
  255.                      Say
  256.                      Say 'Enter your selection below:'
  257.                      PULL eaction
  258.  
  259.                      select
  260.                         when TRANSLATE(SUBSTR(eaction,1,1)) = 'N' then do
  261.                            /* Go to the next group member entry */
  262.                            /* Nothing to do.....will loop to the next entry */
  263.                         end  /* Do */
  264.                         when TRANSLATE(SUBSTR(eaction,1,1)) = 'D' then do
  265.                            /* Delete the current entry from the group */
  266.                            rc = RxVIMRemoveGroupMember(AddrBkPtr,'',gname,ABE_Name.1)
  267.                            if (rc > 0) then call vimerr
  268.                         end  /* Do */
  269.                         when TRANSLATE(SUBSTR(eaction,1,1)) = 'A' then do
  270.                            /* Add a new entry to the group */
  271.                            Say 'Enter the new name to add'
  272.                            PULL new_name
  273.  
  274.                            rc = RxVIMAddGroupMember(AddrBkPtr,'',gname,new_name)
  275.                            if (rc > 0) then call vimerr
  276.                         end  /* Do */
  277.                      otherwise
  278.                      end  /* select */
  279.  
  280.                      /* End the loop if no more entries */
  281.                      if emore = 'False' then do
  282.                         Say 'All entries for this group have been retrieved'
  283.                         eaction = 'X'
  284.                      end  /* Do */
  285.  
  286.                 end /* Do */
  287.  
  288.                 /* Close the  address book */
  289.                 rc = RxVIMCloseAddressBook(AddrBkPtr)
  290.                 if (rc > 0) then call vimerr
  291.  
  292.              end  /* Do */
  293.              when TRANSLATE(SUBSTR(action,1,1)) = 'F' then do
  294.                 /* Create a new group entry in this address book */
  295.  
  296.                 Say '--------------------------------------------------------'
  297.                 Say 'Enter the group name'
  298.                 Pull gname
  299.                 Say
  300.                 Say 'Adding' gname 'to the addressbook'
  301.                 Say '--------------------------------------------------------'
  302.  
  303.                 /* Open the addressbook */
  304.                 rc = RxVIMOpenAddressBook(Session,AddrName.1,'AddrBkPtr')
  305.                 if (rc > 0) then call vimerr
  306.  
  307.                 /* Create the description stem for the create */
  308.                 attrItem.0 = 1
  309.                 attrItem.1.Selector = 'VIMSEL_NAME'
  310.                 attrItem.1.Value    = gname
  311.  
  312.                 /* Add the entry to the address book */
  313.                 rc = RxVIMCreateAddressBookEntry(AddrBkPtr,'VIMSEL_GROUP','attrItem')
  314.                 if (rc > 0) then call vimerr
  315.  
  316.                 /* Close the address book */
  317.                 rc = RxVIMCloseAddressBook(addrBkPtr)
  318.                 if (rc > 0) then call vimerr
  319.  
  320.              end  /* Do */
  321.              when TRANSLATE(SUBSTR(action,1,1)) = 'L' then do
  322.                 /* Search for an entry in this address book */
  323.  
  324.                 Say '--------------------------------------------------------'
  325.                 Say 'Enter the name to change location'
  326.                 Pull ename
  327.                 Say 
  328.                 Say 'Searching for' ename 'in the addressbook'
  329.  
  330.                 /* Open the addressbook */
  331.                 rc = RxVIMOpenAddressBook(Session,AddrName.1,'AddrBkPtr')
  332.                 if (rc > 0) then call vimerr
  333.  
  334.                 /* Create the description stem for the create */
  335.                 searchon = 'VIMSEL_NAME'
  336.                 epos     = ''
  337.                 matchby  = 'VIMSEL_FULL'
  338.                 enumb    = ''
  339.  
  340.                 /* Search for the entry in the address book */
  341.                 rc = RxVIMMatchAddressBook(AddrBkPtr,searchon,ename,matchby,'epos','enumb')
  342.                 if (rc > 0) then do
  343.                     /* Entry not found */
  344.                     Say '--------------------------------------------------------'
  345.                     Say '  Entry not found in the addressbook'
  346.                     Say '--------------------------------------------------------'
  347.                 end  /* Do */
  348.                 else do
  349.  
  350.                     /* Get additional info about specific entry */
  351.                     itemdesc.0 = 3
  352.                     itemdesc.1.selector = 'VIMSEL_LOCATION'
  353.                     itemdesc.1.buffer   = 'location'
  354.                     itemdesc.2.selector = 'VIMSEL_ADDRESS'
  355.                     itemdesc.2.buffer   = 'address'
  356.                     itemdesc.3.selector = 'VIMSEL_TYPE'
  357.                     itemdesc.3.buffer   = 'typebuf'
  358.  
  359.                     rc = RxVIMGetABEntryAttributes(addrBkPtr,epos,'','itemdesc')
  360.                     if (rc > 0) then call vimerr
  361.  
  362.                     Say '--------------------------------------------------------'
  363.                     Say '  Name     -' ename
  364.                     Say '  Ref No   -' epos
  365.                     Say
  366.                     Say '  Address  -' address
  367.                     Say '  Type     -' typebuf
  368.                     Say '  Location -' location
  369.                     Say '--------------------------------------------------------'
  370.                 end  /* Do */
  371.                 Say 'Enter new location - (L)ocal, (R)emote, (M)obile or enter for no change'
  372.                 PULL nlocation
  373.  
  374.                 if LENGTH(STRIP(nlocation)) > 0 then do
  375.  
  376.                     itemdesc.0 = 1
  377.                     itemdesc.1.selector = 'VIMSEL_LOCATION'
  378.  
  379.                     /* Set value of new location from input */
  380.                     Select
  381.                        when TRANSLATE(SUBSTR(nlocation,1,1)) = 'L' then
  382.                          itemdesc.1.value = 'VIMSEL_LOCAL'
  383.                        when TRANSLATE(SUBSTR(nlocation,1,1)) = 'R' then
  384.                          itemdesc.1.value = 'VIMSEL_REMOTE'
  385.                        when TRANSLATE(SUBSTR(nlocation,1,1)) = 'M' then
  386.                          itemdesc.1.value = 'VIMSEL_DIALIN'
  387.                     otherwise
  388.                          itemdesc.1.value = location
  389.                     end  /* select */
  390.                     itemdesc.1.buffer   = 'location'
  391.  
  392.                     /* Call function to set location */
  393.                     rc = RxVIMSetABEntryAttributes(addrBkPtr,epos,'','itemdesc')
  394.                     if (rc > 0) then call vimerr
  395.  
  396.                 end  /* Do */
  397.  
  398.                 /* Close the address book */
  399.                 rc = RxVIMCloseAddressBook(addrBkPtr)
  400.                 if (rc > 0) then call vimerr
  401.  
  402.              end  /* Do */
  403.           otherwise
  404.           end  /* select */
  405.  
  406.           if more = 'False' then do
  407.              Say 'All Address Books have been retrieved'
  408.              action = 'X'
  409.           end  /* Do */
  410.  
  411.      end /* do */
  412.  
  413. /* Close the session with the postoffice */
  414. rc = RxVIMCloseSession(Session)
  415. if (rc > 0) then call vimerr
  416.  
  417.  
  418. /* Terminate the active VIM subsystem connection */
  419. rc = RxVIMTerminate()
  420. if (rc > 0) then call vimerr
  421. signal done
  422.  
  423.  
  424. /***** VIMErr *******/
  425.  
  426. /* If an error occurs, this function will return the text */
  427. /* associated with the error.  Extended text may be       */
  428. /* displayed if it exists for the specified error.        */
  429.  
  430. VIMERR:
  431.  
  432. erc = RxVIMStatusText(Session,rc,'Status')
  433. Say
  434. Say '|-Error Information ------------------------------------|'
  435. Say '  Error Text -' status.1
  436. Say
  437. Say '  Ext Status -' status.2
  438. rc = RxVIMTerminate()
  439. signal done
  440.  
  441.  
  442. /* The done section will unload the RexxVIM extensions */
  443. /* and exit the program                                */
  444. DONE:
  445. /*** Drop all of the external functions ***/
  446. call RxVIMDropFuncs
  447. Say '|-------------------------------------------------------|'
  448. Say 'Demo Complete.  All functions released'
  449. 'pause'
  450. exit
  451.