42 first: array[TEventId] of boolean; |
42 first: array[TEventId] of boolean; |
43 e: TEventId; |
43 e: TEventId; |
44 loaded: boolean; |
44 loaded: boolean; |
45 begin |
45 begin |
46 loaded:= false; |
46 loaded:= false; |
47 for e:= Low(TEventId) to High(TEventId) do first[e]:= true; |
47 for e:= Low(TEventId) to High(TEventId) do |
|
48 first[e]:= true; |
48 |
49 |
49 {$I-} // iochecks off |
50 {$I-} // iochecks off |
50 Assign(f, FileName); |
51 Assign(f, FileName); |
51 filemode:= 0; // readonly |
52 filemode:= 0; // readonly |
52 Reset(f); |
53 Reset(f); |
53 if IOResult = 0 then loaded:= true; |
54 if IOResult = 0 then |
|
55 loaded:= true; |
54 TryDo(loaded, 'Cannot load locale "' + FileName + '"', false); |
56 TryDo(loaded, 'Cannot load locale "' + FileName + '"', false); |
55 if loaded then |
57 if loaded then |
56 begin |
58 begin |
57 while not eof(f) do |
59 while not eof(f) do |
58 begin |
60 begin |
59 readln(f, s); |
61 readln(f, s); |
60 if Length(s) = 0 then continue; |
62 if Length(s) = 0 then |
61 if (s[1] < '0') or (s[1] > '9') then continue; |
63 continue; |
62 TryDo(Length(s) > 6, 'Load locale: empty string', true); |
64 if (s[1] < '0') or (s[1] > '9') then |
63 val(s[1]+s[2], a, c); |
65 continue; |
64 TryDo(c = 0, 'Load locale: numbers should be two-digit: ' + s, true); |
66 TryDo(Length(s) > 6, 'Load locale: empty string', true); |
65 TryDo(s[3] = ':', 'Load locale: ":" expected', true); |
67 val(s[1]+s[2], a, c); |
66 val(s[4]+s[5], b, c); |
68 TryDo(c = 0, 'Load locale: numbers should be two-digit: ' + s, true); |
67 TryDo(c = 0, 'Load locale: numbers should be two-digit' + s, true); |
69 TryDo(s[3] = ':', 'Load locale: ":" expected', true); |
68 TryDo(s[6] = '=', 'Load locale: "=" expected', true); |
70 val(s[4]+s[5], b, c); |
69 Delete(s, 1, 6); |
71 TryDo(c = 0, 'Load locale: numbers should be two-digit' + s, true); |
70 case a of |
72 TryDo(s[6] = '=', 'Load locale: "=" expected', true); |
71 0: if (b >=0) and (b <= ord(High(TAmmoStrId))) then trammo[TAmmoStrId(b)]:= s; |
73 Delete(s, 1, 6); |
72 1: if (b >=0) and (b <= ord(High(TMsgStrId))) then trmsg[TMsgStrId(b)]:= s; |
74 case a of |
73 2: if (b >=0) and (b <= ord(High(TEventId))) then begin |
75 0: if (b >=0) and (b <= ord(High(TAmmoStrId))) then |
74 TryDo(trevt_n[TEventId(b)] < MAX_EVENT_STRINGS, 'Too many event strings in ' + IntToStr(a) + ':' + IntToStr(b), false); |
76 trammo[TAmmoStrId(b)]:= s; |
75 if first[TEventId(b)] then |
77 1: if (b >=0) and (b <= ord(High(TMsgStrId))) then |
76 begin |
78 trmsg[TMsgStrId(b)]:= s; |
77 trevt_n[TEventId(b)]:= 0; |
79 2: if (b >=0) and (b <= ord(High(TEventId))) then |
78 first[TEventId(b)]:= false; |
80 begin |
79 end; |
81 TryDo(trevt_n[TEventId(b)] < MAX_EVENT_STRINGS, 'Too many event strings in ' + IntToStr(a) + ':' + IntToStr(b), false); |
80 trevt[TEventId(b)][trevt_n[TEventId(b)]]:= s; |
82 if first[TEventId(b)] then |
81 inc(trevt_n[TEventId(b)]); |
83 begin |
82 end; |
84 trevt_n[TEventId(b)]:= 0; |
83 3: if (b >=0) and (b <= ord(High(TAmmoStrId))) then trammoc[TAmmoStrId(b)]:= s; |
85 first[TEventId(b)]:= false; |
84 4: if (b >=0) and (b <= ord(High(TAmmoStrId))) then trammod[TAmmoStrId(b)]:= s; |
86 end; |
85 5: if (b >=0) and (b <= ord(High(TGoalStrId))) then trgoal[TGoalStrId(b)]:= s; |
87 trevt[TEventId(b)][trevt_n[TEventId(b)]]:= s; |
|
88 inc(trevt_n[TEventId(b)]); |
|
89 end; |
|
90 3: if (b >=0) and (b <= ord(High(TAmmoStrId))) then |
|
91 trammoc[TAmmoStrId(b)]:= s; |
|
92 4: if (b >=0) and (b <= ord(High(TAmmoStrId))) then |
|
93 trammod[TAmmoStrId(b)]:= s; |
|
94 5: if (b >=0) and (b <= ord(High(TGoalStrId))) then |
|
95 trgoal[TGoalStrId(b)]:= s; |
86 end; |
96 end; |
87 end; |
97 end; |
88 Close(f); |
98 Close(f); |
89 WriteLnToConsole('Locale loaded "' + FileName + '"'); |
99 WriteLnToConsole('Locale loaded "' + FileName + '"'); |
90 end; |
100 end; |
101 |
111 |
102 function Format(fmt: shortstring; var arg: shortstring): shortstring; |
112 function Format(fmt: shortstring; var arg: shortstring): shortstring; |
103 var i: LongInt; |
113 var i: LongInt; |
104 begin |
114 begin |
105 i:= Pos('%1', fmt); |
115 i:= Pos('%1', fmt); |
106 if i = 0 then Format:= fmt |
116 if i = 0 then |
107 else Format:= copy(fmt, 1, i - 1) + arg + Format(copy(fmt, i + 2, Length(fmt) - i - 1), arg) |
117 Format:= fmt |
|
118 else |
|
119 Format:= copy(fmt, 1, i - 1) + arg + Format(copy(fmt, i + 2, Length(fmt) - i - 1), arg) |
108 end; |
120 end; |
109 |
121 |
110 function Format(fmt: ansistring; var arg: ansistring): ansistring; |
122 function Format(fmt: ansistring; var arg: ansistring): ansistring; |
111 var i: LongInt; |
123 var i: LongInt; |
112 begin |
124 begin |
113 i:= Pos('%1', fmt); |
125 i:= Pos('%1', fmt); |
114 if i = 0 then Format:= fmt |
126 if i = 0 then |
115 else Format:= copy(fmt, 1, i - 1) + arg + Format(copy(fmt, i + 2, Length(fmt) - i - 1), arg) |
127 Format:= fmt |
|
128 else |
|
129 Format:= copy(fmt, 1, i - 1) + arg + Format(copy(fmt, i + 2, Length(fmt) - i - 1), arg) |
116 end; |
130 end; |
117 |
131 |
118 procedure LoadLocaleWrapper(str: pchar); cdecl; export; |
132 procedure LoadLocaleWrapper(str: pchar); cdecl; export; |
119 begin |
133 begin |
120 LoadLocale(Strpas(str)); |
134 LoadLocale(Strpas(str)); |