checkcvs.pp 6.1 KB

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