uses Strings;
const
  PathLength  = 100; {65;} {DOS_PATH Length.}
  LineFeed = #10;
  CarriageReturn = #13;
  OutFile = 'warning!.log';
  SubStr = 'skipped';
  SubStr1 = 'SysOp:';
  n= 100;

type
  FileName  = string[PathLength];
var
  Mainfp:text;
  use:    Byte;
  MainFileName,OutputFileName: FileName;

  In_string,In_string1,In_string2: array[0..n] of Char;

 function Open(var fp:text; name: Filename): boolean;
  begin
    Assign(fp,Name);
    {$I-}
    Reset(fp);
    {$I+}
    Open := IOResult = 0;
  end { Open };

 procedure OpenMain;
  begin
   if ParamCount > 2 then
      begin
       Writeln('ERROR: too many paramters.');
       Writeln('ERROR:  file not found: ''', MainFileName, '''');
       Writeln('USAGE:');
       Writeln('skipwarn.exe input_file output_file');
       Writeln('Input_file is usualy the t-mail.log or equivalent.');

       Writeln('it''ll be searched for dangerouse',
                ' t-mail messages about skipping some files..');
       Writeln('Default output_file is warning!.log ');
       Halt(5)
      end;

   if ParamCount = 0 then
    begin
      Write('Enter filename w/ data: ');
      Readln(MainFileName);
      Write('Enter filename for output: ');
      Readln(OutputFileName);
    end;

   if ParamCount = 1 then
                      begin
                       if ParamStr(1)='/?'
                        then
                          begin
      Writeln('USAGE:');
      Writeln('skipwarn.exe input_file output_file');
      Writeln('Input_file is usualy the t-mail.log or equivalent.');
      Writeln('it''ll be searched for dangerouse',
               ' t-mail messages about skipping some files..');
      Writeln('Default output_file is warning!.log ');
                Halt(0)
                          end
                        else
                          begin
                           MainFileName := ParamStr(1);
                           Write('Enter filename for output: ');
                           Readln(OutputFileName)
                          end
                      end;
   if ParamCount = 2 then
                      begin
                       MainFileName  := ParamStr(1);
                       OutputFileName:= ParamStr(2)
                      end;
   if (MainFileName = '') or not Open(Mainfp,MainFileName) then
    begin
      Writeln('ERROR:  file not found: ''', MainFileName, '''');
      Writeln('USAGE:');
      Writeln('skipwarn.exe input_file output_file');
      Writeln('Input_file is usualy the t-mail.log or equivalent.');

      Writeln('it''ll be searched for dangerouse',
               ' t-mail messages about skipping some files..');
      Writeln('Default output_file is warning!.log ');
      Halt(1);
    end;
   if (OutputFileName = '') then OutputFileName:=OutFile;
 end {Open Main};

 procedure ProcessFile(var name: Filename);
  var
   P: PChar;
   fp: text;
  begin  {Process File}
    Assign(fp,Name);
    {$I-}
    Rewrite(fp);
    {$I+}
    if  (IOResult = 0 ) = false then
                                  begin
                                   name:=OutFile;
                                   Assign(fp,Name);
                                   Rewrite(fp)
                                  end;

     Writeln('Reading.. ');
     use:=0;

     Assign(mainfp,MainFileName);
     Reset(mainfp);

     while not EOF(mainfp) do
      begin
        for use:=1 to  n do In_string[use]:=' ';
        Readln(mainfp,In_string);
        P := StrPos(In_string, SubStr1);
        if (P = nil) = false
          then
            begin
             In_string1:=In_string;
             Readln(mainfp,In_string2);
            end;
        P := StrPos(In_string, SubStr);
        if (P = nil) = false
          then
            begin
             Write(fp,CarriageReturn,LineFeed);
             Write(fp,CarriageReturn,LineFeed);
             Writeln(fp,'************ WARNING! ************ ');
             Writeln(fp,In_string1);
             Writeln(fp,In_string2);
             Writeln(fp,In_string);
             Write(fp,CarriageReturn,LineFeed);
            end
      end;
     Writeln('All done.');
     Close(fp);
  end {Process File};


begin
 Writeln('t-mail.log watcher.(c) Olli. License is current GNU GPL.');
 Writeln('Looks in t-mail.log for skipped files.');
 Writeln;
 OpenMain;
 Writeln('Reading data from file ',MainFileName,' . Please wait..');
 ProcessFile(OutputFileName)
end.

