3 This program is part of the Free Pascal run time library
.
4 Copyright (c
) 1998-2000 by Peter Vreman
6 Show the differences between two
.msg files
8 See the file COPYING
.FPC
, included
in this distribution
,
9 for details about the copyright
.
11 This program is distributed
in the hope that it will be useful
,
12 but WITHOUT ANY WARRANTY
; without even the implied warranty of
13 MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE
.
15 **********************************************************************}
36 OrgFileName
,DiffFileName
: String
;
37 OrgRoot
,DiffRoot
: PMsg
;
38 OrgFirst
,DiffFirst
: PMsg
;
42 NewFileName
= 'new.msg';
43 Is_interactive
: boolean
= false;
45 Procedure
GetTranslation( p
: PMsg
);
51 if (i
>0) and (i
<=5) then
52 Writeln(P^
.Enum
,' type "',copy(p^
.text
,1,i-1
),'" "',copy(p^
.text
,i
+1,255),'"')
54 Writeln(P^
.enum
,' "',p^
.text
,'"');
58 Is_interactive
:=false;
62 if (j
>0) and (j
<=5) then
64 if copy(p^
.text
,1,i
)<>copy(s
,1,j
) then
65 Writeln('Different verbosity !!');
69 p^
.text
:=copy(p^
.text
,1,i
)+s
;
72 Function
NewMsg (Var RM
: PMsg
; L
: Longint
; Const E
: TEnum
;Const T
: TText
;C
: pchar
;NbLn
: longint
) : PMsg
;
90 if assigned(last
) then
95 While (R
<>Nil
) and (UpCase(R^
.enum
)>UpCase(P^
.Enum
)) do
100 if assigned(R
) and (UpCase(R^
.Enum
)=UpCase(P^
.Enum
)) then
101 Writeln('Error ',R^
.Enum
,' duplicate');
112 Procedure
PrintList(const name
: string
;R
: PMsg
);
122 Writeln(f
,UpCase(P^
.Enum
));
131 Writeln ('Usage : msgdif [-i] orgfile diffile');
132 Writeln(' optional -i option allows to enter translated messages interactivly');
133 Writeln('Generates ',NewFileName
,' with updated messages');
137 Procedure ProcessOptions
;
142 if (count
>0) and (UpCase(Paramstr(1))='-I') then
146 Is_interactive
:=true;
151 Is_interactive
:=false;
155 OrgfileName
:=Paramstr(i
+1);
156 DiffFileName
:=Paramstr(i
+2);
157 if (OrgFileName
=NewFileName
) or (DiffFileName
=NewFileName
) then
159 Writeln('The file names must be different from ',NewFileName
);
164 Procedure
ProcessFile (FileName
: String
; Var Root
,First
: PMsg
);
170 J
,LineNo
,Count
,NbLn
: Longint
;
171 chararray
: array
[0..ArrayLength
] of char
;
172 currentindex
: longint
;
177 Write ('Processing: ',Filename
,'...');
190 If (length(S
)>0) and Not (S
[1] in ['%','#']) Then
194 writeln (Filename
,'(',LineNo
,') : Invalid entry')
197 chararray
[currentindex
]:=#0;
198 c
:=strnew(@chararray);
200 NewMsg(Root
,LineNo
,Copy(PrevS
,1,Pos('=',PrevS
)-1),
201 Copy(PrevS
,Pos('=',PrevS
)+1,255),c
,NbLn
);
212 if currentindex
+length(s
)+1>ArrayLength
then
213 Writeln('Comment too long : over ',ArrayLength
,' chars')
216 strpcopy(@chararray[currentindex
],s
+#10);
217 inc(currentindex
,length(s
)+1);
222 chararray
[currentindex
]:=#0;
223 c
:=strnew(@chararray);
225 NewMsg(Root
,LineNo
,Copy(PrevS
,1,Pos('=',PrevS
)-1),
226 Copy(PrevS
,Pos('=',PrevS
)+1,255),c
,NbLn
);
227 Writeln (' Done. Read ',LineNo
,' lines, got ',Count
,' constants.');
231 Procedure
ShowDiff (POrg
,PDiff
: PMsg
);
234 count
,orgcount
,diffcount
: longint
;
236 Procedure
NotFound (Org
: Boolean
; P
: PMsg
);
241 Writeln ('Not found in ',DiffFileName
,' : ',Enum
,' ',OrgFileName
,'(',Line
,')')
243 Writeln ('Extra in ',DiffFileName
,'(',line
,') : ',enum
);
254 While (Porg
<>Nil
) and (PDiff
<>Nil
) do
256 // Writeln (POrg^
.enum
,'<=>',PDiff^
.Enum
);
257 If
UpCase(Porg^
.Enum
)>UpCase(PDiff^
.Enum
) then
259 NotFound (True
,Porg
);
262 else If
UpCase(POrg^
.enum
)=UpCase(PDiff^
.Enum
) then
265 POrg^
.Equivalent
:=PDiff
;
266 PDiff^
.Equivalent
:=POrg
;
272 NotFound (False
,PDiff
);
283 NotFound(False
,PDiff
);
286 Writeln(count
,' messages found in common to both files');
287 Writeln(orgcount
,' messages only in ',OrgFileName
);
288 Writeln(diffcount
,' messages only in ',DiffFileName
);
291 procedure
WriteReorderedFile(FileName
: string
;orgnext
,diffnext
: PMsg
);
301 Writeln(t
,'%%% Reordering of ',DiffFileName
,' respective to ',OrgFileName
);
302 Writeln(t
,'%%% Contains all comments from ',DiffFileName
);
303 Assign(t2
,DiffFileName
);
305 Assign(t3
,OrgFileName
);
309 nextdiffkept
:=diffnext
;
310 while assigned(nextdiffkept
) and (nextdiffkept^
.equivalent
=nil) do
311 nextdiffkept
:=nextdiffkept^
.filenext
;
312 { First write the header of diff
}
315 is_msg
:=(pos('=',s
)>1) and (s
[1]<>'%') and (s
[1]<>'#');
322 { Write all messages
in Org order
}
323 while assigned(orgnext
) do
325 if not assigned(orgnext^
.equivalent
) then
327 { Insert a new error msg with the english comments
}
328 Writeln('New error ',orgnext^
.enum
,' added');
329 If Is_interactive
then
330 GetTranslation(orgnext
);
331 Writeln(t
,orgnext^
.enum
,'=',orgnext^
.text
);
333 Write(t
,orgnext^
.comment
);
339 if orgnext^
.text
=orgnext^
.equivalent^
.text
then
341 Writeln(FileName
,'(',i
,') ',orgnext^
.enum
,' not translated');
342 If Is_interactive
then
343 GetTranslation(orgnext^
.equivalent
);
344 if orgnext^
.text
=orgnext^
.equivalent^
.text
then
348 s2
:=upcase(copy(s2
,1,pos('_',s2
)));
349 s3
:=orgnext^
.equivalent^
.text
;
350 s3
:=upcase(copy(s3
,1,pos('_',s3
)));
351 { that are the conditions
in verbose unit
}
352 if (length(s3
)<5) and (s2
<>s3
) then
354 Writeln('Warning: different options for ',orgnext^
.enum
);
355 Writeln('in ',orgFileName
,' : ',s2
);
356 Writeln('in ',diffFileName
,' : ',s3
);
357 If Is_interactive
then
359 Write('Use ',OrgFileName
,' verbosity ? [y/n] ');
361 if UpCase(s
)<>'N' then
362 orgnext^
.equivalent^
.text
:=s2
+copy(orgnext^
.equivalent^
.text
,
367 Writeln(t
,orgnext^
.enum
,'=',orgnext^
.equivalent^
.text
);
368 if assigned(orgnext^
.equivalent^
.comment
) and
369 (strlen(orgnext^
.equivalent^
.comment
)>0) then
370 Write(t
,orgnext^
.equivalent^
.comment
)
371 else if assigned(orgnext^
.comment
) and
372 (strlen(orgnext^
.comment
)>0) then
374 Writeln('Comment from ',OrgFileName
,' for enum ',orgnext^
.enum
,' added');
375 Write(t
,orgnext^
.comment
);
377 inc(i
,orgnext^
.equivalent^
.cnb
);
379 orgnext
:=orgnext^
.filenext
;
382 while assigned(diffnext
) do
384 if not assigned(diffnext^
.Equivalent
) then
386 { Skip removed enum
in errore
.msg
}
387 { maybe a renaming of an enum
!}
388 Writeln(diffnext^
.enum
,' commented out');
389 Writeln(t
,'%%% ',diffnext^
.enum
,'=',diffnext^
.text
);
391 Write(t
,diffnext^
.comment
);
392 inc(i
,diffnext^
.cnb
);
394 diffnext
:=diffnext^
.filenext
;
399 Writeln(ntcount
,' not translated items found');
404 ProcessFile(OrgFileName
,orgroot
,orgfirst
);
405 ProcessFile(DiffFileName
,diffRoot
,difffirst
);
406 PrintList('Org.lst',OrgRoot
);
407 PrintList('Diff.lst',DiffRoot
);
408 ShowDiff (OrgRoot
,DiffRoot
);
409 WriteReorderedFile(NewFileName
,orgfirst
,difffirst
);
413 Revision
1.1 2002/02/19 08:24:16 sasu
416 Revision
1.1 2000/07/13 06:30:14 michael
419 Revision
1.12 2000/05/12 15:03:44 pierre
420 + interactive mode
for translation
422 Revision
1.11 2000/05/12 08:47:25 pierre
423 + add a warning
if the error level is different
in the two files
424 + force to keep the order of orgfile
426 Revision
1.10 2000/05/11 13:37:37 pierre
427 * ordering bugs fixed
429 Revision
1.9 2000/02/09 13:23:11 peter
432 Revision
1.8 2000/01/07 01:15:01 peter
433 * updated copyright to
2000