Rem Program: fcopy.bas - Program to copy a text file to another file
Rem  Usage:  fcopy  source-file  [destination-file]
Rem          If destination-file is not specified, then
Rem          source-file will be copied to stdout.
cmdtail$ = command$
cmdLen = Len(cmdtail$)
If cmdLen = 0 then goto 1000 'print usage for the command
srcfil$ = ""
Rem Get the name of the source file
Gosub 2000
srcfil$ = f$
Rem Take the remnant of the command tail
cmdtail$ = trim$(mid$(cmdtail$,i))
cmdLen = Len(cmdtail$)
f$ = ""
Rem Get the name of the destination file
if cmdLen = 0 then
   f$ = ""
else
   gosub 2000
end if
destfil$ = f$
Rem Rest of the command line is ignored
open "I", #1, srcfil$
if destfil$ <> "" then  ' destination-file was not specified
  open "O", #2, destfil$
end if
while not EOF(1)
   line input#1, lin$
   if destfil$ <> "" Then
      print#2, lin$
   Else  'destination-file was not specified. So print to standard output.
      print lin$
   End If
wend
close
End
Rem  Print Usage
1000 print : print "Usage: fcopy source-file [destination-file]"
print
print "       If destination-file is not specified, the source"
print "          file will be copied to stdout"
print
End
Rem Extract the chars. from the command Line upto the 1st white char.
Rem and store the string in f$
2000:
f$ = ""
for i = 1 to cmdLen
  ch$ = mid$(cmdtail$,i,1)
  if ((ch$ = " ") or (ch$ = chr$(9))) then exit for
  f$ = f$ + ch$
next i
Return
