checkcvs.pas 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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 what happened today, if you specify a
  8. nummeric parameter smaller than 365, CheckCvs searches for entries
  9. 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. 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. PROCEDURE CheckAfile(Name:String;Firstday:LONGINT);
  54. {Outputs filename and relevant CVSLOG entries for all files that have log
  55. entries newer than FirstDay.}
  56. VAR F : Text;
  57. Lines : LONGINT;
  58. Found : BOOLEAN;
  59. S,S2 : String;
  60. ValidLogEntry : BOOLEAN;
  61. Day,Month,Year : LONGINT;
  62. PosDate : LONGINT;
  63. FirstLogEntry : BOOLEAN;
  64. FUNCTION ReadTwo(Position:LONGINT):LONGINT; 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; Found:=FALSE;
  72. REPEAT {Valid files have $Id: somewhere
  73. in the first lines}
  74. ReadLn(F,S);
  75. LTrim(S,' ');
  76. IF Copy(S,1,4)='$Id:' THEN
  77. Found:=TRUE;
  78. DEC(Lines);
  79. UNTIL ((Lines=0) OR Found) OR EOF(F);
  80. IF NOT Found THEN
  81. EXIT;
  82. REPEAT {Valid files have $Id: somewhere
  83. in the first lines}
  84. ReadLn(F,S);
  85. LTrim(S,' ');
  86. IF Copy(S,1,4)='$Log:' THEN
  87. Found:=TRUE;
  88. UNTIL (Found) OR EOF(F);
  89. IF NOT Found THEN
  90. EXIT;
  91. ValidLogEntry:=FALSE;
  92. FirstLogEntry:=TRUE;
  93. REPEAT
  94. ReadLn(F,S);
  95. IF Copy(S,3,8)='Revision' THEN
  96. BEGIN
  97. ValidLogEntry:=FALSE;
  98. S2:=S;
  99. Delete(S,1,11);
  100. Lines:=Pos(' ',S);
  101. IF Lines<>0 THEN
  102. BEGIN
  103. Delete(S,1,Lines);
  104. LTrim(S,' ');
  105. Year:=ReadTwo(1)*100+ReadTwo(3);
  106. Month:=ReadTwo(6);
  107. Day:=ReadTwo(9);
  108. PosDate:=DayNr(Day,Month,Year);
  109. IF (PosDate>=FirstDay) THEN
  110. BEGIN
  111. ValidLogEntry:=TRUE;
  112. IF FirstLogEntry THEN
  113. BEGIN
  114. FirstLogEntry:=FALSE;
  115. Writeln('File: ',Name);
  116. END;
  117. Writeln(S2);
  118. END;
  119. END;
  120. END
  121. ELSE
  122. IF ValidLogEntry THEN
  123. Writeln(S);
  124. UNTIL EOF(F) OR (S[1]='}');
  125. Close(F);
  126. END;
  127. VAR year, month, mday, wday: word;
  128. TheDay,Days : LONGINT;
  129. S : String;
  130. D : SearchRec;
  131. PROCEDURE SearchExtension(Pattern:String);
  132. BEGIN
  133. FindFirst(Pattern,Anyfile-Directory,D);
  134. WHILE DosError=0 DO
  135. BEGIN
  136. CheckAFile(D.Name,TheDay);
  137. FindNext(D);
  138. END;
  139. FindClose(D);
  140. END;
  141. BEGIN
  142. GetDate(year, month, mday, wday); {GetDate}
  143. TheDay:=DayNr(MDay,Month,Year); {Convert to something linear}
  144. IF ParamCount<>0 THEN {If parameter is nummeric, subtract}
  145. BEGIN
  146. Val(ParamStr(1),Days,Year);
  147. IF (Year=0) AND (Days<365) THEN { n days from current date}
  148. Dec(TheDay,Days);
  149. END;
  150. SearchExtension('*.pp'); {Scan files in simple FindFirst loop}
  151. SearchExtension('*.pas');
  152. SearchExtension('*.inc');
  153. END.
  154. {
  155. $Log$
  156. Revision 1.1 2000-01-14 12:02:04 marco
  157. * Initial version
  158. }