!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! Meta command operator: executes Midas command for either;
!    1) a list of strings      filename  
! or 2) a sequence of numbers  #=n1:n2;nskip
!
! @author Jeff Schoen
! @version $Id: forall.mm,v 1.12 2015/09/09 22:12:38 jgs Exp $
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
startmacro/nover/onebase q:line 

global/readall

sedit line len length 1
sedit line oper range 1 len
sedit line command range len+1 ! No 2nd arg, goes to end of line

sedit oper oper upcase ! insure results within the COUNT are uppercase

if oper eqs ""
  ask u:oper "Count string (I=1:5;2) or List filename (FILES) -> "
endif
if command eqs ""
  ask q:command "Command string -> "
endif

switch "ECHO" echo get 0 1
switch "PAUSE" pause get 0 1
 
if "#=" eqss oper

  sedit oper start trim = :
  sedit oper end   trim : ;
  if ";" subs oper
    sedit oper inc trim ;
  else
    res inc 1
  endif
  do nn start end inc
    sedit command cmd gsubs # ^nn
    if echo then say "Exec: ^cmd"
    run/parent ^cmd
    if pause gt 0 pause pause
  enddo

elseif oper fexists

  foreach value infile oper
    sedit command cmd gsubs # "^value"
    if echo then say "Exec: ^cmd"
    run/parent ^cmd
    if pause gt 0 pause pause
  endfor

else
  error "File ^oper does not exist"
endif

endmacro
