'===========================================================================
' Subject: COMBINE/SEPARATE ASCII FILES       Date: 12-28-97 (21:56)       
'  Author: Michael G. Stewart                 Code: QB, QBasic, PDS        
'  Origin: mikegs@juno.com                  Packet: TEXT.ABC
'===========================================================================
'This File Will Combine 10 ASCII Files, and Then Later Separate Them.
'Mike Stewart
'mikegs@juno.com <Normal E-Mail
'mstewart@tincan.tincan.org <File Attachments
'Web Site: http://pages.tripod.com/~MikeGS_CN/index.htm

DECLARE SUB combine (File$)
DECLARE SUB separate (File$)
PRINT "SEPARATE.BAS (C) 1997 Mike Stewart"
PRINT
PRINT "Syntax:"
PRINT
PRINT "  Command$, File$"
PRINT
PRINT "  Command$ - Command "
PRINT "              `S' - SEPARATE"
PRINT "              `C' - COMBINE"
PRINT "     File$ - For SEPARATE the file to separate"
PRINT "             For COMBINE the output file"
PRINT
INPUT "Command: ", Comm$, File$
IF UCASE$(Comm$) = "S" THEN separate (File$)
IF UCASE$(Comm$) = "C" THEN
 DIM SHARED InFile$(1 TO 10)
 FOR a% = 1 TO 10
  PRINT "Input File"; a%; "Name: ";
  INPUT "", s$
  InFile$(a%) = s$
 NEXT a%
 combine (File$)
END IF
PRINT "Invalid Command."
END

SUB combine (File$)
OPEN File$ FOR OUTPUT AS #1
PRINT #1, "WARNING: Multiple Files!"
PRINT #1, "Separate with SEPARATE.BAS"
FOR a% = 1 TO 10
 InFile$(a%) = SPACE$(12) + InFile$(a%)
 s$ = "@" + LTRIM$(RTRIM$(MID$(InFile$(a%), INSTR(LEN(InFile$(a%)) - 11,
InFile$(a%), "\")))) + "#"
 InFile$(a%) = LTRIM$(InFile$(a%))
 PRINT #1, s$
 PRINT "Copying "; InFile$(a%)
 OPEN InFile$(a%) FOR INPUT AS #2
 DO WHILE NOT EOF(2)
  IF EOF(2) THEN EXIT DO
  LINE INPUT #2, in$
  IF LEFT$(in$, 1) = "@" THEN
   in$ = "~" + in$
  END IF
  PRINT #1, in$
 LOOP
 CLOSE #2
NEXT a%
CLOSE #1
PRINT "Thank You For Using SEPARATE.BAS"
END
END SUB

SUB separate (File$)
OPEN File$ FOR INPUT AS #1
OPEN "TEMP.TMP" FOR OUTPUT AS #2
LINE INPUT #1, in$
LINE INPUT #1, in2$
in$ = in$ + " " + in2$
IF in$ <> "WARNING: Multiple Files! Separate with SEPARATE.BAS" THEN
CLOSE #1: CLOSE #2: END
DO WHILE NOT EOF(1)
 LINE INPUT #1, in$
 IF LEFT$(in$, 1) = "@" THEN
  CLOSE #2
  IF OutFile$ = "" THEN KILL "TEMP.TMP"
  OutFile$ = MID$(in$, 2, INSTR(in$, "#") - 2)
  OPEN OutFile$ FOR OUTPUT AS #2
  PRINT "Now Writing "; OutFile$
 ELSE
  IF LEFT$(in$, 2) = "~@" THEN
   in$ = MID$(in$, 2)
  END IF
  PRINT #2, in$
 END IF
LOOP
CLOSE #1
CLOSE #2
PRINT "Thanks for using SEPARATE.BAS."
END
END SUB
