msgdif.pp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. R:=RM;
  37. While (R<>Nil) and (R^.enum<P^.Enum) do
  38. begin
  39. P^.Prev:=R;
  40. R:=R^.next;
  41. end;
  42. P^.Next:=R;
  43. If R<>Nil then
  44. R^.Prev:=P;
  45. If P^.Prev<>Nil then
  46. P^.Prev^.Next:=P
  47. else
  48. RM:=P;
  49. NewMsg:=P;
  50. end;
  51. Procedure Usage;
  52. begin
  53. Writeln ('Usage : msgdif orgfile diffile');
  54. halt(1)
  55. end;
  56. Procedure ProcessOptions;
  57. begin
  58. If ParamCount<>2 then
  59. Usage;
  60. OrgfileName:=Paramstr(1);
  61. DiffFileName:=Paramstr(2);
  62. end;
  63. Procedure ProcessFile (FileName : String; Var Root : PMsg);
  64. Var F : Text;
  65. S : String;
  66. J,LineNo,Count : Longint;
  67. begin
  68. Assign(F,FileName);
  69. Reset(F);
  70. Write ('Processing: ',Filename,'...');
  71. LineNo:=0;
  72. Count:=0;
  73. Root:=Nil;
  74. While not eof(f) do
  75. begin
  76. Readln(F,S);
  77. Inc(LineNo);
  78. If (length(S)>0) and Not (S[1] in ['%','#']) Then
  79. begin
  80. J:=Pos('=',S);
  81. If j<1 then
  82. writeln (Filename,'(',LineNo,') : Invalid entry')
  83. else
  84. begin
  85. NewMsg(Root,LineNo,Copy(S,1,J-1));
  86. Inc(Count);
  87. end;
  88. end;
  89. end;
  90. Writeln (' Done. Read ',LineNo,' lines, got ',Count,' constants.');
  91. Close(f);
  92. end;
  93. Procedure ShowDiff (POrg,PDiff : PMsg);
  94. Procedure NotFound (Org : Boolean; P : PMsg);
  95. begin
  96. With P^ do
  97. If Org Then
  98. Writeln ('Not found in new : ',Enum,' (line ',Line,' in ',OrgFilename,')')
  99. else
  100. Writeln ('Extra in new : ',enum,' (Line',line,' in ',DiffFileName,')')
  101. end;
  102. Var P : PMsg;
  103. begin
  104. While (Porg<>Nil) and (PDiff<>Nil) do
  105. begin
  106. // Writeln (POrg^.enum,'<=>',PDiff^.Enum);
  107. If Porg^.Enum<PDiff^.Enum then
  108. begin
  109. NotFound (True,Porg);
  110. POrg:=POrg^.Next
  111. end
  112. else If POrg^.enum=PDiff^.Enum then
  113. begin
  114. POrg:=POrg^.Next;
  115. PDiff:=PDiff^.Next
  116. end
  117. else
  118. begin
  119. NotFound (False,PDiff);
  120. PDiff:=PDiff^.Next
  121. end;
  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(False,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.2 1999-05-17 15:13:43 michael
  143. + Fixed a bug that caused messages inserted at root not to appear...
  144. Revision 1.1 1999/05/12 16:17:09 peter
  145. * init
  146. }