summaryrefslogtreecommitdiff
path: root/compiler/utils/fixlog.pp
blob: 750b6288789caf04db78398c654fcbd334b1b9ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
{
    Copyright (c) 1998-2002 by Peter Vreman

    Remove all revision logs from source files after X revisions or
    older than date X

    See the file COPYING.FPC, included in this distribution,
    for details about the copyright.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 **********************************************************************}
program fixlog;

{$mode objfpc}
{$H+}

uses
  sysutils;

const
  bufsize = 32*1024;

var
  maxrevs,myear,mmonth,mday : integer;

procedure Date2Int(const date:string;var year,month,day:integer);
begin
  year:=StrToInt(Copy(date,1,4));
  month:=StrToInt(Copy(date,6,2));
  day:=StrToInt(Copy(date,9,2));
  if (year=0) or (month=0) or (day=0) then
   begin
     writeln('wrong date "',date,'", use yyyy/mm/dd');
     halt(2);
   end;
end;


procedure dofile(const fn:string);
var
  t,f : text;
  s : string;
  skip, truncated : boolean;
  year,month,day,
  found,revs,i : integer;
  fbuf,tbuf : pointer;
begin
  getmem(fbuf,bufsize);
  getmem(tbuf,bufsize);
  write('processing ',fn,': ');
  assign(t,fn);
  assign(f,'fixlog.tmp');
  {$push}{$I-}
   reset(t);
  {$pop}
  if ioresult<>0 then
   begin
     writeln('error!');
     exit;
   end;
  rewrite(f);
  settextbuf(t,tbuf^,bufsize);
  settextbuf(f,fbuf^,bufsize);
  found:=0;
  revs:=0;
  skip:=false;
  truncated:=false;
  while not eof(t) do
   begin
     readln(t,s);
     case found of
      0 :
        begin
          if pos('$Log: ',s)>0 then
           found:=1;
          skip:=false;
          writeln(f,s);
        end;
      1 :
        begin
          i:=pos('Revision',s);
          if i>0 then
           begin
             inc(revs);
             if revs>maxrevs then
              begin
                skip:=true;
                truncated:=true;
                found:=2;
              end
             else
              begin
                inc(i,10);
                while (i<length(s)) and (s[i]<>' ') do
                 inc(i);
                while (i<length(s)) and (s[i]=' ') do
                 inc(i);
                if (i<length(s)) and (s[i] in ['0'..'9']) then
                 begin
                   Date2Int(Copy(s,i,10),year,month,day);
                   if (year<Myear) or
                      ((year=MYear) and (month<Mmonth)) or
                      ((year=MYear) and (month=Mmonth) and (day<Mday)) then
                    begin
                      skip:=true;
                      truncated:=true;
                      found:=2;
//                    write(year,'/',month,'/',day,' date');
                    end;
                 end;
              end;
           end
          else
           if pos('}',s)>0 then
            begin
              skip:=false;
              found:=0;
            end;
          if not skip then
           writeln(f,s);
        end;
      2 :
        begin
          if pos('}',s)>0 then
           begin
             skip:=false;
             found:=0;
           end;
          if not skip then
           writeln(f,s);
        end;
     end;
   end;
  close(t);
  close(f);
  if revs=0 then
   writeln(' no log found')
  else
   if truncated then
     writeln(revs-1,' revisions')
  else
     writeln(revs,' revisions');
  erase(t);
  rename(f,fn);
  freemem(tbuf);
  freemem(fbuf);
end;

var
  dir : tsearchrec;
  i   : integer;
  path : string;
begin
  writeln('fixlog v1.01 (C) 1999-2002 Peter Vreman');
  if paramcount<3 then
   begin
     writeln('usage: fixlog <revisions> <yyyy-mm-dd> <files> [files]');
     halt(1);
   end;
  MaxRevs:=StrToInt(ParamStr(1));
  Date2Int(ParamStr(2),MYear,MMonth,MDay);
  for i:=3 to paramcount do
   begin
     path:=ExtractFilePath(paramstr(i));
     if findfirst(paramstr(i),faAnyFile,dir)=0 then
      repeat
        dofile(path+dir.name);
      until findnext(dir)<>0;
     findclose(dir);
   end;
end.