Changeset 4


Ignore:
Timestamp:
Jul 28, 2015, 1:54:42 PM (9 years ago)
Author:
chronos
Message:
  • Added: New parameter -t for program termination if given string found.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/linetime.lpr

    r3 r4  
    2626    LogFile: TFileStream;
    2727    LogEnabled: Boolean;
     28    TermString: string;
     29    TermStringIndex: Integer;
    2830    procedure WriteRaw(Text: string);
    2931    procedure WriteLog(Text: string);
     
    4951begin
    5052  // Quick check parameters
    51   ErrorMsg := CheckOptions('hcl', 'help csv log');
     53  ErrorMsg := CheckOptions('hclt:', 'help csv log termstr');
    5254  if ErrorMsg <> '' then begin
    5355    ShowException(Exception.Create(ErrorMsg));
     
    6264    Exit;
    6365  end;
     66
     67  if HasOption('t', 'termstr') then begin
     68    TermString := GetOptionValue('t', 'termstr');
     69  end else TermString := '';
    6470
    6571  FormatCSV := HasOption('c', 'csv');
     
    7783  StartTime := Now;
    7884  LastLineTime := 0;
     85  TermStringIndex := 1;
    7986  try
    8087    InputStream := TIOStream.Create(iosInput);
     
    8491      SetLength(Buffer, Count);
    8592      ProcessBuffer(Buffer);
    86     until Count = 0;
    87 
     93    until (Count = 0) or Terminated;
    8894    PrintOutput('');
    8995  finally
     
    9399  WriteLog(LineEnding);
    94100
    95   // stop program loop
    96101  Terminate;
    97102end;
     
    145150var
    146151  P: Integer;
     152  I: Integer;
    147153  Part: string;
    148154begin
     
    158164      ShowTime := True;
    159165    end;
     166
     167    // Search for termination string
     168    if TermString <> '' then
     169    for I := 1 to Length(Buffer) - 1 do begin
     170      if TermStringIndex > Length(TermString) then begin
     171        Terminate;
     172        Break;
     173      end;
     174      if Buffer[I] = TermString[TermStringIndex] then
     175        Inc(TermStringIndex)
     176        else TermStringIndex := 1;
     177    end;
    160178  until P = 0;
    161179  PrintOutput(Buffer);
     
    178196  { add your help code here }
    179197  WriteLn('Usage: ', ExeName, ' -h');
    180   WriteLn(' -c --csv Print lines in CSV format');
    181   WriteLn(' -l --log Log output to log files in ~/.linetime/logs');
     198  WriteLn(' -c --csv         Print lines in CSV format');
     199  WriteLn(' -l --log         Log output to log files in ~/.linetime/logs');
     200  WriteLn(' -t --termstr <string> Termination string');
    182201end;
    183202
Note: See TracChangeset for help on using the changeset viewer.