checkcvs.pp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. Program checkcvs;
  2. {
  3. $Id$
  4. This file is part of the Free Pascal run time library.
  5. Copyright (c) 1999-2000 by the Free Pascal development team.
  6. A simple filter program which displays what happened on CVS today.
  7. Without parameters it shows the newest CVS log entry.
  8. If you specify a nummeric parameter smaller than 365,
  9. CheckCvs searches for ALL entries n days back.
  10. Great to quickly check what changed after an update etc.
  11. Todo : add getopts and some switches to increase configurability.
  12. See the file COPYING.FPC, included in this distribution,
  13. for details about the copyright.
  14. This program is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  17. **********************************************************************}
  18. Uses Dos;
  19. Const bufferlimit=10000;
  20. Type
  21. Array12type = ARRAY [1..12] Of longint;
  22. Const
  23. MonthCumm : Array12type = (0,31,59,90,120,151,181,212,243,273,304,334);
  24. Function LeapYr( Year : longint) : boolean;
  25. Begin
  26. LeapYr := (Year Mod 4 = 0) And ((Year Mod 100 <> 0) Or (Year Mod 400 = 0));
  27. End;
  28. Function DayNr( Day,Month,Year: longint) : longint;
  29. {Modified version. A daynr function that returns daynr since 1-1-1980.
  30. Leapyears ok till 2100.}
  31. Var
  32. i : longint;
  33. Begin
  34. i := MonthCumm[Month]+Day;
  35. If (Month > 2) And LeapYr( Year ) Then
  36. INC( i );
  37. INC(I,(Year-1980)*365 + (Year-1976) SHR 2);
  38. { - (Year -2000) DIV 100; makes it ok till 2400}
  39. DayNr := i;
  40. End ;
  41. {TrimLeft isn't overloaded for pascal string yet.}
  42. Procedure LTrim(Var P : String;Ch:Char);
  43. Var I,J : longint;
  44. Begin
  45. I := Length(P); { Keeping length in local data eases optimalisations}
  46. If (I>0) Then
  47. Begin
  48. J := 1;
  49. while (P[J]=Ch) AND (J<=I) Do INC(J);
  50. If J>1 Then
  51. Delete(P,1,J-1);
  52. End;
  53. End;
  54. Var NewestBuffer : PChar; {Buffer containing the "newest" data}
  55. BufferIndex : Longint; {Bytes in buffer}
  56. NewestDate : Longint; {Newest date (the one in NewestBuffer)}
  57. CheckMode : boolean; {Do we search newest, or all msgs since
  58. <parameter> days ago}
  59. Procedure CheckAfile(Name:String;Firstday:longint);
  60. {Outputs filename and relevant CVSLOG entries for all files that have log
  61. entries newer than FirstDay.}
  62. Var F : Text;
  63. Lines : longint;
  64. Found : boolean;
  65. S,S2,S3 : String;
  66. ValidLogEntry : boolean;
  67. Day,Month,Year : longint;
  68. PosDate : longint;
  69. FirstLogEntry : boolean;
  70. Procedure AppendLine (S : String);
  71. Begin
  72. If CheckMode Then
  73. Begin
  74. If (Length(S)<>0) AND ((Length(S)+BufferIndex+2)<BufferLimit) Then
  75. Begin
  76. Move(S[1],NewestBuffer[BufferIndex],Length(S));
  77. Inc(BufferIndex,Length(S));
  78. {$Ifndef Unix}
  79. NewestBuffer[BufferIndex]:=#13;
  80. Inc(BufferIndex);
  81. {$EndIf}
  82. NewestBuffer[BufferIndex]:=#10;
  83. Inc(BufferIndex);
  84. End;
  85. End
  86. Else
  87. Begin
  88. Writeln(S);
  89. End;
  90. End;
  91. Function ReadTwo(Position:longint): longint; INLINE;
  92. Begin
  93. ReadTwo := (ord(S[Position])-48)*10+(ord(S[Position+1])-48);
  94. End;
  95. Begin
  96. Assign(F,Name);
  97. Reset(F);
  98. Lines := 5;
  99. Found := FALSE;
  100. Repeat {Valid files have $Id: somewhere
  101. in the first lines}
  102. ReadLn(F,S);
  103. LTrim(S,' ');
  104. If Copy(S,1,4)='$Id:' Then
  105. Found := TRUE;
  106. dec(Lines);
  107. Until ((Lines=0) Or Found) Or EOF(F);
  108. If Not Found Then
  109. BEGIN
  110. Close(F);
  111. EXIT;
  112. END;
  113. Found := FALSE;
  114. Repeat {Valid files have $Id: somewhere
  115. in the first lines}
  116. ReadLn(F,S);
  117. LTrim(S,' ');
  118. If Copy(S,1,5)='$Log:' Then
  119. Found := TRUE;
  120. Until (Found) Or EOF(F);
  121. If Not Found Then
  122. EXIT;
  123. ValidLogEntry := FALSE;
  124. FirstLogEntry := TRUE;
  125. Repeat
  126. ReadLn(F,S);
  127. S3 := S;
  128. LTrim(S3,' ');
  129. If Copy(S3,1,8)='Revision' Then
  130. Begin
  131. ValidLogEntry := FALSE;
  132. S2 := S;
  133. Delete(S3,1,9);
  134. S := S3;
  135. Lines := Pos(' ',S);
  136. If Lines<>0 Then
  137. Begin
  138. Delete(S,1,Lines);
  139. LTrim(S,' ');
  140. Year := ReadTwo(1)*100+ReadTwo(3);
  141. Month := ReadTwo(6);
  142. Day := ReadTwo(9);
  143. PosDate := DayNr(Day,Month,Year);
  144. If CheckMode Then
  145. Begin
  146. If PosDate>=NewestDate Then
  147. Begin
  148. NewestDate:=PosDate;
  149. BufferIndex:=0;
  150. ValidLogEntry := TRUE;
  151. AppendLine('File: '+Name);
  152. AppendLine(S2);
  153. End;
  154. End
  155. Else
  156. If (PosDate>=FirstDay) Then
  157. Begin
  158. ValidLogEntry := TRUE;
  159. If FirstLogEntry Then
  160. Begin
  161. FirstLogEntry := FALSE;
  162. AppendLine('File: '+Name);
  163. End;
  164. AppendLine(S2);
  165. End;
  166. End;
  167. End
  168. Else
  169. If ValidLogEntry And (S[1]<>'}') Then
  170. AppendLine(S);
  171. Until EOF(F) Or (S[1]='}');
  172. Close(F);
  173. End;
  174. Var year, month, mday, wday: word;
  175. TheDay,Days : longint;
  176. D : SearchRec;
  177. Procedure SearchExtension(Pattern:String);
  178. Begin
  179. FindFirst(Pattern,Anyfile-Directory,D);
  180. while DosError = 0 Do
  181. Begin
  182. CheckAFile(D.Name,TheDay);
  183. FindNext(D);
  184. End;
  185. FindClose(D);
  186. End;
  187. Begin
  188. GetMem(NewestBuffer,bufferlimit);
  189. BufferIndex:=0;
  190. NewestDate:=0;
  191. GetDate(year, month, mday, wday); {GetDate}
  192. TheDay := DayNr(MDay,Month,Year); {Convert to something linear}
  193. If ParamCount<>0 Then {If parameter is nummeric, subtract}
  194. Begin
  195. CheckMode:=FALSE;
  196. Val(ParamStr(1),Days,Year);
  197. If (Year=0) And (Days<365) Then { n days from current date}
  198. dec(TheDay,Days);
  199. End
  200. Else
  201. CheckMode:=True;
  202. SearchExtension('*.pp'); {Scan files in simple FindFirst loop}
  203. SearchExtension('*.pas');
  204. SearchExtension('*.inc');
  205. If CheckMode AND (BufferIndex<>0) THEN
  206. Begin
  207. For Days:=0 TO BufferIndex-1 Do
  208. Write(NewestBuffer[Days]);
  209. End;
  210. FreeMem(NewestBuffer,bufferlimit);
  211. End.
  212. {
  213. $Log$
  214. Revision 1.3 2002-09-07 15:40:30 peter
  215. * old logs removed and tabs fixed
  216. Revision 1.2 2002/06/02 17:10:35 marco
  217. * Renamefest
  218. }