123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- {$mode objfpc}
- {$h+}
- uses
- classes,dom,xmlread;
- procedure error(const s : string);
- begin
- writeln('Error: ',s);
- halt(1);
- end;
- var
- doc : txmldocument;
- root : TDomNode;
- entry,
- currentpath,
- currentinfo : TDomNode;
- hs,
- currentmsg,
- currentauthor,
- currentdate,
- pathtemp,
- currentrevision : string;
- paths : tstringlist;
- i,j,maxequal : longint;
- begin
- paths:=tstringlist.create;
- paths.sorted:=true;
- ReadXMLFile(doc,paramstr(1));
- root:=doc.DocumentElement;
- if root.haschildnodes and
- (root.NodeName='log') then
- begin
- entry:=root.firstchild;
- while assigned(entry) do
- begin
- if entry.NodeName<>'logentry' then
- error('Only log entry entries supported, but '+entry.NodeName+' found.');
- currentmsg:='';
- currentauthor:='';
- currentdate:='';
- { get revision }
- with entry as tdomelement do
- currentrevision:=AttribStrings['revision'];
- if entry.haschildnodes then
- begin
- currentinfo:=entry.firstchild;
- while assigned(currentinfo) do
- begin
- if currentinfo.NodeName='author' then
- begin
- if currentinfo.haschildnodes and
- (currentinfo.firstchild is TDOMText) then
- currentauthor:=(currentinfo.firstchild as TDOMText).Data
- else
- error('Malformed author node');
- end
- else if currentinfo.NodeName='msg' then
- begin
- if currentinfo.haschildnodes then
- begin
- if (currentinfo.firstchild is TDOMText) then
- currentmsg:=(currentinfo.firstchild as TDOMText).Data
- else
- error('Malformed msg node');
- end
- else
- currentmsg:='<empty log message>';
- end
- else if currentinfo.NodeName='date' then
- begin
- if currentinfo.haschildnodes and
- (currentinfo.firstchild is TDOMText) then
- currentdate:=(currentinfo.firstchild as TDOMText).Data
- else
- error('Malformed date node');
- end
- else if currentinfo.NodeName='paths' then
- begin
- currentpath:=currentinfo.firstchild;
- paths.clear;
- while assigned(currentpath) do
- begin
- if currentpath.NodeName<>'path' then
- error('Path node expected');
- if currentpath.haschildnodes and
- (currentpath.firstchild is TDOMText) then
- paths.add((currentpath.firstchild as TDOMText).Data)
- else
- error('Malformed date node');
- currentpath:=currentpath.NextSibling;
- end;
- end
- else
- error('Unknown logentry child '+currentinfo.NodeName+' found');
- currentinfo:=currentinfo.nextsibling;
- end;
- currentdate:=copy(currentdate,1,16);
- { replaced T }
- currentdate[11]:=' ';
- write(currentdate,' ',currentauthor);
- if currentrevision<>'' then
- writeln(' r',currentrevision)
- else
- writeln;
- writeln;
- { search for common prefix }
- maxequal:=65535;
- for i:=1 to paths.Count-1 do
- begin
- j:=1;
- while (paths[0][j]=paths[i][j]) and (j<=maxequal) do
- inc(j);
- dec(j);
- if j<maxequal then
- maxequal:=j;
- end;
- { generate prefix }
- pathtemp:=' * '+copy(paths[0],1,maxequal)+': ';
- for i:=0 to paths.Count-1 do
- begin
- hs:=copy(paths[i],maxequal+1,65535);
- if (length(pathtemp)+length(', '+hs)>80) and
- (pathtemp<>' ') then
- begin
- writeln(pathtemp+',');
- pathtemp:=' ';
- end;
- { non empty path but not first? }
- if (pathtemp<>' ') and (pathtemp[length(pathtemp)-1]<>':') then
- pathtemp:=pathtemp+', ';
- pathtemp:=pathtemp+hs;
- end;
- if pathtemp<>' ' then
- writeln(pathtemp);
- { truncate trailing new line }
- while currentmsg[length(currentmsg)] in [#13,#10] do
- delete(currentmsg,length(currentmsg),1);
- writeln;
- writeln(' ',currentmsg);
- writeln;
- end
- else
- error('Empty log entry found');
- entry:=entry.nextsibling;
- end;
- end
- else
- error('log element not found/wrong xml format');
- end.
|