hedgewars/uLocale.pas
changeset 2722 d891285e500f
parent 2721 87067dcc208b
child 2747 7889a3a9724f
equal deleted inserted replaced
2721:87067dcc208b 2722:d891285e500f
    56 var s: shortstring;
    56 var s: shortstring;
    57     f: textfile;
    57     f: textfile;
    58     a, b, c: LongInt;
    58     a, b, c: LongInt;
    59 	first: array[TEventId] of boolean;
    59 	first: array[TEventId] of boolean;
    60 	e: TEventId;
    60 	e: TEventId;
       
    61     loaded: boolean;
    61 begin
    62 begin
       
    63 loaded:= false;
    62 trammo[sidNothing]:= ' ';
    64 trammo[sidNothing]:= ' ';
    63 for e:= Low(TEventId) to High(TEventId) do first[e]:= true;
    65 for e:= Low(TEventId) to High(TEventId) do first[e]:= true;
    64 
    66 
    65 {$I-} // iochecks off
    67 {$I-} // iochecks off
    66 filemode:= 0; // readonly
    68 filemode:= 0; // readonly
    67 Assign(f, FileName);
    69 Assign(f, FileName);
    68 reset(f);
    70 reset(f);
    69 TryDo(IOResult = 0, 'Cannot load locale "' + FileName + '"', false);
    71 if IOResult = 0 then loaded:= true;
    70 while not eof(f) do
    72 TryDo(loaded, 'Cannot load locale "' + FileName + '"', false);
    71     begin
    73 if loaded then
    72     readln(f, s);
    74    begin
    73     if Length(s) = 0 then continue;
    75    while not eof(f) do
    74     if not (s[1] in ['0'..'9']) then continue;
    76        begin
    75     TryDo(Length(s) > 6, 'Load locale: empty string', true);
    77        readln(f, s);
    76     val(s[1]+s[2], a, c);
    78        if Length(s) = 0 then continue;
    77     TryDo(c = 0, 'Load locale: numbers should be two-digit: ' + s, true);
    79        if not (s[1] in ['0'..'9']) then continue;
    78     TryDo(s[3] = ':', 'Load locale: ":" expected', true);
    80        TryDo(Length(s) > 6, 'Load locale: empty string', true);
    79     val(s[4]+s[5], b, c);
    81        val(s[1]+s[2], a, c);
    80     TryDo(c = 0, 'Load locale: numbers should be two-digit' + s, true);
    82        TryDo(c = 0, 'Load locale: numbers should be two-digit: ' + s, true);
    81     TryDo(s[6] = '=', 'Load locale: "=" expected', true);
    83        TryDo(s[3] = ':', 'Load locale: ":" expected', true);
    82     Delete(s, 1, 6);
    84        val(s[4]+s[5], b, c);
    83     case a of
    85        TryDo(c = 0, 'Load locale: numbers should be two-digit' + s, true);
    84         0: if (b >=0) and (b <= ord(High(TAmmoStrId))) then trammo[TAmmoStrId(b+1)]:= s;
    86        TryDo(s[6] = '=', 'Load locale: "=" expected', true);
    85         1: if (b >=0) and (b <= ord(High(TMsgStrId))) then trmsg[TMsgStrId(b)]:= s;
    87        Delete(s, 1, 6);
    86         2: if (b >=0) and (b <= ord(High(TEventId))) then begin
    88        case a of
    87             TryDo(trevt_n[TEventId(b)] < MAX_EVENT_STRINGS, 'Too many event strings in ' + inttostr(a) + ':' + inttostr(b), false);
    89            0: if (b >=0) and (b <= ord(High(TAmmoStrId))) then trammo[TAmmoStrId(b+1)]:= s;
    88             if first[TEventId(b)] then
    90            1: if (b >=0) and (b <= ord(High(TMsgStrId))) then trmsg[TMsgStrId(b)]:= s;
    89                 begin
    91            2: if (b >=0) and (b <= ord(High(TEventId))) then begin
    90                 trevt_n[TEventId(b)]:= 0;
    92                TryDo(trevt_n[TEventId(b)] < MAX_EVENT_STRINGS, 'Too many event strings in ' + inttostr(a) + ':' + inttostr(b), false);
    91                 first[TEventId(b)]:= false;
    93                if first[TEventId(b)] then
    92                 end;
    94                    begin
    93             trevt[TEventId(b)][trevt_n[TEventId(b)]]:= s;
    95                    trevt_n[TEventId(b)]:= 0;
    94             inc(trevt_n[TEventId(b)]);
    96                    first[TEventId(b)]:= false;
    95             end;
    97                    end;
    96         end;
    98                trevt[TEventId(b)][trevt_n[TEventId(b)]]:= s;
    97     end;
    99                inc(trevt_n[TEventId(b)]);
    98 Close(f)
   100                end;
       
   101            end;
       
   102        end;
       
   103    Close(f)
       
   104    end;
    99 {$I+}
   105 {$I+}
   100 end;
   106 end;
   101 
   107 
   102 function GetEventString(e: TEventId): string;
   108 function GetEventString(e: TEventId): string;
   103 begin
   109 begin