Browse Source

* PChar -> PAnsiChar

Michaël Van Canneyt 2 years ago
parent
commit
290b5b07cf

+ 1 - 1
packages/fcl-process/src/amicommon/pipes.inc

@@ -49,7 +49,7 @@ end;
 
 procedure PipeClose (const FHandle: THandle);
 var
-  Filename: array[0..255] of Char;
+  Filename: array[0..255] of AnsiChar;
   DeleteIt: Boolean;
 begin
   {$if not defined(AMIGA_V1_2_ONLY)}

+ 17 - 16
packages/fcl-process/src/amicommon/process.inc

@@ -32,14 +32,14 @@ begin
   Result := true; (* Dummy version assumes always synchronous execution *)
 end;
 
-function GetNextWordPos (const S: string): integer;
+function GetNextWordPos (const S: ansistring): integer;
 const
   WhiteSpace = [' ', #9, #10, #13];
   Literals = ['"', ''''];
 var
   WStart: integer;
   InLiteral: boolean;
-  LastLiteral: char;
+  LastLiteral: ansiChar;
 begin
   WStart := 1;
 (* Skip whitespaces at the beginning *)
@@ -66,7 +66,7 @@ begin
   Result := WStart;
 end;
 
-function MaybeQuote (const S: string): string;
+function MaybeQuote (const S: ansistring): ansistring;
 begin
   if (Pos (' ', S) <> 0) then
    Result := '"' + S + '"'
@@ -87,11 +87,11 @@ const
 Procedure TProcess.Execute;
 var
   I: integer;
-  ExecName, FoundName: string;
+  ExecName, FoundName: ansistring;
   E2: EProcess;
-  OrigDir: string;
-  Params: string;
-  TempName: string;
+  OrigDir: ansistring;
+  Cmd,Params: ansistring;
+  TempName: ansistring;
   cos: BPTR;
   {$ifdef MorphOS}
   inA, inB, OutA, OutB: BPTR;
@@ -104,7 +104,8 @@ begin
    ExecName := FApplicationName;
   if (FCommandLine <> '') then
    begin
-    Params := FCommandLine;
+    Cmd:=FCommandLine;
+    Params := Cmd;
     if ExecName = '' then
      begin
       I := GetNextWordPos (Params);
@@ -112,7 +113,7 @@ begin
       ExecName := Trim (ExecName);
       Delete (Params, 1, Pred (I));
      end
-    else if Copy (FCommandLine, 1, Length (ExecName)) = ExecName then
+    else if Copy (Cmd, 1, Length (ExecName)) = ExecName then
      Delete (Params, 1, Succ (Length (ExecName)))
     else
      Delete (Params, 1, Pred (GetNextWordPos (Params)));
@@ -143,18 +144,18 @@ begin
       FProcessID := 0;
       // Pipenames, should be unique
       TempName := 'PIPE:PrO_' + HexStr(Self) + HexStr(GetTickCount, 8);
-      inA := DOSOpen(PChar(TempName), MODE_OLDFILE);
-      inB := DOSOpen(PChar(TempName), MODE_NEWFILE);
+      inA := DOSOpen(PAnsiChar(TempName), MODE_OLDFILE);
+      inB := DOSOpen(PAnsiChar(TempName), MODE_NEWFILE);
       TempName := TempName + 'o';
-      outA := DOSOpen(PChar(TempName), MODE_OLDFILE);
-      outB := DOSOpen(PChar(TempName), MODE_NEWFILE);
+      outA := DOSOpen(PAnsiChar(TempName), MODE_OLDFILE);
+      outB := DOSOpen(PAnsiChar(TempName), MODE_NEWFILE);
       // set buffer for all pipes
       SetVBuf(inA, nil, BUF_NONE, -1);
       SetVBuf(inB, nil, BUF_LINE, -1);
       SetVBuf(outA, nil, BUF_NONE, -1);
       SetVBuf(outB, nil, BUF_LINE, -1);
       // the actual Start of the command with given parameter and streams
-      Res := SystemTags(PChar(ExecName + ' ' + Params),
+      Res := SystemTags(PAnsiChar(ExecName + ' ' + Params),
                         [SYS_Input, AsTag(outA),
                          SYS_Output, AsTag(inB),
                          SYS_Asynch, AsTag(True),
@@ -186,8 +187,8 @@ begin
         TempName := 'T:PrO_'+ HexStr(FindTask(nil)) + '_' + IntToHex(UID,8);
       until not FileExists(TempName);
       //sysdebugln('TProcess start: "' + ExecName + ' ' + Params+'"  >' + TempName);
-      cos := AmigaDos.DosOpen(PChar(TempName), MODE_READWRITE);
-      FExitCode := LongInt(amigados.Execute(PChar(ExecName + ' ' + Params), BPTR(0), cos));
+      cos := AmigaDos.DosOpen(PAnsiChar(TempName), MODE_READWRITE);
+      FExitCode := LongInt(amigados.Execute(PAnsiChar(ExecName + ' ' + Params), BPTR(0), cos));
       DosSeek(cos, 0, OFFSET_BEGINNING);
       CreateStreams(0, THandle(cos),0);
     end;

+ 4 - 4
packages/fcl-process/src/amicommon/simpleipc.inc

@@ -105,10 +105,10 @@ Type
 function SafePutToPort(Msg: PMessage; Portname: string): Boolean;
  var
    Port: PMsgPort;
-   PName: PChar;
+   PName: PAnsiChar;
  begin
    Result := False;
-   PName := PChar(Portname + #0);
+   PName := PAnsiChar(Portname + #0);
    Forbid();
    Port := FindPort(PName);
    if Assigned(Port) then
@@ -193,12 +193,12 @@ end;
 Procedure TAmigaServerComm.StartServer;
 begin
   FPortName := PORTNAMESTART + Owner.ServerID + #0;
-  if Assigned(FindPort(PChar(FPortName))) then
+  if Assigned(FindPort(PAnsiChar(FPortName))) then
   begin
     DoError(SErrMsgPortExists,[FPortName]);
     Exit;
   end;
-  FMsgPort^.mp_Node.ln_Name := PChar(FPortName);
+  FMsgPort^.mp_Node.ln_Name := PAnsiChar(FPortName);
   FMsgPort^.mp_Node.ln_Pri := 0;
   AddPort(FMsgPort);
   if Assigned(MsgBody) then

+ 1 - 1
packages/fcl-process/src/dummy/process.inc

@@ -36,7 +36,7 @@ const
 var
   WStart: integer;
   InLiteral: boolean;
-  LastLiteral: char;
+  LastLiteral: AnsiChar;
 begin
   WStart := 1;
 (* Skip whitespaces at the beginning *)

+ 6 - 6
packages/fcl-process/src/os2/simpleipc.inc

@@ -33,7 +33,7 @@ const
 Type
   TPipeClientComm = Class(TIPCClientComm)
   Private
-    FFileName: String;
+    FFileName: AnsiString;
     FStream: TFileStream;
   Public
     Constructor Create(AOWner : TSimpleIPCClient); override;
@@ -97,10 +97,10 @@ end;
 type
   TPipeServerComm = class (TIPCServerComm)
   private
-    FFileName: string;
+    FFileName: ansistring;
     FStream: THandleStream;
     EventSem: THandle;
-    SemName: string;
+    SemName: ansistring;
   public
     constructor Create (AOWner: TSimpleIPCServer); override;
     procedure StartServer; override;
@@ -108,7 +108,7 @@ type
     function  PeekMessage (TimeOut: integer): boolean; override;
     procedure ReadMessage; override;
     function GetInstanceID: string; override;
-    property FileName: string read FFileName;
+    property FileName: Ansistring read FFileName;
     property Stream: THandleStream read FStream;
   end;
 
@@ -128,10 +128,10 @@ var
   H: THandle;
 begin
   if not (Assigned (FStream)) then
-    if (DosCreateNPipe (PChar (FFileName), H, np_Access_Inbound,
+    if (DosCreateNPipe (PAnsiChar (FFileName), H, np_Access_Inbound,
         np_ReadMode_Message or np_WriteMode_Message or 1, PipeBufSize,
                                                PipeBufSize, 0) <> 0) or
-           (DosCreateEventSem (PChar (SemName), EventSem, 0, 0) <> 0) or
+           (DosCreateEventSem (PAnsiChar (SemName), EventSem, 0, 0) <> 0) or
                           (DosSetNPipeSem (H, EventSem, PipeKey) <> 0) or
                                             (DosConnectNPipe (H) <> 0) then
                            Owner.DoError (SErrFailedToCreatePipe, [FFileName]);

+ 3 - 3
packages/fcl-process/src/processbody.inc

@@ -34,8 +34,8 @@ Type
    end;
    TProcessStringList = TProcessStrings;
    {$else}
-   TprocessChar   = {Ansi}Char;
-   TProcessString = {Ansi}String;
+   TprocessChar   = Char;
+   TProcessString = String;
    TProcessStrings = TStrings;
    TProcessStringList = TStringList;
    {$endif}
@@ -228,7 +228,7 @@ Procedure CommandToList(S : TProcessString; List : TProcessStrings);
      Result:=Copy(S,WStart,WEnd-WStart);
 
      if  (Length(Result) > 0)
-     and (Result[1] = Result[Length(Result)]) // if 1st char = last char and..
+     and (Result[1] = Result[Length(Result)]) // if 1st AnsiChar = last AnsiChar and..
      and (Result[1] in Literals) then // it's one of the literals, then
        Result:=Copy(Result, 2, Length(Result) - 2); //delete the 2 (but not others in it)
 

+ 4 - 0
packages/fcl-process/src/processunicode.pp

@@ -38,8 +38,12 @@ Type
   EProcess = Process.EProcess;
 
 {$macro on}
+{$IF SIZEOF(CHAR)=1}
+// For unicode RTL, there is nothing to redefine.
 {$define processunicodestring}
+{$ENDIF}
 {$define TProcessnamemacro:=TProcess}
 
 {$i processbody.inc}
+
 end.

+ 25 - 18
packages/fcl-process/src/unix/process.inc

@@ -62,27 +62,31 @@ begin
 end;
 
 Type
-  TPCharArray = Array[Word] of pchar;
+  TPCharArray = Array[Word] of PAnsiChar;
   PPCharArray = ^TPcharArray;
 
-Function StringsToPCharList(List : TStrings) : PPChar;
+Function StringsToPCharList(List : TStrings) : PPAnsiChar;
 
 Var
   I : Integer;
-  S : String;
+  S : AnsiString;
 
 begin
   I:=(List.Count)+1;
-  GetMem(Result,I*sizeOf(PChar));
+  GetMem(Result,I*sizeOf(PAnsiChar));
   PPCharArray(Result)^[List.Count]:=Nil;
   For I:=0 to List.Count-1 do
     begin
+    {$if SIZEOF(CHAR)=2}
+    S:=UTF8Encode(List[i]);
+    {$ELSE}
     S:=List[i];
-    Result[i]:=StrNew(PChar(S));
+    {$ENDIF}
+    Result[i]:=StrNew(PAnsiChar(S));
     end;
 end;
 
-Procedure FreePCharList(List : PPChar);
+Procedure FreePCharList(List : PPAnsiChar);
 
 Var
   I : integer;
@@ -166,7 +170,7 @@ begin
     Raise EProcess.Create(SErrNoTerminalProgram);
 end;
 
-Function MakeCommand(P : TProcess) : PPchar;
+Function MakeCommand(P : TProcess) : PPAnsiChar;
 
 {$ifdef darwin}
 Const
@@ -181,23 +185,26 @@ Var
   Cmd : String;
   S  : TStringList;
   G : String;
+  PA,PC : String;
   
 begin
-  If (P.ApplicationName='') and (P.CommandLine='') and (P.Executable='') then
+  PA:=P.ApplicationName;
+  PC:=P.CommandLine;
+  If (PA='') and (PC='') and (P.Executable='') then
     Raise EProcess.Create(SNoCommandline);
   S:=TStringList.Create;
   try
-    if (P.ApplicationName='') and (P.CommandLine='') then
+    if (PA='') and (PC='') then
       begin
       S.Assign(P.Parameters);
       S.Insert(0,P.Executable);
       end
     else
       begin
-      If (P.CommandLine='') then
-        Cmd:=P.ApplicationName
+      If (PA='') then
+        Cmd:=PA
       else
-        Cmd:=P.CommandLine;
+        Cmd:=PC;
       CommandToList(Cmd,S);
       end;
     if poNewConsole in P.Options then
@@ -213,9 +220,9 @@ begin
       S.Insert(0,TerminalApp);
       {$else}
       S.Insert(0,'-e');
-      If (P.ApplicationName<>'') then
+      If (PA<>'') then
         begin
-        S.Insert(0,P.ApplicationName);
+        S.Insert(0,PA);
         S.Insert(0,'-title');
         end;
       if suoUseCountChars in P.StartupOptions then
@@ -230,10 +237,10 @@ begin
       {$endif}
       end;
     {$ifndef haiku}
-    if (P.ApplicationName<>'') then
+    if (PA<>'') then
       begin
       S.Add(TitleOption);
-      S.Add(P.ApplicationName);
+      S.Add(PA);
       end;
     G:='';
     if (suoUseSize in P.StartupOptions) then
@@ -311,8 +318,8 @@ Procedure TProcess.Execute;
 Var
   HI,HO,HE : TPipePair;
   PID      : Longint;
-  FEnv     : PPChar;
-  Argv     : PPChar;
+  FEnv     : PPAnsiChar;
+  Argv     : PPAnsiChar;
   fd       : Integer;
   res      : cint;
   FoundName,