Classic Computer Magazine Archive COMPUTE! ISSUE 86 / JULY 1987 / PAGE 91

Text File Splitter For Atari

Frank P. Walters

This Atari utility is especially useful for telecommunications buffs who download long text files to disk. It splits any text file—including those created by SpeedScript—into shorter files for more convenient use.

Have you ever captured a long text file with a modem, and then tried to edit it in your word processor—only to find it was too long to fit in memory? "Text File Splitter" splits a long text file into shorter ones for editing. Type in and save the program.

When you run the program, it asks you for a source filename. This is the name of the long file you wish to split. If you don't specify a drive, the program defaults to drive Dl:. You must also tell the program the density of the source disk. Single-density disks contain 128 bytes per sector, while double-density disks contain about twice that much. This allows the program to estimate the file size, based on the number of disk sectors in its directory entry.

You then choose the number of new files to create, entering a number from 2–5, depending on the size of the original file. Finally, the program asks that you enter the destination disk drive number (1–4).

Single Drive Use

This program can be used with just one disk drive, but you must be sure that the destination disk has enough free space to contain the new files you are creating. The program does not close the channel for the file it is reading between saves, so absolutely no disk-swapping is permitted. If you are splitting an exceptionally long file on a single drive, you may need to use a DOS 2.5 enhanced-density disk or a true double-density disk to contain all the data.

If you have a 130XE computer and a single drive, you can copy the source file into the RAMdisk, deleting the DUP.SYS and MEM.SAV files, if necessary. Format a new disk to use as the destination, then run the program and specify drive D8: for the source file and Dl: for the destination.

The maximum length of each split file is limited to the buffer size displayed at the top of your screen. Other information appears while the task is in progress.

Ready To Edit

The program saves the new files with the same filename as the original, but with extensions .ZZ1, .ZZ2, and so on, in numerical order. When the process is complete, you can load the new files in a word processor for editing, or do what-ever you like. If for any reason you want to reassemble the original file, go to DOS and use the copy (C) function with the append (/A) option. (The copy-with-append function starts each appended file on a new sector, so the reassembled file may use more sectors than the original. You can eliminate the extra sectors by copying the reassembled file to another disk.)

Since the original file is split at arbitrary points, there is no guarantee that any of the smaller files will end with a RETURN character. Thus, if you print a split file without editing, the last portion of text may not be printed unless you force the printer to print an extra RETURN. This can be cured by adding a RETURN at the end of the file when editing. Some editing is normally needed, anyway, since the split files probably will end in the middle of a word or sentence. (You can print the entire file without losing data if you copy the unedited split files from disk to printer with the command D:*.ZZ?,P:.)

Text File Splitter

For instructions on entering this program, please refer to "COMPUTE!'s Guide to Typing In Programs" elsewhere in this issue.

OC 5 REM COPYRIGHT 1987 COMPUTE! PUBLICATIONS, INC. {3 SPACES} ALL RIGHTS RESERVED.
FF 10 READ N0, N1, N2, N3, N4, N15, N12B, Nl55, N255, Q: GOT O 260
IL 20 TRAP 250: CLOSE #N2: OPEN #N2, N4+N2, N0, F$:INPUT #N2; A$: CLOSE #N2
LC 30 IF A$ (N2, N2) <> " " THEN ? : ? "File not found"
	: GOTO 320
CB 40 SEC = VAL(A$ (N15, LEN(A$))) : Q = N0
AA 50 ? : ? "Single (enhanced) or Double density?";
PD 60 GET #N1, K : IF K <> 68 AND K <> 83 THEN 60
KL 70 DEN = N128-N3 : IF K = 68 THEN DEN = N255-N2
AK 80 ? CHR$(K) : BLOCK = INT (SEC*DEN/N255+1) : ? : ? A$
HB 90 IF BL0CK < N4 THEN POP : POP : GOTO 600
NC 100 A$ = "2": IF BL0CK/N2> MEM/N255 THEN A$ = "3" : IF
	BLOCK/N3>MEM/N255 THEN A$ = "4" : IF BLOCK/N4>MEM/N255 THEN
	A$ = "5"
IC 110 B$ = A$ : B = N2 + N3 : IF INT(BLOCK/(ASC(A$)-176)+0.5)MEM/N255 THEN 620
FO 120 IF BLOCK/B < N4 THEN B = N1 : GOTO 120
JL 130 B$ = CHR$ (B+176) : IF B$ < A$ THEN B$=A$
LN 140 ? : ? "File is "; BLOCK ; "BLOCKS long. ": ? "Split into how many files (" "; A$;"- "; B$ ; ") >";
BF 150 GET #N1, K1: IF K < ASC (A$)-N128 OR K > ASC(B$)-N 128 THEN 150
ND 160 FOR I = N0 TO N4 : FIL (I) = N0 : NEXT I
BN 170 ? CHR$ (K) : NUM = K-48 : FOR I = N0 TO NUM-N2 : FIL(I) = INT((BLOCK/NUM) + 0.
	 999) : NEXT I
MM 180 FOR I = N0 TO NUM-N2 : FIL (NUM-N1 ) = FIL (NUM-N1) + FIL(I) : NEXT I : FIL(NUM-N1) = BLOCK-FIL(NUM-N1)
HK 190 RETURN
ED 200 FOR J = N1 TO FIL(I-N1)
AH 210 A$="{,}" : A$ (N255) = A$ : A$(N2) = A$
HB 220 TRAP 240 : XIO N4+N3, #N2, N4, N0, A$
AL 230 B$ (LEN(B$) + N1) = A$: NEXT J : RETURN
HC 240 POP : B$(LEN(B$) + N1) = A$ : RETURN
KB 250 ? : ? : ? "{BELL} ERROR - " ; PEEK(195) : TRAP 40000 : CLR : END
OI 260 DIM A$ (N255), F$(N15), FN$(N15), M$ (N4+N1), FIL (4) : MEM = INT (FRE(N0)/N255) * N255 : IF FRE(0)-MEM < 100 THEN MEM = MEM-N255
IF 270 DIM B$ (MEM) : M$ = STR$(MEM) : FOR I = N1 TO LEN(M$) : J = ASC(M$(I, I)) : J =J + N128 : M$(I, I) = CHR$ (J) : NEXT I
HP 280 GRAPHICS N0 : POKE 710, N128
MK 290 ? "{4 SPACES} DOCUMENT/TEXT FILE SPLITTER {4 SPACES}" : ? "Copyright 1987 Compute! Publ., Inc. "
LI 292 ? "{8 SPACES} All Rights Reserved. {7 SPACES}"
CM 295 ? "{5 SPACES} BUFFER = " ; M$ ; "BYTES"
AB 300 CLOSE #N1 : OPEN #N1, N4, N0, "K : "
KP 310 ? : ? "Enter filename of text file to {8 SPACES} to be split into several files."
HB 320 TRAP 320 : ? : ? "file > " ; : INPUT FN$ : IF FN$ = " " THEN ? "{UP} Quit! {3 DELETE}" : GOTO 590
JD 330 IF LEN(FN$) < N3 THEN 370
BE 340 IF FN$(N1, N2) = "D : " THEN FN$ = FN$ (N3) : GOTO 370
BP 350 IF FN$ (N2, N2) <> " : " AND FN$ (N3, N3) <> " : " THEN 370
LB 360 IF FN$ (N3, N3) = " : " THEN F$ = FN$ : GOTO 380
KA 370 F$ = "D1 : " : F$(N4) = FN$
NP 380 DRV = VAL (F$ (N2, N2) )
PF 390 ? : ? "Insert disk with " ; F$ ; " into " : ? "disk drive " ; DRV ; " and press RETURN ";
MH 400 GET #N1, K : IF K <> N155 THEN 400
NE 410 ?
JL 420 IF Q THEN GOSUB 20 : ? "{UP}" ;
ME 430 ? : ? : ? "Save files on drive # (1-4)> " ;
FI 440 GET #1, K : IF K < 49 OR K > 52 THEN 440
FH 450 FN$ = F$ : FN$ (N2, N2) = CHR$ (K) : ? CHR$ (K)
CN 460 ? : ? "Insert SAVE disk in drive " ; K-4B : ? " and press RETURN" ;
IH 470 GET #1, K : IF K <> N155 THEN 470
IB 480 ? : ? : TRAP 250 : CLOSE #N2 : OPEN #N2, N4, N0, F$ : B$ = " " : FOR I = N1 TO NUM
BA 490 ? "Reading"; F$; " - " ; FIL (I-N1); " BLOCKS" : GOSUB 200
NK 500 IF I = NUM THEN ? "Clearing nulls ";
CF 510 IF I = NUM THEN IF B$(LEN(B$)) = " {,}" ; THEN B$ (LEN (B$)) = " " : ? "{, } " ; : GOTO 510
AK 520 IF I = NUM THEN ?
IL 530 FOR M = N4 TO LEN(FN$) : IF FN$ (M, M) = "." THEN FN$(M + 1) = "ZZ" : FN$ (M+3) = STR$ (I) : POP : GOTO 550
CB 540 NEXT M : FN$ (LEN (FN$)+N1) = ".ZZ" : FN$ (LEN (FN$)+N1) = STR$(I)
FD 550 ? "Saving " ; FN$ ; " - " INT((LEN(B$)/DEN)+0.999) ; " SECTORS"
LD 560 TRAP 250 : CLOSE #N3 : OPEN #N3, N4 * N2, N0, FN$
JC 570 ? #N3 ; B$ ; : CLOSE #N3 : B $ = " " : NEXT I
FD 580 ? : ? " {BELL} DONE! {BELL} {3 SPACES} Hit RETURN to quit " : Q = N1 : GOTO 310
OO 590 CLOSE #N1 : CLOSE #N2 : CLOSE #N3 : TRAP 40000 : CLR : END
BN 600 ? : ? F$ ; " has less than 1020" : ? "BYTES. This program will only split" : ? "files greater than 1020 BYTES."
BO 610 GOTO 590
BD 620 ? : ? "{BELL}" ; F$ ; " is too long to split" : ? "5 ways with " ; MEM ; " byte buffer." ; ? "Modify it to split more than that:"
DC 630 ? "DIM FIL(3) … Lines 100-120 … etc." : GOTO 590
KD 640 DATA 0, 1, 2, 3, 4, 15, 128, 155, 255, 1