home *** CD-ROM | disk | FTP | other *** search
/ Beijing Paradise BBS Backup / PARADISE.ISO / software / BBSDOORW / RADOOR30.ZIP / ML-MOD.ZIP / LANGCOMP.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1994-04-10  |  11.6 KB  |  374 lines

  1. {╔═════════════════════════════════════════════════════════════════════════╗
  2.  ║                                                                         ║
  3.  ║                   (c) CopyRight LiveSystems 1990, 1994                  ║
  4.  ║                                                                         ║
  5.  ║ Author    : Gerhard Hoogterp                                            ║
  6.  ║ FidoNet   : 2:282/100.5   2:283/7.33                                    ║
  7.  ║ BitNet    : GERHARD@LOIPON.WLINK.NL                                     ║
  8.  ║                                                                         ║
  9.  ║ SnailMail : Kremersmaten 108                                            ║
  10.  ║             7511 LC Enschede                                            ║
  11.  ║             The Netherlands                                             ║
  12.  ║                                                                         ║
  13.  ║        This module is part of the RADoor BBS doorwriters toolbox.       ║
  14.  ║                                                                         ║
  15.  ╚═════════════════════════════════════════════════════════════════════════╝}
  16.  
  17.  
  18. {A+,B-,D-,E-,F-,I-,L-,N-,O-,R-,S+,V-}
  19. {$M 10000,0,640000}
  20.  
  21. Program langCompiler;
  22. Uses Dos,
  23.      LowLevel;
  24.  
  25. Const MaxSentence = 500;
  26.  
  27. Type SentencePtr    = ^SentenceRecord;
  28.      SentenceRecord = Record
  29.                         Nr    : Word;
  30.                         Line  : String;
  31.                        End;
  32.  
  33.      Sentences      = Array[1..MaxSentence] of SentencePtr;
  34.  
  35.      SpecialRecord  = Record
  36.                        FileId    : Array[1..32] Of Char;
  37.                        VersionNr : Word;
  38.                        ProgName  : String[8];
  39.                        LanguageID: String[3];           { ENG/NL     }
  40.                        YesDef    : Char;                { Y          }
  41.                        NoDef     : Char;                { N          }
  42.                        StopDef   : Char;                { S          }
  43.                        YesNorm   : Char;                { y          }
  44.                        NoNorm    : Char;                { n          }
  45.                        StopNorm  : Char;                { s          }
  46.                        BrackRgt  : Char;                { [          }
  47.                        BrackLft  : Char;                { ]          }
  48.                        ENTER     : String[10];          { ENTER      }
  49.                        Colors    : Array[0..9] Of Byte; { Colortable }
  50.                        Entries   : Word;
  51.                       End;
  52.  
  53.      IndexEntryRec  = Record
  54.                        Nr    : Word;
  55.                        Start : Word;
  56.                        Len   : Byte;
  57.                       End;
  58.  
  59.  
  60.  
  61.  
  62. Type KeyStr   = String[10];
  63.      KeyWords = ( K_LangID    , K_ProgName ,
  64.                   K_BrackRight, K_BrackLeft,
  65.                   K_YesDef    , K_NoDef    , K_StopDef  ,
  66.                   K_YesNorm   , K_NoNorm   , K_StopNorm ,
  67.                   K_Enter     , K_Color,
  68.                   K_End
  69.                 );
  70.  
  71. Const KeyStrings : Array[K_LangId..Pred(K_End)] of KeyStr =
  72.                    (
  73.                    'LANGID'     , 'PROGNAME'  ,
  74.                    'BRACKRIGHT' , 'BRACKLEFT' ,
  75.                    'YESDEF'     , 'NODEF'     , 'STOPDEF' ,
  76.                    'YESNORM'    , 'NONORM'    , 'STOPNORM',
  77.                    'ENTER'      , 'COLOR'
  78.                    );
  79.  
  80. Function FindKey(Key : KeyStr):KeyWords;
  81. Var Temp : KeyWords;
  82. Begin
  83. Temp:=K_LangID;
  84. While (Temp<K_End) And (KeyStrings[Temp]<>Key) Do
  85.  Temp:=Succ(Temp);
  86. FindKey:=Temp;
  87. End;
  88.  
  89.  
  90.  
  91.  
  92. Var Lines    : Sentences;
  93.     Special  : SpecialRecord;
  94.     Search   : SearchRec;
  95.  
  96. Procedure InitArray;
  97. Var Count : Word;
  98. Begin
  99. For Count:=1 To MaxSentence Do
  100.  Lines[Count]:=NIL;
  101. End;
  102.  
  103. Procedure DisposeArray;
  104. Var Count : Word;
  105. Begin
  106. For Count:=1 To MaxSentence Do
  107.  If Lines[Count]<>NIL
  108.     Then Dispose(Lines[Count]);
  109. End;
  110. Function CheckLine(Var S : String;Nr : Word):Boolean;
  111. Var Count : Byte;
  112. Begin
  113. CheckLine:=False;
  114. Count:=1;
  115. While Count<=Length(S) Do
  116.  Begin
  117.  If S[Count] In ['%','^']
  118.    Then Begin
  119.         If ((Count+1)>Length(S))
  120.            Then Begin
  121.                 WriteLn(#254' Missing argument in line #',Nr);
  122.                 WriteLn(S);
  123.                 WriteLn('':Count,'^');
  124.                 Exit;
  125.                 End;
  126.         Case S[Count] of
  127.          '^' : Begin
  128.                If Not (S[Count+1] In ['0'..'9'])
  129.                   Then Begin
  130.                        WriteLn(#254' Illegal colornumber in line #',Nr);
  131.                        WriteLn(S);
  132.                        WriteLn('':Count,'^');
  133.                        Exit;
  134.                        End;
  135.                End;
  136.          '%' : Begin
  137.                If Not (Upcase(S[Count+1]) in ['Y','N','S','R','L','E'])
  138.                   Then Begin
  139.                        WriteLn(#254' Unknown indentifier in line #',Nr);
  140.                        WriteLn(S);
  141.                        WriteLn('':count,'^');
  142.                        Exit;
  143.                        End
  144.                   Else Begin
  145.                        If S[Count+1] in ['r','l','e']
  146.                           then S[Count+1]:=Upcase(S[Count+1]);
  147.                        End;
  148.                End;
  149.         End; {Case}
  150.         Inc(Count,1);
  151.         End; {If}
  152.  Inc(Count);
  153.  End; {While}
  154. CheckLine:=True;
  155. End;
  156.  
  157.  
  158.  
  159.  
  160. Procedure ReadLanguageFile(FileName : PathStr);
  161. Var LFile : Text;
  162.     Line  : String;
  163.     LineNr: Word;
  164.     ColNr : Byte;
  165.     Key   : KeyStr;
  166.     StrNr : Word;
  167.  
  168. Begin
  169. Assign(LFile,FileName);
  170. Reset(LFile);
  171. If IoResult<>0
  172.    Then Begin
  173.         WriteLn(#254' Couldn''t open '+FileName);
  174.         Halt(1);
  175.         End;
  176.  
  177. LineNr:=0;
  178. While Not Eof(LFile) Do
  179.  Begin
  180.  ReadLn(LFile,Line);
  181.  Inc(LineNr);
  182.  If (Line<>'') And (Line[1]<>';')
  183.     Then Begin
  184.          Key:=FindToken(Line,' ');
  185.          Key:=UpStr(Key);
  186.          SkipLeadingSpaces(Line);
  187.          While Line[Length(Line)]<>'"' Do
  188.            Dec(Line[0]);
  189.          If (Line[1]<>'"') Or
  190.             (Line[Length(Line)]<>'"')
  191.             Then Begin
  192.                  WriteLn(#254' Missing " in line #',LineNr);
  193.                  Close(LFile);
  194.                  DisposeArray;
  195.                  Halt(1);
  196.                  End;
  197.          Delete(Line,1,1);
  198.          Dec(Line[0]);
  199.  
  200.          Case FindKey(Key) Of
  201.            K_LangId      : Begin
  202.                            Line:=UpStr(Line);
  203.                            Special.LanguageID:=Line;
  204.                            End;
  205.            K_ProgName    : Begin
  206.                            Line:=UpStr(Line);
  207.                            Special.ProgName:=Line;
  208.                            End;
  209.            K_YesDef      : Special.YesDef:=Line[1];
  210.            K_NoDef       : Special.NoDef:=Line[1];
  211.            K_Stopdef     : Special.StopDef:=Line[1];
  212.            K_YesNorm     : Special.YesNorm:=Line[1];
  213.            K_NoNorm      : Special.NoNorm:=Line[1];
  214.            K_StopNorm    : Special.StopNorm:=Line[1];
  215.            K_BrackRight  : Special.BrackRgt:=Line[1];
  216.            K_BrackLeft   : Special.BrackLft:=Line[1];
  217.            K_Enter       : Special.Enter:=Line;
  218.            K_Color       : Begin
  219.                            ColNr:=Str2Nr(FindToken(Line,','));
  220.                            If ColNr>9
  221.                               Then Begin
  222.                                    WriteLn(#254' Illegal color number in line #',LineNr);
  223.                                    Close(LFile);
  224.                                    DisposeArray;
  225.                                    Halt(1);
  226.                                    End;
  227.                            Special.Colors[ColNr]:=Str2Nr(Line);
  228.                            End;
  229.            K_End         : Begin
  230.                            If Key[1]<>']'
  231.                               Then Begin
  232.                                    WriteLn(#254' Unrecognised info on line #',LineNr);
  233.                                    Close(LFile);
  234.                                    DisposeArray;
  235.                                    Halt(1);
  236.                                    End;
  237.                            Delete(Key,1,1);
  238.                            StrNr:=Str2Nr(Key);
  239.                            If (StrNr=0) Or (StrNr>MaxSentence)
  240.                               Then Begin
  241.                                    WriteLn(#254' Illegal StringTag in line #',LineNr);
  242.                                    Close(LFile);
  243.                                    DisposeArray;
  244.                                    Halt(1);
  245.                                    End;
  246.                            New(Lines[StrNr]);
  247.                            If Not CheckLine(Line,LineNr)
  248.                               Then Begin
  249.                                    Close(LFile);
  250.                                    DisposeArray;
  251.                                    Halt(1);
  252.                                    End;
  253.                            Lines[StrNr]^.Nr:=StrNr;
  254.                            Lines[StrNr]^.Line:=Line;
  255.                            Inc(Special.Entries);
  256.                            End;
  257.          End; {Case}
  258.          End; {If}
  259.  End; {While}
  260. Close(LFile);
  261. End;
  262.  
  263.  
  264.  
  265. Procedure WriteLanguageFile(FileName : PathStr);
  266. Var Out   : File;
  267.     Idx   : IndexEntryRec;
  268.     Entry : Word;
  269.     Count : Word;
  270.     Start : Word;
  271.  
  272. Begin
  273. Assign(Out,FileName);
  274. Rewrite(Out,1);
  275. If IoResult<>0
  276.    Then Begin
  277.         WriteLn(#254' Couldn''t write languagefile.');
  278.         DisposeArray;
  279.         Halt(1);
  280.         End;
  281.  
  282. BlockWrite(Out,Special,SizeOf(Special));
  283. If IoResult<>0
  284.    Then Begin
  285.         WriteLn(#254' Error writing language header.');
  286.         DisposeArray;
  287.         Close(Out);
  288.         Halt(1);
  289.         End;
  290.  
  291. FillChar(IDX,SizeOf(Idx),#00);
  292. For Count:=1 To MaxSentence Do
  293.  Begin
  294.  If Lines[Count]<>NIL
  295.     Then Begin
  296.          BlockWrite(Out,IDX,SizeOf(IDX));
  297.          If IoResult<>0
  298.             Then Begin
  299.                  WriteLn(#254' Error writing index.');
  300.                  DisposeArray;
  301.                  Close(Out);
  302.                  Halt(1);
  303.                  End;
  304.          End;
  305.  End;
  306.  
  307. Entry:=0;
  308. Start:=FilePos(Out);
  309.  
  310. For Count:=1 to MaxSentence Do
  311.  Begin
  312.  If Lines[Count]<>NIL
  313.     Then Begin
  314.          IDX.Nr:=Lines[Count]^.Nr;
  315.          IDX.Len:=Length(Lines[Count]^.Line);
  316.          IDX.Start:=FileSize(Out)-Start;
  317.  
  318.          BlockWrite(Out,Lines[Count]^.Line[1],Length(Lines[Count]^.Line));
  319.  
  320.          Seek(Out,SizeOf(Special)+(Entry*SizeOf(Idx)));
  321.          BlockWrite(Out,IDX,SizeOf(Idx));
  322.          Seek(Out,FileSize(Out));
  323.          Inc(Entry);
  324.          End;
  325.  End;
  326.  
  327. Close(Out);
  328. End;
  329.  
  330.  
  331.  
  332.  
  333. Var FileName    : PathStr;
  334.     Path        : PathStr;
  335.     Dum         : String[10];
  336.     FileID      : String[32];
  337.  
  338. Begin
  339. WriteLn('LangComp 1.0 (c) LiveSystems 1991,1992 ALL RIGHTS RESERVED, NO GUARANTEES');
  340. WriteLn('Written by G.Hoogterp. E-mail address 2:283/1.2 Last Revision 09 Nov 1991');
  341. WriteLn;
  342. If ParamCount=0
  343.    Then Begin
  344.         WriteLn(#254' Usage:  LangComp <Input FileSpec>');
  345.         WriteLn(#254' The output goes to a file LANGUAGE.<LanguageID>');
  346.         WriteLn(#254' you may use wildcards in the filespec.');
  347.         Halt;
  348.         End;
  349.  
  350. FileName:=ParamStr(1);
  351. FSplit(FileName,Path,Dum,Dum);
  352.  
  353. FindFirst(FileName,AnyFile,Search);
  354. While DosError=0 Do
  355.  Begin
  356.  InitArray;
  357.  FillChar(Special,SizeOf(Special),#00);
  358.  
  359.  FileId:='LiveSystems language file v1.00'^Z;
  360.  Move(FileID[1],Special.FileId,Length(FileID));
  361.  Special.VersionNr:=$0100;
  362.  
  363.  WriteLn(#254' Reading file ',Search.Name);
  364.  ReadLanguageFile(Path+Search.Name);
  365.  
  366.  WriteLn(#254' Writing file '+Special.ProgName+'.'+Special.LanguageID);
  367.  WriteLanguageFile(Path+Special.ProgName+'.'+Special.LanguageID);
  368.  
  369.  DisposeArray;
  370.  FindNext(Search);
  371.  End;
  372.  
  373. End.
  374.