/* *************************************************** */
/* printfiles Arexx Macro                              */
/* © 1992 by K. Klingbeil                              */
/* inserts files into the print list using AmigaDos    */
/* pattern matching facilities                         */
/* USAGE: rx prf -f<Arexx-Script> <insert> -r<remove>  */
/* Example : rx prf -ftest.rexx #?test#? -rtest.h      */
/* this examples inserts all files which contain       */
/* the pattern  'test' info the print list, removes    */
/* the file test.h and executes the Arexx-script       */
/* test.rexx                                           */
/* NOTE: Scripts that are generated from PrintFiles    */
/* itself (Save button in the prefs window) contain    */
/* a 'reset' command at the first line. You should     */
/* call the prf macro with such a script as the first  */
/* argument.                                           */
/* *************************************************** */

options results
address command 'rx prfstart'
if result = 5 then exit

parse arg CmdLine
p = words(CmdLine)

do i = 1 to p
   pattern = word(CmdLine,i)
   if left(pattern,2) == '-r' then removefile(substr(pattern,3))
    else
     if left(pattern,2) == '-f' then rxfile(substr(pattern,3))
      else insertfile(pattern)
end
exit

rxfile: procedure
parse arg template
cmd =  'rx ' template
address command cmd
return 1

removefile: procedure
parse arg template
cmd =  'list >pipe:prf' template 'quick'
address command cmd
address printfiles
open('p','pipe:prf','r')
 do while ~eof('p')
  file = readln('p')
  a = subword(file,1,1)
  b = subword(file,2,1)
  if a ~== '' & b == '' then remfile a
 end
close('p')

return 1

insertfile: procedure
parse arg template
cmd =  'list >pipe:prf' template 'quick'
address command cmd
address printfiles
open('p','pipe:prf','r')
 do while ~eof('p')
  file = readln('p')
  a = subword(file,1,1)
  b = subword(file,2,1)
  if a ~== '' & b == '' then insfile a
 end
close('p')
return  1

