home *** CD-ROM | disk | FTP | other *** search
/ POINT Software Programming / PPROG1.ISO / pascal / swag / findrepl.swg / 0007_FINDDUPL.PAS.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-05-28  |  2.8 KB  |  108 lines

  1. {
  2. TRAVIS GRIGGS
  3.  
  4. > I have one question For you in return: could you send the current
  5. > source code of your Program, or could you otherwise describe what
  6. > your input Text File Characterizations are (how big can the File be,
  7. > how long can the lines be, do you scan each line, or only taglines,
  8.  
  9. Here's the code.  Don't worry about the structure of it.  I know it is bad but
  10. this was a quick and dirty little util I wrote up that I needed.  Have fun With
  11. it and try to speed it up.  And whoever else wants to help have fun!
  12.  
  13. I hope this compiles I took out some stuff that would display a little picture
  14. of a sWord and show the version and product name.  I also tried DJ's idea of
  15. the buffer of 65535 but it said the structure was too large. So I used 64512.
  16. }
  17. Uses Crt;
  18. Type
  19.   BBT  = Array[0..64512] of Char;
  20.  
  21. Var
  22.   BUFF        : ^BBT;
  23.   TheFile,
  24.   logFile     : Text;
  25.   Looking,
  26.   TempStr     : String[80];
  27.   Numoflines,
  28.   F, J, Point : LongInt;
  29.   Divi, Multi : Real;
  30.  
  31. Procedure Stop;
  32. begin
  33.   Close(TheFile);
  34.   Close(LogFile);
  35.   Halt(1);
  36. end;
  37.  
  38. Procedure CommandError(Err:  Byte);
  39. begin
  40.   TextColor(10);
  41.   Case Err Of
  42.     2 : WriteLn('You must specify a File on the command line.');
  43.     3 : WriteLn('Can''t find "', ParamStr(1),'"');
  44.     4 : WriteLn('Too many open Files to open ', ParamStr(1));
  45.     5 : WriteLn('Error in reading ', ParamStr(1));
  46.   end; { end total Case }
  47.   WriteLn;
  48.   Halt(1);
  49. end; { end Procedure }
  50.  
  51. begin
  52.   if Paramcount < 1 Then
  53.     CommandError(2);
  54.   ClrScr;
  55.   Assign(TheFile,ParamStr(1));
  56.   New(BUFF);
  57.   SetTextBuf(TheFile,BUFF^);
  58.   Assign(LogFile,'FINDDUPE.LOG');
  59.   ReWrite(LogFile);
  60.   Reset(TheFile);
  61.   Case IoResult Of
  62.     2 : CommandError(3);
  63.     4 : CommandError(4);
  64.     3,5..162 : CommandError(5);
  65.   end;
  66.   While not EOF(TheFile) Do
  67.   begin
  68.     Readln(TheFile);
  69.     Inc(Numoflines);
  70.   end;
  71.   Writeln('There are ',Numoflines,' lines in this File.');
  72.   Writeln;
  73.   Writeln('Duplicate lines are being written to FINDDUPE.LOG');
  74.   Writeln;
  75.   Writeln('Press any key to stop the search For duplicate lines');
  76.   Point := 0;
  77.   Reset(TheFile);
  78.   While Point <> Numoflines Do
  79.   begin
  80.     GotoXY(1, 7);
  81.     if Point <> 0 Then
  82.     begin
  83.       Divi  := Point / Numoflines;
  84.       Multi := Divi * 100;
  85.       WriteLn(Multi : 3 : 2, '% Completed');
  86.     end;
  87.     Reset(TheFile);
  88.     if Point <> 0 Then
  89.       For J := 1 to Point Do
  90.         Readln(TheFile);
  91.     Readln(TheFile,Looking);
  92.     Reset(TheFile);
  93.     Inc(Point);
  94.     For F := 1 to Numoflines Do
  95.     begin
  96.       if KeyPressed then
  97.         Stop;
  98.       Readln(TheFile, TempStr);
  99.       if (Point <> F) and (TempStr = Looking) Then
  100.         Writeln(LogFile,Looking);
  101.     end;
  102.   end;
  103.   GotoXY(1, 7);
  104.   Writeln('100.00% Completed');
  105.   Close(TheFile);
  106.   Close(LogFile);
  107. end.
  108.