checkcvs.pp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. Program checkcvs;
  2. { $Id$
  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 what happened today, if you specify a
  7. nummeric parameter smaller than 365, CheckCvs searches for entries
  8. 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. Type
  19. Array12type = ARRAY [1..12] Of longint;
  20. Const
  21. MonthCumm : Array12type = (0,31,59,90,120,151,181,212,243,273,304,334);
  22. Function LeapYr( Year : longint) : boolean;
  23. Begin
  24. LeapYr := (Year Mod 4 = 0) And ((Year Mod 100 <> 0) Or (Year Mod 400 = 0));
  25. End;
  26. Function DayNr( Day,Month,Year: longint) : longint;
  27. {Modified version. A daynr function that returns daynr since 1-1-1980.
  28. Leapyears ok till 2100.}
  29. Var
  30. i : longint;
  31. Begin
  32. i := MonthCumm[Month]+Day;
  33. If (Month > 2) And LeapYr( Year ) Then
  34. INC( i );
  35. INC(I,(Year-1980)*365 + (Year-1976) SHR 2);
  36. { - (Year -2000) DIV 100; makes it ok till 2400}
  37. DayNr := i;
  38. End ;
  39. {TrimLeft isn't overloaded for pascal string yet.}
  40. Procedure LTrim(Var P : String;Ch:Char);
  41. Var I,J : longint;
  42. Begin
  43. I := Length(P); { Keeping length in local data eases optimalisations}
  44. If (I>0) Then
  45. Begin
  46. J := 1;
  47. while (P[J]=Ch) AND (J<=I) Do INC(J);
  48. If J>1 Then
  49. Delete(P,1,J-1);
  50. End;
  51. End;
  52. Procedure CheckAfile(Name:String;Firstday:longint);
  53. {Outputs filename and relevant CVSLOG entries for all files that have log
  54. entries newer than FirstDay.}
  55. Var F : Text;
  56. Lines : longint;
  57. Found : boolean;
  58. S,S2,S3 : String;
  59. ValidLogEntry : boolean;
  60. Day,Month,Year : longint;
  61. PosDate : longint;
  62. FirstLogEntry : boolean;
  63. Function ReadTwo(Position:longint): longint;
  64. INLINE;
  65. Begin
  66. ReadTwo := (ord(S[Position])-48)*10+(ord(S[Position+1])-48);
  67. End;
  68. Begin
  69. Assign(F,Name);
  70. Reset(F);
  71. Lines := 5;
  72. Found := FALSE;
  73. Repeat {Valid files have $Id: somewhere
  74. in the first lines}
  75. ReadLn(F,S);
  76. LTrim(S,' ');
  77. If Copy(S,1,4)='$Id:' Then
  78. Found := TRUE;
  79. dec(Lines);
  80. Until ((Lines=0) Or Found) Or EOF(F);
  81. If Not Found Then
  82. EXIT;
  83. Found := FALSE;
  84. Repeat {Valid files have $Id: somewhere
  85. in the first lines}
  86. ReadLn(F,S);
  87. LTrim(S,' ');
  88. If Copy(S,1,5)='$Log:' Then
  89. Found := TRUE;
  90. Until (Found) Or EOF(F);
  91. If Not Found Then
  92. EXIT;
  93. ValidLogEntry := FALSE;
  94. FirstLogEntry := TRUE;
  95. Repeat
  96. ReadLn(F,S);
  97. S3 := S;
  98. LTrim(S3,' ');
  99. If Copy(S3,1,8)='Revision' Then
  100. Begin
  101. ValidLogEntry := FALSE;
  102. S2 := S;
  103. Delete(S3,1,9);
  104. S := S3;
  105. Lines := Pos(' ',S);
  106. If Lines<>0 Then
  107. Begin
  108. Delete(S,1,Lines);
  109. LTrim(S,' ');
  110. Year := ReadTwo(1)*100+ReadTwo(3);
  111. Month := ReadTwo(6);
  112. Day := ReadTwo(9);
  113. PosDate := DayNr(Day,Month,Year);
  114. If (PosDate>=FirstDay) Then
  115. Begin
  116. ValidLogEntry := TRUE;
  117. If FirstLogEntry Then
  118. Begin
  119. FirstLogEntry := FALSE;
  120. Writeln('File: ',Name);
  121. End;
  122. Writeln(S2);
  123. End;
  124. End;
  125. End
  126. Else
  127. If ValidLogEntry And (S[1]<>'}') Then
  128. Writeln(S);
  129. Until EOF(F) Or (S[1]='}');
  130. Close(F);
  131. End;
  132. Var year, month, mday, wday: word;
  133. TheDay,Days : longint;
  134. D : SearchRec;
  135. Procedure SearchExtension(Pattern:String);
  136. Begin
  137. FindFirst(Pattern,Anyfile-Directory,D);
  138. while DosError = 0 Do
  139. Begin
  140. CheckAFile(D.Name,TheDay);
  141. FindNext(D);
  142. End;
  143. FindClose(D);
  144. End;
  145. Begin
  146. GetDate(year, month, mday, wday); {GetDate}
  147. TheDay := DayNr(MDay,Month,Year); {Convert to something linear}
  148. If ParamCount<>0 Then {If parameter is nummeric, subtract}
  149. Begin
  150. Val(ParamStr(1),Days,Year);
  151. If (Year=0) And (Days<365) Then { n days from current date}
  152. dec(TheDay,Days);
  153. End;
  154. SearchExtension('*.pp'); {Scan files in simple FindFirst loop}
  155. SearchExtension('*.pas');
  156. SearchExtension('*.inc');
  157. End.
  158. {
  159. $Log$
  160. Revision 1.2 2000-01-16 13:24:48 marco
  161. * some ugly comments fixed.
  162. Revision 1.1 2000/01/14 22:05:47 marco
  163. * Some fixes, rename .pas to .pp, ptop'ed
  164. Revision 1.1 2000/01/14 12:02:04 marco
  165. * Initial version
  166. }