Jesus Reyes wrote:
Here is one of the parsers from my program (LogAnalyzer on www.mc-antivirus-tet.com) for you to see how dirty job is parsing some kinds of log files.--- bobby <[EMAIL PROTECTED]> escribió: At the moment all the parsers are in the main unit, and I don't see a way to get them sorted like one parser = one unit, or eventually to get them in the future to one parser = one dll. The problem is a bit behind my knowledge. The parser per-se is not slow, it parse 70mb file in less than 20 seconds. The problem is that I want it out of main unit. Thats why I had a request of simple class that can mimic StringGrid. procedure TfrmMain.parKAV45Parser(FileName: string; dlmt: string); var Lista: TStringList; i: integer; Row: integer; sLine: string; sField: string; posComma: integer; posComma2: integer; posComma3: integer; flagValid: boolean; filePath: string; lastFile: string; filePos: extended; begin Lista:= TStringList.Create; Lista.LoadFromFile(FileName); StringGrid1.RowCount := Lista.Count +1; //enough space for sure, the unused space is deleted at the end of this code Row := 0; lastFile := 'there is no chance to have file-name like this string'; //any string that is almost impossible to have as filepath/name filePos := 0; for i:= 0 to Lista.Count-1 do begin // pocni citanje iz liste sLine:= Lista[i]; filePos:= (i/Lista.Count*100); updateProgress(filePos); if cancelOp = true then break; flagValid := false; if (AnsiContainsText(sLine, #9 + 'Infected')) or (AnsiContainsText(sLine, #9 + 'Warning')) or (AnsiContainsText(sLine, #9 + 'Suspicious')) then flagValid := true; if AnsiStartsText('OK', sLine) then flagValid := false; // first field in the line is a filename/path of the file scanned posComma := pos(dlmt, sLine); posComma3 := pos ('/', sLine); // if there is a '/' it means that the rest of the path is inside an archive (ZIP, RAR...) if flagValid then begin if posComma > 0 then begin if PosComma3 > 0 then filePath := copy(sLine, 1, posComma3 - 1) else filePath := copy(sLine, 1, posComma - 1); if (AnsiContainsStr(ExtractFilePath(filePath), ExtractFileName(lastFile)) = false) and (AnsiCompareStr(lastFile,filePath) <> 0) then // now begins the part of code that can be done just with using grid or grid-alike component begin Row := Row + 1; // it may happen that more than one line is describing the same file, put all the info into one row // also, if the files are inside the archive, just one row is used with the path to archive, not the files inside lastFile := filePath; // remember the file for the next cycle in the loop StringGrid1.Cells[0, Row] := filePath; end; Delete(sLine, 1, PosComma); // delete the filename/path from the line repeat // read the rest of the line and parse to rest of the row PosComma := Pos(dlmt, sLine); PosComma := PosEx(dlmt, sLine, PosComma +1); if PosComma > 0 then sField := Copy(sLine, 1, PosComma - 1) else sField := sLine; if AnsiContainsText(sField, 'Infected') then begin repeat posComma2 := pos(dlmt, sField); if posComma2 > 0 then Delete(sField, 1, PosComma2); until posComma2 = 0; if (StringGrid1.Cells[3, Row] = '') or (AnsiContainsStr(sField, StringGrid1.Cells[3, Row])) or (AnsiContainsStr(StringGrid1.Cells[3, Row], sField)) then StringGrid1.Cells[3, Row] := sField else begin StringGrid1.Cells[3, Row] := 'Multiple malware_' + Hash_file(StringGrid1.Cells[0, Row], ComboBox4.ItemIndex); end; end; if AnsiContainsText(sField, 'Warning') then begin repeat posComma2 := pos(dlmt, sField); if posComma2 > 0 then Delete(sField, 1, PosComma2); until posComma2 = 0; if (StringGrid1.Cells[3, Row] = '') or (AnsiContainsStr(sField, StringGrid1.Cells[3, Row])) or (AnsiContainsStr(StringGrid1.Cells[3, Row], sField)) then StringGrid1.Cells[3, Row] := sField else begin StringGrid1.Cells[3, Row] := 'Multiple malware_' + Hash_file(StringGrid1.Cells[0, Row], ComboBox4.ItemIndex); end; end; if AnsiContainsText(sField, 'Suspicious') then begin repeat posComma2 := pos(dlmt, sField); if posComma2 > 0 then Delete(sField, 1, PosComma2); until posComma2 = 0; if (StringGrid1.Cells[3, Row] = '') or (AnsiContainsStr(sField, StringGrid1.Cells[3, Row])) or (AnsiContainsStr(StringGrid1.Cells[3, Row], sField)) then StringGrid1.Cells[3, Row] := sField else begin StringGrid1.Cells[3, Row] := 'Multiple malware_' + Hash_file(StringGrid1.Cells[0, Row], ComboBox4.ItemIndex); end; end; if PosComma > 0 then begin Delete(sLine, 1, PosComma); end; until posComma = 0; // end of the line in log end; end; end; Lista.Free; //the rest of the code will delete unused rows from the StringGrid, as we have them more then we need i := 1; while i <> StringGrid1.RowCount do begin if StringGrid1.Cells[0,i] = '' then begin StringGrid1.RowCount := i; end else i := i + 1; end; end; _________________________________________________________________ To unsubscribe: mail [EMAIL PROTECTED] with "unsubscribe" as the Subject archives at http://www.lazarus.freepascal.org/mailarchives |
- Re: [lazarus] Question of feature... Lepidosteus
- Re: [lazarus] Question of feature: code browse... Alexandre Leclerc
- Re: [lazarus] Question of feature: code browse... Mattias Gaertner
- Re: [lazarus] Question of feature: code b... Alexandre Leclerc
- Re: [lazarus] Question of feature: code b... Graeme Geldenhuys
- [lazarus] Writing a class (please poi... bobby
- Re: [lazarus] Writing a class (pl... Felipe Monteiro de Carvalho
- Re: [lazarus] Writing a class (pl... Alexandre Leclerc
- Re: [lazarus] Writing a class (pl... Alexandre Leclerc
- Re: [lazarus] Writing a class (pl... Jesus Reyes
- Re: [lazarus] Writing a class... bobby
- Re: [lazarus] Writing a ... Alexandre Leclerc
- RE: [lazarus] Question of feature: code browse... George Birbilis
- Re: [lazarus] Question of feature: code b... Burkhard Carstens
- Re: [lazarus] Question of feature: code b... Mattias Gaertner
- Re: [lazarus] Question of feature: co... Michael Van Canneyt
- Re: [lazarus] Question of feature... Mattias Gaertner
- Re: [lazarus] Question of fea... Michael Van Canneyt
- Re: [lazarus] Question o... Mattias Gaertner
- Re: [lazarus] Questi... Michael Van Canneyt
- RE: [lazarus] Question of feature: co... George Birbilis
