home *** CD-ROM | disk | FTP | other *** search
- program FileJoiner;
-
- (*
- FJoin (file joiner) re-creates a large source text file, following a
- file splitting by FSplit. All file to be joined should be typed
- on the command-line. Default reconstruction using FSplit nomenclature
- can be flagged using the -D option with only the filename (no extension).
- FSplit names use extensions which are sequentially numbered, starting at
- *.@@1 and going up to *.@99.
-
- Robert L. Jones, CIS [71251,2566]
- Version 1.0 released to the public domain 6/25/89.
- *)
-
- uses crt,dos;
-
- const
- title : string = 'FJOIN (the file joiner) v1.0 by R. L. Jones';
- var
- FName : array [1..256] of string[80];
- DestFName : string[80];
- DefaultName,EraseFiles : boolean;
- infile,outfile : file;
- NumFiles : byte;
- buf : array [1..2048] of char;
- 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>');
- textcolor(lightgray);
- writeln;
- writeln(' ',title);
- writeln;
- writeln(' The purpose of ',s,'.EXE is to join large text files which were');
- writeln(' previously split by FSPLIT. The user specifies the file names on');
- writeln(' the command line as indicated below. Default filename extensions, as');
- writeln(' originally provided by FSPLIT, can be chosen using the -D switch.');
- writeln(' The default name scheme is: *.@@1 - *.@99. The result of the');
- writeln(' program will be stored in the file "source.$@@". ',s,' can');
- writeln(' re-connect files previously FSPLIT in either ASCII or binary format.');
- writeln;
- writeln(' examples:');
- textcolor(lightred);
- writeln(' ',s,' filename -D <-- use default extensions');
- writeln(' ',s,' filename -DE <-- use default & erase sources');
- writeln(' ',s,' fname1.ext fname2.ext <-- use specified file names');
- writeln(' ',s,' fname1.ext fname2.ext -E <-- use specified files & erase');
- textcolor(lightgray);
- halt(1);
- end;
-
-
- {$F+} PROCEDURE ReturnToDOS; {$F-}
- BEGIN
- {$I-}
- CLOSE(infile);
- if (IOResult <> 0) then ;
- CLOSE(outfile);
- if (IOResult <> 0) then ;
- {$I+}
- textcolor(lightgray);
- ExitProc := ExitSave;
- END;
-
-
- procedure SetUp;
- var
- i : byte;
- s : string[80];
- begin
- ExitSave := ExitProc; { Force return to DOS if we crash. }
- ExitProc := @ReturnToDos;
-
- clrscr;
- DefaultName := FALSE;
- EraseFiles := FALSE;
- if (ParamCount < 2) then Usage;
-
- textcolor(yellow);
- write(title);
- textcolor(lightgray);
-
- FillChar(FName,sizeof(FName),0);
- FName[1] := ParamStr(1);
- DestFName := FName[1];
-
- s := ParamStr(2);
- if (((UpCase(s[2]) = 'D') OR (UpCase(s[3]) = 'D')) AND
- (s[1] in ['/','-','\'])) then
- DefaultName := TRUE;
- if (((UpCase(s[2]) = 'E') OR (UpCase(s[3]) = 'E')) AND
- (s[1] in ['/','-','\'])) then
- EraseFiles := TRUE;
- if (pos('.',FName[1]) = 0) OR (DefaultName) then begin
- DefaultName := TRUE;
- if (pos('.',FName[1]) <> 0) then
- delete(FName[1],pos('.',FName[1]),length(FName[1]));
- end
- else begin
- NumFiles := ParamCount;
- dec(NumFiles);
- i := 2;
- repeat
- FName[i] := ParamStr(i);
- s := FName[i];
- if ((UpCase(s[2]) = 'E') AND (s[1] in ['/','-','\'])) then begin
- EraseFiles := TRUE;
- FName[i] := '';
- dec(i);
- end;
- inc(i);
- dec(NumFiles);
- until NumFiles = 0;
- NumFiles := i-1;
- end;
- if (pos('.',DestFName) <> 0) then
- delete(DestFName,pos('.',DestFName),length(DestFName));
- DestFName := DestFName + '.$@@';
- end; {of SetUp}
-
-
- function OpenFiles : BOOLEAN;
- var
- ch : CHAR;
- begin
- OpenFiles := FALSE;
- if (LENGTH(FName[1]) < 1) then EXIT;
-
- ASSIGN(infile,FName[1]);
- {$I-}
- RESET(infile,1);
- if (IOResult <> 0) then begin
- Exit;
- end;
-
- ASSIGN(outfile,DestFName);
- RESET(outfile,1);
- if (IOResult = 0) then begin
- window(10,9,70,12);
- textcolor(lightred);
- write('Output file already exists; overwrite (Y/N)? ');
- ch := readkey;
- if (UpCase(ch) = 'Y') then begin
- REWRITE(outfile,1);
- if (IOResult <> 0) then Exit;
- end
- else begin
- window(1,1,80,25);
- clrscr;
- HALT(1);
- end;
- clrscr;
- textcolor(lightgray);
- window(1,1,80,25);
- end
- else begin
- REWRITE(outfile,1);
- if (IOResult <> 0) then Exit;
- end;
- OpenFiles := TRUE;
- gotoxy(5,4);
- END; { of OpenFiles }
-
-
- procedure ProcessFile;
- var
- ch : char;
- CurrFile : byte;
- numstrg : string[2];
- i,numread,numwritten : integer;
- begin
- CurrFile := 1;
- repeat
- repeat
- if (KeyPressed) then begin
- ch := ReadKey;
- if upcase(ch) in ['Q',chr(27)] then HALT(1);
- end;
- FillChar(buf,sizeof(buf),0);
- BlockRead(infile,buf,sizeof(buf),numread);
- if (IOResult <> 0) then Exit;
- BlockWrite(outfile,buf,numread,numwritten);
- if (IOResult <> 0) then Exit;
- until (numread = 0) OR (numread <> numwritten);
-
- if (EraseFiles) then begin
- ERASE(infile);
- if (IOResult <> 0) then ;
- end
- else begin
- CLOSE(infile);
- if (IOResult <> 0) then ;
- end;
-
- inc(CurrFile);
- if (DefaultName) then begin
- str(CurrFile,numstrg);
- delete(FName[CurrFile-1],
- pos('.',FName[CurrFile-1]),length(FName[CurrFile-1]));
- if (CurrFile < 10) then
- FName[CurrFile] := FName[CurrFile-1] + '.@@' + numstrg
- else
- FName[CurrFile] := FName[CurrFile-1] + '.@' + numstrg;
- end;
- ASSIGN(infile,FName[CurrFile]);
-
- {
- if DefaultName is true, reset'ing a non-existent file will
- result in an I/O error and exit the procedure
- }
- RESET(infile,1);
- if (IOResult <> 0) then Exit;
- until ((CurrFile > NumFiles) AND not(DefaultName));
- end; { ProcessFile }
-
-
- procedure OpeningRemarks;
- var
- i : byte;
- begin
- gotoxy(1,3);
- write('Processing files:');
- gotoxy(5,4);
- textcolor(lightred);
- if (DefaultName) then begin
- write(FName[1]);
- FName[1] := FName[1] + '.@@1';
- end
- else begin
- for i := 1 to NumFiles-1 do begin
- write(FName[i]);
- write(',');
- end;
- write(FName[NumFiles]);
- end;
- textcolor(lightgray);
- end;
-
-
- BEGIN
- SetUp;
- OpeningRemarks;
- if (NOT (OpenFiles)) then halt(1);
- ProcessFile;
- textcolor(lightgray);
- writeln;
- writeln;
- write('Done...');
- END.
-