getrev.pp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. program getrev;
  2. { The purpose of this program is to
  3. parse the output of svn info several files
  4. and to extract the lastest date and revision
  5. The program expects a single parameter,
  6. being the name of the text file }
  7. procedure Usage;
  8. begin
  9. Writeln(paramstr(0),' requires exactly one parameter');
  10. Writeln('This paramaeter must be the name of the file');
  11. Writeln('Generated by svn info files > filename');
  12. halt(1);
  13. end;
  14. var
  15. filename, fileurl, line, date, lastdate,
  16. revision, oldrevstring, olddate : string;
  17. f : text;
  18. p, io : longint;
  19. rev, lastrev, oldrev : longint;
  20. begin
  21. if paramcount<>1 then
  22. Usage;
  23. filename:=paramstr(1);
  24. {$i-}
  25. assign(f,filename);
  26. reset(f);
  27. io:=ioresult;
  28. if io<>0 then
  29. begin
  30. Writeln('Unable to open ',filename,' for reading, io=',io);
  31. halt(2);
  32. end;
  33. lastrev:=0;
  34. lastdate:='0';
  35. while not eof(f) do
  36. begin
  37. readln(f,line);
  38. p:=pos('URL: ',line);
  39. if p>0 then
  40. begin
  41. fileurl:=copy(line,p+length('URL: '),length(line));
  42. writeln('fileurl=',fileurl);
  43. end;
  44. p:=pos('Last Changed Date: ',line);
  45. if p>0 then
  46. begin
  47. date:=copy(line,p+length('Last Changed Date: '),length(line));
  48. p:=pos(' ',date);
  49. if p>0 then
  50. date:=copy(date,1,p-1);
  51. writeln('date=',date);
  52. if date>lastdate then
  53. lastdate:=date;
  54. end;
  55. p:=pos('Last Changed Rev: ',line);
  56. if p>0 then
  57. begin
  58. revision:=copy(line,p+length('Last Changed Rev: '),length(line));
  59. writeln('rev=',revision);
  60. val(revision,rev);
  61. if rev>lastrev then
  62. lastrev:=rev;
  63. end;
  64. end;
  65. close(f);
  66. assign(f,'revision.inc');
  67. io:=ioresult;
  68. reset(f);
  69. io:=ioresult;
  70. if io<>0 then
  71. begin
  72. Writeln('revision.inc reset failed, io=',io);
  73. end
  74. else
  75. begin
  76. readln(f,oldrevstring);
  77. close(f);
  78. writeln('oldrevstring ',oldrevstring);
  79. if oldrevstring[1]='''' then
  80. oldrevstring:=copy(oldrevstring,2,length(oldrevstring));
  81. p:=length(oldrevstring);
  82. if oldrevstring[p]='''' then
  83. oldrevstring:=copy(oldrevstring,1,p-1);
  84. p:=pos(' rev ',oldrevstring);
  85. if p>0 then
  86. begin
  87. val(copy(oldrevstring,p+5,length(oldrevstring)),oldrev);
  88. olddate:=copy(oldrevstring,1,p-1);
  89. Writeln('Old values ',olddate,' ',oldrev);
  90. if (olddate >= lastdate) and (oldrev >= lastrev) then
  91. begin
  92. Writeln('New values ',lastdate,' ',lastrev);
  93. Writeln('Keeing old values');
  94. lastrev:=oldrev;
  95. lastdate:=olddate;
  96. end;
  97. end;
  98. end;
  99. Writeln('revision.inc set to ''',lastdate,' rev ',lastrev,'''');
  100. assign(f,'revision.inc');
  101. rewrite(f);
  102. io:=ioresult;
  103. if io <> 0 then
  104. begin
  105. Writeln('Error opening revision.inc for writing');
  106. halt(3);
  107. end;
  108. Writeln(f,'''',lastdate,' rev ',lastrev,'''');
  109. close(f);
  110. end.