msgdif.pp 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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;
  15. TText = String;
  16. PMsg = ^TMsg;
  17. TMsg = Record
  18. Line : Longint;
  19. enum : TEnum;
  20. text : TText;
  21. Next,Prev : PMsg;
  22. FileNext,
  23. Equivalent : PMsg;
  24. end;
  25. Var
  26. OrgFileName,DiffFileName : String;
  27. OrgRoot,DiffRoot : PMsg;
  28. OrgFirst,DiffFirst : PMsg;
  29. Last : PMsg;
  30. Function NewMsg (Var RM : PMsg; L : Longint; Const E : TEnum;Const T : TText) : PMsg;
  31. Var
  32. P,R : PMsg;
  33. begin
  34. New(P);
  35. with P^ do
  36. begin
  37. Line:=L;
  38. Text:=T;
  39. enum:=E;
  40. next:=Nil;
  41. prev:=Nil;
  42. filenext:=nil;
  43. equivalent:=nil;
  44. if assigned(last) then
  45. last^.FileNext:=P;
  46. last:=P;
  47. end;
  48. R:=RM;
  49. While (R<>Nil) and (R^.enum<P^.Enum) do
  50. begin
  51. P^.Prev:=R;
  52. R:=R^.next;
  53. end;
  54. P^.Next:=R;
  55. If R<>Nil then
  56. R^.Prev:=P;
  57. If P^.Prev<>Nil then
  58. P^.Prev^.Next:=P
  59. else
  60. RM:=P;
  61. NewMsg:=P;
  62. end;
  63. Procedure Usage;
  64. begin
  65. Writeln ('Usage : msgdif orgfile diffile');
  66. halt(1)
  67. end;
  68. Procedure ProcessOptions;
  69. begin
  70. If ParamCount<>2 then
  71. Usage;
  72. OrgfileName:=Paramstr(1);
  73. DiffFileName:=Paramstr(2);
  74. end;
  75. Procedure ProcessFile (FileName : String; Var Root,First : PMsg);
  76. Var F : Text;
  77. S : String;
  78. J,LineNo,Count : Longint;
  79. begin
  80. Assign(F,FileName);
  81. Reset(F);
  82. Write ('Processing: ',Filename,'...');
  83. LineNo:=0;
  84. Count:=0;
  85. Root:=Nil;
  86. First:=nil;
  87. Last:=nil;
  88. While not eof(f) do
  89. begin
  90. Readln(F,S);
  91. Inc(LineNo);
  92. If (length(S)>0) and Not (S[1] in ['%','#']) Then
  93. begin
  94. J:=Pos('=',S);
  95. If j<1 then
  96. writeln (Filename,'(',LineNo,') : Invalid entry')
  97. else
  98. begin
  99. NewMsg(Root,LineNo,Copy(S,1,J-1),Copy(S,j+1,255));
  100. if First=nil then
  101. First:=Root;
  102. Inc(Count);
  103. end;
  104. end;
  105. end;
  106. Writeln (' Done. Read ',LineNo,' lines, got ',Count,' constants.');
  107. Close(f);
  108. end;
  109. Procedure ShowDiff (POrg,PDiff : PMsg);
  110. Procedure NotFound (Org : Boolean; P : PMsg);
  111. begin
  112. With P^ do
  113. If Org Then
  114. Writeln ('Not found in ',DiffFileName,' : ',Enum,' ',OrgFileName,'(',Line,')')
  115. else
  116. Writeln ('Extra in ',DiffFileName,'(',line,') : ',enum)
  117. end;
  118. Var P : PMsg;
  119. count : longint;
  120. begin
  121. count:=0;
  122. While (Porg<>Nil) and (PDiff<>Nil) do
  123. begin
  124. // Writeln (POrg^.enum,'<=>',PDiff^.Enum);
  125. If Porg^.Enum<PDiff^.Enum then
  126. begin
  127. NotFound (True,Porg);
  128. POrg:=POrg^.Next
  129. end
  130. else If POrg^.enum=PDiff^.Enum then
  131. begin
  132. inc(count);
  133. POrg^.Equivalent:=PDiff;
  134. PDiff^.Equivalent:=POrg;
  135. POrg:=POrg^.Next;
  136. PDiff:=PDiff^.Next;
  137. end
  138. else
  139. begin
  140. NotFound (False,PDiff);
  141. PDiff:=PDiff^.Next
  142. end;
  143. end;
  144. While POrg<>Nil do
  145. begin
  146. NotFound(True,Porg);
  147. POrg:=pOrg^.Next;
  148. end;
  149. While PDiff<>Nil do
  150. begin
  151. NotFound(False,PDiff);
  152. PDiff:=PDiff^.Next;
  153. end;
  154. Writeln(count,' messages found in both files');
  155. end;
  156. procedure WriteReorderedFile(FileName : string;orgnext,diffnext : PMsg);
  157. var t,t2,t3 : text;
  158. i,i2,i3 : longint;
  159. s,s3 : string;
  160. CurrentMsg : PMsg;
  161. nextdiffkept : pmsg;
  162. begin
  163. Assign(t,FileName);
  164. Rewrite(t);
  165. Writeln(t,'%%% Reordering of ',DiffFileName,' respective to ',OrgFileName);
  166. Writeln(t,'%%% Contains all comments from ',DiffFileName);
  167. Assign(t2,DiffFileName);
  168. Reset(t2);
  169. Assign(t3,OrgFileName);
  170. Reset(t3);
  171. i:=2;i2:=0;i3:=0;
  172. s:='';s3:='';
  173. nextdiffkept:=diffnext;
  174. while assigned(nextdiffkept) and (nextdiffkept^.equivalent=nil) do
  175. nextdiffkept:=nextdiffkept^.filenext;
  176. While not eof(t2) do
  177. begin
  178. while assigned(orgnext) and assigned(nextdiffkept) and
  179. (orgnext^.enum<>nextdiffkept^.enum) and not(eof(t3)) do
  180. begin
  181. { Insert a new error msg with the english comments }
  182. while i3<orgnext^.line do
  183. begin
  184. readln(t3,s3);
  185. inc(i3);
  186. end;
  187. writeln(t,s3);
  188. inc(i);
  189. readln(t3,s3);
  190. inc(i3);
  191. while (s3<>'') and (s3[1] in ['#','%']) do
  192. begin
  193. writeln(t,s3);
  194. inc(i);
  195. readln(t3,s3);
  196. inc(i3);
  197. end;
  198. Writeln('New error ',orgnext^.enum,' added');
  199. orgnext:=orgnext^.filenext;
  200. end;
  201. if s='' then
  202. begin
  203. readln(t2,s);
  204. inc(i2);
  205. end;
  206. if assigned(orgnext) and
  207. assigned(diffnext) and (i2=diffnext^.line) then
  208. begin
  209. if assigned(diffnext^.Equivalent) then
  210. begin
  211. if diffnext^.equivalent<>orgnext then
  212. Writeln('Problem inside WriteReorderedFile');
  213. Writeln(t,s);
  214. s:='';
  215. inc(i);
  216. readln(t2,s);
  217. inc(i2);
  218. while (s<>'') and (s[1] in ['#','%']) do
  219. begin
  220. writeln(t,s);
  221. inc(i);
  222. readln(t2,s);
  223. inc(i2);
  224. end;
  225. if diffnext^.Equivalent^.Text=diffnext^.Text then
  226. Writeln(diffnext^.Enum,': ',DiffFileName,'(',i2,') not translated');
  227. Diffnext:=Diffnext^.FileNext;
  228. nextdiffkept:=diffnext;
  229. while assigned(nextdiffkept) and (nextdiffkept^.equivalent=nil) do
  230. nextdiffkept:=nextdiffkept^.filenext;
  231. Orgnext:=orgnext^.filenext;
  232. end
  233. else
  234. begin
  235. { Skip removed enum in errore.msg}
  236. { maybe a renaming of an enum !}
  237. Writeln(diffnext^.enum,' commented out');
  238. Writeln(t,'%%% ',s);
  239. inc(i);
  240. readln(t2,s);
  241. inc(i2);
  242. Diffnext:=Diffnext^.FileNext;
  243. nextdiffkept:=diffnext;
  244. while assigned(nextdiffkept) and (nextdiffkept^.equivalent=nil) do
  245. nextdiffkept:=nextdiffkept^.filenext;
  246. if assigned(diffnext) then
  247. while (i2<diffnext^.line) do
  248. begin
  249. writeln(t,'%%% ',s);
  250. inc(i);
  251. readln(t2,s);
  252. inc(i2);
  253. end;
  254. end;
  255. end
  256. else
  257. begin
  258. writeln(t,s);
  259. inc(i);
  260. s:='';
  261. end;
  262. end;
  263. Close(t);
  264. Close(t2);
  265. Close(t3);
  266. end;
  267. begin
  268. ProcessOptions;
  269. ProcessFile(OrgFileName,orgroot,orgfirst);
  270. ProcessFile(DiffFileName,diffRoot,difffirst);
  271. ShowDiff (OrgRoot,DiffRoot);
  272. WriteReorderedFile('new.msg',orgfirst,difffirst);
  273. end.
  274. {
  275. $Log$
  276. Revision 1.7 1999-06-22 16:32:43 pierre
  277. * wrong change 1.6 removed
  278. Revision 1.5 1999/06/11 13:06:45 peter
  279. * fixed crash with errorn.msg
  280. Revision 1.4 1999/06/09 12:17:34 pierre
  281. * bugfix from fixes-0_99_12 merged
  282. Revision 1.2.2.2 1999/06/09 12:12:19 pierre
  283. * small bug fixed
  284. Revision 1.3 1999/06/09 11:57:29 pierre
  285. * fix branch changes merged
  286. Revision 1.2.2.1 1999/06/09 11:48:18 pierre
  287. * msgdif enhanced: see readme
  288. Revision 1.2 1999/05/17 15:13:43 michael
  289. + Fixed a bug that caused messages inserted at root not to appear...
  290. Revision 1.1 1999/05/12 16:17:09 peter
  291. * init
  292. }