home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / multid.cmd < prev    next >
OS/2 REXX Batch file  |  1994-05-10  |  7KB  |  127 lines

  1. /* Multiple file drag/drop handler                                            */
  2. /* Version 0.11                                                               */
  3. /* Lee S. Fields,  75140,373                                                  */
  4. /* with suggestions/improvements from:                                        */
  5. /*  Paul Prescod 74431,413                                                    */
  6. /*                                                                            */
  7. /* When used as a WPS Program object this program will collect the names of   */
  8. /* the data files dropped on it and either pass them to the specified program */
  9. /* as a list of names or pass them to the specified program one at a time.    */
  10. /*                                                                            */
  11. /* The expected parameter format of this program is:                          */
  12. /*   MULTIDRG type command filename                                           */
  13. /* type is either STACK, ITERATE, or RESET                                    */
  14. /*   STACK passes all the file names to the program in a single command.      */
  15. /*   ITERATE passes the file names individually to the program sequentially   */
  16. /*    in multiple commands.                                                   */
  17. /*   RESET is used to clean up the queue after an abnormal termination, no    */
  18. /*    commands are executed.                                                  */
  19. /* command is the name of the command or program to execute.  Other parameters*/
  20. /*  can be included if they can precede the file name.                        */
  21. /* filename is the name of a file that was dropped and is usually specified as*/
  22. /*  %* in the parameters setting in the program objects notebook.             */
  23. /*                                                                            */
  24. /* Example:                                                                   */
  25. /* Suppose you have a zip file that you use to store nifty REXX files, such as*/
  26. /* this one.  It would be nice to have a program object that you could just   */
  27. /* drop the new files on to add them the zip file.  To do this, create a new  */
  28. /* program object with MULTIDRG.CMD as the program name.  In the parameters   */
  29. /* specify:                                                                   */
  30. /*    STACK ZIP D:\REXX\NIFTY %*                                              */
  31. /* Now if you drag the files MULTIDRG.CMD, XYZ.CMD, and WOW.CMD from the      */
  32. /* D:\NEW directory to this new program object, it would execute the command: */
  33. /*    ZIP D:\REXX\NIFTY D:\NEW\MULTIDRG.CMD D:\NEW\XYZ.CMD D:\NEW\WOW.CMD     */
  34. /*                                                                            */
  35. /* If the parameter setting for type were ITERATE instead of STACK            */
  36. /*    ITERATE ZIP D:\REXX\NIFTY %*                                            */
  37. /* It would have sequentially executed:                                       */
  38. /*    ZIP D:\REXX\NIFTY D:\NEW\MULTIDRG.CMD                                   */
  39. /*    ZIP D:\REXX\NIFTY D:\NEW\XYZ.CMD                                        */
  40. /*    ZIP D:\REXX\NIFTY D:\NEW\WOW.CMD                                        */
  41. /*                                                                            */
  42. /* If the program terminates abnormally, the input queue that is used may not */
  43. /* be deleted and would stop any subsequent runs from working correctly.      */
  44. /* Run this program with the type RESET and the command previously used       */
  45. /*    MULTIDRG RESET command                                                  */
  46. /* to clean up the queue.                                                     */
  47. /*                                                                            */
  48. /* If this program doesn't catch all the files dropped on it, increase the    */
  49. /* value specified in the line "delay=8".  Currently the program sleeps 8     */
  50. /* seconds, processes any items in the queue, and then repeats the cycle until*/
  51. /* it wakes up and finds no items in the queue.  Memory constrained or slower */
  52. /* systems may need more time.  If you plan to drag/drop large numbers of     */
  53. /* files, you should also increase the delay.  On my system the delay needed  */
  54. /* if roughly 1 second per file.                                              */
  55. /*                                                                            */
  56. /* If you can improve this program, please do.  I would, however, like to     */
  57. /* be informed of your changes so I can consolidate and redistribute them.    */
  58.  
  59. /*trace('?I')*/
  60.  
  61. call rxfuncadd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  62. call SysLoadFuncs
  63.  
  64. parse upper arg type rest
  65. filename = word(rest, words(rest))  /* filename is last word */
  66. command = substr(rest, 1, wordindex(rest, words(rest)) - 1)
  67. first = word(command,1)    /* extract first word of command string for queue name*/
  68.  
  69. newqname = 'MULTIDRAGDROP'||first     /* must be uppercase for equality test */
  70.  
  71. if type='RESET' then do          /* manually delete queue in case of abnormal termination */
  72.    call RXQUEUE 'Delete', newqname
  73.    return
  74. end
  75.  
  76. newq = RXQUEUE('Create', newqname)
  77. if newq = newqname then    /* first instance of queue name */
  78.    primary = 1
  79. else do                    /* multiple instance of queue name */
  80.    primary = 0
  81.    call RXQUEUE 'Delete', newq   /* delete this instance */
  82.    newq = newqname               /* use original queue name */
  83. end
  84.  
  85. oldq = RXQUEUE('Set', newq)
  86. push filename
  87.  
  88. if \ primary then do
  89.    call RXQUEUE 'Set', oldq         /* restore original queue */
  90.    return               /* only primary needs to stick around */
  91. end
  92.  
  93. /* only primary task from here on */
  94.  
  95. if type='STACK' then
  96.    newcommand = command
  97.  
  98. delay = 8        /* adjust to suit your system requirements */
  99. say 'Gathering file names...'
  100. call SysSleep delay     /* give other instances a chance to complete */
  101.  
  102. do while queued() > 0      /* delay loop */
  103.    do while queued() > 0   /* empty queue */
  104.       if type='STACK' then do
  105.          pull newparm
  106.          newcommand = newcommand newparm
  107.       end
  108.       else if type='ITERATE' then do
  109.          pull newparm
  110.          command newparm
  111.       end
  112.    end
  113.    say 'checking for more names...'
  114.    call SysSleep delay     /* give other instances a chance to complete */
  115. end
  116.  
  117. if type='STACK' then
  118.    newcommand
  119.    
  120. /* clean up */
  121. if primary then do
  122.    call RXQUEUE 'Delete', newq      /* delete new queue */
  123.    call RXQUEUE 'Set', oldq         /* restore original queue */
  124. end
  125.  
  126. return
  127.