|
@@ -187,7 +187,7 @@ const
|
|
|
EmptyCC: TCountryCode = (Country: 0; Codepage: 0); (* Empty = current *)
|
|
|
(* 819 = IBM codepage number for ISO 8859-1 used in FPC default *)
|
|
|
(* dummy translation between UnicodeString and AnsiString. *)
|
|
|
- IsoCC: TCountryCode = (Country: 1; Codepage: 819); (* Empty = current *)
|
|
|
+ IsoCC: TCountryCode = (Country: 1; Codepage: 819); (* US with ISO 8859-1 *)
|
|
|
(* The following two arrays are initialized on startup in case that *)
|
|
|
(* Dummy* routines must be used. First for current codepage... *)
|
|
|
DBCSLeadRangesEnd: byte = 0;
|
|
@@ -448,7 +448,7 @@ begin
|
|
|
Dec (SrcLen);
|
|
|
Inc (InBuf, SrcLen);
|
|
|
Dec (InBytesLeft, SrcLen);
|
|
|
- DummyUniUConvToUcs := Uls_BufferFull; { According to IBM documentation Uls_Invalid and not Uls_BufferFull as returned by UniUConvFromUcs?! }
|
|
|
+ DummyUniUConvToUcs := Uls_BufferFull; { According to IBM documentation Uls_Invalid and not Uls_BufferFull is returned by UniUConvFromUcs?! }
|
|
|
end
|
|
|
else
|
|
|
begin
|
|
@@ -462,6 +462,19 @@ begin
|
|
|
end;
|
|
|
|
|
|
|
|
|
+function DummyUniMapCtryToLocale (CountryCode: cardinal; LocaleName: PWideChar;
|
|
|
+ BufSize: longint): longint; cdecl;
|
|
|
+begin
|
|
|
+ if BufSize = 0 then
|
|
|
+ DummyUniMapCtryToLocale := Uls_Invalid
|
|
|
+ else
|
|
|
+ begin
|
|
|
+ LocaleName^ := #0;
|
|
|
+ DummyUniMapCtryToLocale := Uls_Unsupported;
|
|
|
+ end;
|
|
|
+end;
|
|
|
+
|
|
|
+
|
|
|
procedure InitDBCSLeadRanges;
|
|
|
var
|
|
|
RC: cardinal;
|
|
@@ -703,6 +716,8 @@ var
|
|
|
RC: cardinal;
|
|
|
CPArr: TCPArray;
|
|
|
ReturnedSize: cardinal;
|
|
|
+ WA: array [0..9] of WideChar; (* Even just 6 WideChars should be enough *)
|
|
|
+ CI: TCountryInfo;
|
|
|
begin
|
|
|
if InInitDefaultCP <> -1 then
|
|
|
begin
|
|
@@ -751,22 +766,50 @@ begin
|
|
|
OSErrorWatch (cardinal (RCI));
|
|
|
DefLocObj := nil;
|
|
|
end;
|
|
|
- RCI := Sys_UniCreateLocaleObject (Uni_UCS_String_Pointer, @WNull, DefLocObj);
|
|
|
- if RCI <> 0 then
|
|
|
+ if UniAPI then (* Do not bother with the locale object otherwise *)
|
|
|
begin
|
|
|
- OSErrorWatch (cardinal (RCI));
|
|
|
-(* The locale dependent routines like comparison require a valid locale *)
|
|
|
-(* setting, but the locale set using environment variable LANG is not *)
|
|
|
-(* recognized by OS/2 -> we try the "Universal" locale as a fallback. *)
|
|
|
- RCI := Sys_UniCreateLocaleObject (Uni_UCS_String_Pointer, @WUniv [0],
|
|
|
- DefLocObj);
|
|
|
+ RCI := Sys_UniCreateLocaleObject (Uni_UCS_String_Pointer, @WNull, DefLocObj);
|
|
|
if RCI <> 0 then
|
|
|
begin
|
|
|
OSErrorWatch (cardinal (RCI));
|
|
|
DefLocObj := nil;
|
|
|
+(* The locale dependent routines like comparison require a valid locale *)
|
|
|
+(* setting, but the locale set using environment variable LANG is not *)
|
|
|
+(* recognized by OS/2 -> let's try to derive the locale from country *)
|
|
|
+ RC := DosQueryCtryInfo (SizeOf (CI), EmptyCC, CI, ReturnedSize);
|
|
|
+ if RC = 0 then
|
|
|
+ begin
|
|
|
+ RCI := Sys_UniMapCtryToLocale (CI.Country, @WA [0],
|
|
|
+ SizeOf (WA) div SizeOf (WideChar));
|
|
|
+ if RCI = 0 then
|
|
|
+ begin
|
|
|
+ RCI := Sys_UniCreateLocaleObject (Uni_UCS_String_Pointer, @WA [0],
|
|
|
+ DefLocObj);
|
|
|
+ if RCI <> 0 then
|
|
|
+ begin
|
|
|
+ OSErrorWatch (cardinal (RCI));
|
|
|
+ DefLocObj := nil;
|
|
|
+ end;
|
|
|
+ end
|
|
|
+ else
|
|
|
+ OSErrorWatch (cardinal (RCI));
|
|
|
+ end
|
|
|
+ else
|
|
|
+ OSErrorWatch (RC);
|
|
|
+ if DefLocObj = nil then
|
|
|
+(* Still no success -> let's use the "Universal" locale as a fallback. *)
|
|
|
+ begin
|
|
|
+ RCI := Sys_UniCreateLocaleObject (Uni_UCS_String_Pointer, @WUniv [0],
|
|
|
+ DefLocObj);
|
|
|
+ if RCI <> 0 then
|
|
|
+ begin
|
|
|
+ OSErrorWatch (cardinal (RCI));
|
|
|
+ DefLocObj := nil;
|
|
|
+ end;
|
|
|
+ end;
|
|
|
end;
|
|
|
- end;
|
|
|
- if not (UniAPI) then
|
|
|
+ end
|
|
|
+ else (* not UniAPI *)
|
|
|
ReInitDummyAnsiSupport;
|
|
|
InInitDefaultCP := -1;
|
|
|
end;
|
|
@@ -1603,8 +1646,14 @@ begin
|
|
|
if RC = 0 then
|
|
|
begin
|
|
|
Sys_UniFreeLocaleObject := TUniFreeLocaleObject (P);
|
|
|
-
|
|
|
- UniAPI := true;
|
|
|
+ RC := DosQueryProcAddr (LibUniHandle,
|
|
|
+ OrdUniMapCtryToLocale, nil, P);
|
|
|
+ if RC = 0 then
|
|
|
+ begin
|
|
|
+ Sys_UniMapCtryToLocale := TUniMapCtryToLocale (P);
|
|
|
+
|
|
|
+ UniAPI := true;
|
|
|
+ end;
|
|
|
end;
|
|
|
end;
|
|
|
end;
|
|
@@ -1631,6 +1680,7 @@ begin
|
|
|
Sys_UniStrColl := @DummyUniStrColl;
|
|
|
Sys_UniCreateLocaleObject := @DummyUniCreateLocaleObject;
|
|
|
Sys_UniFreeLocaleObject := @DummyUniFreeLocaleObject;
|
|
|
+ Sys_UniMapCtryToLocale := @DummyUniMapCtryToLocale;
|
|
|
InitDummyAnsiSupport;
|
|
|
end;
|
|
|
|