home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 18 REXX
/
18-REXX.zip
/
multid.cmd
< prev
next >
Wrap
OS/2 REXX Batch file
|
1994-05-10
|
7KB
|
127 lines
/* Multiple file drag/drop handler */
/* Version 0.11 */
/* Lee S. Fields, 75140,373 */
/* with suggestions/improvements from: */
/* Paul Prescod 74431,413 */
/* */
/* When used as a WPS Program object this program will collect the names of */
/* the data files dropped on it and either pass them to the specified program */
/* as a list of names or pass them to the specified program one at a time. */
/* */
/* The expected parameter format of this program is: */
/* MULTIDRG type command filename */
/* type is either STACK, ITERATE, or RESET */
/* STACK passes all the file names to the program in a single command. */
/* ITERATE passes the file names individually to the program sequentially */
/* in multiple commands. */
/* RESET is used to clean up the queue after an abnormal termination, no */
/* commands are executed. */
/* command is the name of the command or program to execute. Other parameters*/
/* can be included if they can precede the file name. */
/* filename is the name of a file that was dropped and is usually specified as*/
/* %* in the parameters setting in the program objects notebook. */
/* */
/* Example: */
/* Suppose you have a zip file that you use to store nifty REXX files, such as*/
/* this one. It would be nice to have a program object that you could just */
/* drop the new files on to add them the zip file. To do this, create a new */
/* program object with MULTIDRG.CMD as the program name. In the parameters */
/* specify: */
/* STACK ZIP D:\REXX\NIFTY %* */
/* Now if you drag the files MULTIDRG.CMD, XYZ.CMD, and WOW.CMD from the */
/* D:\NEW directory to this new program object, it would execute the command: */
/* ZIP D:\REXX\NIFTY D:\NEW\MULTIDRG.CMD D:\NEW\XYZ.CMD D:\NEW\WOW.CMD */
/* */
/* If the parameter setting for type were ITERATE instead of STACK */
/* ITERATE ZIP D:\REXX\NIFTY %* */
/* It would have sequentially executed: */
/* ZIP D:\REXX\NIFTY D:\NEW\MULTIDRG.CMD */
/* ZIP D:\REXX\NIFTY D:\NEW\XYZ.CMD */
/* ZIP D:\REXX\NIFTY D:\NEW\WOW.CMD */
/* */
/* If the program terminates abnormally, the input queue that is used may not */
/* be deleted and would stop any subsequent runs from working correctly. */
/* Run this program with the type RESET and the command previously used */
/* MULTIDRG RESET command */
/* to clean up the queue. */
/* */
/* If this program doesn't catch all the files dropped on it, increase the */
/* value specified in the line "delay=8". Currently the program sleeps 8 */
/* seconds, processes any items in the queue, and then repeats the cycle until*/
/* it wakes up and finds no items in the queue. Memory constrained or slower */
/* systems may need more time. If you plan to drag/drop large numbers of */
/* files, you should also increase the delay. On my system the delay needed */
/* if roughly 1 second per file. */
/* */
/* If you can improve this program, please do. I would, however, like to */
/* be informed of your changes so I can consolidate and redistribute them. */
/*trace('?I')*/
call rxfuncadd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
call SysLoadFuncs
parse upper arg type rest
filename = word(rest, words(rest)) /* filename is last word */
command = substr(rest, 1, wordindex(rest, words(rest)) - 1)
first = word(command,1) /* extract first word of command string for queue name*/
newqname = 'MULTIDRAGDROP'||first /* must be uppercase for equality test */
if type='RESET' then do /* manually delete queue in case of abnormal termination */
call RXQUEUE 'Delete', newqname
return
end
newq = RXQUEUE('Create', newqname)
if newq = newqname then /* first instance of queue name */
primary = 1
else do /* multiple instance of queue name */
primary = 0
call RXQUEUE 'Delete', newq /* delete this instance */
newq = newqname /* use original queue name */
end
oldq = RXQUEUE('Set', newq)
push filename
if \ primary then do
call RXQUEUE 'Set', oldq /* restore original queue */
return /* only primary needs to stick around */
end
/* only primary task from here on */
if type='STACK' then
newcommand = command
delay = 8 /* adjust to suit your system requirements */
say 'Gathering file names...'
call SysSleep delay /* give other instances a chance to complete */
do while queued() > 0 /* delay loop */
do while queued() > 0 /* empty queue */
if type='STACK' then do
pull newparm
newcommand = newcommand newparm
end
else if type='ITERATE' then do
pull newparm
command newparm
end
end
say 'checking for more names...'
call SysSleep delay /* give other instances a chance to complete */
end
if type='STACK' then
newcommand
/* clean up */
if primary then do
call RXQUEUE 'Delete', newq /* delete new queue */
call RXQUEUE 'Set', oldq /* restore original queue */
end
return