getbyte char unit(163)
[
  char nb
  int signal
  nb=unit(35)
  if(nb<=0)[
    signal=fread(unit+36,unit)
    if(signal== -1)return 26 /* ^Z returned.
    if(signal< -1)[
      ps"read error"; return 26
    ]
    nb=0
  ]
  unit(35)=nb+1
  return unit(nb+36)
]
putbyte char c,unit(163)
[
  char nb
  int signal
  nb=unit(35)
  if(nb<0)[
    signal=fwrite(unit+36, unit+163, unit)
    nb=0
  ]
  unit(36+nb)=c
  if(c==26) if(nb>0)[
    signal=fwrite(unit+36, unit+163, unit)
    nb=0
  ]
  unit(35)=nb+1
  return signal
]
endline char in(0), out(0)
        int lf
[
  char unit(163, tounit(163, c
  int signal
  if(fopen(1,in,0,unit))return
  if(fopen(2,out,0,tounit))return
/* this loop processes each character of the file
  while(signal==0)[
    c=getchar(unit)
    if (c==13) if (lf==1) [
      signal=putchar 13,tounit
      if (signal==0) signal=putchar 10,tounit ]
    else if ((c!=10)+lf!=0) signal=putchar c,tounit
    if (c==26) signal=signal+1 ]
  fclose(tounit)
  fclose(unit)
]
main [endline "from" , "to" , 1]
