fpc/tests/utils/concat.pp
Jonas Maebe 252483ffd8 + support for running the testsuite in parallel. Note that only the "all"
target can be run in parallel, so "clean", "digest" and/or "dbdigest"
    have to be run in separate make invocations if you wish to use -j for
    running the testsuite

git-svn-id: trunk@21406 -
2012-05-28 09:14:56 +00:00

84 lines
1.5 KiB
ObjectPascal

{ Concatenates a number of text files. This code is in the public domain. }
program concat;
uses
SysUtils;
var
Dst: TextFile;
procedure usage;
begin
Writeln('Usage: concat <srcfile1> [<srcfile2> ..] <dstfile>');
Writeln;
halt(1);
end;
procedure DoConcat;
var
Src: TextFile;
I: Longint;
Line: Ansistring;
begin
for I:=1 to ParamCount-1 do
begin
Assign(Src,ParamStr(I));
Reset(Src);
while not Eof(Src) do
begin
ReadLn(Src,Line);
Writeln(Dst,Line);
end;
Close(Src);
end;
Close(Dst);
end;
procedure CheckParas;
var
I: Longint;
begin
{ enough parameters? }
if ParamCount<2 then
Usage;
{ check destination }
if DirectoryExists(ParamStr(ParamCount)) then
begin
Writeln('Destination "',ParamStr(ParamCount),'" is a directory');
halt(2);
end;
Assign(Dst,ParamStr(ParamCount));
{$i-}
Rewrite(Dst);
{$i+}
if IOResult<>0 then
begin
Writeln('Unable to create destination file "',ParamStr(ParamCount),'"');
halt(2);
end;
{ check source(s) }
for I:=1 to ParamCount-1 do
begin
if not FileExists(ParamStr(I)) then
begin
Writeln('File "',ParamStr(I),'" does not exist');
halt(2);
end;
if DirectoryExists(ParamStr(I)) then
begin
Writeln('"',ParamStr(I),'" is a directory');
halt(2);
end;
end;
end;
begin
CheckParas;
DoConcat;
end.