Pārlūkot izejas kodu

rtl: set codepages for TextRec field when Text file is opened + update this field for standard IO files when cwstring is used

git-svn-id: trunk@19543 -
paul 13 gadi atpakaļ
vecāks
revīzija
e08c68f308
2 mainītis faili ar 38 papildinājumiem un 1 dzēšanām
  1. 14 1
      rtl/inc/text.inc
  2. 24 0
      rtl/unix/cwstring.pp

+ 14 - 1
rtl/inc/text.inc

@@ -146,6 +146,11 @@ Begin
   TextRec(t).mode:=mode;
   TextRec(t).bufpos:=0;
   TextRec(t).bufend:=0;
+  {$ifndef ver2_4}
+  { if no codepage is yet assigned then assign default ansi codepage }
+  if TextRec(t).CodePage=CP_ACP then
+    TextRec(t).CodePage:=DefaultSystemCodePage;
+  {$endif ver2_4}
   FileFunc(TextRec(t).OpenFunc)(TextRec(t));
   { reset the mode to closed when an error has occured }
   if InOutRes<>0 then
@@ -1911,10 +1916,18 @@ begin
   TextRec(f).Closefunc:=@FileCloseFunc;
   case mode of
     fmInput :
-      TextRec(f).InOutFunc:=@FileReadFunc;
+      begin
+        TextRec(f).InOutFunc:=@FileReadFunc;
+      {$ifndef ver2_4}
+        TextRec(f).CodePage:=WideStringManager.GetStandardCodePageProc(scpConsoleInput);
+      {$endif ver2_4}
+      end;
     fmOutput :
       begin
         TextRec(f).InOutFunc:=@FileWriteFunc;
+      {$ifndef ver2_4}
+        TextRec(f).CodePage:=WideStringManager.GetStandardCodePageProc(scpConsoleOutput);
+      {$endif ver2_4}
         if Do_Isdevice(hdl) then
           TextRec(f).FlushFunc:=@FileWriteFunc;
       end;

+ 24 - 0
rtl/unix/cwstring.pp

@@ -878,6 +878,26 @@ begin
   Result := iconv2win(ansistring(nl_langinfo(CODESET)))
 end;
 
+{$ifndef ver2_4}
+{$i textrec.inc}
+procedure SetStdIOCodePage(var T: Text); inline;
+begin
+  case TextRec(T).Mode of
+    fmInput:TextRec(T).CodePage:=GetStandardCodePage(scpConsoleInput);
+    fmOutput:TextRec(T).CodePage:=GetStandardCodePage(scpConsoleOutput);
+  end;
+end;
+
+procedure SetStdIOCodePages; inline;
+begin
+  SetStdIOCodePage(Input);
+  SetStdIOCodePage(Output);
+  SetStdIOCodePage(ErrOutput);
+  SetStdIOCodePage(StdOut);
+  SetStdIOCodePage(StdErr);
+end;
+{$endif ver2_4}
+
 Procedure SetCWideStringManager;
 Var
   CWideStringManager : TUnicodeStringManager;
@@ -941,6 +961,10 @@ initialization
   { set the DefaultSystemCodePage }
   DefaultSystemCodePage:=GetStandardCodePage(scpAnsi);
 
+  {$ifndef ver2_4}
+  SetStdIOCodePages;
+  {$endif ver2_4}
+
   { init conversion tables for main program }
   InitThread;
 finalization