msgdif.pp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. {
  2. $Id$
  3. This program is part of the Free Pascal run time library.
  4. Copyright (c) 1998 by Peter Vreman
  5. Show the differences between two .msg files
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. Program messagedif;
  13. Type
  14. TEnum = String[40];
  15. PMsg = ^TMsg;
  16. TMsg = Record
  17. Line : Longint;
  18. enum : TEnum;
  19. Next,Prev : PMsg;
  20. end;
  21. Var
  22. OrgFileName,DiffFileName : String;
  23. OrgRoot,DiffRoot : PMsg;
  24. Function NewMsg (Var RM : PMsg; L : Longint; Const E : TEnum) : PMsg;
  25. Var
  26. P,R : PMsg;
  27. begin
  28. New(P);
  29. with P^ do
  30. begin
  31. Line:=L;
  32. enum:=E;
  33. next:=Nil;
  34. prev:=Nil;
  35. end;
  36. If RM=NIl then
  37. RM:=P
  38. else
  39. begin
  40. R:=RM;
  41. While (R<>Nil) and (R^.enum<P^.Enum) do
  42. begin
  43. P^.Prev:=R;
  44. R:=R^.next;
  45. end;
  46. P^.Next:=R;
  47. If R<>Nil then
  48. R^.Prev:=P;
  49. If P^.Prev<>Nil then
  50. P^.Prev^.Next:=P;
  51. end;
  52. NewMsg:=P;
  53. end;
  54. Procedure Usage;
  55. begin
  56. Writeln ('Usage : msgdif orgfile diffile');
  57. halt(1)
  58. end;
  59. Procedure ProcessOptions;
  60. begin
  61. If ParamCount<>2 then
  62. Usage;
  63. OrgfileName:=Paramstr(1);
  64. DiffFileName:=Paramstr(2);
  65. end;
  66. Procedure ProcessFile (FileName : String; Var Root : PMsg);
  67. Var F : Text;
  68. S : String;
  69. J,LineNo,Count : Longint;
  70. begin
  71. Assign(F,FileName);
  72. Reset(F);
  73. Write ('Processing: ',Filename,'...');
  74. LineNo:=0;
  75. Count:=0;
  76. Root:=Nil;
  77. While not eof(f) do
  78. begin
  79. Readln(F,S);
  80. Inc(LineNo);
  81. If (length(S)>0) and Not (S[1] in ['%','#']) Then
  82. begin
  83. J:=Pos('=',S);
  84. If j<1 then
  85. writeln (Filename,'(',LineNo,') : Invalid entry')
  86. else
  87. begin
  88. NewMsg(Root,LineNo,Copy(S,1,J-1));
  89. Inc(Count);
  90. end;
  91. end;
  92. end;
  93. Writeln (' Done. Read ',LineNo,' lines, got ',Count,' constants.');
  94. Close(f);
  95. end;
  96. Procedure ShowDiff (POrg,PDiff : PMsg);
  97. Procedure NotFound (Org : Boolean; P : PMsg);
  98. begin
  99. With P^ do
  100. If Org Then
  101. Writeln ('Not found in new : ',Enum,' (line ',Line,' in ',OrgFilename,')')
  102. else
  103. Writeln ('Extra in new : ',enum,' (Line',line,' in ',DiffFileName,')')
  104. end;
  105. Var P : PMsg;
  106. begin
  107. While (Porg<>Nil) and (PDiff<>Nil) do
  108. If Porg^.Enum<PDiff^.Enum then
  109. begin
  110. NotFound (True,Porg);
  111. POrg:=POrg^.Next
  112. end
  113. else If POrg^.enum=PDiff^.Enum then
  114. begin
  115. POrg:=POrg^.Next;
  116. PDiff:=PDiff^.Next
  117. end
  118. else
  119. begin
  120. NotFound (False,PDiff);
  121. PDiff:=PDiff^.Next
  122. end;
  123. While POrg<>Nil do
  124. begin
  125. NotFound(True,Porg);
  126. POrg:=pOrg^.Next;
  127. end;
  128. While PDiff<>Nil do
  129. begin
  130. NotFound(True,PDiff);
  131. PDiff:=PDiff^.Next;
  132. end;
  133. end;
  134. begin
  135. ProcessOptions;
  136. ProcessFile(OrgFileName,orgroot);
  137. ProcessFile(DiffFileName,diffRoot);
  138. ShowDiff (OrgRoot,DiffRoot);
  139. end.
  140. {
  141. $Log$
  142. Revision 1.1 1999-05-12 16:17:09 peter
  143. * init
  144. }