home *** CD-ROM | disk | FTP | other *** search
- {$A+,B-,D+,E+,F-,G-,I-,L+,N-,O-,R-,S+,V+,X+}
- {$M 16384,0,655360}
-
- PROGRAM CheckLng;
- {
- Author : Zweistein
- Version : 1.1
- Date : 21-November-1998
-
- Tab Width : 4
-
- History:
-
- 1.0 June 6th, 1998:
- First Version, nothing special
-
- 1.1 November 21st, 1998
- Added check for empty strings
- Comparison of two files
-
- Warning:
-
- Please do NOT regard this piece of software as an example for a good
- programming style. This program was made in state of pure frustration
- during a ".LNG-file error search night shift" ;-)
- }
-
- USES Crt;
-
- CONST
- MAX_ID = 1000;
-
- TYPE
- InfoField = ARRAY[1..MAX_ID] OF Boolean;
-
- VAR
- Missing, ErrorFnd : ARRAY [0..1] OF InfoField;
- Empty : ARRAY [0..1] OF InfoField;
-
-
- PROCEDURE DisplayInfo;
- BEGIN
- WriteLn;
- WriteLn('CheckLng 1.1 - A simple program to check HackMan LNG files');
- WriteLn;
- WriteLn('Synopsis : CHKLNG LanguageFile <OriginalFile>');
- WriteLn;
- WriteLn('Example : CHKLNG GERMAN.LNG ENGLISH.LNG');
- WriteLn;
- WriteLn('This will read the files GERMAN.LNG, and ENGLISH.LNG,');
- WriteLn('check all the lines, count the number of correct, incorrect,');
- WriteLn('and empty strings.');
- WriteLn('The statistics files will be created in the same directory using');
- WriteLn('the file names GERMAN.STT and ENGLISH.STT.');
- WriteLn('Besides, there will be a comparison file named "PROBLEMS.TXT" which');
- WriteLn('shows errors and differences between the two files.');
- WriteLn;
- WriteLn('Press any key to quit ...');
- ReadKey;
- END;
-
-
- FUNCTION WriteField(VAR OutputFile : TEXT; Info : InfoField): Integer;
- VAR
- Error, Len, Cnt : Integer;
- BEGIN
- Error := 0;
- Cnt := 1;
- Len := 0;
- WHILE (Cnt < MAX_ID) AND (Error = 0) DO
- BEGIN
- IF Info[Cnt] THEN
- BEGIN
- Len := Len + 5;
- Write(OutputFile, Cnt:5);
- END;
-
- IF (Len > 45) THEN
- BEGIN
- WriteLn(OutputFile);
- Len := 0;
- END;
- Error := IOResult;
- INC(Cnt);
- END;
-
- IF (Error = 0) THEN
- WriteLn(OutputFile, #13#10#13#10);
- Error := IOResult;
-
- WriteField := Error;
- END;
-
-
- PROCEDURE Process(FileName : STRING; FileNum : Integer);
- VAR
- LngFile, StatFile : TEXT;
- ProblemsFile : TEXT;
- CntOK, CntError : Integer;
- Error, Cnt, Len : Integer;
- TextID, TextErr : Integer;
- CommaPos, QM_Cnt : Integer;
- StatName, Line, ID: STRING;
- LngOpen, StatOpen : Boolean;
- OK : Boolean;
- QuotePos : ARRAY[0..3] OF Integer;
-
- PROCEDURE ShowProblems;
- VAR
- Cnt : Integer;
- BEGIN
- FOR Cnt := 1 TO MAX_ID DO
- BEGIN
- IF (Missing[0, Cnt]) THEN
- WriteLn(ProblemsFile, 'Missing TextID ', Cnt,' in File "',
- ParamStr(1),'"');
- IF (Missing[1, Cnt]) THEN
- WriteLn(ProblemsFile, 'Missing TextID ', Cnt,' in File "',
- ParamStr(2),'"');
-
- IF (ErrorFnd[0, Cnt]) THEN
- WriteLn(ProblemsFile, 'Error in TextID ', Cnt,' in File "',
- ParamStr(1),'"');
- IF (ErrorFnd[1, Cnt]) THEN
- WriteLn(ProblemsFile, 'Error in TextID ', Cnt,' in File "',
- ParamStr(2),'"');
-
- IF (Empty[0, Cnt] <> Empty[1, Cnt]) THEN
- WriteLn(ProblemsFile, 'Difference found in TextID ', Cnt);
- END;
- END;
-
- BEGIN
- LngOpen := False;
- StatOpen := False;
- OK := False;
-
- { init information fields }
- FillChar(Missing[FileNum], SizeOf(InfoField), True);
- FillChar(ErrorFnd[FileNum], SizeOf(InfoField), False);
- FillChar(Empty[FileNum], SizeOf(InfoField), False);
-
- { open/create files }
- Assign(LngFile, FileName);
- IF (IOResult = 0) THEN
- Reset(LngFile);
- Error := IOResult;
-
- IF (Error = 0) THEN
- BEGIN
- LngOpen := True;
- StatName := FileName;
- DEC(StatName[0],3);
- StatName := StatName + 'STT';
- Assign(StatFile, StatName);
- IF (IOResult = 0) THEN
- Rewrite(StatFile);
- Error := IOResult;
- IF (Error = 0) THEN
- StatOpen := True;
- WriteLn(StatFile, 'Language File : ', FileName,#13#10);
- WriteLn(StatFile, 'Lines with no or erroneous ID:'#13#10);
- END;
-
- { check language file }
- Cnt := 0;
- Line := '';
- QM_Cnt := 0;
-
- WHILE NOT EoF(LngFile) AND (Error = 0) DO
- BEGIN
- IF (Length(Line) < 255) THEN
- INC(Cnt);
-
- ReadLn(LngFile, Line);
- Error := IOResult;
-
- IF (Error = 0) THEN
- BEGIN
- CommaPos := Pos(',', Line);
- ID := Copy(Line, 1, CommaPos-1);
- Val(ID, TextID, TextErr);
- IF (TextErr <> 0) OR
- ((TextId < 1) AND (TextID > MAX_ID)) THEN
- WriteLn(StatFile, Cnt:4, ': ',Line)
- ELSE
- BEGIN
- Missing[FileNum, TextID] := False;
-
- Len := Length(Line);
-
- WHILE (CommaPos <= Len) DO
- BEGIN
- IF (Line[CommaPos] = '"') THEN
- BEGIN
- QuotePos[QM_Cnt] := CommaPos;
- INC(QM_Cnt);
- IF (QM_Cnt > 2) THEN
- ErrorFnd[FileNum, TextID] := True;
- END;
- INC(CommaPos);
- END;
-
- IF (QM_Cnt < 2) THEN
- BEGIN
- IF (Length(Line) < 255) THEN
- BEGIN
- ErrorFnd[FileNum, TextID] := True;
- QM_Cnt := 0;
- END
- END
- ELSE
- BEGIN
- IF (QM_Cnt = 2) AND (QuotePos[0] = QuotePos[1]-1) THEN
- Empty[FileNum, TextID] := True;
- QM_Cnt := 0;
- END
- END;
-
- Error := IOResult;
- END;
- END;
-
- { display result }
- IF (Error = 0) THEN
- BEGIN
- WriteLn(StatFile, #13#10'Missing strings:'#13#10);
- IF (WriteField(StatFile, Missing[FileNum]) = 0) THEN
- BEGIN
- WriteLn(StatFile, #13#10'Incorrect strings:'#13#10);
- IF (WriteField(StatFile, ErrorFnd[FileNum]) = 0) THEN
- BEGIN
- WriteLn(StatFile, #13#10'Empty strings:'#13#10);
- WriteField(StatFile, Empty[FileNum]);
- OK := True;
- END;
- END;
- END;
-
- IF OK AND (FileNum = 1) THEN
- BEGIN
- Assign(ProblemsFile, 'PROBLEMS.TXT');
- Rewrite(ProblemsFile);
- ShowProblems;
- Close(ProblemsFile);
- END;
-
-
- IF LngOpen THEN
- Close(LngFile);
- IF StatOpen THEN
- Close(StatFile);
- END;
-
-
- BEGIN
- CASE ParamCount OF
- 0: DisplayInfo;
- 1: Process(ParamStr(1), 0);
- 2: BEGIN
- Process(ParamStr(1), 0);
- Process(ParamStr(2), 1);
- END;
- END;
- END.