hedgewars/uLocale.pas
changeset 11537 bf86c6cb9341
parent 11204 08c6ccc28007
child 11549 b69f5f22a3ba
child 11689 cfc3971de8ac
equal deleted inserted replaced
11536:d1cf1ff6cabb 11537:bf86c6cb9341
    48 begin
    48 begin
    49 for e:= Low(TEventId) to High(TEventId) do
    49 for e:= Low(TEventId) to High(TEventId) do
    50     first[e]:= true;
    50     first[e]:= true;
    51 
    51 
    52 f:= pfsOpenRead(FileName);
    52 f:= pfsOpenRead(FileName);
    53 TryDo(f <> nil, 'Cannot load locale "' + FileName + '"', false);
    53 checkFails(f <> nil, 'Cannot load locale "' + FileName + '"', false);
    54 
    54 
    55 s:= '';
    55 s:= '';
    56 
    56 
    57 if f <> nil then
    57 if f <> nil then
    58     begin
    58     begin
    61         pfsReadLnA(f, s);
    61         pfsReadLnA(f, s);
    62         if Length(s) = 0 then
    62         if Length(s) = 0 then
    63             continue;
    63             continue;
    64         if (s[1] < '0') or (s[1] > '9') then
    64         if (s[1] < '0') or (s[1] > '9') then
    65             continue;
    65             continue;
    66         TryDo(Length(s) > 6, 'Load locale: empty string', true);
    66         checkFails(Length(s) > 6, 'Load locale: empty string', true);
    67         {$IFNDEF PAS2C}
    67         {$IFNDEF PAS2C}
    68         val(s[1]+s[2], a, c);
    68         val(s[1]+s[2], a, c);
    69         TryDo(c = 0, ansistring('Load locale: numbers should be two-digit: ') + s, true);
    69         checkFails(c = 0, ansistring('Load locale: numbers should be two-digit: ') + s, true);
    70         val(s[4]+s[5], b, c);
    70         val(s[4]+s[5], b, c);
    71         TryDo(c = 0, ansistring('Load locale: numbers should be two-digit: ') + s, true);
    71         checkFails(c = 0, ansistring('Load locale: numbers should be two-digit: ') + s, true);
    72         {$ELSE}
    72         {$ELSE}
    73         val(s[1]+s[2], a);
    73         val(s[1]+s[2], a);
    74         val(s[4]+s[5], b);
    74         val(s[4]+s[5], b);
    75         {$ENDIF}
    75         {$ENDIF}
    76         TryDo(s[3] = ':', 'Load locale: ":" expected', true);
    76         checkFails(s[3] = ':', 'Load locale: ":" expected', true);
    77         TryDo(s[6] = '=', 'Load locale: "=" expected', true);
    77         checkFails(s[6] = '=', 'Load locale: "=" expected', true);
       
    78         if not allOK then exit;
    78         Delete(s, 1, 6);
    79         Delete(s, 1, 6);
    79         case a of
    80         case a of
    80             0: if (b >=0) and (b <= ord(High(TAmmoStrId))) then
    81             0: if (b >=0) and (b <= ord(High(TAmmoStrId))) then
    81                 trammo[TAmmoStrId(b)]:= s;
    82                 trammo[TAmmoStrId(b)]:= s;
    82             1: if (b >=0) and (b <= ord(High(TMsgStrId))) then
    83             1: if (b >=0) and (b <= ord(High(TMsgStrId))) then
    83                 trmsg[TMsgStrId(b)]:= s;
    84                 trmsg[TMsgStrId(b)]:= s;
    84             2: if (b >=0) and (b <= ord(High(TEventId))) then
    85             2: if (b >=0) and (b <= ord(High(TEventId))) then
    85                 begin
    86                 begin
    86                 TryDo(trevt_n[TEventId(b)] < MAX_EVENT_STRINGS, 'Too many event strings in ' + IntToStr(a) + ':' + IntToStr(b), false);
    87                 checkFails(trevt_n[TEventId(b)] < MAX_EVENT_STRINGS, 'Too many event strings in ' + IntToStr(a) + ':' + IntToStr(b), false);
    87                 if first[TEventId(b)] then
    88                 if first[TEventId(b)] then
    88                     begin
    89                     begin
    89                     trevt_n[TEventId(b)]:= 0;
    90                     trevt_n[TEventId(b)]:= 0;
    90                     first[TEventId(b)]:= false;
    91                     first[TEventId(b)]:= false;
    91                     end;
    92                     end;