home *** CD-ROM | disk | FTP | other *** search
- program FileSplitter;
-
- (*
- Fsplit (file splitter) creates sub-divisions of a source text file,
- using a command-line file size. The file size should reflect the size
- of the destination media. That is, specifying '1440' for a 1.44M
- 3.5" floppy is OK, as is the parameter '360', in order to make the
- files small enough to fit onto a 360K 5.25" floppy. All file names
- are sequentially numbered, starting at *.@@1 and going up to *.@99.
-
- A binary file mode is also implimented, using a -B switch; this enables
- BlockRead/BlockWrite commands, processing binary files a little faster.
-
- The complimentary FJOIN program can re-connect files previously FSPLIT
- in either ASCII or binary format.
-
- Robert L. Jones, CIS [71251,2566]
- Version 1.1 released to the public domain 6/25/89.
- *)
-
- uses crt,dos;
-
- const
- title : string = 'FSPLIT (the file splitter) v1.1 by R. L. Jones';
- maxsize = 2048;
- var
- FName,DestFName : string;
- BinaryMode : boolean;
- infile,outfile : text;
- Binfile,Boutfile : file;
- buf : array [1..maxsize] of char;
- floppysize : longint;
- sr : searchrec;
- spf : longint; { size per floppy }
- ExitSave : pointer;
-
-
- procedure Usage;
- var
- s : string;
- begin
- s := ParamStr(0);
- repeat
- delete(s,1,pos('\',s));
- until pos('\',s) = 0;
- delete(s,pos('.',s),length(s));
-
- textcolor(lightgreen);
- writeln(' USAGE: ',s,' <source> <value> <option: -B>');
- textcolor(lightgray);
- writeln;
- writeln(' ',title);
- writeln;
- writeln(' The purpose of ',s,'.EXE is to split large text files into segments');
- writeln(' which will fit onto floppy disks. User specifies size of the segments.');
- writeln(' Copying proceeds with a given file until 95% of the portion is used.');
- writeln(' The copying will continue using another file, incrementally numbered');
- writeln(' using the scheme: *.@@1 - *.@99. The user will be prompted before');
- writeln(' overwriting a previously stored file. The <-B> switch will override');
- writeln(' the default ASCII text file mode, and use binary copying techniques');
- writeln(' for non-ASCII files (the complimentary program FJOIN can be used to');
- writeln(' re-connect files split in either ASCII or binary format).');
- writeln;
- writeln(' examples:');
- textcolor(lightred);
- writeln(' ',s,' filename.ext 360 <-- for 360K floppies');
- writeln(' ',s,' filename.ext 1440 <-- for 1.44M floppies');
- writeln(' ',s,' filename.ext 1440 -B <-- for 1.44M in binary mode');
- textcolor(lightgray);
- halt(1);
- end;
-
-
- {$F+} PROCEDURE ReturnToDOS; {$F-}
- BEGIN
- {$I-}
- if (BinaryMode) then begin
- CLOSE(Binfile);
- if (IOResult <> 0) then ;
- CLOSE(Boutfile);
- if (IOResult <> 0) then ;
- end
- else begin
- CLOSE(infile);
- if (IOResult <> 0) then ;
- CLOSE(outfile);
- if (IOResult <> 0) then ;
- end;
- {$I+}
- textcolor(lightgray);
- ExitProc := ExitSave;
- END;
-
-
- procedure SetUp;
- var
- code : integer;
- s : string[80];
- begin
- ExitSave := ExitProc; { Force return to DOS if we crash. }
- ExitProc := @ReturnToDos;
-
- clrscr;
- if (ParamCount < 2) then Usage;
-
- textcolor(yellow);
- write(title);
- BinaryMode := FALSE;
- FName := ParamStr(1);
- DestFName := FName;
- if (pos('.',DestFName) <> 0) then
- delete(DestFName,pos('.',DestFName),length(DestFName));
- DestFName := DestFName + '.@@1';
-
- val(ParamStr(2), floppysize, code);
- if (code <> 0) OR (floppysize < 1) then Usage;
- floppysize := floppysize * 1000; { set to 95%; not 1024 }
-
- if (ParamCount = 3) then begin
- s := ParamStr(3);
- if ((UpCase(s[2]) = 'B') AND (s[1] in ['/','-','\'])) then
- BinaryMode := TRUE;
- end;
- end; {of SetUp}
-
-
- function OpenFiles : BOOLEAN;
- var
- ch : CHAR;
- begin
- OpenFiles := FALSE;
- if (LENGTH(FName) < 1) then EXIT;
-
- FindFirst(FName,$3F,sr);
- if (DosError <> 0) then Exit;
- spf := round(sr.size/floppysize);
- ASSIGN(infile,FName);
- {$I-}
- RESET(infile);
- if (IOResult <> 0) then Exit;
-
- ASSIGN(outfile,DestFName);
- RESET(outfile);
- if (IOResult = 0) then begin
- window(10,9,70,12);
- write('Output file already exists; overwrite (Y/N)? ');
- ch := readkey;
- if (UpCase(ch) = 'Y') then begin
- REWRITE(outfile);
- if (IOResult <> 0) then Exit;
- end
- else HALT(1);
- clrscr;
- window(1,1,80,25);
- end
- else begin
- REWRITE(outfile);
- if (IOResult <> 0) then Exit;
- end;
- OpenFiles := TRUE;
- END; { of OpenFiles }
-
-
- function BinaryOpenFiles : BOOLEAN;
- var
- ch : CHAR;
- begin
- BinaryOpenFiles := FALSE;
- if (LENGTH(FName) < 1) then EXIT;
-
- FindFirst(FName,$3F,sr);
- if (DosError <> 0) then Exit;
- if (floppysize < maxsize) then
- floppysize := maxsize;
- spf := round(sr.size/floppysize) + 1;
-
- ASSIGN(Binfile,FName);
- {$I-}
- RESET(Binfile,1);
- if (IOResult <> 0) then Exit;
-
- ASSIGN(Boutfile,DestFName);
- RESET(Boutfile,1);
- if (IOResult = 0) then begin
- window(10,9,70,12);
- write('Output file already exists; overwrite (Y/N)? ');
- ch := readkey;
- if (UpCase(ch) = 'Y') then begin
- REWRITE(Boutfile,1);
- if (IOResult <> 0) then Exit;
- end
- else begin
- window(1,1,80,25);
- HALT(1);
- end;
- clrscr;
- textcolor(lightgray);
- window(1,1,80,25);
- end
- else begin
- REWRITE(Boutfile,1);
- if (IOResult <> 0) then Exit;
- end;
- BinaryOpenFiles := TRUE;
- END; { of BinaryOpenFiles }
-
-
- procedure ProcessFile;
- var
- ch : char;
- counter : byte;
- currsize,line : longint;
- numstrg : string[2];
- s : string;
- begin
- counter := 1;
- line := 0;
- currsize := 0;
- textcolor(lightgray);
- gotoxy(1,6);
- write('Processing line:');
- textcolor(lightgreen);
- gotoxy(18,5);
- write(counter);
-
- repeat
- inc(line);
- gotoxy(18,6);
- write(line);
- if (KeyPressed) then begin
- ch := ReadKey;
- if upcase(ch) in ['Q',chr(27)] then HALT(1);
- end;
- ReadLn(infile,s);
- if (IOResult <> 0) then Exit;
- inc(currsize,length(s)*sizeof(char));
-
- if (currsize < floppysize) then begin
- WriteLn(outfile,s);
- if (IOResult <> 0) then Exit;
- end
- else begin
- currsize := length(s)*sizeof(char);
- CLOSE(outfile);
- if (IOResult <> 0) then ;
- delete(DestFName,pos('.',DestFName),length(DestFName));
- inc(counter);
- str(counter,numstrg);
- if (counter < 10) then
- DestFName := DestFName + '.@@' + numstrg
- else
- DestFName := DestFName + '.@' + numstrg;
- ASSIGN(outfile,DestFName);
- RESET(outfile);
- if (IOResult = 0) then begin
- window(10,9,70,12);
- write('Output file already exists; overwrite (Y/N)? ');
- ch := readkey;
- if (UpCase(ch) = 'Y') then begin
- REWRITE(outfile);
- if (IOResult <> 0) then Exit;
- end
- else begin
- clrscr;
- window(1,1,80,25);
- Exit;
- end;
- clrscr;
- window(1,1,80,25);
- end
- else begin
- REWRITE(outfile);
- if (IOResult <> 0) then Exit;
- end;
-
- WriteLn(outfile,s);
- if (IOResult <> 0) then Exit;
- gotoxy(18,5);
- write(counter);
- end; { of else }
- until EOF(infile);
- end; { ProcessFile }
-
-
- procedure ProcessBinaryFile;
- var
- ch : char;
- counter,x,y : byte;
- currsize,block : longint;
- numstrg : string[2];
- i,numread,numwritten : integer;
- begin
- counter := 1;
- block := 0;
- currsize := 0;
- textcolor(lightgray);
- gotoxy(1,6);
- write('Processing ',maxsize,'-block: ');
- x := wherex;
- y := wherey;
- textcolor(lightgreen);
- gotoxy(18,5);
- write(counter);
-
- repeat
- inc(block);
- gotoxy(x,y);
- write(block);
-
- if (KeyPressed) then begin
- ch := ReadKey;
- if upcase(ch) in ['Q',chr(27)] then HALT(1);
- end;
- FillChar(buf,sizeof(buf),0);
- BlockRead(Binfile,buf,sizeof(buf),numread);
-
- if (IOResult <> 0) then Exit;
- inc(currsize,numread);
-
- if (currsize <= floppysize) then begin
- BlockWrite(Boutfile,buf,numread,numwritten);
- if (IOResult <> 0) then Exit;
- end
- else begin
- currsize := numread;
- CLOSE(Boutfile);
- if (IOResult <> 0) then ;
- delete(DestFName,pos('.',DestFName),length(DestFName));
- inc(counter);
- str(counter,numstrg);
- if (counter < 10) then
- DestFName := DestFName + '.@@' + numstrg
- else
- DestFName := DestFName + '.@' + numstrg;
- ASSIGN(Boutfile,DestFName);
- RESET(Boutfile,1);
- if (IOResult = 0) then begin
- window(10,9,70,12);
- write('Output file already exists; overwrite (Y/N)? ');
- ch := readkey;
- if (UpCase(ch) = 'Y') then begin
- REWRITE(Boutfile,1);
- if (IOResult <> 0) then Exit;
- end
- else begin
- clrscr;
- window(1,1,80,25);
- Exit;
- end;
- clrscr;
- window(1,1,80,25);
- end
- else begin
- REWRITE(Boutfile,1);
- if (IOResult <> 0) then Exit;
- end;
-
- BlockWrite(Boutfile,buf,numread,numwritten);
- if (IOResult <> 0) then Exit;
- gotoxy(18,5);
- write(counter);
- end; { of else }
- until (numread = 0) OR (numread <> numwritten);
- end; { ProcessBinaryFile }
-
-
- procedure OpeningRemarks;
- begin
- if (BinaryMode) then begin
- if (NOT (BinaryOpenFiles)) then halt(1);
- end
- else begin
- if (NOT (OpenFiles)) then halt(1);
- end;
- gotoxy(1,3);
- textcolor(lightgray);
- write('Spliting file ');
- textcolor(lightred);
- write(FName);
- textcolor(lightgray);
- write(' into ');
- textcolor(lightgreen);
- write(spf);
- textcolor(lightgray);
- write('-',floppysize,' byte files.');
-
- gotoxy(1,5);
- write('Writing file:');
- end;
-
-
- BEGIN
- SetUp;
- OpeningRemarks;
- if (BinaryMode) then
- ProcessBinaryFile
- else
- ProcessFile;
- textcolor(lightgray);
- writeln;
- writeln;
- write('Done...');
- END.
-