begin ; !Copy
!Modded JHB 10/12/84: removed FCOMM call & replaced by COPY.
!Modded JGH 24/01/85: uses PAM values rather than always / & to use stream 0
! GDMR 28/06/85: concatenation now works (again?)

option  "-nocheck-nodiag"
include  "inc:util.imp"

string (255)parm,in,out
byte  sep = '/'

integer  output stream

  routine  copy char by char
  integer  sym
    on  3,9 start 
        selectoutput(0)
        returnif  event_event=9
        printstring(event_message)
        newline unless  event_message=""
        return 
    finish 
    select input (0)
    openinput(1,in) and  selectinput(1) if  in#""
    select output(output stream);  ! GDMR
    cycle 
      readsymbol(sym); printsymbol(sym)
    repeat 
  end 

  predicate  done remotely
  integer  i
    on  3 start 
      false 
    finish 
    falseif  in="" or  out="" or  charno(in,1)=':' or  charno(out,1)=':'
    for  i = 1,1,length(in) cycle 
      falseif  charno(in,i)=','
    repeat 
    copy(in,out)
    true 
  end 

  onevent  3,4 start 
    selectoutput(0); printline(event_message)
    stop 
  finish 

  Select input (0)
  Select output (0)
  sep = PAM_group sep if  pam_group sep >=' '
  parm = cliparam
  if  parm = "" start 
      Prompt ("Input file(s): ")
      read line (in)
      Prompt ("Output file: ")
      read line (out)
      Prompt (":")
  else 
      in = parm and  out = "" unless  parm -> in.(TO STRING(SEP)).out
  finish 

  unless  done remotely start 
    if  out = "" start 
      output stream = 0
    else 
      open output(1, out)
      output stream = 1
    finish 
    parm = in.","
    copy char by char while  parm -> in.(",").parm
  finish 
endofprogram