home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
High Voltage Shareware
/
high1.zip
/
high1
/
DIR4
/
RDUP100.ZIP
/
RDUP.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1993-10-07
|
6KB
|
249 lines
{$M 16384, 0, 0}
uses dos,crt ;
const
tmpd = 'rdup#dir';
masf = 'rdup#fil';
attn = 'δ∞≤▐╙▄√ΣΣ NEXT LINE STARTS NEW FILE!';
procedure showhelp ( errornum : byte );
const
progdata = 'RDUP- Free DOS utility: delete duplicate lines across multiple files.';
progdat2 = 'V1.00: October 07, 1993. (c) 1993 by David Daniel Anderson - Reign Ware.';
usage = 'Usage: RDUP file_spec [/i (=case Insensitive)]';
var
message : string [80];
begin
writeln ( progdata );
writeln ( progdat2 );
writeln ;
writeln ( usage );
writeln ;
case errornum of
1 : message := 'invalid number of command line parameters.';
2 : message := 'unable to create or use storage directory.';
3 : message := 'no files found to process.';
9 : message := 'undefined error.';
end;
writeln ( 'ERROR: (#',errornum,') - ', message );
halt ( errornum );
end;
function converttoupper(w : string) : string;
var
cp : integer; {the position of the character to change.}
begin
for cp := 1 to length(w) do
w[cp] := upcase(w[cp]);
converttoupper := w;
end;
procedure makedir ( tdir : string );
var
resp : char ;
begin
{$I-}
mkdir ( tdir );
if (IOResult <> 0) then begin
writeln ( 'Storage directory ',tdir,' already exists!' );
write ( 'Press "y" to use, any other key to abort: ');
resp := readkey ;
if (upcase (resp) <> 'Y') then showhelp (2);
writeln ( resp );
end;
{$I+}
end;
procedure combine ( tagfiles : string ; var alltg : text );
var
dirinfo : searchrec ;
tagline : string ;
tagfile : text ;
begin
findfirst ( tagfiles, archive, dirinfo );
if ( doserror = 0 ) then begin
assign ( alltg, tmpd+'\'+masf );
rewrite ( alltg );
repeat
assign ( tagfile, dirinfo.name );
reset ( tagfile );
writeln ( alltg,attn );
writeln ( alltg,dirinfo.name );
writeln ( 'Assimilating: ',dirinfo.name );
while ( not ( eof ( tagfile ))) do begin
readln ( tagfile, tagline );
writeln ( alltg, tagline );
end;
close ( tagfile );
findnext ( dirinfo );
until ( doserror <> 0 );
close ( alltg );
end
else
showhelp (3);
end;
procedure separate ( var alltg : text );
var
tagfiles, tagline : string ;
tagfile : text ;
begin
reset ( alltg );
readln ( alltg, tagline );
if (tagline <> attn) then
showhelp (9)
else begin
readln ( alltg, tagline );
assign ( tagfile, tagline );
writeln ( 'De-assimilating: ',tagline );
rewrite ( tagfile );
end;
while ( not ( eof ( alltg ))) do begin
readln ( alltg, tagline );
if (tagline = attn) then begin
close ( tagfile );
readln ( alltg, tagline );
assign ( tagfile, tagline );
writeln ( 'De-Assimilating: ',tagline );
rewrite ( tagfile );
end
else
writeln ( tagfile, tagline );
end;
close ( tagfile );
close ( alltg );
end;
procedure putnumb ( var source : text ; fname : string );
var
numb : word ;
dest : text ;
linec : string ;
begin
assign ( source, fname );
reset ( source );
assign ( dest, 'rwgibber.tmp' );
rewrite ( dest );
numb := 10000 ;
repeat
readln (source,linec);
numb := succ (numb);
writeln ( dest, numb ,' ', linec);
until eof (source);
close ( source );
close ( dest );
erase ( source );
rename ( dest, fname );
end;
procedure rmvnumb ( var source : text ; fname : string );
var
dest : text ;
linec : string ;
begin
assign ( source, fname );
reset ( source );
assign ( dest, 'rwgibber.tmp' );
rewrite ( dest );
repeat
readln ( source, linec );
delete ( linec,1,6);
writeln ( dest,linec );
until eof ( source );
close ( source );
close ( dest );
erase ( source );
rename ( dest, fname );
end;
procedure dduplins ( var sfile : text ; fname : string );
const dischars = 6;
var
dfile : text ;
linecr, lineca,
linenx, linena : string ;
ig_case : boolean ;
ic : string [4];
begin
if ( paramcount = 2 ) then
ig_case := (( converttoupper ( paramstr (2) )) = '/I' )
else ig_case := false ;
if ig_case
then ic := ''
else ic := 'not ';
writeln ( 'Deleting duplicates now, and ',ic,'ignoring case.' );
assign ( sfile, fname );
reset ( sfile );
assign ( dfile, 'rwgibber.tmp' );
rewrite ( dfile );
readln ( sfile,linenx );
linena := linenx;
if ig_case then
linena := converttoupper (linena);
delete ( linena,1,dischars );
while not eof (sfile) do
begin
linecr := linenx;
lineca := linena;
readln ( sfile,linenx );
linena := linenx;
if ig_case then
linena := converttoupper (linena);
delete ( linena,1,dischars );
if (( lineca <> linena ) or ( lineca = attn )) then
writeln ( dfile,linecr );
end;
writeln ( dfile,linenx );
close ( sfile );
close ( dfile );
erase ( sfile );
rename ( dfile, fname );
end;
var
tags : string ;
alltags : text ;
begin
checkbreak := false ;
if ( paramcount < 1 )
or ( paramcount > 2 )
then showhelp (1);
makedir ( tmpd );
tags := paramstr (1);
clrscr ;
writeln ( 'Start!' );
writeln ( 'Constructing master file.' );
combine ( tags, alltags );
chdir ( tmpd );
writeln ( 'Adding line numbers.' );
putnumb ( alltags, masf );
writeln ( 'Shelling out to sort.' );
swapvectors ;
exec ( getenv ('COMSPEC'),' /c rdupsort '+masf+' >nul' );
swapvectors ;
dduplins ( alltags, masf );
writeln ( 'Shelling out to sort.' );
swapvectors ;
exec ( getenv ('COMSPEC'),' /c rdupsort '+masf+' /u >nul' );
swapvectors ;
writeln ( 'Removing line numbers.' );
rmvnumb ( alltags, masf );
separate ( alltags );
writeln ( 'Destroying master file.' );
writeln ( 'Finish!' );
end.